@sirenodeck/sirenodeck 0.2.5 → 0.2.7
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/dist/capture-file-C11RW9NA.mjs +47 -0
- package/dist/darwin-B1ECvuGg.mjs +15 -0
- package/dist/darwin-Bs7hyOFv.mjs +78 -0
- package/dist/darwin-Cm-RiXMK.mjs +56 -0
- package/dist/darwin-DCTL6wDT.mjs +39 -0
- package/dist/darwin-RFhh5cL5.mjs +122 -0
- package/dist/install-yAoVCzK1.mjs +198 -0
- package/dist/linux-BDSwIJbc.mjs +577 -0
- package/dist/linux-CS_pCg0V.mjs +158 -0
- package/dist/linux-Dq07aXcR.mjs +119 -0
- package/dist/linux-OyPmXbFE.mjs +51 -0
- package/dist/live-metrics-CMf02ncg.mjs +975 -0
- package/dist/main.mjs +170 -10
- package/dist/spawn-IWeEQPpd.mjs +69 -0
- package/dist/windows-CRWdUgCn.mjs +45 -0
- package/dist/windows-CTAfiwO_.mjs +361 -0
- package/dist/windows-DeS97h4f.mjs +74 -0
- package/dist/windows-zhWiv_h8.mjs +55 -0
- package/package.json +2 -2
- package/src/cli/commands/run.ts +28 -1
- package/src/cli/commands/start.ts +17 -0
- package/src/cli/startup-display.ts +1 -1
- package/src/core/settings.ts +5 -3
- package/src/device/black-frame.ts +2 -7
- package/src/outputClient/real.ts +2 -0
|
@@ -0,0 +1,577 @@
|
|
|
1
|
+
import { a as withTimeout, o as ProviderError, s as parseCombo } from "./main.mjs";
|
|
2
|
+
import { t as createDarwinClipboardProvider } from "./darwin-DCTL6wDT.mjs";
|
|
3
|
+
//#region src/system/providers/clipboard/linux.ts
|
|
4
|
+
const WL_COPY_TOOL = "wl-copy";
|
|
5
|
+
const WL_PASTE_TOOL = "wl-paste";
|
|
6
|
+
const XCLIP_TOOL = "xclip";
|
|
7
|
+
const XSEL_TOOL = "xsel";
|
|
8
|
+
const probeTool$1 = async (executor, tool, extraFsProbe) => {
|
|
9
|
+
const result = await executor.run("which", [tool]);
|
|
10
|
+
if (result.exitCode === 0 && result.stdout.trim().length > 0) return true;
|
|
11
|
+
return extraFsProbe?.(tool) === true;
|
|
12
|
+
};
|
|
13
|
+
const shellQuote$1 = (value) => `'${value.replace(/'/g, "'\\''")}'`;
|
|
14
|
+
const createLinuxClipboardProvider = (options) => {
|
|
15
|
+
const { executor, logger, timeoutMs: timeoutMsOption } = options;
|
|
16
|
+
const timeoutMs = timeoutMsOption ?? 500;
|
|
17
|
+
const isX11 = options.env?.["WAYLAND_DISPLAY"] === void 0 && options.env?.["DISPLAY"] !== void 0;
|
|
18
|
+
const tools = isX11 ? [XCLIP_TOOL, XSEL_TOOL] : [WL_COPY_TOOL];
|
|
19
|
+
let selectedTool = tools[0];
|
|
20
|
+
let disposed = false;
|
|
21
|
+
const stop = async () => {
|
|
22
|
+
disposed = true;
|
|
23
|
+
};
|
|
24
|
+
const writeText = async (text) => {
|
|
25
|
+
if (disposed) throw new Error("Clipboard provider is disposed");
|
|
26
|
+
const command = isX11 ? selectedTool === XSEL_TOOL ? `printf '%s' ${shellQuote$1(text)} | ${XSEL_TOOL} --clipboard --input` : `printf '%s' ${shellQuote$1(text)} | ${XCLIP_TOOL} -selection clipboard` : `printf '%s' ${shellQuote$1(text)} | ${WL_COPY_TOOL} -o`;
|
|
27
|
+
const startedAt = Date.now();
|
|
28
|
+
logger.info({
|
|
29
|
+
step: "clipboard.writeText",
|
|
30
|
+
command,
|
|
31
|
+
textPreview: text.slice(0, 24)
|
|
32
|
+
}, "clipboard: invoking tool");
|
|
33
|
+
const result = await withTimeout(executor.run("sh", ["-c", command]), timeoutMs + 2500);
|
|
34
|
+
logger.info({
|
|
35
|
+
step: "clipboard.writeText",
|
|
36
|
+
exitCode: result.exitCode,
|
|
37
|
+
stderr: result.stderr.trim(),
|
|
38
|
+
elapsedMs: Date.now() - startedAt
|
|
39
|
+
}, "clipboard: tool returned");
|
|
40
|
+
if (result.exitCode !== 0) {
|
|
41
|
+
logger.warn({ stderr: result.stderr.trim() }, "clipboard: write failed");
|
|
42
|
+
throw new ProviderError("EXEC_FAILED", `clipboard write failed with ${tools.join(" or ")}: ${result.stderr.trim() || "unknown error"}`);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const readText = async () => {
|
|
46
|
+
if (disposed) throw new Error("Clipboard provider is disposed");
|
|
47
|
+
try {
|
|
48
|
+
if (!await ensureProbed()) return "";
|
|
49
|
+
const startedAt = Date.now();
|
|
50
|
+
const result = await withTimeout(isX11 ? selectedTool === XSEL_TOOL ? executor.run(XSEL_TOOL, ["--clipboard", "--output"]) : executor.run(XCLIP_TOOL, [
|
|
51
|
+
"-selection",
|
|
52
|
+
"clipboard",
|
|
53
|
+
"-out"
|
|
54
|
+
]) : executor.run(WL_PASTE_TOOL, []), timeoutMs + 2500);
|
|
55
|
+
logger.info({
|
|
56
|
+
step: "clipboard.readText",
|
|
57
|
+
exitCode: result.exitCode,
|
|
58
|
+
stdoutPreview: result.stdout.slice(0, 32),
|
|
59
|
+
elapsedMs: Date.now() - startedAt
|
|
60
|
+
}, "clipboard: wl-paste returned");
|
|
61
|
+
if (result.exitCode !== 0) return "";
|
|
62
|
+
return result.stdout;
|
|
63
|
+
} catch {
|
|
64
|
+
return "";
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
let _probeDone = false;
|
|
68
|
+
let _probeOk = false;
|
|
69
|
+
const ensureProbed = async () => {
|
|
70
|
+
if (_probeDone) return _probeOk;
|
|
71
|
+
_probeOk = false;
|
|
72
|
+
for (const tool of tools) if (await probeTool$1(executor, tool, options.extraFsProbe)) {
|
|
73
|
+
selectedTool = tool;
|
|
74
|
+
_probeOk = true;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
_probeDone = true;
|
|
78
|
+
if (!_probeOk) logger.warn({ tools }, "clipboard tool not found on PATH; clipboard will throw ProviderError");
|
|
79
|
+
return _probeOk;
|
|
80
|
+
};
|
|
81
|
+
ensureProbed();
|
|
82
|
+
return {
|
|
83
|
+
writeText: async (text) => {
|
|
84
|
+
if (!await ensureProbed()) throw new ProviderError("NOT_AVAILABLE", isX11 ? "none of xclip or xsel found on PATH" : "wl-copy not found on PATH; install the wl-clipboard package");
|
|
85
|
+
await writeText(text);
|
|
86
|
+
},
|
|
87
|
+
readText,
|
|
88
|
+
stop
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/system/providers/clipboard/windows.ts
|
|
93
|
+
const encodePSCommand = (script) => {
|
|
94
|
+
return Buffer.from(script, "utf16le").toString("base64");
|
|
95
|
+
};
|
|
96
|
+
const escapeForPowerShellSingleQuote = (s) => s.replace(/'/g, "''");
|
|
97
|
+
const escapeForDoubleQuote = (s) => s.replace(/[\\"$`]/g, "``$&");
|
|
98
|
+
const createWindowsClipboardProvider = (options) => {
|
|
99
|
+
const { executor, logger, timeoutMs: timeoutMsOption } = options;
|
|
100
|
+
const timeoutMs = timeoutMsOption ?? 500;
|
|
101
|
+
let disposed = false;
|
|
102
|
+
const stop = async () => {
|
|
103
|
+
disposed = true;
|
|
104
|
+
};
|
|
105
|
+
const writeText = async (text) => {
|
|
106
|
+
if (disposed) throw new Error("Clipboard provider is disposed");
|
|
107
|
+
const escaped = escapeForDoubleQuote(text);
|
|
108
|
+
const script = `Set-Clipboard -Value ${`'${escapeForPowerShellSingleQuote(escaped)}'`}`;
|
|
109
|
+
const encoded = encodePSCommand(script);
|
|
110
|
+
const result = await withTimeout(executor.run("powershell", [
|
|
111
|
+
"-NoProfile",
|
|
112
|
+
"-EncodedCommand",
|
|
113
|
+
encoded
|
|
114
|
+
], { timeoutMs }), timeoutMs + 500);
|
|
115
|
+
if (result.exitCode !== 0) {
|
|
116
|
+
logger.warn({ stderr: result.stderr }, "clipboard: powershell failed");
|
|
117
|
+
throw new ProviderError("EXEC_FAILED", `clipboard write failed: ${result.stderr.trim() || "unknown error"}`);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const readText = async () => {
|
|
121
|
+
if (disposed) throw new Error("Clipboard provider is disposed");
|
|
122
|
+
try {
|
|
123
|
+
const result = await withTimeout(executor.run("powershell", [
|
|
124
|
+
"-NoProfile",
|
|
125
|
+
"-Command",
|
|
126
|
+
"Get-Clipboard"
|
|
127
|
+
], { timeoutMs }), timeoutMs + 500);
|
|
128
|
+
if (result.exitCode === 0) return result.stdout;
|
|
129
|
+
} catch {}
|
|
130
|
+
return "";
|
|
131
|
+
};
|
|
132
|
+
return {
|
|
133
|
+
writeText,
|
|
134
|
+
readText,
|
|
135
|
+
stop
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/system/providers/clipboard.ts
|
|
140
|
+
const createNullClipboardProvider = (logger) => {
|
|
141
|
+
if (logger) logger.warn({ provider: "clipboard" }, "OS clipboard provider unavailable, using null provider");
|
|
142
|
+
return {
|
|
143
|
+
async writeText(_text) {
|
|
144
|
+
throw new ProviderError("NOT_AVAILABLE", "Clipboard provider not available on this platform");
|
|
145
|
+
},
|
|
146
|
+
async readText() {
|
|
147
|
+
throw new ProviderError("NOT_AVAILABLE", "Clipboard provider not available on this platform");
|
|
148
|
+
},
|
|
149
|
+
async stop() {}
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
const createClipboardProvider = (options) => {
|
|
153
|
+
options.logger.child({ component: "clipboard" });
|
|
154
|
+
const platform = options.platform ?? process.platform;
|
|
155
|
+
if (platform === "linux") return createLinuxClipboardProvider({
|
|
156
|
+
executor: options.executor,
|
|
157
|
+
...options.env !== void 0 ? { env: options.env } : {},
|
|
158
|
+
logger: options.logger,
|
|
159
|
+
...options.extraFsProbe !== void 0 ? { extraFsProbe: options.extraFsProbe } : {}
|
|
160
|
+
});
|
|
161
|
+
if (platform === "darwin") return createDarwinClipboardProvider({
|
|
162
|
+
executor: options.executor,
|
|
163
|
+
logger: options.logger
|
|
164
|
+
});
|
|
165
|
+
if (platform === "win32") return createWindowsClipboardProvider({
|
|
166
|
+
executor: options.executor,
|
|
167
|
+
logger: options.logger
|
|
168
|
+
});
|
|
169
|
+
createNullClipboardProvider(options.logger);
|
|
170
|
+
throw new ProviderError("UNSUPPORTED_PLATFORM", `Clipboard provider not implemented for platform '${platform}' in this build`);
|
|
171
|
+
};
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/system/providers/key-macro/linux.ts
|
|
174
|
+
const YDOTOOL_TOOL = "ydotool";
|
|
175
|
+
const WTYPE_TOOL = "wtype";
|
|
176
|
+
const YDOTOOL_CLIPBOARD_PRE_DELAY_MS = 50;
|
|
177
|
+
const SC_LEFTCTRL = 29;
|
|
178
|
+
const SC_LEFTALT = 56;
|
|
179
|
+
const SC_LEFTSHIFT = 42;
|
|
180
|
+
const SC_LEFTMETA = 125;
|
|
181
|
+
const SC_ESC = 1;
|
|
182
|
+
const SC_1 = 2;
|
|
183
|
+
const SC_2 = 3;
|
|
184
|
+
const SC_3 = 4;
|
|
185
|
+
const SC_4 = 5;
|
|
186
|
+
const SC_5 = 6;
|
|
187
|
+
const SC_6 = 7;
|
|
188
|
+
const SC_7 = 8;
|
|
189
|
+
const SC_8 = 9;
|
|
190
|
+
const SC_9 = 10;
|
|
191
|
+
const SC_0 = 11;
|
|
192
|
+
const SC_MINUS = 12;
|
|
193
|
+
const SC_EQUAL = 13;
|
|
194
|
+
const SC_BACKSPACE = 14;
|
|
195
|
+
const SC_TAB = 15;
|
|
196
|
+
const SC_Q = 16;
|
|
197
|
+
const SC_W = 17;
|
|
198
|
+
const SC_E = 18;
|
|
199
|
+
const SC_R = 19;
|
|
200
|
+
const SC_T = 20;
|
|
201
|
+
const SC_Y = 21;
|
|
202
|
+
const SC_U = 22;
|
|
203
|
+
const SC_I = 23;
|
|
204
|
+
const SC_O = 24;
|
|
205
|
+
const SC_P = 25;
|
|
206
|
+
const SC_ENTER = 28;
|
|
207
|
+
const SC_A = 30;
|
|
208
|
+
const SC_S = 31;
|
|
209
|
+
const SC_D = 32;
|
|
210
|
+
const SC_F = 33;
|
|
211
|
+
const SC_G = 34;
|
|
212
|
+
const SC_H = 35;
|
|
213
|
+
const SC_J = 36;
|
|
214
|
+
const SC_K = 37;
|
|
215
|
+
const SC_L = 38;
|
|
216
|
+
const SC_Z = 44;
|
|
217
|
+
const SC_X = 45;
|
|
218
|
+
const SC_C = 46;
|
|
219
|
+
const SC_V = 47;
|
|
220
|
+
const SC_B = 48;
|
|
221
|
+
const SC_N = 49;
|
|
222
|
+
const SC_M = 50;
|
|
223
|
+
const SC_COMMA = 51;
|
|
224
|
+
const SC_DOT = 52;
|
|
225
|
+
const SC_CAPSLOCK = 58;
|
|
226
|
+
const SC_SPACE = 57;
|
|
227
|
+
const SC_F1 = 59;
|
|
228
|
+
const SC_F2 = 60;
|
|
229
|
+
const SC_F3 = 61;
|
|
230
|
+
const SC_F4 = 62;
|
|
231
|
+
const SC_F5 = 63;
|
|
232
|
+
const SC_F6 = 64;
|
|
233
|
+
const SC_F7 = 65;
|
|
234
|
+
const SC_F8 = 66;
|
|
235
|
+
const SC_F9 = 67;
|
|
236
|
+
const SC_F10 = 68;
|
|
237
|
+
const SC_F11 = 87;
|
|
238
|
+
const SC_F12 = 88;
|
|
239
|
+
const SC_NUMLOCK = 69;
|
|
240
|
+
const SC_SCROLLLOCK = 70;
|
|
241
|
+
const SC_HOME = 102;
|
|
242
|
+
const SC_UP = 103;
|
|
243
|
+
const SC_PAGEUP = 104;
|
|
244
|
+
const SC_LEFT = 105;
|
|
245
|
+
const SC_RIGHT = 106;
|
|
246
|
+
const SC_END = 107;
|
|
247
|
+
const SC_DOWN = 108;
|
|
248
|
+
const SC_PAGEDOWN = 109;
|
|
249
|
+
const SC_INSERT = 110;
|
|
250
|
+
const SC_DELETE = 111;
|
|
251
|
+
const SC_PAUSE = 119;
|
|
252
|
+
const SC_PRINT = 99;
|
|
253
|
+
const SC_MENU = 139;
|
|
254
|
+
const SC_F13 = 183;
|
|
255
|
+
const SC_F14 = 184;
|
|
256
|
+
const SC_F15 = 185;
|
|
257
|
+
const SC_F16 = 186;
|
|
258
|
+
const SC_F17 = 187;
|
|
259
|
+
const SC_F18 = 188;
|
|
260
|
+
const SC_F19 = 189;
|
|
261
|
+
const SC_F20 = 190;
|
|
262
|
+
const SC_F21 = 191;
|
|
263
|
+
const SC_F22 = 192;
|
|
264
|
+
const SC_F23 = 193;
|
|
265
|
+
const SC_F24 = 194;
|
|
266
|
+
const MOD_SCANCODES = /* @__PURE__ */ new Map([
|
|
267
|
+
["ctrl", SC_LEFTCTRL],
|
|
268
|
+
["alt", SC_LEFTALT],
|
|
269
|
+
["shift", SC_LEFTSHIFT],
|
|
270
|
+
["meta", SC_LEFTMETA],
|
|
271
|
+
["super", SC_LEFTMETA],
|
|
272
|
+
["hyper", SC_LEFTMETA]
|
|
273
|
+
]);
|
|
274
|
+
const MOD_ORDER = [
|
|
275
|
+
"ctrl",
|
|
276
|
+
"alt",
|
|
277
|
+
"shift",
|
|
278
|
+
"super"
|
|
279
|
+
];
|
|
280
|
+
const modToScancode = (mod) => MOD_SCANCODES.get(mod) ?? null;
|
|
281
|
+
const namedKeyToScancode = (name) => {
|
|
282
|
+
switch (name) {
|
|
283
|
+
case "Escape": return SC_ESC;
|
|
284
|
+
case "Tab": return SC_TAB;
|
|
285
|
+
case "Return": return SC_ENTER;
|
|
286
|
+
case "BackSpace": return SC_BACKSPACE;
|
|
287
|
+
case "Caps_Lock": return SC_CAPSLOCK;
|
|
288
|
+
case "Num_Lock": return SC_NUMLOCK;
|
|
289
|
+
case "Scroll_Lock": return SC_SCROLLLOCK;
|
|
290
|
+
case "space": return SC_SPACE;
|
|
291
|
+
case "Print": return SC_PRINT;
|
|
292
|
+
case "Pause": return SC_PAUSE;
|
|
293
|
+
case "Menu": return SC_MENU;
|
|
294
|
+
case "Insert": return SC_INSERT;
|
|
295
|
+
case "Delete": return SC_DELETE;
|
|
296
|
+
case "Home": return SC_HOME;
|
|
297
|
+
case "End": return SC_END;
|
|
298
|
+
case "Page_Up": return SC_PAGEUP;
|
|
299
|
+
case "Page_Down": return SC_PAGEDOWN;
|
|
300
|
+
case "Up": return SC_UP;
|
|
301
|
+
case "Down": return SC_DOWN;
|
|
302
|
+
case "Left": return SC_LEFT;
|
|
303
|
+
case "Right": return SC_RIGHT;
|
|
304
|
+
case "equal": return SC_EQUAL;
|
|
305
|
+
case "minus": return SC_MINUS;
|
|
306
|
+
case "comma": return SC_COMMA;
|
|
307
|
+
case "period": return SC_DOT;
|
|
308
|
+
case "F1": return SC_F1;
|
|
309
|
+
case "F2": return SC_F2;
|
|
310
|
+
case "F3": return SC_F3;
|
|
311
|
+
case "F4": return SC_F4;
|
|
312
|
+
case "F5": return SC_F5;
|
|
313
|
+
case "F6": return SC_F6;
|
|
314
|
+
case "F7": return SC_F7;
|
|
315
|
+
case "F8": return SC_F8;
|
|
316
|
+
case "F9": return SC_F9;
|
|
317
|
+
case "F10": return SC_F10;
|
|
318
|
+
case "F11": return SC_F11;
|
|
319
|
+
case "F12": return SC_F12;
|
|
320
|
+
case "F13": return SC_F13;
|
|
321
|
+
case "F14": return SC_F14;
|
|
322
|
+
case "F15": return SC_F15;
|
|
323
|
+
case "F16": return SC_F16;
|
|
324
|
+
case "F17": return SC_F17;
|
|
325
|
+
case "F18": return SC_F18;
|
|
326
|
+
case "F19": return SC_F19;
|
|
327
|
+
case "F20": return SC_F20;
|
|
328
|
+
case "F21": return SC_F21;
|
|
329
|
+
case "F22": return SC_F22;
|
|
330
|
+
case "F23": return SC_F23;
|
|
331
|
+
case "F24": return SC_F24;
|
|
332
|
+
default: return null;
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
const LETTER_SC = /* @__PURE__ */ new Map([
|
|
336
|
+
["a", SC_A],
|
|
337
|
+
["b", SC_B],
|
|
338
|
+
["c", SC_C],
|
|
339
|
+
["d", SC_D],
|
|
340
|
+
["e", SC_E],
|
|
341
|
+
["f", SC_F],
|
|
342
|
+
["g", SC_G],
|
|
343
|
+
["h", SC_H],
|
|
344
|
+
["i", SC_I],
|
|
345
|
+
["j", SC_J],
|
|
346
|
+
["k", SC_K],
|
|
347
|
+
["l", SC_L],
|
|
348
|
+
["m", SC_M],
|
|
349
|
+
["n", SC_N],
|
|
350
|
+
["o", SC_O],
|
|
351
|
+
["p", SC_P],
|
|
352
|
+
["q", SC_Q],
|
|
353
|
+
["r", SC_R],
|
|
354
|
+
["s", SC_S],
|
|
355
|
+
["t", SC_T],
|
|
356
|
+
["u", SC_U],
|
|
357
|
+
["v", SC_V],
|
|
358
|
+
["w", SC_W],
|
|
359
|
+
["x", SC_X],
|
|
360
|
+
["y", SC_Y],
|
|
361
|
+
["z", SC_Z]
|
|
362
|
+
]);
|
|
363
|
+
const DIGIT_SC = /* @__PURE__ */ new Map([
|
|
364
|
+
["0", SC_0],
|
|
365
|
+
["1", SC_1],
|
|
366
|
+
["2", SC_2],
|
|
367
|
+
["3", SC_3],
|
|
368
|
+
["4", SC_4],
|
|
369
|
+
["5", SC_5],
|
|
370
|
+
["6", SC_6],
|
|
371
|
+
["7", SC_7],
|
|
372
|
+
["8", SC_8],
|
|
373
|
+
["9", SC_9]
|
|
374
|
+
]);
|
|
375
|
+
const KEY_ALIASES = /* @__PURE__ */ new Map([
|
|
376
|
+
["plus", "equal"],
|
|
377
|
+
["minus", "minus"],
|
|
378
|
+
["equal", "equal"],
|
|
379
|
+
["comma", "comma"],
|
|
380
|
+
["period", "period"]
|
|
381
|
+
]);
|
|
382
|
+
const keyToScancode = (key) => {
|
|
383
|
+
const normalized = KEY_ALIASES.get(key) ?? key;
|
|
384
|
+
const fromNamed = namedKeyToScancode(normalized);
|
|
385
|
+
if (fromNamed !== null) return fromNamed;
|
|
386
|
+
const fromLetter = LETTER_SC.get(normalized);
|
|
387
|
+
if (fromLetter !== void 0) return fromLetter;
|
|
388
|
+
const fromDigit = DIGIT_SC.get(normalized);
|
|
389
|
+
if (fromDigit !== void 0) return fromDigit;
|
|
390
|
+
return null;
|
|
391
|
+
};
|
|
392
|
+
const probeTool = async (executor, tool, extraFsProbe) => {
|
|
393
|
+
const result = await executor.run("which", [tool]);
|
|
394
|
+
if (result.exitCode === 0 && result.stdout.trim().length > 0) return true;
|
|
395
|
+
return extraFsProbe?.(tool) === true;
|
|
396
|
+
};
|
|
397
|
+
const shellQuote = (value) => `'${value.replace(/'/g, "'\\''")}'`;
|
|
398
|
+
const YDOTOOL_CTRL_V_ARGS = [
|
|
399
|
+
"key",
|
|
400
|
+
`${SC_LEFTCTRL}:1`,
|
|
401
|
+
`${SC_V}:1`,
|
|
402
|
+
`${SC_V}:0`,
|
|
403
|
+
`${SC_LEFTCTRL}:0`
|
|
404
|
+
];
|
|
405
|
+
const SHIFT_NEEDED_KEYS = /* @__PURE__ */ new Set(["plus", "minus"]);
|
|
406
|
+
const buildYdotoolComboArgs = (input) => {
|
|
407
|
+
const parsed = parseCombo(input);
|
|
408
|
+
if (parsed === null) return null;
|
|
409
|
+
const seenSc = /* @__PURE__ */ new Set();
|
|
410
|
+
const orderedMods = [];
|
|
411
|
+
for (const mod of MOD_ORDER) {
|
|
412
|
+
if (!parsed.mods.includes(mod)) continue;
|
|
413
|
+
const sc = modToScancode(mod);
|
|
414
|
+
if (sc === null) throw new ProviderError("EXEC_FAILED", `ydotool: cannot map modifier '${mod}' to scancode`);
|
|
415
|
+
if (seenSc.has(sc)) continue;
|
|
416
|
+
seenSc.add(sc);
|
|
417
|
+
orderedMods.push(sc);
|
|
418
|
+
}
|
|
419
|
+
for (const mod of parsed.mods) {
|
|
420
|
+
const sc = modToScancode(mod);
|
|
421
|
+
if (sc === null) throw new ProviderError("EXEC_FAILED", `ydotool: cannot map modifier '${mod}' to scancode`);
|
|
422
|
+
if (seenSc.has(sc)) continue;
|
|
423
|
+
seenSc.add(sc);
|
|
424
|
+
orderedMods.push(sc);
|
|
425
|
+
}
|
|
426
|
+
const keySc = keyToScancode(parsed.key);
|
|
427
|
+
if (keySc === null) throw new ProviderError("EXEC_FAILED", `ydotool: cannot map key '${parsed.key}' to scancode (combo keys must be alphanumeric or a named key)`);
|
|
428
|
+
if (SHIFT_NEEDED_KEYS.has(parsed.key) && !parsed.mods.includes("shift") && !seenSc.has(SC_LEFTSHIFT)) {
|
|
429
|
+
seenSc.add(SC_LEFTSHIFT);
|
|
430
|
+
orderedMods.push(SC_LEFTSHIFT);
|
|
431
|
+
}
|
|
432
|
+
const args = ["key"];
|
|
433
|
+
for (const sc of orderedMods) args.push(`${sc}:1`);
|
|
434
|
+
args.push(`${keySc}:1`);
|
|
435
|
+
args.push(`${keySc}:0`);
|
|
436
|
+
for (let i = orderedMods.length - 1; i >= 0; i -= 1) args.push(`${orderedMods[i]}:0`);
|
|
437
|
+
return args;
|
|
438
|
+
};
|
|
439
|
+
const buildYdotoolLiteralArgs = (text) => {
|
|
440
|
+
return [
|
|
441
|
+
"type",
|
|
442
|
+
"--",
|
|
443
|
+
text
|
|
444
|
+
];
|
|
445
|
+
};
|
|
446
|
+
const buildWtypeComboArgs = (input) => {
|
|
447
|
+
const parsed = parseCombo(input);
|
|
448
|
+
if (parsed === null) return null;
|
|
449
|
+
const seen = /* @__PURE__ */ new Set();
|
|
450
|
+
const orderedMods = [];
|
|
451
|
+
for (const mod of MOD_ORDER) if (parsed.mods.includes(mod) && !seen.has(mod)) {
|
|
452
|
+
let wtype = mod;
|
|
453
|
+
if (mod === "meta" || mod === "hyper") wtype = "super";
|
|
454
|
+
seen.add(mod);
|
|
455
|
+
orderedMods.push(wtype);
|
|
456
|
+
}
|
|
457
|
+
for (const mod of parsed.mods) {
|
|
458
|
+
if (seen.has(mod)) continue;
|
|
459
|
+
let wtype = mod;
|
|
460
|
+
if (mod === "meta" || mod === "hyper") wtype = "super";
|
|
461
|
+
seen.add(mod);
|
|
462
|
+
orderedMods.push(wtype);
|
|
463
|
+
}
|
|
464
|
+
const args = [];
|
|
465
|
+
for (const m of orderedMods) args.push("-M", m);
|
|
466
|
+
args.push("-k", parsed.key);
|
|
467
|
+
for (let i = orderedMods.length - 1; i >= 0; i -= 1) args.push("-m", orderedMods[i]);
|
|
468
|
+
return args;
|
|
469
|
+
};
|
|
470
|
+
const buildWtypeLiteralArgs = (text) => {
|
|
471
|
+
return [shellQuote(text)];
|
|
472
|
+
};
|
|
473
|
+
const buildWtypeArgs = (input) => {
|
|
474
|
+
const combo = buildWtypeComboArgs(input);
|
|
475
|
+
if (combo !== null) return combo;
|
|
476
|
+
return buildWtypeLiteralArgs(input);
|
|
477
|
+
};
|
|
478
|
+
const isPureAscii = (text) => /^[\x20-\x7E]*$/.test(text);
|
|
479
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
480
|
+
const runYdotool = async (args, deps) => {
|
|
481
|
+
const baseTimeoutMs = deps.timeoutMs ?? 500;
|
|
482
|
+
try {
|
|
483
|
+
const result = await withTimeout(deps.executor.run(YDOTOOL_TOOL, args), baseTimeoutMs + 2500);
|
|
484
|
+
if (result.exitCode !== 0) throw new ProviderError("EXEC_FAILED", `${YDOTOOL_TOOL} ${args.join(" ")} exited with code ${result.exitCode}: ${result.stderr.trim()}`);
|
|
485
|
+
} catch (err) {
|
|
486
|
+
if (err instanceof ProviderError) throw err;
|
|
487
|
+
throw new ProviderError("EXEC_FAILED", `${YDOTOOL_TOOL} failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
const runWtype = async (args, deps) => {
|
|
491
|
+
const baseTimeoutMs = deps.timeoutMs ?? 500;
|
|
492
|
+
try {
|
|
493
|
+
const result = await withTimeout(deps.executor.run(WTYPE_TOOL, args), baseTimeoutMs + 2500);
|
|
494
|
+
if (result.exitCode !== 0) throw new ProviderError("EXEC_FAILED", `${WTYPE_TOOL} ${args.join(" ")} exited with code ${result.exitCode}: ${result.stderr.trim()}`);
|
|
495
|
+
} catch (err) {
|
|
496
|
+
if (err instanceof ProviderError) throw err;
|
|
497
|
+
throw new ProviderError("EXEC_FAILED", `${WTYPE_TOOL} failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
const sendKeyWtype = async (input, deps) => {
|
|
501
|
+
await runWtype(buildWtypeArgs(input), deps);
|
|
502
|
+
};
|
|
503
|
+
const sendKeyYdotool = async (input, deps, clipboardProvider) => {
|
|
504
|
+
if (parseCombo(input) !== null) {
|
|
505
|
+
await runYdotool(buildYdotoolComboArgs(input), deps);
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
if (isPureAscii(input)) {
|
|
509
|
+
await runYdotool(buildYdotoolLiteralArgs(input), deps);
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
if (clipboardProvider === void 0) throw new ProviderError("NOT_AVAILABLE", "non-ASCII text (e.g. emoji) on Linux needs wl-copy on PATH — install the wl-clipboard package");
|
|
513
|
+
const totalStart = Date.now();
|
|
514
|
+
deps.logger.info({
|
|
515
|
+
step: "keyMacro.nonAscii.start",
|
|
516
|
+
textPreview: input.slice(0, 24)
|
|
517
|
+
}, "keyMacro: typing non-ASCII via clipboard+ctrl+v");
|
|
518
|
+
const writeStart = Date.now();
|
|
519
|
+
await clipboardProvider.writeText(input);
|
|
520
|
+
deps.logger.info({
|
|
521
|
+
step: "keyMacro.nonAscii.afterWrite",
|
|
522
|
+
writeElapsedMs: Date.now() - writeStart
|
|
523
|
+
}, "keyMacro: clipboard writeText done");
|
|
524
|
+
deps.logger.info({
|
|
525
|
+
step: "keyMacro.nonAscii.preDelay",
|
|
526
|
+
ms: YDOTOOL_CLIPBOARD_PRE_DELAY_MS
|
|
527
|
+
}, "keyMacro: pre-keystroke delay");
|
|
528
|
+
await sleep(YDOTOOL_CLIPBOARD_PRE_DELAY_MS);
|
|
529
|
+
const keystrokeStart = Date.now();
|
|
530
|
+
await runYdotool(YDOTOOL_CTRL_V_ARGS, deps);
|
|
531
|
+
deps.logger.info({
|
|
532
|
+
step: "keyMacro.nonAscii.afterKeystroke",
|
|
533
|
+
keystrokeElapsedMs: Date.now() - keystrokeStart,
|
|
534
|
+
totalElapsedMs: Date.now() - totalStart
|
|
535
|
+
}, "keyMacro: ctrl+v keystroke done");
|
|
536
|
+
};
|
|
537
|
+
const createLinuxKeyMacroProvider = async (deps) => {
|
|
538
|
+
const ydotoolOk = await probeTool(deps.executor, YDOTOOL_TOOL, deps.extraFsProbe);
|
|
539
|
+
const wtypeOk = !ydotoolOk && await probeTool(deps.executor, WTYPE_TOOL, deps.extraFsProbe);
|
|
540
|
+
if (!ydotoolOk && !wtypeOk) {
|
|
541
|
+
deps.logger.warn({}, "no key-macro tool found (need ydotool or wtype on PATH); key-macro will throw ProviderError");
|
|
542
|
+
return {
|
|
543
|
+
async sendKey(_input) {
|
|
544
|
+
throw new ProviderError("NOT_AVAILABLE", "no key-macro tool found on PATH (need ydotool or wtype)");
|
|
545
|
+
},
|
|
546
|
+
async stop() {}
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
const tool = ydotoolOk ? YDOTOOL_TOOL : WTYPE_TOOL;
|
|
550
|
+
deps.logger.info({ tool }, "Linux key-macro tool selected");
|
|
551
|
+
let clipboardProvider;
|
|
552
|
+
if (tool === YDOTOOL_TOOL) try {
|
|
553
|
+
clipboardProvider = createClipboardProvider({
|
|
554
|
+
platform: "linux",
|
|
555
|
+
executor: deps.executor,
|
|
556
|
+
env: deps.env,
|
|
557
|
+
logger: deps.logger,
|
|
558
|
+
...deps.extraFsProbe !== void 0 ? { extraFsProbe: deps.extraFsProbe } : {}
|
|
559
|
+
});
|
|
560
|
+
} catch (err) {
|
|
561
|
+
deps.logger.warn({ err }, "linux clipboard provider unavailable; non-ASCII typing will throw");
|
|
562
|
+
}
|
|
563
|
+
if (tool === YDOTOOL_TOOL) return {
|
|
564
|
+
async sendKey(input) {
|
|
565
|
+
await sendKeyYdotool(input, deps, clipboardProvider);
|
|
566
|
+
},
|
|
567
|
+
async stop() {}
|
|
568
|
+
};
|
|
569
|
+
return {
|
|
570
|
+
async sendKey(input) {
|
|
571
|
+
await sendKeyWtype(input, deps);
|
|
572
|
+
},
|
|
573
|
+
async stop() {}
|
|
574
|
+
};
|
|
575
|
+
};
|
|
576
|
+
//#endregion
|
|
577
|
+
export { createLinuxKeyMacroProvider };
|