feat(ags): adapt notif button to new notif center

This commit is contained in:
matt1432 2023-09-11 14:38:24 -04:00
parent 2bd7b36392
commit c97ebf6c51

View file

@ -1,46 +1,51 @@
const { Box, Label } = ags.Widget; const { Box, Label, Icon } = ags.Widget;
const { subprocess } = ags.Utils; const { openWindow, closeWindow } = ags.App;
const deflisten = subprocess; const { Notifications } = ags.Service;
import { EventBox } from '../common.js'; import { EventBox, Separator } from '../common.js';
var notifButtonState = false;
deflisten(
['bash', '-c', '$AGS_PATH/notif.sh icon'],
(output) => {
NotifButton.child.children[0].label = ' ' + output;
},
);
deflisten(
['bash', '-c', '$AGS_PATH/notif-toggle.sh state'],
(output) => {
print(output)
if (output == 'On') {
NotifButton.toggleClassName('toggle-on', false);
} else {
NotifButton.toggleClassName('toggle-on', true);
}
},
);
export const NotifButton = EventBox({ export const NotifButton = EventBox({
className: 'toggle-off', className: 'toggle-off',
onPrimaryClickRelease: function() { onPrimaryClickRelease: () => {
subprocess( if (notifButtonState) {
['bash', '-c', '$AGS_PATH/notif-toggle.sh toggle'], NotifButton.toggleClassName('toggle-on', false);
(output) => { closeWindow('notification-center');
print(output) notifButtonState = false;
if (output == 'On') { }
NotifButton.toggleClassName('toggle-on', true); else {
} else { NotifButton.toggleClassName('toggle-on', true);
NotifButton.toggleClassName('toggle-on', false); openWindow('notification-center');
} notifButtonState = true;
}, }
);
}, },
child: Box({ child: Box({
className: 'notif-panel', className: 'notif-panel',
vertical: false, vertical: false,
child: Label({ children: [
label: "", Separator(28),
}),
Icon({
connections: [
[Notifications, icon => {
icon.icon = Notifications.dnd
? 'notifications-disabled-symbolic'
: 'preferences-system-notifications-symbolic';
}],
],
}),
Separator(8),
Label({
connections: [
[Notifications, label => {
label.label = String(Notifications.notifications.length);
}],
],
}),
],
}), }),
}); });