@sirenodeck/sirenodeck 0.2.10 → 0.4.1
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/config-ui/vite.config.ts +2 -0
- package/dist/main.mjs +1585 -807
- package/dist/{windows-CRWdUgCn.mjs → windows-BCvfQ3PA.mjs} +4 -4
- package/frontend/src/App.tsx +3 -0
- package/frontend/src/components/Deck.tsx +13 -2
- package/frontend/vite.config.ts +2 -0
- package/package.json +10 -1
- package/src/addon/api.ts +24 -1
- package/src/addon/data-directory.ts +52 -0
- package/src/api/protocol-internal.ts +5 -0
- package/src/builtin-addons/index.ts +0 -1
- package/src/builtin-addons/internal-settings/backend.ts +1 -1
- package/src/builtin-addons/internal-settings/buttons/brightness/common/frontend.tsx +14 -3
- package/src/builtin-addons/internal-settings/buttons/brightness-compact/frontend.tsx +6 -0
- package/src/builtin-addons/internal-settings/index.ts +15 -0
- package/src/builtin-addons/register-builtins.ts +0 -3
- package/src/cli/commands/addon-decks.ts +1 -0
- package/src/cli/commands/addon-setup-config.ts +85 -0
- package/src/cli/commands/addon-setup.ts +134 -0
- package/src/cli/commands/run.ts +57 -11
- package/src/cli/commands/service-manager.ts +3 -5
- package/src/cli/commands/start.ts +14 -81
- package/src/cli/commands/status-probes.ts +126 -0
- package/src/cli/commands/status.ts +166 -16
- package/src/cli/commands/stop.ts +4 -0
- package/src/cli/index.ts +2 -0
- package/src/config/environment.ts +44 -0
- package/src/config/loader.ts +17 -1
- package/src/config/schemas.ts +2 -1
- package/src/config/validation.ts +5 -1
- package/src/deck/addon-handler-bridge.ts +105 -6
- package/src/deck/addon-settings.ts +94 -0
- package/src/deck/deck-config.ts +1 -0
- package/src/deck/inject-config-ui-button.ts +25 -14
- package/src/deck/runtime/runtime.ts +175 -3
- package/src/deck/system-back-injection.ts +2 -0
- package/src/deck/system-buttons/registry.tsx +1 -0
- package/src/deck/system-buttons/types.ts +1 -0
- package/src/outputClient/real.ts +18 -1
- package/src/render/browser-renderer.ts +68 -12
- package/src/render/ws-bridge.ts +2 -0
- package/src/system/credentials/native.ts +74 -0
- package/src/system/credentials/store.ts +77 -0
- package/src/system/providers/notification/windows.ts +4 -4
- package/src/themes/default/sirenodeck.json +1 -0
- package/src/themes/light/sirenodeck.json +1 -0
- package/src/themes/manifest.ts +1 -0
- package/src/ui/primitives/Chip.tsx +1 -0
- package/src/ui/primitives/StatusIndicator.tsx +36 -0
- package/src/ui/primitives/index.ts +1 -0
- package/src/ui/surfaces/BinaryToggleSurface.tsx +52 -0
- package/src/ui/surfaces/LoadingSurface.tsx +34 -0
- package/src/ui/surfaces/index.ts +2 -0
- package/src/util/build-fingerprint.ts +32 -0
- package/src/util/daemon-control.ts +41 -0
- package/src/util/runtime-health.ts +57 -0
- package/src/util/runtime-identity.ts +25 -0
- package/src/vite/component-identity.ts +48 -0
- package/src/builtin-addons/brightness/README.md +0 -51
- package/src/builtin-addons/brightness/buttons/brightness/backend.ts +0 -13
- package/src/builtin-addons/brightness/buttons/brightness/config.ts +0 -20
- package/src/builtin-addons/brightness/buttons/brightness/frontend.tsx +0 -50
- package/src/builtin-addons/brightness/domain/macos.ts +0 -46
- package/src/builtin-addons/brightness/index.d.ts +0 -5
- package/src/builtin-addons/brightness/index.ts +0 -20
- package/src/builtin-addons/brightness/poller.ts +0 -27
- package/src/builtin-addons/brightness/sirenodeck.json +0 -6
- /package/src/builtin-addons/{brightness/providers → internal-settings/brightness-providers}/darwin.ts +0 -0
- /package/src/builtin-addons/{brightness/providers → internal-settings/brightness-providers}/index.ts +0 -0
- /package/src/builtin-addons/{brightness/providers → internal-settings/brightness-providers}/linux.ts +0 -0
- /package/src/builtin-addons/{brightness/providers → internal-settings/brightness-providers}/windows.ts +0 -0
package/dist/main.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import yargs from "yargs";
|
|
|
5
5
|
import { hideBin } from "yargs/helpers";
|
|
6
6
|
import { basename, dirname, extname, isAbsolute, join, normalize, resolve, sep } from "node:path";
|
|
7
7
|
import { Writable } from "node:stream";
|
|
8
|
-
import { cancel, confirm, intro, isCancel, log, log as log$1, note, outro, select, spinner } from "@clack/prompts";
|
|
8
|
+
import { cancel, confirm, confirm as confirm$1, intro, isCancel, isCancel as isCancel$1, log, log as log$1, multiselect, note, outro, password, select, spinner, text } from "@clack/prompts";
|
|
9
9
|
import pino from "pino";
|
|
10
10
|
import { chmodSync, closeSync, copyFileSync, cpSync, createWriteStream, existsSync, fchmodSync, fsyncSync, mkdirSync, mkdtempSync, openSync, readFileSync, readSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
|
|
11
11
|
import { createHash, randomBytes } from "node:crypto";
|
|
@@ -15,18 +15,18 @@ import { execFile, execFileSync, spawn } from "node:child_process";
|
|
|
15
15
|
import { z } from "zod";
|
|
16
16
|
import { connect, createServer } from "node:net";
|
|
17
17
|
import { createServer as createServer$1 } from "node:http";
|
|
18
|
-
import { open, readFile, readdir, stat, unlink } from "node:fs/promises";
|
|
18
|
+
import { chmod, lstat, mkdir, open, readFile, readdir, stat, unlink } from "node:fs/promises";
|
|
19
19
|
import { createContext, createElement, useCallback, useContext, useEffect, useRef, useState } from "react";
|
|
20
20
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
21
21
|
import * as lucideIcons from "lucide-react";
|
|
22
|
-
import { YAMLMap, YAMLParseError, YAMLSeq, parse, parseAllDocuments, parseDocument, stringify } from "yaml";
|
|
22
|
+
import { YAMLMap, YAMLParseError, YAMLSeq, isMap, isScalar, isSeq, parse, parseAllDocuments, parseDocument, stringify } from "yaml";
|
|
23
23
|
import { execa } from "execa";
|
|
24
24
|
import { sessionBus } from "dbus-next";
|
|
25
25
|
import chokidar from "chokidar";
|
|
26
|
-
import { WebSocketServer } from "ws";
|
|
27
|
-
import { getStreamDeckModelName, listStreamDecks, openStreamDeck } from "@elgato-stream-deck/node";
|
|
26
|
+
import WebSocket, { WebSocketServer } from "ws";
|
|
28
27
|
import sharp from "sharp";
|
|
29
|
-
import {
|
|
28
|
+
import { getStreamDeckModelName, listStreamDecks, openStreamDeck } from "@elgato-stream-deck/node";
|
|
29
|
+
import { promisify, styleText } from "node:util";
|
|
30
30
|
import { applyEdits, modify, parse as parse$1 } from "jsonc-parser";
|
|
31
31
|
import qrcode from "qrcode";
|
|
32
32
|
//#region \0rolldown/runtime.js
|
|
@@ -74,7 +74,7 @@ const LEVEL_LABEL = {
|
|
|
74
74
|
50: "ERROR",
|
|
75
75
|
60: "FATAL"
|
|
76
76
|
};
|
|
77
|
-
const colorize = (color, text) => process.stdout.isTTY ? `${color}${text}${RESET}` : text;
|
|
77
|
+
const colorize$1 = (color, text) => process.stdout.isTTY ? `${color}${text}${RESET}` : text;
|
|
78
78
|
const COMPONENT_COLOR = {
|
|
79
79
|
runtime: CYAN,
|
|
80
80
|
methods: CYAN,
|
|
@@ -154,25 +154,25 @@ const formatHuman = (jsonLine, options = {}) => {
|
|
|
154
154
|
const level = LEVEL_LABEL[levelNum] ?? "INFO";
|
|
155
155
|
const levelColor = LEVEL_COLOR[levelNum] ?? CYAN;
|
|
156
156
|
const msg = typeof entry["msg"] === "string" ? entry["msg"] : "";
|
|
157
|
-
const head = colorize(levelColor, level.padEnd(5));
|
|
157
|
+
const head = colorize$1(levelColor, level.padEnd(5));
|
|
158
158
|
const time = options.timestamps === true ? formatLogTime(entry["time"]) : null;
|
|
159
|
-
const timeTag = time !== null ? `${colorize(DIM, time)} ` : "";
|
|
159
|
+
const timeTag = time !== null ? `${colorize$1(DIM, time)} ` : "";
|
|
160
160
|
const component = typeof entry["component"] === "string" ? entry["component"] : "";
|
|
161
|
-
const componentTag = component.length > 0 ? ` ${colorize(colorForComponent(component), `[${component}]`)}` : "";
|
|
161
|
+
const componentTag = component.length > 0 ? ` ${colorize$1(colorForComponent(component), `[${component}]`)}` : "";
|
|
162
162
|
const ctxParts = [];
|
|
163
163
|
for (const key of CONTEXT_FIELDS) {
|
|
164
164
|
const value = entry[key];
|
|
165
165
|
if (value === void 0 || value === null) continue;
|
|
166
166
|
const display = formatContextValue(key, value);
|
|
167
167
|
if (display.length === 0) continue;
|
|
168
|
-
ctxParts.push(`${colorize(DIM, `${key}:`)} ${display}`);
|
|
168
|
+
ctxParts.push(`${colorize$1(DIM, `${key}:`)} ${display}`);
|
|
169
169
|
}
|
|
170
170
|
const err = entry["err"];
|
|
171
171
|
if (err !== null && typeof err === "object") {
|
|
172
172
|
const e = err;
|
|
173
173
|
const errType = typeof e.type === "string" ? e.type : "Error";
|
|
174
174
|
const errMsg = typeof e.message === "string" ? e.message : "";
|
|
175
|
-
if (errMsg.length > 0) ctxParts.push(`${colorize(DIM, "err:")} ${colorize(RED, `${errType}: ${errMsg}`)}`);
|
|
175
|
+
if (errMsg.length > 0) ctxParts.push(`${colorize$1(DIM, "err:")} ${colorize$1(RED, `${errType}: ${errMsg}`)}`);
|
|
176
176
|
}
|
|
177
177
|
return `${timeTag}${head}${componentTag} ${msg}${ctxParts.length > 0 ? ` (${ctxParts.join(", ")})` : ""}`;
|
|
178
178
|
};
|
|
@@ -308,7 +308,7 @@ const levelNameFromNumber = (level) => {
|
|
|
308
308
|
};
|
|
309
309
|
//#endregion
|
|
310
310
|
//#region package.json
|
|
311
|
-
var version$1 = "0.
|
|
311
|
+
var version$1 = "0.4.1";
|
|
312
312
|
//#endregion
|
|
313
313
|
//#region src/version.ts
|
|
314
314
|
const PACKAGE_NAME = "@sirenodeck/sirenodeck";
|
|
@@ -822,8 +822,6 @@ const refreshStaleUnit = (content, currentScript, nodePath, exists = existsSync)
|
|
|
822
822
|
const match = content.match(/^ExecStart="([^"]+)" "([^"]+\/dist\/main\.mjs)" start$/m);
|
|
823
823
|
const oldScript = match?.[2];
|
|
824
824
|
if (match === null || oldScript === void 0 || oldScript === currentScript || !exists(currentScript)) return content;
|
|
825
|
-
const brewUpgrade = oldScript.includes("/Cellar/sirenodeck/") && currentScript.includes("/Cellar/sirenodeck/");
|
|
826
|
-
if (exists(oldScript) && !brewUpgrade) return content;
|
|
827
825
|
return content.replace(match[0], `ExecStart="${nodePath}" "${currentScript}" start`);
|
|
828
826
|
};
|
|
829
827
|
const systemctl = (userLevel, args) => {
|
|
@@ -937,8 +935,9 @@ const invokeManager = async (options) => {
|
|
|
937
935
|
const plist = join(homedir(), "Library", "LaunchAgents", `${DAEMON_NAME}.plist`);
|
|
938
936
|
const uid = String(process.getuid?.() ?? 0);
|
|
939
937
|
if (action === "start") await bootstrapWithRetry(uid, plist, DAEMON_NAME);
|
|
940
|
-
else if (action === "stop")
|
|
941
|
-
|
|
938
|
+
else if (action === "stop") {
|
|
939
|
+
if (isJobLoaded(uid, DAEMON_NAME)) launchctl("bootout", [`gui/${uid}/${DAEMON_NAME}`]);
|
|
940
|
+
} else if (action === "restart") {
|
|
942
941
|
try {
|
|
943
942
|
launchctl("bootout", [`gui/${uid}/${DAEMON_NAME}`]);
|
|
944
943
|
} catch {}
|
|
@@ -1106,6 +1105,7 @@ const resolveConfigPath$1 = (options) => {
|
|
|
1106
1105
|
//#region src/themes/manifest.ts
|
|
1107
1106
|
const ThemeColorTokenSchema = z.object({
|
|
1108
1107
|
background: z.string().min(1),
|
|
1108
|
+
modalDeckBgr: z.string().min(1).optional(),
|
|
1109
1109
|
frame: z.string().min(1),
|
|
1110
1110
|
foreground: z.string().min(1),
|
|
1111
1111
|
"foreground-contrast": z.string().min(1),
|
|
@@ -2022,6 +2022,61 @@ const startHttpServer = async (options) => {
|
|
|
2022
2022
|
};
|
|
2023
2023
|
};
|
|
2024
2024
|
//#endregion
|
|
2025
|
+
//#region src/util/runtime-identity.ts
|
|
2026
|
+
const development = process.env.SIRENO_DEV_MODE === "true";
|
|
2027
|
+
let buildId = null;
|
|
2028
|
+
buildId = "8d333f4a04af63988df6c4ecb9ac6da7bbfc3a40389d8d8c532391bdaa7f448a";
|
|
2029
|
+
const runtimeIdentity = {
|
|
2030
|
+
version: `${VERSION}${development ? "-dev" : ""}`,
|
|
2031
|
+
buildId
|
|
2032
|
+
};
|
|
2033
|
+
//#endregion
|
|
2034
|
+
//#region src/util/runtime-health.ts
|
|
2035
|
+
const runtimeHealthSchema = z.object({
|
|
2036
|
+
identity: z.object({
|
|
2037
|
+
version: z.string(),
|
|
2038
|
+
buildId: z.string().nullable()
|
|
2039
|
+
}).strict(),
|
|
2040
|
+
core: z.enum([
|
|
2041
|
+
"starting",
|
|
2042
|
+
"ready",
|
|
2043
|
+
"stopping"
|
|
2044
|
+
]),
|
|
2045
|
+
renderer: z.object({
|
|
2046
|
+
state: z.enum([
|
|
2047
|
+
"starting",
|
|
2048
|
+
"healthy",
|
|
2049
|
+
"recovering",
|
|
2050
|
+
"failed",
|
|
2051
|
+
"not-applicable"
|
|
2052
|
+
]),
|
|
2053
|
+
lastFrameAt: z.number().finite().nullable()
|
|
2054
|
+
}).strict()
|
|
2055
|
+
}).strict();
|
|
2056
|
+
const health = {
|
|
2057
|
+
identity: runtimeIdentity,
|
|
2058
|
+
core: "starting",
|
|
2059
|
+
renderer: {
|
|
2060
|
+
state: "starting",
|
|
2061
|
+
lastFrameAt: null
|
|
2062
|
+
}
|
|
2063
|
+
};
|
|
2064
|
+
const runtimeHealth = {
|
|
2065
|
+
snapshot: () => ({
|
|
2066
|
+
...health,
|
|
2067
|
+
renderer: { ...health.renderer }
|
|
2068
|
+
}),
|
|
2069
|
+
setCore: (state) => {
|
|
2070
|
+
health.core = state;
|
|
2071
|
+
},
|
|
2072
|
+
setRenderer: (state, lastFrameAt = health.renderer.lastFrameAt) => {
|
|
2073
|
+
health.renderer = {
|
|
2074
|
+
state,
|
|
2075
|
+
lastFrameAt
|
|
2076
|
+
};
|
|
2077
|
+
}
|
|
2078
|
+
};
|
|
2079
|
+
//#endregion
|
|
2025
2080
|
//#region src/util/daemon-control.ts
|
|
2026
2081
|
const GET_TOKEN = "get-token\n";
|
|
2027
2082
|
/**
|
|
@@ -2039,6 +2094,7 @@ const startDaemonControl = async (token, paths, logger) => {
|
|
|
2039
2094
|
socket.setEncoding("utf8");
|
|
2040
2095
|
socket.on("data", (data) => {
|
|
2041
2096
|
if (String(data).trim() === "get-token") socket.end(`${token}\n`);
|
|
2097
|
+
else if (String(data).trim() === "get-health") socket.end(`${JSON.stringify(runtimeHealth.snapshot())}\n`);
|
|
2042
2098
|
else socket.destroy();
|
|
2043
2099
|
});
|
|
2044
2100
|
});
|
|
@@ -2083,6 +2139,35 @@ const requestDaemonToken = (paths, timeoutMs = 1e3) => new Promise((resolve) =>
|
|
|
2083
2139
|
const removeDaemonControl = (paths) => {
|
|
2084
2140
|
if (existsSync(paths.controlSocket)) unlinkSync(paths.controlSocket);
|
|
2085
2141
|
};
|
|
2142
|
+
const requestDaemonHealth = (paths, timeoutMs = 1e3) => new Promise((resolve) => {
|
|
2143
|
+
if (!existsSync(paths.controlSocket)) return resolve(null);
|
|
2144
|
+
const socket = connect(paths.controlSocket);
|
|
2145
|
+
let data = "";
|
|
2146
|
+
let settled = false;
|
|
2147
|
+
const finish = (value) => {
|
|
2148
|
+
if (settled) return;
|
|
2149
|
+
settled = true;
|
|
2150
|
+
clearTimeout(timer);
|
|
2151
|
+
socket.destroy();
|
|
2152
|
+
resolve(value);
|
|
2153
|
+
};
|
|
2154
|
+
const timer = setTimeout(() => finish(null), timeoutMs);
|
|
2155
|
+
socket.setEncoding("utf8");
|
|
2156
|
+
socket.on("connect", () => socket.write("get-health\n"));
|
|
2157
|
+
socket.on("data", (chunk) => {
|
|
2158
|
+
data += chunk;
|
|
2159
|
+
if (!data.includes("\n")) return;
|
|
2160
|
+
try {
|
|
2161
|
+
const parsed = JSON.parse(data.split("\n", 1)[0]);
|
|
2162
|
+
const result = runtimeHealthSchema.safeParse(parsed);
|
|
2163
|
+
finish(result.success ? result.data : null);
|
|
2164
|
+
} catch {
|
|
2165
|
+
finish(null);
|
|
2166
|
+
}
|
|
2167
|
+
});
|
|
2168
|
+
socket.on("error", () => finish(null));
|
|
2169
|
+
socket.on("close", () => finish(null));
|
|
2170
|
+
});
|
|
2086
2171
|
//#endregion
|
|
2087
2172
|
//#region src/cli/commands/addon-registry.ts
|
|
2088
2173
|
const buildAddonByType = (scanned) => {
|
|
@@ -3011,142 +3096,365 @@ var AddonRegistry = class {
|
|
|
3011
3096
|
//#region src/deck/system-buttons/types.ts
|
|
3012
3097
|
const SYSTEM_BUTTON_TYPES = [
|
|
3013
3098
|
"core:back",
|
|
3099
|
+
"core:modal-ok",
|
|
3014
3100
|
"core:settings-entry",
|
|
3015
3101
|
"core:overlay-toggle",
|
|
3016
3102
|
"core:temporary-error"
|
|
3017
3103
|
];
|
|
3018
3104
|
const isSystemButtonType = (value) => SYSTEM_BUTTON_TYPES.includes(value);
|
|
3019
3105
|
//#endregion
|
|
3020
|
-
//#region src/
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
];
|
|
3039
|
-
|
|
3040
|
-
const
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3106
|
+
//#region src/deck/position-buttons.ts
|
|
3107
|
+
/**
|
|
3108
|
+
* Assigns a position to every button — no drops.
|
|
3109
|
+
*
|
|
3110
|
+
* - Buttons with a valid explicit `position` keep it (first-come wins
|
|
3111
|
+
* for duplicates).
|
|
3112
|
+
* - Duplicate positions and buttons without a position fall through to
|
|
3113
|
+
* a "gap" queue, filled sequentially starting at 0 in array order.
|
|
3114
|
+
* - Positions ≥ keyCount are preserved: the caller is responsible for
|
|
3115
|
+
* pagination (group by `floor(pos / (K-2))`). The deck-config and
|
|
3116
|
+
* addon-deck pipelines both go through `paginateDeck` for that.
|
|
3117
|
+
* - The internal contract: every emitted button has `position` set.
|
|
3118
|
+
*
|
|
3119
|
+
* ponytail: O(n²) scan is fine for deck sizes (<30).
|
|
3120
|
+
*/
|
|
3121
|
+
const positionButtons = (buttons, keyCount, logger) => {
|
|
3122
|
+
const occupied = /* @__PURE__ */ new Set();
|
|
3123
|
+
const result = [];
|
|
3124
|
+
const unfixed = [];
|
|
3125
|
+
for (const btn of buttons) {
|
|
3126
|
+
const pos = btn.position;
|
|
3127
|
+
if (pos === void 0 || !Number.isFinite(pos) || pos < 0) {
|
|
3128
|
+
unfixed.push(btn);
|
|
3129
|
+
continue;
|
|
3130
|
+
}
|
|
3131
|
+
if (occupied.has(pos)) {
|
|
3132
|
+
logger?.debug({
|
|
3133
|
+
position: pos,
|
|
3134
|
+
reason: "duplicate"
|
|
3135
|
+
}, "duplicate position, treating as unfixed");
|
|
3136
|
+
unfixed.push(btn);
|
|
3137
|
+
continue;
|
|
3138
|
+
}
|
|
3139
|
+
occupied.add(pos);
|
|
3140
|
+
result.push(btn);
|
|
3141
|
+
}
|
|
3142
|
+
let gap = 0;
|
|
3143
|
+
for (const btn of unfixed) {
|
|
3144
|
+
while (occupied.has(gap)) gap++;
|
|
3145
|
+
occupied.add(gap);
|
|
3146
|
+
result.push({
|
|
3147
|
+
...btn,
|
|
3148
|
+
position: gap
|
|
3149
|
+
});
|
|
3150
|
+
gap++;
|
|
3056
3151
|
}
|
|
3152
|
+
return result;
|
|
3057
3153
|
};
|
|
3058
3154
|
//#endregion
|
|
3059
|
-
//#region src/
|
|
3060
|
-
const
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3155
|
+
//#region src/core/icon-source.ts
|
|
3156
|
+
const EMOJI_RE = /^(?:[\p{Extended_Pictographic}\p{Emoji_Component}]\uFE0F?(?:\u200D[\p{Extended_Pictographic}\p{Emoji_Component}]\uFE0F?)*|\p{Regional_Indicator}{2})$/u;
|
|
3157
|
+
const ICON_FALLBACK = "icon://alert-circle";
|
|
3158
|
+
const ABSOLUTE_PATH_RE = /^(?:\/|\\|[A-Za-z]:[\\/])/;
|
|
3159
|
+
/**
|
|
3160
|
+
* Validate that a runtime icon source is one of:
|
|
3161
|
+
* - `icon://<name>` — Lucide icon by name (resolved by the runtime
|
|
3162
|
+
* `resolveIconSource`)
|
|
3163
|
+
* - `asset://<id>` — pre-resolved asset id from the registry
|
|
3164
|
+
* - `addon://<a>/<p>` — asset inside an addon's frontendEntry dir
|
|
3165
|
+
* - `builtin://<p>` — asset inside the builtin addon's dir
|
|
3166
|
+
* - absolute path — asset resolved directly
|
|
3167
|
+
* - relative path — asset resolved against the config's baseDirs
|
|
3168
|
+
* (e.g. `./assets/chrome.svg`, `../shared/icon.svg`,
|
|
3169
|
+
* `~/Pictures/x.png`)
|
|
3170
|
+
* - a single emoji (Presentation, or base+VS16 like ✈️; also
|
|
3171
|
+
* regional-indicator pair flags like 🇪🇸, and ZWJ sequences
|
|
3172
|
+
* like 🏳️🌈 or 👨👩👧)
|
|
3173
|
+
*
|
|
3174
|
+
* Rejected: empty string, "%", "abc", multi-char (e.g. "abc🔥"),
|
|
3175
|
+
* inline URLs (data:, http://, https://, file://) — these must be
|
|
3176
|
+
* pre-resolved to asset:// before reaching the runtime.
|
|
3177
|
+
*
|
|
3178
|
+
* Anything rejected here triggers a runtime fallback (alert-circle
|
|
3179
|
+
* Lucide icon) AND, at config-load, a zod validation error.
|
|
3180
|
+
*/
|
|
3181
|
+
const isIconSource = (s) => {
|
|
3182
|
+
if (typeof s !== "string" || s.length === 0) return false;
|
|
3183
|
+
if (EMOJI_RE.test(s)) return true;
|
|
3184
|
+
if (s.startsWith("icon://") && s.length > 7) return true;
|
|
3185
|
+
if (s.startsWith("asset://") && s.length > 8) return true;
|
|
3186
|
+
if (s.startsWith("addon://")) {
|
|
3187
|
+
const rest = s.slice(8);
|
|
3188
|
+
const slash = rest.indexOf("/");
|
|
3189
|
+
if (slash > 0 && slash < rest.length - 1) return true;
|
|
3190
|
+
return false;
|
|
3191
|
+
}
|
|
3192
|
+
if (s.startsWith("builtin://") && s.length > 10) return true;
|
|
3193
|
+
if (s.startsWith("data:") || s.startsWith("http://") || s.startsWith("https://") || s.startsWith("file://")) return false;
|
|
3194
|
+
if (ABSOLUTE_PATH_RE.test(s)) return true;
|
|
3195
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(s)) return false;
|
|
3196
|
+
if (s === "." || s === "~" || s.startsWith("./") || s.startsWith("../") || s.startsWith("~/") || s.startsWith("~\\") || /[\\/]/.test(s) || s.startsWith("/")) return true;
|
|
3197
|
+
return false;
|
|
3068
3198
|
};
|
|
3069
3199
|
//#endregion
|
|
3070
|
-
//#region src/
|
|
3071
|
-
const
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
const
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
"
|
|
3108
|
-
"
|
|
3109
|
-
"4xl": "text-4xl",
|
|
3110
|
-
"5xl": "text-5xl"
|
|
3111
|
-
};
|
|
3112
|
-
const RICH_TONE_TAGS = [
|
|
3113
|
-
"accent",
|
|
3114
|
-
"danger",
|
|
3115
|
-
"foreground",
|
|
3116
|
-
"primary",
|
|
3117
|
-
"success"
|
|
3118
|
-
];
|
|
3119
|
-
const RICH_SIZE_TAGS = [
|
|
3120
|
-
"xxs",
|
|
3121
|
-
"xs",
|
|
3122
|
-
"sm",
|
|
3123
|
-
"md",
|
|
3124
|
-
"lg",
|
|
3125
|
-
"xl",
|
|
3126
|
-
"2xl",
|
|
3127
|
-
"3xl",
|
|
3128
|
-
"4xl",
|
|
3129
|
-
"5xl"
|
|
3130
|
-
];
|
|
3131
|
-
const RICH_TAG_NAMES = /* @__PURE__ */ new Set([
|
|
3132
|
-
...RICH_TONE_TAGS,
|
|
3133
|
-
...RICH_SIZE_TAGS,
|
|
3134
|
-
"blink",
|
|
3135
|
-
"dim",
|
|
3136
|
-
"strong"
|
|
3200
|
+
//#region src/config/schemas.ts
|
|
3201
|
+
const TriggerSchema = z.object({
|
|
3202
|
+
process_name: z.union([z.string(), z.array(z.string()).min(1)]).optional(),
|
|
3203
|
+
window_name: z.union([z.string(), z.array(z.string()).min(1)]).optional()
|
|
3204
|
+
}).strict().refine((t) => t.process_name !== void 0 || t.window_name !== void 0, { message: "trigger requires at least one of `process_name` or `window_name`" });
|
|
3205
|
+
const ButtonActionsSchema = z.object({
|
|
3206
|
+
tap: z.string().min(1).optional().meta({ title: "Tap action" }),
|
|
3207
|
+
dbltap: z.string().min(1).optional().meta({ title: "Double-tap action" }),
|
|
3208
|
+
hold: z.string().min(1).optional().meta({ title: "Hold action" })
|
|
3209
|
+
}).strict();
|
|
3210
|
+
/**
|
|
3211
|
+
* Runtime icon source. Accepted shapes:
|
|
3212
|
+
* - `icon://<name>` — Lucide icon by name (resolved at render time)
|
|
3213
|
+
* - `asset://<id>` — pre-resolved asset id from the registry
|
|
3214
|
+
* - a single emoji (Presentation or base+VS16 like ✈️)
|
|
3215
|
+
*
|
|
3216
|
+
* Anything else is rejected at config-load time so typos surface before
|
|
3217
|
+
* the daemon starts. The runtime also has a fallback path (alert-circle
|
|
3218
|
+
* Lucide icon) so an invalid source that's slipped through can't crash
|
|
3219
|
+
* the render tree.
|
|
3220
|
+
*/
|
|
3221
|
+
const IconSourceSchema = z.string().min(1).refine(isIconSource, { message: "icon must be icon://<name>, asset://<id>, or a single emoji (one Presentation character or one base+VS16 like ✈️)" });
|
|
3222
|
+
const ButtonConfigSchema = z.record(z.string(), z.unknown()).optional();
|
|
3223
|
+
/**
|
|
3224
|
+
* Closed core set of per-button hue names. Themes declare which of these
|
|
3225
|
+
* (or which additional names like riptide's `neon-pink`) they support
|
|
3226
|
+
* by adding entries to `variants.<name>` in their manifest. Themes are
|
|
3227
|
+
* authoritative — this list is a convention hint, not a constraint on
|
|
3228
|
+
* the theme. Names not declared in the active theme fall back to
|
|
3229
|
+
* "default" with a console.warn at render time (ButtonFrame).
|
|
3230
|
+
*/
|
|
3231
|
+
const ButtonColorSchema = z.enum([
|
|
3232
|
+
"blue",
|
|
3233
|
+
"green",
|
|
3234
|
+
"purple",
|
|
3235
|
+
"cyan",
|
|
3236
|
+
"magenta",
|
|
3237
|
+
"amber",
|
|
3238
|
+
"lime"
|
|
3137
3239
|
]);
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3240
|
+
const ButtonDefSchema = z.object({
|
|
3241
|
+
position: z.number().int().nonnegative().optional(),
|
|
3242
|
+
type: z.string().min(1),
|
|
3243
|
+
config: ButtonConfigSchema,
|
|
3244
|
+
accent: z.string().optional(),
|
|
3245
|
+
background: z.string().optional(),
|
|
3246
|
+
actions: ButtonActionsSchema.optional(),
|
|
3247
|
+
/**
|
|
3248
|
+
* Variant token name. Resolved by ButtonFrame against the active
|
|
3249
|
+
* theme's CSS vars at render time. Themes may declare extra
|
|
3250
|
+
* variants beyond the 5-required set; users pick from whatever the
|
|
3251
|
+
* active theme supports. Unknown names fall back to "default" with
|
|
3252
|
+
* a console.warn.
|
|
3253
|
+
*/
|
|
3254
|
+
variant: z.string().min(1).optional(),
|
|
3255
|
+
/**
|
|
3256
|
+
* Per-button hue customisation. Themes declare a `variants.<name>`
|
|
3257
|
+
* entry for each buttonColor they support. See ButtonColorSchema
|
|
3258
|
+
* for the closed core set; themes may add their own names
|
|
3259
|
+
* (e.g. riptide's `neon-pink`) and the runtime accepts them — but
|
|
3260
|
+
* this Zod schema restricts to the core set so typos fail-fast at
|
|
3261
|
+
* config load.
|
|
3262
|
+
*/
|
|
3263
|
+
buttonColor: ButtonColorSchema.optional(),
|
|
3264
|
+
label: z.string().optional(),
|
|
3265
|
+
icon: IconSourceSchema.optional(),
|
|
3266
|
+
iconUrl: z.string().min(1).optional(),
|
|
3267
|
+
size: z.string().optional(),
|
|
3268
|
+
textSize: z.string().optional(),
|
|
3269
|
+
borderRadius: z.string().optional(),
|
|
3270
|
+
addon: z.string().optional(),
|
|
3271
|
+
action: z.string().optional()
|
|
3272
|
+
}).strict();
|
|
3273
|
+
const ButtonEntrySchema = z.union([ButtonDefSchema, z.string()]);
|
|
3274
|
+
const DeckDefSchema = z.object({
|
|
3275
|
+
name: z.string().min(1).optional(),
|
|
3276
|
+
label: z.string().min(1).optional(),
|
|
3277
|
+
columns: z.number().int().positive().optional(),
|
|
3278
|
+
rows: z.number().int().positive().optional(),
|
|
3279
|
+
icon: IconSourceSchema.optional(),
|
|
3280
|
+
background: z.string().min(1).optional(),
|
|
3281
|
+
paginated: z.boolean().optional(),
|
|
3282
|
+
trigger: TriggerSchema.optional(),
|
|
3283
|
+
autoShow: z.boolean().optional(),
|
|
3284
|
+
buttons: z.array(ButtonEntrySchema)
|
|
3285
|
+
}).strict();
|
|
3286
|
+
const UserDeckCreateSchema = z.object({
|
|
3287
|
+
id: z.string().min(1),
|
|
3288
|
+
name: z.string().min(1).optional(),
|
|
3289
|
+
icon: IconSourceSchema.optional(),
|
|
3290
|
+
background: z.string().min(1).optional(),
|
|
3291
|
+
paginated: z.boolean().optional()
|
|
3292
|
+
}).strict();
|
|
3293
|
+
const UserDeckUpdateSchema = z.object({
|
|
3294
|
+
name: z.string().min(1).optional(),
|
|
3295
|
+
icon: IconSourceSchema.nullable().optional(),
|
|
3296
|
+
background: z.string().min(1).nullable().optional(),
|
|
3297
|
+
paginated: z.boolean().optional(),
|
|
3298
|
+
trigger: TriggerSchema.nullable().optional(),
|
|
3299
|
+
autoShow: z.boolean().optional()
|
|
3300
|
+
}).strict();
|
|
3301
|
+
/**
|
|
3302
|
+
* Phase 11: per-deck overrides for an addon-deck generated by `createDeck(s)`.
|
|
3303
|
+
* The deck id is the key in the parent record. Field-level overrides
|
|
3304
|
+
* (`autoShow`/`name`/`icon`/`trigger`) apply on top of the generated
|
|
3305
|
+
* deck; `config` is forwarded to `createDeck(s)({config})` as an
|
|
3306
|
+
* additive merge over the addon's default config.
|
|
3307
|
+
*/
|
|
3308
|
+
const AddonDeckOverrideSchema = z.object({
|
|
3309
|
+
autoShow: z.boolean().optional(),
|
|
3310
|
+
name: z.string().min(1).optional(),
|
|
3311
|
+
icon: IconSourceSchema.optional(),
|
|
3312
|
+
trigger: TriggerSchema.optional(),
|
|
3313
|
+
config: z.record(z.string(), z.unknown()).optional()
|
|
3314
|
+
}).strict();
|
|
3315
|
+
const AddonDeckDefaultsSchema = z.object({ autoShow: z.boolean().optional() }).strict();
|
|
3316
|
+
/**
|
|
3317
|
+
* Phase 11: addon-config block under `addons[i]`. Hosts three shape variants:
|
|
3318
|
+
* - `defaults:` addon-wide deck defaults (applied before per-deck overrides)
|
|
3319
|
+
* - `decks:` record keyed by addon deck id, with per-deck overrides
|
|
3320
|
+
* - `service:` addon-global backend settings (never merged into deck config)
|
|
3321
|
+
*/
|
|
3322
|
+
const AddonConfigSchema = z.object({
|
|
3323
|
+
defaults: AddonDeckDefaultsSchema.optional(),
|
|
3324
|
+
decks: z.record(z.string(), AddonDeckOverrideSchema).optional(),
|
|
3325
|
+
service: z.record(z.string(), z.unknown()).optional()
|
|
3326
|
+
}).strict();
|
|
3327
|
+
const AddonEntrySchema = z.union([z.string().min(1), z.object({
|
|
3328
|
+
src: z.string().min(1),
|
|
3329
|
+
enabled: z.boolean().optional(),
|
|
3330
|
+
global: z.boolean().optional(),
|
|
3331
|
+
config: AddonConfigSchema.optional()
|
|
3332
|
+
}).strict()]);
|
|
3333
|
+
const LoggingSchema = z.object({
|
|
3334
|
+
level: z.enum([
|
|
3335
|
+
"trace",
|
|
3336
|
+
"debug",
|
|
3337
|
+
"info",
|
|
3338
|
+
"warn",
|
|
3339
|
+
"error",
|
|
3340
|
+
"fatal",
|
|
3341
|
+
"silent"
|
|
3342
|
+
]).optional(),
|
|
3343
|
+
verbose: z.boolean().optional()
|
|
3344
|
+
}).strict().optional();
|
|
3345
|
+
const LockSchema = z.object({ buttons: z.array(ButtonDefSchema).optional() }).strict().optional();
|
|
3346
|
+
const ThemeEntrySchema = z.union([z.string().min(1), z.object({
|
|
3347
|
+
src: z.string().min(1),
|
|
3348
|
+
global: z.boolean().optional()
|
|
3349
|
+
}).strict()]);
|
|
3350
|
+
const RawConfigSchema = z.object({
|
|
3351
|
+
theme: ThemeEntrySchema.optional(),
|
|
3352
|
+
logging: LoggingSchema,
|
|
3353
|
+
decks: z.record(z.string(), DeckDefSchema),
|
|
3354
|
+
addons: z.array(AddonEntrySchema).optional(),
|
|
3355
|
+
lock: LockSchema
|
|
3356
|
+
}).strict();
|
|
3357
|
+
//#endregion
|
|
3358
|
+
//#region src/builtin-addons/core/buttons/action/backend.ts
|
|
3359
|
+
var backend_default$23 = { configSchema: z.object({
|
|
3360
|
+
icon: IconSourceSchema.optional().meta({
|
|
3361
|
+
title: "Icon",
|
|
3362
|
+
"x-control": "icon"
|
|
3363
|
+
}),
|
|
3364
|
+
label: z.string().optional().meta({ title: "Label" })
|
|
3365
|
+
}).refine((c) => Boolean(c.icon) || Boolean(c.label), { message: "core:action requires at least one of 'icon' or 'label'" }) };
|
|
3366
|
+
//#endregion
|
|
3367
|
+
//#region src/ui/theme-presentation.tsx
|
|
3368
|
+
const ThemeUiPresentationContext = createContext(void 0);
|
|
3369
|
+
function useThemeUiPresentation() {
|
|
3370
|
+
return useContext(ThemeUiPresentationContext);
|
|
3371
|
+
}
|
|
3372
|
+
//#endregion
|
|
3373
|
+
//#region src/ui/utils/cn.ts
|
|
3374
|
+
const cn = (...inputs) => {
|
|
3375
|
+
return (Array.isArray(inputs[0]) ? inputs[0] : inputs).filter(Boolean).join(" ");
|
|
3376
|
+
};
|
|
3377
|
+
//#endregion
|
|
3378
|
+
//#region src/ui/primitives/Text.tsx
|
|
3379
|
+
const ALIGN_CLASS = {
|
|
3380
|
+
center: "text-center",
|
|
3381
|
+
left: "text-left",
|
|
3382
|
+
right: "text-right"
|
|
3383
|
+
};
|
|
3384
|
+
const TONE_CLASS$2 = {
|
|
3385
|
+
accent: "text-accent",
|
|
3386
|
+
danger: "text-danger",
|
|
3387
|
+
fg: "text-fg",
|
|
3388
|
+
foreground: "text-fg",
|
|
3389
|
+
"foreground-contrast": "text-foreground-contrast",
|
|
3390
|
+
primary: "text-primary",
|
|
3391
|
+
success: "text-success",
|
|
3392
|
+
muted: "text-muted"
|
|
3393
|
+
};
|
|
3394
|
+
const TYPOGRAPHY_CLASS = {
|
|
3395
|
+
aux: "font-aux",
|
|
3396
|
+
main: "font-main",
|
|
3397
|
+
mono: "font-mono"
|
|
3398
|
+
};
|
|
3399
|
+
const WEIGHT_CLASS = {
|
|
3400
|
+
normal: "font-normal",
|
|
3401
|
+
semibold: "font-semibold",
|
|
3402
|
+
bold: "font-bold",
|
|
3403
|
+
light: "font-light",
|
|
3404
|
+
thin: "font-thin",
|
|
3405
|
+
extralight: "font-extralight",
|
|
3406
|
+
black: "font-black"
|
|
3407
|
+
};
|
|
3408
|
+
const SIZE_CLASS = {
|
|
3409
|
+
xxs: "text-[8px]",
|
|
3410
|
+
xs: "text-xs",
|
|
3411
|
+
sm: "text-sm",
|
|
3412
|
+
md: "text-md",
|
|
3413
|
+
lg: "text-lg",
|
|
3414
|
+
xl: "text-xl",
|
|
3415
|
+
"2xl": "text-2xl",
|
|
3416
|
+
"3xl": "text-3xl",
|
|
3417
|
+
"4xl": "text-4xl",
|
|
3418
|
+
"5xl": "text-5xl"
|
|
3419
|
+
};
|
|
3420
|
+
const RICH_TONE_TAGS = [
|
|
3421
|
+
"accent",
|
|
3422
|
+
"danger",
|
|
3423
|
+
"foreground",
|
|
3424
|
+
"primary",
|
|
3425
|
+
"success"
|
|
3426
|
+
];
|
|
3427
|
+
const RICH_SIZE_TAGS = [
|
|
3428
|
+
"xxs",
|
|
3429
|
+
"xs",
|
|
3430
|
+
"sm",
|
|
3431
|
+
"md",
|
|
3432
|
+
"lg",
|
|
3433
|
+
"xl",
|
|
3434
|
+
"2xl",
|
|
3435
|
+
"3xl",
|
|
3436
|
+
"4xl",
|
|
3437
|
+
"5xl"
|
|
3438
|
+
];
|
|
3439
|
+
const RICH_TAG_NAMES = /* @__PURE__ */ new Set([
|
|
3440
|
+
...RICH_TONE_TAGS,
|
|
3441
|
+
...RICH_SIZE_TAGS,
|
|
3442
|
+
"blink",
|
|
3443
|
+
"dim",
|
|
3444
|
+
"strong"
|
|
3445
|
+
]);
|
|
3446
|
+
function isRichToneTag(tag) {
|
|
3447
|
+
return RICH_TONE_TAGS.includes(tag);
|
|
3448
|
+
}
|
|
3449
|
+
function isRichSizeTag(tag) {
|
|
3450
|
+
return RICH_SIZE_TAGS.includes(tag);
|
|
3451
|
+
}
|
|
3452
|
+
function parseRichText(input) {
|
|
3453
|
+
let index = 0;
|
|
3454
|
+
function parseSequence(stop) {
|
|
3455
|
+
const nodes = [];
|
|
3456
|
+
let textStart = index;
|
|
3457
|
+
const flushText = () => {
|
|
3150
3458
|
if (textStart < index) nodes.push({
|
|
3151
3459
|
type: "text",
|
|
3152
3460
|
value: input.slice(textStart, index)
|
|
@@ -3601,56 +3909,12 @@ function chipBase(props) {
|
|
|
3601
3909
|
return /* @__PURE__ */ jsx(Text, {
|
|
3602
3910
|
className: cn(["inline-flex items-center justify-center rounded-full border px-2 py-0 font-aux uppercase tracking-wide font-bold", TONE_CLASS$1[tone]]),
|
|
3603
3911
|
size: props.size ?? "sm",
|
|
3912
|
+
tone,
|
|
3604
3913
|
"data-sireno-ui-chip": "true",
|
|
3605
3914
|
text: props.text
|
|
3606
3915
|
});
|
|
3607
3916
|
}
|
|
3608
3917
|
//#endregion
|
|
3609
|
-
//#region src/core/icon-source.ts
|
|
3610
|
-
const EMOJI_RE = /^(?:[\p{Extended_Pictographic}\p{Emoji_Component}]\uFE0F?(?:\u200D[\p{Extended_Pictographic}\p{Emoji_Component}]\uFE0F?)*|\p{Regional_Indicator}{2})$/u;
|
|
3611
|
-
const ICON_FALLBACK = "icon://alert-circle";
|
|
3612
|
-
const ABSOLUTE_PATH_RE = /^(?:\/|\\|[A-Za-z]:[\\/])/;
|
|
3613
|
-
/**
|
|
3614
|
-
* Validate that a runtime icon source is one of:
|
|
3615
|
-
* - `icon://<name>` — Lucide icon by name (resolved by the runtime
|
|
3616
|
-
* `resolveIconSource`)
|
|
3617
|
-
* - `asset://<id>` — pre-resolved asset id from the registry
|
|
3618
|
-
* - `addon://<a>/<p>` — asset inside an addon's frontendEntry dir
|
|
3619
|
-
* - `builtin://<p>` — asset inside the builtin addon's dir
|
|
3620
|
-
* - absolute path — asset resolved directly
|
|
3621
|
-
* - relative path — asset resolved against the config's baseDirs
|
|
3622
|
-
* (e.g. `./assets/chrome.svg`, `../shared/icon.svg`,
|
|
3623
|
-
* `~/Pictures/x.png`)
|
|
3624
|
-
* - a single emoji (Presentation, or base+VS16 like ✈️; also
|
|
3625
|
-
* regional-indicator pair flags like 🇪🇸, and ZWJ sequences
|
|
3626
|
-
* like 🏳️🌈 or 👨👩👧)
|
|
3627
|
-
*
|
|
3628
|
-
* Rejected: empty string, "%", "abc", multi-char (e.g. "abc🔥"),
|
|
3629
|
-
* inline URLs (data:, http://, https://, file://) — these must be
|
|
3630
|
-
* pre-resolved to asset:// before reaching the runtime.
|
|
3631
|
-
*
|
|
3632
|
-
* Anything rejected here triggers a runtime fallback (alert-circle
|
|
3633
|
-
* Lucide icon) AND, at config-load, a zod validation error.
|
|
3634
|
-
*/
|
|
3635
|
-
const isIconSource = (s) => {
|
|
3636
|
-
if (typeof s !== "string" || s.length === 0) return false;
|
|
3637
|
-
if (EMOJI_RE.test(s)) return true;
|
|
3638
|
-
if (s.startsWith("icon://") && s.length > 7) return true;
|
|
3639
|
-
if (s.startsWith("asset://") && s.length > 8) return true;
|
|
3640
|
-
if (s.startsWith("addon://")) {
|
|
3641
|
-
const rest = s.slice(8);
|
|
3642
|
-
const slash = rest.indexOf("/");
|
|
3643
|
-
if (slash > 0 && slash < rest.length - 1) return true;
|
|
3644
|
-
return false;
|
|
3645
|
-
}
|
|
3646
|
-
if (s.startsWith("builtin://") && s.length > 10) return true;
|
|
3647
|
-
if (s.startsWith("data:") || s.startsWith("http://") || s.startsWith("https://") || s.startsWith("file://")) return false;
|
|
3648
|
-
if (ABSOLUTE_PATH_RE.test(s)) return true;
|
|
3649
|
-
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(s)) return false;
|
|
3650
|
-
if (s === "." || s === "~" || s.startsWith("./") || s.startsWith("../") || s.startsWith("~/") || s.startsWith("~\\") || /[\\/]/.test(s) || s.startsWith("/")) return true;
|
|
3651
|
-
return false;
|
|
3652
|
-
};
|
|
3653
|
-
//#endregion
|
|
3654
3918
|
//#region src/ui/contexts/AssetCacheContext.tsx
|
|
3655
3919
|
const AssetCacheContext = createContext(/* @__PURE__ */ new Map());
|
|
3656
3920
|
const useAssetCache = () => {
|
|
@@ -4357,475 +4621,118 @@ function valueChartBase(props) {
|
|
|
4357
4621
|
//#region src/ui/surfaces/PaginatedSurface.tsx
|
|
4358
4622
|
function normalizePages(pages) {
|
|
4359
4623
|
return Array.isArray(pages) ? pages : [pages];
|
|
4360
|
-
}
|
|
4361
|
-
const DOT_ACTIVE = "bg-white";
|
|
4362
|
-
const DOT_INACTIVE = "bg-white/30";
|
|
4363
|
-
function PaginatedSurface({ pages, gesture, intervalMs, autoReturnMs, className, style }) {
|
|
4364
|
-
const themeUi = useThemeUiPresentation();
|
|
4365
|
-
if (themeUi?.surfaces?.paginated) return themeUi.surfaces.paginated({
|
|
4366
|
-
pages,
|
|
4367
|
-
gesture,
|
|
4368
|
-
intervalMs,
|
|
4369
|
-
autoReturnMs,
|
|
4370
|
-
className,
|
|
4371
|
-
style
|
|
4372
|
-
}, void 0, paginatedSurfaceBase);
|
|
4373
|
-
return paginatedSurfaceBase({
|
|
4374
|
-
pages,
|
|
4375
|
-
gesture,
|
|
4376
|
-
intervalMs,
|
|
4377
|
-
autoReturnMs,
|
|
4378
|
-
className,
|
|
4379
|
-
style
|
|
4380
|
-
});
|
|
4381
|
-
}
|
|
4382
|
-
function paginatedSurfaceBase({ pages, gesture, intervalMs, autoReturnMs, className, style }) {
|
|
4383
|
-
const allPages = normalizePages(pages);
|
|
4384
|
-
const count = allPages.length;
|
|
4385
|
-
const [current, setCurrent] = useState(0);
|
|
4386
|
-
const lastGestureAt = useRef(0);
|
|
4387
|
-
const timerRef = useRef(null);
|
|
4388
|
-
const autoReturnTimerRef = useRef(null);
|
|
4389
|
-
const clearTimer = useCallback(() => {
|
|
4390
|
-
if (timerRef.current !== null) {
|
|
4391
|
-
window.clearInterval(timerRef.current);
|
|
4392
|
-
timerRef.current = null;
|
|
4393
|
-
}
|
|
4394
|
-
}, []);
|
|
4395
|
-
const clearAutoReturnTimer = useCallback(() => {
|
|
4396
|
-
if (autoReturnTimerRef.current !== null) {
|
|
4397
|
-
window.clearTimeout(autoReturnTimerRef.current);
|
|
4398
|
-
autoReturnTimerRef.current = null;
|
|
4399
|
-
}
|
|
4400
|
-
}, []);
|
|
4401
|
-
const advance = useCallback(() => {
|
|
4402
|
-
setCurrent((p) => (p + 1) % count);
|
|
4403
|
-
}, [count]);
|
|
4404
|
-
useEffect(() => {
|
|
4405
|
-
if (gesture?.gesture === "tap" && gesture.at !== lastGestureAt.current) {
|
|
4406
|
-
lastGestureAt.current = gesture.at;
|
|
4407
|
-
clearTimer();
|
|
4408
|
-
advance();
|
|
4409
|
-
}
|
|
4410
|
-
}, [
|
|
4411
|
-
gesture,
|
|
4412
|
-
advance,
|
|
4413
|
-
clearTimer
|
|
4414
|
-
]);
|
|
4415
|
-
useEffect(() => {
|
|
4416
|
-
if (intervalMs === void 0 || count <= 1) return;
|
|
4417
|
-
clearTimer();
|
|
4418
|
-
timerRef.current = window.setInterval(advance, intervalMs);
|
|
4419
|
-
return clearTimer;
|
|
4420
|
-
}, [
|
|
4421
|
-
intervalMs,
|
|
4422
|
-
count,
|
|
4423
|
-
advance,
|
|
4424
|
-
clearTimer
|
|
4425
|
-
]);
|
|
4426
|
-
useEffect(() => {
|
|
4427
|
-
clearAutoReturnTimer();
|
|
4428
|
-
if (autoReturnMs === void 0 || current === 0) return;
|
|
4429
|
-
autoReturnTimerRef.current = window.setTimeout(() => {
|
|
4430
|
-
setCurrent(0);
|
|
4431
|
-
}, autoReturnMs);
|
|
4432
|
-
return clearAutoReturnTimer;
|
|
4433
|
-
}, [
|
|
4434
|
-
current,
|
|
4435
|
-
autoReturnMs,
|
|
4436
|
-
clearAutoReturnTimer
|
|
4437
|
-
]);
|
|
4438
|
-
useEffect(() => {
|
|
4439
|
-
setCurrent((p) => p >= count ? 0 : p);
|
|
4440
|
-
}, [count]);
|
|
4441
|
-
const page = allPages[current];
|
|
4442
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
4443
|
-
className: cn("relative flex h-full w-full flex-col", className),
|
|
4444
|
-
style,
|
|
4445
|
-
children: [/* @__PURE__ */ jsx("div", {
|
|
4446
|
-
className: "min-h-0 flex-1",
|
|
4447
|
-
children: page.render(page.config)
|
|
4448
|
-
}), count > 1 && /* @__PURE__ */ jsx("div", {
|
|
4449
|
-
className: "absolute bottom-[-4px] left-0 right-0 flex items-center justify-center gap-1",
|
|
4450
|
-
children: allPages.map((_, i) => /* @__PURE__ */ jsx("div", { className: cn("h-1 w-1 rounded-full", i === current ? DOT_ACTIVE : DOT_INACTIVE) }, i))
|
|
4451
|
-
})]
|
|
4452
|
-
});
|
|
4453
|
-
}
|
|
4454
|
-
//#endregion
|
|
4455
|
-
//#region src/ui/surfaces/paginated-schema.ts
|
|
4456
|
-
/**
|
|
4457
|
-
* Wraps a page schema to accept either a single page object or an array.
|
|
4458
|
-
* Normalizes to `{ pages: [...] }`.
|
|
4459
|
-
*
|
|
4460
|
-
* @example
|
|
4461
|
-
* const Config = pagesSchema(z.discriminatedUnion("type", [BarPage, ChartPage]))
|
|
4462
|
-
* // single: { type: "bars", metrics: ["cpu"] } → { pages: [{ type: "bars", metrics: [...] }] }
|
|
4463
|
-
* // array: [{ type: "bars", ... }, { type: "chart", ... }] → { pages: [...] }
|
|
4464
|
-
*/
|
|
4465
|
-
function pagesSchema(page) {
|
|
4466
|
-
return z.preprocess((input) => {
|
|
4467
|
-
if (Array.isArray(input)) return { pages: input };
|
|
4468
|
-
if (input && typeof input === "object" && !("pages" in input)) return { pages: [input] };
|
|
4469
|
-
return input;
|
|
4470
|
-
}, z.object({ pages: z.array(page).min(1).max(5) }).strict());
|
|
4471
|
-
}
|
|
4472
|
-
//#endregion
|
|
4473
|
-
//#region src/api/react/registry.ts
|
|
4474
|
-
var ChannelRegistry = class ChannelRegistry {
|
|
4475
|
-
static _instance = null;
|
|
4476
|
-
static _announceSubscribe = null;
|
|
4477
|
-
lastPayloads = /* @__PURE__ */ new Map();
|
|
4478
|
-
listeners = /* @__PURE__ */ new Map();
|
|
4479
|
-
listenerCounts = /* @__PURE__ */ new Map();
|
|
4480
|
-
pendingChannels = [];
|
|
4481
|
-
flushScheduled = false;
|
|
4482
|
-
static instance() {
|
|
4483
|
-
if (ChannelRegistry._instance === null) ChannelRegistry._instance = new ChannelRegistry();
|
|
4484
|
-
return ChannelRegistry._instance;
|
|
4485
|
-
}
|
|
4486
|
-
static resetForTests() {
|
|
4487
|
-
ChannelRegistry._instance = null;
|
|
4488
|
-
ChannelRegistry._announceSubscribe = null;
|
|
4489
|
-
}
|
|
4490
|
-
static setAnnounceSubscribe(cb) {
|
|
4491
|
-
ChannelRegistry._announceSubscribe = cb;
|
|
4492
|
-
}
|
|
4493
|
-
publish(channel, payload) {
|
|
4494
|
-
this.lastPayloads.set(channel, payload);
|
|
4495
|
-
const set = this.listeners.get(channel);
|
|
4496
|
-
if (set !== void 0) for (const l of set) l(payload);
|
|
4497
|
-
}
|
|
4498
|
-
subscribe(channel, cb) {
|
|
4499
|
-
let set = this.listeners.get(channel);
|
|
4500
|
-
if (set === void 0) {
|
|
4501
|
-
set = /* @__PURE__ */ new Set();
|
|
4502
|
-
this.listeners.set(channel, set);
|
|
4503
|
-
}
|
|
4504
|
-
const listener = cb;
|
|
4505
|
-
set.add(listener);
|
|
4506
|
-
const prevCount = this.listenerCounts.get(channel) ?? 0;
|
|
4507
|
-
this.listenerCounts.set(channel, prevCount + 1);
|
|
4508
|
-
if (prevCount === 0) {
|
|
4509
|
-
this.pendingChannels.push(channel);
|
|
4510
|
-
if (!this.flushScheduled) {
|
|
4511
|
-
this.flushScheduled = true;
|
|
4512
|
-
queueMicrotask(() => this.flushPendingSubscriptions());
|
|
4513
|
-
}
|
|
4514
|
-
}
|
|
4515
|
-
return () => {
|
|
4516
|
-
set?.delete(listener);
|
|
4517
|
-
const count = this.listenerCounts.get(channel) ?? 0;
|
|
4518
|
-
if (count <= 1) this.listenerCounts.delete(channel);
|
|
4519
|
-
else this.listenerCounts.set(channel, count - 1);
|
|
4520
|
-
};
|
|
4521
|
-
}
|
|
4522
|
-
flushPendingSubscriptions() {
|
|
4523
|
-
this.flushScheduled = false;
|
|
4524
|
-
if (this.pendingChannels.length === 0) return;
|
|
4525
|
-
const channels = [...new Set(this.pendingChannels)];
|
|
4526
|
-
this.pendingChannels = [];
|
|
4527
|
-
ChannelRegistry._announceSubscribe?.(channels);
|
|
4528
|
-
}
|
|
4529
|
-
last(channel) {
|
|
4530
|
-
return this.lastPayloads.get(channel);
|
|
4531
|
-
}
|
|
4532
|
-
clear() {
|
|
4533
|
-
this.lastPayloads.clear();
|
|
4534
|
-
this.listeners.clear();
|
|
4535
|
-
this.listenerCounts.clear();
|
|
4536
|
-
this.pendingChannels = [];
|
|
4537
|
-
this.flushScheduled = false;
|
|
4538
|
-
}
|
|
4539
|
-
};
|
|
4540
|
-
//#endregion
|
|
4541
|
-
//#region src/api/react/use-addon-channel.ts
|
|
4542
|
-
const useAddonChannel$2 = (channel) => {
|
|
4543
|
-
const [data, setData] = useState(() => ChannelRegistry.instance().last(channel));
|
|
4544
|
-
useEffect(() => {
|
|
4545
|
-
return ChannelRegistry.instance().subscribe(channel, (payload) => {
|
|
4546
|
-
setData(payload);
|
|
4547
|
-
});
|
|
4548
|
-
}, [channel]);
|
|
4549
|
-
return { data };
|
|
4550
|
-
};
|
|
4551
|
-
//#endregion
|
|
4552
|
-
//#region src/api/react/use-button-state.tsx
|
|
4553
|
-
const NullButton = () => null;
|
|
4554
|
-
//#endregion
|
|
4555
|
-
//#region src/builtin-addons/brightness/buttons/brightness/frontend.tsx
|
|
4556
|
-
const BrightnessButtonFrontend$1 = ({ config }) => {
|
|
4557
|
-
const { action } = config ?? {};
|
|
4558
|
-
const { data } = useAddonChannel$2("brightness:current");
|
|
4559
|
-
if (data === void 0) return /* @__PURE__ */ jsx(Text, {
|
|
4560
|
-
size: "xs",
|
|
4561
|
-
tone: "muted",
|
|
4562
|
-
typography: "mono",
|
|
4563
|
-
className: "flex h-full w-full items-center justify-center",
|
|
4564
|
-
text: "—"
|
|
4565
|
-
});
|
|
4566
|
-
const pct = Math.max(0, Math.min(100, data.value / (data.max || 100) * 100));
|
|
4567
|
-
return /* @__PURE__ */ jsxs("span", {
|
|
4568
|
-
className: "flex h-full w-full flex-col items-stretch justify-center gap-1 p-2",
|
|
4569
|
-
children: [
|
|
4570
|
-
/* @__PURE__ */ jsxs("span", {
|
|
4571
|
-
className: "flex items-baseline justify-between",
|
|
4572
|
-
children: [/* @__PURE__ */ jsx(Text, {
|
|
4573
|
-
size: "xs",
|
|
4574
|
-
tone: "muted",
|
|
4575
|
-
fit: "ellipsis",
|
|
4576
|
-
text: "Brightness"
|
|
4577
|
-
}), /* @__PURE__ */ jsx(Text, {
|
|
4578
|
-
size: "xs",
|
|
4579
|
-
tone: "fg",
|
|
4580
|
-
text: `${pct.toFixed(0)}%`
|
|
4581
|
-
})]
|
|
4582
|
-
}),
|
|
4583
|
-
/* @__PURE__ */ jsx("span", {
|
|
4584
|
-
className: "block h-1.5 w-full overflow-hidden rounded bg-bar",
|
|
4585
|
-
children: /* @__PURE__ */ jsx("span", {
|
|
4586
|
-
className: "block h-full bg-accent",
|
|
4587
|
-
style: { width: `${pct}%` }
|
|
4588
|
-
})
|
|
4589
|
-
}),
|
|
4590
|
-
/* @__PURE__ */ jsx(Text, {
|
|
4591
|
-
size: "xs",
|
|
4592
|
-
tone: "muted",
|
|
4593
|
-
className: "text-center",
|
|
4594
|
-
typography: "aux",
|
|
4595
|
-
text: `Tap: ${action ?? "up"}`
|
|
4596
|
-
})
|
|
4597
|
-
]
|
|
4598
|
-
});
|
|
4599
|
-
};
|
|
4600
|
-
//#endregion
|
|
4601
|
-
//#region src/builtin-addons/brightness/index.ts
|
|
4602
|
-
const manifest$9 = {
|
|
4603
|
-
apiVersion: 1,
|
|
4604
|
-
name: "brightness",
|
|
4605
|
-
buttonTypes: { "brightness:brightness": {
|
|
4606
|
-
frontend: BrightnessButtonFrontend$1,
|
|
4607
|
-
service: {
|
|
4608
|
-
...backend_default$24,
|
|
4609
|
-
gestureHandlers: ["tap"]
|
|
4610
|
-
}
|
|
4611
|
-
} },
|
|
4612
|
-
publishIntervalMs: 2e3
|
|
4613
|
-
};
|
|
4614
|
-
//#endregion
|
|
4615
|
-
//#region src/deck/position-buttons.ts
|
|
4616
|
-
/**
|
|
4617
|
-
* Assigns a position to every button — no drops.
|
|
4618
|
-
*
|
|
4619
|
-
* - Buttons with a valid explicit `position` keep it (first-come wins
|
|
4620
|
-
* for duplicates).
|
|
4621
|
-
* - Duplicate positions and buttons without a position fall through to
|
|
4622
|
-
* a "gap" queue, filled sequentially starting at 0 in array order.
|
|
4623
|
-
* - Positions ≥ keyCount are preserved: the caller is responsible for
|
|
4624
|
-
* pagination (group by `floor(pos / (K-2))`). The deck-config and
|
|
4625
|
-
* addon-deck pipelines both go through `paginateDeck` for that.
|
|
4626
|
-
* - The internal contract: every emitted button has `position` set.
|
|
4627
|
-
*
|
|
4628
|
-
* ponytail: O(n²) scan is fine for deck sizes (<30).
|
|
4629
|
-
*/
|
|
4630
|
-
const positionButtons = (buttons, keyCount, logger) => {
|
|
4631
|
-
const occupied = /* @__PURE__ */ new Set();
|
|
4632
|
-
const result = [];
|
|
4633
|
-
const unfixed = [];
|
|
4634
|
-
for (const btn of buttons) {
|
|
4635
|
-
const pos = btn.position;
|
|
4636
|
-
if (pos === void 0 || !Number.isFinite(pos) || pos < 0) {
|
|
4637
|
-
unfixed.push(btn);
|
|
4638
|
-
continue;
|
|
4639
|
-
}
|
|
4640
|
-
if (occupied.has(pos)) {
|
|
4641
|
-
logger?.debug({
|
|
4642
|
-
position: pos,
|
|
4643
|
-
reason: "duplicate"
|
|
4644
|
-
}, "duplicate position, treating as unfixed");
|
|
4645
|
-
unfixed.push(btn);
|
|
4646
|
-
continue;
|
|
4647
|
-
}
|
|
4648
|
-
occupied.add(pos);
|
|
4649
|
-
result.push(btn);
|
|
4650
|
-
}
|
|
4651
|
-
let gap = 0;
|
|
4652
|
-
for (const btn of unfixed) {
|
|
4653
|
-
while (occupied.has(gap)) gap++;
|
|
4654
|
-
occupied.add(gap);
|
|
4655
|
-
result.push({
|
|
4656
|
-
...btn,
|
|
4657
|
-
position: gap
|
|
4658
|
-
});
|
|
4659
|
-
gap++;
|
|
4660
|
-
}
|
|
4661
|
-
return result;
|
|
4662
|
-
};
|
|
4663
|
-
//#endregion
|
|
4664
|
-
//#region src/config/schemas.ts
|
|
4665
|
-
const TriggerSchema = z.object({
|
|
4666
|
-
process_name: z.union([z.string(), z.array(z.string()).min(1)]).optional(),
|
|
4667
|
-
window_name: z.union([z.string(), z.array(z.string()).min(1)]).optional()
|
|
4668
|
-
}).strict().refine((t) => t.process_name !== void 0 || t.window_name !== void 0, { message: "trigger requires at least one of `process_name` or `window_name`" });
|
|
4669
|
-
const ButtonActionsSchema = z.object({
|
|
4670
|
-
tap: z.string().min(1).optional().meta({ title: "Tap action" }),
|
|
4671
|
-
dbltap: z.string().min(1).optional().meta({ title: "Double-tap action" }),
|
|
4672
|
-
hold: z.string().min(1).optional().meta({ title: "Hold action" })
|
|
4673
|
-
}).strict();
|
|
4674
|
-
/**
|
|
4675
|
-
* Runtime icon source. Accepted shapes:
|
|
4676
|
-
* - `icon://<name>` — Lucide icon by name (resolved at render time)
|
|
4677
|
-
* - `asset://<id>` — pre-resolved asset id from the registry
|
|
4678
|
-
* - a single emoji (Presentation or base+VS16 like ✈️)
|
|
4679
|
-
*
|
|
4680
|
-
* Anything else is rejected at config-load time so typos surface before
|
|
4681
|
-
* the daemon starts. The runtime also has a fallback path (alert-circle
|
|
4682
|
-
* Lucide icon) so an invalid source that's slipped through can't crash
|
|
4683
|
-
* the render tree.
|
|
4684
|
-
*/
|
|
4685
|
-
const IconSourceSchema = z.string().min(1).refine(isIconSource, { message: "icon must be icon://<name>, asset://<id>, or a single emoji (one Presentation character or one base+VS16 like ✈️)" });
|
|
4686
|
-
const ButtonConfigSchema = z.record(z.string(), z.unknown()).optional();
|
|
4687
|
-
/**
|
|
4688
|
-
* Closed core set of per-button hue names. Themes declare which of these
|
|
4689
|
-
* (or which additional names like riptide's `neon-pink`) they support
|
|
4690
|
-
* by adding entries to `variants.<name>` in their manifest. Themes are
|
|
4691
|
-
* authoritative — this list is a convention hint, not a constraint on
|
|
4692
|
-
* the theme. Names not declared in the active theme fall back to
|
|
4693
|
-
* "default" with a console.warn at render time (ButtonFrame).
|
|
4694
|
-
*/
|
|
4695
|
-
const ButtonColorSchema = z.enum([
|
|
4696
|
-
"blue",
|
|
4697
|
-
"green",
|
|
4698
|
-
"purple",
|
|
4699
|
-
"cyan",
|
|
4700
|
-
"magenta",
|
|
4701
|
-
"amber",
|
|
4702
|
-
"lime"
|
|
4703
|
-
]);
|
|
4704
|
-
const ButtonDefSchema = z.object({
|
|
4705
|
-
position: z.number().int().nonnegative().optional(),
|
|
4706
|
-
type: z.string().min(1),
|
|
4707
|
-
config: ButtonConfigSchema,
|
|
4708
|
-
accent: z.string().optional(),
|
|
4709
|
-
background: z.string().optional(),
|
|
4710
|
-
actions: ButtonActionsSchema.optional(),
|
|
4711
|
-
/**
|
|
4712
|
-
* Variant token name. Resolved by ButtonFrame against the active
|
|
4713
|
-
* theme's CSS vars at render time. Themes may declare extra
|
|
4714
|
-
* variants beyond the 5-required set; users pick from whatever the
|
|
4715
|
-
* active theme supports. Unknown names fall back to "default" with
|
|
4716
|
-
* a console.warn.
|
|
4717
|
-
*/
|
|
4718
|
-
variant: z.string().min(1).optional(),
|
|
4719
|
-
/**
|
|
4720
|
-
* Per-button hue customisation. Themes declare a `variants.<name>`
|
|
4721
|
-
* entry for each buttonColor they support. See ButtonColorSchema
|
|
4722
|
-
* for the closed core set; themes may add their own names
|
|
4723
|
-
* (e.g. riptide's `neon-pink`) and the runtime accepts them — but
|
|
4724
|
-
* this Zod schema restricts to the core set so typos fail-fast at
|
|
4725
|
-
* config load.
|
|
4726
|
-
*/
|
|
4727
|
-
buttonColor: ButtonColorSchema.optional(),
|
|
4728
|
-
label: z.string().optional(),
|
|
4729
|
-
icon: IconSourceSchema.optional(),
|
|
4730
|
-
iconUrl: z.string().min(1).optional(),
|
|
4731
|
-
size: z.string().optional(),
|
|
4732
|
-
textSize: z.string().optional(),
|
|
4733
|
-
borderRadius: z.string().optional(),
|
|
4734
|
-
addon: z.string().optional(),
|
|
4735
|
-
action: z.string().optional()
|
|
4736
|
-
}).strict();
|
|
4737
|
-
const ButtonEntrySchema = z.union([ButtonDefSchema, z.string()]);
|
|
4738
|
-
const DeckDefSchema = z.object({
|
|
4739
|
-
name: z.string().min(1).optional(),
|
|
4740
|
-
label: z.string().min(1).optional(),
|
|
4741
|
-
columns: z.number().int().positive().optional(),
|
|
4742
|
-
rows: z.number().int().positive().optional(),
|
|
4743
|
-
icon: IconSourceSchema.optional(),
|
|
4744
|
-
background: z.string().min(1).optional(),
|
|
4745
|
-
paginated: z.boolean().optional(),
|
|
4746
|
-
trigger: TriggerSchema.optional(),
|
|
4747
|
-
autoShow: z.boolean().optional(),
|
|
4748
|
-
buttons: z.array(ButtonEntrySchema)
|
|
4749
|
-
}).strict();
|
|
4750
|
-
const UserDeckCreateSchema = z.object({
|
|
4751
|
-
id: z.string().min(1),
|
|
4752
|
-
name: z.string().min(1).optional(),
|
|
4753
|
-
icon: IconSourceSchema.optional(),
|
|
4754
|
-
background: z.string().min(1).optional(),
|
|
4755
|
-
paginated: z.boolean().optional()
|
|
4756
|
-
}).strict();
|
|
4757
|
-
const UserDeckUpdateSchema = z.object({
|
|
4758
|
-
name: z.string().min(1).optional(),
|
|
4759
|
-
icon: IconSourceSchema.nullable().optional(),
|
|
4760
|
-
background: z.string().min(1).nullable().optional(),
|
|
4761
|
-
paginated: z.boolean().optional(),
|
|
4762
|
-
trigger: TriggerSchema.nullable().optional(),
|
|
4763
|
-
autoShow: z.boolean().optional()
|
|
4764
|
-
}).strict();
|
|
4765
|
-
/**
|
|
4766
|
-
* Phase 11: per-deck overrides for an addon-deck generated by `createDeck(s)`.
|
|
4767
|
-
* The deck id is the key in the parent record. Field-level overrides
|
|
4768
|
-
* (`autoShow`/`name`/`icon`/`trigger`) apply on top of the generated
|
|
4769
|
-
* deck; `config` is forwarded to `createDeck(s)({config})` as an
|
|
4770
|
-
* additive merge over the addon's default config.
|
|
4771
|
-
*/
|
|
4772
|
-
const AddonDeckOverrideSchema = z.object({
|
|
4773
|
-
autoShow: z.boolean().optional(),
|
|
4774
|
-
name: z.string().min(1).optional(),
|
|
4775
|
-
icon: IconSourceSchema.optional(),
|
|
4776
|
-
trigger: TriggerSchema.optional(),
|
|
4777
|
-
config: z.record(z.string(), z.unknown()).optional()
|
|
4778
|
-
}).strict();
|
|
4779
|
-
const AddonDeckDefaultsSchema = z.object({ autoShow: z.boolean().optional() }).strict();
|
|
4624
|
+
}
|
|
4625
|
+
const DOT_ACTIVE = "bg-white";
|
|
4626
|
+
const DOT_INACTIVE = "bg-white/30";
|
|
4627
|
+
function PaginatedSurface({ pages, gesture, intervalMs, autoReturnMs, className, style }) {
|
|
4628
|
+
const themeUi = useThemeUiPresentation();
|
|
4629
|
+
if (themeUi?.surfaces?.paginated) return themeUi.surfaces.paginated({
|
|
4630
|
+
pages,
|
|
4631
|
+
gesture,
|
|
4632
|
+
intervalMs,
|
|
4633
|
+
autoReturnMs,
|
|
4634
|
+
className,
|
|
4635
|
+
style
|
|
4636
|
+
}, void 0, paginatedSurfaceBase);
|
|
4637
|
+
return paginatedSurfaceBase({
|
|
4638
|
+
pages,
|
|
4639
|
+
gesture,
|
|
4640
|
+
intervalMs,
|
|
4641
|
+
autoReturnMs,
|
|
4642
|
+
className,
|
|
4643
|
+
style
|
|
4644
|
+
});
|
|
4645
|
+
}
|
|
4646
|
+
function paginatedSurfaceBase({ pages, gesture, intervalMs, autoReturnMs, className, style }) {
|
|
4647
|
+
const allPages = normalizePages(pages);
|
|
4648
|
+
const count = allPages.length;
|
|
4649
|
+
const [current, setCurrent] = useState(0);
|
|
4650
|
+
const lastGestureAt = useRef(0);
|
|
4651
|
+
const timerRef = useRef(null);
|
|
4652
|
+
const autoReturnTimerRef = useRef(null);
|
|
4653
|
+
const clearTimer = useCallback(() => {
|
|
4654
|
+
if (timerRef.current !== null) {
|
|
4655
|
+
window.clearInterval(timerRef.current);
|
|
4656
|
+
timerRef.current = null;
|
|
4657
|
+
}
|
|
4658
|
+
}, []);
|
|
4659
|
+
const clearAutoReturnTimer = useCallback(() => {
|
|
4660
|
+
if (autoReturnTimerRef.current !== null) {
|
|
4661
|
+
window.clearTimeout(autoReturnTimerRef.current);
|
|
4662
|
+
autoReturnTimerRef.current = null;
|
|
4663
|
+
}
|
|
4664
|
+
}, []);
|
|
4665
|
+
const advance = useCallback(() => {
|
|
4666
|
+
setCurrent((p) => (p + 1) % count);
|
|
4667
|
+
}, [count]);
|
|
4668
|
+
useEffect(() => {
|
|
4669
|
+
if (gesture?.gesture === "tap" && gesture.at !== lastGestureAt.current) {
|
|
4670
|
+
lastGestureAt.current = gesture.at;
|
|
4671
|
+
clearTimer();
|
|
4672
|
+
advance();
|
|
4673
|
+
}
|
|
4674
|
+
}, [
|
|
4675
|
+
gesture,
|
|
4676
|
+
advance,
|
|
4677
|
+
clearTimer
|
|
4678
|
+
]);
|
|
4679
|
+
useEffect(() => {
|
|
4680
|
+
if (intervalMs === void 0 || count <= 1) return;
|
|
4681
|
+
clearTimer();
|
|
4682
|
+
timerRef.current = window.setInterval(advance, intervalMs);
|
|
4683
|
+
return clearTimer;
|
|
4684
|
+
}, [
|
|
4685
|
+
intervalMs,
|
|
4686
|
+
count,
|
|
4687
|
+
advance,
|
|
4688
|
+
clearTimer
|
|
4689
|
+
]);
|
|
4690
|
+
useEffect(() => {
|
|
4691
|
+
clearAutoReturnTimer();
|
|
4692
|
+
if (autoReturnMs === void 0 || current === 0) return;
|
|
4693
|
+
autoReturnTimerRef.current = window.setTimeout(() => {
|
|
4694
|
+
setCurrent(0);
|
|
4695
|
+
}, autoReturnMs);
|
|
4696
|
+
return clearAutoReturnTimer;
|
|
4697
|
+
}, [
|
|
4698
|
+
current,
|
|
4699
|
+
autoReturnMs,
|
|
4700
|
+
clearAutoReturnTimer
|
|
4701
|
+
]);
|
|
4702
|
+
useEffect(() => {
|
|
4703
|
+
setCurrent((p) => p >= count ? 0 : p);
|
|
4704
|
+
}, [count]);
|
|
4705
|
+
const page = allPages[current];
|
|
4706
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
4707
|
+
className: cn("relative flex h-full w-full flex-col", className),
|
|
4708
|
+
style,
|
|
4709
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
4710
|
+
className: "min-h-0 flex-1",
|
|
4711
|
+
children: page.render(page.config)
|
|
4712
|
+
}), count > 1 && /* @__PURE__ */ jsx("div", {
|
|
4713
|
+
className: "absolute bottom-[-4px] left-0 right-0 flex items-center justify-center gap-1",
|
|
4714
|
+
children: allPages.map((_, i) => /* @__PURE__ */ jsx("div", { className: cn("h-1 w-1 rounded-full", i === current ? DOT_ACTIVE : DOT_INACTIVE) }, i))
|
|
4715
|
+
})]
|
|
4716
|
+
});
|
|
4717
|
+
}
|
|
4718
|
+
//#endregion
|
|
4719
|
+
//#region src/ui/surfaces/paginated-schema.ts
|
|
4780
4720
|
/**
|
|
4781
|
-
*
|
|
4782
|
-
*
|
|
4783
|
-
*
|
|
4784
|
-
*
|
|
4721
|
+
* Wraps a page schema to accept either a single page object or an array.
|
|
4722
|
+
* Normalizes to `{ pages: [...] }`.
|
|
4723
|
+
*
|
|
4724
|
+
* @example
|
|
4725
|
+
* const Config = pagesSchema(z.discriminatedUnion("type", [BarPage, ChartPage]))
|
|
4726
|
+
* // single: { type: "bars", metrics: ["cpu"] } → { pages: [{ type: "bars", metrics: [...] }] }
|
|
4727
|
+
* // array: [{ type: "bars", ... }, { type: "chart", ... }] → { pages: [...] }
|
|
4785
4728
|
*/
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
global: z.boolean().optional(),
|
|
4794
|
-
config: AddonConfigSchema.optional()
|
|
4795
|
-
}).strict()]);
|
|
4796
|
-
const LoggingSchema = z.object({
|
|
4797
|
-
level: z.enum([
|
|
4798
|
-
"trace",
|
|
4799
|
-
"debug",
|
|
4800
|
-
"info",
|
|
4801
|
-
"warn",
|
|
4802
|
-
"error",
|
|
4803
|
-
"fatal",
|
|
4804
|
-
"silent"
|
|
4805
|
-
]).optional(),
|
|
4806
|
-
verbose: z.boolean().optional()
|
|
4807
|
-
}).strict().optional();
|
|
4808
|
-
const LockSchema = z.object({ buttons: z.array(ButtonDefSchema).optional() }).strict().optional();
|
|
4809
|
-
const ThemeEntrySchema = z.union([z.string().min(1), z.object({
|
|
4810
|
-
src: z.string().min(1),
|
|
4811
|
-
global: z.boolean().optional()
|
|
4812
|
-
}).strict()]);
|
|
4813
|
-
const RawConfigSchema = z.object({
|
|
4814
|
-
theme: ThemeEntrySchema.optional(),
|
|
4815
|
-
logging: LoggingSchema,
|
|
4816
|
-
decks: z.record(z.string(), DeckDefSchema),
|
|
4817
|
-
addons: z.array(AddonEntrySchema).optional(),
|
|
4818
|
-
lock: LockSchema
|
|
4819
|
-
}).strict();
|
|
4820
|
-
//#endregion
|
|
4821
|
-
//#region src/builtin-addons/core/buttons/action/backend.ts
|
|
4822
|
-
var backend_default$23 = { configSchema: z.object({
|
|
4823
|
-
icon: IconSourceSchema.optional().meta({
|
|
4824
|
-
title: "Icon",
|
|
4825
|
-
"x-control": "icon"
|
|
4826
|
-
}),
|
|
4827
|
-
label: z.string().optional().meta({ title: "Label" })
|
|
4828
|
-
}).refine((c) => Boolean(c.icon) || Boolean(c.label), { message: "core:action requires at least one of 'icon' or 'label'" }) };
|
|
4729
|
+
function pagesSchema(page) {
|
|
4730
|
+
return z.preprocess((input) => {
|
|
4731
|
+
if (Array.isArray(input)) return { pages: input };
|
|
4732
|
+
if (input && typeof input === "object" && !("pages" in input)) return { pages: [input] };
|
|
4733
|
+
return input;
|
|
4734
|
+
}, z.object({ pages: z.array(page).min(1).max(5) }).strict());
|
|
4735
|
+
}
|
|
4829
4736
|
//#endregion
|
|
4830
4737
|
//#region src/builtin-addons/core/buttons/action/frontend.tsx
|
|
4831
4738
|
const CoreActionButtonFrontend = ({ config }) => {
|
|
@@ -4875,6 +4782,88 @@ var backend_default$21 = {
|
|
|
4875
4782
|
onTap: async () => {}
|
|
4876
4783
|
};
|
|
4877
4784
|
//#endregion
|
|
4785
|
+
//#region src/api/react/registry.ts
|
|
4786
|
+
var ChannelRegistry = class ChannelRegistry {
|
|
4787
|
+
static _instance = null;
|
|
4788
|
+
static _announceSubscribe = null;
|
|
4789
|
+
lastPayloads = /* @__PURE__ */ new Map();
|
|
4790
|
+
listeners = /* @__PURE__ */ new Map();
|
|
4791
|
+
listenerCounts = /* @__PURE__ */ new Map();
|
|
4792
|
+
pendingChannels = [];
|
|
4793
|
+
flushScheduled = false;
|
|
4794
|
+
static instance() {
|
|
4795
|
+
if (ChannelRegistry._instance === null) ChannelRegistry._instance = new ChannelRegistry();
|
|
4796
|
+
return ChannelRegistry._instance;
|
|
4797
|
+
}
|
|
4798
|
+
static resetForTests() {
|
|
4799
|
+
ChannelRegistry._instance = null;
|
|
4800
|
+
ChannelRegistry._announceSubscribe = null;
|
|
4801
|
+
}
|
|
4802
|
+
static setAnnounceSubscribe(cb) {
|
|
4803
|
+
ChannelRegistry._announceSubscribe = cb;
|
|
4804
|
+
}
|
|
4805
|
+
publish(channel, payload) {
|
|
4806
|
+
this.lastPayloads.set(channel, payload);
|
|
4807
|
+
const set = this.listeners.get(channel);
|
|
4808
|
+
if (set !== void 0) for (const l of set) l(payload);
|
|
4809
|
+
}
|
|
4810
|
+
subscribe(channel, cb) {
|
|
4811
|
+
let set = this.listeners.get(channel);
|
|
4812
|
+
if (set === void 0) {
|
|
4813
|
+
set = /* @__PURE__ */ new Set();
|
|
4814
|
+
this.listeners.set(channel, set);
|
|
4815
|
+
}
|
|
4816
|
+
const listener = cb;
|
|
4817
|
+
set.add(listener);
|
|
4818
|
+
const prevCount = this.listenerCounts.get(channel) ?? 0;
|
|
4819
|
+
this.listenerCounts.set(channel, prevCount + 1);
|
|
4820
|
+
if (prevCount === 0) {
|
|
4821
|
+
this.pendingChannels.push(channel);
|
|
4822
|
+
if (!this.flushScheduled) {
|
|
4823
|
+
this.flushScheduled = true;
|
|
4824
|
+
queueMicrotask(() => this.flushPendingSubscriptions());
|
|
4825
|
+
}
|
|
4826
|
+
}
|
|
4827
|
+
return () => {
|
|
4828
|
+
set?.delete(listener);
|
|
4829
|
+
const count = this.listenerCounts.get(channel) ?? 0;
|
|
4830
|
+
if (count <= 1) this.listenerCounts.delete(channel);
|
|
4831
|
+
else this.listenerCounts.set(channel, count - 1);
|
|
4832
|
+
};
|
|
4833
|
+
}
|
|
4834
|
+
flushPendingSubscriptions() {
|
|
4835
|
+
this.flushScheduled = false;
|
|
4836
|
+
if (this.pendingChannels.length === 0) return;
|
|
4837
|
+
const channels = [...new Set(this.pendingChannels)];
|
|
4838
|
+
this.pendingChannels = [];
|
|
4839
|
+
ChannelRegistry._announceSubscribe?.(channels);
|
|
4840
|
+
}
|
|
4841
|
+
last(channel) {
|
|
4842
|
+
return this.lastPayloads.get(channel);
|
|
4843
|
+
}
|
|
4844
|
+
clear() {
|
|
4845
|
+
this.lastPayloads.clear();
|
|
4846
|
+
this.listeners.clear();
|
|
4847
|
+
this.listenerCounts.clear();
|
|
4848
|
+
this.pendingChannels = [];
|
|
4849
|
+
this.flushScheduled = false;
|
|
4850
|
+
}
|
|
4851
|
+
};
|
|
4852
|
+
//#endregion
|
|
4853
|
+
//#region src/api/react/use-addon-channel.ts
|
|
4854
|
+
const useAddonChannel$2 = (channel) => {
|
|
4855
|
+
const [data, setData] = useState(() => ChannelRegistry.instance().last(channel));
|
|
4856
|
+
useEffect(() => {
|
|
4857
|
+
return ChannelRegistry.instance().subscribe(channel, (payload) => {
|
|
4858
|
+
setData(payload);
|
|
4859
|
+
});
|
|
4860
|
+
}, [channel]);
|
|
4861
|
+
return { data };
|
|
4862
|
+
};
|
|
4863
|
+
//#endregion
|
|
4864
|
+
//#region src/api/react/use-button-state.tsx
|
|
4865
|
+
const NullButton = () => null;
|
|
4866
|
+
//#endregion
|
|
4878
4867
|
//#region src/builtin-addons/core/buttons/media-sample/frontend.tsx
|
|
4879
4868
|
var frontend_default$1 = NullButton;
|
|
4880
4869
|
//#endregion
|
|
@@ -9828,7 +9817,7 @@ const BrightnessButtonFrontend = ({ variant, gesture }) => {
|
|
|
9828
9817
|
const [showProgress, setShowProgress] = useState(false);
|
|
9829
9818
|
const timerRef = useRef(null);
|
|
9830
9819
|
useEffect(() => {
|
|
9831
|
-
if (gesture?.gesture !== "tap" && gesture?.gesture !== "dbl-tap") return;
|
|
9820
|
+
if (gesture?.gesture !== "tap" && gesture?.gesture !== "dbl-tap" && gesture?.gesture !== "hold") return;
|
|
9832
9821
|
setShowProgress(true);
|
|
9833
9822
|
if (timerRef.current) clearTimeout(timerRef.current);
|
|
9834
9823
|
timerRef.current = setTimeout(() => setShowProgress(false), PROGRESS_VISIBLE_MS$1);
|
|
@@ -9838,7 +9827,7 @@ const BrightnessButtonFrontend = ({ variant, gesture }) => {
|
|
|
9838
9827
|
}, []);
|
|
9839
9828
|
return /* @__PURE__ */ jsx(IconLabelProgressSurface, {
|
|
9840
9829
|
source: `icon://${variant === "down" ? "sun-dim" : "sun"}`,
|
|
9841
|
-
label: variant === "down" ? "Darker" : "Lighter",
|
|
9830
|
+
label: variant === "compact" ? "Tap + / Hold −" : variant === "down" ? "Darker" : "Lighter",
|
|
9842
9831
|
progress,
|
|
9843
9832
|
visible: showProgress
|
|
9844
9833
|
});
|
|
@@ -9850,6 +9839,12 @@ const BrightnessDownButtonFrontend = ({ gesture }) => /* @__PURE__ */ jsx(Bright
|
|
|
9850
9839
|
gesture: gesture ?? null
|
|
9851
9840
|
});
|
|
9852
9841
|
//#endregion
|
|
9842
|
+
//#region src/builtin-addons/internal-settings/buttons/brightness-compact/frontend.tsx
|
|
9843
|
+
const CompactBrightnessFrontend = ({ gesture }) => /* @__PURE__ */ jsx(BrightnessButtonFrontend, {
|
|
9844
|
+
variant: "compact",
|
|
9845
|
+
gesture: gesture ?? null
|
|
9846
|
+
});
|
|
9847
|
+
//#endregion
|
|
9853
9848
|
//#region src/builtin-addons/internal-settings/buttons/brightness-up/backend.ts
|
|
9854
9849
|
var backend_default$9 = {
|
|
9855
9850
|
configSchema: z.object({ step: z.number().positive().max(100).default(5).meta({ title: "Brightness step" }) }),
|
|
@@ -9913,6 +9908,24 @@ const internalSettingsAddon = {
|
|
|
9913
9908
|
gestureHandlers: ["tap", "dbl-tap"]
|
|
9914
9909
|
}
|
|
9915
9910
|
},
|
|
9911
|
+
"internal-settings:compact-brightness": {
|
|
9912
|
+
frontend: CompactBrightnessFrontend,
|
|
9913
|
+
service: {
|
|
9914
|
+
...withInternal(backend_default$9),
|
|
9915
|
+
gestureHandlers: [
|
|
9916
|
+
"tap",
|
|
9917
|
+
"dbl-tap",
|
|
9918
|
+
"hold"
|
|
9919
|
+
],
|
|
9920
|
+
onHold: ({ coreMethods }) => {
|
|
9921
|
+
coreMethods.adjustBrightness({ direction: "down" });
|
|
9922
|
+
}
|
|
9923
|
+
}
|
|
9924
|
+
},
|
|
9925
|
+
"internal-settings:compact-app-info": {
|
|
9926
|
+
frontend: AppInfoButtonFrontend,
|
|
9927
|
+
service: { internal: true }
|
|
9928
|
+
},
|
|
9916
9929
|
"internal-settings:app-info": {
|
|
9917
9930
|
frontend: AppInfoButtonFrontend,
|
|
9918
9931
|
service: {
|
|
@@ -13204,7 +13217,6 @@ const registerBuiltins = (registry) => {
|
|
|
13204
13217
|
registry.load(systemStatusAddon);
|
|
13205
13218
|
registry.load(manifest$1);
|
|
13206
13219
|
registry.load(manifest);
|
|
13207
|
-
registry.load(manifest$9);
|
|
13208
13220
|
registerCodingAgentsAddon(registry);
|
|
13209
13221
|
};
|
|
13210
13222
|
/**
|
|
@@ -13233,7 +13245,6 @@ const BUILTIN_MANIFESTS = /* @__PURE__ */ new Map([
|
|
|
13233
13245
|
["system-status", systemStatusAddon],
|
|
13234
13246
|
["value-display", manifest$1],
|
|
13235
13247
|
["weather", manifest],
|
|
13236
|
-
["brightness", manifest$9],
|
|
13237
13248
|
["coding-agents", manifest$3]
|
|
13238
13249
|
]);
|
|
13239
13250
|
[
|
|
@@ -13462,6 +13473,29 @@ const expandButtonReferences = (raw, configDir) => {
|
|
|
13462
13473
|
return raw;
|
|
13463
13474
|
};
|
|
13464
13475
|
//#endregion
|
|
13476
|
+
//#region src/config/environment.ts
|
|
13477
|
+
var MissingEnvironmentVariableError = class extends Error {
|
|
13478
|
+
variable;
|
|
13479
|
+
configPath;
|
|
13480
|
+
constructor(variable, configPath) {
|
|
13481
|
+
super(`Environment variable ${variable} is not set (at ${configPath || "<root>"})`);
|
|
13482
|
+
this.variable = variable;
|
|
13483
|
+
this.configPath = configPath;
|
|
13484
|
+
this.name = "MissingEnvironmentVariableError";
|
|
13485
|
+
}
|
|
13486
|
+
};
|
|
13487
|
+
/** Resolve placeholders in values, never mapping keys or YAML source text. */
|
|
13488
|
+
const resolveEnvironmentVariables = (value, env = process.env, path = "") => {
|
|
13489
|
+
if (typeof value === "string") return value.replace(/\$\{env:([A-Za-z_][A-Za-z0-9_]*)\}/g, (_match, name) => {
|
|
13490
|
+
const resolved = Object.hasOwn(env, name) ? env[name] : void 0;
|
|
13491
|
+
if (resolved === void 0) throw new MissingEnvironmentVariableError(name, path);
|
|
13492
|
+
return resolved;
|
|
13493
|
+
});
|
|
13494
|
+
if (Array.isArray(value)) return value.map((item, index) => resolveEnvironmentVariables(item, env, `${path}[${index}]`));
|
|
13495
|
+
if (typeof value === "object" && value !== null) return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, resolveEnvironmentVariables(item, env, path ? `${path}.${key}` : key)]));
|
|
13496
|
+
return value;
|
|
13497
|
+
};
|
|
13498
|
+
//#endregion
|
|
13465
13499
|
//#region src/config/loader.ts
|
|
13466
13500
|
var ConfigLoadError = class extends Error {
|
|
13467
13501
|
issues;
|
|
@@ -13546,7 +13580,16 @@ const reportZodIssues = (issues) => issues.map((issue) => {
|
|
|
13546
13580
|
const loadConfig = ({ configPath }) => {
|
|
13547
13581
|
const configDir = dirname(configPath);
|
|
13548
13582
|
const raw = loadConfigFile(configPath);
|
|
13549
|
-
|
|
13583
|
+
let expanded;
|
|
13584
|
+
try {
|
|
13585
|
+
expanded = resolveEnvironmentVariables(expandButtonReferences(raw, configDir));
|
|
13586
|
+
} catch (err) {
|
|
13587
|
+
if (err instanceof MissingEnvironmentVariableError) throw new ConfigLoadError(err.message, [{
|
|
13588
|
+
message: err.message,
|
|
13589
|
+
path: err.configPath
|
|
13590
|
+
}]);
|
|
13591
|
+
throw err;
|
|
13592
|
+
}
|
|
13550
13593
|
const result = RawConfigSchema.safeParse(expanded);
|
|
13551
13594
|
if (!result.success) {
|
|
13552
13595
|
const issues = flattenZodIssues(result.error.issues);
|
|
@@ -13559,7 +13602,7 @@ const loadConfig = ({ configPath }) => {
|
|
|
13559
13602
|
};
|
|
13560
13603
|
//#endregion
|
|
13561
13604
|
//#region src/config/validation.ts
|
|
13562
|
-
const validateButton = (btn, registry, path, deckId, position) => {
|
|
13605
|
+
const validateButton = (btn, registry, path, deckId, position, allowInternal = false) => {
|
|
13563
13606
|
const base = {
|
|
13564
13607
|
deckId,
|
|
13565
13608
|
position
|
|
@@ -13582,7 +13625,7 @@ const validateButton = (btn, registry, path, deckId, position) => {
|
|
|
13582
13625
|
};
|
|
13583
13626
|
}
|
|
13584
13627
|
const def = registry.getButtonType(btn.type);
|
|
13585
|
-
if (isSystemButtonType(btn.type) || def.def.service.internal === true) {
|
|
13628
|
+
if (isSystemButtonType(btn.type) || !allowInternal && def.def.service.internal === true) {
|
|
13586
13629
|
issues.push({
|
|
13587
13630
|
level: "error",
|
|
13588
13631
|
path: `${path}.type`,
|
|
@@ -15246,6 +15289,7 @@ const paginate = (items, opts) => {
|
|
|
15246
15289
|
//#region src/deck/system-back-injection.ts
|
|
15247
15290
|
const computeSystemButtonForSlotN1 = (deck, state) => {
|
|
15248
15291
|
if (state.lockActive === true) return null;
|
|
15292
|
+
if (deck.isModal) return "core:modal-ok";
|
|
15249
15293
|
if (deck.isMain) return "core:settings-entry";
|
|
15250
15294
|
return "core:back";
|
|
15251
15295
|
};
|
|
@@ -15327,6 +15371,9 @@ const createRuntime = (options) => {
|
|
|
15327
15371
|
}
|
|
15328
15372
|
let brightness = 50;
|
|
15329
15373
|
let lockActive = false;
|
|
15374
|
+
const modals = [];
|
|
15375
|
+
let deferredOverlay = null;
|
|
15376
|
+
let interruption = null;
|
|
15330
15377
|
let legacyActiveApp = {
|
|
15331
15378
|
getActive: async () => null,
|
|
15332
15379
|
stop: async () => void 0
|
|
@@ -15337,6 +15384,17 @@ const createRuntime = (options) => {
|
|
|
15337
15384
|
const deckById = (id) => decks.find((d) => d.id === id);
|
|
15338
15385
|
const setDecks = (next) => {
|
|
15339
15386
|
decks = next;
|
|
15387
|
+
const activeModal = modals[0];
|
|
15388
|
+
for (let i = modals.length - 1; i >= 0; i--) if (deckById(modals[i].deckId) === void 0) modals.splice(i, 1);
|
|
15389
|
+
if (!lockActive && activeModal && modals[0] !== activeModal) {
|
|
15390
|
+
pubSub.publish("runtime:deck-inactive", { deckId: activeModal.deckId });
|
|
15391
|
+
pubSub.publish("runtime:activeDeck", { deckId: getActiveDeckId() });
|
|
15392
|
+
}
|
|
15393
|
+
if (interruption !== null && deckById(interruption.deckId) === void 0) {
|
|
15394
|
+
const previous = interruption.deckId;
|
|
15395
|
+
interruption = null;
|
|
15396
|
+
pubSub.publish("runtime:deck-inactive", { deckId: previous });
|
|
15397
|
+
}
|
|
15340
15398
|
buttonIndex.clear();
|
|
15341
15399
|
for (const deck of decks) {
|
|
15342
15400
|
if (!Array.isArray(deck.buttons)) continue;
|
|
@@ -15373,10 +15431,15 @@ const createRuntime = (options) => {
|
|
|
15373
15431
|
const id = getActiveDeckId();
|
|
15374
15432
|
const deck = deckById(id);
|
|
15375
15433
|
if (deck === void 0) throw new Error(`Active deck '${id}' not found`);
|
|
15376
|
-
return
|
|
15434
|
+
return !lockActive && modals[0]?.deckId === id ? {
|
|
15435
|
+
...deck,
|
|
15436
|
+
isModal: true
|
|
15437
|
+
} : deck;
|
|
15377
15438
|
};
|
|
15378
15439
|
const getActiveDeckId = () => {
|
|
15379
15440
|
if (lockActive) return "core:lock";
|
|
15441
|
+
if (modals[0]) return modals[0].deckId;
|
|
15442
|
+
if (interruption !== null) return interruption.deckId;
|
|
15380
15443
|
if (overlayDeckId !== null) {
|
|
15381
15444
|
if (transientDeckId !== null) return transientDeckId;
|
|
15382
15445
|
const stack = overlayNavStacks.get(overlayDeckId);
|
|
@@ -15386,6 +15449,51 @@ const createRuntime = (options) => {
|
|
|
15386
15449
|
return transientDeckId ?? navStack[navStack.length - 1] ?? mainDeck.id;
|
|
15387
15450
|
};
|
|
15388
15451
|
const snapshotRegularActiveDeckId = () => overlayPreviousActiveId ?? transientDeckId ?? navStack[navStack.length - 1] ?? mainDeck.id;
|
|
15452
|
+
const showModal = (id, options) => {
|
|
15453
|
+
if (!deckById(id)) return null;
|
|
15454
|
+
const previous = getActiveDeckId();
|
|
15455
|
+
const entry = {
|
|
15456
|
+
deckId: id,
|
|
15457
|
+
onOk: options?.onOk
|
|
15458
|
+
};
|
|
15459
|
+
modals.push(entry);
|
|
15460
|
+
if (!lockActive && modals[0] === entry) {
|
|
15461
|
+
pubSub.publish("runtime:deck-inactive", { deckId: previous });
|
|
15462
|
+
pubSub.publish("runtime:activeDeck", { deckId: id });
|
|
15463
|
+
}
|
|
15464
|
+
return () => {
|
|
15465
|
+
const index = modals.indexOf(entry);
|
|
15466
|
+
if (index < 0) return;
|
|
15467
|
+
const wasActive = index === 0 && !lockActive;
|
|
15468
|
+
modals.splice(index, 1);
|
|
15469
|
+
if (wasActive) {
|
|
15470
|
+
pubSub.publish("runtime:deck-inactive", { deckId: id });
|
|
15471
|
+
pubSub.publish("runtime:activeDeck", { deckId: getActiveDeckId() });
|
|
15472
|
+
if (modals.length === 0 && deferredOverlay) {
|
|
15473
|
+
const pending = deferredOverlay;
|
|
15474
|
+
deferredOverlay = null;
|
|
15475
|
+
setOverlay(pending.deckId, { source: pending.source });
|
|
15476
|
+
}
|
|
15477
|
+
}
|
|
15478
|
+
};
|
|
15479
|
+
};
|
|
15480
|
+
const interruptDeck = (id, options) => {
|
|
15481
|
+
if (lockActive || deckById(id) === void 0) return null;
|
|
15482
|
+
const previous = getActiveDeckId();
|
|
15483
|
+
const current = {
|
|
15484
|
+
deckId: id,
|
|
15485
|
+
onBack: options?.onBack
|
|
15486
|
+
};
|
|
15487
|
+
interruption = current;
|
|
15488
|
+
pubSub.publish("runtime:deck-inactive", { deckId: previous });
|
|
15489
|
+
pubSub.publish("runtime:activeDeck", { deckId: id });
|
|
15490
|
+
return () => {
|
|
15491
|
+
if (interruption !== current) return;
|
|
15492
|
+
interruption = null;
|
|
15493
|
+
pubSub.publish("runtime:deck-inactive", { deckId: id });
|
|
15494
|
+
pubSub.publish("runtime:activeDeck", { deckId: getActiveDeckId() });
|
|
15495
|
+
};
|
|
15496
|
+
};
|
|
15389
15497
|
const enterLock = () => {
|
|
15390
15498
|
const snapshot = {
|
|
15391
15499
|
activeDeckId: snapshotRegularActiveDeckId(),
|
|
@@ -15393,6 +15501,11 @@ const createRuntime = (options) => {
|
|
|
15393
15501
|
};
|
|
15394
15502
|
if (lockActive) return snapshot;
|
|
15395
15503
|
lockActive = true;
|
|
15504
|
+
if (interruption !== null) {
|
|
15505
|
+
const previous = interruption.deckId;
|
|
15506
|
+
interruption = null;
|
|
15507
|
+
pubSub.publish("runtime:deck-inactive", { deckId: previous });
|
|
15508
|
+
}
|
|
15396
15509
|
logger.info(snapshot, "runtime: lock active");
|
|
15397
15510
|
pubSub.publish("runtime:lock-mode", {
|
|
15398
15511
|
active: true,
|
|
@@ -15403,6 +15516,7 @@ const createRuntime = (options) => {
|
|
|
15403
15516
|
return snapshot;
|
|
15404
15517
|
};
|
|
15405
15518
|
const navigateToDeck = (id, navOptions) => {
|
|
15519
|
+
if (!lockActive && modals.length > 0) return;
|
|
15406
15520
|
if (id === getActiveDeckId()) return;
|
|
15407
15521
|
let resolvedId = id;
|
|
15408
15522
|
let target = deckById(id);
|
|
@@ -15417,6 +15531,15 @@ const createRuntime = (options) => {
|
|
|
15417
15531
|
logger.warn({ deckId: id }, "navigateToDeck: deck not found");
|
|
15418
15532
|
return;
|
|
15419
15533
|
}
|
|
15534
|
+
if (interruption !== null) {
|
|
15535
|
+
const previous = interruption.deckId;
|
|
15536
|
+
interruption = null;
|
|
15537
|
+
pubSub.publish("runtime:deck-inactive", { deckId: previous });
|
|
15538
|
+
if (getActiveDeckId() === resolvedId) {
|
|
15539
|
+
pubSub.publish("runtime:activeDeck", { deckId: resolvedId });
|
|
15540
|
+
return;
|
|
15541
|
+
}
|
|
15542
|
+
}
|
|
15420
15543
|
const previousActiveId = getActiveDeckId();
|
|
15421
15544
|
if (overlayDeckId !== null) {
|
|
15422
15545
|
if (overlayNavStacks.get(overlayDeckId) === void 0) overlayNavStacks.set(overlayDeckId, [overlayDeckId]);
|
|
@@ -15432,12 +15555,20 @@ const createRuntime = (options) => {
|
|
|
15432
15555
|
pubSub.publish("runtime:activeDeck", { deckId: resolvedId });
|
|
15433
15556
|
};
|
|
15434
15557
|
const goBack = () => {
|
|
15558
|
+
if (!lockActive && modals.length > 0) return;
|
|
15559
|
+
if (interruption !== null) {
|
|
15560
|
+
const previous = interruption.deckId;
|
|
15561
|
+
interruption = null;
|
|
15562
|
+
pubSub.publish("runtime:deck-inactive", { deckId: previous });
|
|
15563
|
+
pubSub.publish("runtime:activeDeck", { deckId: getActiveDeckId() });
|
|
15564
|
+
return;
|
|
15565
|
+
}
|
|
15435
15566
|
if (overlayDeckId !== null) {
|
|
15436
15567
|
const stack = overlayNavStacks.get(overlayDeckId);
|
|
15437
15568
|
if (stack !== void 0 && stack.length > 1) {
|
|
15438
|
-
stack.pop();
|
|
15569
|
+
const departed = stack.pop();
|
|
15439
15570
|
const prev = stack[stack.length - 1];
|
|
15440
|
-
pubSub.publish("runtime:deck-inactive", { deckId:
|
|
15571
|
+
pubSub.publish("runtime:deck-inactive", { deckId: departed });
|
|
15441
15572
|
pubSub.publish("runtime:activeDeck", { deckId: prev });
|
|
15442
15573
|
} else setOverlay(null);
|
|
15443
15574
|
return;
|
|
@@ -15469,10 +15600,23 @@ const createRuntime = (options) => {
|
|
|
15469
15600
|
pubSub.publish("runtime:activeDeck", { deckId: prev });
|
|
15470
15601
|
};
|
|
15471
15602
|
const setOverlay = (deckId, opts) => {
|
|
15603
|
+
if (!lockActive && modals.length > 0) {
|
|
15604
|
+
deferredOverlay = {
|
|
15605
|
+
deckId,
|
|
15606
|
+
...opts?.source ? { source: opts.source } : {}
|
|
15607
|
+
};
|
|
15608
|
+
return;
|
|
15609
|
+
}
|
|
15472
15610
|
if (deckId !== null && deckById(deckId) === void 0) {
|
|
15473
15611
|
logger.warn({ deckId }, "setOverlay: deck not found");
|
|
15474
15612
|
return;
|
|
15475
15613
|
}
|
|
15614
|
+
if (interruption !== null && deckId === overlayDeckId) return;
|
|
15615
|
+
if (interruption !== null && deckId !== overlayDeckId) {
|
|
15616
|
+
const previous = interruption.deckId;
|
|
15617
|
+
interruption = null;
|
|
15618
|
+
pubSub.publish("runtime:deck-inactive", { deckId: previous });
|
|
15619
|
+
}
|
|
15476
15620
|
if (deckId !== null && !overlayNavStacks.has(deckId)) overlayNavStacks.set(deckId, [deckId]);
|
|
15477
15621
|
const previousActiveId = getActiveDeckId();
|
|
15478
15622
|
const previousOverlayId = overlayDeckId;
|
|
@@ -15514,12 +15658,40 @@ const createRuntime = (options) => {
|
|
|
15514
15658
|
}, "mounted addon button");
|
|
15515
15659
|
};
|
|
15516
15660
|
const handleSystemButton = (type, gesture) => {
|
|
15661
|
+
if ((type === "core:back" || type === "core:modal-ok") && !lockActive && modals[0]) {
|
|
15662
|
+
if (gesture === "tap" || gesture === "hold") {
|
|
15663
|
+
const entry = modals.shift();
|
|
15664
|
+
pubSub.publish("runtime:deck-inactive", { deckId: entry.deckId });
|
|
15665
|
+
pubSub.publish("runtime:activeDeck", { deckId: getActiveDeckId() });
|
|
15666
|
+
if (modals.length === 0 && deferredOverlay) {
|
|
15667
|
+
const pending = deferredOverlay;
|
|
15668
|
+
deferredOverlay = null;
|
|
15669
|
+
setOverlay(pending.deckId, { source: pending.source });
|
|
15670
|
+
}
|
|
15671
|
+
if (entry.onOk) Promise.resolve().then(entry.onOk).catch((err) => logger.error({ err }, "modal OK action failed"));
|
|
15672
|
+
}
|
|
15673
|
+
return true;
|
|
15674
|
+
}
|
|
15517
15675
|
if (type === "core:back") {
|
|
15518
15676
|
if (gesture === "tap") {
|
|
15677
|
+
if (interruption?.onBack) {
|
|
15678
|
+
const current = interruption;
|
|
15679
|
+
if (current.backPending) return true;
|
|
15680
|
+
current.backPending = true;
|
|
15681
|
+
Promise.resolve().then(current.onBack).catch((err) => logger.error({ err }, "interruption back action failed")).finally(() => {
|
|
15682
|
+
current.backPending = false;
|
|
15683
|
+
});
|
|
15684
|
+
return true;
|
|
15685
|
+
}
|
|
15519
15686
|
goBack();
|
|
15520
15687
|
return true;
|
|
15521
15688
|
}
|
|
15522
15689
|
if (gesture === "hold") {
|
|
15690
|
+
if (interruption !== null) {
|
|
15691
|
+
const previous = interruption.deckId;
|
|
15692
|
+
interruption = null;
|
|
15693
|
+
pubSub.publish("runtime:deck-inactive", { deckId: previous });
|
|
15694
|
+
}
|
|
15523
15695
|
if (overlayDeckId !== null) setOverlay(null);
|
|
15524
15696
|
navStack.length = 0;
|
|
15525
15697
|
navStack.push(mainDeck.id);
|
|
@@ -15577,6 +15749,7 @@ const createRuntime = (options) => {
|
|
|
15577
15749
|
logger.warn({ buttonId }, "invokeAction: button not found");
|
|
15578
15750
|
return;
|
|
15579
15751
|
}
|
|
15752
|
+
if (!lockActive && modals[0] && found.deckId !== modals[0].deckId) return;
|
|
15580
15753
|
try {
|
|
15581
15754
|
if (handleSystemButton(found.button.type, gesture)) return;
|
|
15582
15755
|
if (lockActive && found.deckId === "core:lock") {
|
|
@@ -15700,6 +15873,7 @@ const createRuntime = (options) => {
|
|
|
15700
15873
|
logger.warn({ buttonId }, "dispatchGesture: button not found");
|
|
15701
15874
|
return;
|
|
15702
15875
|
}
|
|
15876
|
+
if (!lockActive && modals[0] && found.deckId !== modals[0].deckId) return;
|
|
15703
15877
|
gestureListener?.(found.button.id, {
|
|
15704
15878
|
gesture,
|
|
15705
15879
|
at: Date.now(),
|
|
@@ -15735,6 +15909,12 @@ const createRuntime = (options) => {
|
|
|
15735
15909
|
reason: "session-unlocked"
|
|
15736
15910
|
});
|
|
15737
15911
|
pubSub.publish("runtime:invalidate", void 0);
|
|
15912
|
+
if (modals[0]) pubSub.publish("runtime:activeDeck", { deckId: modals[0].deckId });
|
|
15913
|
+
else if (deferredOverlay) {
|
|
15914
|
+
const pending = deferredOverlay;
|
|
15915
|
+
deferredOverlay = null;
|
|
15916
|
+
setOverlay(pending.deckId, { source: pending.source });
|
|
15917
|
+
}
|
|
15738
15918
|
};
|
|
15739
15919
|
const startLegacyPolicy = () => {
|
|
15740
15920
|
legacyPolicy?.dispose();
|
|
@@ -15783,6 +15963,8 @@ const createRuntime = (options) => {
|
|
|
15783
15963
|
deckExists: (id) => deckById(id) !== void 0 || deckById(`${id}-p1`) !== void 0,
|
|
15784
15964
|
setDecks,
|
|
15785
15965
|
navigateToDeck,
|
|
15966
|
+
interruptDeck,
|
|
15967
|
+
showModal,
|
|
15786
15968
|
goBack,
|
|
15787
15969
|
setOverlay,
|
|
15788
15970
|
getOverlay,
|
|
@@ -15990,6 +16172,7 @@ const buildDeckConfigMessage = (deck, addonByType, resolverOptions = {}, navStat
|
|
|
15990
16172
|
surfaces: { [deck.id]: {
|
|
15991
16173
|
id: deck.id,
|
|
15992
16174
|
name: deck.name ?? deck.id,
|
|
16175
|
+
...deck.isModal === true ? { isModal: true } : {},
|
|
15993
16176
|
buttons: finalButtons,
|
|
15994
16177
|
...deck.buttonColor !== void 0 ? { buttonColor: deck.buttonColor } : {},
|
|
15995
16178
|
...deck.variant !== void 0 && deck.variant.length > 0 ? { variant: deck.variant } : {},
|
|
@@ -16161,7 +16344,13 @@ const paginateDeck = (opts) => {
|
|
|
16161
16344
|
};
|
|
16162
16345
|
//#endregion
|
|
16163
16346
|
//#region src/deck/inject-config-ui-button.ts
|
|
16164
|
-
const injectConfigUiButton = (decks, configUiUrl) => decks.map((deck) => deck.id !== "internal-settings:settings" ? deck : {
|
|
16347
|
+
const injectConfigUiButton = (decks, configUiUrl, keyCount = 15) => decks.map((deck) => deck.id !== "internal-settings:settings" && !deck.id.startsWith("internal-settings:settings-p") ? deck : keyCount === 6 ? {
|
|
16348
|
+
...deck,
|
|
16349
|
+
buttons: deck.buttons.map((button) => button.type === "internal-settings:compact-app-info" ? {
|
|
16350
|
+
...button,
|
|
16351
|
+
actions: { tap: `url://${configUiUrl}` }
|
|
16352
|
+
} : button)
|
|
16353
|
+
} : {
|
|
16165
16354
|
...deck,
|
|
16166
16355
|
buttons: [...deck.buttons, {
|
|
16167
16356
|
id: "config-ui",
|
|
@@ -16175,16 +16364,83 @@ const injectConfigUiButton = (decks, configUiUrl) => decks.map((deck) => deck.id
|
|
|
16175
16364
|
}]
|
|
16176
16365
|
});
|
|
16177
16366
|
//#endregion
|
|
16178
|
-
//#region src/deck/
|
|
16179
|
-
const
|
|
16180
|
-
|
|
16181
|
-
|
|
16182
|
-
|
|
16183
|
-
|
|
16184
|
-
|
|
16185
|
-
|
|
16186
|
-
|
|
16367
|
+
//#region src/deck/addon-settings.ts
|
|
16368
|
+
const settingsId = "internal-settings:settings";
|
|
16369
|
+
const buildAddonSettingsDecks = (decks, addons, keyCount) => {
|
|
16370
|
+
const base = decks.find((deck) => deck.id === settingsId);
|
|
16371
|
+
if (!base) return [...decks];
|
|
16372
|
+
const compact = keyCount === 6;
|
|
16373
|
+
const entries = addons.filter((addon) => addon.settings !== void 0);
|
|
16374
|
+
const start = compact ? 2 : 4;
|
|
16375
|
+
const available = keyCount - 1 - start;
|
|
16376
|
+
const paginated = entries.length > available;
|
|
16377
|
+
const pageSize = available - (paginated ? 1 : 0);
|
|
16378
|
+
if (pageSize < 1) return [...decks];
|
|
16379
|
+
const total = Math.max(1, Math.ceil(entries.length / pageSize));
|
|
16380
|
+
const pageId = (page) => page === 0 ? settingsId : `${settingsId}-p${page + 1}`;
|
|
16381
|
+
const pages = Array.from({ length: total }, (_, page) => {
|
|
16382
|
+
const buttons = compact ? [{
|
|
16383
|
+
id: "app-info",
|
|
16384
|
+
type: "internal-settings:compact-app-info",
|
|
16385
|
+
position: 0,
|
|
16386
|
+
config: { icon: "addon://internal-settings/logo72x72.png" }
|
|
16387
|
+
}, {
|
|
16388
|
+
id: "brightness",
|
|
16389
|
+
type: "internal-settings:compact-brightness",
|
|
16390
|
+
position: 1
|
|
16391
|
+
}] : [
|
|
16392
|
+
{
|
|
16393
|
+
id: "app-info",
|
|
16394
|
+
type: "internal-settings:app-info",
|
|
16395
|
+
position: 0,
|
|
16396
|
+
config: { icon: "addon://internal-settings/logo72x72.png" }
|
|
16397
|
+
},
|
|
16398
|
+
{
|
|
16399
|
+
id: "brightness-down",
|
|
16400
|
+
type: "internal-settings:brightness-down",
|
|
16401
|
+
position: 1
|
|
16402
|
+
},
|
|
16403
|
+
{
|
|
16404
|
+
id: "brightness-up",
|
|
16405
|
+
type: "internal-settings:brightness-up",
|
|
16406
|
+
position: 2
|
|
16407
|
+
}
|
|
16408
|
+
];
|
|
16409
|
+
for (const [index, addon] of entries.slice(page * pageSize, (page + 1) * pageSize).entries()) {
|
|
16410
|
+
const settings = addon.settings;
|
|
16411
|
+
buttons.push({
|
|
16412
|
+
id: `settings-${addon.name}`,
|
|
16413
|
+
type: "core:change-deck",
|
|
16414
|
+
position: start + index,
|
|
16415
|
+
config: {
|
|
16416
|
+
deck: settings.deck,
|
|
16417
|
+
label: settings.label,
|
|
16418
|
+
icon: settings.icon
|
|
16419
|
+
}
|
|
16420
|
+
});
|
|
16421
|
+
}
|
|
16422
|
+
if (paginated) buttons.push({
|
|
16423
|
+
id: "page-nav",
|
|
16424
|
+
type: "core:page-nav",
|
|
16425
|
+
position: keyCount - 2,
|
|
16426
|
+
config: {
|
|
16427
|
+
currentPage: page + 1,
|
|
16428
|
+
totalPages: total,
|
|
16429
|
+
prevDeckId: pageId(Math.max(0, page - 1)),
|
|
16430
|
+
nextDeckId: pageId(Math.min(total - 1, page + 1))
|
|
16431
|
+
}
|
|
16432
|
+
});
|
|
16433
|
+
return {
|
|
16434
|
+
...base,
|
|
16435
|
+
id: pageId(page),
|
|
16436
|
+
buttons,
|
|
16437
|
+
sourceDeckId: settingsId,
|
|
16438
|
+
projectionId: pageId(page),
|
|
16439
|
+
pageIndex: page,
|
|
16440
|
+
paginated
|
|
16441
|
+
};
|
|
16187
16442
|
});
|
|
16443
|
+
return decks.flatMap((deck) => deck.id === settingsId ? pages : [deck]);
|
|
16188
16444
|
};
|
|
16189
16445
|
//#endregion
|
|
16190
16446
|
//#region src/deck/runtime-subscriptions.ts
|
|
@@ -16319,7 +16575,7 @@ const createNotificationProvider = async (options) => {
|
|
|
16319
16575
|
});
|
|
16320
16576
|
}
|
|
16321
16577
|
if (platform === "win32") {
|
|
16322
|
-
const { createWindowsNotificationProvider } = await import("./windows-
|
|
16578
|
+
const { createWindowsNotificationProvider } = await import("./windows-BCvfQ3PA.mjs");
|
|
16323
16579
|
return createWindowsNotificationProvider({
|
|
16324
16580
|
executor: options.executor,
|
|
16325
16581
|
logger: options.logger,
|
|
@@ -18035,6 +18291,124 @@ const BUILTIN_GLOBAL_SERVICES = /* @__PURE__ */ new Map([["coding-agents", {
|
|
|
18035
18291
|
lastLiveCount = -1;
|
|
18036
18292
|
}
|
|
18037
18293
|
}]]);
|
|
18294
|
+
/** Error messages must not include credential values or native error details. */
|
|
18295
|
+
var CredentialStoreError = class extends Error {
|
|
18296
|
+
code;
|
|
18297
|
+
constructor(code) {
|
|
18298
|
+
super(`Credential store: ${code}`);
|
|
18299
|
+
this.code = code;
|
|
18300
|
+
this.name = "CredentialStoreError";
|
|
18301
|
+
}
|
|
18302
|
+
};
|
|
18303
|
+
const validateName = (name) => {
|
|
18304
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(name)) throw new CredentialStoreError("invalid-name");
|
|
18305
|
+
};
|
|
18306
|
+
/** Bind an addon identity so callers cannot choose another namespace. */
|
|
18307
|
+
const scopeCredentials = (backend, addon) => {
|
|
18308
|
+
return {
|
|
18309
|
+
availability: () => backend.availability(),
|
|
18310
|
+
get: async (name) => {
|
|
18311
|
+
validateName(name);
|
|
18312
|
+
return backend.get(addon, name);
|
|
18313
|
+
},
|
|
18314
|
+
set: async (name, value) => {
|
|
18315
|
+
validateName(name);
|
|
18316
|
+
if (Buffer.byteLength(value, "utf8") > 2560) throw new CredentialStoreError("too-large");
|
|
18317
|
+
await backend.set(addon, name, value);
|
|
18318
|
+
},
|
|
18319
|
+
delete: async (name) => {
|
|
18320
|
+
validateName(name);
|
|
18321
|
+
await backend.delete(addon, name);
|
|
18322
|
+
}
|
|
18323
|
+
};
|
|
18324
|
+
};
|
|
18325
|
+
//#endregion
|
|
18326
|
+
//#region src/system/credentials/native.ts
|
|
18327
|
+
const accountFor = (addon, name) => createHash("sha256").update(JSON.stringify([addon, name])).digest("hex");
|
|
18328
|
+
/** Entries contain no user-provided names in native-store metadata. */
|
|
18329
|
+
const createNativeCredentialBackend = (createEntry = async (account) => {
|
|
18330
|
+
const { AsyncEntry } = await import("@napi-rs/keyring");
|
|
18331
|
+
return new AsyncEntry("sirenodeck.credentials.v1", account, { linux: { store: "secret-service" } });
|
|
18332
|
+
}) => {
|
|
18333
|
+
const entry = async (addon, name) => {
|
|
18334
|
+
try {
|
|
18335
|
+
return await createEntry(accountFor(addon, name));
|
|
18336
|
+
} catch {
|
|
18337
|
+
throw new CredentialStoreError("unavailable");
|
|
18338
|
+
}
|
|
18339
|
+
};
|
|
18340
|
+
return {
|
|
18341
|
+
availability: async () => {
|
|
18342
|
+
try {
|
|
18343
|
+
await (await createEntry(accountFor("sirenodeck", "availability-probe"))).getSecret();
|
|
18344
|
+
return "available";
|
|
18345
|
+
} catch {
|
|
18346
|
+
return "unavailable";
|
|
18347
|
+
}
|
|
18348
|
+
},
|
|
18349
|
+
get: async (addon, name) => {
|
|
18350
|
+
const item = await entry(addon, name);
|
|
18351
|
+
try {
|
|
18352
|
+
const bytes = await item.getSecret();
|
|
18353
|
+
return bytes === null ? void 0 : new TextDecoder("utf-8", { fatal: true }).decode(Uint8Array.from(bytes));
|
|
18354
|
+
} catch {
|
|
18355
|
+
throw new CredentialStoreError("operation-failed");
|
|
18356
|
+
}
|
|
18357
|
+
},
|
|
18358
|
+
set: async (addon, name, value) => {
|
|
18359
|
+
const item = await entry(addon, name);
|
|
18360
|
+
try {
|
|
18361
|
+
await item.setSecret(new TextEncoder().encode(value));
|
|
18362
|
+
} catch {
|
|
18363
|
+
throw new CredentialStoreError("operation-failed");
|
|
18364
|
+
}
|
|
18365
|
+
},
|
|
18366
|
+
delete: async (addon, name) => {
|
|
18367
|
+
const item = await entry(addon, name);
|
|
18368
|
+
try {
|
|
18369
|
+
await item.deleteCredential();
|
|
18370
|
+
} catch {
|
|
18371
|
+
throw new CredentialStoreError("operation-failed");
|
|
18372
|
+
}
|
|
18373
|
+
}
|
|
18374
|
+
};
|
|
18375
|
+
};
|
|
18376
|
+
//#endregion
|
|
18377
|
+
//#region src/addon/data-directory.ts
|
|
18378
|
+
const addonDataRoot = () => {
|
|
18379
|
+
if (process.platform === "win32") {
|
|
18380
|
+
const local = process.env["LOCALAPPDATA"];
|
|
18381
|
+
if (!local || !isAbsolute(local)) throw new Error("LOCALAPPDATA is unavailable");
|
|
18382
|
+
return join(local, "sirenodeck");
|
|
18383
|
+
}
|
|
18384
|
+
if (process.platform === "darwin") return join(homedir(), "Library", "Application Support", "sirenodeck");
|
|
18385
|
+
const xdg = process.env["XDG_DATA_HOME"];
|
|
18386
|
+
return join(xdg && isAbsolute(xdg) ? xdg : join(homedir(), ".local", "share"), "sirenodeck");
|
|
18387
|
+
};
|
|
18388
|
+
const createAddonDataDirectory = (name, root) => {
|
|
18389
|
+
let result;
|
|
18390
|
+
return () => {
|
|
18391
|
+
result ??= (async () => {
|
|
18392
|
+
const base = root ?? addonDataRoot();
|
|
18393
|
+
if (!isAbsolute(base)) throw new Error("Addon data root must be absolute");
|
|
18394
|
+
const addons = join(base, "addons");
|
|
18395
|
+
const directory = join(addons, createHash("sha256").update(name).digest("hex"));
|
|
18396
|
+
await mkdir(base, {
|
|
18397
|
+
recursive: true,
|
|
18398
|
+
mode: 448
|
|
18399
|
+
});
|
|
18400
|
+
for (const path of [addons, directory]) {
|
|
18401
|
+
await mkdir(path, { mode: 448 }).catch((error) => {
|
|
18402
|
+
if (error.code !== "EEXIST") throw error;
|
|
18403
|
+
});
|
|
18404
|
+
if (!(await lstat(path)).isDirectory()) throw new Error(`Not a directory: ${path}`);
|
|
18405
|
+
if (process.platform !== "win32") await chmod(path, 448);
|
|
18406
|
+
}
|
|
18407
|
+
return directory;
|
|
18408
|
+
})();
|
|
18409
|
+
return result;
|
|
18410
|
+
};
|
|
18411
|
+
};
|
|
18038
18412
|
//#endregion
|
|
18039
18413
|
//#region src/deck/addon-handler-bridge.ts
|
|
18040
18414
|
const namespacedKey = (addonName, methodName) => `${addonName}:${methodName}`;
|
|
@@ -18071,7 +18445,7 @@ const staticGlobalServiceModule = (addonName) => {
|
|
|
18071
18445
|
return fromManifest.manifest?.globalService === void 0 ? null : fromManifest;
|
|
18072
18446
|
};
|
|
18073
18447
|
const bridgeAddonServices = async (params) => {
|
|
18074
|
-
const { runtime, decks, scanned, externalAddons, executor, pubSub, store, signal, statePublisher, bridge, methods, requestDeckRebuild } = params;
|
|
18448
|
+
const { runtime, decks, scanned, externalAddons, executor, pubSub, store, signal, statePublisher, bridge, methods, addonServiceConfigs, credentialBackend = createNativeCredentialBackend(), requestDeckRebuild } = params;
|
|
18075
18449
|
const logger = params.logger.child({ component: "addon-handler" });
|
|
18076
18450
|
const allAddons = [...scanned, ...externalAddons];
|
|
18077
18451
|
runtime.setGestureListener((buttonId, event) => {
|
|
@@ -18086,6 +18460,7 @@ const bridgeAddonServices = async (params) => {
|
|
|
18086
18460
|
const trackedCleanup = [];
|
|
18087
18461
|
const addonModules = /* @__PURE__ */ new Map();
|
|
18088
18462
|
const addonGlobalServices = /* @__PURE__ */ new Map();
|
|
18463
|
+
const addonDataDirectories = /* @__PURE__ */ new Map();
|
|
18089
18464
|
const addonMethods = /* @__PURE__ */ new Map();
|
|
18090
18465
|
for (const addon of allAddons) {
|
|
18091
18466
|
if (addon.globalServiceEntry === null) continue;
|
|
@@ -18110,10 +18485,46 @@ const bridgeAddonServices = async (params) => {
|
|
|
18110
18485
|
}
|
|
18111
18486
|
}
|
|
18112
18487
|
for (const [addonName, globalService] of addonGlobalServices) {
|
|
18488
|
+
const getDataDirectory = createAddonDataDirectory(addonName, params.addonDataRoot);
|
|
18489
|
+
addonDataDirectories.set(addonName, getDataDirectory);
|
|
18490
|
+
const interruptions = /* @__PURE__ */ new Set();
|
|
18491
|
+
abortController.signal.addEventListener("abort", () => {
|
|
18492
|
+
for (const release of interruptions) release();
|
|
18493
|
+
interruptions.clear();
|
|
18494
|
+
});
|
|
18113
18495
|
const primaryChannel = globalService.pollers?.[0]?.channel;
|
|
18114
18496
|
const pollersById = /* @__PURE__ */ new Map();
|
|
18115
18497
|
for (const poller of globalService.pollers ?? []) pollersById.set(poller.id, poller);
|
|
18116
18498
|
const ctx = {
|
|
18499
|
+
getDataDirectory,
|
|
18500
|
+
interruptDeck: (deckId, options) => {
|
|
18501
|
+
if (abortController.signal.aborted) return null;
|
|
18502
|
+
const release = runtime.interruptDeck(deckId, options);
|
|
18503
|
+
if (release === null) return null;
|
|
18504
|
+
const ownedRelease = () => {
|
|
18505
|
+
interruptions.delete(ownedRelease);
|
|
18506
|
+
release();
|
|
18507
|
+
};
|
|
18508
|
+
interruptions.add(ownedRelease);
|
|
18509
|
+
return ownedRelease;
|
|
18510
|
+
},
|
|
18511
|
+
showModal: (deckId, options) => {
|
|
18512
|
+
if (abortController.signal.aborted) return null;
|
|
18513
|
+
let ownedRelease;
|
|
18514
|
+
const release = runtime.showModal(deckId, { onOk: async () => {
|
|
18515
|
+
interruptions.delete(ownedRelease);
|
|
18516
|
+
if (abortController.signal.aborted) return;
|
|
18517
|
+
await options?.onOk?.();
|
|
18518
|
+
} });
|
|
18519
|
+
if (release === null) return null;
|
|
18520
|
+
ownedRelease = () => {
|
|
18521
|
+
interruptions.delete(ownedRelease);
|
|
18522
|
+
release();
|
|
18523
|
+
};
|
|
18524
|
+
interruptions.add(ownedRelease);
|
|
18525
|
+
return ownedRelease;
|
|
18526
|
+
},
|
|
18527
|
+
credentials: scopeCredentials(credentialBackend, addonName),
|
|
18117
18528
|
publish: (data) => {
|
|
18118
18529
|
if (primaryChannel !== void 0) {
|
|
18119
18530
|
bridge.broadcast({
|
|
@@ -18155,7 +18566,7 @@ const bridgeAddonServices = async (params) => {
|
|
|
18155
18566
|
bridge.registerCacheablePoller(poller.channel, () => poller.poll(ctx));
|
|
18156
18567
|
}
|
|
18157
18568
|
try {
|
|
18158
|
-
const result = globalService.onLoad?.(ctx);
|
|
18569
|
+
const result = globalService.onLoad?.(ctx, addonServiceConfigs?.get(addonName));
|
|
18159
18570
|
if (result instanceof Promise) result.catch((err) => {
|
|
18160
18571
|
logger.error({
|
|
18161
18572
|
addonName,
|
|
@@ -18252,19 +18663,39 @@ const bridgeAddonServices = async (params) => {
|
|
|
18252
18663
|
signal: abortController.signal,
|
|
18253
18664
|
store
|
|
18254
18665
|
};
|
|
18255
|
-
|
|
18666
|
+
let buttonAbort = new AbortController();
|
|
18256
18667
|
abortController.signal.addEventListener("abort", () => buttonAbort.abort());
|
|
18257
|
-
|
|
18668
|
+
let wrappedCtx = {
|
|
18258
18669
|
...buttonCtx,
|
|
18259
18670
|
signal: buttonAbort.signal
|
|
18260
18671
|
};
|
|
18261
|
-
const
|
|
18262
|
-
existing.push({
|
|
18672
|
+
const entry = {
|
|
18263
18673
|
handlerId,
|
|
18264
18674
|
buttonAbort,
|
|
18265
18675
|
buttonService,
|
|
18266
|
-
wrappedCtx
|
|
18267
|
-
|
|
18676
|
+
wrappedCtx,
|
|
18677
|
+
activate: () => {
|
|
18678
|
+
if (!buttonAbort.signal.aborted || abortController.signal.aborted) return;
|
|
18679
|
+
buttonAbort = new AbortController();
|
|
18680
|
+
wrappedCtx = {
|
|
18681
|
+
...buttonCtx,
|
|
18682
|
+
signal: buttonAbort.signal
|
|
18683
|
+
};
|
|
18684
|
+
entry.buttonAbort = buttonAbort;
|
|
18685
|
+
entry.wrappedCtx = wrappedCtx;
|
|
18686
|
+
try {
|
|
18687
|
+
buttonService.onMount?.(wrappedCtx);
|
|
18688
|
+
} catch (err) {
|
|
18689
|
+
logger.error({
|
|
18690
|
+
addonName,
|
|
18691
|
+
buttonType,
|
|
18692
|
+
err
|
|
18693
|
+
}, `addon onMount threw`);
|
|
18694
|
+
}
|
|
18695
|
+
}
|
|
18696
|
+
};
|
|
18697
|
+
const existing = deckButtonCleanup.get(deck.id) ?? [];
|
|
18698
|
+
existing.push(entry);
|
|
18268
18699
|
deckButtonCleanup.set(deck.id, existing);
|
|
18269
18700
|
try {
|
|
18270
18701
|
buttonService.onMount?.(wrappedCtx);
|
|
@@ -18361,6 +18792,7 @@ const bridgeAddonServices = async (params) => {
|
|
|
18361
18792
|
const tracked = deckButtonCleanup.get(deckId);
|
|
18362
18793
|
if (tracked === void 0) return;
|
|
18363
18794
|
for (const { buttonAbort, buttonService, wrappedCtx } of tracked) {
|
|
18795
|
+
if (buttonAbort.signal.aborted) continue;
|
|
18364
18796
|
try {
|
|
18365
18797
|
buttonService.onUnmount?.(wrappedCtx);
|
|
18366
18798
|
} catch (err) {
|
|
@@ -18373,16 +18805,22 @@ const bridgeAddonServices = async (params) => {
|
|
|
18373
18805
|
}
|
|
18374
18806
|
});
|
|
18375
18807
|
trackedCleanup.push(unsubscribeDeckInactive);
|
|
18808
|
+
trackedCleanup.push(pubSub.subscribe("runtime:activeDeck", (payload) => {
|
|
18809
|
+
if (typeof payload !== "object" || payload === null || !("deckId" in payload)) return;
|
|
18810
|
+
for (const entry of deckButtonCleanup.get(String(payload.deckId)) ?? []) entry.activate();
|
|
18811
|
+
}));
|
|
18376
18812
|
abortController.signal.addEventListener("abort", () => {
|
|
18377
18813
|
for (const [addonName, globalService] of addonGlobalServices) try {
|
|
18378
18814
|
const ctx = {
|
|
18815
|
+
getDataDirectory: addonDataDirectories.get(addonName),
|
|
18816
|
+
credentials: scopeCredentials(credentialBackend, addonName),
|
|
18379
18817
|
publish: () => {},
|
|
18380
18818
|
poll: async () => {},
|
|
18381
18819
|
signal: abortController.signal,
|
|
18382
18820
|
executor,
|
|
18383
18821
|
notify: methods.notify
|
|
18384
18822
|
};
|
|
18385
|
-
globalService.onUnload?.(ctx);
|
|
18823
|
+
globalService.onUnload?.(ctx, addonServiceConfigs?.get(addonName));
|
|
18386
18824
|
} catch (err) {
|
|
18387
18825
|
logger.error({
|
|
18388
18826
|
addonName,
|
|
@@ -18398,13 +18836,15 @@ const bridgeAddonServices = async (params) => {
|
|
|
18398
18836
|
unmountButtons();
|
|
18399
18837
|
for (const [addonName, globalService] of addonGlobalServices) try {
|
|
18400
18838
|
const ctx = {
|
|
18839
|
+
getDataDirectory: addonDataDirectories.get(addonName),
|
|
18840
|
+
credentials: scopeCredentials(credentialBackend, addonName),
|
|
18401
18841
|
publish: () => {},
|
|
18402
18842
|
poll: async () => {},
|
|
18403
18843
|
signal: abortController.signal,
|
|
18404
18844
|
executor,
|
|
18405
18845
|
notify: methods.notify
|
|
18406
18846
|
};
|
|
18407
|
-
globalService.onUnload?.(ctx);
|
|
18847
|
+
globalService.onUnload?.(ctx, addonServiceConfigs?.get(addonName));
|
|
18408
18848
|
} catch (err) {
|
|
18409
18849
|
logger.error({
|
|
18410
18850
|
addonName,
|
|
@@ -18534,6 +18974,10 @@ const helloAckMessageSchema = baseServerMessage.extend({
|
|
|
18534
18974
|
type: z.literal("hello-ack"),
|
|
18535
18975
|
version: z.literal(1),
|
|
18536
18976
|
device: deviceInfoSchema.optional(),
|
|
18977
|
+
build: z.object({
|
|
18978
|
+
version: z.string(),
|
|
18979
|
+
buildId: z.string().nullable()
|
|
18980
|
+
}).strict().optional(),
|
|
18537
18981
|
config: z.unknown()
|
|
18538
18982
|
}).strict();
|
|
18539
18983
|
const deviceInfoMessageSchema = baseServerMessage.extend({
|
|
@@ -18565,6 +19009,7 @@ const deckConfigSurfaceSchema = z.object({
|
|
|
18565
19009
|
id: z.string(),
|
|
18566
19010
|
name: z.string(),
|
|
18567
19011
|
buttons: z.array(deckConfigSurfaceButtonSchema),
|
|
19012
|
+
isModal: z.boolean().optional(),
|
|
18568
19013
|
buttonColor: z.string().optional(),
|
|
18569
19014
|
variant: z.string().optional(),
|
|
18570
19015
|
buttonErrors: z.array(z.object({
|
|
@@ -19028,6 +19473,7 @@ const startWsBridge = (options) => {
|
|
|
19028
19473
|
const ack = helloAckMessageSchema.parse({
|
|
19029
19474
|
type: "hello-ack",
|
|
19030
19475
|
version: 1,
|
|
19476
|
+
build: runtimeIdentity,
|
|
19031
19477
|
...currentDevice !== null ? { device: currentDevice } : {},
|
|
19032
19478
|
config: currentTheme !== void 0 ? { theme: currentTheme.name } : {}
|
|
19033
19479
|
});
|
|
@@ -20212,6 +20658,7 @@ var BrowserRenderer = class BrowserRenderer {
|
|
|
20212
20658
|
context = null;
|
|
20213
20659
|
page = null;
|
|
20214
20660
|
running = false;
|
|
20661
|
+
recovering = null;
|
|
20215
20662
|
logger;
|
|
20216
20663
|
constructor(options) {
|
|
20217
20664
|
this.options = options;
|
|
@@ -20242,6 +20689,12 @@ var BrowserRenderer = class BrowserRenderer {
|
|
|
20242
20689
|
(original error: ${message.split("\n")[0] ?? ""})`);
|
|
20243
20690
|
throw err;
|
|
20244
20691
|
}
|
|
20692
|
+
await this.openPage();
|
|
20693
|
+
if (this.pubSub) this.subscriptions.push({ unsubscribe: this.pubSub.subscribe("runtime:activeDeck", () => this.debouncer.trigger()) }, { unsubscribe: this.pubSub.subscribe("runtime:invalidate", () => this.debouncer.trigger()) });
|
|
20694
|
+
this.cadence.start();
|
|
20695
|
+
this.running = true;
|
|
20696
|
+
}
|
|
20697
|
+
async openPage() {
|
|
20245
20698
|
const { columns, rows } = gridForKeyCount(this.options.device.getKeyCount());
|
|
20246
20699
|
const vpWidth = columns * 96;
|
|
20247
20700
|
const vpHeight = rows * 96;
|
|
@@ -20251,9 +20704,6 @@ var BrowserRenderer = class BrowserRenderer {
|
|
|
20251
20704
|
} });
|
|
20252
20705
|
this.page = await this.context.newPage();
|
|
20253
20706
|
await this.page.goto(this.options.frontendUrl, { waitUntil: "networkidle" });
|
|
20254
|
-
if (this.pubSub) this.subscriptions.push({ unsubscribe: this.pubSub.subscribe("runtime:activeDeck", () => this.debouncer.trigger()) }, { unsubscribe: this.pubSub.subscribe("runtime:invalidate", () => this.debouncer.trigger()) });
|
|
20255
|
-
this.cadence.start();
|
|
20256
|
-
this.running = true;
|
|
20257
20707
|
}
|
|
20258
20708
|
/**
|
|
20259
20709
|
* Repaints every key on the next tick.
|
|
@@ -20274,16 +20724,53 @@ var BrowserRenderer = class BrowserRenderer {
|
|
|
20274
20724
|
this.debouncer.dispose();
|
|
20275
20725
|
for (const sub of this.subscriptions) sub.unsubscribe();
|
|
20276
20726
|
this.subscriptions.length = 0;
|
|
20277
|
-
|
|
20278
|
-
|
|
20279
|
-
|
|
20727
|
+
await this.recovering;
|
|
20728
|
+
await Promise.allSettled([
|
|
20729
|
+
this.page?.close(),
|
|
20730
|
+
this.context?.close(),
|
|
20731
|
+
this.browser?.close()
|
|
20732
|
+
]);
|
|
20280
20733
|
this.page = null;
|
|
20281
20734
|
this.context = null;
|
|
20282
20735
|
this.browser = null;
|
|
20283
20736
|
}
|
|
20284
20737
|
static BLANK_THRESHOLD = 20;
|
|
20738
|
+
async recover() {
|
|
20739
|
+
runtimeHealth.setRenderer("recovering");
|
|
20740
|
+
const factory = this.options.playwrightFactory ?? (async () => await import("playwright"));
|
|
20741
|
+
for (let attempt = 1; attempt <= 3 && this.running; attempt++) {
|
|
20742
|
+
await Promise.allSettled([
|
|
20743
|
+
this.page?.close(),
|
|
20744
|
+
this.context?.close(),
|
|
20745
|
+
this.browser?.close()
|
|
20746
|
+
]);
|
|
20747
|
+
this.page = null;
|
|
20748
|
+
this.context = null;
|
|
20749
|
+
this.browser = null;
|
|
20750
|
+
if (!this.running) break;
|
|
20751
|
+
try {
|
|
20752
|
+
const playwright = await factory();
|
|
20753
|
+
this.browser = await playwright.chromium.launch({ headless: true });
|
|
20754
|
+
await this.openPage();
|
|
20755
|
+
await this.page.screenshot({ type: "png" });
|
|
20756
|
+
this.tracker.reset();
|
|
20757
|
+
this.logger.info({ attempt }, "browser renderer recovered");
|
|
20758
|
+
return;
|
|
20759
|
+
} catch (err) {
|
|
20760
|
+
this.logger.warn({
|
|
20761
|
+
err,
|
|
20762
|
+
attempt
|
|
20763
|
+
}, "browser renderer recovery failed");
|
|
20764
|
+
}
|
|
20765
|
+
}
|
|
20766
|
+
if (this.running) {
|
|
20767
|
+
this.cadence.stop();
|
|
20768
|
+
runtimeHealth.setRenderer("failed");
|
|
20769
|
+
await this.options.onFatalCrash?.();
|
|
20770
|
+
}
|
|
20771
|
+
}
|
|
20285
20772
|
async tick(source) {
|
|
20286
|
-
if (!this.page) return;
|
|
20773
|
+
if (!this.page || this.recovering) return;
|
|
20287
20774
|
try {
|
|
20288
20775
|
const png = await this.page.screenshot({ type: "png" });
|
|
20289
20776
|
const { columns, rows } = gridForKeyCount(this.options.device.getKeyCount());
|
|
@@ -20317,11 +20804,18 @@ var BrowserRenderer = class BrowserRenderer {
|
|
|
20317
20804
|
source
|
|
20318
20805
|
}, "frontend appears blank — React tree may have crashed (check the browser console or HMR errors)");
|
|
20319
20806
|
}
|
|
20807
|
+
runtimeHealth.setRenderer("healthy", Date.now());
|
|
20320
20808
|
} catch (err) {
|
|
20321
20809
|
this.logger.warn({
|
|
20322
20810
|
err,
|
|
20323
20811
|
source
|
|
20324
20812
|
}, "renderer tick failed");
|
|
20813
|
+
if (/target crashed|target page, context or browser has been closed/i.test(err.message)) {
|
|
20814
|
+
this.recovering ??= this.recover().finally(() => {
|
|
20815
|
+
this.recovering = null;
|
|
20816
|
+
});
|
|
20817
|
+
await this.recovering;
|
|
20818
|
+
}
|
|
20325
20819
|
}
|
|
20326
20820
|
}
|
|
20327
20821
|
};
|
|
@@ -20689,10 +21183,23 @@ var RealOutputClient = class {
|
|
|
20689
21183
|
logger
|
|
20690
21184
|
});
|
|
20691
21185
|
logger.info({ frontendUrl }, "real mode: frontend URL");
|
|
21186
|
+
let rendererFailed = false;
|
|
20692
21187
|
renderer = new BrowserRenderer({
|
|
20693
21188
|
frontendUrl: `${frontendUrl}${frontendUrl.includes("?") ? "&" : "?"}compact=1`,
|
|
20694
21189
|
device,
|
|
20695
21190
|
logger,
|
|
21191
|
+
onFatalCrash: async () => {
|
|
21192
|
+
rendererFailed = true;
|
|
21193
|
+
try {
|
|
21194
|
+
const svg = Buffer.from("<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"72\" height=\"72\"><rect width=\"72\" height=\"72\" fill=\"#7f1d1d\"/><text x=\"36\" y=\"28\" fill=\"white\" text-anchor=\"middle\" font-family=\"sans-serif\" font-weight=\"bold\" font-size=\"12\">RENDER</text><text x=\"36\" y=\"47\" fill=\"white\" text-anchor=\"middle\" font-family=\"sans-serif\" font-weight=\"bold\" font-size=\"12\">ERROR</text></svg>");
|
|
21195
|
+
const pixels = await sharp(svg).removeAlpha().raw().toBuffer();
|
|
21196
|
+
for (let i = 0; i < device.getKeyCount(); i++) await device.fillKeyBuffer(i, pixels);
|
|
21197
|
+
} catch (err) {
|
|
21198
|
+
logger.error({ err }, "failed to display renderer error");
|
|
21199
|
+
} finally {
|
|
21200
|
+
opts.onChildCrash?.();
|
|
21201
|
+
}
|
|
21202
|
+
},
|
|
20696
21203
|
...opts.intervalMs !== void 0 ? { intervalMs: opts.intervalMs } : {},
|
|
20697
21204
|
pubSub: opts.pubSub
|
|
20698
21205
|
});
|
|
@@ -20718,7 +21225,7 @@ var RealOutputClient = class {
|
|
|
20718
21225
|
wsUrl: opts.bridge.url,
|
|
20719
21226
|
childPids,
|
|
20720
21227
|
async pushBlackFrame() {
|
|
20721
|
-
await pushBlackFrame(device, logger);
|
|
21228
|
+
if (!rendererFailed) await pushBlackFrame(device, logger);
|
|
20722
21229
|
},
|
|
20723
21230
|
async pushRawImage(filePath) {
|
|
20724
21231
|
try {
|
|
@@ -21067,14 +21574,17 @@ const collectAddonDefaultButtonConfig = (registry, userDecks, logger) => {
|
|
|
21067
21574
|
for (const addon of registry.listAddons()) {
|
|
21068
21575
|
if (addon.defaultButton === void 0) continue;
|
|
21069
21576
|
let matchCount = 0;
|
|
21070
|
-
for (const deck of userDecks)
|
|
21071
|
-
if (
|
|
21072
|
-
|
|
21073
|
-
|
|
21074
|
-
|
|
21075
|
-
|
|
21076
|
-
|
|
21077
|
-
|
|
21577
|
+
for (const deck of userDecks) {
|
|
21578
|
+
if (deck.addonOwner !== void 0) continue;
|
|
21579
|
+
for (const btn of deck.buttons) if (btn.type === addon.defaultButton || btn.type === addon.name) {
|
|
21580
|
+
if (matchCount > 0) logger.warn({
|
|
21581
|
+
addon: addon.name,
|
|
21582
|
+
defaultButton: addon.defaultButton,
|
|
21583
|
+
deckId: deck.id
|
|
21584
|
+
}, "collectAddonDefaultButtonConfig: multiple launcher buttons found, using first");
|
|
21585
|
+
if (matchCount === 0) result.set(addon.name, btn.config ?? {});
|
|
21586
|
+
matchCount++;
|
|
21587
|
+
}
|
|
21078
21588
|
}
|
|
21079
21589
|
}
|
|
21080
21590
|
return result;
|
|
@@ -21259,7 +21769,7 @@ const collectActiveDeckAddonNames = (deck, addonByType) => {
|
|
|
21259
21769
|
return [...addonNames];
|
|
21260
21770
|
};
|
|
21261
21771
|
const setupAddonServices = (options) => {
|
|
21262
|
-
const { runtime, decks, pubSub, scanned, externalAddons, addonByType, executor, statePublisher, bridge, initialDeck, signal, store, methods, logger, requestDeckRebuild } = options;
|
|
21772
|
+
const { runtime, decks, pubSub, scanned, externalAddons, addonByType, executor, statePublisher, bridge, initialDeck, signal, store, methods, logger, requestDeckRebuild, addonServiceConfigs } = options;
|
|
21263
21773
|
const addonBridge = bridgeAddonServices({
|
|
21264
21774
|
runtime,
|
|
21265
21775
|
decks,
|
|
@@ -21273,6 +21783,7 @@ const setupAddonServices = (options) => {
|
|
|
21273
21783
|
bridge,
|
|
21274
21784
|
store,
|
|
21275
21785
|
methods,
|
|
21786
|
+
...addonServiceConfigs !== void 0 ? { addonServiceConfigs } : {},
|
|
21276
21787
|
...requestDeckRebuild !== void 0 ? { requestDeckRebuild } : {}
|
|
21277
21788
|
});
|
|
21278
21789
|
const unsubscribeDeck = pubSub.subscribe("runtime:activeDeck", (payload) => {
|
|
@@ -21355,7 +21866,7 @@ const loadExternalAddonsIntoRegistry = async (registry, config, configDir, homeD
|
|
|
21355
21866
|
if (missing.length > 0 && process.stdin.isTTY) {
|
|
21356
21867
|
for (const source of missing) {
|
|
21357
21868
|
const entry = entries.find((candidate) => (typeof candidate === "string" ? candidate : candidate.src) === source);
|
|
21358
|
-
if (await confirm({
|
|
21869
|
+
if (await confirm$1({
|
|
21359
21870
|
message: `Addon '${source}' is not installed. Install it now?`,
|
|
21360
21871
|
initialValue: true
|
|
21361
21872
|
})) await installPackage({
|
|
@@ -21439,7 +21950,7 @@ const validateAndLoadConfig = async (options) => {
|
|
|
21439
21950
|
} catch (error) {
|
|
21440
21951
|
const source = config.theme === void 0 ? null : typeof config.theme === "string" ? config.theme : config.theme.src;
|
|
21441
21952
|
if (source === null || !isNpmAddonSpec(source) || !process.stdin.isTTY) throw error;
|
|
21442
|
-
if (!await confirm({
|
|
21953
|
+
if (!await confirm$1({
|
|
21443
21954
|
message: `Theme '${source}' is not installed. Install it now?`,
|
|
21444
21955
|
initialValue: true
|
|
21445
21956
|
})) throw error;
|
|
@@ -21485,7 +21996,7 @@ const buildAddonConfigOverrides = (addonEntries, addonSpecToName, logger) => {
|
|
|
21485
21996
|
if (src === null) continue;
|
|
21486
21997
|
const cfg = typeof entry === "object" && entry !== null ? entry.config : void 0;
|
|
21487
21998
|
if (typeof cfg !== "object" || cfg === null) continue;
|
|
21488
|
-
const { decks: perDeckRaw, defaults, ...rest } = cfg;
|
|
21999
|
+
const { decks: perDeckRaw, defaults, service: _service, ...rest } = cfg;
|
|
21489
22000
|
const addonName = addonSpecToName.get(src);
|
|
21490
22001
|
if (addonName === void 0) {
|
|
21491
22002
|
logger.warn({ src }, "addon config override targets an addon that failed to load; ignoring");
|
|
@@ -21499,6 +22010,15 @@ const buildAddonConfigOverrides = (addonEntries, addonSpecToName, logger) => {
|
|
|
21499
22010
|
}
|
|
21500
22011
|
return overrides;
|
|
21501
22012
|
};
|
|
22013
|
+
const buildAddonServiceConfigs = (addonEntries, addonSpecToName) => {
|
|
22014
|
+
const configs = /* @__PURE__ */ new Map();
|
|
22015
|
+
for (const entry of addonEntries) {
|
|
22016
|
+
if (typeof entry === "string" || entry.enabled === false) continue;
|
|
22017
|
+
const name = addonSpecToName.get(entry.src);
|
|
22018
|
+
if (name !== void 0 && entry.config?.service !== void 0) configs.set(name, entry.config.service);
|
|
22019
|
+
}
|
|
22020
|
+
return configs;
|
|
22021
|
+
};
|
|
21502
22022
|
const buildRuntime = (options, loaded, keyCount, lockActive = false) => {
|
|
21503
22023
|
const { logger } = options;
|
|
21504
22024
|
const { config, registry, theme, themeDir } = loaded;
|
|
@@ -21587,14 +22107,14 @@ const buildRuntime = (options, loaded, keyCount, lockActive = false) => {
|
|
|
21587
22107
|
buttons: []
|
|
21588
22108
|
}];
|
|
21589
22109
|
const materializedDecks = materializeAddonDecks(registry, effectiveDecks, logger, keyCount, config.lock?.buttons, addonConfigOverrides);
|
|
21590
|
-
const sourceDecks =
|
|
22110
|
+
const sourceDecks = buildAddonSettingsDecks(materializedDecks, registry.listAddons(), keyCount);
|
|
21591
22111
|
const allDecsWithSystemButtons = injectSystemButtons(sourceDecks, keyCount, { lockActive });
|
|
21592
22112
|
const { decks: allDecks, errorsByDeck } = applyConfigErrorReplacements(allDecsWithSystemButtons, config, registry, logger);
|
|
21593
22113
|
const token = process.env["SIRENO_TOKEN"] ?? "";
|
|
21594
22114
|
const configUiUrl = new URL(options.configUiUrl ?? `http://127.0.0.1:${DEFAULT_CONFIG_UI_PORT}/`);
|
|
21595
22115
|
if (token.length > 0) configUiUrl.searchParams.set("token", token);
|
|
21596
22116
|
configUiUrl.hash = "/config";
|
|
21597
|
-
const runtimeDecks = injectConfigUiButton(allDecks, configUiUrl.toString());
|
|
22117
|
+
const runtimeDecks = injectConfigUiButton(allDecks, configUiUrl.toString(), keyCount);
|
|
21598
22118
|
const { runtime, methods, pubSub, store } = createDeckRuntime({
|
|
21599
22119
|
decks: runtimeDecks,
|
|
21600
22120
|
logger
|
|
@@ -21638,7 +22158,7 @@ const applyConfigErrorReplacements = (decks, config, registry, logger) => {
|
|
|
21638
22158
|
if (position === void 0) continue;
|
|
21639
22159
|
if (btn.type.startsWith("core:")) continue;
|
|
21640
22160
|
const path = `decks.${deck.id}.buttons[@position:${position}]`;
|
|
21641
|
-
const { issues, schemaIssues } = validateButton(btn, registry, path, deck.id, position);
|
|
22161
|
+
const { issues, schemaIssues } = validateButton(btn, registry, path, deck.id, position, deck.addonOwner !== void 0 && btn.type.startsWith(`${deck.addonOwner.addonName}:`));
|
|
21642
22162
|
if (issues.length === 0) continue;
|
|
21643
22163
|
const details = schemaIssues.map((i) => `${[...i.path].join(".") || "(root)"}: ${i.message}`).join("; ") || issues.map((i) => i.message).join("; ");
|
|
21644
22164
|
logger.warn({
|
|
@@ -21762,15 +22282,15 @@ const startSystemProviders = async (options, methods) => {
|
|
|
21762
22282
|
url
|
|
21763
22283
|
};
|
|
21764
22284
|
};
|
|
21765
|
-
const browserFrontendMain = (entry) => {
|
|
22285
|
+
const browserFrontendMain = (entry, dedicated = false) => {
|
|
21766
22286
|
const dir = dirname(entry);
|
|
21767
22287
|
const pkgRoot = basename(dir) === "dist" ? dirname(dir) : dir;
|
|
21768
|
-
const src = resolve(pkgRoot, "src", "index.ts");
|
|
22288
|
+
const src = resolve(pkgRoot, "src", dedicated ? "frontend-entry.ts" : "index.ts");
|
|
21769
22289
|
return existsSync(src) ? src : entry;
|
|
21770
22290
|
};
|
|
21771
22291
|
const addonSpecFromScanned = (s) => ({
|
|
21772
22292
|
name: s.name,
|
|
21773
|
-
frontend: s.browserEntry != null ? { main: browserFrontendMain(s.browserEntry) } : s.frontendEntry !== null ? { main: browserFrontendMain(s.frontendEntry) } : void 0,
|
|
22293
|
+
frontend: s.browserEntry != null ? { main: browserFrontendMain(s.browserEntry, s.browserEntry !== s.frontendEntry) } : s.frontendEntry !== null ? { main: browserFrontendMain(s.frontendEntry) } : void 0,
|
|
21774
22294
|
buttons: s.types.map((t) => ({ type: t })),
|
|
21775
22295
|
buttonTypes: Object.fromEntries(Object.entries(s.buttonTypes).map(([type, info]) => [type, info.exportName])),
|
|
21776
22296
|
defaultButton: s.defaultButton
|
|
@@ -22028,7 +22548,8 @@ const runPipeline = async (options) => {
|
|
|
22028
22548
|
});
|
|
22029
22549
|
const externalAddonDirs = buildExternalAddonDirs(loadedConfig.config.addons ?? [], loadedConfig.configPath, loadedConfig.addonEntryPaths);
|
|
22030
22550
|
let resolverOptions = buildResolverOptions(addonBundle.addonByType, [dirname(loadedConfig.configPath)], externalAddonDirs);
|
|
22031
|
-
|
|
22551
|
+
let currentLoadedConfig = loadedConfig;
|
|
22552
|
+
const reInjectedDecks = (isLocked) => buildRuntime(options, currentLoadedConfig, descriptor.keyCount, isLocked).decks;
|
|
22032
22553
|
if (providers.session.getState() === "locked") {
|
|
22033
22554
|
const reInjected = reInjectedDecks(true);
|
|
22034
22555
|
runtime.setDecks(reInjected);
|
|
@@ -22087,11 +22608,10 @@ const runPipeline = async (options) => {
|
|
|
22087
22608
|
presentation?.refresh({ force: true });
|
|
22088
22609
|
});
|
|
22089
22610
|
const serviceDecks = [...decks];
|
|
22090
|
-
let currentLoadedConfig = loadedConfig;
|
|
22091
22611
|
const nextMainDeckId = (config) => config.decks["main"] !== void 0 ? "main" : Object.keys(config.decks)[0] ?? "main";
|
|
22092
22612
|
const requestDeckRebuild = async () => {
|
|
22093
22613
|
if (runtime === null || descriptor === null || outputClient === null || bridge === null || addonBundle === null || loadedConfig === null || providers === null) return;
|
|
22094
|
-
const rebuilt = buildRuntime(options,
|
|
22614
|
+
const rebuilt = buildRuntime(options, currentLoadedConfig, descriptor.keyCount, providers.session.getState() === "locked").decks;
|
|
22095
22615
|
await addonServices?.reconcile(rebuilt);
|
|
22096
22616
|
decks = rebuilt;
|
|
22097
22617
|
serviceDecks.splice(0, serviceDecks.length, ...rebuilt);
|
|
@@ -22126,6 +22646,7 @@ const runPipeline = async (options) => {
|
|
|
22126
22646
|
keyCount: descriptor.keyCount,
|
|
22127
22647
|
resolverOptions,
|
|
22128
22648
|
requestDeckRebuild,
|
|
22649
|
+
addonServiceConfigs: buildAddonServiceConfigs(loadedConfig.config.addons ?? [], loadedConfig.addonSpecToName),
|
|
22129
22650
|
...mainDeck !== void 0 ? { initialDeck: mainDeck } : {},
|
|
22130
22651
|
signal: bridgeSignal.signal,
|
|
22131
22652
|
store,
|
|
@@ -22187,6 +22708,8 @@ const runPipeline = async (options) => {
|
|
|
22187
22708
|
lanAddresses: lanAddresses.map((a) => a.address)
|
|
22188
22709
|
});
|
|
22189
22710
|
currentOutputHandle = outputHandle;
|
|
22711
|
+
runtimeHealth.setCore("ready");
|
|
22712
|
+
if (options.emulator === true) runtimeHealth.setRenderer("not-applicable");
|
|
22190
22713
|
let refreshQueue = Promise.resolve();
|
|
22191
22714
|
editorMutationService = createConfigMutationService({ configPath: loadedConfig.configPath });
|
|
22192
22715
|
const refreshConfig = async (notifyEditor = true) => {
|
|
@@ -22285,6 +22808,7 @@ const runPipeline = async (options) => {
|
|
|
22285
22808
|
});
|
|
22286
22809
|
await done;
|
|
22287
22810
|
} finally {
|
|
22811
|
+
runtimeHealth.setCore("stopping");
|
|
22288
22812
|
unsubscribeBrightnessSettings?.();
|
|
22289
22813
|
settingsStore?.close();
|
|
22290
22814
|
if (unregisterSignal !== null) unregisterSignal();
|
|
@@ -23481,11 +24005,11 @@ const enableClaudeHooks = () => {
|
|
|
23481
24005
|
const onboardClaudeCode = async (options) => {
|
|
23482
24006
|
if (isClaudeHookInstalled() && isClaudeHookEnabled()) return false;
|
|
23483
24007
|
note("The coding-agents addon can show each Claude Code session and its live state.\n\nSireno Deck will add hooks to your Claude Code settings. They report only local session state (id, directory, status) to files owned by your user; no prompts or code are captured. Existing hooks are left untouched.", "Claude Code integration");
|
|
23484
|
-
const answer = options.yes === true ? true : await confirm({
|
|
24008
|
+
const answer = options.yes === true ? true : await confirm$1({
|
|
23485
24009
|
message: "Add the Claude Code session-state hooks now?",
|
|
23486
24010
|
initialValue: true
|
|
23487
24011
|
});
|
|
23488
|
-
if (isCancel(answer) || !answer) return false;
|
|
24012
|
+
if (isCancel$1(answer) || !answer) return false;
|
|
23489
24013
|
installClaudeHook();
|
|
23490
24014
|
if (!enableClaudeHooks()) {
|
|
23491
24015
|
note(`Could not update ${claudeSettingsPath()} because it is not valid JSON. Nothing was changed.`, "Claude Code integration");
|
|
@@ -23504,11 +24028,11 @@ const onboardCodingAgents = async (configPath, options = {}) => {
|
|
|
23504
24028
|
let changed = false;
|
|
23505
24029
|
if (!openCodeDone) {
|
|
23506
24030
|
note("The coding-agents addon can show each OpenCode terminal instance and its live state.\n\nSireno Deck will install a global OpenCode plugin. It reports only local process state to files owned by your user; no prompts or code are captured.", "OpenCode integration");
|
|
23507
|
-
const answer = options.yes === true ? true : await confirm({
|
|
24031
|
+
const answer = options.yes === true ? true : await confirm$1({
|
|
23508
24032
|
message: "Install the OpenCode instance-state plugin now?",
|
|
23509
24033
|
initialValue: true
|
|
23510
24034
|
});
|
|
23511
|
-
if (!isCancel(answer) && answer) {
|
|
24035
|
+
if (!isCancel$1(answer) && answer) {
|
|
23512
24036
|
if (openCodeMajorVersion === null) note("Could not detect a supported OpenCode version. Make sure `opencode --version` works, then run setup again. No plugin files were changed.", "OpenCode integration");
|
|
23513
24037
|
else {
|
|
23514
24038
|
const installedPath = installOpenCodePlugin(openCodeMajorVersion);
|
|
@@ -23633,11 +24157,11 @@ const reProbeCapability = async (step, deps) => {
|
|
|
23633
24157
|
const runDarwinAccessibilityStep = async (yesBatched) => {
|
|
23634
24158
|
if (await hasDarwinAccessibility(realExecutor)) return "installed";
|
|
23635
24159
|
if (!yesBatched) {
|
|
23636
|
-
const shouldOpen = await confirm({
|
|
24160
|
+
const shouldOpen = await confirm$1({
|
|
23637
24161
|
message: "Open System Settings at Privacy & Security → Accessibility?",
|
|
23638
24162
|
initialValue: true
|
|
23639
24163
|
});
|
|
23640
|
-
if (isCancel(shouldOpen) || !shouldOpen) return "manual";
|
|
24164
|
+
if (isCancel$1(shouldOpen) || !shouldOpen) return "manual";
|
|
23641
24165
|
}
|
|
23642
24166
|
if (!await openSettingsUrl(realExecutor, "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility")) {
|
|
23643
24167
|
log$1.warn("Could not open System Settings automatically.");
|
|
@@ -23645,11 +24169,11 @@ const runDarwinAccessibilityStep = async (yesBatched) => {
|
|
|
23645
24169
|
}
|
|
23646
24170
|
log$1.info(`Enable ${color.green(appNeedingAccessibility())} in the list that just opened.`);
|
|
23647
24171
|
if (yesBatched) return "manual";
|
|
23648
|
-
const granted = await confirm({
|
|
24172
|
+
const granted = await confirm$1({
|
|
23649
24173
|
message: "Granted? (re-checks the permission)",
|
|
23650
24174
|
initialValue: true
|
|
23651
24175
|
});
|
|
23652
|
-
if (isCancel(granted) || !granted) return "manual";
|
|
24176
|
+
if (isCancel$1(granted) || !granted) return "manual";
|
|
23653
24177
|
if (await hasDarwinAccessibility(realExecutor)) return "installed";
|
|
23654
24178
|
log$1.warn("Still not granted for this process — macOS applies the grant to the app that launched sirenodeck, so restart your terminal and re-run.");
|
|
23655
24179
|
return "manual";
|
|
@@ -23669,11 +24193,11 @@ const runInstallStep = async (step, yesBatched, logger, deps) => {
|
|
|
23669
24193
|
s.start(`Checking ${step.packages.join(", ")}`);
|
|
23670
24194
|
s.stop(`${step.packages.join(", ")} not found — install needed`);
|
|
23671
24195
|
if (!yesBatched) {
|
|
23672
|
-
const shouldRun = await confirm({
|
|
24196
|
+
const shouldRun = await confirm$1({
|
|
23673
24197
|
message: `Install ${step.title}?`,
|
|
23674
24198
|
initialValue: !step.sudo
|
|
23675
24199
|
});
|
|
23676
|
-
if (isCancel(shouldRun) || !shouldRun) return "skipped";
|
|
24200
|
+
if (isCancel$1(shouldRun) || !shouldRun) return "skipped";
|
|
23677
24201
|
}
|
|
23678
24202
|
let command;
|
|
23679
24203
|
let args;
|
|
@@ -23760,11 +24284,11 @@ const runInstallStep = async (step, yesBatched, logger, deps) => {
|
|
|
23760
24284
|
};
|
|
23761
24285
|
const runUdevStep = async (step, yesBatched, logger) => {
|
|
23762
24286
|
if (!yesBatched) {
|
|
23763
|
-
const shouldRun = await confirm({
|
|
24287
|
+
const shouldRun = await confirm$1({
|
|
23764
24288
|
message: `Install udev rules to ${process.platform === "linux" ? "/etc/udev/rules.d/70-sirenodeck.rules" : "system location"}?`,
|
|
23765
24289
|
initialValue: false
|
|
23766
24290
|
});
|
|
23767
|
-
if (isCancel(shouldRun) || !shouldRun) return "skipped";
|
|
24291
|
+
if (isCancel$1(shouldRun) || !shouldRun) return "skipped";
|
|
23768
24292
|
}
|
|
23769
24293
|
const nopasswd = await isSudoNopasswd();
|
|
23770
24294
|
let password = "";
|
|
@@ -23824,11 +24348,11 @@ const runConfigSeed = async (report, options, logger) => {
|
|
|
23824
24348
|
logger.warn({ path: report.config.path }, "config missing and non-interactive mode — skipping seed");
|
|
23825
24349
|
return false;
|
|
23826
24350
|
}
|
|
23827
|
-
const shouldSeed = await confirm({
|
|
24351
|
+
const shouldSeed = await confirm$1({
|
|
23828
24352
|
message: `Seed default config to ${report.config.path}?`,
|
|
23829
24353
|
initialValue: true
|
|
23830
24354
|
});
|
|
23831
|
-
if (isCancel(shouldSeed) || !shouldSeed) return false;
|
|
24355
|
+
if (isCancel$1(shouldSeed) || !shouldSeed) return false;
|
|
23832
24356
|
const s = spinner();
|
|
23833
24357
|
s.start(`Seeding ${report.config.path}`);
|
|
23834
24358
|
try {
|
|
@@ -24033,11 +24557,11 @@ const installConfigSkill = async (options = {}) => {
|
|
|
24033
24557
|
intro("sirenodeck skills");
|
|
24034
24558
|
note("Install the Sireno Deck config skill for your preferred coding agent. It helps your agent configure and update decks, buttons, and themes from your config.yml. The skill is installed globally from GitHub; it can read and edit your config only with your agent's normal file access.", "Configure decks with your agent");
|
|
24035
24559
|
if (!yes && options.confirmed !== true) {
|
|
24036
|
-
const answer = await confirm({
|
|
24560
|
+
const answer = await confirm$1({
|
|
24037
24561
|
message: "Install the Sireno Deck config skill globally?",
|
|
24038
24562
|
initialValue: false
|
|
24039
24563
|
});
|
|
24040
|
-
if (isCancel(answer) || !answer) {
|
|
24564
|
+
if (isCancel$1(answer) || !answer) {
|
|
24041
24565
|
log$1.info("Skill installation cancelled.");
|
|
24042
24566
|
return false;
|
|
24043
24567
|
}
|
|
@@ -24088,11 +24612,11 @@ const offerPath = () => join(process.env["XDG_CONFIG_HOME"] ?? join(homedir(), "
|
|
|
24088
24612
|
const offerConfigSkillOnFirstRun = async () => {
|
|
24089
24613
|
if (process.stdin.isTTY !== true || existsSync(offerPath())) return;
|
|
24090
24614
|
note("Your coding agent can help configure and update Sireno Deck decks, buttons, and themes. This optional skill is installed from GitHub.", "Sireno Deck agent skill");
|
|
24091
|
-
const answer = await confirm({
|
|
24615
|
+
const answer = await confirm$1({
|
|
24092
24616
|
message: "Install the Sireno Deck skill for your coding agent?",
|
|
24093
24617
|
initialValue: false
|
|
24094
24618
|
});
|
|
24095
|
-
if (isCancel(answer) || !answer) {
|
|
24619
|
+
if (isCancel$1(answer) || !answer) {
|
|
24096
24620
|
saveOfferChoice("declined");
|
|
24097
24621
|
return;
|
|
24098
24622
|
}
|
|
@@ -24374,24 +24898,6 @@ const killPortListeners = async (ports, logger) => {
|
|
|
24374
24898
|
}
|
|
24375
24899
|
await new Promise((r) => setTimeout(r, 500));
|
|
24376
24900
|
};
|
|
24377
|
-
const promptConflict = async (pid) => {
|
|
24378
|
-
const who = pid === null ? "" : ` with pid ${pid}`;
|
|
24379
|
-
if (!process.stdin.isTTY) throw new Error(`Daemon already running${who} (non-interactive: not stopping)`);
|
|
24380
|
-
const answer = await select({
|
|
24381
|
-
message: `Daemon already running${who}.`,
|
|
24382
|
-
options: [{
|
|
24383
|
-
value: "restart",
|
|
24384
|
-
label: "restart",
|
|
24385
|
-
hint: "Stop the existing daemon and start a new one"
|
|
24386
|
-
}, {
|
|
24387
|
-
value: "cancel",
|
|
24388
|
-
label: "cancel",
|
|
24389
|
-
hint: "Exit without changes"
|
|
24390
|
-
}]
|
|
24391
|
-
});
|
|
24392
|
-
if (isCancel(answer)) return "cancel";
|
|
24393
|
-
return answer;
|
|
24394
|
-
};
|
|
24395
24901
|
const stopExisting = async (pid, logger) => {
|
|
24396
24902
|
if (!isRunning(pid)) {
|
|
24397
24903
|
logger.warn({ pid }, "existing pid file is stale, removing");
|
|
@@ -24404,28 +24910,16 @@ const stopExisting = async (pid, logger) => {
|
|
|
24404
24910
|
removeStartLock();
|
|
24405
24911
|
return;
|
|
24406
24912
|
}
|
|
24913
|
+
if (!isOurDaemon(pid)) throw new Error(`Refusing to stop unverified daemon PID ${pid}`);
|
|
24407
24914
|
logger.info({ pid }, "stopping existing daemon");
|
|
24408
24915
|
try {
|
|
24409
24916
|
process.kill(pid, "SIGTERM");
|
|
24410
24917
|
} catch (err) {
|
|
24411
|
-
|
|
24412
|
-
err,
|
|
24413
|
-
pid
|
|
24414
|
-
}, "failed to send SIGTERM to existing daemon");
|
|
24918
|
+
throw new Error(`Failed to stop existing daemon ${pid}`, { cause: err });
|
|
24415
24919
|
}
|
|
24416
|
-
const deadline = Date.now() +
|
|
24920
|
+
const deadline = Date.now() + 2e4;
|
|
24417
24921
|
while (Date.now() < deadline && isRunning(pid)) await new Promise((r) => setTimeout(r, 100));
|
|
24418
|
-
if (isRunning(pid)) {
|
|
24419
|
-
logger.warn({ pid }, "existing daemon did not exit in 5s, sending SIGKILL");
|
|
24420
|
-
try {
|
|
24421
|
-
process.kill(pid, "SIGKILL");
|
|
24422
|
-
} catch (err) {
|
|
24423
|
-
logger.warn({
|
|
24424
|
-
err,
|
|
24425
|
-
pid
|
|
24426
|
-
}, "failed to send SIGKILL to existing daemon");
|
|
24427
|
-
}
|
|
24428
|
-
}
|
|
24922
|
+
if (isRunning(pid)) throw new Error(`Existing daemon ${pid} did not exit after SIGTERM`);
|
|
24429
24923
|
await terminateChildren({
|
|
24430
24924
|
logger,
|
|
24431
24925
|
timeoutMs: 2e3
|
|
@@ -24719,7 +25213,7 @@ const runFirstRunCheckIfNeeded = async (options, logger) => {
|
|
|
24719
25213
|
process.exitCode = 1;
|
|
24720
25214
|
return false;
|
|
24721
25215
|
}
|
|
24722
|
-
if (!await confirm({
|
|
25216
|
+
if (!await confirm$1({
|
|
24723
25217
|
message: "It looks like this is your first run (missing config or system capabilities). Run the setup wizard now?",
|
|
24724
25218
|
initialValue: true
|
|
24725
25219
|
})) {
|
|
@@ -24754,36 +25248,17 @@ const start = async (options) => {
|
|
|
24754
25248
|
logger.warn({ err: error }, "start: agent skill offer failed, continuing");
|
|
24755
25249
|
}
|
|
24756
25250
|
await onboardCodingAgents(resolveConfigPath(options).path);
|
|
25251
|
+
if (isUnitInstalled()) await invokeManager({
|
|
25252
|
+
action: "stop",
|
|
25253
|
+
logger
|
|
25254
|
+
});
|
|
24757
25255
|
const existing = readPid();
|
|
24758
|
-
|
|
24759
|
-
|
|
24760
|
-
|
|
24761
|
-
return "cancelled";
|
|
24762
|
-
}
|
|
24763
|
-
if (isUnitInstalled()) {
|
|
24764
|
-
const resolvedRestart = resolveConfigPath(options);
|
|
24765
|
-
writeConfigPath(resolvedRestart.path);
|
|
24766
|
-
writeFlags(buildRuntimeFlags(options));
|
|
24767
|
-
logger.info({ configPath: resolvedRestart.path }, "start: daemon is service-managed — restarting through the service manager");
|
|
24768
|
-
await invokeManager({
|
|
24769
|
-
action: "restart",
|
|
24770
|
-
logger
|
|
24771
|
-
});
|
|
24772
|
-
const deadline = Date.now() + 1e4;
|
|
24773
|
-
let restarted = null;
|
|
24774
|
-
while (Date.now() < deadline) {
|
|
24775
|
-
await new Promise((r) => setTimeout(r, 200));
|
|
24776
|
-
const pid = readPid();
|
|
24777
|
-
if (pid !== null && pid !== existing && isRunning(pid)) {
|
|
24778
|
-
restarted = pid;
|
|
24779
|
-
break;
|
|
24780
|
-
}
|
|
24781
|
-
}
|
|
24782
|
-
logger.info({ pid: restarted }, restarted === null ? "start: service manager restarted the daemon (pid not yet visible)" : "start: daemon restarted by the service manager");
|
|
24783
|
-
return "started";
|
|
24784
|
-
}
|
|
25256
|
+
const lockHeld = await isSocketLive(instanceLockPath(resolveDaemonPaths()));
|
|
25257
|
+
if (lockHeld || existing !== null && isRunning(existing)) {
|
|
25258
|
+
if (lockHeld && (existing === null || !isRunning(existing))) throw new Error("A daemon holds the instance lock but has no live PID; refusing to stop an unidentified process");
|
|
24785
25259
|
if (existing !== null) await stopExisting(existing, logger);
|
|
24786
|
-
else
|
|
25260
|
+
else throw new Error("A daemon holds the instance lock but has no PID; refusing to stop an unidentified process");
|
|
25261
|
+
if (await isSocketLive(instanceLockPath(resolveDaemonPaths()))) throw new Error("The previous daemon still holds the instance lock");
|
|
24787
25262
|
removePidFile();
|
|
24788
25263
|
removeDaemonControl(resolveDaemonPaths());
|
|
24789
25264
|
removeRuntimeStateFile();
|
|
@@ -25118,6 +25593,10 @@ const killGracefully = async (pid, logger, label) => {
|
|
|
25118
25593
|
}
|
|
25119
25594
|
};
|
|
25120
25595
|
const stop = async ({ logger }) => {
|
|
25596
|
+
if (isUnitInstalled()) await invokeManager({
|
|
25597
|
+
action: "stop",
|
|
25598
|
+
logger
|
|
25599
|
+
});
|
|
25121
25600
|
const pid = readPid();
|
|
25122
25601
|
if (pid === null) {
|
|
25123
25602
|
logger.info("stop: no running daemon found");
|
|
@@ -25229,6 +25708,96 @@ const restart = async (options) => {
|
|
|
25229
25708
|
};
|
|
25230
25709
|
const isDevInvocation = () => (process.argv[1] ?? "").endsWith(".ts");
|
|
25231
25710
|
//#endregion
|
|
25711
|
+
//#region src/cli/commands/status-probes.ts
|
|
25712
|
+
const parseIdentity = (value) => {
|
|
25713
|
+
if (!value || typeof value !== "object") return null;
|
|
25714
|
+
const v = value;
|
|
25715
|
+
if (typeof v.version !== "string" || !(typeof v.buildId === "string" || v.buildId === null)) return null;
|
|
25716
|
+
return {
|
|
25717
|
+
version: v.version,
|
|
25718
|
+
buildId: v.buildId
|
|
25719
|
+
};
|
|
25720
|
+
};
|
|
25721
|
+
const probeWebIdentity = async (value, component) => {
|
|
25722
|
+
const base = localUrl(value, ["http:", "https:"]);
|
|
25723
|
+
if (!base) return null;
|
|
25724
|
+
try {
|
|
25725
|
+
const response = await fetch(new URL("/assets/sirenodeck-build.json", base), {
|
|
25726
|
+
signal: AbortSignal.timeout(1500),
|
|
25727
|
+
redirect: "manual"
|
|
25728
|
+
});
|
|
25729
|
+
if (!response.ok || !response.headers.get("content-type")?.includes("application/json")) return null;
|
|
25730
|
+
const body = await response.json();
|
|
25731
|
+
if (!body || typeof body !== "object" || !("component" in body) || body.component !== component) return null;
|
|
25732
|
+
return parseIdentity(body);
|
|
25733
|
+
} catch {
|
|
25734
|
+
return null;
|
|
25735
|
+
}
|
|
25736
|
+
};
|
|
25737
|
+
const localUrl = (value, protocols) => {
|
|
25738
|
+
try {
|
|
25739
|
+
const url = new URL(value);
|
|
25740
|
+
if (!protocols.includes(url.protocol)) return null;
|
|
25741
|
+
if (![
|
|
25742
|
+
"localhost",
|
|
25743
|
+
"127.0.0.1",
|
|
25744
|
+
"[::1]"
|
|
25745
|
+
].includes(url.hostname)) return null;
|
|
25746
|
+
return url;
|
|
25747
|
+
} catch {
|
|
25748
|
+
return null;
|
|
25749
|
+
}
|
|
25750
|
+
};
|
|
25751
|
+
const probeHttp = async (value) => {
|
|
25752
|
+
const url = localUrl(value, ["http:", "https:"]);
|
|
25753
|
+
if (!url) return "unknown";
|
|
25754
|
+
try {
|
|
25755
|
+
return (await fetch(url, {
|
|
25756
|
+
signal: AbortSignal.timeout(1500),
|
|
25757
|
+
redirect: "manual"
|
|
25758
|
+
})).ok ? "responding" : "unreachable";
|
|
25759
|
+
} catch {
|
|
25760
|
+
return "unreachable";
|
|
25761
|
+
}
|
|
25762
|
+
};
|
|
25763
|
+
const probeBridgeInfo = (value, token) => {
|
|
25764
|
+
const url = localUrl(value, ["ws:", "wss:"]);
|
|
25765
|
+
if (!url || token === null) return Promise.resolve({
|
|
25766
|
+
status: "unknown",
|
|
25767
|
+
identity: null
|
|
25768
|
+
});
|
|
25769
|
+
return new Promise((resolve) => {
|
|
25770
|
+
const socket = new WebSocket(url);
|
|
25771
|
+
const timer = setTimeout(() => finish("unreachable"), 1500);
|
|
25772
|
+
let finished = false;
|
|
25773
|
+
const finish = (result, identity = null) => {
|
|
25774
|
+
if (finished) return;
|
|
25775
|
+
finished = true;
|
|
25776
|
+
clearTimeout(timer);
|
|
25777
|
+
socket.terminate();
|
|
25778
|
+
resolve({
|
|
25779
|
+
status: result,
|
|
25780
|
+
identity
|
|
25781
|
+
});
|
|
25782
|
+
};
|
|
25783
|
+
socket.on("open", () => socket.send(JSON.stringify({
|
|
25784
|
+
type: "hello",
|
|
25785
|
+
version: 1,
|
|
25786
|
+
token
|
|
25787
|
+
})));
|
|
25788
|
+
socket.on("message", (data) => {
|
|
25789
|
+
try {
|
|
25790
|
+
const message = JSON.parse(data.toString());
|
|
25791
|
+
if (message.type === "hello-ack") finish(message.version === 1 ? "responding" : "unreachable", parseIdentity(message.build));
|
|
25792
|
+
} catch {
|
|
25793
|
+
finish("unreachable");
|
|
25794
|
+
}
|
|
25795
|
+
});
|
|
25796
|
+
socket.on("error", () => finish("unreachable"));
|
|
25797
|
+
socket.on("close", () => finish("unreachable"));
|
|
25798
|
+
});
|
|
25799
|
+
};
|
|
25800
|
+
//#endregion
|
|
25232
25801
|
//#region src/cli/commands/status.ts
|
|
25233
25802
|
const formatUptime = (ms) => {
|
|
25234
25803
|
if (ms < 0) return "—";
|
|
@@ -25240,12 +25809,32 @@ const formatUptime = (ms) => {
|
|
|
25240
25809
|
if (minutes > 0) return `${minutes}m ${seconds}s`;
|
|
25241
25810
|
return `${seconds}s`;
|
|
25242
25811
|
};
|
|
25812
|
+
const group = (title, details) => [title, ...details.map((detail, i) => {
|
|
25813
|
+
const separator = detail.indexOf(": ");
|
|
25814
|
+
const formatted = separator < 0 ? detail : `${detail.slice(0, separator + 2)}${colorize(detail.slice(separator + 2), 97)}`;
|
|
25815
|
+
return `${i === details.length - 1 ? "└─" : "├─"} ${formatted}`;
|
|
25816
|
+
})].join("\n");
|
|
25817
|
+
const colorize = (value, color) => {
|
|
25818
|
+
return process.env.NO_COLOR === void 0 && process.env.FORCE_COLOR !== "0" && (process.stdout.isTTY || process.env.FORCE_COLOR !== void 0 && process.env.FORCE_COLOR !== "") ? `\u001b[${color}m${value.replaceAll("\x1B[39m", `\u001b[${color}m`)}\u001b[39m` : value;
|
|
25819
|
+
};
|
|
25820
|
+
const coloredStatus = (value) => {
|
|
25821
|
+
const color = /^(running|ready|healthy|responding|same source)/i.test(value) ? 32 : /^(failed|unreachable|MISMATCH|stale)/i.test(value) ? 31 : 33;
|
|
25822
|
+
return colorize(value, color);
|
|
25823
|
+
};
|
|
25243
25824
|
const status = async ({ logger }) => {
|
|
25244
25825
|
const paths = resolveDaemonPaths();
|
|
25245
25826
|
const pid = readPid(paths);
|
|
25246
25827
|
if (pid === null) {
|
|
25247
25828
|
intro("sirenodeck status");
|
|
25248
25829
|
log$1.error("Daemon is not running");
|
|
25830
|
+
for (const component of [
|
|
25831
|
+
"Core",
|
|
25832
|
+
"Bridge",
|
|
25833
|
+
"Frontend",
|
|
25834
|
+
"Config UI",
|
|
25835
|
+
"Renderer",
|
|
25836
|
+
"Device"
|
|
25837
|
+
]) log$1.info(`${component}: unknown (daemon not running)`);
|
|
25249
25838
|
cancel("✗ No daemon process found");
|
|
25250
25839
|
return;
|
|
25251
25840
|
}
|
|
@@ -25255,36 +25844,87 @@ const status = async ({ logger }) => {
|
|
|
25255
25844
|
const childPids = readChildren(paths)?.pids ?? [];
|
|
25256
25845
|
const configPath = readConfigPath(paths);
|
|
25257
25846
|
intro("sirenodeck status");
|
|
25847
|
+
let daemonDetails = [];
|
|
25258
25848
|
if (alive) {
|
|
25259
25849
|
const startedAt = state?.startedAt ?? null;
|
|
25260
25850
|
const uptime = startedAt !== null ? formatUptime(Date.now() - startedAt) : "—";
|
|
25261
|
-
|
|
25851
|
+
daemonDetails = [
|
|
25852
|
+
`PID: ${pid}`,
|
|
25853
|
+
`Uptime: ${uptime}`,
|
|
25854
|
+
`Children: ${childPids.length > 0 ? `${childPids.length} (${childPids.join(", ")})` : "none tracked"}`
|
|
25855
|
+
];
|
|
25262
25856
|
} else log$1.warn(`Status: stale pid file (pid ${pid} not alive)`);
|
|
25263
25857
|
const isEmulator = state?.emulatorMode === true || flags?.emulator === true;
|
|
25264
25858
|
const deviceModel = typeof flags?.deviceModel === "string" ? flags.deviceModel : "mk2";
|
|
25265
|
-
if (isEmulator) log$1.info(
|
|
25859
|
+
if (isEmulator) log$1.info(group("Device", [`Mode: emulator`, `Model: ${deviceModel}`]));
|
|
25266
25860
|
else {
|
|
25267
25861
|
let hardwareLabel = "—";
|
|
25268
25862
|
try {
|
|
25269
25863
|
const devices = await listDevices();
|
|
25270
25864
|
if (devices.length > 0 && devices[0] !== void 0) hardwareLabel = devices[0].label;
|
|
25271
25865
|
} catch {}
|
|
25272
|
-
log$1.info(
|
|
25866
|
+
log$1.info(group("Device", [`Mode: hardware`, `Model: ${hardwareLabel}`]));
|
|
25273
25867
|
}
|
|
25274
25868
|
const remoteOn = state?.remote === true || flags?.remote === true;
|
|
25275
|
-
log$1.info(`Remote: ${remoteOn ? "on" : "off"}`);
|
|
25276
|
-
log$1.info(`Config: ${configPath ?? "—"}`);
|
|
25277
25869
|
const theme = state?.theme ?? "default";
|
|
25278
|
-
log$1.info(
|
|
25279
|
-
|
|
25280
|
-
|
|
25870
|
+
log$1.info(group("Configuration", [
|
|
25871
|
+
`Config: ${configPath ?? "—"}`,
|
|
25872
|
+
`Theme: ${theme}`,
|
|
25873
|
+
`Remote: ${remoteOn ? "on" : "off"}`
|
|
25874
|
+
]));
|
|
25875
|
+
if (!alive && childPids.length > 0) log$1.info(`Children: ${childPids.length} (${childPids.join(", ")})`);
|
|
25876
|
+
else if (!alive) log$1.info("Children: none tracked");
|
|
25281
25877
|
if (alive && state !== null) {
|
|
25282
|
-
const
|
|
25283
|
-
|
|
25284
|
-
|
|
25285
|
-
|
|
25878
|
+
const [token, health, frontend, configUi, frontendIdentity, configUiIdentity] = await Promise.all([
|
|
25879
|
+
requestDaemonToken(paths),
|
|
25880
|
+
requestDaemonHealth(paths),
|
|
25881
|
+
probeHttp(state.frontendUrl),
|
|
25882
|
+
state.configUiUrl ? probeHttp(state.configUiUrl) : Promise.resolve("unknown"),
|
|
25883
|
+
probeWebIdentity(state.frontendUrl, "frontend"),
|
|
25884
|
+
state.configUiUrl ? probeWebIdentity(state.configUiUrl, "config-ui") : Promise.resolve(null)
|
|
25885
|
+
]);
|
|
25886
|
+
const bridge = await probeBridgeInfo(state.wsUrl, token);
|
|
25887
|
+
const identityLabel = (identity) => {
|
|
25888
|
+
if (!identity) return "version/build unknown";
|
|
25889
|
+
const matches = identity.buildId && health?.identity?.buildId ? identity.buildId === health.identity.buildId && identity.version === health.identity.version ? "same source as daemon" : "MISMATCH" : "comparison unknown";
|
|
25890
|
+
return `${identity.version} build ${identity.buildId?.slice(0, 12) ?? "unknown"} (${coloredStatus(matches)})`;
|
|
25891
|
+
};
|
|
25892
|
+
log$1.info(group(`Daemon: ${coloredStatus("running")}`, [...daemonDetails, `Version: ${identityLabel(health?.identity ?? null)}`]));
|
|
25893
|
+
log$1.info(group("CLI", [`Version: ${identityLabel(runtimeIdentity)}`]));
|
|
25894
|
+
log$1.info(group(`Core: ${coloredStatus(health?.core ?? "unknown")}`, [`Version: ${identityLabel(health?.identity ?? null)}`]));
|
|
25895
|
+
log$1.info(group(`Bridge: ${coloredStatus(bridge.status)}`, [
|
|
25896
|
+
`Check: authenticated WebSocket handshake`,
|
|
25897
|
+
`URL: ${state.wsUrl}`,
|
|
25898
|
+
`Version: ${identityLabel(bridge.identity)}`
|
|
25899
|
+
]));
|
|
25900
|
+
log$1.info(group(`Frontend: ${coloredStatus(frontend)}`, [
|
|
25901
|
+
`Check: HTTP`,
|
|
25902
|
+
`URL: ${state.frontendUrl}`,
|
|
25903
|
+
`Version: ${identityLabel(frontendIdentity)}`
|
|
25904
|
+
]));
|
|
25905
|
+
log$1.info(group(`Config UI: ${coloredStatus(configUi)}`, [
|
|
25906
|
+
`Check: HTTP`,
|
|
25907
|
+
...state.configUiUrl ? [`URL: ${state.configUiUrl}`] : [],
|
|
25908
|
+
`Version: ${identityLabel(configUiIdentity)}`
|
|
25909
|
+
]));
|
|
25910
|
+
if (isEmulator) log$1.info("Renderer: not applicable (emulator mode)");
|
|
25911
|
+
else {
|
|
25912
|
+
const rendererState = health?.renderer?.state === "healthy" && health.renderer.lastFrameAt !== null && Date.now() - health.renderer.lastFrameAt > 1e4 ? "degraded (no recent frame)" : health?.renderer?.state ?? "unknown";
|
|
25913
|
+
const lastFrame = health?.renderer?.lastFrameAt ? new Date(health.renderer.lastFrameAt).toISOString() : "unknown";
|
|
25914
|
+
log$1.info(group(`Renderer: ${coloredStatus(rendererState)}`, [`Last frame: ${lastFrame}`, `Version: ${identityLabel(health?.identity ?? null)}`]));
|
|
25915
|
+
}
|
|
25286
25916
|
outro("✓ Status snapshot");
|
|
25287
|
-
} else
|
|
25917
|
+
} else {
|
|
25918
|
+
if (alive) log$1.info(group(`Daemon: ${coloredStatus("running")}`, daemonDetails));
|
|
25919
|
+
for (const component of [
|
|
25920
|
+
"Core",
|
|
25921
|
+
"Bridge",
|
|
25922
|
+
"Frontend",
|
|
25923
|
+
"Config UI",
|
|
25924
|
+
"Renderer"
|
|
25925
|
+
]) log$1.info(`${component}: unknown (runtime state unavailable)`);
|
|
25926
|
+
cancel(alive ? "✗ Daemon is running but runtime state is unavailable" : "✗ Stale pid file — daemon process is not running");
|
|
25927
|
+
}
|
|
25288
25928
|
};
|
|
25289
25929
|
//#endregion
|
|
25290
25930
|
//#region src/outputClient/open-browser.ts
|
|
@@ -25304,6 +25944,143 @@ const openBrowser = (url, logger, noOpen = false) => {
|
|
|
25304
25944
|
});
|
|
25305
25945
|
};
|
|
25306
25946
|
//#endregion
|
|
25947
|
+
//#region src/cli/commands/addon-setup-config.ts
|
|
25948
|
+
const saveAddonProvider = async (path, addonName, provider) => {
|
|
25949
|
+
const mutation = createConfigMutationService({ configPath: path });
|
|
25950
|
+
const candidates = [];
|
|
25951
|
+
for (const source of mutation.sources()) {
|
|
25952
|
+
const doc = parseDocument(readFileSync(source, "utf8"));
|
|
25953
|
+
if (doc.errors.length) continue;
|
|
25954
|
+
const addons = doc.get("addons");
|
|
25955
|
+
if (!isSeq(addons)) continue;
|
|
25956
|
+
addons.items.forEach((item, index) => {
|
|
25957
|
+
const value = isMap(item) ? item.get("src") : isScalar(item) ? item.value : void 0;
|
|
25958
|
+
if (typeof value !== "string") return;
|
|
25959
|
+
const base = basename(value.replace(/\/$/, ""));
|
|
25960
|
+
let name = base === addonName || base === `addon-${addonName}`;
|
|
25961
|
+
const manifestPath = resolve(dirname(source), value, "sirenodeck.json");
|
|
25962
|
+
if (!name && existsSync(manifestPath)) try {
|
|
25963
|
+
name = JSON.parse(readFileSync(manifestPath, "utf8")).name === addonName;
|
|
25964
|
+
} catch {}
|
|
25965
|
+
if (name) candidates.push({
|
|
25966
|
+
path: source,
|
|
25967
|
+
index
|
|
25968
|
+
});
|
|
25969
|
+
});
|
|
25970
|
+
}
|
|
25971
|
+
if (candidates.length !== 1) throw new Error(`Expected one ${addonName} addon entry; found ${candidates.length}`);
|
|
25972
|
+
const target = candidates[0];
|
|
25973
|
+
const document = parseDocument(mutation.readSource(target.path), { keepSourceTokens: true });
|
|
25974
|
+
const addonPath = ["addons", target.index];
|
|
25975
|
+
const item = document.getIn(addonPath);
|
|
25976
|
+
if (!isMap(item)) {
|
|
25977
|
+
const src = typeof item === "string" ? item : isScalar(item) ? item.value : void 0;
|
|
25978
|
+
if (typeof src !== "string") throw new Error("Invalid addon entry");
|
|
25979
|
+
document.setIn(addonPath, document.createNode({ src }));
|
|
25980
|
+
}
|
|
25981
|
+
const providersPath = [
|
|
25982
|
+
...addonPath,
|
|
25983
|
+
"config",
|
|
25984
|
+
"service",
|
|
25985
|
+
"providers"
|
|
25986
|
+
];
|
|
25987
|
+
let providers = document.getIn(providersPath);
|
|
25988
|
+
if (providers === void 0) {
|
|
25989
|
+
document.setIn(providersPath, []);
|
|
25990
|
+
providers = document.getIn(providersPath);
|
|
25991
|
+
}
|
|
25992
|
+
if (!isSeq(providers)) throw new Error("Calendar providers must be a list");
|
|
25993
|
+
const matches = providers.items.filter((entry) => isMap(entry) && entry.get("id") === provider.id);
|
|
25994
|
+
if (matches.length > 1) throw new Error("Duplicate calendar account IDs in config");
|
|
25995
|
+
if (matches.length === 1) {
|
|
25996
|
+
const existing = matches[0];
|
|
25997
|
+
if (!isMap(existing) || existing.get("type") !== provider.type) throw new Error("Account ID is already used by another provider");
|
|
25998
|
+
for (const [key, value] of Object.entries(provider)) existing.set(key, value);
|
|
25999
|
+
} else providers.add(provider);
|
|
26000
|
+
await mutation.apply({
|
|
26001
|
+
kind: "edit-source",
|
|
26002
|
+
path: target.path,
|
|
26003
|
+
content: document.toString()
|
|
26004
|
+
});
|
|
26005
|
+
};
|
|
26006
|
+
//#endregion
|
|
26007
|
+
//#region src/cli/commands/addon-setup.ts
|
|
26008
|
+
const addonSetupCommand = {
|
|
26009
|
+
command: "addon-setup <module>",
|
|
26010
|
+
describe: "Run an installed addon's interactive setup module",
|
|
26011
|
+
builder: (yargs) => yargs.positional("module", {
|
|
26012
|
+
type: "string",
|
|
26013
|
+
demandOption: true,
|
|
26014
|
+
description: "Path to the addon's setup module"
|
|
26015
|
+
}),
|
|
26016
|
+
handler: async ({ module }) => {
|
|
26017
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) throw new Error("Addon setup requires an interactive terminal");
|
|
26018
|
+
const setup = await import(pathToFileURL(resolve(module)).href);
|
|
26019
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(setup.addonName) || typeof setup.setupAddon !== "function") throw new Error("Invalid addon setup module");
|
|
26020
|
+
const logger = createLogger({});
|
|
26021
|
+
const pid = readPid();
|
|
26022
|
+
let configPath = pid !== null && isRunning(pid) ? readConfigPath() : null;
|
|
26023
|
+
await setup.setupAddon({
|
|
26024
|
+
credentials: scopeCredentials(createNativeCredentialBackend(), setup.addonName),
|
|
26025
|
+
openUrl: (url) => {
|
|
26026
|
+
console.log(`Open this URL if your browser does not start:\n${url}`);
|
|
26027
|
+
openBrowser(url, logger);
|
|
26028
|
+
},
|
|
26029
|
+
text: async (message, secret) => {
|
|
26030
|
+
const value = secret ? await password({ message }) : await text({ message });
|
|
26031
|
+
if (isCancel(value)) throw new Error("Addon setup cancelled");
|
|
26032
|
+
return value;
|
|
26033
|
+
},
|
|
26034
|
+
selectMany: async (message, options) => {
|
|
26035
|
+
const value = await multiselect({
|
|
26036
|
+
message,
|
|
26037
|
+
options: options.map(({ color, ...option }) => {
|
|
26038
|
+
const useColor = process.stdout.isTTY && process.env["NO_COLOR"] === void 0 && process.env["TERM"] !== "dumb";
|
|
26039
|
+
const hex = /^#[0-9a-f]{6}$/i.test(color ?? "") ? color.slice(1) : void 0;
|
|
26040
|
+
const rgb = hex === void 0 ? void 0 : [
|
|
26041
|
+
0,
|
|
26042
|
+
2,
|
|
26043
|
+
4
|
|
26044
|
+
].map((i) => parseInt(hex.slice(i, i + 2), 16));
|
|
26045
|
+
const marker = rgb && useColor ? `\x1b[38;2;${rgb.join(";")}m■\x1b[0m` : "■";
|
|
26046
|
+
return {
|
|
26047
|
+
...option,
|
|
26048
|
+
label: `${marker} ${useColor ? styleText("white", option.label) : option.label}`
|
|
26049
|
+
};
|
|
26050
|
+
}),
|
|
26051
|
+
required: true
|
|
26052
|
+
});
|
|
26053
|
+
if (isCancel(value)) throw new Error("Addon setup cancelled");
|
|
26054
|
+
return value;
|
|
26055
|
+
},
|
|
26056
|
+
confirm: async (message) => {
|
|
26057
|
+
const value = await confirm({
|
|
26058
|
+
message,
|
|
26059
|
+
initialValue: false
|
|
26060
|
+
});
|
|
26061
|
+
if (isCancel(value)) throw new Error("Addon setup cancelled");
|
|
26062
|
+
return value;
|
|
26063
|
+
},
|
|
26064
|
+
saveProvider: async (provider) => {
|
|
26065
|
+
if (!configPath) {
|
|
26066
|
+
const value = await text({ message: "Config file path (leave blank for manual instructions)" });
|
|
26067
|
+
if (isCancel(value)) throw new Error("Addon setup cancelled");
|
|
26068
|
+
if (!value.trim()) return null;
|
|
26069
|
+
configPath = resolveUserPath(value.trim());
|
|
26070
|
+
}
|
|
26071
|
+
try {
|
|
26072
|
+
await saveAddonProvider(configPath, setup.addonName, provider);
|
|
26073
|
+
return configPath;
|
|
26074
|
+
} catch (error) {
|
|
26075
|
+
console.error(`Could not update config: ${error instanceof Error ? error.message : String(error)}`);
|
|
26076
|
+
return null;
|
|
26077
|
+
}
|
|
26078
|
+
},
|
|
26079
|
+
print: (message) => console.log(message)
|
|
26080
|
+
});
|
|
26081
|
+
}
|
|
26082
|
+
};
|
|
26083
|
+
//#endregion
|
|
25307
26084
|
//#region src/cli/index.ts
|
|
25308
26085
|
const buildLogger = (argv) => {
|
|
25309
26086
|
const normalized = argv.logLevel === "none" ? "silent" : argv.logLevel;
|
|
@@ -25508,6 +26285,7 @@ const buildCli = async () => {
|
|
|
25508
26285
|
logsCommand,
|
|
25509
26286
|
systemRequirementsCommand,
|
|
25510
26287
|
installCommand,
|
|
26288
|
+
addonSetupCommand,
|
|
25511
26289
|
skillsCommand
|
|
25512
26290
|
],
|
|
25513
26291
|
packageName: PACKAGE_NAME,
|