@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,361 @@
|
|
|
1
|
+
import { a as withTimeout, o as ProviderError, s as parseCombo } from "./main.mjs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
//#region src/system/providers/key-macro/windows.ts
|
|
7
|
+
const CACHE_DIR = join(tmpdir(), "sirenodeck", "key-macro-windows");
|
|
8
|
+
const HELPER_DLL = join(CACHE_DIR, "sirenokey-input.dll");
|
|
9
|
+
const HELPER_SRC_HASH = join(CACHE_DIR, "sirenokey-input.dll.src.sha256");
|
|
10
|
+
const sourceHash = (src) => createHash("sha256").update(src, "utf8").digest("hex");
|
|
11
|
+
const readCachedHash = () => {
|
|
12
|
+
try {
|
|
13
|
+
return readFileSync(HELPER_SRC_HASH, "utf8").trim();
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const writeCachedHash = (hash) => {
|
|
19
|
+
try {
|
|
20
|
+
writeFileSync(HELPER_SRC_HASH, `${hash}\n`, "utf8");
|
|
21
|
+
} catch {}
|
|
22
|
+
};
|
|
23
|
+
const HELPED_SOURCE = String.raw`
|
|
24
|
+
using System;
|
|
25
|
+
using System.Collections.Generic;
|
|
26
|
+
using System.Runtime.InteropServices;
|
|
27
|
+
|
|
28
|
+
public static class SirenoKey
|
|
29
|
+
{
|
|
30
|
+
[DllImport("user32.dll", SetLastError = true)]
|
|
31
|
+
static extern uint SendInput(uint n, INPUT[] p, int cb);
|
|
32
|
+
|
|
33
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
34
|
+
struct INPUT { public uint type; public INPUTUNION u; }
|
|
35
|
+
|
|
36
|
+
[StructLayout(LayoutKind.Explicit)]
|
|
37
|
+
struct INPUTUNION {
|
|
38
|
+
[FieldOffset(0)] public KEYBDINPUT k;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
42
|
+
struct KEYBDINPUT {
|
|
43
|
+
public ushort wVk;
|
|
44
|
+
public ushort wScan;
|
|
45
|
+
public uint dwFlags;
|
|
46
|
+
public uint time;
|
|
47
|
+
public IntPtr dwExtraInfo;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const uint INPUT_KEYBOARD = 1;
|
|
51
|
+
const ushort KEYEVENTF_UNICODE = 0x0004;
|
|
52
|
+
const ushort KEYEVENTF_KEYUP = 0x0002;
|
|
53
|
+
const ushort KEYEVENTF_EXTENDEDKEY = 0x0001;
|
|
54
|
+
|
|
55
|
+
static bool IsExtended(ushort vk) {
|
|
56
|
+
return vk == 0x21 || vk == 0x22 || vk == 0x23 || vk == 0x24
|
|
57
|
+
|| vk == 0x25 || vk == 0x26 || vk == 0x27 || vk == 0x28
|
|
58
|
+
|| vk == 0x2D || vk == 0x2E
|
|
59
|
+
|| vk == 0x6F || vk == 0x0D
|
|
60
|
+
|| vk == 0xA3 || vk == 0xA5;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static INPUT MkDown(ushort vk) {
|
|
64
|
+
var i = new INPUT();
|
|
65
|
+
i.type = INPUT_KEYBOARD;
|
|
66
|
+
i.u.k.wVk = vk;
|
|
67
|
+
i.u.k.dwFlags = (uint)(IsExtended(vk) ? KEYEVENTF_EXTENDEDKEY : 0);
|
|
68
|
+
return i;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static INPUT MkUp(ushort vk) {
|
|
72
|
+
var i = new INPUT();
|
|
73
|
+
i.type = INPUT_KEYBOARD;
|
|
74
|
+
i.u.k.wVk = vk;
|
|
75
|
+
i.u.k.dwFlags = (uint)((IsExtended(vk) ? KEYEVENTF_EXTENDEDKEY : 0) | KEYEVENTF_KEYUP);
|
|
76
|
+
return i;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static string Err(int expected, uint sent) {
|
|
80
|
+
int err = Marshal.GetLastWin32Error();
|
|
81
|
+
return "fail:" + err + ":SendInput returned " + sent + " of " + expected;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static uint Send(INPUT[] arr) {
|
|
85
|
+
return SendInput((uint)arr.Length, arr, Marshal.SizeOf(typeof(INPUT)));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public static string TypeText(string s) {
|
|
89
|
+
if (s == null) s = "";
|
|
90
|
+
var inputs = new List<INPUT>();
|
|
91
|
+
foreach (var ch in s) {
|
|
92
|
+
ushort sc = (ushort)ch;
|
|
93
|
+
var down = new INPUT();
|
|
94
|
+
down.type = INPUT_KEYBOARD;
|
|
95
|
+
down.u.k.wVk = 0;
|
|
96
|
+
down.u.k.wScan = sc;
|
|
97
|
+
down.u.k.dwFlags = KEYEVENTF_UNICODE;
|
|
98
|
+
inputs.Add(down);
|
|
99
|
+
var up = new INPUT();
|
|
100
|
+
up.type = INPUT_KEYBOARD;
|
|
101
|
+
up.u.k.wVk = 0;
|
|
102
|
+
up.u.k.wScan = sc;
|
|
103
|
+
up.u.k.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP;
|
|
104
|
+
inputs.Add(up);
|
|
105
|
+
}
|
|
106
|
+
var arr = inputs.ToArray();
|
|
107
|
+
if (arr.Length == 0) return "ok:0:";
|
|
108
|
+
uint sent = Send(arr);
|
|
109
|
+
if (sent != arr.Length) return Err(arr.Length, sent);
|
|
110
|
+
return "ok:0:";
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public static string TapKey(ushort vk) {
|
|
114
|
+
var arr = new INPUT[] { MkDown(vk), MkUp(vk) };
|
|
115
|
+
uint sent = Send(arr);
|
|
116
|
+
if (sent != (uint)arr.Length) return Err(arr.Length, sent);
|
|
117
|
+
return "ok:0:";
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public static string KeyDown(ushort vk) {
|
|
121
|
+
var arr = new INPUT[] { MkDown(vk) };
|
|
122
|
+
uint sent = Send(arr);
|
|
123
|
+
if (sent != (uint)arr.Length) return Err(arr.Length, sent);
|
|
124
|
+
return "ok:0:";
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
public static string KeyUp(ushort vk) {
|
|
128
|
+
var arr = new INPUT[] { MkUp(vk) };
|
|
129
|
+
uint sent = Send(arr);
|
|
130
|
+
if (sent != (uint)arr.Length) return Err(arr.Length, sent);
|
|
131
|
+
return "ok:0:";
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
`;
|
|
135
|
+
const COMPILE_PS = (cacheDir, dllPath) => `
|
|
136
|
+
$ErrorActionPreference = 'Stop'
|
|
137
|
+
$src = @'
|
|
138
|
+
${HELPED_SOURCE}
|
|
139
|
+
'@
|
|
140
|
+
try {
|
|
141
|
+
Add-Type -TypeDefinition $src -Language CSharp
|
|
142
|
+
$asm = [SirenoKey].Assembly.Location
|
|
143
|
+
if (-not (Test-Path '${escapeForPSSingleQuote(cacheDir)}')) {
|
|
144
|
+
New-Item -ItemType Directory -Path '${escapeForPSSingleQuote(cacheDir)}' -Force | Out-Null
|
|
145
|
+
}
|
|
146
|
+
Copy-Item -Path $asm -Destination '${escapeForPSSingleQuote(dllPath)}' -Force
|
|
147
|
+
exit 0
|
|
148
|
+
} catch {
|
|
149
|
+
[Console]::Error.WriteLine($_.Exception.Message)
|
|
150
|
+
exit 1
|
|
151
|
+
}
|
|
152
|
+
`;
|
|
153
|
+
const escapeForPSSingleQuote = (s) => s.replace(/'/g, "''");
|
|
154
|
+
const encodePSCommand = (script) => {
|
|
155
|
+
return Buffer.from(script, "utf16le").toString("base64");
|
|
156
|
+
};
|
|
157
|
+
const VK_CONTROL = 17;
|
|
158
|
+
const VK_SHIFT = 16;
|
|
159
|
+
const VK_MENU = 18;
|
|
160
|
+
const VK_LWIN = 91;
|
|
161
|
+
const VK_NAMED = /* @__PURE__ */ new Map([
|
|
162
|
+
["Return", 13],
|
|
163
|
+
["Tab", 9],
|
|
164
|
+
["Escape", 27],
|
|
165
|
+
["BackSpace", 8],
|
|
166
|
+
["Delete", 46],
|
|
167
|
+
["Insert", 45],
|
|
168
|
+
["Home", 36],
|
|
169
|
+
["End", 35],
|
|
170
|
+
["Page_Up", 33],
|
|
171
|
+
["Page_Down", 34],
|
|
172
|
+
["Up", 38],
|
|
173
|
+
["Down", 40],
|
|
174
|
+
["Left", 37],
|
|
175
|
+
["Right", 39],
|
|
176
|
+
["space", 32],
|
|
177
|
+
["F1", 112],
|
|
178
|
+
["F2", 113],
|
|
179
|
+
["F3", 114],
|
|
180
|
+
["F4", 115],
|
|
181
|
+
["F5", 116],
|
|
182
|
+
["F6", 117],
|
|
183
|
+
["F7", 118],
|
|
184
|
+
["F8", 119],
|
|
185
|
+
["F9", 120],
|
|
186
|
+
["F10", 121],
|
|
187
|
+
["F11", 122],
|
|
188
|
+
["F12", 123],
|
|
189
|
+
["F13", 124],
|
|
190
|
+
["F14", 125],
|
|
191
|
+
["F15", 126],
|
|
192
|
+
["F16", 127],
|
|
193
|
+
["F17", 128],
|
|
194
|
+
["F18", 129],
|
|
195
|
+
["F19", 130],
|
|
196
|
+
["F20", 131],
|
|
197
|
+
["F21", 132],
|
|
198
|
+
["F22", 133],
|
|
199
|
+
["F23", 134],
|
|
200
|
+
["F24", 135],
|
|
201
|
+
["Caps_Lock", 20],
|
|
202
|
+
["Num_Lock", 144],
|
|
203
|
+
["Scroll_Lock", 145],
|
|
204
|
+
["Pause", 19],
|
|
205
|
+
["Menu", 93],
|
|
206
|
+
["Print", 42],
|
|
207
|
+
["plus", 187],
|
|
208
|
+
["minus", 189],
|
|
209
|
+
["equal", 187],
|
|
210
|
+
["comma", 188],
|
|
211
|
+
["period", 190]
|
|
212
|
+
]);
|
|
213
|
+
const MOD_TO_VK = /* @__PURE__ */ new Map([
|
|
214
|
+
["ctrl", VK_CONTROL],
|
|
215
|
+
["shift", VK_SHIFT],
|
|
216
|
+
["alt", VK_MENU],
|
|
217
|
+
["meta", VK_LWIN],
|
|
218
|
+
["super", VK_LWIN],
|
|
219
|
+
["hyper", VK_LWIN]
|
|
220
|
+
]);
|
|
221
|
+
const MOD_ORDER = [
|
|
222
|
+
"ctrl",
|
|
223
|
+
"alt",
|
|
224
|
+
"shift",
|
|
225
|
+
"super"
|
|
226
|
+
];
|
|
227
|
+
const modToVk = (mod) => MOD_TO_VK.get(mod) ?? null;
|
|
228
|
+
const keyToVk = (key) => {
|
|
229
|
+
const named = VK_NAMED.get(key);
|
|
230
|
+
if (named !== void 0) return named;
|
|
231
|
+
if (key.length === 1) {
|
|
232
|
+
const code = key.charCodeAt(0);
|
|
233
|
+
if (code >= 97 && code <= 122) return code - 32;
|
|
234
|
+
if (code >= 48 && code <= 57) return code;
|
|
235
|
+
}
|
|
236
|
+
return null;
|
|
237
|
+
};
|
|
238
|
+
const escapeForPSDoubleQuote = (s) => s.replace(/[\\"$`]/g, "``$&");
|
|
239
|
+
const compileHelper = async (deps) => {
|
|
240
|
+
if (!existsSync(CACHE_DIR)) try {
|
|
241
|
+
mkdirSync(CACHE_DIR, { recursive: true });
|
|
242
|
+
} catch (err) {
|
|
243
|
+
deps.logger.warn({
|
|
244
|
+
err,
|
|
245
|
+
cacheDir: CACHE_DIR
|
|
246
|
+
}, "windows key-macro: failed to create cache dir");
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
const expectedHash = sourceHash(HELPED_SOURCE);
|
|
250
|
+
if (readCachedHash() === expectedHash && existsSync(HELPER_DLL)) {
|
|
251
|
+
deps.logger.debug({ dllPath: HELPER_DLL }, "windows key-macro: using cached DLL (source hash unchanged)");
|
|
252
|
+
return { dllPath: HELPER_DLL };
|
|
253
|
+
}
|
|
254
|
+
const script = COMPILE_PS(CACHE_DIR, HELPER_DLL);
|
|
255
|
+
const encoded = encodePSCommand(script);
|
|
256
|
+
try {
|
|
257
|
+
const result = await deps.executor.run("powershell", [
|
|
258
|
+
"-NoProfile",
|
|
259
|
+
"-EncodedCommand",
|
|
260
|
+
encoded
|
|
261
|
+
]);
|
|
262
|
+
if (result.exitCode !== 0) {
|
|
263
|
+
deps.logger.warn({ stderr: result.stderr.trim() }, "windows key-macro: helper compile failed");
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
} catch (err) {
|
|
267
|
+
deps.logger.warn({ err }, "windows key-macro: helper compile threw");
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
if (!existsSync(HELPER_DLL)) {
|
|
271
|
+
deps.logger.warn({ dllPath: HELPER_DLL }, "windows key-macro: helper DLL missing after compile");
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
writeCachedHash(expectedHash);
|
|
275
|
+
return { dllPath: HELPER_DLL };
|
|
276
|
+
};
|
|
277
|
+
const buildTypeTextPS = (dllPath, text) => {
|
|
278
|
+
const escapedText = escapeForPSDoubleQuote(text);
|
|
279
|
+
return `[Reflection.Assembly]::LoadFrom('${escapeForPSSingleQuote(dllPath)}') | Out-Null
|
|
280
|
+
$r = [SirenoKey]::TypeText("${escapedText}")
|
|
281
|
+
Write-Output $r
|
|
282
|
+
`;
|
|
283
|
+
};
|
|
284
|
+
const buildComboPS = (dllPath, orderedMods, keyVk) => {
|
|
285
|
+
const dllEsc = escapeForPSSingleQuote(dllPath);
|
|
286
|
+
const lines = [];
|
|
287
|
+
lines.push(`[Reflection.Assembly]::LoadFrom('${dllEsc}') | Out-Null`);
|
|
288
|
+
for (const vk of orderedMods) lines.push(`$null = [SirenoKey]::KeyDown(${vk})`);
|
|
289
|
+
lines.push(`$null = [SirenoKey]::TapKey(${keyVk})`);
|
|
290
|
+
for (const vk of [...orderedMods].reverse()) lines.push(`$null = [SirenoKey]::KeyUp(${vk})`);
|
|
291
|
+
lines.push(`Write-Output 'ok:0:'`);
|
|
292
|
+
return lines.join("\n") + "\n";
|
|
293
|
+
};
|
|
294
|
+
const parseResponse = (stdout) => {
|
|
295
|
+
const m = stdout.match(/^(ok|fail):(\d+):(.*)$/);
|
|
296
|
+
if (m === null) return null;
|
|
297
|
+
return {
|
|
298
|
+
ok: m[1] === "ok",
|
|
299
|
+
win32: Number(m[2]),
|
|
300
|
+
message: m[3] ?? ""
|
|
301
|
+
};
|
|
302
|
+
};
|
|
303
|
+
const sendViaPowerShell = async (script, deps) => {
|
|
304
|
+
const timeoutMs = deps.timeoutMs ?? 500;
|
|
305
|
+
const encoded = encodePSCommand(script);
|
|
306
|
+
const result = await withTimeout(deps.executor.run("powershell", [
|
|
307
|
+
"-NoProfile",
|
|
308
|
+
"-EncodedCommand",
|
|
309
|
+
encoded
|
|
310
|
+
]), timeoutMs + 2500);
|
|
311
|
+
if (result.exitCode !== 0) throw new ProviderError("EXEC_FAILED", `powershell exited ${result.exitCode}: ${result.stderr.trim() || result.stdout.trim()}`);
|
|
312
|
+
const parsed = parseResponse(result.stdout.trim());
|
|
313
|
+
if (parsed === null) throw new ProviderError("EXEC_FAILED", `unexpected SendInput response: ${result.stdout.trim().slice(0, 200)}`);
|
|
314
|
+
if (!parsed.ok) throw new ProviderError("EXEC_FAILED", `SendInput failed (Win32 #${parsed.win32}): ${parsed.message}`);
|
|
315
|
+
return parsed;
|
|
316
|
+
};
|
|
317
|
+
const createWindowsKeyMacroProvider = async (deps) => {
|
|
318
|
+
const helper = await compileHelper(deps);
|
|
319
|
+
if (helper === null) return {
|
|
320
|
+
async sendKey(_input) {
|
|
321
|
+
throw new ProviderError("NOT_AVAILABLE", "Windows key-macro unavailable: failed to compile SendInput helper (PowerShell Add-Type failed). Check that PowerShell 5+ is on PATH and user32.dll is reachable.");
|
|
322
|
+
},
|
|
323
|
+
async stop() {}
|
|
324
|
+
};
|
|
325
|
+
deps.logger.info({ dllPath: helper.dllPath }, "Windows key-macro provider initialised (Win32 SendInput)");
|
|
326
|
+
return {
|
|
327
|
+
async sendKey(input) {
|
|
328
|
+
const parsed = parseCombo(input);
|
|
329
|
+
if (parsed !== null) {
|
|
330
|
+
const seenVk = /* @__PURE__ */ new Set();
|
|
331
|
+
const orderedMods = [];
|
|
332
|
+
const mods = (parsed.key === "plus" || parsed.key === "minus") && !parsed.mods.includes("shift") ? [...parsed.mods, "shift"] : parsed.mods;
|
|
333
|
+
for (const mod of MOD_ORDER) {
|
|
334
|
+
if (!mods.includes(mod)) continue;
|
|
335
|
+
const vk = modToVk(mod);
|
|
336
|
+
if (vk === null) throw new ProviderError("EXEC_FAILED", `windows: cannot map modifier '${mod}' to VK code`);
|
|
337
|
+
if (seenVk.has(vk)) continue;
|
|
338
|
+
seenVk.add(vk);
|
|
339
|
+
orderedMods.push(vk);
|
|
340
|
+
}
|
|
341
|
+
for (const mod of mods) {
|
|
342
|
+
const vk = modToVk(mod);
|
|
343
|
+
if (vk === null) throw new ProviderError("EXEC_FAILED", `windows: cannot map modifier '${mod}' to VK code`);
|
|
344
|
+
if (seenVk.has(vk)) continue;
|
|
345
|
+
seenVk.add(vk);
|
|
346
|
+
orderedMods.push(vk);
|
|
347
|
+
}
|
|
348
|
+
const keyVk = keyToVk(parsed.key);
|
|
349
|
+
if (keyVk === null) throw new ProviderError("EXEC_FAILED", `windows: cannot map key '${parsed.key}' to VK code (combo keys must be alphanumeric or a named key)`);
|
|
350
|
+
const script = buildComboPS(helper.dllPath, orderedMods, keyVk);
|
|
351
|
+
await sendViaPowerShell(script, deps);
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
const script = buildTypeTextPS(helper.dllPath, input);
|
|
355
|
+
await sendViaPowerShell(script, deps);
|
|
356
|
+
},
|
|
357
|
+
async stop() {}
|
|
358
|
+
};
|
|
359
|
+
};
|
|
360
|
+
//#endregion
|
|
361
|
+
export { createWindowsKeyMacroProvider };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
//#region src/system/providers/active-app/windows.ts
|
|
2
|
+
const DEFAULT_POLL_MS = 1e3;
|
|
3
|
+
const PS_GET_ACTIVE = `Add-Type -AssemblyName UIAutomationClient,UIAutomationTypes; $el=[System.Windows.Automation.AutomationElement]::FocusedElement; "{0}|{1}" -f $el.Current.Name, $el.Current.ProcessId`;
|
|
4
|
+
const parseOutput = (raw) => {
|
|
5
|
+
const trimmed = raw.trim();
|
|
6
|
+
if (trimmed.length === 0) return null;
|
|
7
|
+
const idx = trimmed.lastIndexOf("|");
|
|
8
|
+
if (idx < 0) return null;
|
|
9
|
+
const name = trimmed.substring(0, idx).trim();
|
|
10
|
+
const pidStr = trimmed.substring(idx + 1).trim();
|
|
11
|
+
const pid = Number.parseInt(pidStr, 10);
|
|
12
|
+
if (name.length === 0) return null;
|
|
13
|
+
return {
|
|
14
|
+
name,
|
|
15
|
+
pid: Number.isFinite(pid) ? pid : null
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const createWindowsActiveAppProvider = async (deps) => {
|
|
19
|
+
const pollMs = deps.pollIntervalMs ?? DEFAULT_POLL_MS;
|
|
20
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
21
|
+
let last = null;
|
|
22
|
+
let stopped = false;
|
|
23
|
+
const snapshot = async () => {
|
|
24
|
+
try {
|
|
25
|
+
const result = await deps.executor.run("powershell", [
|
|
26
|
+
"-NoProfile",
|
|
27
|
+
"-Command",
|
|
28
|
+
PS_GET_ACTIVE
|
|
29
|
+
], { timeoutMs: 3e3 });
|
|
30
|
+
if (result.exitCode !== 0) return last;
|
|
31
|
+
const parsed = parseOutput(result.stdout);
|
|
32
|
+
if (parsed === null) return last;
|
|
33
|
+
return {
|
|
34
|
+
name: parsed.name,
|
|
35
|
+
windowTitle: parsed.name,
|
|
36
|
+
processId: parsed.pid
|
|
37
|
+
};
|
|
38
|
+
} catch (err) {
|
|
39
|
+
deps.logger.warn({ err }, "active-app: powershell failed");
|
|
40
|
+
return last;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
let interval = null;
|
|
44
|
+
interval = setInterval(() => {
|
|
45
|
+
if (stopped) return;
|
|
46
|
+
snapshot().then((s) => {
|
|
47
|
+
if (stopped) return;
|
|
48
|
+
if (!(last !== null && s !== null && last.name === s.name && last.processId === s.processId)) {
|
|
49
|
+
last = s;
|
|
50
|
+
for (const h of subscribers) h(s);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}, pollMs);
|
|
54
|
+
return {
|
|
55
|
+
async getActive() {
|
|
56
|
+
return snapshot();
|
|
57
|
+
},
|
|
58
|
+
subscribe(handler) {
|
|
59
|
+
subscribers.add(handler);
|
|
60
|
+
return () => {
|
|
61
|
+
subscribers.delete(handler);
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
async stop() {
|
|
65
|
+
stopped = true;
|
|
66
|
+
if (interval !== null) {
|
|
67
|
+
clearInterval(interval);
|
|
68
|
+
interval = null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
//#endregion
|
|
74
|
+
export { createWindowsActiveAppProvider };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
//#region src/system/providers/session/windows.ts
|
|
2
|
+
const toState = (locked) => locked ? "locked" : "unlocked";
|
|
3
|
+
const PS_GET_LOGONUI = `if (Get-Process logonui -ErrorAction SilentlyContinue) { 'true' } else { 'false' }`;
|
|
4
|
+
const parseLockResult = (raw) => raw.trim().toLowerCase() === "true";
|
|
5
|
+
const createWindowsSessionProvider = async (deps) => {
|
|
6
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
7
|
+
let state = "unknown";
|
|
8
|
+
let stopped = false;
|
|
9
|
+
const pollMs = deps.pollIntervalMs ?? 5e3;
|
|
10
|
+
const tick = async () => {
|
|
11
|
+
try {
|
|
12
|
+
const result = await deps.executor.run("powershell", [
|
|
13
|
+
"-NoProfile",
|
|
14
|
+
"-Command",
|
|
15
|
+
PS_GET_LOGONUI
|
|
16
|
+
], { timeoutMs: 2e3 });
|
|
17
|
+
if (result.exitCode !== 0) return state;
|
|
18
|
+
return toState(parseLockResult(result.stdout));
|
|
19
|
+
} catch (err) {
|
|
20
|
+
deps.logger.debug({ err }, "session: powershell failed");
|
|
21
|
+
return state;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
state = await tick();
|
|
25
|
+
let interval = setInterval(() => {
|
|
26
|
+
if (stopped) return;
|
|
27
|
+
tick().then((s) => {
|
|
28
|
+
if (stopped) return;
|
|
29
|
+
if (s !== state) {
|
|
30
|
+
state = s;
|
|
31
|
+
for (const l of listeners) l(state);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}, pollMs);
|
|
35
|
+
return {
|
|
36
|
+
getState() {
|
|
37
|
+
return state;
|
|
38
|
+
},
|
|
39
|
+
subscribe(handler) {
|
|
40
|
+
listeners.add(handler);
|
|
41
|
+
return () => {
|
|
42
|
+
listeners.delete(handler);
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
async stop() {
|
|
46
|
+
stopped = true;
|
|
47
|
+
if (interval !== null) {
|
|
48
|
+
clearInterval(interval);
|
|
49
|
+
interval = null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
//#endregion
|
|
55
|
+
export { createWindowsSessionProvider };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sirenodeck/sirenodeck",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "CLI for managing Elgato Stream Deck devices via a config-driven deck system.",
|
|
5
5
|
"homepage": "https://deck.sireno.dev",
|
|
6
6
|
"bugs": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"bin",
|
|
20
20
|
"config",
|
|
21
|
-
"dist
|
|
21
|
+
"dist",
|
|
22
22
|
"src",
|
|
23
23
|
"LICENSE",
|
|
24
24
|
"README.md",
|
package/src/cli/commands/run.ts
CHANGED
|
@@ -110,6 +110,11 @@ import {
|
|
|
110
110
|
} from "@/outputClient"
|
|
111
111
|
import type { AddonInventoryEntry } from "@/api/protocol-internal"
|
|
112
112
|
import { loadDeviceConfig } from "@/util/device-config"
|
|
113
|
+
import {
|
|
114
|
+
createSettingsStore,
|
|
115
|
+
resolveSettingsPath,
|
|
116
|
+
type SettingsStore,
|
|
117
|
+
} from "@/core/settings"
|
|
113
118
|
import {
|
|
114
119
|
collectAddonDefaultButtonConfig,
|
|
115
120
|
materializeAddonDecks,
|
|
@@ -163,6 +168,7 @@ export interface RunOptions {
|
|
|
163
168
|
readonly remote?: boolean
|
|
164
169
|
readonly deviceModel?: string
|
|
165
170
|
readonly frontendUrl?: string
|
|
171
|
+
readonly configUiUrl?: string
|
|
166
172
|
readonly intervalMs?: number
|
|
167
173
|
readonly xdgConfigHome?: string
|
|
168
174
|
readonly homeDir?: string
|
|
@@ -902,7 +908,9 @@ const buildRuntime = (
|
|
|
902
908
|
logger,
|
|
903
909
|
)
|
|
904
910
|
const token = process.env["SIRENO_TOKEN"] ?? ""
|
|
905
|
-
const configUiUrl = new URL(
|
|
911
|
+
const configUiUrl = new URL(
|
|
912
|
+
options.configUiUrl ?? `http://127.0.0.1:${DEFAULT_CONFIG_UI_PORT}/`,
|
|
913
|
+
)
|
|
906
914
|
if (token.length > 0) configUiUrl.searchParams.set("token", token)
|
|
907
915
|
configUiUrl.hash = "/config"
|
|
908
916
|
const runtimeDecks = injectConfigUiButton(allDecks, configUiUrl.toString())
|
|
@@ -1505,6 +1513,8 @@ export const runPipeline = async (options: RunOptions): Promise<void> => {
|
|
|
1505
1513
|
let configWatcher: ConfigWatcher | null = null
|
|
1506
1514
|
let outputHandle: OutputHandle | null = null
|
|
1507
1515
|
let currentOutputHandle: OutputHandle | null = null
|
|
1516
|
+
let settingsStore: SettingsStore | null = null
|
|
1517
|
+
let unsubscribeBrightnessSettings: (() => void) | null = null
|
|
1508
1518
|
let unregisterSignal: (() => void) | null = null
|
|
1509
1519
|
let unregisterReload: (() => void) | null = null
|
|
1510
1520
|
let unsubscribeLockMode: (() => void) | null = null
|
|
@@ -1521,6 +1531,10 @@ export const runPipeline = async (options: RunOptions): Promise<void> => {
|
|
|
1521
1531
|
})
|
|
1522
1532
|
|
|
1523
1533
|
try {
|
|
1534
|
+
settingsStore = createSettingsStore({
|
|
1535
|
+
path: resolveSettingsPath(xdgConfigHome),
|
|
1536
|
+
logger,
|
|
1537
|
+
})
|
|
1524
1538
|
// Validate config first so a broken YAML exits before we ever touch
|
|
1525
1539
|
// hardware or spawn an emulator.
|
|
1526
1540
|
loadedConfig = await validateAndLoadConfig(options)
|
|
@@ -1544,8 +1558,13 @@ export const runPipeline = async (options: RunOptions): Promise<void> => {
|
|
|
1544
1558
|
decks = loaded.decks
|
|
1545
1559
|
pubSub = loaded.pubSub
|
|
1546
1560
|
runtime = loaded.runtime
|
|
1561
|
+
runtime.setBrightness(settingsStore.get().brightness)
|
|
1547
1562
|
methods = loaded.methods
|
|
1548
1563
|
store = loaded.store
|
|
1564
|
+
unsubscribeBrightnessSettings = pubSub.subscribe<{ value: number }>(
|
|
1565
|
+
"methods:adjustBrightness",
|
|
1566
|
+
({ value }) => settingsStore?.update({ brightness: value }),
|
|
1567
|
+
)
|
|
1549
1568
|
|
|
1550
1569
|
providers = await startSystemProviders(options, methods)
|
|
1551
1570
|
hostPolicy = createHostPolicyCoordinator({
|
|
@@ -1775,6 +1794,9 @@ export const runPipeline = async (options: RunOptions): Promise<void> => {
|
|
|
1775
1794
|
logger,
|
|
1776
1795
|
})
|
|
1777
1796
|
addonServicesDispose = () => addonServices?.dispose()
|
|
1797
|
+
pubSub.publish("sireno:settings:brightness", {
|
|
1798
|
+
value: runtime.getBrightness(),
|
|
1799
|
+
})
|
|
1778
1800
|
|
|
1779
1801
|
for (const deck of decks) {
|
|
1780
1802
|
registerDeckIcon(deck, resolverOptions, logger)
|
|
@@ -1856,6 +1878,9 @@ export const runPipeline = async (options: RunOptions): Promise<void> => {
|
|
|
1856
1878
|
...(options.frontendUrl !== undefined
|
|
1857
1879
|
? { frontendUrl: options.frontendUrl }
|
|
1858
1880
|
: {}),
|
|
1881
|
+
...(options.configUiUrl !== undefined
|
|
1882
|
+
? { configUiUrl: options.configUiUrl }
|
|
1883
|
+
: {}),
|
|
1859
1884
|
...(options.port !== undefined ? { port: options.port } : {}),
|
|
1860
1885
|
...(options.intervalMs !== undefined
|
|
1861
1886
|
? { intervalMs: options.intervalMs }
|
|
@@ -2082,6 +2107,8 @@ export const runPipeline = async (options: RunOptions): Promise<void> => {
|
|
|
2082
2107
|
|
|
2083
2108
|
await done
|
|
2084
2109
|
} finally {
|
|
2110
|
+
unsubscribeBrightnessSettings?.()
|
|
2111
|
+
settingsStore?.close()
|
|
2085
2112
|
if (unregisterSignal !== null) unregisterSignal()
|
|
2086
2113
|
if (unregisterReload !== null) unregisterReload()
|
|
2087
2114
|
if (bridgeSignal !== null) bridgeSignal.abort()
|
|
@@ -75,6 +75,7 @@ import { buildStandardProbeDeps } from "@/cli/probe-deps"
|
|
|
75
75
|
import { onboardCodingAgents } from "@/cli/coding-agents-onboarding"
|
|
76
76
|
import { resolveUserPath } from "@/cli/cwd"
|
|
77
77
|
import { offerConfigSkillOnFirstRun } from "@/cli/skills-first-run"
|
|
78
|
+
import { resolveInstallRoot } from "../install-root"
|
|
78
79
|
|
|
79
80
|
export interface StartOptions {
|
|
80
81
|
readonly config?: string
|
|
@@ -83,6 +84,7 @@ export interface StartOptions {
|
|
|
83
84
|
readonly remote?: boolean
|
|
84
85
|
readonly deviceModel?: string
|
|
85
86
|
readonly frontendUrl?: string
|
|
87
|
+
readonly configUiUrl?: string
|
|
86
88
|
readonly intervalMs?: number
|
|
87
89
|
readonly xdgConfigHome?: string
|
|
88
90
|
readonly homeDir?: string
|
|
@@ -106,6 +108,7 @@ const toRunOptions = (
|
|
|
106
108
|
remote: options.remote,
|
|
107
109
|
deviceModel: options.deviceModel,
|
|
108
110
|
frontendUrl: options.frontendUrl,
|
|
111
|
+
configUiUrl: options.configUiUrl,
|
|
109
112
|
intervalMs: options.intervalMs,
|
|
110
113
|
xdgConfigHome: options.xdgConfigHome,
|
|
111
114
|
homeDir: options.homeDir,
|
|
@@ -116,6 +119,8 @@ const toRunOptions = (
|
|
|
116
119
|
})
|
|
117
120
|
|
|
118
121
|
const resolveFrontendDist = (): string => {
|
|
122
|
+
const installRoot = resolveInstallRoot()
|
|
123
|
+
if (installRoot !== null) return join(installRoot, "frontend", "dist")
|
|
119
124
|
const here = dirname(fileURLToPath(import.meta.url))
|
|
120
125
|
return resolvePath(here, "../../../frontend/dist")
|
|
121
126
|
}
|
|
@@ -590,6 +595,11 @@ const runInProcessSetup = async (
|
|
|
590
595
|
// letting it also override a fresh invocation made one past `--emulator`
|
|
591
596
|
// run force every later plain `p dev start` into emulator mode.
|
|
592
597
|
const runtimeFlags = buildRuntimeFlags(options)
|
|
598
|
+
const installRoot = resolveInstallRoot()
|
|
599
|
+
const installedFrontendUrl =
|
|
600
|
+
installRoot !== null && runtimeFlags.emulator !== true
|
|
601
|
+
? `http://127.0.0.1:${runtimeFlags.httpPort}`
|
|
602
|
+
: undefined
|
|
593
603
|
writeConfigPath(configPath)
|
|
594
604
|
writeFlags(runtimeFlags)
|
|
595
605
|
|
|
@@ -605,6 +615,13 @@ const runInProcessSetup = async (
|
|
|
605
615
|
remote: runtimeFlags.remote,
|
|
606
616
|
deviceModel: runtimeFlags.deviceModel,
|
|
607
617
|
httpPort: runtimeFlags.httpPort,
|
|
618
|
+
...(options.frontendUrl === undefined &&
|
|
619
|
+
installedFrontendUrl !== undefined
|
|
620
|
+
? {
|
|
621
|
+
frontendUrl: installedFrontendUrl,
|
|
622
|
+
configUiUrl: installedFrontendUrl,
|
|
623
|
+
}
|
|
624
|
+
: {}),
|
|
608
625
|
},
|
|
609
626
|
(pids) => {
|
|
610
627
|
writeChildren({ pids: [...pids] })
|
|
@@ -188,7 +188,7 @@ export const formatFeaturesList = (
|
|
|
188
188
|
"Features",
|
|
189
189
|
...items.map(
|
|
190
190
|
(it) =>
|
|
191
|
-
`│
|
|
191
|
+
`│ ${it.available ? color.green("✓") : color.red("✗")} ${it.name}${!it.available && it.reason ? ` — ${it.reason}` : ""}`,
|
|
192
192
|
),
|
|
193
193
|
]
|
|
194
194
|
|
package/src/core/settings.ts
CHANGED
|
@@ -34,9 +34,10 @@ const SETTINGS_FILE = "settings.json"
|
|
|
34
34
|
const resolveXdgConfigHome = (): string =>
|
|
35
35
|
process.env["XDG_CONFIG_HOME"] ?? join(homedir(), ".config")
|
|
36
36
|
|
|
37
|
-
export const resolveSettingsPath = (
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
export const resolveSettingsPath = (
|
|
38
|
+
xdgConfigHome: string = resolveXdgConfigHome(),
|
|
39
|
+
): string => {
|
|
40
|
+
const dir = join(xdgConfigHome, SETTINGS_DIR)
|
|
40
41
|
return join(dir, SETTINGS_FILE)
|
|
41
42
|
}
|
|
42
43
|
|
|
@@ -71,6 +72,7 @@ export const loadSettings = (
|
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
export const atomicWriteJson = (path: string, data: unknown): void => {
|
|
75
|
+
mkdirSync(dirname(path), { recursive: true })
|
|
74
76
|
const tmpPath = `${path}.${randomBytes(6).toString("hex")}.tmp`
|
|
75
77
|
const fd = openSync(tmpPath, "w", 0o600)
|
|
76
78
|
try {
|