This commit is contained in:
Nico
2024-10-31 10:33:46 +01:00
commit ad6d893cb0
237 changed files with 19793 additions and 0 deletions

View File

@@ -0,0 +1,139 @@
import GLib from "gi://GLib"
import icons from "../../lib/icons.js"
const time = (time, format = "%H:%M") => GLib.DateTime
.new_from_unix_local(time)
.format(format)
const NotificationIcon = ({ app_entry, app_icon, image }) => {
if (image) {
return Widget.Box({
vpack: "start",
hexpand: false,
class_name: "icon img",
css: `
background-image: url("${image}");
background-size: cover;
background-repeat: no-repeat;
background-position: center;
min-width: 78px;
min-height: 78px;
`,
})
}
let icon = icons.fallback.notification
if (Utils.lookUpIcon(app_icon))
icon = app_icon
if (Utils.lookUpIcon(app_entry || ""))
icon = app_entry || ""
return Widget.Box({
vpack: "start",
hexpand: false,
class_name: "icon",
css: `
min-width: 78px;
min-height: 78px;
`,
child: Widget.Icon({
icon,
size: 58,
hpack: "center", hexpand: true,
vpack: "center", vexpand: true,
}),
})
}
export default (notification) => {
const content = Widget.Box({
class_name: "content",
children: [
NotificationIcon(notification),
Widget.Box({
hexpand: true,
vertical: true,
children: [
Widget.Box({
children: [
Widget.Label({
class_name: "title",
xalign: 0,
justification: "left",
hexpand: true,
max_width_chars: 24,
truncate: "end",
wrap: true,
label: notification.summary.trim(),
use_markup: true,
}),
Widget.Label({
class_name: "time",
vpack: "start",
label: time(notification.time),
}),
Widget.Button({
class_name: "close-button",
vpack: "start",
hexpand: false,
vexpand: false,
child: Widget.Icon("window-close-symbolic"),
on_clicked: notification.close,
}),
],
}),
Widget.Label({
class_name: "description",
hexpand: true,
use_markup: true,
xalign: 0,
justification: "left",
label: notification.body.trim(),
max_width_chars: 24,
wrap: true,
}),
],
}),
],
})
const actionsbox = notification.actions.length > 0 ? Widget.Revealer({
transition: "slide_down",
child: Widget.EventBox({
child: Widget.Box({
class_name: "actions horizontal",
children: notification.actions.map(action => Widget.Button({
class_name: "action-button",
on_clicked: () => notification.invoke(action.id),
hexpand: true,
child: Widget.Label(action.label),
})),
}),
}),
}) : null
const eventbox = Widget.EventBox({
vexpand: false,
on_primary_click: notification.dismiss,
on_hover() {
if (actionsbox)
actionsbox.reveal_child = true
},
on_hover_lost() {
if (actionsbox)
actionsbox.reveal_child = true
notification.dismiss()
},
child: Widget.Box({
vertical: true,
children: actionsbox ? [content, actionsbox] : [content],
}),
})
return Widget.Box({
class_name: `notification ${notification.urgency}`,
child: eventbox,
})
}

View File

@@ -0,0 +1,95 @@
import Notification from "./Notification.js"
import options from "../../options.js"
const notifications = await Service.import("notifications")
const { transitionDuration } = options
const { position, blacklist } = options.notifications
const { timeout, idle } = Utils
function Animated(id) {
const n = notifications.getNotification(id)
const widget = Notification(n)
const inner = Widget.Revealer({
css: "border: 1px solid magenta;",
transition: "slide_left",
transition_duration: transitionDuration,
child: widget,
})
const outer = Widget.Revealer({
css: "border: 1px solid yellow;",
transition: "slide_down",
transition_duration: transitionDuration,
child: inner,
})
const box = Widget.Box({
hpack: "end",
child: outer,
})
idle(() => {
outer.reveal_child = true
timeout(transitionDuration, () => {
inner.reveal_child = true
})
})
return Object.assign(box, {
dismiss() {
inner.reveal_child = false
timeout(transitionDuration, () => {
outer.reveal_child = false
timeout(transitionDuration, () => {
box.destroy()
})
})
},
})
}
function PopupList() {
const map = new Map
const box = Widget.Box({
hpack: "end",
vertical: true,
css: `min-width: ${options.notifications.width}px;`,
})
function remove(_, id) {
map.get(id)?.dismiss()
map.delete(id)
}
return box
.hook(notifications, (_, id) => {
if (id !== undefined) {
if (map.has(id))
remove(null, id)
if (blacklist.includes(notifications.getNotification(id).app_name))
return
if (notifications.dnd)
return
const w = Animated(id)
map.set(id, w)
box.children = [w, ...box.children]
}
}, "notified")
.hook(notifications, remove, "dismissed")
.hook(notifications, remove, "closed")
}
export default (monitor) => Widget.Window({
monitor,
name: `notifications${monitor}`,
anchor: position,
class_name: "notifications",
child: Widget.Box({
css: "padding: 2px;",
child: PopupList(),
}),
})