nixos-configs/modules/ags/config/ts/osd/main.ts

69 lines
1.5 KiB
TypeScript
Raw Normal View History

const { timeout } = Utils;
const { Stack } = Widget;
2023-11-10 23:51:50 -05:00
import PopupWindow from '../misc/popup.ts';
2024-01-29 20:56:56 -05:00
// Types
import { BoxGeneric, StackGeneric } from 'global-types';
2023-11-10 23:51:50 -05:00
// Import all the OSDs as an array
2024-01-29 20:56:56 -05:00
const OSDList = [] as Array<(stack: StackGeneric) => BoxGeneric>;
import * as Modules from './osds.ts';
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-29 20:56:56 -05:00
attribute: { popup: (osd: BoxGeneric) => {
if (!osd) {
console.log();
}
2024-01-29 20:56:56 -05:00
} },
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-29 20:56:56 -05:00
stack.attribute.popup = (osd: BoxGeneric) => {
++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',
content: OSDs(),
});