ai-battery 0.1.14 → 0.1.15
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 +7 -2
- package/bin/ai-battery-hud.js +302 -56
- package/bin/ai-battery-hud.ps1 +140 -22
- package/bin/ai-battery-macos-status.applescript +81 -3
- package/bin/ai-battery.js +133 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@ Codex 86% │ 5h 18:09 │ 7d 82% ┃ Claude 4% │ 5h 18:10 │ 7d 71%
|
|
|
54
54
|
| `ai-battery setup codex` | 지원 | 지원 | 지원 | 지원 | Codex `[tui].status_line`을 맞추고, Windows는 `codex.cmd` wrapper, WSL/Linux/macOS는 POSIX shell wrapper를 설치합니다. |
|
|
55
55
|
| `ai-battery hud` | 지원 | 지원 | 미지원 | 지원 | Windows/WSL은 PowerShell/WinForms HUD, macOS는 menu bar status item입니다. |
|
|
56
56
|
|
|
57
|
-
실행 중
|
|
57
|
+
실행 중 감지는 Linux/WSL은 `/proc`, macOS는 `ps`, Windows는 PowerShell 프로세스 목록을 사용합니다. 텍스트 출력은 흰색/회색으로, macOS HUD는 실행 중인 항목만 색상 배터리바로 강조하고 비실행 항목은 흐린 회색 계열로 표시합니다.
|
|
58
58
|
|
|
59
59
|
## Install
|
|
60
60
|
|
|
@@ -247,7 +247,7 @@ Claude가 한 번 이상 statusLine payload를 전달해야 Claude의 사용량
|
|
|
247
247
|
|
|
248
248
|
## Desktop HUD
|
|
249
249
|
|
|
250
|
-
일반 터미널 위에 외부 프로세스가 안전하게 status line을 덧그리는 방식은 안정적이지 않습니다. 그래서 Windows에서는 floating overlay를, macOS에서는 상단 menu bar status item을 제공합니다. Windows native에서는 WSL 없이 PowerShell/WinForms로 바로 실행되고, WSL에서는 `powershell.exe`를 통해 같은 HUD를 띄웁니다. macOS에서는 투명 배경의 작은 SVG 이미지로 Codex와 Claude 로고, 짧은 미터,
|
|
250
|
+
일반 터미널 위에 외부 프로세스가 안전하게 status line을 덧그리는 방식은 안정적이지 않습니다. 그래서 Windows에서는 floating overlay를, macOS에서는 상단 menu bar status item을 제공합니다. Windows native에서는 WSL 없이 PowerShell/WinForms로 바로 실행되고, WSL에서는 `powershell.exe`를 통해 같은 HUD를 띄웁니다. macOS에서는 투명 배경의 작은 SVG 이미지로 Codex와 Claude 로고, 짧은 미터, 퍼센트를 표시하고, 클릭하면 자세한 상태를 볼 수 있습니다.
|
|
251
251
|
|
|
252
252
|
```bash
|
|
253
253
|
ai-battery hud
|
|
@@ -272,6 +272,11 @@ Claude [battery:76] │ 5h 00:47 │ 7d 59%
|
|
|
272
272
|
| `ai-battery hud -Once` | 콘솔에서 한 번만 출력합니다. |
|
|
273
273
|
| `ai-battery hud -Interval 2` | 갱신 주기를 바꿉니다. |
|
|
274
274
|
| `ai-battery hud -Mode tray` | Windows tray icon 모드로 실행합니다. macOS에서는 menu bar item이 기본입니다. |
|
|
275
|
+
| `ai-battery hud light` / `ai-battery hud dark` | Windows floating HUD를 밝은 작업표시줄용 검은 글자 또는 어두운 작업표시줄용 흰 글자로 바꿉니다. |
|
|
276
|
+
| `ai-battery hud black` / `ai-battery hud white` | 글자색을 직접 검은색 또는 흰색으로 바꿉니다. |
|
|
277
|
+
| `ai-battery hud --backdrop` / `ai-battery hud --no-backdrop` | Windows floating HUD 글자 뒤 어두운 backing을 켜거나 끕니다. |
|
|
278
|
+
|
|
279
|
+
Windows floating HUD는 기본적으로 투명 배경에 밝은 글자로 표시합니다. 밝은 작업표시줄에서는 `ai-battery hud light`, 어두운 작업표시줄에서는 `ai-battery hud dark`를 쓰면 됩니다. 글자색으로 직접 고르려면 `ai-battery hud black` 또는 `ai-battery hud white`를 쓰세요. 로그인 자동 실행에도 같은 모드를 저장하려면 `ai-battery hud autostart on light`처럼 붙이면 됩니다.
|
|
275
280
|
|
|
276
281
|
Windows autostart는 `HKCU\Software\Microsoft\Windows\CurrentVersion\Run`에 사용자 단위로 등록됩니다. Windows native에서는 WSL 없이 바로 실행되고, WSL에서 등록한 경우에는 HUD 스크립트 사본을 `%LOCALAPPDATA%\ai-battery`에 둡니다. macOS autostart는 `~/Library/LaunchAgents/com.ai-battery.hud.plist`로 등록됩니다. ai-battery를 업데이트한 뒤에는 `ai-battery hud autostart on`을 다시 실행해 등록 경로를 갱신하세요.
|
|
277
282
|
|
package/bin/ai-battery-hud.js
CHANGED
|
@@ -104,6 +104,15 @@ function waitForFile(filePath, timeoutMs = 3500) {
|
|
|
104
104
|
return false;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
function isDirectRun() {
|
|
108
|
+
if (!process.argv[1]) return false;
|
|
109
|
+
try {
|
|
110
|
+
return fs.realpathSync(process.argv[1]) === scriptPath;
|
|
111
|
+
} catch {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
107
116
|
function snapshotHasWeekly(jsonText) {
|
|
108
117
|
try {
|
|
109
118
|
const snapshot = JSON.parse(jsonText);
|
|
@@ -216,21 +225,41 @@ function macCommands(options) {
|
|
|
216
225
|
return {
|
|
217
226
|
title: `${envPrefix} ${node} ${batteryJs} --menu-bar-image${providerArgs} 2>/dev/null`,
|
|
218
227
|
detailImage: `${envPrefix} ${node} ${batteryJs} --menu-detail-image${providerArgs} 2>/dev/null`,
|
|
219
|
-
detail: `${envPrefix} ${node} ${batteryJs} --no-color${providerArgs} 2>/dev/null
|
|
228
|
+
detail: `${envPrefix} ${node} ${batteryJs} --no-color${providerArgs} 2>/dev/null`,
|
|
229
|
+
state: `${envPrefix} ${node} ${batteryJs} --hud-state${providerArgs} 2>/dev/null`
|
|
220
230
|
};
|
|
221
231
|
}
|
|
222
232
|
|
|
223
233
|
function macHudPids() {
|
|
224
|
-
const result = spawnSync("
|
|
234
|
+
const result = spawnSync("ps", ["-axo", "pid=,args="], {
|
|
225
235
|
encoding: "utf8",
|
|
226
236
|
stdio: ["ignore", "pipe", "ignore"]
|
|
227
237
|
});
|
|
228
238
|
if (result.status !== 0) return [];
|
|
229
|
-
return (result.stdout
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
239
|
+
return macHudPidsFromPsOutput(result.stdout, process.pid);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function macHudCommandMatches(cmdline) {
|
|
243
|
+
const text = String(cmdline || "").trim();
|
|
244
|
+
if (!text.includes("ai-battery-macos-status.applescript")) return false;
|
|
245
|
+
if (!text.includes("--menu-bar-image") || !text.includes("--menu-detail-image")) return false;
|
|
246
|
+
return path.basename(text.split(/\s+/, 1)[0] || "") === "osascript";
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function macHudPidsFromPsOutput(output, ownPid = process.pid) {
|
|
250
|
+
return String(output || "")
|
|
251
|
+
.split(/\r?\n/)
|
|
252
|
+
.map((line) => {
|
|
253
|
+
const match = line.match(/^\s*(\d+)\s+(.*)$/);
|
|
254
|
+
if (!match) return null;
|
|
255
|
+
return { pid: Number(match[1]), cmdline: match[2] };
|
|
256
|
+
})
|
|
257
|
+
.filter((proc) => proc
|
|
258
|
+
&& Number.isInteger(proc.pid)
|
|
259
|
+
&& proc.pid > 0
|
|
260
|
+
&& proc.pid !== ownPid
|
|
261
|
+
&& macHudCommandMatches(proc.cmdline))
|
|
262
|
+
.map((proc) => proc.pid);
|
|
234
263
|
}
|
|
235
264
|
|
|
236
265
|
function macLaunchAgentPath() {
|
|
@@ -351,7 +380,8 @@ function runMacHud(cliArgs) {
|
|
|
351
380
|
commands.title,
|
|
352
381
|
commands.detailImage,
|
|
353
382
|
commands.detail,
|
|
354
|
-
String(options.interval)
|
|
383
|
+
String(options.interval),
|
|
384
|
+
commands.state
|
|
355
385
|
];
|
|
356
386
|
|
|
357
387
|
if (options.foreground) {
|
|
@@ -368,60 +398,249 @@ function runMacHud(cliArgs) {
|
|
|
368
398
|
process.exit(0);
|
|
369
399
|
}
|
|
370
400
|
|
|
371
|
-
if (process.platform === "darwin") {
|
|
372
|
-
runMacHud(process.argv.slice(2));
|
|
373
|
-
}
|
|
374
|
-
|
|
375
401
|
const useWsl = isWsl();
|
|
376
402
|
const powershell = "powershell.exe";
|
|
377
403
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
404
|
+
function normalizeHudTextOption(value) {
|
|
405
|
+
const normalized = String(value || "").trim().toLowerCase();
|
|
406
|
+
if (["black", "dark", "ink"].includes(normalized)) return "dark";
|
|
407
|
+
if (["white", "light", "bright"].includes(normalized)) return "light";
|
|
408
|
+
throw new Error("--text must be one of: black or white");
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function hudTextForTaskbar(value) {
|
|
412
|
+
const normalized = String(value || "").trim().toLowerCase();
|
|
413
|
+
if (["light", "white-taskbar", "light-taskbar", "lightbar"].includes(normalized)) return "dark";
|
|
414
|
+
if (["dark", "black-taskbar", "dark-taskbar", "darkbar"].includes(normalized)) return "light";
|
|
415
|
+
throw new Error("taskbar color must be one of: light or dark");
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function normalizeHudBackdropOption(value) {
|
|
419
|
+
const normalized = String(value || "").trim().toLowerCase();
|
|
420
|
+
if (["1", "true", "yes", "on", "solid", "backdrop"].includes(normalized)) return "on";
|
|
421
|
+
if (["0", "false", "no", "off", "none", "transparent"].includes(normalized)) return "off";
|
|
422
|
+
throw new Error("--backdrop must be one of: on, off");
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function optionValue(cliArgs, index, optionName) {
|
|
426
|
+
const next = cliArgs[index + 1];
|
|
427
|
+
if (!next || String(next).startsWith("-")) {
|
|
428
|
+
throw new Error(`${optionName} requires a value`);
|
|
429
|
+
}
|
|
430
|
+
return next;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function windowsHudUsage() {
|
|
434
|
+
return [
|
|
435
|
+
"Taskbar color:",
|
|
436
|
+
" ai-battery hud light light taskbar -> black text",
|
|
437
|
+
" ai-battery hud dark dark taskbar -> white text",
|
|
438
|
+
"",
|
|
439
|
+
"Text color:",
|
|
440
|
+
" ai-battery hud black black text",
|
|
441
|
+
" ai-battery hud white white text",
|
|
442
|
+
"",
|
|
443
|
+
"Other:",
|
|
444
|
+
" ai-battery hud stop",
|
|
445
|
+
" ai-battery hud status",
|
|
446
|
+
" ai-battery hud --backdrop",
|
|
447
|
+
" ai-battery hud autostart on light"
|
|
448
|
+
].join("\n");
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function describeWindowsHudOptions(filteredArgs) {
|
|
452
|
+
const descriptions = [];
|
|
453
|
+
for (let i = 0; i < filteredArgs.length; i += 1) {
|
|
454
|
+
const option = String(filteredArgs[i]).toLowerCase();
|
|
455
|
+
const value = filteredArgs[i + 1];
|
|
456
|
+
if (option === "-text") {
|
|
457
|
+
descriptions.push(value === "dark" ? "black text" : "white text");
|
|
458
|
+
i += 1;
|
|
459
|
+
} else if (option === "-backdrop") {
|
|
460
|
+
descriptions.push(value === "on" ? "backdrop on" : "backdrop off");
|
|
461
|
+
i += 1;
|
|
462
|
+
} else if (option === "-transparent") {
|
|
463
|
+
descriptions.push(value === "solid" ? "solid background" : "transparent background");
|
|
418
464
|
i += 1;
|
|
419
465
|
}
|
|
420
|
-
} else {
|
|
421
|
-
filteredArgs.push(arg);
|
|
422
466
|
}
|
|
467
|
+
|
|
468
|
+
return [...new Set(descriptions)].join(", ");
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
const HUD_PASSTHROUGH_OPTIONS_WITH_VALUE = new Set([
|
|
472
|
+
"-batterycommand",
|
|
473
|
+
"-batterycommandbase64",
|
|
474
|
+
"-initialjsonbase64",
|
|
475
|
+
"-interval",
|
|
476
|
+
"-mode",
|
|
477
|
+
"-opacity",
|
|
478
|
+
"-position",
|
|
479
|
+
"-readypath",
|
|
480
|
+
"-width"
|
|
481
|
+
]);
|
|
482
|
+
|
|
483
|
+
const HUD_PASSTHROUGH_SWITCHES = new Set([
|
|
484
|
+
"-clickthrough",
|
|
485
|
+
"-locked",
|
|
486
|
+
"-movable",
|
|
487
|
+
"-once",
|
|
488
|
+
"-stopexisting",
|
|
489
|
+
"-usewsl"
|
|
490
|
+
]);
|
|
491
|
+
|
|
492
|
+
function parseWindowsHudArgs(cliArgs) {
|
|
493
|
+
const passthroughArgs = [];
|
|
494
|
+
let textMode = null;
|
|
495
|
+
let backdropMode = null;
|
|
496
|
+
let transparentMode = null;
|
|
497
|
+
let foreground = false;
|
|
498
|
+
let once = false;
|
|
499
|
+
let stop = false;
|
|
500
|
+
let subcommand = null;
|
|
501
|
+
let autostartAction = "status";
|
|
502
|
+
|
|
503
|
+
const setTextMode = (value) => {
|
|
504
|
+
textMode = normalizeHudTextOption(value);
|
|
505
|
+
};
|
|
506
|
+
const setBackdropMode = (value) => {
|
|
507
|
+
backdropMode = normalizeHudBackdropOption(value);
|
|
508
|
+
if (backdropMode === "on" && textMode === null) {
|
|
509
|
+
textMode = "light";
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
const optionalBackdropValue = (value) => {
|
|
513
|
+
try {
|
|
514
|
+
return normalizeHudBackdropOption(value);
|
|
515
|
+
} catch {
|
|
516
|
+
return null;
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
for (let i = 0; i < cliArgs.length; i += 1) {
|
|
521
|
+
const arg = cliArgs[i];
|
|
522
|
+
const lowerArg = String(arg).toLowerCase();
|
|
523
|
+
if (arg === "-Foreground" || arg === "--foreground") {
|
|
524
|
+
foreground = true;
|
|
525
|
+
} else if (arg === "-Movable" || arg === "--movable") {
|
|
526
|
+
passthroughArgs.push("-Movable");
|
|
527
|
+
} else if (arg === "-Once" || arg === "--once") {
|
|
528
|
+
once = true;
|
|
529
|
+
passthroughArgs.push("-Once");
|
|
530
|
+
} else if (arg === "-Stop" || arg === "--stop" || arg === "stop") {
|
|
531
|
+
stop = true;
|
|
532
|
+
passthroughArgs.push("-StopExisting");
|
|
533
|
+
} else if (arg === "start") {
|
|
534
|
+
// Launching is the default action.
|
|
535
|
+
} else if (arg === "status") {
|
|
536
|
+
subcommand = "status";
|
|
537
|
+
} else if (arg === "autostart") {
|
|
538
|
+
subcommand = "autostart";
|
|
539
|
+
const next = cliArgs[i + 1];
|
|
540
|
+
if (next === "on" || next === "off" || next === "status") {
|
|
541
|
+
autostartAction = next;
|
|
542
|
+
i += 1;
|
|
543
|
+
}
|
|
544
|
+
} else if (lowerArg === "--black" || lowerArg === "black") {
|
|
545
|
+
setTextMode("black");
|
|
546
|
+
} else if (lowerArg === "--white" || lowerArg === "white") {
|
|
547
|
+
setTextMode("white");
|
|
548
|
+
} else if (lowerArg === "--light" || lowerArg === "light") {
|
|
549
|
+
textMode = hudTextForTaskbar("light");
|
|
550
|
+
} else if (lowerArg === "--dark" || lowerArg === "dark") {
|
|
551
|
+
textMode = hudTextForTaskbar("dark");
|
|
552
|
+
} else if (lowerArg === "--text" || lowerArg === "--hud-text") {
|
|
553
|
+
setTextMode(optionValue(cliArgs, i, arg));
|
|
554
|
+
i += 1;
|
|
555
|
+
} else if (lowerArg.startsWith("--text=") || lowerArg.startsWith("--hud-text=")) {
|
|
556
|
+
setTextMode(arg.slice(arg.indexOf("=") + 1));
|
|
557
|
+
} else if (lowerArg === "--backdrop") {
|
|
558
|
+
const next = cliArgs[i + 1];
|
|
559
|
+
const backdropValue = next && !String(next).startsWith("-") ? optionalBackdropValue(next) : null;
|
|
560
|
+
if (backdropValue) {
|
|
561
|
+
setBackdropMode(backdropValue);
|
|
562
|
+
i += 1;
|
|
563
|
+
} else {
|
|
564
|
+
setBackdropMode("on");
|
|
565
|
+
}
|
|
566
|
+
} else if (lowerArg.startsWith("--backdrop=")) {
|
|
567
|
+
setBackdropMode(arg.slice(arg.indexOf("=") + 1));
|
|
568
|
+
} else if (lowerArg === "-backdrop") {
|
|
569
|
+
setBackdropMode(optionValue(cliArgs, i, arg));
|
|
570
|
+
i += 1;
|
|
571
|
+
} else if (lowerArg === "--no-backdrop") {
|
|
572
|
+
setBackdropMode("off");
|
|
573
|
+
} else if (lowerArg === "--solid") {
|
|
574
|
+
transparentMode = "solid";
|
|
575
|
+
} else if (lowerArg === "--transparent") {
|
|
576
|
+
transparentMode = "on";
|
|
577
|
+
} else if (lowerArg === "-transparent") {
|
|
578
|
+
transparentMode = optionValue(cliArgs, i, arg);
|
|
579
|
+
i += 1;
|
|
580
|
+
} else if (lowerArg === "-text") {
|
|
581
|
+
setTextMode(optionValue(cliArgs, i, arg));
|
|
582
|
+
i += 1;
|
|
583
|
+
} else if (arg.startsWith("-")) {
|
|
584
|
+
if (HUD_PASSTHROUGH_OPTIONS_WITH_VALUE.has(lowerArg)) {
|
|
585
|
+
passthroughArgs.push(arg, optionValue(cliArgs, i, arg));
|
|
586
|
+
i += 1;
|
|
587
|
+
} else if (HUD_PASSTHROUGH_SWITCHES.has(lowerArg)) {
|
|
588
|
+
passthroughArgs.push(arg);
|
|
589
|
+
} else {
|
|
590
|
+
throw new Error(`unknown HUD option: ${arg}`);
|
|
591
|
+
}
|
|
592
|
+
} else {
|
|
593
|
+
throw new Error(`unknown HUD option: ${arg}`);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
const filteredArgs = [...passthroughArgs];
|
|
598
|
+
if (backdropMode !== null) filteredArgs.push("-Backdrop", backdropMode);
|
|
599
|
+
if (textMode !== null) filteredArgs.push("-Text", textMode);
|
|
600
|
+
if (transparentMode !== null) filteredArgs.push("-Transparent", transparentMode);
|
|
601
|
+
|
|
602
|
+
return {
|
|
603
|
+
filteredArgs,
|
|
604
|
+
foreground,
|
|
605
|
+
once,
|
|
606
|
+
stop,
|
|
607
|
+
subcommand,
|
|
608
|
+
autostartAction
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
function runDesktopHud(cliArgs) {
|
|
613
|
+
if (process.platform === "darwin") {
|
|
614
|
+
runMacHud(cliArgs);
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
if (!useWsl && process.platform !== "win32") {
|
|
619
|
+
console.error("ai-battery-hud: desktop HUD needs Windows (native or WSL) or macOS.");
|
|
620
|
+
console.error("On Linux terminals use: ai-battery --watch");
|
|
621
|
+
process.exit(1);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
if (!commandExists(powershell)) {
|
|
625
|
+
console.error("ai-battery-hud: powershell.exe is required for the Windows HUD.");
|
|
626
|
+
process.exit(1);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
runWindowsHud(cliArgs);
|
|
423
630
|
}
|
|
424
631
|
|
|
632
|
+
function runWindowsHud(cliArgs) {
|
|
633
|
+
const parsedArgs = (() => {
|
|
634
|
+
try {
|
|
635
|
+
return parseWindowsHudArgs(cliArgs);
|
|
636
|
+
} catch (error) {
|
|
637
|
+
console.error(`ai-battery-hud: ${error.message}`);
|
|
638
|
+
console.error(windowsHudUsage());
|
|
639
|
+
process.exit(1);
|
|
640
|
+
}
|
|
641
|
+
})();
|
|
642
|
+
const { filteredArgs, foreground, once, stop, subcommand, autostartAction } = parsedArgs;
|
|
643
|
+
|
|
425
644
|
const hudScript = useWsl ? wslPath(ps1Path) : ps1Path;
|
|
426
645
|
const nodePath = process.execPath;
|
|
427
646
|
const batteryJs = path.join(scriptDir, "ai-battery.js");
|
|
@@ -468,6 +687,10 @@ function autostartEnable() {
|
|
|
468
687
|
// launches the copy so sign-in start never depends on WSL being up. The HUD
|
|
469
688
|
// must run as a separate PowerShell process whose command line contains
|
|
470
689
|
// ai-battery-hud.ps1: stop/status and single-instance cleanup match it.
|
|
690
|
+
const autostartExtraArgs = filteredArgs
|
|
691
|
+
.filter((arg) => arg !== "-Once" && arg !== "-StopExisting")
|
|
692
|
+
.map(psSingleQuote)
|
|
693
|
+
.join(" ");
|
|
471
694
|
const autostartScript = [
|
|
472
695
|
"# Generated by: ai-battery hud autostart on",
|
|
473
696
|
`$src = ${psSingleQuote(hudScript)}`,
|
|
@@ -475,7 +698,9 @@ function autostartEnable() {
|
|
|
475
698
|
"try { Copy-Item $src $hud -Force -ErrorAction Stop } catch { }",
|
|
476
699
|
`$battery = ${psSingleQuote(batteryCommand)}`,
|
|
477
700
|
"$batteryB64 = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($battery))",
|
|
478
|
-
"$invoke = '& ' + \"'\" + ($hud -replace \"'\", \"''\") + \"'\" + ' -BatteryCommandBase64 ' + $batteryB64"
|
|
701
|
+
"$invoke = '& ' + \"'\" + ($hud -replace \"'\", \"''\") + \"'\" + ' -BatteryCommandBase64 ' + $batteryB64"
|
|
702
|
+
+ (autostartExtraArgs ? ` + ${psSingleQuote(` ${autostartExtraArgs}`)}` : "")
|
|
703
|
+
+ (useWsl ? " + ' -UseWsl'" : ""),
|
|
479
704
|
"$argList = @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', ('\"' + ($invoke -replace '\"', '\\\"') + '\"')) -join ' '",
|
|
480
705
|
"Start-Process -WindowStyle Hidden -FilePath 'powershell.exe' -ArgumentList $argList",
|
|
481
706
|
""
|
|
@@ -531,6 +756,9 @@ if (subcommand === "autostart") {
|
|
|
531
756
|
process.exit(0);
|
|
532
757
|
}
|
|
533
758
|
|
|
759
|
+
const wasRunning = (!foreground && !once && !stop)
|
|
760
|
+
? hudProcessStatus().startsWith("running ")
|
|
761
|
+
: false;
|
|
534
762
|
const initialJson = stop ? null : prefetchInitialJson(batteryCommand, useWsl);
|
|
535
763
|
const readyPath = (!useWsl && process.platform === "win32" && !foreground && !once && !stop)
|
|
536
764
|
? path.join(os.tmpdir(), `ai-battery-hud-ready-${process.pid}-${Date.now()}.json`)
|
|
@@ -593,6 +821,24 @@ if (useWsl) {
|
|
|
593
821
|
if (readyPath && !waitForFile(readyPath)) {
|
|
594
822
|
console.log("AI Battery HUD start requested, but no visible window was confirmed. Run: ai-battery hud --foreground");
|
|
595
823
|
} else {
|
|
596
|
-
|
|
824
|
+
const detail = describeWindowsHudOptions(filteredArgs);
|
|
825
|
+
const action = wasRunning ? (detail ? "updated" : "restarted") : "started";
|
|
826
|
+
console.log(`AI Battery HUD ${action}${detail ? `: ${detail}` : ""}.`);
|
|
827
|
+
if (!wasRunning) {
|
|
828
|
+
console.log("Drag to move. Right-click to exit.");
|
|
829
|
+
}
|
|
597
830
|
}
|
|
598
831
|
if (readyPath) fs.rmSync(readyPath, { force: true });
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
if (isDirectRun()) {
|
|
835
|
+
runDesktopHud(process.argv.slice(2));
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
export {
|
|
839
|
+
macHudCommandMatches,
|
|
840
|
+
macHudPidsFromPsOutput,
|
|
841
|
+
describeWindowsHudOptions,
|
|
842
|
+
parseWindowsHudArgs,
|
|
843
|
+
windowsHudUsage
|
|
844
|
+
};
|
package/bin/ai-battery-hud.ps1
CHANGED
|
@@ -7,6 +7,9 @@ param(
|
|
|
7
7
|
[string]$BatteryCommandBase64 = "",
|
|
8
8
|
[string]$InitialJsonBase64 = "",
|
|
9
9
|
[int]$Width = 282,
|
|
10
|
+
[string]$Backdrop = $(if ($env:AI_BATTERY_HUD_BACKDROP) { $env:AI_BATTERY_HUD_BACKDROP } elseif ($env:CLAUDEX_BATTERY_HUD_BACKDROP) { $env:CLAUDEX_BATTERY_HUD_BACKDROP } else { "off" }),
|
|
11
|
+
[string]$Text = $(if ($env:AI_BATTERY_HUD_TEXT) { $env:AI_BATTERY_HUD_TEXT } elseif ($env:CLAUDEX_BATTERY_HUD_TEXT) { $env:CLAUDEX_BATTERY_HUD_TEXT } else { "light" }),
|
|
12
|
+
[string]$Transparent = "",
|
|
10
13
|
[double]$Opacity = $(if ($env:AI_BATTERY_HUD_OPACITY) { [double]$env:AI_BATTERY_HUD_OPACITY } elseif ($env:CLAUDEX_BATTERY_HUD_OPACITY) { [double]$env:CLAUDEX_BATTERY_HUD_OPACITY } else { 1.0 }),
|
|
11
14
|
[switch]$Locked,
|
|
12
15
|
[switch]$Movable,
|
|
@@ -461,15 +464,44 @@ function Get-PercentColor([Nullable[int]]$Percent) {
|
|
|
461
464
|
return [System.Drawing.Color]::FromArgb(80, 220, 120)
|
|
462
465
|
}
|
|
463
466
|
|
|
464
|
-
function
|
|
465
|
-
|
|
467
|
+
function Test-HudDarkText {
|
|
468
|
+
$normalized = ([string]$Text).Trim().ToLowerInvariant()
|
|
469
|
+
return @("dark", "black", "ink", "light-taskbar", "lightbar") -contains $normalized
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
function Get-HudActiveTextColor {
|
|
473
|
+
if ($script:hudDarkText) { return [System.Drawing.Color]::FromArgb(28, 28, 28) }
|
|
474
|
+
return [System.Drawing.Color]::FromArgb(235, 235, 235)
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
function Get-HudMutedTextColor {
|
|
478
|
+
if ($script:hudDarkText) { return [System.Drawing.Color]::FromArgb(88, 88, 88) }
|
|
466
479
|
return [System.Drawing.Color]::FromArgb(145, 145, 145)
|
|
467
480
|
}
|
|
468
481
|
|
|
469
|
-
function Get-
|
|
482
|
+
function Get-HudDividerColor {
|
|
483
|
+
if ($script:hudDarkText) { return [System.Drawing.Color]::FromArgb(100, 100, 100) }
|
|
470
484
|
return [System.Drawing.Color]::FromArgb(132, 132, 132)
|
|
471
485
|
}
|
|
472
486
|
|
|
487
|
+
function Get-HudBatteryTextColor([bool]$Running) {
|
|
488
|
+
if ($script:hudDarkText) {
|
|
489
|
+
if ($Running) { return [System.Drawing.Color]::FromArgb(20, 20, 20) }
|
|
490
|
+
return [System.Drawing.Color]::FromArgb(78, 78, 78)
|
|
491
|
+
}
|
|
492
|
+
if ($Running) { return [System.Drawing.Color]::FromArgb(255, 255, 255) }
|
|
493
|
+
return [System.Drawing.Color]::FromArgb(235, 235, 235)
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
function Get-ActivityColor($Result) {
|
|
497
|
+
if ($Result -and $Result.running) { return Get-HudActiveTextColor }
|
|
498
|
+
return Get-HudMutedTextColor
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function Get-DividerColor {
|
|
502
|
+
return Get-HudDividerColor
|
|
503
|
+
}
|
|
504
|
+
|
|
473
505
|
function Format-Parts($Result, [string]$Name) {
|
|
474
506
|
$isRunning = [bool]($Result -and $Result.running)
|
|
475
507
|
$textColor = Get-ActivityColor $Result
|
|
@@ -793,14 +825,22 @@ function New-HudBitmapSurface([int]$Width, [int]$Height) {
|
|
|
793
825
|
}
|
|
794
826
|
|
|
795
827
|
function Test-HudTransparentSurface {
|
|
796
|
-
$value = $
|
|
828
|
+
$value = $Transparent
|
|
829
|
+
if (-not $value) { $value = $env:AI_BATTERY_HUD_TRANSPARENT }
|
|
797
830
|
if (-not $value) { $value = $env:CLAUDEX_BATTERY_HUD_TRANSPARENT }
|
|
798
831
|
if (-not $value) { return $true }
|
|
799
832
|
$normalized = ([string]$value).Trim().ToLowerInvariant()
|
|
800
833
|
return -not (@("0", "false", "no", "off", "solid") -contains $normalized)
|
|
801
834
|
}
|
|
802
835
|
|
|
836
|
+
function Test-HudContrastBackdrop {
|
|
837
|
+
$normalized = ([string]$Backdrop).Trim().ToLowerInvariant()
|
|
838
|
+
if (-not $normalized) { $normalized = "off" }
|
|
839
|
+
return @("1", "true", "yes", "on", "solid", "backdrop") -contains $normalized
|
|
840
|
+
}
|
|
841
|
+
|
|
803
842
|
Update-HudDpiScale
|
|
843
|
+
$script:hudDarkText = Test-HudDarkText
|
|
804
844
|
|
|
805
845
|
function Get-LineText($Parts) {
|
|
806
846
|
return "$($Parts.Prefix)[battery]$($Parts.Suffix)"
|
|
@@ -952,17 +992,26 @@ function New-BatteryImage([Nullable[int]]$Percent, [bool]$Running = $true, [int]
|
|
|
952
992
|
|
|
953
993
|
$outlineColor = [System.Drawing.Color]::FromArgb(170, 170, 170)
|
|
954
994
|
$mutedColor = [System.Drawing.Color]::FromArgb(120, 120, 120)
|
|
995
|
+
if ($script:hudDarkText) {
|
|
996
|
+
$outlineColor = [System.Drawing.Color]::FromArgb(58, 58, 58)
|
|
997
|
+
$mutedColor = [System.Drawing.Color]::FromArgb(98, 98, 98)
|
|
998
|
+
}
|
|
955
999
|
$activeOutlineColor = if ($Running) { $outlineColor } else { $mutedColor }
|
|
956
1000
|
# The fill always keeps its charge color (matching the terminal bar);
|
|
957
1001
|
# running state is signalled by the outline and text colors instead.
|
|
958
1002
|
$fillColor = Get-PercentColor $Percent
|
|
959
1003
|
$outlinePen = [System.Drawing.Pen]::new($(if ($null -eq $Percent) { $mutedColor } else { $activeOutlineColor }), 1.0)
|
|
960
1004
|
$fillBrush = [System.Drawing.SolidBrush]::new($fillColor)
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
1005
|
+
$interiorColor = if ($script:hudDarkText) {
|
|
1006
|
+
[System.Drawing.Color]::FromArgb(246, 246, 246)
|
|
1007
|
+
} else {
|
|
1008
|
+
# A solid dark interior keeps the desktop from bleeding through the empty
|
|
1009
|
+
# part of the battery, so the percent text stays readable on any wallpaper.
|
|
1010
|
+
[System.Drawing.Color]::FromArgb(46, 46, 46)
|
|
1011
|
+
}
|
|
1012
|
+
$interiorBrush = [System.Drawing.SolidBrush]::new($interiorColor)
|
|
964
1013
|
$terminalBrush = [System.Drawing.SolidBrush]::new($(if ($null -eq $Percent) { $mutedColor } else { $activeOutlineColor }))
|
|
965
|
-
$textBrush = [System.Drawing.SolidBrush]::new(
|
|
1014
|
+
$textBrush = [System.Drawing.SolidBrush]::new((Get-HudBatteryTextColor $Running))
|
|
966
1015
|
$batteryText = if ($null -eq $Percent) { "--" } else { [string][int]$Percent }
|
|
967
1016
|
$fontSize = if ($batteryText.Length -ge 3) { 4.4 } elseif ($batteryText.Length -ge 2) { 5.1 } else { 5.8 }
|
|
968
1017
|
$batteryFont = $null
|
|
@@ -1221,12 +1270,23 @@ $form.TopMost = $true
|
|
|
1221
1270
|
$form.ShowInTaskbar = $false
|
|
1222
1271
|
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::None
|
|
1223
1272
|
$script:hudTransparentSurface = Test-HudTransparentSurface
|
|
1273
|
+
$script:hudContrastBackdrop = Test-HudContrastBackdrop
|
|
1274
|
+
$script:hudChromeBackColor = [System.Drawing.Color]::FromArgb(24, 24, 24)
|
|
1224
1275
|
if ($script:hudTransparentSurface) {
|
|
1225
|
-
$transparentBackColor =
|
|
1276
|
+
$transparentBackColor = if ($script:hudDarkText -and (-not $script:hudContrastBackdrop)) {
|
|
1277
|
+
[System.Drawing.Color]::FromArgb(254, 254, 254)
|
|
1278
|
+
} else {
|
|
1279
|
+
[System.Drawing.Color]::FromArgb(18, 18, 18)
|
|
1280
|
+
}
|
|
1226
1281
|
$form.BackColor = $transparentBackColor
|
|
1227
1282
|
$form.TransparencyKey = $transparentBackColor
|
|
1228
1283
|
} else {
|
|
1229
|
-
$form.BackColor =
|
|
1284
|
+
$form.BackColor = $script:hudChromeBackColor
|
|
1285
|
+
}
|
|
1286
|
+
$script:hudSurfaceBackColor = if ($script:hudContrastBackdrop -or (-not $script:hudTransparentSurface)) {
|
|
1287
|
+
$script:hudChromeBackColor
|
|
1288
|
+
} else {
|
|
1289
|
+
$form.BackColor
|
|
1230
1290
|
}
|
|
1231
1291
|
$form.Opacity = [math]::Max(0.2, [math]::Min(1.0, $Opacity))
|
|
1232
1292
|
|
|
@@ -1243,7 +1303,7 @@ $panel.Padding = if ($Mode -eq "floating" -or $Mode -eq "statusline") {
|
|
|
1243
1303
|
} else {
|
|
1244
1304
|
New-HudPadding 10 7 10 6
|
|
1245
1305
|
}
|
|
1246
|
-
$panel.BackColor = $
|
|
1306
|
+
$panel.BackColor = $script:hudSurfaceBackColor
|
|
1247
1307
|
$panel.RowStyles.Add([System.Windows.Forms.RowStyle]::new([System.Windows.Forms.SizeType]::Percent, 50)) | Out-Null
|
|
1248
1308
|
$panel.RowStyles.Add([System.Windows.Forms.RowStyle]::new([System.Windows.Forms.SizeType]::Percent, 50)) | Out-Null
|
|
1249
1309
|
$panel.ColumnStyles.Add([System.Windows.Forms.ColumnStyle]::new([System.Windows.Forms.SizeType]::Percent, 100)) | Out-Null
|
|
@@ -1255,7 +1315,7 @@ function New-HudRow {
|
|
|
1255
1315
|
$row.WrapContents = $false
|
|
1256
1316
|
$row.Margin = [System.Windows.Forms.Padding]::new(0)
|
|
1257
1317
|
$row.Padding = [System.Windows.Forms.Padding]::new(0)
|
|
1258
|
-
$row.BackColor = $
|
|
1318
|
+
$row.BackColor = $script:hudSurfaceBackColor
|
|
1259
1319
|
return $row
|
|
1260
1320
|
}
|
|
1261
1321
|
|
|
@@ -1266,7 +1326,7 @@ function New-HudLabel([int]$RightMargin = 0) {
|
|
|
1266
1326
|
$label.Height = Scale-HudValue 18
|
|
1267
1327
|
$label.Font = $font
|
|
1268
1328
|
$label.UseCompatibleTextRendering = $false
|
|
1269
|
-
$label.BackColor = $
|
|
1329
|
+
$label.BackColor = $script:hudSurfaceBackColor
|
|
1270
1330
|
$label.Margin = New-HudPadding 0 0 $RightMargin 0
|
|
1271
1331
|
$label.TextAlign = [System.Drawing.ContentAlignment]::MiddleLeft
|
|
1272
1332
|
return $label
|
|
@@ -1277,8 +1337,8 @@ function New-HudIconBox {
|
|
|
1277
1337
|
$box.Width = Scale-HudValue 40
|
|
1278
1338
|
$box.Height = Scale-HudValue 18
|
|
1279
1339
|
$box.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::Zoom
|
|
1280
|
-
$box.BackColor = $
|
|
1281
|
-
$box.ForeColor =
|
|
1340
|
+
$box.BackColor = $script:hudSurfaceBackColor
|
|
1341
|
+
$box.ForeColor = Get-HudBatteryTextColor $true
|
|
1282
1342
|
$box.Margin = New-HudPadding 0 0 2 0
|
|
1283
1343
|
$box.add_Paint({
|
|
1284
1344
|
param($sender, $event)
|
|
@@ -1316,7 +1376,7 @@ function New-HudLineIconBox {
|
|
|
1316
1376
|
$box.Width = Scale-HudValue 21
|
|
1317
1377
|
$box.Height = Scale-HudValue 18
|
|
1318
1378
|
$box.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::CenterImage
|
|
1319
|
-
$box.BackColor = $
|
|
1379
|
+
$box.BackColor = $script:hudSurfaceBackColor
|
|
1320
1380
|
$box.Margin = New-HudPadding 3 0 0 0
|
|
1321
1381
|
return $box
|
|
1322
1382
|
}
|
|
@@ -1359,12 +1419,32 @@ foreach ($label in @($codexIconLabel, $claudeIconLabel)) {
|
|
|
1359
1419
|
$codexHudControls = @($codexPrefixLabel, $codexIconLabel, $codexDivider1, $codexResetLabel, $codexDivider2, $codexWeekLabel, $codexExtraLabel)
|
|
1360
1420
|
$claudeHudControls = @($claudePrefixLabel, $claudeIconLabel, $claudeDivider1, $claudeResetLabel, $claudeDivider2, $claudeWeekLabel, $claudeExtraLabel)
|
|
1361
1421
|
|
|
1422
|
+
function Test-PointInBounds($Bounds, [System.Drawing.Point]$Point) {
|
|
1423
|
+
if (-not $Bounds) { return $false }
|
|
1424
|
+
return $Bounds.Contains($Point)
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1362
1427
|
$menu = New-Object System.Windows.Forms.ContextMenuStrip
|
|
1363
1428
|
$menu.Font = $font
|
|
1429
|
+
$menu.AutoClose = $true
|
|
1430
|
+
$script:hudMenuOpenedAt = [datetime]::UtcNow
|
|
1431
|
+
$script:hudMenuLastInsideAt = [datetime]::UtcNow
|
|
1432
|
+
$script:hudMenuReadyForOutsideClick = $false
|
|
1364
1433
|
$exitItem = $menu.Items.Add("Exit")
|
|
1365
1434
|
$exitItem.add_Click({ $form.Close() })
|
|
1435
|
+
$menu.add_Opened({
|
|
1436
|
+
$script:hudMenuOpenedAt = [datetime]::UtcNow
|
|
1437
|
+
$script:hudMenuLastInsideAt = [datetime]::UtcNow
|
|
1438
|
+
$script:hudMenuReadyForOutsideClick = $false
|
|
1439
|
+
})
|
|
1440
|
+
function Hide-HudMenu {
|
|
1441
|
+
if ($menu -and -not $menu.IsDisposed -and $menu.Visible) {
|
|
1442
|
+
$menu.Close([System.Windows.Forms.ToolStripDropDownCloseReason]::CloseCalled)
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1366
1445
|
$form.ContextMenuStrip = $menu
|
|
1367
1446
|
$panel.ContextMenuStrip = $menu
|
|
1447
|
+
|
|
1368
1448
|
foreach ($label in $codexHudControls) {
|
|
1369
1449
|
$label.ContextMenuStrip = $menu
|
|
1370
1450
|
$codexRow.Controls.Add($label) | Out-Null
|
|
@@ -1737,6 +1817,7 @@ function Ensure-HudTopMost {
|
|
|
1737
1817
|
function Set-HudHiddenForFullscreen([bool]$Hidden) {
|
|
1738
1818
|
$script:hudHiddenForFullscreen = $Hidden
|
|
1739
1819
|
if ($Hidden) {
|
|
1820
|
+
Hide-HudMenu
|
|
1740
1821
|
if ($hitForm -and -not $hitForm.IsDisposed -and $hitForm.Visible) {
|
|
1741
1822
|
[AiBatteryNative]::ShowWindow($hitForm.Handle, [AiBatteryNative]::SW_HIDE) | Out-Null
|
|
1742
1823
|
$hitForm.Hide()
|
|
@@ -1776,6 +1857,38 @@ function Update-HudVisibilityForFullscreen {
|
|
|
1776
1857
|
|
|
1777
1858
|
$script:fullscreenCheckPending = $false
|
|
1778
1859
|
|
|
1860
|
+
function Update-HudMenuAutoHide {
|
|
1861
|
+
if (-not $menu -or $menu.IsDisposed -or -not $menu.Visible) { return }
|
|
1862
|
+
$now = [datetime]::UtcNow
|
|
1863
|
+
$point = [System.Windows.Forms.Cursor]::Position
|
|
1864
|
+
$insideMenu = Test-PointInBounds $menu.Bounds $point
|
|
1865
|
+
$insideHud = Test-PointInBounds $form.Bounds $point
|
|
1866
|
+
if ($hitForm -and -not $hitForm.IsDisposed) {
|
|
1867
|
+
$insideHud = $insideHud -or (Test-PointInBounds $hitForm.Bounds $point)
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
if ($insideMenu -or $insideHud) {
|
|
1871
|
+
$script:hudMenuLastInsideAt = $now
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
$buttons = [System.Windows.Forms.Control]::MouseButtons
|
|
1875
|
+
if (-not $script:hudMenuReadyForOutsideClick) {
|
|
1876
|
+
if ($buttons -eq [System.Windows.Forms.MouseButtons]::None) {
|
|
1877
|
+
$script:hudMenuReadyForOutsideClick = $true
|
|
1878
|
+
}
|
|
1879
|
+
return
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1882
|
+
if ($buttons -ne [System.Windows.Forms.MouseButtons]::None -and -not $insideMenu) {
|
|
1883
|
+
Hide-HudMenu
|
|
1884
|
+
return
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
if ((-not $insideMenu) -and (-not $insideHud) -and (($now - $script:hudMenuLastInsideAt).TotalMilliseconds -gt 1500)) {
|
|
1888
|
+
Hide-HudMenu
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1779
1892
|
function Request-FullscreenCheck {
|
|
1780
1893
|
if (-not $form -or $form.IsDisposed) { return }
|
|
1781
1894
|
if ($form.InvokeRequired) {
|
|
@@ -1843,11 +1956,7 @@ function Set-HudBatteryImage($Box, [Nullable[int]]$Percent, [bool]$Running) {
|
|
|
1843
1956
|
$oldImage = $Box.Image
|
|
1844
1957
|
$Box.Image = New-BatteryImage $Percent $Running 36 16 $false
|
|
1845
1958
|
$Box.AccessibleName = if ($null -eq $Percent) { "--" } else { [string][int]$Percent }
|
|
1846
|
-
$Box.ForeColor =
|
|
1847
|
-
[System.Drawing.Color]::FromArgb(255, 255, 255)
|
|
1848
|
-
} else {
|
|
1849
|
-
[System.Drawing.Color]::FromArgb(235, 235, 235)
|
|
1850
|
-
}
|
|
1959
|
+
$Box.ForeColor = Get-HudBatteryTextColor $Running
|
|
1851
1960
|
$Box.Visible = $true
|
|
1852
1961
|
$Box.Tag = $true
|
|
1853
1962
|
$Box.Invalidate()
|
|
@@ -2121,7 +2230,7 @@ function Resize-HudToContent {
|
|
|
2121
2230
|
|
|
2122
2231
|
function Show-HudMessage([string]$Message) {
|
|
2123
2232
|
$codexPrefixLabel.Text = $Message
|
|
2124
|
-
$codexPrefixLabel.ForeColor =
|
|
2233
|
+
$codexPrefixLabel.ForeColor = Get-HudMutedTextColor
|
|
2125
2234
|
$codexPrefixLabel.Width = (Get-LabelTextWidth $codexPrefixLabel) + (Scale-HudValue 1)
|
|
2126
2235
|
$codexPrefixLabel.Visible = $true
|
|
2127
2236
|
$codexPrefixLabel.Tag = $true
|
|
@@ -2233,6 +2342,9 @@ $timer.add_Tick({ Invoke-HudPump })
|
|
|
2233
2342
|
$topMostTimer = New-Object System.Windows.Forms.Timer
|
|
2234
2343
|
$topMostTimer.Interval = 150
|
|
2235
2344
|
$topMostTimer.add_Tick({ Update-HudVisibilityForFullscreen })
|
|
2345
|
+
$menuAutoHideTimer = New-Object System.Windows.Forms.Timer
|
|
2346
|
+
$menuAutoHideTimer.Interval = 50
|
|
2347
|
+
$menuAutoHideTimer.add_Tick({ Update-HudMenuAutoHide })
|
|
2236
2348
|
$form.add_FormClosed({
|
|
2237
2349
|
if ($canMove) {
|
|
2238
2350
|
Write-HudPosition $form.Location
|
|
@@ -2241,6 +2353,8 @@ $form.add_FormClosed({
|
|
|
2241
2353
|
$timer.Dispose()
|
|
2242
2354
|
$topMostTimer.Stop()
|
|
2243
2355
|
$topMostTimer.Dispose()
|
|
2356
|
+
$menuAutoHideTimer.Stop()
|
|
2357
|
+
$menuAutoHideTimer.Dispose()
|
|
2244
2358
|
Stop-FullscreenEventHooks
|
|
2245
2359
|
Stop-SnapshotFetch
|
|
2246
2360
|
foreach ($box in @($codexIconLabel, $claudeIconLabel)) {
|
|
@@ -2249,6 +2363,9 @@ $form.add_FormClosed({
|
|
|
2249
2363
|
$box.Image = $null
|
|
2250
2364
|
}
|
|
2251
2365
|
}
|
|
2366
|
+
if ($menu -and -not $menu.IsDisposed) {
|
|
2367
|
+
$menu.Dispose()
|
|
2368
|
+
}
|
|
2252
2369
|
$font.Dispose()
|
|
2253
2370
|
$symbolFont.Dispose()
|
|
2254
2371
|
if ($hitForm -and -not $hitForm.IsDisposed) {
|
|
@@ -2292,4 +2409,5 @@ if ($ClickThrough) {
|
|
|
2292
2409
|
$timer.Start()
|
|
2293
2410
|
Start-FullscreenEventHooks
|
|
2294
2411
|
$topMostTimer.Start()
|
|
2412
|
+
$menuAutoHideTimer.Start()
|
|
2295
2413
|
[System.Windows.Forms.Application]::Run($form)
|
|
@@ -9,7 +9,14 @@ property refreshTimer : missing value
|
|
|
9
9
|
property titleCommand : ""
|
|
10
10
|
property detailCommand : ""
|
|
11
11
|
property tooltipCommand : ""
|
|
12
|
+
property stateCommand : ""
|
|
12
13
|
property refreshInterval : 10
|
|
14
|
+
property activeRefreshInterval : 10
|
|
15
|
+
property readyRefreshInterval : 10
|
|
16
|
+
property idleRefreshInterval : 30
|
|
17
|
+
property fastRefreshInterval : 2
|
|
18
|
+
property fastUntilDate : missing value
|
|
19
|
+
property lastHudState : ""
|
|
13
20
|
|
|
14
21
|
on run argv
|
|
15
22
|
if (count of argv) < 2 then error "ai-battery macOS status item requires title and detail commands"
|
|
@@ -22,6 +29,7 @@ on run argv
|
|
|
22
29
|
try
|
|
23
30
|
set refreshInterval to (item 4 of argv) as real
|
|
24
31
|
end try
|
|
32
|
+
if (count of argv) is greater than or equal to 5 then set stateCommand to item 5 of argv
|
|
25
33
|
else
|
|
26
34
|
if (count of argv) is greater than or equal to 3 then
|
|
27
35
|
try
|
|
@@ -29,6 +37,7 @@ on run argv
|
|
|
29
37
|
end try
|
|
30
38
|
end if
|
|
31
39
|
end if
|
|
40
|
+
my configureIntervals_()
|
|
32
41
|
|
|
33
42
|
current application's NSApplication's sharedApplication()
|
|
34
43
|
current application's NSApp's setActivationPolicy:(current application's NSApplicationActivationPolicyAccessory)
|
|
@@ -39,6 +48,7 @@ on run argv
|
|
|
39
48
|
statusItem's button()'s setToolTip:"AI Battery"
|
|
40
49
|
|
|
41
50
|
set statusMenu to current application's NSMenu's alloc()'s initWithTitle:"AI Battery"
|
|
51
|
+
statusMenu's setDelegate:me
|
|
42
52
|
set detailItem to current application's NSMenuItem's alloc()'s initWithTitle:"Loading..." action:(missing value) keyEquivalent:""
|
|
43
53
|
detailItem's setEnabled:false
|
|
44
54
|
statusMenu's addItem:detailItem
|
|
@@ -54,16 +64,76 @@ on run argv
|
|
|
54
64
|
|
|
55
65
|
statusItem's setMenu:statusMenu
|
|
56
66
|
my refresh_(missing value)
|
|
57
|
-
|
|
58
|
-
set refreshTimer to current application's NSTimer's scheduledTimerWithTimeInterval:refreshInterval target:me selector:"refresh:" userInfo:(missing value) repeats:true
|
|
59
|
-
current application's NSRunLoop's currentRunLoop()'s addTimer:refreshTimer forMode:(current application's NSRunLoopCommonModes)
|
|
60
67
|
current application's NSApp's |run|()
|
|
61
68
|
end run
|
|
62
69
|
|
|
70
|
+
on configureIntervals_()
|
|
71
|
+
set activeRefreshInterval to refreshInterval
|
|
72
|
+
if activeRefreshInterval is greater than 10 then set activeRefreshInterval to 10
|
|
73
|
+
|
|
74
|
+
set readyRefreshInterval to refreshInterval
|
|
75
|
+
if readyRefreshInterval is less than 10 then set readyRefreshInterval to 10
|
|
76
|
+
if readyRefreshInterval is greater than 15 then set readyRefreshInterval to 15
|
|
77
|
+
|
|
78
|
+
set idleRefreshInterval to refreshInterval * 3
|
|
79
|
+
if idleRefreshInterval is less than 30 then set idleRefreshInterval to 30
|
|
80
|
+
if idleRefreshInterval is greater than 60 then set idleRefreshInterval to 60
|
|
81
|
+
|
|
82
|
+
set fastRefreshInterval to 2
|
|
83
|
+
if refreshInterval is less than 2 then set fastRefreshInterval to refreshInterval
|
|
84
|
+
end configureIntervals_
|
|
85
|
+
|
|
86
|
+
on scheduleRefresh_(secondsUntilRefresh)
|
|
87
|
+
try
|
|
88
|
+
refreshTimer's invalidate()
|
|
89
|
+
end try
|
|
90
|
+
set refreshTimer to current application's NSTimer's scheduledTimerWithTimeInterval:secondsUntilRefresh target:me selector:"refresh:" userInfo:(missing value) repeats:false
|
|
91
|
+
current application's NSRunLoop's currentRunLoop()'s addTimer:refreshTimer forMode:(current application's NSRunLoopCommonModes)
|
|
92
|
+
end scheduleRefresh_
|
|
93
|
+
|
|
94
|
+
on fastWindowActive_()
|
|
95
|
+
if fastUntilDate is missing value then return false
|
|
96
|
+
try
|
|
97
|
+
set secondsLeft to (fastUntilDate's timeIntervalSinceNow()) as real
|
|
98
|
+
if secondsLeft is greater than 0 then return true
|
|
99
|
+
end try
|
|
100
|
+
return false
|
|
101
|
+
end fastWindowActive_
|
|
102
|
+
|
|
103
|
+
on startFastWindow_(secondsToRun)
|
|
104
|
+
set fastUntilDate to current application's NSDate's dateWithTimeIntervalSinceNow:(secondsToRun)
|
|
105
|
+
end startFastWindow_
|
|
106
|
+
|
|
107
|
+
on refreshIntervalForState_(hudState)
|
|
108
|
+
if (my fastWindowActive_()) then return fastRefreshInterval
|
|
109
|
+
if hudState is "background-running" then return fastRefreshInterval
|
|
110
|
+
if hudState is "foreground-running" then return activeRefreshInterval
|
|
111
|
+
if hudState is "background-ready" then return readyRefreshInterval
|
|
112
|
+
return idleRefreshInterval
|
|
113
|
+
end refreshIntervalForState_
|
|
114
|
+
|
|
115
|
+
on updateFastWindowForState_(hudState)
|
|
116
|
+
if hudState is "" then return
|
|
117
|
+
if lastHudState is "" then
|
|
118
|
+
set lastHudState to hudState
|
|
119
|
+
return
|
|
120
|
+
end if
|
|
121
|
+
if hudState is not lastHudState then
|
|
122
|
+
set lastHudState to hudState
|
|
123
|
+
my startFastWindow_(45)
|
|
124
|
+
end if
|
|
125
|
+
end updateFastWindowForState_
|
|
126
|
+
|
|
127
|
+
on menuWillOpen_(sender)
|
|
128
|
+
my startFastWindow_(30)
|
|
129
|
+
my refresh_(missing value)
|
|
130
|
+
end menuWillOpen_
|
|
131
|
+
|
|
63
132
|
on refresh_(sender)
|
|
64
133
|
set titleText to "AI --"
|
|
65
134
|
set detailText to "AI Battery unavailable"
|
|
66
135
|
set tooltipText to "AI Battery unavailable"
|
|
136
|
+
set hudState to ""
|
|
67
137
|
set imagePath to ""
|
|
68
138
|
set menuImage to missing value
|
|
69
139
|
set detailImage to missing value
|
|
@@ -80,6 +150,12 @@ on refresh_(sender)
|
|
|
80
150
|
set tooltipText to (do shell script (tooltipCommand as text))
|
|
81
151
|
end try
|
|
82
152
|
|
|
153
|
+
if stateCommand is not "" then
|
|
154
|
+
try
|
|
155
|
+
set hudState to (do shell script (stateCommand as text))
|
|
156
|
+
end try
|
|
157
|
+
end if
|
|
158
|
+
|
|
83
159
|
if imagePath is "" then set imagePath to "AI --"
|
|
84
160
|
if detailText is "" then set detailText to "AI Battery unavailable"
|
|
85
161
|
if tooltipText is "" then set tooltipText to detailText
|
|
@@ -123,6 +199,8 @@ on refresh_(sender)
|
|
|
123
199
|
end if
|
|
124
200
|
|
|
125
201
|
statusItem's button()'s setToolTip:tooltipText
|
|
202
|
+
my updateFastWindowForState_(hudState)
|
|
203
|
+
my scheduleRefresh_(my refreshIntervalForState_(hudState))
|
|
126
204
|
end refresh_
|
|
127
205
|
|
|
128
206
|
on quit_(sender)
|
package/bin/ai-battery.js
CHANGED
|
@@ -16,6 +16,7 @@ const CLAUDE_LIMIT_HIT_TAIL_BYTES = 256 * 1024;
|
|
|
16
16
|
const CLAUDE_LIMIT_HIT_MAX_FILES = 80;
|
|
17
17
|
const CLAUDE_CODEX_CACHE_SECONDS = 60;
|
|
18
18
|
const CLAUDE_CODEX_FALLBACK_CACHE_SECONDS = 15;
|
|
19
|
+
const BACKGROUND_USAGE_RUNNING_SECONDS = 5 * 60;
|
|
19
20
|
const DIVIDER = "│";
|
|
20
21
|
const PROVIDER_DIVIDER = "┃";
|
|
21
22
|
const ANSI_RE = /\u001b\[[0-?]*[ -/]*[@-~]/g;
|
|
@@ -48,6 +49,8 @@ const MENU_BAR_WARNING = "#FF9F0A";
|
|
|
48
49
|
const MENU_BAR_DANGER = "#FF453A";
|
|
49
50
|
const MENU_BAR_OUTLINE_OPACITY = "0.42";
|
|
50
51
|
const MENU_DETAIL_OUTLINE_OPACITY = "0.14";
|
|
52
|
+
const MENU_DIM_TEXT = "#A1A1AA";
|
|
53
|
+
const MENU_DIM_OUTLINE_OPACITY = "0.24";
|
|
51
54
|
|
|
52
55
|
function parseArgs(argv) {
|
|
53
56
|
const args = {
|
|
@@ -65,6 +68,7 @@ function parseArgs(argv) {
|
|
|
65
68
|
menuBar: false,
|
|
66
69
|
menuBarImage: false,
|
|
67
70
|
menuDetailImage: false,
|
|
71
|
+
hudState: false,
|
|
68
72
|
silent: false,
|
|
69
73
|
force: false,
|
|
70
74
|
header: true,
|
|
@@ -129,6 +133,9 @@ function parseArgs(argv) {
|
|
|
129
133
|
} else if (arg === "--menu-detail-image") {
|
|
130
134
|
args.menuDetailImage = true;
|
|
131
135
|
args.style = "plain";
|
|
136
|
+
} else if (arg === "--hud-state") {
|
|
137
|
+
args.hudState = true;
|
|
138
|
+
args.style = "plain";
|
|
132
139
|
} else if (arg === "--version" || arg === "-v") {
|
|
133
140
|
args.version = true;
|
|
134
141
|
} else if (arg === "--help" || arg === "-h") {
|
|
@@ -2029,6 +2036,28 @@ function codexSessionMeta(filePath) {
|
|
|
2029
2036
|
}
|
|
2030
2037
|
}
|
|
2031
2038
|
|
|
2039
|
+
function codexUsageLooksBackground(meta) {
|
|
2040
|
+
if (!meta) return false;
|
|
2041
|
+
const text = [
|
|
2042
|
+
meta.originator,
|
|
2043
|
+
meta.source,
|
|
2044
|
+
meta.client?.name,
|
|
2045
|
+
meta.clientInfo?.name,
|
|
2046
|
+
meta.client_info?.name
|
|
2047
|
+
].filter(Boolean).join(" ").toLowerCase();
|
|
2048
|
+
if (!text) return false;
|
|
2049
|
+
if (text.includes("codex-tui") || /\bcli\b/.test(text)) return false;
|
|
2050
|
+
return (
|
|
2051
|
+
text.includes("remote")
|
|
2052
|
+
|| text.includes("mobile")
|
|
2053
|
+
|| text.includes("desktop")
|
|
2054
|
+
|| text.includes("codex app")
|
|
2055
|
+
|| text.includes("codex_app")
|
|
2056
|
+
|| text.includes("vscode")
|
|
2057
|
+
|| text.includes("vs code")
|
|
2058
|
+
);
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2032
2061
|
function sameOrNestedPath(a, b) {
|
|
2033
2062
|
if (!a || !b) return false;
|
|
2034
2063
|
const left = path.resolve(a);
|
|
@@ -2245,6 +2274,21 @@ function claudeCommandIsBackground(cmdline) {
|
|
|
2245
2274
|
|| cmdline.includes("--bg-spare");
|
|
2246
2275
|
}
|
|
2247
2276
|
|
|
2277
|
+
function codexCommandIsBackground(cmdline) {
|
|
2278
|
+
const tokens = commandLineTokens(cmdline);
|
|
2279
|
+
if (!tokens.length) return false;
|
|
2280
|
+
|
|
2281
|
+
let commandIndex = -1;
|
|
2282
|
+
const firstBase = commandTokenBasename(tokens[0]).toLowerCase();
|
|
2283
|
+
if (tokenMatchesProviderExecutable(tokens[0], "codex")) {
|
|
2284
|
+
commandIndex = 0;
|
|
2285
|
+
} else if (/^node(?:\.exe)?$/i.test(firstBase) && tokenMatchesProviderExecutable(tokens[1], "codex")) {
|
|
2286
|
+
commandIndex = 1;
|
|
2287
|
+
}
|
|
2288
|
+
|
|
2289
|
+
return commandIndex >= 0 && tokens[commandIndex + 1] === "app-server";
|
|
2290
|
+
}
|
|
2291
|
+
|
|
2248
2292
|
function commandLineTokens(cmdline) {
|
|
2249
2293
|
return (String(cmdline || "").match(/"(?:(?:\\.|[^"\\])*)"|'[^']*'|\S+/g) || [])
|
|
2250
2294
|
.map((token) => token.replace(/^"(.*)"$/s, "$1").replace(/^'(.*)'$/s, "$1").replace(/\\"/g, "\""))
|
|
@@ -2297,6 +2341,7 @@ function aiBatteryRunnerCommandTokens(tokens) {
|
|
|
2297
2341
|
|
|
2298
2342
|
function commandMatchesProvider(cmdline, provider) {
|
|
2299
2343
|
const text = String(cmdline || "");
|
|
2344
|
+
if (provider === "codex" && codexCommandIsBackground(text)) return false;
|
|
2300
2345
|
if (provider === "claude" && claudeCommandIsBackground(text)) return false;
|
|
2301
2346
|
if (
|
|
2302
2347
|
text.includes("ai-battery.js")
|
|
@@ -2476,6 +2521,10 @@ function isProviderRunning(provider) {
|
|
|
2476
2521
|
return providerRunningInProcesses(provider, scanProcessCommands());
|
|
2477
2522
|
}
|
|
2478
2523
|
|
|
2524
|
+
function codexBackgroundReadyInProcesses(processes) {
|
|
2525
|
+
return processes.some((proc) => codexCommandIsBackground(proc.cmdline));
|
|
2526
|
+
}
|
|
2527
|
+
|
|
2479
2528
|
function readStdin() {
|
|
2480
2529
|
return new Promise((resolve, reject) => {
|
|
2481
2530
|
let input = "";
|
|
@@ -2987,14 +3036,18 @@ function readCodex(options = {}) {
|
|
|
2987
3036
|
writeScanCache("codex-status", scan);
|
|
2988
3037
|
}
|
|
2989
3038
|
|
|
3039
|
+
const processes = options.includeRunning === false ? null : scanProcessCommands();
|
|
2990
3040
|
const running = typeof options.runningOverride === "boolean"
|
|
2991
3041
|
? options.runningOverride
|
|
2992
3042
|
: (
|
|
2993
3043
|
options.includeRunning === false
|
|
2994
3044
|
? Boolean(scan.running)
|
|
2995
|
-
:
|
|
3045
|
+
: providerRunningInProcesses("codex", processes)
|
|
2996
3046
|
);
|
|
2997
|
-
const
|
|
3047
|
+
const backgroundReady = processes
|
|
3048
|
+
? codexBackgroundReadyInProcesses(processes)
|
|
3049
|
+
: Boolean(scan.backgroundReady);
|
|
3050
|
+
const result = { ...scan, running, backgroundReady };
|
|
2998
3051
|
if (result.ok) result.ageSeconds = cacheAgeSeconds(result.timestamp ?? null);
|
|
2999
3052
|
return result;
|
|
3000
3053
|
}
|
|
@@ -3057,18 +3110,24 @@ function scanCodexStatus() {
|
|
|
3057
3110
|
|
|
3058
3111
|
const primary = normalizeLimit(rateLimits.primary);
|
|
3059
3112
|
const secondary = normalizeLimit(rateLimits.secondary);
|
|
3113
|
+
const sessionMeta = codexSessionMeta(match.file);
|
|
3114
|
+
const timestamp = match.json.timestamp ?? null;
|
|
3060
3115
|
|
|
3061
3116
|
return {
|
|
3062
3117
|
provider: "codex",
|
|
3063
3118
|
ok: true,
|
|
3064
3119
|
planType: rateLimits.plan_type ?? null,
|
|
3065
3120
|
limitId: rateLimits.limit_id ?? null,
|
|
3066
|
-
timestamp
|
|
3121
|
+
timestamp,
|
|
3067
3122
|
source: match.file,
|
|
3068
3123
|
percentRemaining: primary?.remainingPercent ?? null,
|
|
3069
3124
|
percentUsed: primary?.usedPercent ?? null,
|
|
3070
3125
|
primary,
|
|
3071
3126
|
secondary,
|
|
3127
|
+
usageUpdate: {
|
|
3128
|
+
timestamp,
|
|
3129
|
+
background: codexUsageLooksBackground(sessionMeta)
|
|
3130
|
+
},
|
|
3072
3131
|
approvalPolicy,
|
|
3073
3132
|
sandboxMode,
|
|
3074
3133
|
collaborationMode,
|
|
@@ -3741,6 +3800,14 @@ function renderMenuBar(snapshot) {
|
|
|
3741
3800
|
return parts.length ? parts.join(" ") : "AI --";
|
|
3742
3801
|
}
|
|
3743
3802
|
|
|
3803
|
+
function renderHudState(snapshot) {
|
|
3804
|
+
const results = snapshot.results.filter(Boolean);
|
|
3805
|
+
if (results.some((result) => result.running === true)) return "foreground-running";
|
|
3806
|
+
if (results.some(codexBackgroundUsageRunning)) return "background-running";
|
|
3807
|
+
if (results.some((result) => result.provider === "codex" && result.backgroundReady === true)) return "background-ready";
|
|
3808
|
+
return "idle";
|
|
3809
|
+
}
|
|
3810
|
+
|
|
3744
3811
|
function svgEscape(value) {
|
|
3745
3812
|
return String(value)
|
|
3746
3813
|
.replace(/&/g, "&")
|
|
@@ -3923,17 +3990,11 @@ function imageDataUri(filePath) {
|
|
|
3923
3990
|
return `data:${mime};base64,${fs.readFileSync(filePath).toString("base64")}`;
|
|
3924
3991
|
}
|
|
3925
3992
|
|
|
3926
|
-
function
|
|
3993
|
+
function menuBatteryColor(percent, running = true) {
|
|
3994
|
+
if (!running) return MENU_DIM_TEXT;
|
|
3927
3995
|
if (typeof percent !== "number") return MENU_BAR_WHITE;
|
|
3928
3996
|
if (percent <= 20) return MENU_BAR_DANGER;
|
|
3929
3997
|
if (percent <= 40) return MENU_BAR_WARNING;
|
|
3930
|
-
return MENU_BAR_WHITE;
|
|
3931
|
-
}
|
|
3932
|
-
|
|
3933
|
-
function menuDetailBatteryColor(percent) {
|
|
3934
|
-
if (typeof percent !== "number") return "none";
|
|
3935
|
-
if (percent <= 20) return MENU_BAR_DANGER;
|
|
3936
|
-
if (percent <= 40) return MENU_BAR_WARNING;
|
|
3937
3998
|
return MENU_DETAIL_GREEN;
|
|
3938
3999
|
}
|
|
3939
4000
|
|
|
@@ -3980,6 +4041,7 @@ function renderMenuBarImage(snapshot) {
|
|
|
3980
4041
|
|
|
3981
4042
|
visibleResults.forEach((result, index) => {
|
|
3982
4043
|
const x = startX + (index * providerWidth);
|
|
4044
|
+
const running = result.running === true;
|
|
3983
4045
|
const percent = typeof result.percentRemaining === "number" ? clamp(result.percentRemaining, 0, 100) : null;
|
|
3984
4046
|
const meterX = x + 23;
|
|
3985
4047
|
const meterY = 3;
|
|
@@ -3991,16 +4053,18 @@ function renderMenuBarImage(snapshot) {
|
|
|
3991
4053
|
const meterInnerWidth = meterWidth - 4;
|
|
3992
4054
|
const meterInnerHeight = meterHeight - 3.4;
|
|
3993
4055
|
const fillWidth = percent === null ? 0 : Math.max(percent > 0 ? 2 : 0, Math.round((percent / 100) * meterInnerWidth));
|
|
3994
|
-
const fill =
|
|
4056
|
+
const fill = menuBatteryColor(percent, running);
|
|
3995
4057
|
const label = percent === null ? "--" : `${Math.round(percent)}%`;
|
|
3996
4058
|
const labelX = meterX + (meterWidth / 2);
|
|
4059
|
+
const textFill = running ? MENU_BAR_WHITE : MENU_DIM_TEXT;
|
|
4060
|
+
const outlineOpacity = running ? MENU_BAR_OUTLINE_OPACITY : MENU_DIM_OUTLINE_OPACITY;
|
|
3997
4061
|
|
|
3998
4062
|
items.push(menuBarImageIcon(result.provider, x, 3));
|
|
3999
|
-
items.push(`<rect x="${meterX}" y="${meterY}" width="${meterWidth}" height="${meterHeight}" rx="2.5" fill="none" stroke="${MENU_BAR_WHITE}" stroke-opacity="${
|
|
4063
|
+
items.push(`<rect x="${meterX}" y="${meterY}" width="${meterWidth}" height="${meterHeight}" rx="2.5" fill="none" stroke="${MENU_BAR_WHITE}" stroke-opacity="${outlineOpacity}" stroke-width="${meterStroke}"/>`);
|
|
4000
4064
|
if (fillWidth > 0) {
|
|
4001
4065
|
items.push(`<rect x="${meterInnerX}" y="${meterInnerY}" width="${fillWidth}" height="${meterInnerHeight}" rx="0.8" fill="${fill}"/>`);
|
|
4002
4066
|
}
|
|
4003
|
-
items.push(`<text x="${labelX}" y="21" text-anchor="middle" font-family="-apple-system, BlinkMacSystemFont, 'SF Pro Text', sans-serif" font-size="9.5" font-weight="650" fill="${
|
|
4067
|
+
items.push(`<text x="${labelX}" y="21" text-anchor="middle" font-family="-apple-system, BlinkMacSystemFont, 'SF Pro Text', sans-serif" font-size="9.5" font-weight="650" fill="${textFill}">${svgEscape(label)}</text>`);
|
|
4004
4068
|
});
|
|
4005
4069
|
|
|
4006
4070
|
if (!items.length) {
|
|
@@ -4043,11 +4107,44 @@ function menuDetailMetaText(result) {
|
|
|
4043
4107
|
return parts.join(" · ");
|
|
4044
4108
|
}
|
|
4045
4109
|
|
|
4110
|
+
function shortAgeText(timestamp) {
|
|
4111
|
+
const seconds = cacheAgeSeconds(timestamp);
|
|
4112
|
+
if (typeof seconds !== "number") return null;
|
|
4113
|
+
if (seconds < 60) return `${seconds}s ago`;
|
|
4114
|
+
const minutes = Math.floor(seconds / 60);
|
|
4115
|
+
if (minutes < 60) return `${minutes}m ago`;
|
|
4116
|
+
const hours = Math.floor(minutes / 60);
|
|
4117
|
+
if (hours < 24) return `${hours}h ago`;
|
|
4118
|
+
const days = Math.floor(hours / 24);
|
|
4119
|
+
if (days < 7) return `${days}d ago`;
|
|
4120
|
+
return new Date(timestamp).toISOString().slice(0, 10);
|
|
4121
|
+
}
|
|
4122
|
+
|
|
4123
|
+
function codexBackgroundUsageRunning(result) {
|
|
4124
|
+
if (result?.provider !== "codex" || result.running === true) return false;
|
|
4125
|
+
if (result.usageUpdate?.background !== true) return false;
|
|
4126
|
+
const seconds = cacheAgeSeconds(result.usageUpdate?.timestamp ?? result.timestamp ?? null);
|
|
4127
|
+
return typeof seconds === "number" && seconds <= BACKGROUND_USAGE_RUNNING_SECONDS;
|
|
4128
|
+
}
|
|
4129
|
+
|
|
4130
|
+
function menuDetailUsageUpdateText(result) {
|
|
4131
|
+
if (result.provider !== "codex" || result.running === true) return null;
|
|
4132
|
+
if (codexBackgroundUsageRunning(result)) {
|
|
4133
|
+
const timestamp = result.usageUpdate?.timestamp ?? result.timestamp ?? null;
|
|
4134
|
+
const age = shortAgeText(timestamp);
|
|
4135
|
+
if (age) return `local idle · background running · updated ${age}`;
|
|
4136
|
+
}
|
|
4137
|
+
if (result.backgroundReady === true) return "local idle · background ready";
|
|
4138
|
+
return null;
|
|
4139
|
+
}
|
|
4140
|
+
|
|
4046
4141
|
function renderMenuDetailImage(snapshot) {
|
|
4047
4142
|
const visibleResults = snapshot.results.filter(Boolean);
|
|
4048
4143
|
const rows = visibleResults.length ? visibleResults : [{ provider: "ai", ok: false }];
|
|
4049
4144
|
const width = 392;
|
|
4050
|
-
const
|
|
4145
|
+
const usageTexts = rows.map(menuDetailUsageUpdateText);
|
|
4146
|
+
const hasUsageText = usageTexts.some(Boolean);
|
|
4147
|
+
const rowHeight = hasUsageText ? 46 : 36;
|
|
4051
4148
|
const verticalPadding = 8;
|
|
4052
4149
|
const height = (rows.length * rowHeight) + (verticalPadding * 2);
|
|
4053
4150
|
const barX = 86;
|
|
@@ -4057,23 +4154,33 @@ function renderMenuDetailImage(snapshot) {
|
|
|
4057
4154
|
|
|
4058
4155
|
rows.forEach((result, index) => {
|
|
4059
4156
|
const y = verticalPadding + (index * rowHeight);
|
|
4060
|
-
const baseline = y + 22;
|
|
4157
|
+
const baseline = y + (hasUsageText ? 19 : 22);
|
|
4158
|
+
const usageBaseline = y + 38;
|
|
4159
|
+
const usageText = usageTexts[index];
|
|
4061
4160
|
const provider = result.provider === "codex" ? "Codex" : result.provider === "claude" ? "Claude" : "AI";
|
|
4161
|
+
const running = result.running === true;
|
|
4062
4162
|
const percent = typeof result.percentRemaining === "number" ? clamp(result.percentRemaining, 0, 100) : null;
|
|
4063
4163
|
const fillWidth = percent === null ? 0 : Math.max(percent > 0 ? 3 : 0, Math.round((percent / 100) * barWidth));
|
|
4064
|
-
const fill =
|
|
4164
|
+
const fill = menuBatteryColor(percent, running);
|
|
4065
4165
|
const percentText = percent === null ? "--%" : `${Math.round(percent)}%`;
|
|
4066
4166
|
const metaText = result.ok ? menuDetailMetaText(result) : "unavailable";
|
|
4067
4167
|
const barY = baseline - barHeight;
|
|
4168
|
+
const primaryFill = running ? "#F5F5F7" : MENU_DIM_TEXT;
|
|
4169
|
+
const metaFill = running ? MENU_DIM_TEXT : "#8E8E93";
|
|
4170
|
+
const trackOpacity = running ? "0.10" : "0.06";
|
|
4171
|
+
const outlineOpacity = running ? MENU_DETAIL_OUTLINE_OPACITY : MENU_DIM_OUTLINE_OPACITY;
|
|
4068
4172
|
|
|
4069
|
-
items.push(`<text x="14" y="${baseline}" font-family="-apple-system, BlinkMacSystemFont, 'SF Pro Text', sans-serif" font-size="13" font-weight="650" fill="
|
|
4070
|
-
items.push(`<rect x="${barX}" y="${barY}" width="${barWidth}" height="${barHeight}" rx="4" fill="#FFFFFF" fill-opacity="
|
|
4173
|
+
items.push(`<text x="14" y="${baseline}" font-family="-apple-system, BlinkMacSystemFont, 'SF Pro Text', sans-serif" font-size="13" font-weight="650" fill="${primaryFill}">${svgEscape(provider)}</text>`);
|
|
4174
|
+
items.push(`<rect x="${barX}" y="${barY}" width="${barWidth}" height="${barHeight}" rx="4" fill="#FFFFFF" fill-opacity="${trackOpacity}" stroke="#FFFFFF" stroke-opacity="${outlineOpacity}" stroke-width="1"/>`);
|
|
4071
4175
|
if (fillWidth > 0) {
|
|
4072
4176
|
items.push(`<rect x="${barX}" y="${barY}" width="${fillWidth}" height="${barHeight}" rx="4" fill="${fill}"/>`);
|
|
4073
4177
|
}
|
|
4074
|
-
items.push(`<text x="${barX + barWidth + 12}" y="${baseline}" font-family="-apple-system, BlinkMacSystemFont, 'SF Pro Text', sans-serif" font-size="13" font-weight="700" fill="
|
|
4178
|
+
items.push(`<text x="${barX + barWidth + 12}" y="${baseline}" font-family="-apple-system, BlinkMacSystemFont, 'SF Pro Text', sans-serif" font-size="13" font-weight="700" fill="${primaryFill}">${svgEscape(percentText)}</text>`);
|
|
4075
4179
|
if (metaText) {
|
|
4076
|
-
items.push(`<text x="${width - 14}" y="${baseline}" text-anchor="end" font-family="-apple-system, BlinkMacSystemFont, 'SF Pro Text', sans-serif" font-size="13" font-weight="550" fill="
|
|
4180
|
+
items.push(`<text x="${width - 14}" y="${baseline}" text-anchor="end" font-family="-apple-system, BlinkMacSystemFont, 'SF Pro Text', sans-serif" font-size="13" font-weight="550" fill="${metaFill}">${svgEscape(metaText)}</text>`);
|
|
4181
|
+
}
|
|
4182
|
+
if (usageText) {
|
|
4183
|
+
items.push(`<text x="${width - 14}" y="${usageBaseline}" text-anchor="end" font-family="-apple-system, BlinkMacSystemFont, 'SF Pro Text', sans-serif" font-size="10.5" font-weight="500" fill="#8E8E93">${svgEscape(usageText)}</text>`);
|
|
4077
4184
|
}
|
|
4078
4185
|
});
|
|
4079
4186
|
|
|
@@ -4109,6 +4216,7 @@ function applyLeftPadding(output, args) {
|
|
|
4109
4216
|
|
|
4110
4217
|
function render(snapshot, args) {
|
|
4111
4218
|
if (args.json) return JSON.stringify(snapshot, null, 2);
|
|
4219
|
+
if (args.hudState) return renderHudState(snapshot);
|
|
4112
4220
|
if (args.menuBarImage) return renderMenuBarImage(snapshot);
|
|
4113
4221
|
if (args.menuDetailImage) return renderMenuDetailImage(snapshot);
|
|
4114
4222
|
if (args.menuBar) return renderMenuBar(snapshot);
|
|
@@ -4469,6 +4577,7 @@ export {
|
|
|
4469
4577
|
bar,
|
|
4470
4578
|
claudeHeader,
|
|
4471
4579
|
commandMatchesProvider,
|
|
4580
|
+
codexBackgroundReadyInProcesses,
|
|
4472
4581
|
codexStatusLineMatches,
|
|
4473
4582
|
codexWrapperScript,
|
|
4474
4583
|
firstPercentValue,
|
|
@@ -4486,6 +4595,9 @@ export {
|
|
|
4486
4595
|
removeAiBatteryShellPathBlock,
|
|
4487
4596
|
percentValue,
|
|
4488
4597
|
providerRunningInProcesses,
|
|
4598
|
+
renderHudState,
|
|
4599
|
+
renderMenuBarImage,
|
|
4600
|
+
renderMenuDetailImage,
|
|
4489
4601
|
rowptyDiagnostic,
|
|
4490
4602
|
sameFilePath,
|
|
4491
4603
|
visibleWidth,
|