refactor(ags): update typechecking to match latest types
This commit is contained in:
parent
a126d97bbf
commit
ae615b08f5
13 changed files with 142 additions and 139 deletions
|
@ -7,9 +7,7 @@ import { lookUpIcon } from 'resource:///com/github/Aylur/ags/utils.js';
|
||||||
import CursorBox from '../misc/cursorbox.js';
|
import CursorBox from '../misc/cursorbox.js';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/** @param {import('types/service/applications.js').Application} app */
|
||||||
* @param {import('types/service/applications.js').Application} app
|
|
||||||
*/
|
|
||||||
export default (app) => {
|
export default (app) => {
|
||||||
const icon = Icon({ size: 42 });
|
const icon = Icon({ size: 42 });
|
||||||
const iconString = app.app.get_string('Icon');
|
const iconString = app.app.get_string('Icon');
|
||||||
|
|
|
@ -23,10 +23,9 @@ const Applauncher = ({ window_name = 'applauncher' } = {}) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
fzfResults = fzf.find(text);
|
fzfResults = fzf.find(text);
|
||||||
|
// @ts-expect-error
|
||||||
list.set_sort_func((a, b) => {
|
list.set_sort_func((a, b) => {
|
||||||
// @ts-expect-error
|
|
||||||
const row1 = a.get_children()[0]?.attribute.app.name;
|
const row1 = a.get_children()[0]?.attribute.app.name;
|
||||||
// @ts-expect-error
|
|
||||||
const row2 = b.get_children()[0]?.attribute.app.name;
|
const row2 = b.get_children()[0]?.attribute.app.name;
|
||||||
|
|
||||||
if (!row1 || !row2) {
|
if (!row1 || !row2) {
|
||||||
|
@ -39,7 +38,8 @@ const Applauncher = ({ window_name = 'applauncher' } = {}) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const makeNewChildren = () => {
|
const makeNewChildren = () => {
|
||||||
list.get_children().forEach((ch) => {
|
// @ts-expect-error
|
||||||
|
Array.from(list.get_children()).forEach((ch) => {
|
||||||
ch.destroy();
|
ch.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@ const Applauncher = ({ window_name = 'applauncher' } = {}) => {
|
||||||
.flatMap((app) => AppItem(app));
|
.flatMap((app) => AppItem(app));
|
||||||
|
|
||||||
children.forEach((ch) => {
|
children.forEach((ch) => {
|
||||||
|
// @ts-expect-error
|
||||||
list.add(ch);
|
list.add(ch);
|
||||||
});
|
});
|
||||||
list.show_all();
|
list.show_all();
|
||||||
|
@ -84,11 +85,10 @@ const Applauncher = ({ window_name = 'applauncher' } = {}) => {
|
||||||
setSort(text);
|
setSort(text);
|
||||||
let visibleApps = 0;
|
let visibleApps = 0;
|
||||||
|
|
||||||
list.get_children().forEach((row) => {
|
// @ts-expect-error
|
||||||
// @ts-expect-error
|
Array.from(list.get_children()).forEach((row) => {
|
||||||
row.changed();
|
row.changed();
|
||||||
|
|
||||||
// @ts-expect-error
|
|
||||||
const item = row.get_children()[0];
|
const item = row.get_children()[0];
|
||||||
|
|
||||||
if (item?.attribute.app) {
|
if (item?.attribute.app) {
|
||||||
|
|
|
@ -14,7 +14,6 @@ export default () => Box({
|
||||||
children: [
|
children: [
|
||||||
Icon({
|
Icon({
|
||||||
class_name: 'battery-indicator',
|
class_name: 'battery-indicator',
|
||||||
// @ts-expect-error
|
|
||||||
icon: Battery.bind('icon_name'),
|
icon: Battery.bind('icon_name'),
|
||||||
}).hook(Battery, (self) => {
|
}).hook(Battery, (self) => {
|
||||||
self.toggleClassName('charging', Battery.charging);
|
self.toggleClassName('charging', Battery.charging);
|
||||||
|
|
|
@ -8,7 +8,6 @@ const SPACING = 5;
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const icon = Icon({
|
const icon = Icon({
|
||||||
// @ts-expect-error
|
|
||||||
icon: Brightness.bind('screenIcon'),
|
icon: Brightness.bind('screenIcon'),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ export default () => Box({
|
||||||
.query(Hyprland.active.client.class)[0];
|
.query(Hyprland.active.client.class)[0];
|
||||||
|
|
||||||
if (app) {
|
if (app) {
|
||||||
self.icon = app.icon_name;
|
self.icon = app.icon_name || '';
|
||||||
self.visible = Hyprland.active.client.title !== '';
|
self.visible = Hyprland.active.client.title !== '';
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -9,7 +9,7 @@ const SPACING = 4;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Label} self
|
* @param {import('types/widgets/label').default} self
|
||||||
* @param {string} layout
|
* @param {string} layout
|
||||||
* @param {string} _
|
* @param {string} _
|
||||||
*/
|
*/
|
||||||
|
@ -21,7 +21,6 @@ const getKbdLayout = (self, _, layout) => {
|
||||||
|
|
||||||
const shortName = layout.match(/\(([A-Za-z]+)\)/);
|
const shortName = layout.match(/\(([A-Za-z]+)\)/);
|
||||||
|
|
||||||
// @ts-expect-error
|
|
||||||
self.label = shortName ? shortName[1] : layout;
|
self.label = shortName ? shortName[1] : layout;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -35,7 +34,6 @@ const getKbdLayout = (self, _, layout) => {
|
||||||
const shortName = layout
|
const shortName = layout
|
||||||
.match(/\(([A-Za-z]+)\)/);
|
.match(/\(([A-Za-z]+)\)/);
|
||||||
|
|
||||||
// @ts-expect-error
|
|
||||||
self.label = shortName ? shortName[1] : layout;
|
self.label = shortName ? shortName[1] : layout;
|
||||||
}).catch(print);
|
}).catch(print);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ export default () => {
|
||||||
const label = Label().hook(Network, (self) => {
|
const label = Label().hook(Network, (self) => {
|
||||||
if (Network.wifi.internet === 'connected' ||
|
if (Network.wifi.internet === 'connected' ||
|
||||||
Network.wifi.internet === 'connecting') {
|
Network.wifi.internet === 'connecting') {
|
||||||
self.label = Network.wifi.ssid;
|
self.label = Network.wifi.ssid || 'Unknown';
|
||||||
}
|
}
|
||||||
else if (Network.wired.internet === 'connected' ||
|
else if (Network.wired.internet === 'connected' ||
|
||||||
Network.wired.internet === 'connecting') {
|
Network.wired.internet === 'connecting') {
|
||||||
|
|
|
@ -26,6 +26,7 @@ const SysTrayItem = (item) => {
|
||||||
|
|
||||||
child: Icon({
|
child: Icon({
|
||||||
size: 24,
|
size: 24,
|
||||||
|
// @ts-expect-error
|
||||||
icon: item.bind('icon'),
|
icon: item.bind('icon'),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
|
@ -38,50 +39,39 @@ const SysTray = () => MenuBar({
|
||||||
},
|
},
|
||||||
|
|
||||||
setup: (self) => {
|
setup: (self) => {
|
||||||
/**
|
|
||||||
* @param {import('types/widget').default} _
|
|
||||||
* @param {string} id
|
|
||||||
*/
|
|
||||||
const addTray = (_, id) => {
|
|
||||||
const item = SystemTray.getItem(id);
|
|
||||||
|
|
||||||
if (self.attribute.items.has(id) || !item) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const w = SysTrayItem(item);
|
|
||||||
|
|
||||||
// Early return if item is in blocklist
|
|
||||||
if (!w) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.attribute.items.set(id, w);
|
|
||||||
self.child = w;
|
|
||||||
self.show_all();
|
|
||||||
// @ts-expect-error
|
|
||||||
w.child.reveal_child = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {import('types/widget').default} _
|
|
||||||
* @param {string} id
|
|
||||||
*/
|
|
||||||
const removeTray = (_, id) => {
|
|
||||||
if (!self.attribute.items.has(id)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.attribute.items.get(id).child.reveal_child = false;
|
|
||||||
timeout(REVEAL_DURATION, () => {
|
|
||||||
self.attribute.items.get(id).destroy();
|
|
||||||
self.attribute.items.delete(id);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
self
|
self
|
||||||
.hook(SystemTray, addTray, 'added')
|
.hook(SystemTray, (_, id) => {
|
||||||
.hook(SystemTray, removeTray, 'removed');
|
const item = SystemTray.getItem(id);
|
||||||
|
|
||||||
|
if (self.attribute.items.has(id) || !item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const w = SysTrayItem(item);
|
||||||
|
|
||||||
|
// Early return if item is in blocklist
|
||||||
|
if (!w) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.attribute.items.set(id, w);
|
||||||
|
self.child = w;
|
||||||
|
self.show_all();
|
||||||
|
// @ts-expect-error
|
||||||
|
w.child.reveal_child = true;
|
||||||
|
}, 'added')
|
||||||
|
|
||||||
|
.hook(SystemTray, (_, id) => {
|
||||||
|
if (!self.attribute.items.has(id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.attribute.items.get(id).child.reveal_child = false;
|
||||||
|
timeout(REVEAL_DURATION, () => {
|
||||||
|
self.attribute.items.get(id).destroy();
|
||||||
|
self.attribute.items.delete(id);
|
||||||
|
});
|
||||||
|
}, 'removed');
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -102,6 +92,7 @@ export default () => {
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
}).hook(SystemTray, (self) => {
|
}).hook(SystemTray, (self) => {
|
||||||
|
// @ts-expect-error
|
||||||
self.reveal_child = systray.get_children().length > 0;
|
self.reveal_child = systray.get_children().length > 0;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,8 +14,11 @@ const BarCloser = (variable) => Window({
|
||||||
child: EventBox({
|
child: EventBox({
|
||||||
on_hover: (self) => {
|
on_hover: (self) => {
|
||||||
variable.value = false;
|
variable.value = false;
|
||||||
// @ts-expect-error
|
const parent = self.get_parent();
|
||||||
self.get_parent().visible = false;
|
|
||||||
|
if (parent) {
|
||||||
|
parent.visible = false;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
child: Box({
|
child: Box({
|
||||||
|
@ -64,11 +67,11 @@ export default (props) => {
|
||||||
transition: 'slide_down',
|
transition: 'slide_down',
|
||||||
reveal_child: true,
|
reveal_child: true,
|
||||||
|
|
||||||
binds: [['revealChild', Revealed, 'value']],
|
}).bind('reveal_child', Revealed),
|
||||||
}),
|
|
||||||
|
|
||||||
Revealer({
|
Revealer({
|
||||||
binds: [['revealChild', Revealed, 'value', (v) => !v]],
|
reveal_child: Revealed.bind()
|
||||||
|
.transform((v) => !v),
|
||||||
|
|
||||||
child: EventBox({
|
child: EventBox({
|
||||||
on_hover: () => {
|
on_hover: () => {
|
||||||
|
|
|
@ -126,86 +126,100 @@ export default () => {
|
||||||
setup: false,
|
setup: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
setup: (self) => {
|
setup: /** @param {any} self */ (self) => {
|
||||||
self
|
self
|
||||||
.hook(Mpris, (overlay, bus_name) => {
|
.hook(Mpris,
|
||||||
const players = overlay.attribute.players;
|
/**
|
||||||
|
* @param {Overlay} overlay
|
||||||
|
* @param {string} bus_name
|
||||||
|
*/
|
||||||
|
(overlay, bus_name) => {
|
||||||
|
const players = overlay.attribute.players;
|
||||||
|
|
||||||
if (players.has(bus_name)) {
|
if (players.has(bus_name)) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sometimes the signal doesn't give the bus_name
|
|
||||||
if (!bus_name) {
|
|
||||||
const player = Mpris.players.find((p) => {
|
|
||||||
return !players.has(p.bus_name);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (player) {
|
|
||||||
bus_name = player.bus_name;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Get the one on top so we can move it up later
|
// Sometimes the signal doesn't give the bus_name
|
||||||
const previousFirst = overlay.attribute.list().at(-1);
|
if (!bus_name) {
|
||||||
|
const player = Mpris.players.find((p) => {
|
||||||
|
return !players.has(p.bus_name);
|
||||||
|
});
|
||||||
|
|
||||||
// Make the new player
|
if (player) {
|
||||||
const player = Mpris.getPlayer(bus_name);
|
bus_name = player.bus_name;
|
||||||
const Colors = Variable(null);
|
}
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!player) {
|
// Get the one on top so we can move it up later
|
||||||
return;
|
const previousFirst = overlay.attribute.list().at(-1);
|
||||||
}
|
|
||||||
|
|
||||||
players.set(
|
// Make the new player
|
||||||
bus_name,
|
const player = Mpris.getPlayer(bus_name);
|
||||||
// @ts-expect-error
|
const Colors = Variable(null);
|
||||||
PlayerBox(player, Colors, content.child),
|
|
||||||
);
|
|
||||||
overlay.overlays = Array.from(players.values())
|
|
||||||
.map((widget) => widget);
|
|
||||||
|
|
||||||
const includes = overlay.attribute
|
if (!player) {
|
||||||
.includesWidget(previousFirst);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Select favorite player at startup
|
players.set(
|
||||||
if (!overlay.attribute.setup && players.has(FAVE_PLAYER)) {
|
bus_name,
|
||||||
overlay.attribute.moveToTop(players.get(FAVE_PLAYER));
|
// @ts-expect-error
|
||||||
overlay.attribute.setup = true;
|
PlayerBox(player, Colors, content.child),
|
||||||
}
|
);
|
||||||
|
overlay.overlays = Array.from(players.values())
|
||||||
|
.map((widget) => widget);
|
||||||
|
|
||||||
// Move previousFirst on top again
|
const includes = overlay.attribute
|
||||||
else if (includes) {
|
.includesWidget(previousFirst);
|
||||||
overlay.attribute.moveToTop(previousFirst);
|
|
||||||
}
|
|
||||||
}, 'player-added')
|
|
||||||
|
|
||||||
.hook(Mpris, (overlay, bus_name) => {
|
// Select favorite player at startup
|
||||||
const players = overlay.attribute.players;
|
const attrs = overlay.attribute;
|
||||||
|
|
||||||
if (!bus_name || !players.has(bus_name)) {
|
if (!attrs.setup && players.has(FAVE_PLAYER)) {
|
||||||
return;
|
attrs.moveToTop(players.get(FAVE_PLAYER));
|
||||||
}
|
attrs.setup = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Get the one on top so we can move it up later
|
// Move previousFirst on top again
|
||||||
const previousFirst = overlay.attribute.list().at(-1);
|
else if (includes) {
|
||||||
|
attrs.moveToTop(previousFirst);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'player-added')
|
||||||
|
|
||||||
// Remake overlays without deleted one
|
.hook(Mpris,
|
||||||
players.delete(bus_name);
|
/**
|
||||||
overlay.overlays = Array.from(players.values())
|
* @param {Overlay} overlay
|
||||||
.map((widget) => widget);
|
* @param {string} bus_name
|
||||||
|
*/
|
||||||
|
(overlay, bus_name) => {
|
||||||
|
const players = overlay.attribute.players;
|
||||||
|
|
||||||
// Move previousFirst on top again
|
if (!bus_name || !players.has(bus_name)) {
|
||||||
const includes = overlay.attribute
|
return;
|
||||||
.includesWidget(previousFirst);
|
}
|
||||||
|
|
||||||
if (includes) {
|
// Get the one on top so we can move it up later
|
||||||
overlay.attribute.moveToTop(previousFirst);
|
const previousFirst = overlay.attribute.list().at(-1);
|
||||||
}
|
|
||||||
}, 'player-closed');
|
// Remake overlays without deleted one
|
||||||
|
players.delete(bus_name);
|
||||||
|
overlay.overlays = Array.from(players.values())
|
||||||
|
.map((widget) => widget);
|
||||||
|
|
||||||
|
// Move previousFirst on top again
|
||||||
|
const includes = overlay.attribute
|
||||||
|
.includesWidget(previousFirst);
|
||||||
|
|
||||||
|
if (includes) {
|
||||||
|
overlay.attribute.moveToTop(previousFirst);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'player-closed');
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ export default ({
|
||||||
|
|
||||||
get_child: () => widget.child,
|
get_child: () => widget.child,
|
||||||
|
|
||||||
|
/** @param {import('types/widget').Widget} new_child */
|
||||||
set_child: (new_child) => {
|
set_child: (new_child) => {
|
||||||
widget.child = new_child;
|
widget.child = new_child;
|
||||||
},
|
},
|
||||||
|
|
|
@ -3,16 +3,15 @@ const { get_home_dir } = imports.gi.GLib;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} Persist
|
* @param {{
|
||||||
* @property {string} name
|
* name: string
|
||||||
* @property {typeof imports.gi.GObject} gobject
|
* gobject: typeof imports.gi.GObject
|
||||||
* @property {string} prop
|
* prop: string
|
||||||
* @property {boolean|string=} condition - if string, compare following props to this
|
* condition?: boolean|string // if string, compare following props to this
|
||||||
* @property {boolean|string=} whenTrue
|
* whenTrue?: boolean|string
|
||||||
* @property {boolean|string=} whenFalse
|
* whenFalse?: boolean|string
|
||||||
* @property {string=} signal
|
* signal?: string
|
||||||
*
|
* }} o
|
||||||
* @param {Persist} props
|
|
||||||
*/
|
*/
|
||||||
export default ({
|
export default ({
|
||||||
name,
|
name,
|
||||||
|
|
|
@ -68,9 +68,10 @@ export default ({
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
get_child: () => window.child.children[0].child,
|
get_child: () => window.child.children[0].child,
|
||||||
|
|
||||||
set_child: (newChild) => {
|
/** @param {import('types/widget').Widget} new_child */
|
||||||
|
set_child: (new_child) => {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
window.child.children[0].child = newChild;
|
window.child.children[0].child = new_child;
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
window.child.children[0].show_all();
|
window.child.children[0].show_all();
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue