@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
js 39 lines 1.07 KB
Raw
1 // targetPid, targetTitle, and reply are supplied by the one-shot native helper.
2 let finished = false;
3 let target;
4 const deadline = new QTimer();
5 deadline.singleShot = true;
6 deadline.interval = 4000;
7 function finish(activated) {
8 if (finished) return;
9 finished = true;
10 deadline.stop();
11 reply({ activated });
12 }
13 function confirm() {
14 if (target && workspace.activeWindow === target) finish(true);
15 }
16 function activate() {
17 if (finished) return;
18 const matches = workspace
19 .windowList()
20 .filter((w) => w.pid === targetPid && w.caption === targetTitle);
21 if (matches.length > 1) return finish(false);
22 if (matches.length !== 1) return;
23 target = matches[0];
24 target.minimized = false;
25 workspace.activeWindow = target;
26 confirm();
27 }
28 function watch(window) {
29 if (window.pid === targetPid) window.captionChanged.connect(activate);
30 }
31 workspace.windowAdded.connect((window) => {
32 watch(window);
33 activate();
34 });
35 workspace.windowActivated.connect(confirm);
36 workspace.windowList().forEach(watch);
37 deadline.timeout.connect(() => finish(false));
38 deadline.start();
39 activate();