2024-01-30 11:29:07 -05:00
|
|
|
const { Box, Icon, ProgressBar } = Widget;
|
2023-11-27 22:02:28 -05:00
|
|
|
|
|
|
|
const Y_POS = 80;
|
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
// Types
|
2024-02-27 16:55:01 -05:00
|
|
|
import { ConnectFunc, OSD } from 'global-types';
|
2024-01-13 11:15:08 -05:00
|
|
|
|
2023-11-27 22:02:28 -05:00
|
|
|
|
2024-02-27 16:55:01 -05:00
|
|
|
export default ({ name, stack, icon, info }: OSD) => {
|
2024-01-13 11:15:08 -05:00
|
|
|
let connectFunc: ConnectFunc;
|
2024-02-27 16:55:01 -05:00
|
|
|
const status = info.widget ?
|
|
|
|
info.widget :
|
|
|
|
ProgressBar({ vpack: 'center' });
|
2023-11-27 22:02:28 -05:00
|
|
|
|
2024-02-27 16:55:01 -05:00
|
|
|
// Wrapper to get sliding up anim
|
2023-11-27 22:02:28 -05:00
|
|
|
const osd = Box({
|
2024-02-27 16:55:01 -05:00
|
|
|
name,
|
2023-11-27 22:02:28 -05:00
|
|
|
css: `margin-bottom: ${Y_POS}px;`,
|
2024-02-27 16:55:01 -05:00
|
|
|
children: [
|
|
|
|
// Actual OSD
|
|
|
|
Box({
|
|
|
|
class_name: 'osd',
|
|
|
|
children: [
|
|
|
|
Icon({
|
|
|
|
hpack: 'start',
|
|
|
|
icon,
|
|
|
|
}),
|
|
|
|
status,
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
2023-11-27 22:02:28 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
2023-11-27 22:02:28 -05:00
|
|
|
r();
|
2024-02-27 16:55:01 -05:00
|
|
|
}).then(() => stack.attribute.popup(name));
|
2023-11-27 22:02:28 -05:00
|
|
|
}
|
|
|
|
else {
|
2024-02-27 16:55:01 -05:00
|
|
|
connectFunc = () => stack.attribute.popup(name);
|
2023-11-27 22:02:28 -05:00
|
|
|
}
|
|
|
|
|
2024-02-27 16:55:01 -05:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2023-11-27 22:02:28 -05:00
|
|
|
|
|
|
|
return osd;
|
|
|
|
};
|