refactor(ags): update typechecking to match latest types

This commit is contained in:
matt1432 2023-12-19 13:44:12 -05:00
parent a126d97bbf
commit ae615b08f5
13 changed files with 142 additions and 139 deletions

View file

@ -7,9 +7,7 @@ import { lookUpIcon } from 'resource:///com/github/Aylur/ags/utils.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) => {
const icon = Icon({ size: 42 });
const iconString = app.app.get_string('Icon');

View file

@ -23,10 +23,9 @@ const Applauncher = ({ window_name = 'applauncher' } = {}) => {
});
fzfResults = fzf.find(text);
// @ts-expect-error
list.set_sort_func((a, b) => {
// @ts-expect-error
const row1 = a.get_children()[0]?.attribute.app.name;
// @ts-expect-error
const row2 = b.get_children()[0]?.attribute.app.name;
if (!row1 || !row2) {
@ -39,7 +38,8 @@ const Applauncher = ({ window_name = 'applauncher' } = {}) => {
};
const makeNewChildren = () => {
list.get_children().forEach((ch) => {
// @ts-expect-error
Array.from(list.get_children()).forEach((ch) => {
ch.destroy();
});
@ -47,6 +47,7 @@ const Applauncher = ({ window_name = 'applauncher' } = {}) => {
.flatMap((app) => AppItem(app));
children.forEach((ch) => {
// @ts-expect-error
list.add(ch);
});
list.show_all();
@ -84,11 +85,10 @@ const Applauncher = ({ window_name = 'applauncher' } = {}) => {
setSort(text);
let visibleApps = 0;
list.get_children().forEach((row) => {
// @ts-expect-error
// @ts-expect-error
Array.from(list.get_children()).forEach((row) => {
row.changed();
// @ts-expect-error
const item = row.get_children()[0];
if (item?.attribute.app) {

View file

@ -14,7 +14,6 @@ export default () => Box({
children: [
Icon({
class_name: 'battery-indicator',
// @ts-expect-error
icon: Battery.bind('icon_name'),
}).hook(Battery, (self) => {
self.toggleClassName('charging', Battery.charging);

View file

@ -8,7 +8,6 @@ const SPACING = 5;
export default () => {
const icon = Icon({
// @ts-expect-error
icon: Brightness.bind('screenIcon'),
});

View file

@ -17,7 +17,7 @@ export default () => Box({
.query(Hyprland.active.client.class)[0];
if (app) {
self.icon = app.icon_name;
self.icon = app.icon_name || '';
self.visible = Hyprland.active.client.title !== '';
}
}),

View file

@ -9,7 +9,7 @@ const SPACING = 4;
/**
* @param {Label} self
* @param {import('types/widgets/label').default} self
* @param {string} layout
* @param {string} _
*/
@ -21,7 +21,6 @@ const getKbdLayout = (self, _, layout) => {
const shortName = layout.match(/\(([A-Za-z]+)\)/);
// @ts-expect-error
self.label = shortName ? shortName[1] : layout;
}
else {
@ -35,7 +34,6 @@ const getKbdLayout = (self, _, layout) => {
const shortName = layout
.match(/\(([A-Za-z]+)\)/);
// @ts-expect-error
self.label = shortName ? shortName[1] : layout;
}).catch(print);
}

View file

@ -25,7 +25,7 @@ export default () => {
const label = Label().hook(Network, (self) => {
if (Network.wifi.internet === 'connected' ||
Network.wifi.internet === 'connecting') {
self.label = Network.wifi.ssid;
self.label = Network.wifi.ssid || 'Unknown';
}
else if (Network.wired.internet === 'connected' ||
Network.wired.internet === 'connecting') {

View file

@ -26,6 +26,7 @@ const SysTrayItem = (item) => {
child: Icon({
size: 24,
// @ts-expect-error
icon: item.bind('icon'),
}),
}),
@ -38,50 +39,39 @@ const SysTray = () => MenuBar({
},
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
.hook(SystemTray, addTray, 'added')
.hook(SystemTray, removeTray, 'removed');
.hook(SystemTray, (_, 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;
}, '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) => {
// @ts-expect-error
self.reveal_child = systray.get_children().length > 0;
});
};

View file

@ -14,8 +14,11 @@ const BarCloser = (variable) => Window({
child: EventBox({
on_hover: (self) => {
variable.value = false;
// @ts-expect-error
self.get_parent().visible = false;
const parent = self.get_parent();
if (parent) {
parent.visible = false;
}
},
child: Box({
@ -64,11 +67,11 @@ export default (props) => {
transition: 'slide_down',
reveal_child: true,
binds: [['revealChild', Revealed, 'value']],
}),
}).bind('reveal_child', Revealed),
Revealer({
binds: [['revealChild', Revealed, 'value', (v) => !v]],
reveal_child: Revealed.bind()
.transform((v) => !v),
child: EventBox({
on_hover: () => {

View file

@ -126,86 +126,100 @@ export default () => {
setup: false,
},
setup: (self) => {
setup: /** @param {any} self */ (self) => {
self
.hook(Mpris, (overlay, bus_name) => {
const players = overlay.attribute.players;
.hook(Mpris,
/**
* @param {Overlay} overlay
* @param {string} bus_name
*/
(overlay, bus_name) => {
const players = overlay.attribute.players;
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 {
if (players.has(bus_name)) {
return;
}
}
// Get the one on top so we can move it up later
const previousFirst = overlay.attribute.list().at(-1);
// Sometimes the signal doesn't give the bus_name
if (!bus_name) {
const player = Mpris.players.find((p) => {
return !players.has(p.bus_name);
});
// Make the new player
const player = Mpris.getPlayer(bus_name);
const Colors = Variable(null);
if (player) {
bus_name = player.bus_name;
}
else {
return;
}
}
if (!player) {
return;
}
// Get the one on top so we can move it up later
const previousFirst = overlay.attribute.list().at(-1);
players.set(
bus_name,
// @ts-expect-error
PlayerBox(player, Colors, content.child),
);
overlay.overlays = Array.from(players.values())
.map((widget) => widget);
// Make the new player
const player = Mpris.getPlayer(bus_name);
const Colors = Variable(null);
const includes = overlay.attribute
.includesWidget(previousFirst);
if (!player) {
return;
}
// Select favorite player at startup
if (!overlay.attribute.setup && players.has(FAVE_PLAYER)) {
overlay.attribute.moveToTop(players.get(FAVE_PLAYER));
overlay.attribute.setup = true;
}
players.set(
bus_name,
// @ts-expect-error
PlayerBox(player, Colors, content.child),
);
overlay.overlays = Array.from(players.values())
.map((widget) => widget);
// Move previousFirst on top again
else if (includes) {
overlay.attribute.moveToTop(previousFirst);
}
}, 'player-added')
const includes = overlay.attribute
.includesWidget(previousFirst);
.hook(Mpris, (overlay, bus_name) => {
const players = overlay.attribute.players;
// Select favorite player at startup
const attrs = overlay.attribute;
if (!bus_name || !players.has(bus_name)) {
return;
}
if (!attrs.setup && players.has(FAVE_PLAYER)) {
attrs.moveToTop(players.get(FAVE_PLAYER));
attrs.setup = true;
}
// Get the one on top so we can move it up later
const previousFirst = overlay.attribute.list().at(-1);
// Move previousFirst on top again
else if (includes) {
attrs.moveToTop(previousFirst);
}
},
'player-added')
// Remake overlays without deleted one
players.delete(bus_name);
overlay.overlays = Array.from(players.values())
.map((widget) => widget);
.hook(Mpris,
/**
* @param {Overlay} overlay
* @param {string} bus_name
*/
(overlay, bus_name) => {
const players = overlay.attribute.players;
// Move previousFirst on top again
const includes = overlay.attribute
.includesWidget(previousFirst);
if (!bus_name || !players.has(bus_name)) {
return;
}
if (includes) {
overlay.attribute.moveToTop(previousFirst);
}
}, 'player-closed');
// Get the one on top so we can move it up later
const previousFirst = overlay.attribute.list().at(-1);
// 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');
},
});

View file

@ -35,6 +35,7 @@ export default ({
get_child: () => widget.child,
/** @param {import('types/widget').Widget} new_child */
set_child: (new_child) => {
widget.child = new_child;
},

View file

@ -3,16 +3,15 @@ const { get_home_dir } = imports.gi.GLib;
/**
* @typedef {Object} Persist
* @property {string} name
* @property {typeof imports.gi.GObject} gobject
* @property {string} prop
* @property {boolean|string=} condition - if string, compare following props to this
* @property {boolean|string=} whenTrue
* @property {boolean|string=} whenFalse
* @property {string=} signal
*
* @param {Persist} props
* @param {{
* name: string
* gobject: typeof imports.gi.GObject
* prop: string
* condition?: boolean|string // if string, compare following props to this
* whenTrue?: boolean|string
* whenFalse?: boolean|string
* signal?: string
* }} o
*/
export default ({
name,

View file

@ -68,9 +68,10 @@ export default ({
// @ts-expect-error
get_child: () => window.child.children[0].child,
set_child: (newChild) => {
/** @param {import('types/widget').Widget} new_child */
set_child: (new_child) => {
// @ts-expect-error
window.child.children[0].child = newChild;
window.child.children[0].child = new_child;
// @ts-expect-error
window.child.children[0].show_all();
},