@sirenodeck/sirenodeck 0.1.1-alpha.0 → 0.2.2
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/LICENSE +674 -21
- package/bin/dev.js +12 -2
- package/dist/main.mjs +3655 -1657
- package/package.json +18 -16
- package/src/api/protocol-internal.ts +16 -1
- package/src/assets/logo.png +0 -0
- package/src/assets/logo72x72.png +0 -0
- package/src/builtin-addons/brightness/buttons/brightness/config.ts +12 -2
- package/src/builtin-addons/coding-agents/buttons/agent/config.ts +5 -1
- package/src/builtin-addons/coding-agents/buttons/summary/config.ts +15 -3
- package/src/builtin-addons/coding-agents/buttons/summary/frontend.tsx +3 -3
- package/src/builtin-addons/coding-agents/global/backend.ts +56 -34
- package/src/builtin-addons/coding-agents/providers/opencode.ts +4 -5
- package/src/builtin-addons/core/buttons/action/config.ts +5 -2
- package/src/builtin-addons/core/buttons/change-deck/config.ts +6 -3
- package/src/builtin-addons/core/buttons/media-sample/config.ts +2 -2
- package/src/builtin-addons/core/buttons/toggle/config.ts +26 -9
- package/src/builtin-addons/date-time/buttons/custom/config.ts +5 -1
- package/src/builtin-addons/date-time/buttons/date/config.ts +2 -2
- package/src/builtin-addons/date-time/buttons/time/config.ts +5 -1
- package/src/builtin-addons/emoji-selector/buttons/category/config.ts +3 -3
- package/src/builtin-addons/emoji-selector/buttons/emoji/config.ts +5 -2
- package/src/builtin-addons/emoji-selector/support.ts +5 -2
- package/src/builtin-addons/global-services.ts +23 -0
- package/src/builtin-addons/internal-settings/buttons/app-info/config.ts +2 -1
- package/src/builtin-addons/internal-settings/buttons/brightness-down/config.ts +6 -1
- package/src/builtin-addons/internal-settings/buttons/brightness-up/config.ts +6 -1
- package/src/builtin-addons/media/backend.ts +54 -0
- package/src/builtin-addons/media/buttons/volume/volume-down/config.ts +1 -1
- package/src/builtin-addons/media/buttons/volume/volume-up/config.ts +1 -1
- package/src/builtin-addons/session/buttons/time/config.ts +1 -1
- package/src/builtin-addons/system-status/buttons/system-status/schemas.ts +32 -6
- package/src/builtin-addons/system-status/manifest.ts +49 -0
- package/src/builtin-addons/value-display/buttons/value-display/config.ts +23 -9
- package/src/builtin-addons/weather/buttons/weather/config.ts +11 -6
- package/src/cli/coding-agents-onboarding.ts +181 -34
- package/src/cli/commands/command-executor.ts +61 -0
- package/src/cli/commands/emulator-mode.ts +17 -2
- package/src/cli/commands/network-bind.ts +13 -9
- package/src/cli/commands/restart.ts +15 -5
- package/src/cli/commands/run.ts +174 -317
- package/src/cli/commands/service/render-template.ts +10 -0
- package/src/cli/commands/skills.ts +106 -0
- package/src/cli/commands/start.ts +39 -9
- package/src/cli/commands/stop.ts +3 -2
- package/src/cli/commands/system-requirements.ts +1 -0
- package/src/cli/index.ts +16 -3
- package/src/cli/main.ts +15 -2
- package/src/cli/package-manager.ts +6 -0
- package/src/cli/skills-first-run.ts +46 -0
- package/src/cli/startup-display.ts +35 -17
- package/src/config/mutation.ts +13 -1
- package/src/config/schemas.ts +3 -3
- package/src/config/validation.ts +7 -1
- package/src/core/icon-asset-registry.ts +11 -6
- package/src/deck/addon-handler-bridge.ts +246 -176
- package/src/deck/deck-config.ts +11 -2
- package/src/deck/deck-presentation-publisher.ts +116 -0
- package/src/deck/index.ts +13 -0
- package/src/deck/inject-config-ui-button.ts +23 -0
- package/src/deck/methods.ts +23 -0
- package/src/deck/position-settings-version-button.ts +20 -0
- package/src/deck/runtime/host-policy-coordinator.ts +186 -0
- package/src/deck/runtime/runtime.ts +123 -250
- package/src/deck/system-back-injection.ts +2 -1
- package/src/device/reconnecting.ts +8 -1
- package/src/index.ts +1 -2
- package/src/outputClient/emulator.ts +13 -0
- package/src/outputClient/index.ts +8 -0
- package/src/outputClient/real.ts +40 -45
- package/src/outputClient/remote-mirror.ts +77 -0
- package/src/outputClient/types.ts +2 -0
- package/src/render/editor-handler.ts +12 -1
- package/src/render/frontend-bridge-url.ts +10 -0
- package/src/render/push-startup-screen.ts +76 -0
- package/src/render/ws-bridge.ts +2 -0
- package/src/system/providers/active-app/capture-file.ts +61 -0
- package/src/system/providers/active-app/wayland-gnome.ts +26 -10
- package/src/system/providers/active-app.ts +6 -0
- package/src/system/providers/clipboard/darwin.ts +28 -4
- package/src/system/providers/url.ts +57 -0
- package/src/util/logger.ts +19 -3
- package/src/version.ts +3 -1
- package/src/vite/virtual-modules.ts +12 -6
package/src/outputClient/real.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { existsSync } from "node:fs"
|
|
1
2
|
import { fileURLToPath } from "node:url"
|
|
2
3
|
|
|
3
4
|
import type pino from "pino"
|
|
@@ -9,8 +10,10 @@ import { createReconnectingDevice } from "@/device/reconnecting"
|
|
|
9
10
|
import { connectStreamDeck, type StreamDeckDevice } from "@/device/stream-deck"
|
|
10
11
|
import { BrowserRenderer } from "@/render/browser-renderer"
|
|
11
12
|
import { pushRawImage } from "@/render/push-raw-image"
|
|
13
|
+
import { pushStartupScreen } from "@/render/push-startup-screen"
|
|
12
14
|
import { NoStreamDeckFoundError, selectDevice } from "@/system/device-selection"
|
|
13
15
|
import { saveDeviceConfig } from "@/util/device-config"
|
|
16
|
+
import { VERSION } from "@/version"
|
|
14
17
|
|
|
15
18
|
import {
|
|
16
19
|
DEFAULT_FRONTEND_PORT,
|
|
@@ -144,24 +147,14 @@ export class RealOutputClient implements OutputClient {
|
|
|
144
147
|
let configUiSupervisor: SuperviseHandle | null = null
|
|
145
148
|
|
|
146
149
|
try {
|
|
147
|
-
// ponytail:
|
|
148
|
-
//
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
new URL("../assets/
|
|
152
|
-
)
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
imagePath: splashPath,
|
|
156
|
-
device,
|
|
157
|
-
logger,
|
|
158
|
-
})
|
|
159
|
-
} catch (err) {
|
|
160
|
-
logger.warn(
|
|
161
|
-
{ err: (err as Error).message, splashPath },
|
|
162
|
-
"real: splash push failed (non-fatal)",
|
|
163
|
-
)
|
|
164
|
-
}
|
|
150
|
+
// ponytail: paint the waiting state directly to hardware before Vite or
|
|
151
|
+
// Playwright starts; the deck must remain useful when its frontend is down.
|
|
152
|
+
const logoCandidates = [
|
|
153
|
+
new URL("../assets/logo72x72.png", import.meta.url),
|
|
154
|
+
new URL("../src/assets/logo72x72.png", import.meta.url),
|
|
155
|
+
].map((url) => fileURLToPath(url))
|
|
156
|
+
const logoPath = logoCandidates.find(existsSync) ?? logoCandidates[0]!
|
|
157
|
+
await pushStartupScreen({ logoPath, version: VERSION, device, logger })
|
|
165
158
|
|
|
166
159
|
opts.bridge.setDevice(descriptor)
|
|
167
160
|
|
|
@@ -269,31 +262,33 @@ export class RealOutputClient implements OutputClient {
|
|
|
269
262
|
})
|
|
270
263
|
}
|
|
271
264
|
|
|
272
|
-
let configUiUrl =
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
265
|
+
let configUiUrl =
|
|
266
|
+
opts.configUiUrl ?? `http://127.0.0.1:${DEFAULT_FRONTEND_PORT + 1}`
|
|
267
|
+
if (opts.configUiUrl === undefined)
|
|
268
|
+
configUiSupervisor = await supervise({
|
|
269
|
+
label: "config ui vite",
|
|
270
|
+
kill: killChild,
|
|
271
|
+
delayScheduleMs: DEFAULT_VITE_RETRY_SCHEDULE_MS,
|
|
272
|
+
spawn: async () => {
|
|
273
|
+
const r = await spawnConfigUiVite({
|
|
274
|
+
port: DEFAULT_FRONTEND_PORT + 1,
|
|
275
|
+
cwd: resolveConfigUiCwd(),
|
|
276
|
+
pnpmCommand: "pnpm",
|
|
277
|
+
readyTimeoutMs: 30_000,
|
|
278
|
+
logger,
|
|
279
|
+
wsUrl: `ws://127.0.0.1:${opts.bridge.port}`,
|
|
280
|
+
frontendUrl,
|
|
281
|
+
configPath: opts.configPath,
|
|
282
|
+
emulatorMode: false,
|
|
283
|
+
onPid: opts.onChildPid,
|
|
284
|
+
})
|
|
285
|
+
configUiUrl = r.url
|
|
286
|
+
return r.process
|
|
287
|
+
},
|
|
288
|
+
onGiveUp: () => opts.onChildCrash?.(),
|
|
289
|
+
isShuttingDown: () => shuttingDown,
|
|
290
|
+
logger,
|
|
291
|
+
})
|
|
297
292
|
|
|
298
293
|
logger.info({ frontendUrl }, "real mode: frontend URL")
|
|
299
294
|
|
|
@@ -309,7 +304,7 @@ export class RealOutputClient implements OutputClient {
|
|
|
309
304
|
await renderer.start()
|
|
310
305
|
|
|
311
306
|
const frontendVitePid = frontendSupervisor?.process.pid ?? 0
|
|
312
|
-
const configUiPid = configUiSupervisor
|
|
307
|
+
const configUiPid = configUiSupervisor?.process.pid ?? 0
|
|
313
308
|
const childPids = [frontendVitePid, configUiPid].filter((pid) => pid > 0)
|
|
314
309
|
|
|
315
310
|
const state: RuntimeState = {
|
|
@@ -319,7 +314,7 @@ export class RealOutputClient implements OutputClient {
|
|
|
319
314
|
lanHost: opts.lanHost ?? "127.0.0.1",
|
|
320
315
|
addresses: opts.lanAddresses ?? [],
|
|
321
316
|
emulatorMode: false,
|
|
322
|
-
remote:
|
|
317
|
+
remote: opts.remote === true,
|
|
323
318
|
startedAt: Date.now(),
|
|
324
319
|
theme: opts.theme.name,
|
|
325
320
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type pino from "pino"
|
|
2
|
+
|
|
3
|
+
import type { DeviceDescriptor } from "@/device/registry"
|
|
4
|
+
|
|
5
|
+
import { EmulatorOutputClient } from "./emulator"
|
|
6
|
+
import { RealOutputClient } from "./real"
|
|
7
|
+
import type { InitOptions, OutputClient, OutputHandle } from "./types"
|
|
8
|
+
|
|
9
|
+
/** Runs the physical deck and remote emulator against one runtime. */
|
|
10
|
+
export class RemoteMirrorOutputClient implements OutputClient {
|
|
11
|
+
private readonly real: RealOutputClient
|
|
12
|
+
private readonly emulator = new EmulatorOutputClient()
|
|
13
|
+
private hardwareSelected = false
|
|
14
|
+
|
|
15
|
+
get kind(): "real" | "emulator" {
|
|
16
|
+
return this.hardwareSelected ? "real" : "emulator"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
constructor(options: { readonly xdgConfigHome: string }) {
|
|
20
|
+
this.real = new RealOutputClient(options)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
validateReady(): Promise<void> {
|
|
24
|
+
return this.real.validateReady()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
listDevices(): Promise<ReadonlyArray<DeviceDescriptor>> {
|
|
28
|
+
return this.real.listDevices().then(async (devices) => {
|
|
29
|
+
if (devices.length > 0) {
|
|
30
|
+
this.hardwareSelected = true
|
|
31
|
+
return devices
|
|
32
|
+
}
|
|
33
|
+
this.hardwareSelected = false
|
|
34
|
+
return this.emulator.listDevices()
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async selectDevice(
|
|
39
|
+
devices: ReadonlyArray<DeviceDescriptor>,
|
|
40
|
+
savedId: string | null,
|
|
41
|
+
logger: pino.Logger,
|
|
42
|
+
): Promise<DeviceDescriptor> {
|
|
43
|
+
if (!this.hardwareSelected) {
|
|
44
|
+
return this.emulator.selectDevice(devices, savedId, logger)
|
|
45
|
+
}
|
|
46
|
+
const descriptor = await this.real.selectDevice(devices, savedId, logger)
|
|
47
|
+
this.emulator.setDisplayDevice(descriptor)
|
|
48
|
+
return descriptor
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
storeSelection(descriptor: DeviceDescriptor): Promise<void> {
|
|
52
|
+
return this.hardwareSelected
|
|
53
|
+
? this.real.storeSelection(descriptor)
|
|
54
|
+
: Promise.resolve()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async init(opts: InitOptions): Promise<OutputHandle> {
|
|
58
|
+
if (!this.hardwareSelected) return this.emulator.init(opts)
|
|
59
|
+
|
|
60
|
+
const emulatorHandle = await this.emulator.init(opts)
|
|
61
|
+
const token = process.env["SIRENO_TOKEN"] ?? ""
|
|
62
|
+
const realHandle = await this.real.init({
|
|
63
|
+
...opts,
|
|
64
|
+
frontendUrl: `http://127.0.0.1:5180${token.length > 0 ? `?token=${encodeURIComponent(token)}` : ""}`,
|
|
65
|
+
configUiUrl: emulatorHandle.configUiUrl,
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
...realHandle,
|
|
70
|
+
configUiUrl: emulatorHandle.configUiUrl,
|
|
71
|
+
childPids: [...emulatorHandle.childPids, ...realHandle.childPids],
|
|
72
|
+
async stop(): Promise<void> {
|
|
73
|
+
await Promise.allSettled([realHandle.stop(), emulatorHandle.stop()])
|
|
74
|
+
},
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -30,6 +30,8 @@ export interface InitOptions {
|
|
|
30
30
|
readonly configPath?: string
|
|
31
31
|
readonly logger: pino.Logger
|
|
32
32
|
readonly frontendUrl?: string
|
|
33
|
+
/** Reuse a Config UI started by a companion output transport. */
|
|
34
|
+
readonly configUiUrl?: string
|
|
33
35
|
readonly port?: number
|
|
34
36
|
readonly intervalMs?: number
|
|
35
37
|
/**
|
|
@@ -18,9 +18,15 @@ export interface EditorMessageHandlerOptions {
|
|
|
18
18
|
readonly mutationService: ConfigMutationService
|
|
19
19
|
readonly getState: () => Omit<
|
|
20
20
|
EditorStateMessage,
|
|
21
|
-
|
|
21
|
+
| "type"
|
|
22
|
+
| "revision"
|
|
23
|
+
| "canUndo"
|
|
24
|
+
| "buttonSchemas"
|
|
25
|
+
| "themeVariants"
|
|
26
|
+
| "surfaces"
|
|
22
27
|
> & {
|
|
23
28
|
buttonSchemas?: EditorStateMessage["buttonSchemas"]
|
|
29
|
+
themeVariants?: EditorStateMessage["themeVariants"]
|
|
24
30
|
surfaces?: EditorStateMessage["surfaces"]
|
|
25
31
|
revision?: number
|
|
26
32
|
}
|
|
@@ -161,6 +167,11 @@ export const createEditorMessageHandler = (
|
|
|
161
167
|
return
|
|
162
168
|
}
|
|
163
169
|
if (message.type === "editor-asset-write") {
|
|
170
|
+
if (message.revision !== revision) {
|
|
171
|
+
result(socket, message.requestId, false, "stale editor revision")
|
|
172
|
+
send(socket, state())
|
|
173
|
+
return
|
|
174
|
+
}
|
|
164
175
|
void options.mutationService
|
|
165
176
|
.writeAsset(message.filename, message.data)
|
|
166
177
|
.then(() => result(socket, message.requestId, true))
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chooses the endpoint embedded in Vite-served frontend clients. The service
|
|
3
|
+
* bridge keeps listening at its own URL; SIRENO_WS_PROXY_URL only redirects
|
|
4
|
+
* frontend clients through a local capture/debugging proxy.
|
|
5
|
+
*/
|
|
6
|
+
export const frontendBridgeUrl = (
|
|
7
|
+
environment: NodeJS.ProcessEnv = process.env,
|
|
8
|
+
fallback = "ws://127.0.0.1:52937",
|
|
9
|
+
): string =>
|
|
10
|
+
environment["SIRENO_WS_PROXY_URL"] ?? environment["SIRENO_WS_URL"] ?? fallback
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs"
|
|
2
|
+
|
|
3
|
+
import sharp from "sharp"
|
|
4
|
+
|
|
5
|
+
import { gridForKeyCount } from "@/device/models"
|
|
6
|
+
|
|
7
|
+
import type { PushRawImageDevice } from "./push-raw-image"
|
|
8
|
+
|
|
9
|
+
const KEY_SIZE = 72
|
|
10
|
+
const CHANNELS = 3
|
|
11
|
+
const KEY_BYTES = KEY_SIZE * KEY_SIZE * CHANNELS
|
|
12
|
+
|
|
13
|
+
export interface PushStartupScreenOptions {
|
|
14
|
+
readonly logoPath: string
|
|
15
|
+
readonly version: string
|
|
16
|
+
readonly device: PushRawImageDevice
|
|
17
|
+
readonly logger: {
|
|
18
|
+
warn: (obj: unknown, msg?: string) => void
|
|
19
|
+
info: (obj: unknown, msg?: string) => void
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const escapeXml = (value: string): string =>
|
|
24
|
+
value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">")
|
|
25
|
+
|
|
26
|
+
const textTile = (text: string, fontSize: number): Buffer =>
|
|
27
|
+
Buffer.from(
|
|
28
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${KEY_SIZE}" height="${KEY_SIZE}"><rect width="100%" height="100%" fill="#000"/><text x="50%" y="50%" fill="#fff" font-family="sans-serif" font-size="${fontSize}" text-anchor="middle" dominant-baseline="middle">${escapeXml(text)}</text></svg>`,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
const renderTile = async (source: Buffer): Promise<Buffer> =>
|
|
32
|
+
sharp(source)
|
|
33
|
+
.resize(KEY_SIZE, KEY_SIZE, { fit: "contain" })
|
|
34
|
+
.flatten({ background: "#000" })
|
|
35
|
+
.removeAlpha()
|
|
36
|
+
.raw()
|
|
37
|
+
.toBuffer()
|
|
38
|
+
|
|
39
|
+
export async function pushStartupScreen({
|
|
40
|
+
logoPath,
|
|
41
|
+
version,
|
|
42
|
+
device,
|
|
43
|
+
logger,
|
|
44
|
+
}: PushStartupScreenOptions): Promise<void> {
|
|
45
|
+
try {
|
|
46
|
+
const keyCount = device.getKeyCount()
|
|
47
|
+
const { columns, rows } = gridForKeyCount(keyCount)
|
|
48
|
+
const logo = renderTile(readFileSync(logoPath))
|
|
49
|
+
const versionImage = renderTile(textTile(`v${version}`, 13))
|
|
50
|
+
const loadingImage = renderTile(textTile("Loading...", 11))
|
|
51
|
+
const row = Math.floor(rows / 2)
|
|
52
|
+
const logoColumn = Math.floor(columns / 2)
|
|
53
|
+
const firstColumn = Math.max(0, logoColumn - 1)
|
|
54
|
+
const firstKey = row * columns + firstColumn
|
|
55
|
+
const tiles = new Map<number, Promise<Buffer>>([
|
|
56
|
+
[firstKey, versionImage],
|
|
57
|
+
[firstKey + 1, logo],
|
|
58
|
+
[firstKey + 2, loadingImage],
|
|
59
|
+
])
|
|
60
|
+
const black = Buffer.alloc(KEY_BYTES)
|
|
61
|
+
const writes = Array.from({ length: keyCount }, async (_, keyIndex) =>
|
|
62
|
+
device.fillKeyBuffer(keyIndex, await (tiles.get(keyIndex) ?? black)),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
await Promise.all(writes)
|
|
66
|
+
logger.info(
|
|
67
|
+
{ keyCount, centerRow: row, logoPosition: firstKey + 1 },
|
|
68
|
+
"pushStartupScreen: rendered device startup screen",
|
|
69
|
+
)
|
|
70
|
+
} catch (err) {
|
|
71
|
+
logger.warn(
|
|
72
|
+
{ err: (err as Error).message, logoPath },
|
|
73
|
+
"pushStartupScreen: could not render startup screen",
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
}
|
package/src/render/ws-bridge.ts
CHANGED
|
@@ -50,6 +50,7 @@ export interface WsBridge {
|
|
|
50
50
|
setActiveTheme?(theme: { name: string; version?: number }): void
|
|
51
51
|
setDeckTree(tree: Omit<DeckTreeMessage, "type">): void
|
|
52
52
|
broadcast(message: WsMessage): void
|
|
53
|
+
sendToCaller?(socket: WebSocket, message: WsMessage): void
|
|
53
54
|
registerCacheablePoller(
|
|
54
55
|
channel: string,
|
|
55
56
|
pollFn: () => unknown | Promise<unknown>,
|
|
@@ -274,6 +275,7 @@ export const startWsBridge = (options: WsBridgeOptions): Promise<WsBridge> => {
|
|
|
274
275
|
if (client.readyState === client.OPEN) client.send(payload)
|
|
275
276
|
}
|
|
276
277
|
},
|
|
278
|
+
sendToCaller: (socket, message) => sendToSocket(socket, message),
|
|
277
279
|
registerCacheablePoller: (channel, pollFn) => {
|
|
278
280
|
cacheablePollers.set(channel, pollFn)
|
|
279
281
|
const waiting = pendingChannelSubs.get(channel)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs"
|
|
2
|
+
|
|
3
|
+
import type { ActiveAppProvider, ActiveAppSnapshot } from "../active-app"
|
|
4
|
+
|
|
5
|
+
const sameSnapshot = (
|
|
6
|
+
left: ActiveAppSnapshot | null,
|
|
7
|
+
right: ActiveAppSnapshot | null,
|
|
8
|
+
): boolean =>
|
|
9
|
+
left?.name === right?.name &&
|
|
10
|
+
left?.windowTitle === right?.windowTitle &&
|
|
11
|
+
left?.processId === right?.processId
|
|
12
|
+
|
|
13
|
+
const readSnapshot = (path: string): ActiveAppSnapshot | null => {
|
|
14
|
+
try {
|
|
15
|
+
const value: unknown = JSON.parse(readFileSync(path, "utf8"))
|
|
16
|
+
if (value === null) return null
|
|
17
|
+
if (typeof value !== "object" || Array.isArray(value)) return null
|
|
18
|
+
const snapshot = value as Record<string, unknown>
|
|
19
|
+
if (typeof snapshot["name"] !== "string") return null
|
|
20
|
+
const windowTitle = snapshot["windowTitle"]
|
|
21
|
+
const processId = snapshot["processId"]
|
|
22
|
+
return {
|
|
23
|
+
name: snapshot["name"],
|
|
24
|
+
windowTitle: typeof windowTitle === "string" ? windowTitle : null,
|
|
25
|
+
processId:
|
|
26
|
+
typeof processId === "number" && Number.isFinite(processId)
|
|
27
|
+
? processId
|
|
28
|
+
: null,
|
|
29
|
+
}
|
|
30
|
+
} catch {
|
|
31
|
+
return null
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const createCaptureFileActiveAppProvider = (
|
|
36
|
+
path: string,
|
|
37
|
+
): ActiveAppProvider => {
|
|
38
|
+
const subscribers = new Set<(snapshot: ActiveAppSnapshot | null) => void>()
|
|
39
|
+
let last = readSnapshot(path)
|
|
40
|
+
const interval = setInterval(() => {
|
|
41
|
+
const next = readSnapshot(path)
|
|
42
|
+
if (sameSnapshot(last, next)) return
|
|
43
|
+
last = next
|
|
44
|
+
for (const subscriber of subscribers) subscriber(next)
|
|
45
|
+
}, 100)
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
async getActive() {
|
|
49
|
+
last = readSnapshot(path)
|
|
50
|
+
return last
|
|
51
|
+
},
|
|
52
|
+
subscribe(handler) {
|
|
53
|
+
subscribers.add(handler)
|
|
54
|
+
return () => subscribers.delete(handler)
|
|
55
|
+
},
|
|
56
|
+
async stop() {
|
|
57
|
+
clearInterval(interval)
|
|
58
|
+
subscribers.clear()
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -71,7 +71,6 @@ export const hasWaylandGnomeSession = async ({
|
|
|
71
71
|
if (
|
|
72
72
|
env["XDG_SESSION_TYPE"] !== undefined ||
|
|
73
73
|
env["WAYLAND_DISPLAY"] !== undefined ||
|
|
74
|
-
env["DISPLAY"] !== undefined ||
|
|
75
74
|
env["XDG_CURRENT_DESKTOP"] !== undefined
|
|
76
75
|
) {
|
|
77
76
|
return false
|
|
@@ -79,6 +78,30 @@ export const hasWaylandGnomeSession = async ({
|
|
|
79
78
|
if (typeof process.getuid !== "function") return false
|
|
80
79
|
|
|
81
80
|
try {
|
|
81
|
+
// Detached daemons often have no graphical variables in their own
|
|
82
|
+
// environment. systemd --user retains the desktop environment that started
|
|
83
|
+
// the graphical session; use it before probing logind's incomplete Desktop
|
|
84
|
+
// property (Ubuntu commonly leaves that property empty).
|
|
85
|
+
const managerEnvironment = await executor.run(
|
|
86
|
+
"systemctl",
|
|
87
|
+
["--user", "show-environment"],
|
|
88
|
+
{ timeoutMs: PROBE_TIMEOUT_MS },
|
|
89
|
+
)
|
|
90
|
+
const managerEnv: NodeJS.ProcessEnv = {}
|
|
91
|
+
for (const key of [
|
|
92
|
+
"XDG_CURRENT_DESKTOP",
|
|
93
|
+
"XDG_SESSION_TYPE",
|
|
94
|
+
"WAYLAND_DISPLAY",
|
|
95
|
+
]) {
|
|
96
|
+
managerEnv[key] = sessionProperty(managerEnvironment.stdout, key)
|
|
97
|
+
}
|
|
98
|
+
if (
|
|
99
|
+
managerEnvironment.exitCode === 0 &&
|
|
100
|
+
shouldUseWaylandGnomeProvider(managerEnv)
|
|
101
|
+
) {
|
|
102
|
+
return true
|
|
103
|
+
}
|
|
104
|
+
|
|
82
105
|
const sessions = await executor.run("loginctl", [
|
|
83
106
|
"show-user",
|
|
84
107
|
String(process.getuid()),
|
|
@@ -108,17 +131,10 @@ export const hasWaylandGnomeSession = async ({
|
|
|
108
131
|
|
|
109
132
|
// Ubuntu's logind session can omit Desktop. systemd's user manager
|
|
110
133
|
// retains the graphical session variables that the daemon inherits.
|
|
111
|
-
const environment = await executor.run("systemctl", [
|
|
112
|
-
"--user",
|
|
113
|
-
"show-environment",
|
|
114
|
-
])
|
|
115
134
|
if (
|
|
116
|
-
|
|
135
|
+
managerEnvironment.exitCode === 0 &&
|
|
117
136
|
isGnomeDesktop({
|
|
118
|
-
XDG_CURRENT_DESKTOP:
|
|
119
|
-
environment.stdout,
|
|
120
|
-
"XDG_CURRENT_DESKTOP",
|
|
121
|
-
),
|
|
137
|
+
XDG_CURRENT_DESKTOP: managerEnv["XDG_CURRENT_DESKTOP"],
|
|
122
138
|
})
|
|
123
139
|
)
|
|
124
140
|
return true
|
|
@@ -47,6 +47,12 @@ export interface CreateActiveAppProviderOptions {
|
|
|
47
47
|
export const createActiveAppProvider = async (
|
|
48
48
|
options: CreateActiveAppProviderOptions,
|
|
49
49
|
): Promise<ActiveAppProvider> => {
|
|
50
|
+
const captureFile = process.env["SIRENO_CAPTURE_ACTIVE_APP_FILE"]
|
|
51
|
+
if (captureFile !== undefined) {
|
|
52
|
+
const { createCaptureFileActiveAppProvider } =
|
|
53
|
+
await import("./active-app/capture-file")
|
|
54
|
+
return createCaptureFileActiveAppProvider(captureFile)
|
|
55
|
+
}
|
|
50
56
|
const platform = options.platform ?? process.platform
|
|
51
57
|
if (platform === "linux") {
|
|
52
58
|
if (options.executor === undefined) {
|
|
@@ -26,9 +26,28 @@ export const createDarwinClipboardProvider = (
|
|
|
26
26
|
const escaped = text.replace(/'/g, "'\\''")
|
|
27
27
|
try {
|
|
28
28
|
const result = await withTimeout(
|
|
29
|
-
executor.run(
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
executor.run(
|
|
30
|
+
"sh",
|
|
31
|
+
[
|
|
32
|
+
"-c",
|
|
33
|
+
// ponytail: `pbcopy` decides how to read its input from the
|
|
34
|
+
// locale, and with none set it falls back to Mac OS Roman. The
|
|
35
|
+
// daemon normally runs under launchd, which passes almost no
|
|
36
|
+
// environment — the generated unit sets PATH and nothing else — so
|
|
37
|
+
// the bytes of an emoji arrived as the Mac OS Roman characters
|
|
38
|
+
// that happen to share them: 🏉 pasted as "üèâ", 🥏 as "ü•è",
|
|
39
|
+
// each with an invisible Apple-logo byte in front. Nothing failed;
|
|
40
|
+
// pbcopy exited 0 and faithfully copied the wrong text.
|
|
41
|
+
//
|
|
42
|
+
// Stating the encoding here fixes it wherever the daemon was
|
|
43
|
+
// started from, rather than relying on a locale it may not have
|
|
44
|
+
// inherited. `export` so it applies to pbcopy, not just printf.
|
|
45
|
+
`export LC_CTYPE=UTF-8; printf '%s' '${escaped}' | pbcopy`,
|
|
46
|
+
],
|
|
47
|
+
{
|
|
48
|
+
timeoutMs,
|
|
49
|
+
},
|
|
50
|
+
),
|
|
32
51
|
timeoutMs + 500,
|
|
33
52
|
)
|
|
34
53
|
if (result.exitCode !== 0) {
|
|
@@ -51,7 +70,12 @@ export const createDarwinClipboardProvider = (
|
|
|
51
70
|
if (disposed) throw new Error("Clipboard provider is disposed")
|
|
52
71
|
try {
|
|
53
72
|
const result = await withTimeout(
|
|
54
|
-
|
|
73
|
+
// Same locale caveat as the write: without LC_CTYPE, pbpaste renders
|
|
74
|
+
// the pasteboard as Mac OS Roman and hands back mojibake for anything
|
|
75
|
+
// outside ASCII.
|
|
76
|
+
executor.run("sh", ["-c", "export LC_CTYPE=UTF-8; pbpaste"], {
|
|
77
|
+
timeoutMs,
|
|
78
|
+
}),
|
|
55
79
|
timeoutMs + 500,
|
|
56
80
|
)
|
|
57
81
|
if (result.exitCode === 0) return result.stdout
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { CommandExecutor } from "./shared"
|
|
2
|
+
|
|
3
|
+
export interface UrlProvider {
|
|
4
|
+
open(url: string): Promise<void>
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const ALLOWED_PROTOCOLS = new Set(["http:", "https:", "mailto:", "tel:"])
|
|
8
|
+
|
|
9
|
+
export const validateOpenUrl = (value: string): string => {
|
|
10
|
+
let url: URL
|
|
11
|
+
try {
|
|
12
|
+
url = new URL(value)
|
|
13
|
+
} catch {
|
|
14
|
+
throw new Error("url:// requires a valid absolute URL")
|
|
15
|
+
}
|
|
16
|
+
if (!ALLOWED_PROTOCOLS.has(url.protocol)) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`url:// does not allow the '${url.protocol}' protocol; use http, https, mailto, or tel`,
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
if (
|
|
22
|
+
(url.protocol === "http:" || url.protocol === "https:") &&
|
|
23
|
+
url.hostname.length === 0
|
|
24
|
+
) {
|
|
25
|
+
throw new Error("url:// HTTP(S) URLs must include a host")
|
|
26
|
+
}
|
|
27
|
+
if (
|
|
28
|
+
(url.protocol === "mailto:" || url.protocol === "tel:") &&
|
|
29
|
+
url.pathname.length === 0
|
|
30
|
+
) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`url:// ${url.protocol.slice(0, -1)} URLs must include a target`,
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
return value
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const createUrlProvider = (
|
|
39
|
+
platform: NodeJS.Platform,
|
|
40
|
+
executor: CommandExecutor,
|
|
41
|
+
): UrlProvider => ({
|
|
42
|
+
async open(value) {
|
|
43
|
+
const url = validateOpenUrl(value)
|
|
44
|
+
const [command, args] =
|
|
45
|
+
platform === "darwin"
|
|
46
|
+
? ["open", [url]]
|
|
47
|
+
: platform === "win32"
|
|
48
|
+
? ["rundll32.exe", ["url.dll,FileProtocolHandler", url]]
|
|
49
|
+
: ["xdg-open", [url]]
|
|
50
|
+
const result = await executor.run(command, args)
|
|
51
|
+
if (result.exitCode !== 0) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
`Unable to open URL (${command} exited ${result.exitCode}): ${result.stderr}`,
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
})
|
package/src/util/logger.ts
CHANGED
|
@@ -90,6 +90,7 @@ const CONTEXT_FIELDS = [
|
|
|
90
90
|
"addonConfigEntries",
|
|
91
91
|
"icon",
|
|
92
92
|
"fullPath",
|
|
93
|
+
"reason",
|
|
93
94
|
] as const
|
|
94
95
|
|
|
95
96
|
const FORWARDED_CONTEXT_FIELDS = [
|
|
@@ -128,6 +129,22 @@ const formatLogTime = (value: unknown): string | null => {
|
|
|
128
129
|
return `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}.${pad(d.getMilliseconds(), 3)}`
|
|
129
130
|
}
|
|
130
131
|
|
|
132
|
+
const formatContextValue = (key: string, value: unknown): string => {
|
|
133
|
+
if (key === "reason" && typeof value === "object" && value !== null) {
|
|
134
|
+
const reason = value as {
|
|
135
|
+
type?: unknown
|
|
136
|
+
message?: unknown
|
|
137
|
+
value?: unknown
|
|
138
|
+
}
|
|
139
|
+
if (typeof reason.message === "string" && reason.message.length > 0) {
|
|
140
|
+
const type = typeof reason.type === "string" ? reason.type : "Error"
|
|
141
|
+
return `${type}: ${reason.message}`
|
|
142
|
+
}
|
|
143
|
+
if (typeof reason.value === "string") return reason.value
|
|
144
|
+
}
|
|
145
|
+
return typeof value === "string" ? value : JSON.stringify(value)
|
|
146
|
+
}
|
|
147
|
+
|
|
131
148
|
export const formatHuman = (
|
|
132
149
|
jsonLine: string,
|
|
133
150
|
options: FormatHumanOptions = {},
|
|
@@ -161,7 +178,7 @@ export const formatHuman = (
|
|
|
161
178
|
for (const key of CONTEXT_FIELDS) {
|
|
162
179
|
const value = entry[key]
|
|
163
180
|
if (value === undefined || value === null) continue
|
|
164
|
-
const display =
|
|
181
|
+
const display = formatContextValue(key, value)
|
|
165
182
|
if (display.length === 0) continue
|
|
166
183
|
ctxParts.push(`${colorize(DIM, `${key}:`)} ${display}`)
|
|
167
184
|
}
|
|
@@ -223,8 +240,7 @@ class HumanWritable extends Writable {
|
|
|
223
240
|
for (const key of CONTEXT_FIELDS) {
|
|
224
241
|
const value = entry[key]
|
|
225
242
|
if (value === undefined || value === null) continue
|
|
226
|
-
const display =
|
|
227
|
-
typeof value === "string" ? value : JSON.stringify(value)
|
|
243
|
+
const display = formatContextValue(key, value)
|
|
228
244
|
if (display.length === 0) continue
|
|
229
245
|
ctxParts.push(`${key}: ${display}`)
|
|
230
246
|
}
|
package/src/version.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import packageJson from "../package.json" with { type: "json" }
|
|
2
|
+
|
|
1
3
|
export const PACKAGE_NAME = "@sirenodeck/sirenodeck"
|
|
2
4
|
/**
|
|
3
5
|
* The name users actually type. `PACKAGE_NAME` is the npm package, which is
|
|
@@ -5,6 +7,6 @@ export const PACKAGE_NAME = "@sirenodeck/sirenodeck"
|
|
|
5
7
|
* a string that is not a runnable command. Keep the two separate.
|
|
6
8
|
*/
|
|
7
9
|
export const BIN_NAME = "sirenodeck"
|
|
8
|
-
export const VERSION =
|
|
10
|
+
export const VERSION: string = packageJson.version
|
|
9
11
|
export const SIRENO_ADDON_API_VERSION = 3
|
|
10
12
|
export const PROTOCOL_VERSION = 3
|