nixos-configs/devices/wim/config/ags/js/osd/ctor.js

49 lines
1.3 KiB
JavaScript
Raw Normal View History

import { Box, Icon, ProgressBar } from 'resource:///com/github/Aylur/ags/widget.js';
const Y_POS = 80;
2023-12-21 01:25:59 -05:00
export default ({ stack, icon, info }) => {
let connectFunc;
const osd = Box({
css: `margin-bottom: ${Y_POS}px;`,
children: [Box({
2023-12-21 01:25:59 -05:00
class_name: 'osd',
children: [
Icon({
hpack: 'start',
// Can take a string or an object of props
...(typeof icon === 'string' ? { icon } : icon),
}),
// Can take a static widget instead of a progressbar
info.logic ?
ProgressBar({ vpack: 'center' }) :
info.widget,
],
})],
});
// Handle requests to show the OSD
// Different wether it's a bar or static
if (info.logic) {
2023-12-21 01:25:59 -05:00
/**
* @param {import('types/widgets/box').default} self
* @returns {Promise<void>}
*/
connectFunc = (self) => new Promise((r) => {
info.logic(self);
2023-12-21 01:25:59 -05:00
// @ts-expect-error
r();
2023-12-21 01:25:59 -05:00
}).then(() => stack.attribute.popup(osd));
}
else {
2023-12-21 01:25:59 -05:00
connectFunc = () => stack.attribute.popup(osd);
}
2023-12-21 01:25:59 -05:00
// @ts-expect-error
osd.children[0].children[1].hook(info.mod, connectFunc, info.signal);
return osd;
};