ai-battery 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -14
- package/bin/ai-battery-macos-rail.applescript +227 -0
- package/bin/ai-battery-macos-status.applescript +5 -12
- package/bin/ai-battery-run +701 -31
- package/bin/ai-battery-tmux.js +17 -0
- package/bin/terminal-compositor.js +111 -0
- package/docs/REFERENCE.md +23 -3
- package/docs/RELEASING.md +30 -7
- package/docs/WINDOWS-TERMINAL-SHARED-BAR.md +74 -0
- package/docs/hud-preview.svg +75 -20
- package/docs/terminal-vertical-preview.svg +73 -0
- package/lib/cli.js +1148 -240
- package/lib/core/atomic-rename.js +18 -0
- package/lib/core/cli-help.js +57 -12
- package/lib/core/cli-messages.js +45 -1
- package/lib/core/cli-output.js +277 -72
- package/lib/core/cli-wrappers.js +410 -0
- package/lib/core/config-editor.js +194 -29
- package/lib/core/display-config.js +45 -0
- package/lib/core/integration-files.js +32 -3
- package/lib/core/shared-bar.js +603 -0
- package/lib/core/statusline-git.js +179 -15
- package/lib/core/terminal.js +25 -7
- package/lib/core/tmux-status.js +172 -0
- package/lib/core/uninstall.js +20 -7
- package/lib/core/usage-store.js +85 -0
- package/lib/hud/launcher.js +32 -33
- package/lib/platforms/linux/gnome-extension/extension.js +7 -6
- package/lib/platforms/linux/hud.js +157 -42
- package/lib/platforms/linux/panel.js +16 -3
- package/lib/platforms/linux/rail.js +412 -0
- package/lib/platforms/macos/hud.js +152 -44
- package/lib/platforms/process-scanner.js +77 -29
- package/lib/platforms/windows/autostart-cleanup.js +1 -1
- package/lib/platforms/windows/codex-runner.js +178 -21
- package/lib/platforms/windows/hud/controls.ps1 +65 -15
- package/lib/platforms/windows/hud/main.ps1 +715 -54
- package/lib/platforms/windows/hud/rendering.ps1 +1284 -2
- package/lib/platforms/windows/hud/snapshot.ps1 +26 -46
- package/lib/platforms/windows/hud-launcher.js +234 -81
- package/lib/platforms/windows/shared-bar-platform.js +972 -0
- package/lib/platforms/windows/terminal-compositor.js +210 -25
- package/lib/platforms/windows/wt-bar.js +729 -0
- package/lib/platforms/windows/wt-fragment.js +665 -0
- package/lib/platforms/windows/wt-keybinding.js +300 -0
- package/lib/providers/antigravity.js +155 -8
- package/package.json +6 -2
- package/vendor/PaneContext.cs +875 -0
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
// Native GJS floating vertical rail HUD: GTK3 owns the window, Node owns usage scans.
|
|
2
|
+
import Cairo from "cairo";
|
|
3
|
+
import Gio from "gi://Gio";
|
|
4
|
+
import GLib from "gi://GLib";
|
|
5
|
+
|
|
6
|
+
const value = (name, fallback = "") => {
|
|
7
|
+
const index = ARGV.indexOf(name);
|
|
8
|
+
return index >= 0 ? ARGV[index + 1] : fallback;
|
|
9
|
+
};
|
|
10
|
+
const busName = value("--bus-name");
|
|
11
|
+
const controlPath = "/org/hnode/AiBattery/Hud";
|
|
12
|
+
const controlInterface = "org.hnode.AiBattery.Hud";
|
|
13
|
+
const env = Object.fromEntries(["LANGUAGE", "LC_ALL", "LC_MESSAGES", "LANG"].map(name => [name, GLib.getenv(name)]));
|
|
14
|
+
|
|
15
|
+
function railLanguage(vars) {
|
|
16
|
+
const explicit = Boolean(vars.LANGUAGE?.trim());
|
|
17
|
+
const candidates = explicit
|
|
18
|
+
? vars.LANGUAGE.split(":")
|
|
19
|
+
: [vars.LC_ALL || vars.LC_MESSAGES || vars.LANG || "", ...(GLib.get_language_names?.() || [])];
|
|
20
|
+
for (const candidate of candidates) {
|
|
21
|
+
const base = String(candidate || "").trim().toLowerCase().split(/[_@.\-]/)[0];
|
|
22
|
+
if (base === "ko") return "ko";
|
|
23
|
+
if (base === "en") return "en";
|
|
24
|
+
if (["c", "posix"].includes(base) && explicit) return "en";
|
|
25
|
+
}
|
|
26
|
+
return "en";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const language = railLanguage(env);
|
|
30
|
+
const t = (english, korean) => language === "ko" ? korean : english;
|
|
31
|
+
const encode = text => new TextEncoder().encode(text);
|
|
32
|
+
const clampScale = s => Math.max(0.5, Math.min(3.0, Math.round((Number(s) || 1) * 100) / 100));
|
|
33
|
+
|
|
34
|
+
let Gtk;
|
|
35
|
+
let Gdk;
|
|
36
|
+
let GdkPixbuf;
|
|
37
|
+
let GLibUnix;
|
|
38
|
+
|
|
39
|
+
async function main() {
|
|
40
|
+
try {
|
|
41
|
+
const giGtk = await import("gi://Gtk?version=3.0");
|
|
42
|
+
const giGdk = await import("gi://Gdk?version=3.0");
|
|
43
|
+
Gtk = giGtk.default;
|
|
44
|
+
Gdk = giGdk.default;
|
|
45
|
+
({ default: GdkPixbuf } = await import("gi://GdkPixbuf?version=2.0"));
|
|
46
|
+
try { ({ default: GLibUnix } = await import("gi://GLibUnix?version=2.0")); } catch { /* Older GLib exports signal_add on GLib. */ }
|
|
47
|
+
let sessionAvailable = true;
|
|
48
|
+
try {
|
|
49
|
+
Gio.bus_get_sync(Gio.BusType.SESSION, null);
|
|
50
|
+
} catch {
|
|
51
|
+
sessionAvailable = false;
|
|
52
|
+
}
|
|
53
|
+
const displayAvailable = Boolean(GLib.getenv("DISPLAY") || GLib.getenv("WAYLAND_DISPLAY"));
|
|
54
|
+
if (ARGV.includes("--probe")) {
|
|
55
|
+
print(JSON.stringify({ sessionAvailable, displayAvailable }));
|
|
56
|
+
} else if (!sessionAvailable || !displayAvailable) {
|
|
57
|
+
throw new Error("No graphical desktop session");
|
|
58
|
+
} else {
|
|
59
|
+
runRail();
|
|
60
|
+
}
|
|
61
|
+
} catch (error) {
|
|
62
|
+
printerr(`ai-battery-hud: ${error.message}`);
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const controlXml = `<node><interface name="org.hnode.AiBattery.Hud">
|
|
68
|
+
<method name="GetStatus"><arg type="s" direction="out"/></method>
|
|
69
|
+
<method name="Refresh"/><method name="Quit"/>
|
|
70
|
+
</interface></node>`;
|
|
71
|
+
|
|
72
|
+
function runRail() {
|
|
73
|
+
Gtk.init(null);
|
|
74
|
+
const loop = new GLib.MainLoop(null, false);
|
|
75
|
+
const readyFile = value("--ready");
|
|
76
|
+
const interval = Math.max(1, Number(value("--interval", "2")) || 2);
|
|
77
|
+
const provider = value("--provider", "all");
|
|
78
|
+
let scale = clampScale(value("--scale", "1"));
|
|
79
|
+
const pid = new Gio.Credentials().get_unix_pid();
|
|
80
|
+
let snapshot = null;
|
|
81
|
+
let lastError = null;
|
|
82
|
+
let pixbuf = null;
|
|
83
|
+
let railImagePath = "";
|
|
84
|
+
let baseWidth = 44;
|
|
85
|
+
let baseHeight = 130;
|
|
86
|
+
let ready = false;
|
|
87
|
+
let busy = false;
|
|
88
|
+
let pending = false;
|
|
89
|
+
let timer = 0;
|
|
90
|
+
let subprocess = null;
|
|
91
|
+
let fastUntil = 0;
|
|
92
|
+
let owner = 0;
|
|
93
|
+
let controlExport = null;
|
|
94
|
+
|
|
95
|
+
const cssProvider = new Gtk.CssProvider();
|
|
96
|
+
cssProvider.load_from_data("window, window.background { background-color: transparent; background-image: none; border: none; box-shadow: none; }");
|
|
97
|
+
Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
|
|
98
|
+
|
|
99
|
+
const window = new Gtk.Window({ type: Gtk.WindowType.TOPLEVEL, title: "AI Battery" });
|
|
100
|
+
window.set_decorated(false);
|
|
101
|
+
window.set_app_paintable(true);
|
|
102
|
+
window.set_skip_taskbar_hint(true);
|
|
103
|
+
window.set_skip_pager_hint(true);
|
|
104
|
+
window.set_keep_above(true);
|
|
105
|
+
window.stick();
|
|
106
|
+
window.set_accept_focus(false);
|
|
107
|
+
window.set_resizable(false);
|
|
108
|
+
window.set_type_hint(Gdk.WindowTypeHint.UTILITY);
|
|
109
|
+
window.set_default_size(Math.round(baseWidth * scale), Math.round(baseHeight * scale));
|
|
110
|
+
|
|
111
|
+
const screen = window.get_screen();
|
|
112
|
+
const visual = screen?.get_rgba_visual();
|
|
113
|
+
if (visual) window.set_visual(visual);
|
|
114
|
+
|
|
115
|
+
window.connect("draw", (_widget, cr) => {
|
|
116
|
+
cr.setOperator(Cairo.Operator.SOURCE);
|
|
117
|
+
cr.setSourceRGBA(0, 0, 0, 0);
|
|
118
|
+
cr.paint();
|
|
119
|
+
return false;
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const display = Gdk.Display.get_default();
|
|
123
|
+
const monitor = display?.get_primary_monitor?.() || display?.get_monitor?.(0);
|
|
124
|
+
if (monitor) {
|
|
125
|
+
const workarea = monitor.get_workarea();
|
|
126
|
+
window.move(workarea.x + Math.max(0, workarea.width - Math.round(baseWidth * scale) - 14), workarea.y + 44);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const area = new Gtk.DrawingArea();
|
|
130
|
+
area.set_app_paintable(true);
|
|
131
|
+
area.set_size_request(Math.round(baseWidth * scale), Math.round(baseHeight * scale));
|
|
132
|
+
area.add_events(
|
|
133
|
+
Gdk.EventMask.BUTTON_PRESS_MASK
|
|
134
|
+
| Gdk.EventMask.BUTTON_RELEASE_MASK
|
|
135
|
+
| Gdk.EventMask.POINTER_MOTION_MASK
|
|
136
|
+
| Gdk.EventMask.LEAVE_NOTIFY_MASK
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
area.connect("draw", (_widget, cr) => {
|
|
140
|
+
cr.setOperator(Cairo.Operator.SOURCE);
|
|
141
|
+
cr.setSourceRGBA(0, 0, 0, 0);
|
|
142
|
+
cr.paint();
|
|
143
|
+
cr.setOperator(Cairo.Operator.OVER);
|
|
144
|
+
if (pixbuf) {
|
|
145
|
+
const deviceScale = Math.max(1, window.get_scale_factor?.() || 1);
|
|
146
|
+
cr.save();
|
|
147
|
+
cr.scale(1 / deviceScale, 1 / deviceScale);
|
|
148
|
+
Gdk.cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
|
|
149
|
+
cr.paint();
|
|
150
|
+
cr.restore();
|
|
151
|
+
}
|
|
152
|
+
return false;
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
function applyScale(nextScale) {
|
|
156
|
+
scale = clampScale(nextScale);
|
|
157
|
+
if (!railImagePath) return;
|
|
158
|
+
try {
|
|
159
|
+
const deviceScale = Math.max(1, window.get_scale_factor?.() || 1);
|
|
160
|
+
const targetW = Math.max(24, Math.round(baseWidth * scale));
|
|
161
|
+
const targetH = Math.max(32, Math.round(baseHeight * scale));
|
|
162
|
+
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(railImagePath, targetW * deviceScale, targetH * deviceScale, true);
|
|
163
|
+
area.set_size_request(targetW, targetH);
|
|
164
|
+
window.resize(targetW, targetH);
|
|
165
|
+
area.queue_draw();
|
|
166
|
+
} catch (error) {
|
|
167
|
+
lastError = error.message;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const menu = new Gtk.Menu();
|
|
172
|
+
const largerItem = new Gtk.MenuItem({ label: t("Larger (+)", "크게 (+)") });
|
|
173
|
+
largerItem.connect("activate", () => applyScale(scale + 0.15));
|
|
174
|
+
const smallerItem = new Gtk.MenuItem({ label: t("Smaller (-)", "작게 (-)") });
|
|
175
|
+
smallerItem.connect("activate", () => applyScale(scale - 0.15));
|
|
176
|
+
const resetSizeItem = new Gtk.MenuItem({ label: t("Reset Size (100%)", "기본 크기 (100%)") });
|
|
177
|
+
resetSizeItem.connect("activate", () => applyScale(1));
|
|
178
|
+
const sep = new Gtk.SeparatorMenuItem();
|
|
179
|
+
const refreshItem = new Gtk.MenuItem({ label: t("Refresh", "새로고침") });
|
|
180
|
+
refreshItem.connect("activate", () => {
|
|
181
|
+
fastUntil = GLib.get_monotonic_time() + 30e6;
|
|
182
|
+
refresh();
|
|
183
|
+
});
|
|
184
|
+
const quitItem = new Gtk.MenuItem({ label: t("Quit AI Battery", "AI Battery 종료") });
|
|
185
|
+
quitItem.connect("activate", quit);
|
|
186
|
+
menu.append(largerItem);
|
|
187
|
+
menu.append(smallerItem);
|
|
188
|
+
menu.append(resetSizeItem);
|
|
189
|
+
menu.append(sep);
|
|
190
|
+
menu.append(refreshItem);
|
|
191
|
+
menu.append(quitItem);
|
|
192
|
+
menu.show_all();
|
|
193
|
+
|
|
194
|
+
let resizeDrag = null;
|
|
195
|
+
|
|
196
|
+
function cornerAt(x, y, w, h) {
|
|
197
|
+
const zone = Math.max(6, Math.min(12, Math.floor(Math.min(w, h) / 4)));
|
|
198
|
+
const left = x < zone;
|
|
199
|
+
const right = x >= w - zone;
|
|
200
|
+
const top = y < zone;
|
|
201
|
+
const bottom = y >= h - zone;
|
|
202
|
+
if (top && left) return "nw";
|
|
203
|
+
if (top && right) return "ne";
|
|
204
|
+
if (bottom && left) return "sw";
|
|
205
|
+
if (bottom && right) return "se";
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function setCornerCursor(corner) {
|
|
210
|
+
const gdkWin = area.get_window();
|
|
211
|
+
if (!gdkWin || !display) return;
|
|
212
|
+
if (!corner) {
|
|
213
|
+
gdkWin.set_cursor(null);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const name = corner === "nw" || corner === "se" ? "nwse-resize" : "nesw-resize";
|
|
217
|
+
gdkWin.set_cursor(Gdk.Cursor.new_from_name(display, name));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
area.connect("button-press-event", (_widget, event) => {
|
|
221
|
+
const [, button] = event.get_button();
|
|
222
|
+
if (button === 1) {
|
|
223
|
+
const [, x, y] = event.get_coords();
|
|
224
|
+
const [, xRoot, yRoot] = event.get_root_coords();
|
|
225
|
+
const [curW, curH] = window.get_size();
|
|
226
|
+
const corner = cornerAt(x, y, curW, curH);
|
|
227
|
+
if (corner) {
|
|
228
|
+
const [winX, winY] = window.get_position();
|
|
229
|
+
resizeDrag = { corner, startX: xRoot, startY: yRoot, startScale: scale, startWinX: winX, startWinY: winY, startW: curW, startH: curH };
|
|
230
|
+
setCornerCursor(corner);
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
window.begin_move_drag(button, Math.round(xRoot), Math.round(yRoot), event.get_time());
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
if (button === 3) {
|
|
237
|
+
menu.popup_at_pointer(event);
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
return false;
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
area.connect("button-release-event", (_widget, event) => {
|
|
244
|
+
const [, button] = event.get_button();
|
|
245
|
+
if (button === 1 && resizeDrag) {
|
|
246
|
+
resizeDrag = null;
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
return false;
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
area.connect("motion-notify-event", (_widget, event) => {
|
|
253
|
+
if (resizeDrag) {
|
|
254
|
+
const [, xRoot, yRoot] = event.get_root_coords();
|
|
255
|
+
const dx = xRoot - resizeDrag.startX;
|
|
256
|
+
const dy = yRoot - resizeDrag.startY;
|
|
257
|
+
const sx = resizeDrag.corner.includes("w") ? -dx : dx;
|
|
258
|
+
const sy = resizeDrag.corner.includes("n") ? -dy : dy;
|
|
259
|
+
const deltaW = (sx + (sy * (baseWidth / baseHeight))) / 2;
|
|
260
|
+
const nextScale = clampScale(resizeDrag.startScale * ((resizeDrag.startW + deltaW) / resizeDrag.startW));
|
|
261
|
+
applyScale(nextScale);
|
|
262
|
+
const [newW, newH] = window.get_size();
|
|
263
|
+
const nextX = resizeDrag.corner.includes("w") ? resizeDrag.startWinX + (resizeDrag.startW - newW) : resizeDrag.startWinX;
|
|
264
|
+
const nextY = resizeDrag.corner.includes("n") ? resizeDrag.startWinY + (resizeDrag.startH - newH) : resizeDrag.startWinY;
|
|
265
|
+
if (resizeDrag.corner.includes("w") || resizeDrag.corner.includes("n")) {
|
|
266
|
+
window.move(Math.round(nextX), Math.round(nextY));
|
|
267
|
+
}
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
270
|
+
const [, x, y] = event.get_coords();
|
|
271
|
+
const [curW, curH] = window.get_size();
|
|
272
|
+
setCornerCursor(cornerAt(x, y, curW, curH));
|
|
273
|
+
return false;
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
area.connect("leave-notify-event", () => {
|
|
277
|
+
if (!resizeDrag) setCornerCursor(null);
|
|
278
|
+
return false;
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
window.connect("delete-event", () => {
|
|
282
|
+
quit();
|
|
283
|
+
return true;
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
window.add(area);
|
|
287
|
+
window.show_all();
|
|
288
|
+
window.set_keep_above(true);
|
|
289
|
+
|
|
290
|
+
function maybeReady() {
|
|
291
|
+
if (snapshot && !ready && readyFile) {
|
|
292
|
+
GLib.file_set_contents(readyFile, encode(JSON.stringify({ pid, busName, registered: true, presentation: "rail", scale })));
|
|
293
|
+
ready = true;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function nextInterval(state) {
|
|
298
|
+
const fast = Math.min(interval, 2);
|
|
299
|
+
if (GLib.get_monotonic_time() < fastUntil || state === "background-running") return fast;
|
|
300
|
+
return interval;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function schedule() {
|
|
304
|
+
if (timer) GLib.source_remove(timer);
|
|
305
|
+
timer = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, nextInterval(snapshot?.state), () => {
|
|
306
|
+
timer = 0;
|
|
307
|
+
refresh();
|
|
308
|
+
return GLib.SOURCE_REMOVE;
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function updateRail(data) {
|
|
313
|
+
if (data.railImage) {
|
|
314
|
+
try {
|
|
315
|
+
railImagePath = data.railImage;
|
|
316
|
+
const base = GdkPixbuf.Pixbuf.new_from_file(railImagePath);
|
|
317
|
+
baseWidth = Math.max(24, base.get_width());
|
|
318
|
+
baseHeight = Math.max(32, base.get_height());
|
|
319
|
+
applyScale(scale);
|
|
320
|
+
} catch (error) {
|
|
321
|
+
lastError = error.message;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function refresh() {
|
|
327
|
+
if (busy) { pending = true; return; }
|
|
328
|
+
if (timer) { GLib.source_remove(timer); timer = 0; }
|
|
329
|
+
busy = true;
|
|
330
|
+
try {
|
|
331
|
+
subprocess = Gio.Subprocess.new([value("--node"), value("--snapshot"), provider], Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_PIPE);
|
|
332
|
+
let timeout = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 12, () => {
|
|
333
|
+
timeout = 0; subprocess?.force_exit(); return GLib.SOURCE_REMOVE;
|
|
334
|
+
});
|
|
335
|
+
subprocess.communicate_utf8_async(null, null, (process, result) => {
|
|
336
|
+
if (timeout) GLib.source_remove(timeout);
|
|
337
|
+
try {
|
|
338
|
+
const [, stdout, stderr] = process.communicate_utf8_finish(result);
|
|
339
|
+
if (!process.get_successful()) throw new Error(stderr.trim() || "Usage scan failed");
|
|
340
|
+
const data = JSON.parse(stdout);
|
|
341
|
+
if (snapshot && snapshot.state !== data.state) fastUntil = GLib.get_monotonic_time() + 45e6;
|
|
342
|
+
lastError = null;
|
|
343
|
+
updateRail(data);
|
|
344
|
+
snapshot = data;
|
|
345
|
+
maybeReady();
|
|
346
|
+
} catch (error) {
|
|
347
|
+
lastError = error.message || String(error);
|
|
348
|
+
printerr(`ai-battery-hud: ${lastError}`);
|
|
349
|
+
} finally {
|
|
350
|
+
subprocess = null;
|
|
351
|
+
busy = false;
|
|
352
|
+
if (pending) { pending = false; refresh(); } else schedule();
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
} catch (error) {
|
|
356
|
+
busy = false;
|
|
357
|
+
lastError = error.message || String(error);
|
|
358
|
+
printerr(`ai-battery-hud: ${lastError}`);
|
|
359
|
+
schedule();
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function quit() {
|
|
364
|
+
GLib.idle_add(GLib.PRIORITY_DEFAULT, () => { loop.quit(); return GLib.SOURCE_REMOVE; });
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const controls = {
|
|
368
|
+
GetStatus() {
|
|
369
|
+
return JSON.stringify({
|
|
370
|
+
app: "ai-battery",
|
|
371
|
+
running: true,
|
|
372
|
+
pid,
|
|
373
|
+
registered: true,
|
|
374
|
+
presentation: "rail",
|
|
375
|
+
scale,
|
|
376
|
+
state: snapshot?.state || "loading",
|
|
377
|
+
updatedAt: snapshot?.generatedAt || null,
|
|
378
|
+
provider,
|
|
379
|
+
interval,
|
|
380
|
+
rows: snapshot?.rows || [],
|
|
381
|
+
error: lastError
|
|
382
|
+
});
|
|
383
|
+
},
|
|
384
|
+
Refresh: refresh,
|
|
385
|
+
Quit: quit
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
owner = Gio.bus_own_name(Gio.BusType.SESSION, busName, Gio.BusNameOwnerFlags.NONE,
|
|
389
|
+
connection => {
|
|
390
|
+
controlExport = Gio.DBusExportedObject.wrapJSObject(controlXml, controls);
|
|
391
|
+
controlExport.export(connection, controlPath);
|
|
392
|
+
},
|
|
393
|
+
() => {
|
|
394
|
+
refresh();
|
|
395
|
+
},
|
|
396
|
+
() => {
|
|
397
|
+
printerr("Linux HUD name unavailable or desktop session ended");
|
|
398
|
+
quit();
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
const signalAdd = GLibUnix?.signal_add || GLib.unix_signal_add;
|
|
402
|
+
signalAdd(GLib.PRIORITY_DEFAULT, 15, () => { quit(); return GLib.SOURCE_REMOVE; });
|
|
403
|
+
signalAdd(GLib.PRIORITY_DEFAULT, 2, () => { quit(); return GLib.SOURCE_REMOVE; });
|
|
404
|
+
loop.run();
|
|
405
|
+
if (timer) GLib.source_remove(timer);
|
|
406
|
+
subprocess?.force_exit();
|
|
407
|
+
Gio.bus_unown_name(owner);
|
|
408
|
+
controlExport?.unexport();
|
|
409
|
+
window.destroy();
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
await main();
|