Tweak notifications on AGS
This commit is contained in:
parent
d675225c83
commit
55a3387697
|
@ -4,129 +4,137 @@ notifications.forceTimeout = true
|
||||||
|
|
||||||
/** @param {import('resource:///com/github/Aylur/ags/service/notifications.js').Notification} n */
|
/** @param {import('resource:///com/github/Aylur/ags/service/notifications.js').Notification} n */
|
||||||
function NotificationIcon({ app_entry, app_icon, image }) {
|
function NotificationIcon({ app_entry, app_icon, image }) {
|
||||||
if (image) {
|
if (image) {
|
||||||
return Widget.Box({
|
|
||||||
css: `background-image: url("${image}");`
|
|
||||||
+ "background-size: contain;"
|
|
||||||
+ "background-repeat: no-repeat;"
|
|
||||||
+ "background-position: center;",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
let icon = "dialog-information-symbolic"
|
|
||||||
if (Utils.lookUpIcon(app_icon))
|
|
||||||
icon = app_icon
|
|
||||||
|
|
||||||
if (app_entry && Utils.lookUpIcon(app_entry))
|
|
||||||
icon = app_entry
|
|
||||||
|
|
||||||
return Widget.Box({
|
return Widget.Box({
|
||||||
child: Widget.Icon(icon),
|
css: `background-image: url("${image}");`
|
||||||
|
+ "background-size: contain;"
|
||||||
|
+ "background-repeat: no-repeat;"
|
||||||
|
+ "background-position: center;",
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
let icon = "dialog-information-symbolic"
|
||||||
|
if (Utils.lookUpIcon(app_icon))
|
||||||
|
icon = app_icon
|
||||||
|
|
||||||
|
if (app_entry && Utils.lookUpIcon(app_entry))
|
||||||
|
icon = app_entry
|
||||||
|
|
||||||
|
return Widget.Box({
|
||||||
|
child: Widget.Icon(icon),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param {import('resource:///com/github/Aylur/ags/service/notifications.js').Notification} n */
|
/** @param {import('resource:///com/github/Aylur/ags/service/notifications.js').Notification} n */
|
||||||
function Notification(n) {
|
function Notification(n) {
|
||||||
const icon = Widget.Box({
|
const icon = Widget.Box({
|
||||||
vpack: "start",
|
vpack: "start",
|
||||||
class_name: "icon",
|
class_name: "icon",
|
||||||
child: NotificationIcon(n),
|
child: NotificationIcon(n),
|
||||||
})
|
})
|
||||||
|
|
||||||
const title = Widget.Label({
|
const title = Widget.Label({
|
||||||
class_name: "title",
|
class_name: "title",
|
||||||
xalign: 0,
|
xalign: 0,
|
||||||
justification: "left",
|
justification: "left",
|
||||||
hexpand: true,
|
hexpand: true,
|
||||||
max_width_chars: 24,
|
max_width_chars: 24,
|
||||||
truncate: "end",
|
truncate: "end",
|
||||||
wrap: true,
|
wrap: true,
|
||||||
label: n.summary,
|
label: n.summary,
|
||||||
use_markup: true,
|
use_markup: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
const body = Widget.Label({
|
const body = Widget.Label({
|
||||||
class_name: "body",
|
class_name: "body",
|
||||||
hexpand: true,
|
hexpand: true,
|
||||||
use_markup: true,
|
use_markup: true,
|
||||||
xalign: 0,
|
xalign: 0,
|
||||||
justification: "left",
|
justification: "left",
|
||||||
label: n.body,
|
label: n.body,
|
||||||
wrap: true,
|
wrap: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
const actions = Widget.Box({
|
const actions = Widget.Box({
|
||||||
class_name: "actions",
|
class_name: "actions",
|
||||||
children: n.actions.map(({ id, label }) => Widget.Button({
|
children: n.actions.map(({ id, label }) => Widget.Button({
|
||||||
class_name: "action-button",
|
class_name: "action-button",
|
||||||
on_clicked: () => {
|
on_clicked: () => {
|
||||||
n.invoke(id)
|
n.invoke(id)
|
||||||
n.dismiss()
|
n.dismiss()
|
||||||
},
|
},
|
||||||
hexpand: true,
|
hexpand: true,
|
||||||
child: Widget.Label(label),
|
child: Widget.Label(label),
|
||||||
})),
|
})),
|
||||||
})
|
})
|
||||||
|
|
||||||
return Widget.EventBox(
|
return Widget.EventBox(
|
||||||
{
|
{
|
||||||
attribute: { id: n.id },
|
attribute: { id: n.id },
|
||||||
on_primary_click: n.dismiss,
|
on_primary_click: n.dismiss,
|
||||||
},
|
},
|
||||||
|
Widget.Box(
|
||||||
|
{
|
||||||
|
class_name: `notification ${n.urgency}`,
|
||||||
|
vertical: true,
|
||||||
|
},
|
||||||
|
Widget.Box([
|
||||||
|
icon,
|
||||||
Widget.Box(
|
Widget.Box(
|
||||||
{
|
{ vertical: true },
|
||||||
class_name: `notification ${n.urgency}`,
|
title,
|
||||||
vertical: true,
|
body,
|
||||||
},
|
|
||||||
Widget.Box([
|
|
||||||
icon,
|
|
||||||
Widget.Box(
|
|
||||||
{ vertical: true },
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
),
|
|
||||||
]),
|
|
||||||
actions,
|
|
||||||
),
|
),
|
||||||
)
|
]),
|
||||||
|
actions,
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function NotificationPopups(monitor = 0) {
|
export function NotificationPopups(monitor = 0) {
|
||||||
const list = Widget.Box({
|
const list = Widget.Box({
|
||||||
vertical: true,
|
vertical: true,
|
||||||
children: notifications.popups.map(Notification),
|
children: notifications.popups.map(Notification),
|
||||||
})
|
})
|
||||||
|
|
||||||
function onNotified(_, /** @type {number} */ id) {
|
function onNotified(_, /** @type {number} */ id) {
|
||||||
|
const n = notifications.getNotification(id)
|
||||||
|
if (n) {
|
||||||
|
list.children = [Notification(n), ...list.children]
|
||||||
|
// Schedule a timeout to dismiss the notification
|
||||||
|
setTimeout(() => {
|
||||||
const n = notifications.getNotification(id)
|
const n = notifications.getNotification(id)
|
||||||
if (n)
|
if (n) { // if the notification is still there
|
||||||
list.children = [Notification(n), ...list.children]
|
n.dismiss()
|
||||||
|
}
|
||||||
|
}, notifications.popupTimeout)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function onDismissed(_, /** @type {number} */ id) {
|
function onDismissed(_, /** @type {number} */ id) {
|
||||||
list.children.find(n => n.attribute.id === id)?.destroy()
|
list.children.find(n => n.attribute.id === id)?.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
list.hook(notifications, onNotified, "notified")
|
list.hook(notifications, onNotified, "notified")
|
||||||
.hook(notifications, onDismissed, "dismissed")
|
.hook(notifications, onDismissed, "dismissed")
|
||||||
|
|
||||||
return Widget.Window({
|
return Widget.Window({
|
||||||
monitor,
|
monitor,
|
||||||
name: `notifications${monitor}`,
|
name: `notifications${monitor}`,
|
||||||
class_name: "notification-popups",
|
class_name: "notification-popups",
|
||||||
anchor: ["top", "right"],
|
anchor: ["top", "right"],
|
||||||
child: Widget.Box({
|
child: Widget.Box({
|
||||||
css: "min-width: 2px; min-height: 2px;",
|
css: "min-width: 2px; min-height: 2px;",
|
||||||
class_name: "notifications",
|
class_name: "notifications",
|
||||||
vertical: true,
|
vertical: true,
|
||||||
child: list,
|
child: list,
|
||||||
|
|
||||||
/** this is a simple one liner that could be used instead of
|
/** this is a simple one liner that could be used instead of
|
||||||
hooking into the 'notified' and 'dismissed' signals.
|
hooking into the 'notified' and 'dismissed' signals.
|
||||||
but its not very optimized becuase it will recreate
|
but its not very optimized becuase it will recreate
|
||||||
the whole list everytime a notification is added or dismissed */
|
the whole list everytime a notification is added or dismissed */
|
||||||
// children: notifications.bind('popups')
|
// children: notifications.bind('popups')
|
||||||
// .as(popups => popups.map(Notification))
|
// .as(popups => popups.map(Notification))
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
];
|
];
|
||||||
|
|
||||||
home.packages = with pkgs; [
|
home.packages = with pkgs; [
|
||||||
libreoffice
|
onlyoffice-bin
|
||||||
telegram-desktop
|
telegram-desktop
|
||||||
webcord
|
webcord
|
||||||
devenv
|
devenv
|
||||||
|
|
|
@ -105,8 +105,7 @@
|
||||||
wget = ''wget --hsts-file = "$XDG_DATA_HOME/wget-hsts"'';
|
wget = ''wget --hsts-file = "$XDG_DATA_HOME/wget-hsts"'';
|
||||||
python = "python3";
|
python = "python3";
|
||||||
vim = "nvim";
|
vim = "nvim";
|
||||||
v = ''
|
v = ''echo $(pwd) > /tmp/oil_dir && nvim -c ':lua require("oil").open()' && cd "$(cat /tmp/oil_dir 2> /dev/null || pwd)"'';
|
||||||
nvim -c ':lua require("oil").open()' && cd "$(cat /tmp/oil_dir 2> /dev/null || pwd)"'';
|
|
||||||
cpr =
|
cpr =
|
||||||
"rsync --archive -hh --partial --info = stats1,progress2 --modify-window = 1";
|
"rsync --archive -hh --partial --info = stats1,progress2 --modify-window = 1";
|
||||||
mvr =
|
mvr =
|
||||||
|
|
Loading…
Reference in New Issue