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
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,11 +39,8 @@ const SysTray = () => MenuBar({
},
setup: (self) => {
/**
* @param {import('types/widget').default} _
* @param {string} id
*/
const addTray = (_, id) => {
self
.hook(SystemTray, (_, id) => {
const item = SystemTray.getItem(id);
if (self.attribute.items.has(id) || !item) {
@ -61,13 +59,9 @@ const SysTray = () => MenuBar({
self.show_all();
// @ts-expect-error
w.child.reveal_child = true;
};
}, 'added')
/**
* @param {import('types/widget').default} _
* @param {string} id
*/
const removeTray = (_, id) => {
.hook(SystemTray, (_, id) => {
if (!self.attribute.items.has(id)) {
return;
}
@ -77,11 +71,7 @@ const SysTray = () => MenuBar({
self.attribute.items.get(id).destroy();
self.attribute.items.delete(id);
});
};
self
.hook(SystemTray, addTray, 'added')
.hook(SystemTray, removeTray, 'removed');
}, '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,9 +126,14 @@ export default () => {
setup: false,
},
setup: (self) => {
setup: /** @param {any} self */ (self) => {
self
.hook(Mpris, (overlay, bus_name) => {
.hook(Mpris,
/**
* @param {Overlay} overlay
* @param {string} bus_name
*/
(overlay, bus_name) => {
const players = overlay.attribute.players;
if (players.has(bus_name)) {
@ -172,18 +177,26 @@ export default () => {
.includesWidget(previousFirst);
// Select favorite player at startup
if (!overlay.attribute.setup && players.has(FAVE_PLAYER)) {
overlay.attribute.moveToTop(players.get(FAVE_PLAYER));
overlay.attribute.setup = true;
const attrs = overlay.attribute;
if (!attrs.setup && players.has(FAVE_PLAYER)) {
attrs.moveToTop(players.get(FAVE_PLAYER));
attrs.setup = true;
}
// Move previousFirst on top again
else if (includes) {
overlay.attribute.moveToTop(previousFirst);
attrs.moveToTop(previousFirst);
}
}, 'player-added')
},
'player-added')
.hook(Mpris, (overlay, bus_name) => {
.hook(Mpris,
/**
* @param {Overlay} overlay
* @param {string} bus_name
*/
(overlay, bus_name) => {
const players = overlay.attribute.players;
if (!bus_name || !players.has(bus_name)) {
@ -205,7 +218,8 @@ export default () => {
if (includes) {
overlay.attribute.moveToTop(previousFirst);
}
}, 'player-closed');
},
'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();
},