1// targetPid, targetTitle, and reply are supplied by the one-shot native helper.
2let finished = false;
3let target;
4const deadline = new QTimer();
5deadline.singleShot = true;
6deadline.interval = 4000;
7function finish(activated) {
8 if (finished) return;
9 finished = true;
10 deadline.stop();
11 reply({ activated });
12}
13function confirm() {
14 if (target && workspace.activeWindow === target) finish(true);
15}
16function 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}
28function watch(window) {
29 if (window.pid === targetPid) window.captionChanged.connect(activate);
30}
31workspace.windowAdded.connect((window) => {
32 watch(window);
33 activate();
34});
35workspace.windowActivated.connect(confirm);
36workspace.windowList().forEach(watch);
37deadline.timeout.connect(() => finish(false));
38deadline.start();
39activate();