nixos-configs/devices/wim/config/ags/ts/osd/main.ts

66 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-11-10 23:51:50 -05:00
import App from 'resource:///com/github/Aylur/ags/app.js';
2023-11-10 23:51:50 -05:00
import { timeout } from 'resource:///com/github/Aylur/ags/utils.js';
import { Stack } from 'resource:///com/github/Aylur/ags/widget.js';
import PopupWindow from '../misc/popup.js';
2024-01-13 11:15:08 -05:00
import AgsBox from 'types/widgets/box.js';
import AgsStack from 'types/widgets/stack.js';
2023-11-10 23:51:50 -05:00
// Import all the OSDs as an array
2024-01-13 11:15:08 -05:00
const OSDList = [] as Array<(stack: AgsStack) => AgsBox>;
import * as Modules from './osds.js';
for (const osd in Modules) {
OSDList.push(Modules[osd]);
} // Array
2023-11-10 23:51:50 -05:00
const HIDE_DELAY = 2000;
const transition_duration = 300;
2023-11-10 23:51:50 -05:00
const OSDs = () => {
2023-11-10 23:51:50 -05:00
const stack = Stack({
transition: 'over_up_down',
transition_duration,
2023-12-21 01:25:59 -05:00
2024-01-13 11:15:08 -05:00
attribute: { popup: () => {/**/} },
2023-11-10 23:51:50 -05:00
});
2023-12-23 01:14:21 -05:00
// Send reference of stack to all items
stack.items = OSDList.map((osd, i) => [`${i}`, osd(stack)]);
// Delay popup method so it
// doesn't show any OSDs at launch
timeout(1000, () => {
let count = 0;
2023-11-10 23:51:50 -05:00
2024-01-13 11:15:08 -05:00
stack.attribute.popup = (osd: AgsBox) => {
++count;
stack.set_visible_child(osd);
App.openWindow('osd');
2023-11-10 23:51:50 -05:00
timeout(HIDE_DELAY, () => {
--count;
2023-11-10 23:51:50 -05:00
if (count === 0) {
App.closeWindow('osd');
}
});
};
});
return stack;
2023-11-10 23:51:50 -05:00
};
export default () => PopupWindow({
name: 'osd',
anchor: ['bottom'],
exclusivity: 'ignore',
close_on_unfocus: 'stay',
transition: 'slide_up',
transition_duration,
bezier: 'ease',
child: OSDs(),
});