ags: update to new syntax

This commit is contained in:
end-4
2024-01-11 16:50:12 +07:00
parent c61db15a88
commit 85704218e3
74 changed files with 2155 additions and 1898 deletions
+4 -3
View File
@@ -1,6 +1,7 @@
const { Gio, Gdk, GLib, Gtk } = imports.gi;
import { App, Widget, Utils } from '../../imports.js';
const { Box, Button, CenterBox, Label, Revealer } = Widget;
const { Gio } = imports.gi;
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
const { Box, Button, Label } = Widget;
import { MaterialIcon } from "../../lib/materialicon.js";
import { getCalendarLayout } from "../../lib/calendarlayout.js";
import { setupCursorHover } from "../../lib/cursorhover.js";
@@ -1,15 +1,11 @@
// This file is for the notification widget on the sidebar
// This file is for the notification list on the sidebar
// For the popup notifications, see onscreendisplay.js
// The actual widget for each single notification is in lib/notification.js
const { GLib, Gtk } = imports.gi;
import { Service, Utils, Widget } from '../../imports.js';
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
import Notifications from 'resource:///com/github/Aylur/ags/service/notifications.js';
const { lookUpIcon, timeout } = Utils;
const { Box, Button, Icon, Label, Revealer, Scrollable, Stack } = Widget;
const { Box, Button, Label, Scrollable, Stack } = Widget;
import { MaterialIcon } from "../../lib/materialicon.js";
import { setupCursorHover } from "../../lib/cursorhover.js";
import { ConfigToggle, ConfigSegmentedSelection, ConfigGap } from '../../lib/configwidgets.js';
import Notification from "../../lib/notification.js";
export default (props) => {
@@ -35,8 +31,8 @@ export default (props) => {
vertical: true,
vpack: 'start',
className: 'spacing-v-5-revealer',
connections: [
[Notifications, (box, id) => {
setup: (self) => self
.hook(Notifications, (box, id) => {
if (box.get_children().length == 0) { // On init there's no notif, or 1st notif
Notifications.notifications
.forEach(n => {
@@ -58,17 +54,16 @@ export default (props) => {
box.pack_end(NewNotif, false, false, 0);
box.show_all();
}
}, 'notified'],
[Notifications, (box, id) => {
}, 'notified')
.hook(Notifications, (box, id) => {
if (!id) return;
for (const ch of box.children) {
if (ch._id === id) {
ch._destroyWithAnims();
ch.attribute.destroyWithAnims();
}
}
}, 'closed'],
],
}, 'closed')
,
});
const ListActionButton = (icon, name, action) => Button({
className: 'notif-listaction-btn',
@@ -100,7 +95,7 @@ export default (props) => {
Label({
hexpand: true,
xalign: 0,
className: 'txt-title-small margin-left-10',
className: 'txt-title-small margin-left-10',
// ^ (extra margin on the left so that it looks similarly spaced
// when compared to borderless "Clear" button on the right)
label: 'Notifications',
+33 -33
View File
@@ -1,5 +1,7 @@
const { GLib } = imports.gi;
import { Widget, Utils, Service } from '../../imports.js';
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
import Bluetooth from 'resource:///com/github/Aylur/ags/service/bluetooth.js';
import Network from 'resource:///com/github/Aylur/ags/service/network.js';
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
@@ -20,21 +22,19 @@ function expandTilde(path) {
export const ToggleIconWifi = (props = {}) => Widget.Button({
className: 'txt-small sidebar-iconbutton',
tooltipText: 'Wifi | Right-click to configure',
onClicked: Network.toggleWifi,
onClicked: () => Network.toggleWifi(),
onSecondaryClickRelease: () => {
execAsync(['bash', '-c', 'XDG_CURRENT_DESKTOP="gnome" gnome-control-center wifi', '&']);
App.closeWindow('sideright');
},
child: NetworkIndicator(),
connections: [
[Network, button => {
setup: (self) => {
setupCursorHover(self);
self.hook(Network, button => {
button.toggleClassName('sidebar-button-active', [Network.wifi?.internet, Network.wired?.internet].includes('connected'))
}],
[Network, button => {
button.tooltipText = (`${Network.wifi?.ssid} | Right-click to configure` || 'Unknown');
}],
],
setup: setupCursorHover,
});
},
...props,
});
@@ -53,12 +53,12 @@ export const ToggleIconBluetooth = (props = {}) => Widget.Button({
App.closeWindow('sideright');
},
child: BluetoothIndicator(),
connections: [
[Bluetooth, button => {
setup: (self) => {
setupCursorHover(self);
self.hook(Bluetooth, button => {
button.toggleClassName('sidebar-button-active', Bluetooth?.enabled)
}],
],
setup: setupCursorHover,
});
},
...props,
});
@@ -82,24 +82,24 @@ export const HyprToggleIcon = (icon, name, hyprlandConfigValue, props = {}) => W
})
export const ModuleNightLight = (props = {}) => Widget.Button({ // TODO: Make this work
properties: [
['enabled', false],
['yellowlight', undefined],
],
attribute: {
enabled: false,
yellowlight: undefined,
},
className: 'txt-small sidebar-iconbutton',
tooltipText: 'Night Light',
onClicked: (self) => {
self._enabled = !self._enabled;
self.toggleClassName('sidebar-button-active', self._enabled);
// if (self._enabled) Utils.execAsync(['bash', '-c', 'wlsunset & disown'])
if (self._enabled) Utils.execAsync('wlsunset')
self.attribute.enabled = !self.attribute.enabled;
self.toggleClassName('sidebar-button-active', self.attribute.enabled);
// if (self.attribute.enabled) Utils.execAsync(['bash', '-c', 'wlsunset & disown'])
if (self.attribute.enabled) Utils.execAsync('wlsunset')
else Utils.execAsync('pkill wlsunset');
},
child: MaterialIcon('nightlight', 'norm'),
setup: (self) => {
setupCursorHover(self);
self._enabled = !!exec('pidof wlsunset');
self.toggleClassName('sidebar-button-active', self._enabled);
self.attribute.enabled = !!exec('pidof wlsunset');
self.toggleClassName('sidebar-button-active', self.attribute.enabled);
},
...props,
});
@@ -131,17 +131,17 @@ export const ModuleInvertColors = (props = {}) => Widget.Button({
})
export const ModuleIdleInhibitor = (props = {}) => Widget.Button({ // TODO: Make this work
properties: [
['enabled', false],
['inhibitor', undefined],
],
attribute: {
enabled: false,
inhibitor: undefined,
},
className: 'txt-small sidebar-iconbutton',
tooltipText: 'Keep system awake',
onClicked: (self) => {
self._enabled = !self._enabled;
self.toggleClassName('sidebar-button-active', self._enabled);
if (self._enabled) {
self._inhibitor = Utils.subprocess(
self.attribute.enabled = !self.attribute.enabled;
self.toggleClassName('sidebar-button-active', self.attribute.enabled);
if (self.attribute.enabled) {
self.attribute.inhibitor = Utils.subprocess(
['wayland-idle-inhibitor.py'],
(output) => print(output),
(err) => logError(err),
@@ -149,7 +149,7 @@ export const ModuleIdleInhibitor = (props = {}) => Widget.Button({ // TODO: Make
);
}
else {
self._inhibitor.force_exit();
self.attribute.inhibitor.force_exit();
}
},
child: MaterialIcon('coffee', 'norm'),
+9 -34
View File
@@ -1,5 +1,5 @@
const { GLib, Gdk, Gtk } = imports.gi;
import { Utils, Widget } from '../../imports.js';
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
const { execAsync, exec } = Utils;
const { Box, EventBox } = Widget;
import {
@@ -17,44 +17,19 @@ import {
import ModuleNotificationList from "./notificationlist.js";
import { ModuleCalendar } from "./calendar.js";
// const NUM_OF_TOGGLES_PER_LINE = 5;
// const togglesFlowBox = Widget.FlowBox({
// className: 'sidebar-group spacing-h-10',
// setup: (self) => {
// self.set_max_children_per_line(NUM_OF_TOGGLES_PER_LINE);
// self.add(ToggleIconWifi({ hexpand: true }));
// self.add(ToggleIconBluetooth({ hexpand: true }));
// self.add(HyprToggleIcon('mouse', 'Raw input', 'input:force_no_accel', { hexpand: true }));
// self.add(HyprToggleIcon('front_hand', 'No touchpad while typing', 'input:touchpad:disable_while_typing', { hexpand: true }));
// self.add(ModuleNightLight({ hexpand: true }));
// // Setup flowbox rearrange
// self.connect('child-activated', (self, child) => {
// if (child.get_index() === 0) {
// self.reorder_child(child, self.get_children().length - 1);
// } else {
// self.reorder_child(child, 0);
// }
// });
// }
// })
const timeRow = Box({
className: 'spacing-h-5 sidebar-group-invisible-morehorizpad',
children: [
// Widget.Label({
// className: 'txt-title txt',
// connections: [[5000, label => {
// label.label = GLib.DateTime.new_now_local().format("%H:%M");
// }]],
// }),
Widget.Label({
hpack: 'center',
className: 'txt-small txt',
connections: [[5000, label => {
execAsync(['bash', '-c', `uptime -p | sed -e 's/up //;s/ hours,/h/;s/ minutes/m/'`]).then(upTimeString => {
label.label = `System uptime: ${upTimeString}`;
}).catch(print);
}]],
setup: (self) => self
.poll(5000, label => {
execAsync(['bash', '-c', `uptime -p | sed -e 's/up //;s/ hours,/h/;s/ minutes/m/'`]).then(upTimeString => {
label.label = `Uptime: ${upTimeString}`;
}).catch(print);
})
,
}),
Widget.Box({ hexpand: true }),
// ModuleEditIcon({ hpack: 'end' }), // TODO: Make this work
+29 -26
View File
@@ -1,6 +1,6 @@
const { Gio, Gdk, GLib, Gtk } = imports.gi;
import { App, Widget, Utils } from '../../imports.js';
const { Box, Button, CenterBox, Label, Revealer } = Widget;
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
const { Box, Button, Label, Revealer } = Widget;
import { MaterialIcon } from "../../lib/materialicon.js";
import Todo from "../../services/todo.js";
import { setupCursorHover } from "../../lib/cursorhover.js";
@@ -73,33 +73,36 @@ const todoListItem = (task, id, isDone, isEven = false) => {
}
const todoItems = (isDone) => Widget.Scrollable({
hscroll: 'never',
vscroll: 'automatic',
child: Widget.Box({
vertical: true,
connections: [[Todo, (self) => {
self.children = Todo.todo_json.map((task, i) => {
if (task.done != isDone) return null;
return todoListItem(task, i, isDone);
})
if (self.children.length == 0) {
self.homogeneous = true;
self.children = [
Widget.Box({
hexpand: true,
vertical: true,
vpack: 'center',
className: 'txt',
children: [
MaterialIcon(`${isDone ? 'checklist' : 'check_circle'}`, 'badonkers'),
Label({ label: `${isDone ? 'Finished tasks will go here' : 'Nothing here!'}` })
]
})
]
}
else self.homogeneous = false;
}, 'updated']]
setup: (self) => self
.hook(Todo, (self) => {
self.children = Todo.todo_json.map((task, i) => {
if (task.done != isDone) return null;
return todoListItem(task, i, isDone);
})
if (self.children.length == 0) {
self.homogeneous = true;
self.children = [
Widget.Box({
hexpand: true,
vertical: true,
vpack: 'center',
className: 'txt',
children: [
MaterialIcon(`${isDone ? 'checklist' : 'check_circle'}`, 'badonkers'),
Label({ label: `${isDone ? 'Finished tasks will go here' : 'Nothing here!'}` })
]
})
]
}
else self.homogeneous = false;
}, 'updated')
,
}),
setup: (listContents) => {
listContents.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
const vScrollbar = listContents.get_vscrollbar();
vScrollbar.get_style_context().add_class('sidebar-scrollbar');
}