-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.ts
36 lines (32 loc) · 1.13 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { timeout, Variable } from "astal";
import { App, Widget } from "astal/gtk3";
export const uptime = Variable("").poll(60_000, "cat /proc/uptime", (out) => {
const uptime = Number.parseInt(out.split('.')[0]) / 60;
if (uptime > 18 * 60)
return 'Go Sleep';
const h = Math.floor(uptime / 60);
const s = Math.floor(uptime % 60);
return `${h}:${s < 10 ? '0' + s : s}`;
});
export function toggleWindow(windowName: string, delay: number=300) {
const window = App.get_window(windowName);
if (window === null)
return
if (window.is_visible()) {
(window.get_child() as Widget.Revealer).revealChild = false;
timeout(delay, () => window.hide());
}
else {
window.show();
(window.get_child() as Widget.Revealer).revealChild = true;
}
}
export function hideWindow(windowName: string, delay: number=300) {
const window = App.get_window(windowName);
if (window === null)
return
if (window.is_visible()) {
(window.get_child() as Widget.Revealer).revealChild = false;
timeout(delay, () => window.hide());
}
}