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

64 lines
1.4 KiB
JavaScript
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';
// Import all the OSDs as an array
const OSDList = [];
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;
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',
2023-12-21 01:25:59 -05:00
transition_duration: 200,
attribute: {
popup: () => {/**/},
},
2023-11-10 23:51:50 -05:00
});
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
2023-12-21 01:25:59 -05:00
/** @param {import('types/widgets/box').default} osd */
stack.attribute.popup = (osd) => {
++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: 200,
child: OSDs(),
});