nixos-configs/nixosModules/ags/config/ts/osd/ctor.ts

63 lines
1.5 KiB
TypeScript
Raw Normal View History

const { Box, Icon, ProgressBar } = Widget;
const Y_POS = 80;
2024-01-13 11:15:08 -05:00
// Types
2024-02-27 18:27:47 -05:00
import { ConnectFunc, OSD, OSDStack } from 'global-types';
2024-01-13 11:15:08 -05:00
2024-02-27 18:27:47 -05:00
export default ({ name, icon, info }: OSD) => {
2024-01-13 11:15:08 -05:00
let connectFunc: ConnectFunc;
const status = info.widget ?
info.widget :
ProgressBar({ vpack: 'center' });
// Wrapper to get sliding up anim
const osd = Box({
name,
css: `margin-bottom: ${Y_POS}px;`,
children: [
// Actual OSD
Box({
class_name: 'osd',
children: [
Icon({
hpack: 'start',
icon,
}),
status,
],
}),
],
});
// Handle requests to show the OSD
// Different wether it's a bar or static
if (info.logic) {
2024-01-13 11:15:08 -05:00
connectFunc = (self) => new Promise<void>((r) => {
if (info.logic && self) {
info.logic(self);
}
r();
2024-02-27 18:27:47 -05:00
}).then(() => (osd.get_parent() as OSDStack)?.attribute?.popup(name))
.catch(console.error);
}
else {
2024-02-27 18:27:47 -05:00
connectFunc = () => (osd.get_parent() as OSDStack)
?.attribute?.popup(name);
}
if (info.signal) {
if (typeof info.signal === 'string') {
status.hook(info.mod, connectFunc, info.signal);
}
else {
info.signal.forEach((sig) => {
status.hook(info.mod, connectFunc, sig);
});
}
}
return osd;
};