@sirenodeck/sirenodeck 0.2.10 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.mjs +1089 -626
- 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/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 +1 -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 +53 -11
- package/src/cli/commands/service-manager.ts +3 -5
- package/src/cli/commands/start.ts +14 -81
- 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/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/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
26
|
import { WebSocketServer } from "ws";
|
|
27
27
|
import { getStreamDeckModelName, listStreamDecks, openStreamDeck } from "@elgato-stream-deck/node";
|
|
28
28
|
import sharp from "sharp";
|
|
29
|
-
import { promisify } from "node:util";
|
|
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
|
|
@@ -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.0";
|
|
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),
|
|
@@ -3011,51 +3011,274 @@ var AddonRegistry = class {
|
|
|
3011
3011
|
//#region src/deck/system-buttons/types.ts
|
|
3012
3012
|
const SYSTEM_BUTTON_TYPES = [
|
|
3013
3013
|
"core:back",
|
|
3014
|
+
"core:modal-ok",
|
|
3014
3015
|
"core:settings-entry",
|
|
3015
3016
|
"core:overlay-toggle",
|
|
3016
3017
|
"core:temporary-error"
|
|
3017
3018
|
];
|
|
3018
3019
|
const isSystemButtonType = (value) => SYSTEM_BUTTON_TYPES.includes(value);
|
|
3019
3020
|
//#endregion
|
|
3020
|
-
//#region src/
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
];
|
|
3021
|
+
//#region src/deck/position-buttons.ts
|
|
3022
|
+
/**
|
|
3023
|
+
* Assigns a position to every button — no drops.
|
|
3024
|
+
*
|
|
3025
|
+
* - Buttons with a valid explicit `position` keep it (first-come wins
|
|
3026
|
+
* for duplicates).
|
|
3027
|
+
* - Duplicate positions and buttons without a position fall through to
|
|
3028
|
+
* a "gap" queue, filled sequentially starting at 0 in array order.
|
|
3029
|
+
* - Positions ≥ keyCount are preserved: the caller is responsible for
|
|
3030
|
+
* pagination (group by `floor(pos / (K-2))`). The deck-config and
|
|
3031
|
+
* addon-deck pipelines both go through `paginateDeck` for that.
|
|
3032
|
+
* - The internal contract: every emitted button has `position` set.
|
|
3033
|
+
*
|
|
3034
|
+
* ponytail: O(n²) scan is fine for deck sizes (<30).
|
|
3035
|
+
*/
|
|
3036
|
+
const positionButtons = (buttons, keyCount, logger) => {
|
|
3037
|
+
const occupied = /* @__PURE__ */ new Set();
|
|
3038
|
+
const result = [];
|
|
3039
|
+
const unfixed = [];
|
|
3040
|
+
for (const btn of buttons) {
|
|
3041
|
+
const pos = btn.position;
|
|
3042
|
+
if (pos === void 0 || !Number.isFinite(pos) || pos < 0) {
|
|
3043
|
+
unfixed.push(btn);
|
|
3044
|
+
continue;
|
|
3045
|
+
}
|
|
3046
|
+
if (occupied.has(pos)) {
|
|
3047
|
+
logger?.debug({
|
|
3048
|
+
position: pos,
|
|
3049
|
+
reason: "duplicate"
|
|
3050
|
+
}, "duplicate position, treating as unfixed");
|
|
3051
|
+
unfixed.push(btn);
|
|
3052
|
+
continue;
|
|
3053
|
+
}
|
|
3054
|
+
occupied.add(pos);
|
|
3055
|
+
result.push(btn);
|
|
3056
|
+
}
|
|
3057
|
+
let gap = 0;
|
|
3058
|
+
for (const btn of unfixed) {
|
|
3059
|
+
while (occupied.has(gap)) gap++;
|
|
3060
|
+
occupied.add(gap);
|
|
3061
|
+
result.push({
|
|
3062
|
+
...btn,
|
|
3063
|
+
position: gap
|
|
3064
|
+
});
|
|
3065
|
+
gap++;
|
|
3066
|
+
}
|
|
3067
|
+
return result;
|
|
3039
3068
|
};
|
|
3040
|
-
const formatCommand = (cmd) => cmd.map(escape).join(" ");
|
|
3041
3069
|
//#endregion
|
|
3042
|
-
//#region src/
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3070
|
+
//#region src/core/icon-source.ts
|
|
3071
|
+
const EMOJI_RE = /^(?:[\p{Extended_Pictographic}\p{Emoji_Component}]\uFE0F?(?:\u200D[\p{Extended_Pictographic}\p{Emoji_Component}]\uFE0F?)*|\p{Regional_Indicator}{2})$/u;
|
|
3072
|
+
const ICON_FALLBACK = "icon://alert-circle";
|
|
3073
|
+
const ABSOLUTE_PATH_RE = /^(?:\/|\\|[A-Za-z]:[\\/])/;
|
|
3074
|
+
/**
|
|
3075
|
+
* Validate that a runtime icon source is one of:
|
|
3076
|
+
* - `icon://<name>` — Lucide icon by name (resolved by the runtime
|
|
3077
|
+
* `resolveIconSource`)
|
|
3078
|
+
* - `asset://<id>` — pre-resolved asset id from the registry
|
|
3079
|
+
* - `addon://<a>/<p>` — asset inside an addon's frontendEntry dir
|
|
3080
|
+
* - `builtin://<p>` — asset inside the builtin addon's dir
|
|
3081
|
+
* - absolute path — asset resolved directly
|
|
3082
|
+
* - relative path — asset resolved against the config's baseDirs
|
|
3083
|
+
* (e.g. `./assets/chrome.svg`, `../shared/icon.svg`,
|
|
3084
|
+
* `~/Pictures/x.png`)
|
|
3085
|
+
* - a single emoji (Presentation, or base+VS16 like ✈️; also
|
|
3086
|
+
* regional-indicator pair flags like 🇪🇸, and ZWJ sequences
|
|
3087
|
+
* like 🏳️🌈 or 👨👩👧)
|
|
3088
|
+
*
|
|
3089
|
+
* Rejected: empty string, "%", "abc", multi-char (e.g. "abc🔥"),
|
|
3090
|
+
* inline URLs (data:, http://, https://, file://) — these must be
|
|
3091
|
+
* pre-resolved to asset:// before reaching the runtime.
|
|
3092
|
+
*
|
|
3093
|
+
* Anything rejected here triggers a runtime fallback (alert-circle
|
|
3094
|
+
* Lucide icon) AND, at config-load, a zod validation error.
|
|
3095
|
+
*/
|
|
3096
|
+
const isIconSource = (s) => {
|
|
3097
|
+
if (typeof s !== "string" || s.length === 0) return false;
|
|
3098
|
+
if (EMOJI_RE.test(s)) return true;
|
|
3099
|
+
if (s.startsWith("icon://") && s.length > 7) return true;
|
|
3100
|
+
if (s.startsWith("asset://") && s.length > 8) return true;
|
|
3101
|
+
if (s.startsWith("addon://")) {
|
|
3102
|
+
const rest = s.slice(8);
|
|
3103
|
+
const slash = rest.indexOf("/");
|
|
3104
|
+
if (slash > 0 && slash < rest.length - 1) return true;
|
|
3105
|
+
return false;
|
|
3056
3106
|
}
|
|
3107
|
+
if (s.startsWith("builtin://") && s.length > 10) return true;
|
|
3108
|
+
if (s.startsWith("data:") || s.startsWith("http://") || s.startsWith("https://") || s.startsWith("file://")) return false;
|
|
3109
|
+
if (ABSOLUTE_PATH_RE.test(s)) return true;
|
|
3110
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(s)) return false;
|
|
3111
|
+
if (s === "." || s === "~" || s.startsWith("./") || s.startsWith("../") || s.startsWith("~/") || s.startsWith("~\\") || /[\\/]/.test(s) || s.startsWith("/")) return true;
|
|
3112
|
+
return false;
|
|
3057
3113
|
};
|
|
3058
3114
|
//#endregion
|
|
3115
|
+
//#region src/config/schemas.ts
|
|
3116
|
+
const TriggerSchema = z.object({
|
|
3117
|
+
process_name: z.union([z.string(), z.array(z.string()).min(1)]).optional(),
|
|
3118
|
+
window_name: z.union([z.string(), z.array(z.string()).min(1)]).optional()
|
|
3119
|
+
}).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`" });
|
|
3120
|
+
const ButtonActionsSchema = z.object({
|
|
3121
|
+
tap: z.string().min(1).optional().meta({ title: "Tap action" }),
|
|
3122
|
+
dbltap: z.string().min(1).optional().meta({ title: "Double-tap action" }),
|
|
3123
|
+
hold: z.string().min(1).optional().meta({ title: "Hold action" })
|
|
3124
|
+
}).strict();
|
|
3125
|
+
/**
|
|
3126
|
+
* Runtime icon source. Accepted shapes:
|
|
3127
|
+
* - `icon://<name>` — Lucide icon by name (resolved at render time)
|
|
3128
|
+
* - `asset://<id>` — pre-resolved asset id from the registry
|
|
3129
|
+
* - a single emoji (Presentation or base+VS16 like ✈️)
|
|
3130
|
+
*
|
|
3131
|
+
* Anything else is rejected at config-load time so typos surface before
|
|
3132
|
+
* the daemon starts. The runtime also has a fallback path (alert-circle
|
|
3133
|
+
* Lucide icon) so an invalid source that's slipped through can't crash
|
|
3134
|
+
* the render tree.
|
|
3135
|
+
*/
|
|
3136
|
+
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 ✈️)" });
|
|
3137
|
+
const ButtonConfigSchema = z.record(z.string(), z.unknown()).optional();
|
|
3138
|
+
/**
|
|
3139
|
+
* Closed core set of per-button hue names. Themes declare which of these
|
|
3140
|
+
* (or which additional names like riptide's `neon-pink`) they support
|
|
3141
|
+
* by adding entries to `variants.<name>` in their manifest. Themes are
|
|
3142
|
+
* authoritative — this list is a convention hint, not a constraint on
|
|
3143
|
+
* the theme. Names not declared in the active theme fall back to
|
|
3144
|
+
* "default" with a console.warn at render time (ButtonFrame).
|
|
3145
|
+
*/
|
|
3146
|
+
const ButtonColorSchema = z.enum([
|
|
3147
|
+
"blue",
|
|
3148
|
+
"green",
|
|
3149
|
+
"purple",
|
|
3150
|
+
"cyan",
|
|
3151
|
+
"magenta",
|
|
3152
|
+
"amber",
|
|
3153
|
+
"lime"
|
|
3154
|
+
]);
|
|
3155
|
+
const ButtonDefSchema = z.object({
|
|
3156
|
+
position: z.number().int().nonnegative().optional(),
|
|
3157
|
+
type: z.string().min(1),
|
|
3158
|
+
config: ButtonConfigSchema,
|
|
3159
|
+
accent: z.string().optional(),
|
|
3160
|
+
background: z.string().optional(),
|
|
3161
|
+
actions: ButtonActionsSchema.optional(),
|
|
3162
|
+
/**
|
|
3163
|
+
* Variant token name. Resolved by ButtonFrame against the active
|
|
3164
|
+
* theme's CSS vars at render time. Themes may declare extra
|
|
3165
|
+
* variants beyond the 5-required set; users pick from whatever the
|
|
3166
|
+
* active theme supports. Unknown names fall back to "default" with
|
|
3167
|
+
* a console.warn.
|
|
3168
|
+
*/
|
|
3169
|
+
variant: z.string().min(1).optional(),
|
|
3170
|
+
/**
|
|
3171
|
+
* Per-button hue customisation. Themes declare a `variants.<name>`
|
|
3172
|
+
* entry for each buttonColor they support. See ButtonColorSchema
|
|
3173
|
+
* for the closed core set; themes may add their own names
|
|
3174
|
+
* (e.g. riptide's `neon-pink`) and the runtime accepts them — but
|
|
3175
|
+
* this Zod schema restricts to the core set so typos fail-fast at
|
|
3176
|
+
* config load.
|
|
3177
|
+
*/
|
|
3178
|
+
buttonColor: ButtonColorSchema.optional(),
|
|
3179
|
+
label: z.string().optional(),
|
|
3180
|
+
icon: IconSourceSchema.optional(),
|
|
3181
|
+
iconUrl: z.string().min(1).optional(),
|
|
3182
|
+
size: z.string().optional(),
|
|
3183
|
+
textSize: z.string().optional(),
|
|
3184
|
+
borderRadius: z.string().optional(),
|
|
3185
|
+
addon: z.string().optional(),
|
|
3186
|
+
action: z.string().optional()
|
|
3187
|
+
}).strict();
|
|
3188
|
+
const ButtonEntrySchema = z.union([ButtonDefSchema, z.string()]);
|
|
3189
|
+
const DeckDefSchema = z.object({
|
|
3190
|
+
name: z.string().min(1).optional(),
|
|
3191
|
+
label: z.string().min(1).optional(),
|
|
3192
|
+
columns: z.number().int().positive().optional(),
|
|
3193
|
+
rows: z.number().int().positive().optional(),
|
|
3194
|
+
icon: IconSourceSchema.optional(),
|
|
3195
|
+
background: z.string().min(1).optional(),
|
|
3196
|
+
paginated: z.boolean().optional(),
|
|
3197
|
+
trigger: TriggerSchema.optional(),
|
|
3198
|
+
autoShow: z.boolean().optional(),
|
|
3199
|
+
buttons: z.array(ButtonEntrySchema)
|
|
3200
|
+
}).strict();
|
|
3201
|
+
const UserDeckCreateSchema = z.object({
|
|
3202
|
+
id: z.string().min(1),
|
|
3203
|
+
name: z.string().min(1).optional(),
|
|
3204
|
+
icon: IconSourceSchema.optional(),
|
|
3205
|
+
background: z.string().min(1).optional(),
|
|
3206
|
+
paginated: z.boolean().optional()
|
|
3207
|
+
}).strict();
|
|
3208
|
+
const UserDeckUpdateSchema = z.object({
|
|
3209
|
+
name: z.string().min(1).optional(),
|
|
3210
|
+
icon: IconSourceSchema.nullable().optional(),
|
|
3211
|
+
background: z.string().min(1).nullable().optional(),
|
|
3212
|
+
paginated: z.boolean().optional(),
|
|
3213
|
+
trigger: TriggerSchema.nullable().optional(),
|
|
3214
|
+
autoShow: z.boolean().optional()
|
|
3215
|
+
}).strict();
|
|
3216
|
+
/**
|
|
3217
|
+
* Phase 11: per-deck overrides for an addon-deck generated by `createDeck(s)`.
|
|
3218
|
+
* The deck id is the key in the parent record. Field-level overrides
|
|
3219
|
+
* (`autoShow`/`name`/`icon`/`trigger`) apply on top of the generated
|
|
3220
|
+
* deck; `config` is forwarded to `createDeck(s)({config})` as an
|
|
3221
|
+
* additive merge over the addon's default config.
|
|
3222
|
+
*/
|
|
3223
|
+
const AddonDeckOverrideSchema = z.object({
|
|
3224
|
+
autoShow: z.boolean().optional(),
|
|
3225
|
+
name: z.string().min(1).optional(),
|
|
3226
|
+
icon: IconSourceSchema.optional(),
|
|
3227
|
+
trigger: TriggerSchema.optional(),
|
|
3228
|
+
config: z.record(z.string(), z.unknown()).optional()
|
|
3229
|
+
}).strict();
|
|
3230
|
+
const AddonDeckDefaultsSchema = z.object({ autoShow: z.boolean().optional() }).strict();
|
|
3231
|
+
/**
|
|
3232
|
+
* Phase 11: addon-config block under `addons[i]`. Hosts three shape variants:
|
|
3233
|
+
* - `defaults:` addon-wide deck defaults (applied before per-deck overrides)
|
|
3234
|
+
* - `decks:` record keyed by addon deck id, with per-deck overrides
|
|
3235
|
+
* - `service:` addon-global backend settings (never merged into deck config)
|
|
3236
|
+
*/
|
|
3237
|
+
const AddonConfigSchema = z.object({
|
|
3238
|
+
defaults: AddonDeckDefaultsSchema.optional(),
|
|
3239
|
+
decks: z.record(z.string(), AddonDeckOverrideSchema).optional(),
|
|
3240
|
+
service: z.record(z.string(), z.unknown()).optional()
|
|
3241
|
+
}).strict();
|
|
3242
|
+
const AddonEntrySchema = z.union([z.string().min(1), z.object({
|
|
3243
|
+
src: z.string().min(1),
|
|
3244
|
+
enabled: z.boolean().optional(),
|
|
3245
|
+
global: z.boolean().optional(),
|
|
3246
|
+
config: AddonConfigSchema.optional()
|
|
3247
|
+
}).strict()]);
|
|
3248
|
+
const LoggingSchema = z.object({
|
|
3249
|
+
level: z.enum([
|
|
3250
|
+
"trace",
|
|
3251
|
+
"debug",
|
|
3252
|
+
"info",
|
|
3253
|
+
"warn",
|
|
3254
|
+
"error",
|
|
3255
|
+
"fatal",
|
|
3256
|
+
"silent"
|
|
3257
|
+
]).optional(),
|
|
3258
|
+
verbose: z.boolean().optional()
|
|
3259
|
+
}).strict().optional();
|
|
3260
|
+
const LockSchema = z.object({ buttons: z.array(ButtonDefSchema).optional() }).strict().optional();
|
|
3261
|
+
const ThemeEntrySchema = z.union([z.string().min(1), z.object({
|
|
3262
|
+
src: z.string().min(1),
|
|
3263
|
+
global: z.boolean().optional()
|
|
3264
|
+
}).strict()]);
|
|
3265
|
+
const RawConfigSchema = z.object({
|
|
3266
|
+
theme: ThemeEntrySchema.optional(),
|
|
3267
|
+
logging: LoggingSchema,
|
|
3268
|
+
decks: z.record(z.string(), DeckDefSchema),
|
|
3269
|
+
addons: z.array(AddonEntrySchema).optional(),
|
|
3270
|
+
lock: LockSchema
|
|
3271
|
+
}).strict();
|
|
3272
|
+
//#endregion
|
|
3273
|
+
//#region src/builtin-addons/core/buttons/action/backend.ts
|
|
3274
|
+
var backend_default$23 = { configSchema: z.object({
|
|
3275
|
+
icon: IconSourceSchema.optional().meta({
|
|
3276
|
+
title: "Icon",
|
|
3277
|
+
"x-control": "icon"
|
|
3278
|
+
}),
|
|
3279
|
+
label: z.string().optional().meta({ title: "Label" })
|
|
3280
|
+
}).refine((c) => Boolean(c.icon) || Boolean(c.label), { message: "core:action requires at least one of 'icon' or 'label'" }) };
|
|
3281
|
+
//#endregion
|
|
3059
3282
|
//#region src/ui/theme-presentation.tsx
|
|
3060
3283
|
const ThemeUiPresentationContext = createContext(void 0);
|
|
3061
3284
|
function useThemeUiPresentation() {
|
|
@@ -3601,56 +3824,12 @@ function chipBase(props) {
|
|
|
3601
3824
|
return /* @__PURE__ */ jsx(Text, {
|
|
3602
3825
|
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
3826
|
size: props.size ?? "sm",
|
|
3827
|
+
tone,
|
|
3604
3828
|
"data-sireno-ui-chip": "true",
|
|
3605
3829
|
text: props.text
|
|
3606
3830
|
});
|
|
3607
3831
|
}
|
|
3608
3832
|
//#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
3833
|
//#region src/ui/contexts/AssetCacheContext.tsx
|
|
3655
3834
|
const AssetCacheContext = createContext(/* @__PURE__ */ new Map());
|
|
3656
3835
|
const useAssetCache = () => {
|
|
@@ -4432,400 +4611,43 @@ function paginatedSurfaceBase({ pages, gesture, intervalMs, autoReturnMs, classN
|
|
|
4432
4611
|
return clearAutoReturnTimer;
|
|
4433
4612
|
}, [
|
|
4434
4613
|
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
|
-
};
|
|
4614
|
+
autoReturnMs,
|
|
4615
|
+
clearAutoReturnTimer
|
|
4616
|
+
]);
|
|
4617
|
+
useEffect(() => {
|
|
4618
|
+
setCurrent((p) => p >= count ? 0 : p);
|
|
4619
|
+
}, [count]);
|
|
4620
|
+
const page = allPages[current];
|
|
4621
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
4622
|
+
className: cn("relative flex h-full w-full flex-col", className),
|
|
4623
|
+
style,
|
|
4624
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
4625
|
+
className: "min-h-0 flex-1",
|
|
4626
|
+
children: page.render(page.config)
|
|
4627
|
+
}), count > 1 && /* @__PURE__ */ jsx("div", {
|
|
4628
|
+
className: "absolute bottom-[-4px] left-0 right-0 flex items-center justify-center gap-1",
|
|
4629
|
+
children: allPages.map((_, i) => /* @__PURE__ */ jsx("div", { className: cn("h-1 w-1 rounded-full", i === current ? DOT_ACTIVE : DOT_INACTIVE) }, i))
|
|
4630
|
+
})]
|
|
4631
|
+
});
|
|
4632
|
+
}
|
|
4663
4633
|
//#endregion
|
|
4664
|
-
//#region src/
|
|
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();
|
|
4634
|
+
//#region src/ui/surfaces/paginated-schema.ts
|
|
4674
4635
|
/**
|
|
4675
|
-
*
|
|
4676
|
-
*
|
|
4677
|
-
* - `asset://<id>` — pre-resolved asset id from the registry
|
|
4678
|
-
* - a single emoji (Presentation or base+VS16 like ✈️)
|
|
4636
|
+
* Wraps a page schema to accept either a single page object or an array.
|
|
4637
|
+
* Normalizes to `{ pages: [...] }`.
|
|
4679
4638
|
*
|
|
4680
|
-
*
|
|
4681
|
-
*
|
|
4682
|
-
*
|
|
4683
|
-
*
|
|
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();
|
|
4780
|
-
/**
|
|
4781
|
-
* Phase 11: addon-config block under `addons[i]`. Hosts three shape variants:
|
|
4782
|
-
* - `defaults:` addon-wide deck defaults (applied before per-deck overrides)
|
|
4783
|
-
* - `decks:` record keyed by addon deck id, with per-deck overrides
|
|
4784
|
-
* - addon-wide opaque config (anything else; merged into `createDeck(s)({config})`)
|
|
4639
|
+
* @example
|
|
4640
|
+
* const Config = pagesSchema(z.discriminatedUnion("type", [BarPage, ChartPage]))
|
|
4641
|
+
* // single: { type: "bars", metrics: ["cpu"] } → { pages: [{ type: "bars", metrics: [...] }] }
|
|
4642
|
+
* // array: [{ type: "bars", ... }, { type: "chart", ... }] → { pages: [...] }
|
|
4785
4643
|
*/
|
|
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'" }) };
|
|
4644
|
+
function pagesSchema(page) {
|
|
4645
|
+
return z.preprocess((input) => {
|
|
4646
|
+
if (Array.isArray(input)) return { pages: input };
|
|
4647
|
+
if (input && typeof input === "object" && !("pages" in input)) return { pages: [input] };
|
|
4648
|
+
return input;
|
|
4649
|
+
}, z.object({ pages: z.array(page).min(1).max(5) }).strict());
|
|
4650
|
+
}
|
|
4829
4651
|
//#endregion
|
|
4830
4652
|
//#region src/builtin-addons/core/buttons/action/frontend.tsx
|
|
4831
4653
|
const CoreActionButtonFrontend = ({ config }) => {
|
|
@@ -4857,23 +4679,105 @@ var backend_default$22 = {
|
|
|
4857
4679
|
}
|
|
4858
4680
|
};
|
|
4859
4681
|
//#endregion
|
|
4860
|
-
//#region src/builtin-addons/core/buttons/change-deck/frontend.tsx
|
|
4861
|
-
const CoreChangeDeckButtonFrontend = ({ config }) => {
|
|
4862
|
-
const { icon, label } = config ?? {};
|
|
4863
|
-
return /* @__PURE__ */ jsx(IconLabelSurface, {
|
|
4864
|
-
...icon !== void 0 ? { source: icon } : {},
|
|
4865
|
-
label: label ?? ""
|
|
4866
|
-
});
|
|
4682
|
+
//#region src/builtin-addons/core/buttons/change-deck/frontend.tsx
|
|
4683
|
+
const CoreChangeDeckButtonFrontend = ({ config }) => {
|
|
4684
|
+
const { icon, label } = config ?? {};
|
|
4685
|
+
return /* @__PURE__ */ jsx(IconLabelSurface, {
|
|
4686
|
+
...icon !== void 0 ? { source: icon } : {},
|
|
4687
|
+
label: label ?? ""
|
|
4688
|
+
});
|
|
4689
|
+
};
|
|
4690
|
+
//#endregion
|
|
4691
|
+
//#region src/builtin-addons/core/buttons/media-sample/backend.ts
|
|
4692
|
+
var backend_default$21 = {
|
|
4693
|
+
configSchema: z.object({
|
|
4694
|
+
channel: z.string().min(1).meta({ title: "Data channel" }),
|
|
4695
|
+
fallback: z.unknown().optional().meta({ title: "Fallback value" })
|
|
4696
|
+
}),
|
|
4697
|
+
onTap: async () => {}
|
|
4698
|
+
};
|
|
4699
|
+
//#endregion
|
|
4700
|
+
//#region src/api/react/registry.ts
|
|
4701
|
+
var ChannelRegistry = class ChannelRegistry {
|
|
4702
|
+
static _instance = null;
|
|
4703
|
+
static _announceSubscribe = null;
|
|
4704
|
+
lastPayloads = /* @__PURE__ */ new Map();
|
|
4705
|
+
listeners = /* @__PURE__ */ new Map();
|
|
4706
|
+
listenerCounts = /* @__PURE__ */ new Map();
|
|
4707
|
+
pendingChannels = [];
|
|
4708
|
+
flushScheduled = false;
|
|
4709
|
+
static instance() {
|
|
4710
|
+
if (ChannelRegistry._instance === null) ChannelRegistry._instance = new ChannelRegistry();
|
|
4711
|
+
return ChannelRegistry._instance;
|
|
4712
|
+
}
|
|
4713
|
+
static resetForTests() {
|
|
4714
|
+
ChannelRegistry._instance = null;
|
|
4715
|
+
ChannelRegistry._announceSubscribe = null;
|
|
4716
|
+
}
|
|
4717
|
+
static setAnnounceSubscribe(cb) {
|
|
4718
|
+
ChannelRegistry._announceSubscribe = cb;
|
|
4719
|
+
}
|
|
4720
|
+
publish(channel, payload) {
|
|
4721
|
+
this.lastPayloads.set(channel, payload);
|
|
4722
|
+
const set = this.listeners.get(channel);
|
|
4723
|
+
if (set !== void 0) for (const l of set) l(payload);
|
|
4724
|
+
}
|
|
4725
|
+
subscribe(channel, cb) {
|
|
4726
|
+
let set = this.listeners.get(channel);
|
|
4727
|
+
if (set === void 0) {
|
|
4728
|
+
set = /* @__PURE__ */ new Set();
|
|
4729
|
+
this.listeners.set(channel, set);
|
|
4730
|
+
}
|
|
4731
|
+
const listener = cb;
|
|
4732
|
+
set.add(listener);
|
|
4733
|
+
const prevCount = this.listenerCounts.get(channel) ?? 0;
|
|
4734
|
+
this.listenerCounts.set(channel, prevCount + 1);
|
|
4735
|
+
if (prevCount === 0) {
|
|
4736
|
+
this.pendingChannels.push(channel);
|
|
4737
|
+
if (!this.flushScheduled) {
|
|
4738
|
+
this.flushScheduled = true;
|
|
4739
|
+
queueMicrotask(() => this.flushPendingSubscriptions());
|
|
4740
|
+
}
|
|
4741
|
+
}
|
|
4742
|
+
return () => {
|
|
4743
|
+
set?.delete(listener);
|
|
4744
|
+
const count = this.listenerCounts.get(channel) ?? 0;
|
|
4745
|
+
if (count <= 1) this.listenerCounts.delete(channel);
|
|
4746
|
+
else this.listenerCounts.set(channel, count - 1);
|
|
4747
|
+
};
|
|
4748
|
+
}
|
|
4749
|
+
flushPendingSubscriptions() {
|
|
4750
|
+
this.flushScheduled = false;
|
|
4751
|
+
if (this.pendingChannels.length === 0) return;
|
|
4752
|
+
const channels = [...new Set(this.pendingChannels)];
|
|
4753
|
+
this.pendingChannels = [];
|
|
4754
|
+
ChannelRegistry._announceSubscribe?.(channels);
|
|
4755
|
+
}
|
|
4756
|
+
last(channel) {
|
|
4757
|
+
return this.lastPayloads.get(channel);
|
|
4758
|
+
}
|
|
4759
|
+
clear() {
|
|
4760
|
+
this.lastPayloads.clear();
|
|
4761
|
+
this.listeners.clear();
|
|
4762
|
+
this.listenerCounts.clear();
|
|
4763
|
+
this.pendingChannels = [];
|
|
4764
|
+
this.flushScheduled = false;
|
|
4765
|
+
}
|
|
4766
|
+
};
|
|
4767
|
+
//#endregion
|
|
4768
|
+
//#region src/api/react/use-addon-channel.ts
|
|
4769
|
+
const useAddonChannel$2 = (channel) => {
|
|
4770
|
+
const [data, setData] = useState(() => ChannelRegistry.instance().last(channel));
|
|
4771
|
+
useEffect(() => {
|
|
4772
|
+
return ChannelRegistry.instance().subscribe(channel, (payload) => {
|
|
4773
|
+
setData(payload);
|
|
4774
|
+
});
|
|
4775
|
+
}, [channel]);
|
|
4776
|
+
return { data };
|
|
4867
4777
|
};
|
|
4868
4778
|
//#endregion
|
|
4869
|
-
//#region src/
|
|
4870
|
-
|
|
4871
|
-
configSchema: z.object({
|
|
4872
|
-
channel: z.string().min(1).meta({ title: "Data channel" }),
|
|
4873
|
-
fallback: z.unknown().optional().meta({ title: "Fallback value" })
|
|
4874
|
-
}),
|
|
4875
|
-
onTap: async () => {}
|
|
4876
|
-
};
|
|
4779
|
+
//#region src/api/react/use-button-state.tsx
|
|
4780
|
+
const NullButton = () => null;
|
|
4877
4781
|
//#endregion
|
|
4878
4782
|
//#region src/builtin-addons/core/buttons/media-sample/frontend.tsx
|
|
4879
4783
|
var frontend_default$1 = NullButton;
|
|
@@ -9828,7 +9732,7 @@ const BrightnessButtonFrontend = ({ variant, gesture }) => {
|
|
|
9828
9732
|
const [showProgress, setShowProgress] = useState(false);
|
|
9829
9733
|
const timerRef = useRef(null);
|
|
9830
9734
|
useEffect(() => {
|
|
9831
|
-
if (gesture?.gesture !== "tap" && gesture?.gesture !== "dbl-tap") return;
|
|
9735
|
+
if (gesture?.gesture !== "tap" && gesture?.gesture !== "dbl-tap" && gesture?.gesture !== "hold") return;
|
|
9832
9736
|
setShowProgress(true);
|
|
9833
9737
|
if (timerRef.current) clearTimeout(timerRef.current);
|
|
9834
9738
|
timerRef.current = setTimeout(() => setShowProgress(false), PROGRESS_VISIBLE_MS$1);
|
|
@@ -9838,7 +9742,7 @@ const BrightnessButtonFrontend = ({ variant, gesture }) => {
|
|
|
9838
9742
|
}, []);
|
|
9839
9743
|
return /* @__PURE__ */ jsx(IconLabelProgressSurface, {
|
|
9840
9744
|
source: `icon://${variant === "down" ? "sun-dim" : "sun"}`,
|
|
9841
|
-
label: variant === "down" ? "Darker" : "Lighter",
|
|
9745
|
+
label: variant === "compact" ? "Tap + / Hold −" : variant === "down" ? "Darker" : "Lighter",
|
|
9842
9746
|
progress,
|
|
9843
9747
|
visible: showProgress
|
|
9844
9748
|
});
|
|
@@ -9850,6 +9754,12 @@ const BrightnessDownButtonFrontend = ({ gesture }) => /* @__PURE__ */ jsx(Bright
|
|
|
9850
9754
|
gesture: gesture ?? null
|
|
9851
9755
|
});
|
|
9852
9756
|
//#endregion
|
|
9757
|
+
//#region src/builtin-addons/internal-settings/buttons/brightness-compact/frontend.tsx
|
|
9758
|
+
const CompactBrightnessFrontend = ({ gesture }) => /* @__PURE__ */ jsx(BrightnessButtonFrontend, {
|
|
9759
|
+
variant: "compact",
|
|
9760
|
+
gesture: gesture ?? null
|
|
9761
|
+
});
|
|
9762
|
+
//#endregion
|
|
9853
9763
|
//#region src/builtin-addons/internal-settings/buttons/brightness-up/backend.ts
|
|
9854
9764
|
var backend_default$9 = {
|
|
9855
9765
|
configSchema: z.object({ step: z.number().positive().max(100).default(5).meta({ title: "Brightness step" }) }),
|
|
@@ -9913,6 +9823,24 @@ const internalSettingsAddon = {
|
|
|
9913
9823
|
gestureHandlers: ["tap", "dbl-tap"]
|
|
9914
9824
|
}
|
|
9915
9825
|
},
|
|
9826
|
+
"internal-settings:compact-brightness": {
|
|
9827
|
+
frontend: CompactBrightnessFrontend,
|
|
9828
|
+
service: {
|
|
9829
|
+
...withInternal(backend_default$9),
|
|
9830
|
+
gestureHandlers: [
|
|
9831
|
+
"tap",
|
|
9832
|
+
"dbl-tap",
|
|
9833
|
+
"hold"
|
|
9834
|
+
],
|
|
9835
|
+
onHold: ({ coreMethods }) => {
|
|
9836
|
+
coreMethods.adjustBrightness({ direction: "down" });
|
|
9837
|
+
}
|
|
9838
|
+
}
|
|
9839
|
+
},
|
|
9840
|
+
"internal-settings:compact-app-info": {
|
|
9841
|
+
frontend: AppInfoButtonFrontend,
|
|
9842
|
+
service: { internal: true }
|
|
9843
|
+
},
|
|
9916
9844
|
"internal-settings:app-info": {
|
|
9917
9845
|
frontend: AppInfoButtonFrontend,
|
|
9918
9846
|
service: {
|
|
@@ -13204,7 +13132,6 @@ const registerBuiltins = (registry) => {
|
|
|
13204
13132
|
registry.load(systemStatusAddon);
|
|
13205
13133
|
registry.load(manifest$1);
|
|
13206
13134
|
registry.load(manifest);
|
|
13207
|
-
registry.load(manifest$9);
|
|
13208
13135
|
registerCodingAgentsAddon(registry);
|
|
13209
13136
|
};
|
|
13210
13137
|
/**
|
|
@@ -13233,7 +13160,6 @@ const BUILTIN_MANIFESTS = /* @__PURE__ */ new Map([
|
|
|
13233
13160
|
["system-status", systemStatusAddon],
|
|
13234
13161
|
["value-display", manifest$1],
|
|
13235
13162
|
["weather", manifest],
|
|
13236
|
-
["brightness", manifest$9],
|
|
13237
13163
|
["coding-agents", manifest$3]
|
|
13238
13164
|
]);
|
|
13239
13165
|
[
|
|
@@ -13462,6 +13388,29 @@ const expandButtonReferences = (raw, configDir) => {
|
|
|
13462
13388
|
return raw;
|
|
13463
13389
|
};
|
|
13464
13390
|
//#endregion
|
|
13391
|
+
//#region src/config/environment.ts
|
|
13392
|
+
var MissingEnvironmentVariableError = class extends Error {
|
|
13393
|
+
variable;
|
|
13394
|
+
configPath;
|
|
13395
|
+
constructor(variable, configPath) {
|
|
13396
|
+
super(`Environment variable ${variable} is not set (at ${configPath || "<root>"})`);
|
|
13397
|
+
this.variable = variable;
|
|
13398
|
+
this.configPath = configPath;
|
|
13399
|
+
this.name = "MissingEnvironmentVariableError";
|
|
13400
|
+
}
|
|
13401
|
+
};
|
|
13402
|
+
/** Resolve placeholders in values, never mapping keys or YAML source text. */
|
|
13403
|
+
const resolveEnvironmentVariables = (value, env = process.env, path = "") => {
|
|
13404
|
+
if (typeof value === "string") return value.replace(/\$\{env:([A-Za-z_][A-Za-z0-9_]*)\}/g, (_match, name) => {
|
|
13405
|
+
const resolved = Object.hasOwn(env, name) ? env[name] : void 0;
|
|
13406
|
+
if (resolved === void 0) throw new MissingEnvironmentVariableError(name, path);
|
|
13407
|
+
return resolved;
|
|
13408
|
+
});
|
|
13409
|
+
if (Array.isArray(value)) return value.map((item, index) => resolveEnvironmentVariables(item, env, `${path}[${index}]`));
|
|
13410
|
+
if (typeof value === "object" && value !== null) return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, resolveEnvironmentVariables(item, env, path ? `${path}.${key}` : key)]));
|
|
13411
|
+
return value;
|
|
13412
|
+
};
|
|
13413
|
+
//#endregion
|
|
13465
13414
|
//#region src/config/loader.ts
|
|
13466
13415
|
var ConfigLoadError = class extends Error {
|
|
13467
13416
|
issues;
|
|
@@ -13546,7 +13495,16 @@ const reportZodIssues = (issues) => issues.map((issue) => {
|
|
|
13546
13495
|
const loadConfig = ({ configPath }) => {
|
|
13547
13496
|
const configDir = dirname(configPath);
|
|
13548
13497
|
const raw = loadConfigFile(configPath);
|
|
13549
|
-
|
|
13498
|
+
let expanded;
|
|
13499
|
+
try {
|
|
13500
|
+
expanded = resolveEnvironmentVariables(expandButtonReferences(raw, configDir));
|
|
13501
|
+
} catch (err) {
|
|
13502
|
+
if (err instanceof MissingEnvironmentVariableError) throw new ConfigLoadError(err.message, [{
|
|
13503
|
+
message: err.message,
|
|
13504
|
+
path: err.configPath
|
|
13505
|
+
}]);
|
|
13506
|
+
throw err;
|
|
13507
|
+
}
|
|
13550
13508
|
const result = RawConfigSchema.safeParse(expanded);
|
|
13551
13509
|
if (!result.success) {
|
|
13552
13510
|
const issues = flattenZodIssues(result.error.issues);
|
|
@@ -13559,7 +13517,7 @@ const loadConfig = ({ configPath }) => {
|
|
|
13559
13517
|
};
|
|
13560
13518
|
//#endregion
|
|
13561
13519
|
//#region src/config/validation.ts
|
|
13562
|
-
const validateButton = (btn, registry, path, deckId, position) => {
|
|
13520
|
+
const validateButton = (btn, registry, path, deckId, position, allowInternal = false) => {
|
|
13563
13521
|
const base = {
|
|
13564
13522
|
deckId,
|
|
13565
13523
|
position
|
|
@@ -13582,7 +13540,7 @@ const validateButton = (btn, registry, path, deckId, position) => {
|
|
|
13582
13540
|
};
|
|
13583
13541
|
}
|
|
13584
13542
|
const def = registry.getButtonType(btn.type);
|
|
13585
|
-
if (isSystemButtonType(btn.type) || def.def.service.internal === true) {
|
|
13543
|
+
if (isSystemButtonType(btn.type) || !allowInternal && def.def.service.internal === true) {
|
|
13586
13544
|
issues.push({
|
|
13587
13545
|
level: "error",
|
|
13588
13546
|
path: `${path}.type`,
|
|
@@ -15246,6 +15204,7 @@ const paginate = (items, opts) => {
|
|
|
15246
15204
|
//#region src/deck/system-back-injection.ts
|
|
15247
15205
|
const computeSystemButtonForSlotN1 = (deck, state) => {
|
|
15248
15206
|
if (state.lockActive === true) return null;
|
|
15207
|
+
if (deck.isModal) return "core:modal-ok";
|
|
15249
15208
|
if (deck.isMain) return "core:settings-entry";
|
|
15250
15209
|
return "core:back";
|
|
15251
15210
|
};
|
|
@@ -15327,6 +15286,9 @@ const createRuntime = (options) => {
|
|
|
15327
15286
|
}
|
|
15328
15287
|
let brightness = 50;
|
|
15329
15288
|
let lockActive = false;
|
|
15289
|
+
const modals = [];
|
|
15290
|
+
let deferredOverlay = null;
|
|
15291
|
+
let interruption = null;
|
|
15330
15292
|
let legacyActiveApp = {
|
|
15331
15293
|
getActive: async () => null,
|
|
15332
15294
|
stop: async () => void 0
|
|
@@ -15337,6 +15299,17 @@ const createRuntime = (options) => {
|
|
|
15337
15299
|
const deckById = (id) => decks.find((d) => d.id === id);
|
|
15338
15300
|
const setDecks = (next) => {
|
|
15339
15301
|
decks = next;
|
|
15302
|
+
const activeModal = modals[0];
|
|
15303
|
+
for (let i = modals.length - 1; i >= 0; i--) if (deckById(modals[i].deckId) === void 0) modals.splice(i, 1);
|
|
15304
|
+
if (!lockActive && activeModal && modals[0] !== activeModal) {
|
|
15305
|
+
pubSub.publish("runtime:deck-inactive", { deckId: activeModal.deckId });
|
|
15306
|
+
pubSub.publish("runtime:activeDeck", { deckId: getActiveDeckId() });
|
|
15307
|
+
}
|
|
15308
|
+
if (interruption !== null && deckById(interruption.deckId) === void 0) {
|
|
15309
|
+
const previous = interruption.deckId;
|
|
15310
|
+
interruption = null;
|
|
15311
|
+
pubSub.publish("runtime:deck-inactive", { deckId: previous });
|
|
15312
|
+
}
|
|
15340
15313
|
buttonIndex.clear();
|
|
15341
15314
|
for (const deck of decks) {
|
|
15342
15315
|
if (!Array.isArray(deck.buttons)) continue;
|
|
@@ -15373,10 +15346,15 @@ const createRuntime = (options) => {
|
|
|
15373
15346
|
const id = getActiveDeckId();
|
|
15374
15347
|
const deck = deckById(id);
|
|
15375
15348
|
if (deck === void 0) throw new Error(`Active deck '${id}' not found`);
|
|
15376
|
-
return
|
|
15349
|
+
return !lockActive && modals[0]?.deckId === id ? {
|
|
15350
|
+
...deck,
|
|
15351
|
+
isModal: true
|
|
15352
|
+
} : deck;
|
|
15377
15353
|
};
|
|
15378
15354
|
const getActiveDeckId = () => {
|
|
15379
15355
|
if (lockActive) return "core:lock";
|
|
15356
|
+
if (modals[0]) return modals[0].deckId;
|
|
15357
|
+
if (interruption !== null) return interruption.deckId;
|
|
15380
15358
|
if (overlayDeckId !== null) {
|
|
15381
15359
|
if (transientDeckId !== null) return transientDeckId;
|
|
15382
15360
|
const stack = overlayNavStacks.get(overlayDeckId);
|
|
@@ -15386,6 +15364,51 @@ const createRuntime = (options) => {
|
|
|
15386
15364
|
return transientDeckId ?? navStack[navStack.length - 1] ?? mainDeck.id;
|
|
15387
15365
|
};
|
|
15388
15366
|
const snapshotRegularActiveDeckId = () => overlayPreviousActiveId ?? transientDeckId ?? navStack[navStack.length - 1] ?? mainDeck.id;
|
|
15367
|
+
const showModal = (id, options) => {
|
|
15368
|
+
if (!deckById(id)) return null;
|
|
15369
|
+
const previous = getActiveDeckId();
|
|
15370
|
+
const entry = {
|
|
15371
|
+
deckId: id,
|
|
15372
|
+
onOk: options?.onOk
|
|
15373
|
+
};
|
|
15374
|
+
modals.push(entry);
|
|
15375
|
+
if (!lockActive && modals[0] === entry) {
|
|
15376
|
+
pubSub.publish("runtime:deck-inactive", { deckId: previous });
|
|
15377
|
+
pubSub.publish("runtime:activeDeck", { deckId: id });
|
|
15378
|
+
}
|
|
15379
|
+
return () => {
|
|
15380
|
+
const index = modals.indexOf(entry);
|
|
15381
|
+
if (index < 0) return;
|
|
15382
|
+
const wasActive = index === 0 && !lockActive;
|
|
15383
|
+
modals.splice(index, 1);
|
|
15384
|
+
if (wasActive) {
|
|
15385
|
+
pubSub.publish("runtime:deck-inactive", { deckId: id });
|
|
15386
|
+
pubSub.publish("runtime:activeDeck", { deckId: getActiveDeckId() });
|
|
15387
|
+
if (modals.length === 0 && deferredOverlay) {
|
|
15388
|
+
const pending = deferredOverlay;
|
|
15389
|
+
deferredOverlay = null;
|
|
15390
|
+
setOverlay(pending.deckId, { source: pending.source });
|
|
15391
|
+
}
|
|
15392
|
+
}
|
|
15393
|
+
};
|
|
15394
|
+
};
|
|
15395
|
+
const interruptDeck = (id, options) => {
|
|
15396
|
+
if (lockActive || deckById(id) === void 0) return null;
|
|
15397
|
+
const previous = getActiveDeckId();
|
|
15398
|
+
const current = {
|
|
15399
|
+
deckId: id,
|
|
15400
|
+
onBack: options?.onBack
|
|
15401
|
+
};
|
|
15402
|
+
interruption = current;
|
|
15403
|
+
pubSub.publish("runtime:deck-inactive", { deckId: previous });
|
|
15404
|
+
pubSub.publish("runtime:activeDeck", { deckId: id });
|
|
15405
|
+
return () => {
|
|
15406
|
+
if (interruption !== current) return;
|
|
15407
|
+
interruption = null;
|
|
15408
|
+
pubSub.publish("runtime:deck-inactive", { deckId: id });
|
|
15409
|
+
pubSub.publish("runtime:activeDeck", { deckId: getActiveDeckId() });
|
|
15410
|
+
};
|
|
15411
|
+
};
|
|
15389
15412
|
const enterLock = () => {
|
|
15390
15413
|
const snapshot = {
|
|
15391
15414
|
activeDeckId: snapshotRegularActiveDeckId(),
|
|
@@ -15393,6 +15416,11 @@ const createRuntime = (options) => {
|
|
|
15393
15416
|
};
|
|
15394
15417
|
if (lockActive) return snapshot;
|
|
15395
15418
|
lockActive = true;
|
|
15419
|
+
if (interruption !== null) {
|
|
15420
|
+
const previous = interruption.deckId;
|
|
15421
|
+
interruption = null;
|
|
15422
|
+
pubSub.publish("runtime:deck-inactive", { deckId: previous });
|
|
15423
|
+
}
|
|
15396
15424
|
logger.info(snapshot, "runtime: lock active");
|
|
15397
15425
|
pubSub.publish("runtime:lock-mode", {
|
|
15398
15426
|
active: true,
|
|
@@ -15403,6 +15431,7 @@ const createRuntime = (options) => {
|
|
|
15403
15431
|
return snapshot;
|
|
15404
15432
|
};
|
|
15405
15433
|
const navigateToDeck = (id, navOptions) => {
|
|
15434
|
+
if (!lockActive && modals.length > 0) return;
|
|
15406
15435
|
if (id === getActiveDeckId()) return;
|
|
15407
15436
|
let resolvedId = id;
|
|
15408
15437
|
let target = deckById(id);
|
|
@@ -15417,6 +15446,15 @@ const createRuntime = (options) => {
|
|
|
15417
15446
|
logger.warn({ deckId: id }, "navigateToDeck: deck not found");
|
|
15418
15447
|
return;
|
|
15419
15448
|
}
|
|
15449
|
+
if (interruption !== null) {
|
|
15450
|
+
const previous = interruption.deckId;
|
|
15451
|
+
interruption = null;
|
|
15452
|
+
pubSub.publish("runtime:deck-inactive", { deckId: previous });
|
|
15453
|
+
if (getActiveDeckId() === resolvedId) {
|
|
15454
|
+
pubSub.publish("runtime:activeDeck", { deckId: resolvedId });
|
|
15455
|
+
return;
|
|
15456
|
+
}
|
|
15457
|
+
}
|
|
15420
15458
|
const previousActiveId = getActiveDeckId();
|
|
15421
15459
|
if (overlayDeckId !== null) {
|
|
15422
15460
|
if (overlayNavStacks.get(overlayDeckId) === void 0) overlayNavStacks.set(overlayDeckId, [overlayDeckId]);
|
|
@@ -15432,12 +15470,20 @@ const createRuntime = (options) => {
|
|
|
15432
15470
|
pubSub.publish("runtime:activeDeck", { deckId: resolvedId });
|
|
15433
15471
|
};
|
|
15434
15472
|
const goBack = () => {
|
|
15473
|
+
if (!lockActive && modals.length > 0) return;
|
|
15474
|
+
if (interruption !== null) {
|
|
15475
|
+
const previous = interruption.deckId;
|
|
15476
|
+
interruption = null;
|
|
15477
|
+
pubSub.publish("runtime:deck-inactive", { deckId: previous });
|
|
15478
|
+
pubSub.publish("runtime:activeDeck", { deckId: getActiveDeckId() });
|
|
15479
|
+
return;
|
|
15480
|
+
}
|
|
15435
15481
|
if (overlayDeckId !== null) {
|
|
15436
15482
|
const stack = overlayNavStacks.get(overlayDeckId);
|
|
15437
15483
|
if (stack !== void 0 && stack.length > 1) {
|
|
15438
|
-
stack.pop();
|
|
15484
|
+
const departed = stack.pop();
|
|
15439
15485
|
const prev = stack[stack.length - 1];
|
|
15440
|
-
pubSub.publish("runtime:deck-inactive", { deckId:
|
|
15486
|
+
pubSub.publish("runtime:deck-inactive", { deckId: departed });
|
|
15441
15487
|
pubSub.publish("runtime:activeDeck", { deckId: prev });
|
|
15442
15488
|
} else setOverlay(null);
|
|
15443
15489
|
return;
|
|
@@ -15469,10 +15515,23 @@ const createRuntime = (options) => {
|
|
|
15469
15515
|
pubSub.publish("runtime:activeDeck", { deckId: prev });
|
|
15470
15516
|
};
|
|
15471
15517
|
const setOverlay = (deckId, opts) => {
|
|
15518
|
+
if (!lockActive && modals.length > 0) {
|
|
15519
|
+
deferredOverlay = {
|
|
15520
|
+
deckId,
|
|
15521
|
+
...opts?.source ? { source: opts.source } : {}
|
|
15522
|
+
};
|
|
15523
|
+
return;
|
|
15524
|
+
}
|
|
15472
15525
|
if (deckId !== null && deckById(deckId) === void 0) {
|
|
15473
15526
|
logger.warn({ deckId }, "setOverlay: deck not found");
|
|
15474
15527
|
return;
|
|
15475
15528
|
}
|
|
15529
|
+
if (interruption !== null && deckId === overlayDeckId) return;
|
|
15530
|
+
if (interruption !== null && deckId !== overlayDeckId) {
|
|
15531
|
+
const previous = interruption.deckId;
|
|
15532
|
+
interruption = null;
|
|
15533
|
+
pubSub.publish("runtime:deck-inactive", { deckId: previous });
|
|
15534
|
+
}
|
|
15476
15535
|
if (deckId !== null && !overlayNavStacks.has(deckId)) overlayNavStacks.set(deckId, [deckId]);
|
|
15477
15536
|
const previousActiveId = getActiveDeckId();
|
|
15478
15537
|
const previousOverlayId = overlayDeckId;
|
|
@@ -15514,12 +15573,40 @@ const createRuntime = (options) => {
|
|
|
15514
15573
|
}, "mounted addon button");
|
|
15515
15574
|
};
|
|
15516
15575
|
const handleSystemButton = (type, gesture) => {
|
|
15576
|
+
if ((type === "core:back" || type === "core:modal-ok") && !lockActive && modals[0]) {
|
|
15577
|
+
if (gesture === "tap" || gesture === "hold") {
|
|
15578
|
+
const entry = modals.shift();
|
|
15579
|
+
pubSub.publish("runtime:deck-inactive", { deckId: entry.deckId });
|
|
15580
|
+
pubSub.publish("runtime:activeDeck", { deckId: getActiveDeckId() });
|
|
15581
|
+
if (modals.length === 0 && deferredOverlay) {
|
|
15582
|
+
const pending = deferredOverlay;
|
|
15583
|
+
deferredOverlay = null;
|
|
15584
|
+
setOverlay(pending.deckId, { source: pending.source });
|
|
15585
|
+
}
|
|
15586
|
+
if (entry.onOk) Promise.resolve().then(entry.onOk).catch((err) => logger.error({ err }, "modal OK action failed"));
|
|
15587
|
+
}
|
|
15588
|
+
return true;
|
|
15589
|
+
}
|
|
15517
15590
|
if (type === "core:back") {
|
|
15518
15591
|
if (gesture === "tap") {
|
|
15592
|
+
if (interruption?.onBack) {
|
|
15593
|
+
const current = interruption;
|
|
15594
|
+
if (current.backPending) return true;
|
|
15595
|
+
current.backPending = true;
|
|
15596
|
+
Promise.resolve().then(current.onBack).catch((err) => logger.error({ err }, "interruption back action failed")).finally(() => {
|
|
15597
|
+
current.backPending = false;
|
|
15598
|
+
});
|
|
15599
|
+
return true;
|
|
15600
|
+
}
|
|
15519
15601
|
goBack();
|
|
15520
15602
|
return true;
|
|
15521
15603
|
}
|
|
15522
15604
|
if (gesture === "hold") {
|
|
15605
|
+
if (interruption !== null) {
|
|
15606
|
+
const previous = interruption.deckId;
|
|
15607
|
+
interruption = null;
|
|
15608
|
+
pubSub.publish("runtime:deck-inactive", { deckId: previous });
|
|
15609
|
+
}
|
|
15523
15610
|
if (overlayDeckId !== null) setOverlay(null);
|
|
15524
15611
|
navStack.length = 0;
|
|
15525
15612
|
navStack.push(mainDeck.id);
|
|
@@ -15577,6 +15664,7 @@ const createRuntime = (options) => {
|
|
|
15577
15664
|
logger.warn({ buttonId }, "invokeAction: button not found");
|
|
15578
15665
|
return;
|
|
15579
15666
|
}
|
|
15667
|
+
if (!lockActive && modals[0] && found.deckId !== modals[0].deckId) return;
|
|
15580
15668
|
try {
|
|
15581
15669
|
if (handleSystemButton(found.button.type, gesture)) return;
|
|
15582
15670
|
if (lockActive && found.deckId === "core:lock") {
|
|
@@ -15700,6 +15788,7 @@ const createRuntime = (options) => {
|
|
|
15700
15788
|
logger.warn({ buttonId }, "dispatchGesture: button not found");
|
|
15701
15789
|
return;
|
|
15702
15790
|
}
|
|
15791
|
+
if (!lockActive && modals[0] && found.deckId !== modals[0].deckId) return;
|
|
15703
15792
|
gestureListener?.(found.button.id, {
|
|
15704
15793
|
gesture,
|
|
15705
15794
|
at: Date.now(),
|
|
@@ -15735,6 +15824,12 @@ const createRuntime = (options) => {
|
|
|
15735
15824
|
reason: "session-unlocked"
|
|
15736
15825
|
});
|
|
15737
15826
|
pubSub.publish("runtime:invalidate", void 0);
|
|
15827
|
+
if (modals[0]) pubSub.publish("runtime:activeDeck", { deckId: modals[0].deckId });
|
|
15828
|
+
else if (deferredOverlay) {
|
|
15829
|
+
const pending = deferredOverlay;
|
|
15830
|
+
deferredOverlay = null;
|
|
15831
|
+
setOverlay(pending.deckId, { source: pending.source });
|
|
15832
|
+
}
|
|
15738
15833
|
};
|
|
15739
15834
|
const startLegacyPolicy = () => {
|
|
15740
15835
|
legacyPolicy?.dispose();
|
|
@@ -15783,6 +15878,8 @@ const createRuntime = (options) => {
|
|
|
15783
15878
|
deckExists: (id) => deckById(id) !== void 0 || deckById(`${id}-p1`) !== void 0,
|
|
15784
15879
|
setDecks,
|
|
15785
15880
|
navigateToDeck,
|
|
15881
|
+
interruptDeck,
|
|
15882
|
+
showModal,
|
|
15786
15883
|
goBack,
|
|
15787
15884
|
setOverlay,
|
|
15788
15885
|
getOverlay,
|
|
@@ -15990,6 +16087,7 @@ const buildDeckConfigMessage = (deck, addonByType, resolverOptions = {}, navStat
|
|
|
15990
16087
|
surfaces: { [deck.id]: {
|
|
15991
16088
|
id: deck.id,
|
|
15992
16089
|
name: deck.name ?? deck.id,
|
|
16090
|
+
...deck.isModal === true ? { isModal: true } : {},
|
|
15993
16091
|
buttons: finalButtons,
|
|
15994
16092
|
...deck.buttonColor !== void 0 ? { buttonColor: deck.buttonColor } : {},
|
|
15995
16093
|
...deck.variant !== void 0 && deck.variant.length > 0 ? { variant: deck.variant } : {},
|
|
@@ -16161,7 +16259,13 @@ const paginateDeck = (opts) => {
|
|
|
16161
16259
|
};
|
|
16162
16260
|
//#endregion
|
|
16163
16261
|
//#region src/deck/inject-config-ui-button.ts
|
|
16164
|
-
const injectConfigUiButton = (decks, configUiUrl) => decks.map((deck) => deck.id !== "internal-settings:settings" ? deck : {
|
|
16262
|
+
const injectConfigUiButton = (decks, configUiUrl, keyCount = 15) => decks.map((deck) => deck.id !== "internal-settings:settings" && !deck.id.startsWith("internal-settings:settings-p") ? deck : keyCount === 6 ? {
|
|
16263
|
+
...deck,
|
|
16264
|
+
buttons: deck.buttons.map((button) => button.type === "internal-settings:compact-app-info" ? {
|
|
16265
|
+
...button,
|
|
16266
|
+
actions: { tap: `url://${configUiUrl}` }
|
|
16267
|
+
} : button)
|
|
16268
|
+
} : {
|
|
16165
16269
|
...deck,
|
|
16166
16270
|
buttons: [...deck.buttons, {
|
|
16167
16271
|
id: "config-ui",
|
|
@@ -16175,16 +16279,83 @@ const injectConfigUiButton = (decks, configUiUrl) => decks.map((deck) => deck.id
|
|
|
16175
16279
|
}]
|
|
16176
16280
|
});
|
|
16177
16281
|
//#endregion
|
|
16178
|
-
//#region src/deck/
|
|
16179
|
-
const
|
|
16180
|
-
|
|
16181
|
-
|
|
16182
|
-
|
|
16183
|
-
|
|
16184
|
-
|
|
16185
|
-
|
|
16186
|
-
|
|
16282
|
+
//#region src/deck/addon-settings.ts
|
|
16283
|
+
const settingsId = "internal-settings:settings";
|
|
16284
|
+
const buildAddonSettingsDecks = (decks, addons, keyCount) => {
|
|
16285
|
+
const base = decks.find((deck) => deck.id === settingsId);
|
|
16286
|
+
if (!base) return [...decks];
|
|
16287
|
+
const compact = keyCount === 6;
|
|
16288
|
+
const entries = addons.filter((addon) => addon.settings !== void 0);
|
|
16289
|
+
const start = compact ? 2 : 4;
|
|
16290
|
+
const available = keyCount - 1 - start;
|
|
16291
|
+
const paginated = entries.length > available;
|
|
16292
|
+
const pageSize = available - (paginated ? 1 : 0);
|
|
16293
|
+
if (pageSize < 1) return [...decks];
|
|
16294
|
+
const total = Math.max(1, Math.ceil(entries.length / pageSize));
|
|
16295
|
+
const pageId = (page) => page === 0 ? settingsId : `${settingsId}-p${page + 1}`;
|
|
16296
|
+
const pages = Array.from({ length: total }, (_, page) => {
|
|
16297
|
+
const buttons = compact ? [{
|
|
16298
|
+
id: "app-info",
|
|
16299
|
+
type: "internal-settings:compact-app-info",
|
|
16300
|
+
position: 0,
|
|
16301
|
+
config: { icon: "addon://internal-settings/logo72x72.png" }
|
|
16302
|
+
}, {
|
|
16303
|
+
id: "brightness",
|
|
16304
|
+
type: "internal-settings:compact-brightness",
|
|
16305
|
+
position: 1
|
|
16306
|
+
}] : [
|
|
16307
|
+
{
|
|
16308
|
+
id: "app-info",
|
|
16309
|
+
type: "internal-settings:app-info",
|
|
16310
|
+
position: 0,
|
|
16311
|
+
config: { icon: "addon://internal-settings/logo72x72.png" }
|
|
16312
|
+
},
|
|
16313
|
+
{
|
|
16314
|
+
id: "brightness-down",
|
|
16315
|
+
type: "internal-settings:brightness-down",
|
|
16316
|
+
position: 1
|
|
16317
|
+
},
|
|
16318
|
+
{
|
|
16319
|
+
id: "brightness-up",
|
|
16320
|
+
type: "internal-settings:brightness-up",
|
|
16321
|
+
position: 2
|
|
16322
|
+
}
|
|
16323
|
+
];
|
|
16324
|
+
for (const [index, addon] of entries.slice(page * pageSize, (page + 1) * pageSize).entries()) {
|
|
16325
|
+
const settings = addon.settings;
|
|
16326
|
+
buttons.push({
|
|
16327
|
+
id: `settings-${addon.name}`,
|
|
16328
|
+
type: "core:change-deck",
|
|
16329
|
+
position: start + index,
|
|
16330
|
+
config: {
|
|
16331
|
+
deck: settings.deck,
|
|
16332
|
+
label: settings.label,
|
|
16333
|
+
icon: settings.icon
|
|
16334
|
+
}
|
|
16335
|
+
});
|
|
16336
|
+
}
|
|
16337
|
+
if (paginated) buttons.push({
|
|
16338
|
+
id: "page-nav",
|
|
16339
|
+
type: "core:page-nav",
|
|
16340
|
+
position: keyCount - 2,
|
|
16341
|
+
config: {
|
|
16342
|
+
currentPage: page + 1,
|
|
16343
|
+
totalPages: total,
|
|
16344
|
+
prevDeckId: pageId(Math.max(0, page - 1)),
|
|
16345
|
+
nextDeckId: pageId(Math.min(total - 1, page + 1))
|
|
16346
|
+
}
|
|
16347
|
+
});
|
|
16348
|
+
return {
|
|
16349
|
+
...base,
|
|
16350
|
+
id: pageId(page),
|
|
16351
|
+
buttons,
|
|
16352
|
+
sourceDeckId: settingsId,
|
|
16353
|
+
projectionId: pageId(page),
|
|
16354
|
+
pageIndex: page,
|
|
16355
|
+
paginated
|
|
16356
|
+
};
|
|
16187
16357
|
});
|
|
16358
|
+
return decks.flatMap((deck) => deck.id === settingsId ? pages : [deck]);
|
|
16188
16359
|
};
|
|
16189
16360
|
//#endregion
|
|
16190
16361
|
//#region src/deck/runtime-subscriptions.ts
|
|
@@ -16319,7 +16490,7 @@ const createNotificationProvider = async (options) => {
|
|
|
16319
16490
|
});
|
|
16320
16491
|
}
|
|
16321
16492
|
if (platform === "win32") {
|
|
16322
|
-
const { createWindowsNotificationProvider } = await import("./windows-
|
|
16493
|
+
const { createWindowsNotificationProvider } = await import("./windows-BCvfQ3PA.mjs");
|
|
16323
16494
|
return createWindowsNotificationProvider({
|
|
16324
16495
|
executor: options.executor,
|
|
16325
16496
|
logger: options.logger,
|
|
@@ -18035,6 +18206,124 @@ const BUILTIN_GLOBAL_SERVICES = /* @__PURE__ */ new Map([["coding-agents", {
|
|
|
18035
18206
|
lastLiveCount = -1;
|
|
18036
18207
|
}
|
|
18037
18208
|
}]]);
|
|
18209
|
+
/** Error messages must not include credential values or native error details. */
|
|
18210
|
+
var CredentialStoreError = class extends Error {
|
|
18211
|
+
code;
|
|
18212
|
+
constructor(code) {
|
|
18213
|
+
super(`Credential store: ${code}`);
|
|
18214
|
+
this.code = code;
|
|
18215
|
+
this.name = "CredentialStoreError";
|
|
18216
|
+
}
|
|
18217
|
+
};
|
|
18218
|
+
const validateName = (name) => {
|
|
18219
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(name)) throw new CredentialStoreError("invalid-name");
|
|
18220
|
+
};
|
|
18221
|
+
/** Bind an addon identity so callers cannot choose another namespace. */
|
|
18222
|
+
const scopeCredentials = (backend, addon) => {
|
|
18223
|
+
return {
|
|
18224
|
+
availability: () => backend.availability(),
|
|
18225
|
+
get: async (name) => {
|
|
18226
|
+
validateName(name);
|
|
18227
|
+
return backend.get(addon, name);
|
|
18228
|
+
},
|
|
18229
|
+
set: async (name, value) => {
|
|
18230
|
+
validateName(name);
|
|
18231
|
+
if (Buffer.byteLength(value, "utf8") > 2560) throw new CredentialStoreError("too-large");
|
|
18232
|
+
await backend.set(addon, name, value);
|
|
18233
|
+
},
|
|
18234
|
+
delete: async (name) => {
|
|
18235
|
+
validateName(name);
|
|
18236
|
+
await backend.delete(addon, name);
|
|
18237
|
+
}
|
|
18238
|
+
};
|
|
18239
|
+
};
|
|
18240
|
+
//#endregion
|
|
18241
|
+
//#region src/system/credentials/native.ts
|
|
18242
|
+
const accountFor = (addon, name) => createHash("sha256").update(JSON.stringify([addon, name])).digest("hex");
|
|
18243
|
+
/** Entries contain no user-provided names in native-store metadata. */
|
|
18244
|
+
const createNativeCredentialBackend = (createEntry = async (account) => {
|
|
18245
|
+
const { AsyncEntry } = await import("@napi-rs/keyring");
|
|
18246
|
+
return new AsyncEntry("sirenodeck.credentials.v1", account, { linux: { store: "secret-service" } });
|
|
18247
|
+
}) => {
|
|
18248
|
+
const entry = async (addon, name) => {
|
|
18249
|
+
try {
|
|
18250
|
+
return await createEntry(accountFor(addon, name));
|
|
18251
|
+
} catch {
|
|
18252
|
+
throw new CredentialStoreError("unavailable");
|
|
18253
|
+
}
|
|
18254
|
+
};
|
|
18255
|
+
return {
|
|
18256
|
+
availability: async () => {
|
|
18257
|
+
try {
|
|
18258
|
+
await (await createEntry(accountFor("sirenodeck", "availability-probe"))).getSecret();
|
|
18259
|
+
return "available";
|
|
18260
|
+
} catch {
|
|
18261
|
+
return "unavailable";
|
|
18262
|
+
}
|
|
18263
|
+
},
|
|
18264
|
+
get: async (addon, name) => {
|
|
18265
|
+
const item = await entry(addon, name);
|
|
18266
|
+
try {
|
|
18267
|
+
const bytes = await item.getSecret();
|
|
18268
|
+
return bytes === null ? void 0 : new TextDecoder("utf-8", { fatal: true }).decode(Uint8Array.from(bytes));
|
|
18269
|
+
} catch {
|
|
18270
|
+
throw new CredentialStoreError("operation-failed");
|
|
18271
|
+
}
|
|
18272
|
+
},
|
|
18273
|
+
set: async (addon, name, value) => {
|
|
18274
|
+
const item = await entry(addon, name);
|
|
18275
|
+
try {
|
|
18276
|
+
await item.setSecret(new TextEncoder().encode(value));
|
|
18277
|
+
} catch {
|
|
18278
|
+
throw new CredentialStoreError("operation-failed");
|
|
18279
|
+
}
|
|
18280
|
+
},
|
|
18281
|
+
delete: async (addon, name) => {
|
|
18282
|
+
const item = await entry(addon, name);
|
|
18283
|
+
try {
|
|
18284
|
+
await item.deleteCredential();
|
|
18285
|
+
} catch {
|
|
18286
|
+
throw new CredentialStoreError("operation-failed");
|
|
18287
|
+
}
|
|
18288
|
+
}
|
|
18289
|
+
};
|
|
18290
|
+
};
|
|
18291
|
+
//#endregion
|
|
18292
|
+
//#region src/addon/data-directory.ts
|
|
18293
|
+
const addonDataRoot = () => {
|
|
18294
|
+
if (process.platform === "win32") {
|
|
18295
|
+
const local = process.env["LOCALAPPDATA"];
|
|
18296
|
+
if (!local || !isAbsolute(local)) throw new Error("LOCALAPPDATA is unavailable");
|
|
18297
|
+
return join(local, "sirenodeck");
|
|
18298
|
+
}
|
|
18299
|
+
if (process.platform === "darwin") return join(homedir(), "Library", "Application Support", "sirenodeck");
|
|
18300
|
+
const xdg = process.env["XDG_DATA_HOME"];
|
|
18301
|
+
return join(xdg && isAbsolute(xdg) ? xdg : join(homedir(), ".local", "share"), "sirenodeck");
|
|
18302
|
+
};
|
|
18303
|
+
const createAddonDataDirectory = (name, root) => {
|
|
18304
|
+
let result;
|
|
18305
|
+
return () => {
|
|
18306
|
+
result ??= (async () => {
|
|
18307
|
+
const base = root ?? addonDataRoot();
|
|
18308
|
+
if (!isAbsolute(base)) throw new Error("Addon data root must be absolute");
|
|
18309
|
+
const addons = join(base, "addons");
|
|
18310
|
+
const directory = join(addons, createHash("sha256").update(name).digest("hex"));
|
|
18311
|
+
await mkdir(base, {
|
|
18312
|
+
recursive: true,
|
|
18313
|
+
mode: 448
|
|
18314
|
+
});
|
|
18315
|
+
for (const path of [addons, directory]) {
|
|
18316
|
+
await mkdir(path, { mode: 448 }).catch((error) => {
|
|
18317
|
+
if (error.code !== "EEXIST") throw error;
|
|
18318
|
+
});
|
|
18319
|
+
if (!(await lstat(path)).isDirectory()) throw new Error(`Not a directory: ${path}`);
|
|
18320
|
+
if (process.platform !== "win32") await chmod(path, 448);
|
|
18321
|
+
}
|
|
18322
|
+
return directory;
|
|
18323
|
+
})();
|
|
18324
|
+
return result;
|
|
18325
|
+
};
|
|
18326
|
+
};
|
|
18038
18327
|
//#endregion
|
|
18039
18328
|
//#region src/deck/addon-handler-bridge.ts
|
|
18040
18329
|
const namespacedKey = (addonName, methodName) => `${addonName}:${methodName}`;
|
|
@@ -18071,7 +18360,7 @@ const staticGlobalServiceModule = (addonName) => {
|
|
|
18071
18360
|
return fromManifest.manifest?.globalService === void 0 ? null : fromManifest;
|
|
18072
18361
|
};
|
|
18073
18362
|
const bridgeAddonServices = async (params) => {
|
|
18074
|
-
const { runtime, decks, scanned, externalAddons, executor, pubSub, store, signal, statePublisher, bridge, methods, requestDeckRebuild } = params;
|
|
18363
|
+
const { runtime, decks, scanned, externalAddons, executor, pubSub, store, signal, statePublisher, bridge, methods, addonServiceConfigs, credentialBackend = createNativeCredentialBackend(), requestDeckRebuild } = params;
|
|
18075
18364
|
const logger = params.logger.child({ component: "addon-handler" });
|
|
18076
18365
|
const allAddons = [...scanned, ...externalAddons];
|
|
18077
18366
|
runtime.setGestureListener((buttonId, event) => {
|
|
@@ -18086,6 +18375,7 @@ const bridgeAddonServices = async (params) => {
|
|
|
18086
18375
|
const trackedCleanup = [];
|
|
18087
18376
|
const addonModules = /* @__PURE__ */ new Map();
|
|
18088
18377
|
const addonGlobalServices = /* @__PURE__ */ new Map();
|
|
18378
|
+
const addonDataDirectories = /* @__PURE__ */ new Map();
|
|
18089
18379
|
const addonMethods = /* @__PURE__ */ new Map();
|
|
18090
18380
|
for (const addon of allAddons) {
|
|
18091
18381
|
if (addon.globalServiceEntry === null) continue;
|
|
@@ -18110,10 +18400,46 @@ const bridgeAddonServices = async (params) => {
|
|
|
18110
18400
|
}
|
|
18111
18401
|
}
|
|
18112
18402
|
for (const [addonName, globalService] of addonGlobalServices) {
|
|
18403
|
+
const getDataDirectory = createAddonDataDirectory(addonName, params.addonDataRoot);
|
|
18404
|
+
addonDataDirectories.set(addonName, getDataDirectory);
|
|
18405
|
+
const interruptions = /* @__PURE__ */ new Set();
|
|
18406
|
+
abortController.signal.addEventListener("abort", () => {
|
|
18407
|
+
for (const release of interruptions) release();
|
|
18408
|
+
interruptions.clear();
|
|
18409
|
+
});
|
|
18113
18410
|
const primaryChannel = globalService.pollers?.[0]?.channel;
|
|
18114
18411
|
const pollersById = /* @__PURE__ */ new Map();
|
|
18115
18412
|
for (const poller of globalService.pollers ?? []) pollersById.set(poller.id, poller);
|
|
18116
18413
|
const ctx = {
|
|
18414
|
+
getDataDirectory,
|
|
18415
|
+
interruptDeck: (deckId, options) => {
|
|
18416
|
+
if (abortController.signal.aborted) return null;
|
|
18417
|
+
const release = runtime.interruptDeck(deckId, options);
|
|
18418
|
+
if (release === null) return null;
|
|
18419
|
+
const ownedRelease = () => {
|
|
18420
|
+
interruptions.delete(ownedRelease);
|
|
18421
|
+
release();
|
|
18422
|
+
};
|
|
18423
|
+
interruptions.add(ownedRelease);
|
|
18424
|
+
return ownedRelease;
|
|
18425
|
+
},
|
|
18426
|
+
showModal: (deckId, options) => {
|
|
18427
|
+
if (abortController.signal.aborted) return null;
|
|
18428
|
+
let ownedRelease;
|
|
18429
|
+
const release = runtime.showModal(deckId, { onOk: async () => {
|
|
18430
|
+
interruptions.delete(ownedRelease);
|
|
18431
|
+
if (abortController.signal.aborted) return;
|
|
18432
|
+
await options?.onOk?.();
|
|
18433
|
+
} });
|
|
18434
|
+
if (release === null) return null;
|
|
18435
|
+
ownedRelease = () => {
|
|
18436
|
+
interruptions.delete(ownedRelease);
|
|
18437
|
+
release();
|
|
18438
|
+
};
|
|
18439
|
+
interruptions.add(ownedRelease);
|
|
18440
|
+
return ownedRelease;
|
|
18441
|
+
},
|
|
18442
|
+
credentials: scopeCredentials(credentialBackend, addonName),
|
|
18117
18443
|
publish: (data) => {
|
|
18118
18444
|
if (primaryChannel !== void 0) {
|
|
18119
18445
|
bridge.broadcast({
|
|
@@ -18155,7 +18481,7 @@ const bridgeAddonServices = async (params) => {
|
|
|
18155
18481
|
bridge.registerCacheablePoller(poller.channel, () => poller.poll(ctx));
|
|
18156
18482
|
}
|
|
18157
18483
|
try {
|
|
18158
|
-
const result = globalService.onLoad?.(ctx);
|
|
18484
|
+
const result = globalService.onLoad?.(ctx, addonServiceConfigs?.get(addonName));
|
|
18159
18485
|
if (result instanceof Promise) result.catch((err) => {
|
|
18160
18486
|
logger.error({
|
|
18161
18487
|
addonName,
|
|
@@ -18252,19 +18578,39 @@ const bridgeAddonServices = async (params) => {
|
|
|
18252
18578
|
signal: abortController.signal,
|
|
18253
18579
|
store
|
|
18254
18580
|
};
|
|
18255
|
-
|
|
18581
|
+
let buttonAbort = new AbortController();
|
|
18256
18582
|
abortController.signal.addEventListener("abort", () => buttonAbort.abort());
|
|
18257
|
-
|
|
18583
|
+
let wrappedCtx = {
|
|
18258
18584
|
...buttonCtx,
|
|
18259
18585
|
signal: buttonAbort.signal
|
|
18260
18586
|
};
|
|
18261
|
-
const
|
|
18262
|
-
existing.push({
|
|
18587
|
+
const entry = {
|
|
18263
18588
|
handlerId,
|
|
18264
18589
|
buttonAbort,
|
|
18265
18590
|
buttonService,
|
|
18266
|
-
wrappedCtx
|
|
18267
|
-
|
|
18591
|
+
wrappedCtx,
|
|
18592
|
+
activate: () => {
|
|
18593
|
+
if (!buttonAbort.signal.aborted || abortController.signal.aborted) return;
|
|
18594
|
+
buttonAbort = new AbortController();
|
|
18595
|
+
wrappedCtx = {
|
|
18596
|
+
...buttonCtx,
|
|
18597
|
+
signal: buttonAbort.signal
|
|
18598
|
+
};
|
|
18599
|
+
entry.buttonAbort = buttonAbort;
|
|
18600
|
+
entry.wrappedCtx = wrappedCtx;
|
|
18601
|
+
try {
|
|
18602
|
+
buttonService.onMount?.(wrappedCtx);
|
|
18603
|
+
} catch (err) {
|
|
18604
|
+
logger.error({
|
|
18605
|
+
addonName,
|
|
18606
|
+
buttonType,
|
|
18607
|
+
err
|
|
18608
|
+
}, `addon onMount threw`);
|
|
18609
|
+
}
|
|
18610
|
+
}
|
|
18611
|
+
};
|
|
18612
|
+
const existing = deckButtonCleanup.get(deck.id) ?? [];
|
|
18613
|
+
existing.push(entry);
|
|
18268
18614
|
deckButtonCleanup.set(deck.id, existing);
|
|
18269
18615
|
try {
|
|
18270
18616
|
buttonService.onMount?.(wrappedCtx);
|
|
@@ -18361,6 +18707,7 @@ const bridgeAddonServices = async (params) => {
|
|
|
18361
18707
|
const tracked = deckButtonCleanup.get(deckId);
|
|
18362
18708
|
if (tracked === void 0) return;
|
|
18363
18709
|
for (const { buttonAbort, buttonService, wrappedCtx } of tracked) {
|
|
18710
|
+
if (buttonAbort.signal.aborted) continue;
|
|
18364
18711
|
try {
|
|
18365
18712
|
buttonService.onUnmount?.(wrappedCtx);
|
|
18366
18713
|
} catch (err) {
|
|
@@ -18373,16 +18720,22 @@ const bridgeAddonServices = async (params) => {
|
|
|
18373
18720
|
}
|
|
18374
18721
|
});
|
|
18375
18722
|
trackedCleanup.push(unsubscribeDeckInactive);
|
|
18723
|
+
trackedCleanup.push(pubSub.subscribe("runtime:activeDeck", (payload) => {
|
|
18724
|
+
if (typeof payload !== "object" || payload === null || !("deckId" in payload)) return;
|
|
18725
|
+
for (const entry of deckButtonCleanup.get(String(payload.deckId)) ?? []) entry.activate();
|
|
18726
|
+
}));
|
|
18376
18727
|
abortController.signal.addEventListener("abort", () => {
|
|
18377
18728
|
for (const [addonName, globalService] of addonGlobalServices) try {
|
|
18378
18729
|
const ctx = {
|
|
18730
|
+
getDataDirectory: addonDataDirectories.get(addonName),
|
|
18731
|
+
credentials: scopeCredentials(credentialBackend, addonName),
|
|
18379
18732
|
publish: () => {},
|
|
18380
18733
|
poll: async () => {},
|
|
18381
18734
|
signal: abortController.signal,
|
|
18382
18735
|
executor,
|
|
18383
18736
|
notify: methods.notify
|
|
18384
18737
|
};
|
|
18385
|
-
globalService.onUnload?.(ctx);
|
|
18738
|
+
globalService.onUnload?.(ctx, addonServiceConfigs?.get(addonName));
|
|
18386
18739
|
} catch (err) {
|
|
18387
18740
|
logger.error({
|
|
18388
18741
|
addonName,
|
|
@@ -18398,13 +18751,15 @@ const bridgeAddonServices = async (params) => {
|
|
|
18398
18751
|
unmountButtons();
|
|
18399
18752
|
for (const [addonName, globalService] of addonGlobalServices) try {
|
|
18400
18753
|
const ctx = {
|
|
18754
|
+
getDataDirectory: addonDataDirectories.get(addonName),
|
|
18755
|
+
credentials: scopeCredentials(credentialBackend, addonName),
|
|
18401
18756
|
publish: () => {},
|
|
18402
18757
|
poll: async () => {},
|
|
18403
18758
|
signal: abortController.signal,
|
|
18404
18759
|
executor,
|
|
18405
18760
|
notify: methods.notify
|
|
18406
18761
|
};
|
|
18407
|
-
globalService.onUnload?.(ctx);
|
|
18762
|
+
globalService.onUnload?.(ctx, addonServiceConfigs?.get(addonName));
|
|
18408
18763
|
} catch (err) {
|
|
18409
18764
|
logger.error({
|
|
18410
18765
|
addonName,
|
|
@@ -18565,6 +18920,7 @@ const deckConfigSurfaceSchema = z.object({
|
|
|
18565
18920
|
id: z.string(),
|
|
18566
18921
|
name: z.string(),
|
|
18567
18922
|
buttons: z.array(deckConfigSurfaceButtonSchema),
|
|
18923
|
+
isModal: z.boolean().optional(),
|
|
18568
18924
|
buttonColor: z.string().optional(),
|
|
18569
18925
|
variant: z.string().optional(),
|
|
18570
18926
|
buttonErrors: z.array(z.object({
|
|
@@ -21067,14 +21423,17 @@ const collectAddonDefaultButtonConfig = (registry, userDecks, logger) => {
|
|
|
21067
21423
|
for (const addon of registry.listAddons()) {
|
|
21068
21424
|
if (addon.defaultButton === void 0) continue;
|
|
21069
21425
|
let matchCount = 0;
|
|
21070
|
-
for (const deck of userDecks)
|
|
21071
|
-
if (
|
|
21072
|
-
|
|
21073
|
-
|
|
21074
|
-
|
|
21075
|
-
|
|
21076
|
-
|
|
21077
|
-
|
|
21426
|
+
for (const deck of userDecks) {
|
|
21427
|
+
if (deck.addonOwner !== void 0) continue;
|
|
21428
|
+
for (const btn of deck.buttons) if (btn.type === addon.defaultButton || btn.type === addon.name) {
|
|
21429
|
+
if (matchCount > 0) logger.warn({
|
|
21430
|
+
addon: addon.name,
|
|
21431
|
+
defaultButton: addon.defaultButton,
|
|
21432
|
+
deckId: deck.id
|
|
21433
|
+
}, "collectAddonDefaultButtonConfig: multiple launcher buttons found, using first");
|
|
21434
|
+
if (matchCount === 0) result.set(addon.name, btn.config ?? {});
|
|
21435
|
+
matchCount++;
|
|
21436
|
+
}
|
|
21078
21437
|
}
|
|
21079
21438
|
}
|
|
21080
21439
|
return result;
|
|
@@ -21259,7 +21618,7 @@ const collectActiveDeckAddonNames = (deck, addonByType) => {
|
|
|
21259
21618
|
return [...addonNames];
|
|
21260
21619
|
};
|
|
21261
21620
|
const setupAddonServices = (options) => {
|
|
21262
|
-
const { runtime, decks, pubSub, scanned, externalAddons, addonByType, executor, statePublisher, bridge, initialDeck, signal, store, methods, logger, requestDeckRebuild } = options;
|
|
21621
|
+
const { runtime, decks, pubSub, scanned, externalAddons, addonByType, executor, statePublisher, bridge, initialDeck, signal, store, methods, logger, requestDeckRebuild, addonServiceConfigs } = options;
|
|
21263
21622
|
const addonBridge = bridgeAddonServices({
|
|
21264
21623
|
runtime,
|
|
21265
21624
|
decks,
|
|
@@ -21273,6 +21632,7 @@ const setupAddonServices = (options) => {
|
|
|
21273
21632
|
bridge,
|
|
21274
21633
|
store,
|
|
21275
21634
|
methods,
|
|
21635
|
+
...addonServiceConfigs !== void 0 ? { addonServiceConfigs } : {},
|
|
21276
21636
|
...requestDeckRebuild !== void 0 ? { requestDeckRebuild } : {}
|
|
21277
21637
|
});
|
|
21278
21638
|
const unsubscribeDeck = pubSub.subscribe("runtime:activeDeck", (payload) => {
|
|
@@ -21355,7 +21715,7 @@ const loadExternalAddonsIntoRegistry = async (registry, config, configDir, homeD
|
|
|
21355
21715
|
if (missing.length > 0 && process.stdin.isTTY) {
|
|
21356
21716
|
for (const source of missing) {
|
|
21357
21717
|
const entry = entries.find((candidate) => (typeof candidate === "string" ? candidate : candidate.src) === source);
|
|
21358
|
-
if (await confirm({
|
|
21718
|
+
if (await confirm$1({
|
|
21359
21719
|
message: `Addon '${source}' is not installed. Install it now?`,
|
|
21360
21720
|
initialValue: true
|
|
21361
21721
|
})) await installPackage({
|
|
@@ -21439,7 +21799,7 @@ const validateAndLoadConfig = async (options) => {
|
|
|
21439
21799
|
} catch (error) {
|
|
21440
21800
|
const source = config.theme === void 0 ? null : typeof config.theme === "string" ? config.theme : config.theme.src;
|
|
21441
21801
|
if (source === null || !isNpmAddonSpec(source) || !process.stdin.isTTY) throw error;
|
|
21442
|
-
if (!await confirm({
|
|
21802
|
+
if (!await confirm$1({
|
|
21443
21803
|
message: `Theme '${source}' is not installed. Install it now?`,
|
|
21444
21804
|
initialValue: true
|
|
21445
21805
|
})) throw error;
|
|
@@ -21485,7 +21845,7 @@ const buildAddonConfigOverrides = (addonEntries, addonSpecToName, logger) => {
|
|
|
21485
21845
|
if (src === null) continue;
|
|
21486
21846
|
const cfg = typeof entry === "object" && entry !== null ? entry.config : void 0;
|
|
21487
21847
|
if (typeof cfg !== "object" || cfg === null) continue;
|
|
21488
|
-
const { decks: perDeckRaw, defaults, ...rest } = cfg;
|
|
21848
|
+
const { decks: perDeckRaw, defaults, service: _service, ...rest } = cfg;
|
|
21489
21849
|
const addonName = addonSpecToName.get(src);
|
|
21490
21850
|
if (addonName === void 0) {
|
|
21491
21851
|
logger.warn({ src }, "addon config override targets an addon that failed to load; ignoring");
|
|
@@ -21499,6 +21859,15 @@ const buildAddonConfigOverrides = (addonEntries, addonSpecToName, logger) => {
|
|
|
21499
21859
|
}
|
|
21500
21860
|
return overrides;
|
|
21501
21861
|
};
|
|
21862
|
+
const buildAddonServiceConfigs = (addonEntries, addonSpecToName) => {
|
|
21863
|
+
const configs = /* @__PURE__ */ new Map();
|
|
21864
|
+
for (const entry of addonEntries) {
|
|
21865
|
+
if (typeof entry === "string" || entry.enabled === false) continue;
|
|
21866
|
+
const name = addonSpecToName.get(entry.src);
|
|
21867
|
+
if (name !== void 0 && entry.config?.service !== void 0) configs.set(name, entry.config.service);
|
|
21868
|
+
}
|
|
21869
|
+
return configs;
|
|
21870
|
+
};
|
|
21502
21871
|
const buildRuntime = (options, loaded, keyCount, lockActive = false) => {
|
|
21503
21872
|
const { logger } = options;
|
|
21504
21873
|
const { config, registry, theme, themeDir } = loaded;
|
|
@@ -21587,14 +21956,14 @@ const buildRuntime = (options, loaded, keyCount, lockActive = false) => {
|
|
|
21587
21956
|
buttons: []
|
|
21588
21957
|
}];
|
|
21589
21958
|
const materializedDecks = materializeAddonDecks(registry, effectiveDecks, logger, keyCount, config.lock?.buttons, addonConfigOverrides);
|
|
21590
|
-
const sourceDecks =
|
|
21959
|
+
const sourceDecks = buildAddonSettingsDecks(materializedDecks, registry.listAddons(), keyCount);
|
|
21591
21960
|
const allDecsWithSystemButtons = injectSystemButtons(sourceDecks, keyCount, { lockActive });
|
|
21592
21961
|
const { decks: allDecks, errorsByDeck } = applyConfigErrorReplacements(allDecsWithSystemButtons, config, registry, logger);
|
|
21593
21962
|
const token = process.env["SIRENO_TOKEN"] ?? "";
|
|
21594
21963
|
const configUiUrl = new URL(options.configUiUrl ?? `http://127.0.0.1:${DEFAULT_CONFIG_UI_PORT}/`);
|
|
21595
21964
|
if (token.length > 0) configUiUrl.searchParams.set("token", token);
|
|
21596
21965
|
configUiUrl.hash = "/config";
|
|
21597
|
-
const runtimeDecks = injectConfigUiButton(allDecks, configUiUrl.toString());
|
|
21966
|
+
const runtimeDecks = injectConfigUiButton(allDecks, configUiUrl.toString(), keyCount);
|
|
21598
21967
|
const { runtime, methods, pubSub, store } = createDeckRuntime({
|
|
21599
21968
|
decks: runtimeDecks,
|
|
21600
21969
|
logger
|
|
@@ -21638,7 +22007,7 @@ const applyConfigErrorReplacements = (decks, config, registry, logger) => {
|
|
|
21638
22007
|
if (position === void 0) continue;
|
|
21639
22008
|
if (btn.type.startsWith("core:")) continue;
|
|
21640
22009
|
const path = `decks.${deck.id}.buttons[@position:${position}]`;
|
|
21641
|
-
const { issues, schemaIssues } = validateButton(btn, registry, path, deck.id, position);
|
|
22010
|
+
const { issues, schemaIssues } = validateButton(btn, registry, path, deck.id, position, deck.addonOwner !== void 0 && btn.type.startsWith(`${deck.addonOwner.addonName}:`));
|
|
21642
22011
|
if (issues.length === 0) continue;
|
|
21643
22012
|
const details = schemaIssues.map((i) => `${[...i.path].join(".") || "(root)"}: ${i.message}`).join("; ") || issues.map((i) => i.message).join("; ");
|
|
21644
22013
|
logger.warn({
|
|
@@ -21762,15 +22131,15 @@ const startSystemProviders = async (options, methods) => {
|
|
|
21762
22131
|
url
|
|
21763
22132
|
};
|
|
21764
22133
|
};
|
|
21765
|
-
const browserFrontendMain = (entry) => {
|
|
22134
|
+
const browserFrontendMain = (entry, dedicated = false) => {
|
|
21766
22135
|
const dir = dirname(entry);
|
|
21767
22136
|
const pkgRoot = basename(dir) === "dist" ? dirname(dir) : dir;
|
|
21768
|
-
const src = resolve(pkgRoot, "src", "index.ts");
|
|
22137
|
+
const src = resolve(pkgRoot, "src", dedicated ? "frontend-entry.ts" : "index.ts");
|
|
21769
22138
|
return existsSync(src) ? src : entry;
|
|
21770
22139
|
};
|
|
21771
22140
|
const addonSpecFromScanned = (s) => ({
|
|
21772
22141
|
name: s.name,
|
|
21773
|
-
frontend: s.browserEntry != null ? { main: browserFrontendMain(s.browserEntry) } : s.frontendEntry !== null ? { main: browserFrontendMain(s.frontendEntry) } : void 0,
|
|
22142
|
+
frontend: s.browserEntry != null ? { main: browserFrontendMain(s.browserEntry, s.browserEntry !== s.frontendEntry) } : s.frontendEntry !== null ? { main: browserFrontendMain(s.frontendEntry) } : void 0,
|
|
21774
22143
|
buttons: s.types.map((t) => ({ type: t })),
|
|
21775
22144
|
buttonTypes: Object.fromEntries(Object.entries(s.buttonTypes).map(([type, info]) => [type, info.exportName])),
|
|
21776
22145
|
defaultButton: s.defaultButton
|
|
@@ -22028,7 +22397,8 @@ const runPipeline = async (options) => {
|
|
|
22028
22397
|
});
|
|
22029
22398
|
const externalAddonDirs = buildExternalAddonDirs(loadedConfig.config.addons ?? [], loadedConfig.configPath, loadedConfig.addonEntryPaths);
|
|
22030
22399
|
let resolverOptions = buildResolverOptions(addonBundle.addonByType, [dirname(loadedConfig.configPath)], externalAddonDirs);
|
|
22031
|
-
|
|
22400
|
+
let currentLoadedConfig = loadedConfig;
|
|
22401
|
+
const reInjectedDecks = (isLocked) => buildRuntime(options, currentLoadedConfig, descriptor.keyCount, isLocked).decks;
|
|
22032
22402
|
if (providers.session.getState() === "locked") {
|
|
22033
22403
|
const reInjected = reInjectedDecks(true);
|
|
22034
22404
|
runtime.setDecks(reInjected);
|
|
@@ -22087,11 +22457,10 @@ const runPipeline = async (options) => {
|
|
|
22087
22457
|
presentation?.refresh({ force: true });
|
|
22088
22458
|
});
|
|
22089
22459
|
const serviceDecks = [...decks];
|
|
22090
|
-
let currentLoadedConfig = loadedConfig;
|
|
22091
22460
|
const nextMainDeckId = (config) => config.decks["main"] !== void 0 ? "main" : Object.keys(config.decks)[0] ?? "main";
|
|
22092
22461
|
const requestDeckRebuild = async () => {
|
|
22093
22462
|
if (runtime === null || descriptor === null || outputClient === null || bridge === null || addonBundle === null || loadedConfig === null || providers === null) return;
|
|
22094
|
-
const rebuilt = buildRuntime(options,
|
|
22463
|
+
const rebuilt = buildRuntime(options, currentLoadedConfig, descriptor.keyCount, providers.session.getState() === "locked").decks;
|
|
22095
22464
|
await addonServices?.reconcile(rebuilt);
|
|
22096
22465
|
decks = rebuilt;
|
|
22097
22466
|
serviceDecks.splice(0, serviceDecks.length, ...rebuilt);
|
|
@@ -22126,6 +22495,7 @@ const runPipeline = async (options) => {
|
|
|
22126
22495
|
keyCount: descriptor.keyCount,
|
|
22127
22496
|
resolverOptions,
|
|
22128
22497
|
requestDeckRebuild,
|
|
22498
|
+
addonServiceConfigs: buildAddonServiceConfigs(loadedConfig.config.addons ?? [], loadedConfig.addonSpecToName),
|
|
22129
22499
|
...mainDeck !== void 0 ? { initialDeck: mainDeck } : {},
|
|
22130
22500
|
signal: bridgeSignal.signal,
|
|
22131
22501
|
store,
|
|
@@ -23481,11 +23851,11 @@ const enableClaudeHooks = () => {
|
|
|
23481
23851
|
const onboardClaudeCode = async (options) => {
|
|
23482
23852
|
if (isClaudeHookInstalled() && isClaudeHookEnabled()) return false;
|
|
23483
23853
|
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({
|
|
23854
|
+
const answer = options.yes === true ? true : await confirm$1({
|
|
23485
23855
|
message: "Add the Claude Code session-state hooks now?",
|
|
23486
23856
|
initialValue: true
|
|
23487
23857
|
});
|
|
23488
|
-
if (isCancel(answer) || !answer) return false;
|
|
23858
|
+
if (isCancel$1(answer) || !answer) return false;
|
|
23489
23859
|
installClaudeHook();
|
|
23490
23860
|
if (!enableClaudeHooks()) {
|
|
23491
23861
|
note(`Could not update ${claudeSettingsPath()} because it is not valid JSON. Nothing was changed.`, "Claude Code integration");
|
|
@@ -23504,11 +23874,11 @@ const onboardCodingAgents = async (configPath, options = {}) => {
|
|
|
23504
23874
|
let changed = false;
|
|
23505
23875
|
if (!openCodeDone) {
|
|
23506
23876
|
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({
|
|
23877
|
+
const answer = options.yes === true ? true : await confirm$1({
|
|
23508
23878
|
message: "Install the OpenCode instance-state plugin now?",
|
|
23509
23879
|
initialValue: true
|
|
23510
23880
|
});
|
|
23511
|
-
if (!isCancel(answer) && answer) {
|
|
23881
|
+
if (!isCancel$1(answer) && answer) {
|
|
23512
23882
|
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
23883
|
else {
|
|
23514
23884
|
const installedPath = installOpenCodePlugin(openCodeMajorVersion);
|
|
@@ -23633,11 +24003,11 @@ const reProbeCapability = async (step, deps) => {
|
|
|
23633
24003
|
const runDarwinAccessibilityStep = async (yesBatched) => {
|
|
23634
24004
|
if (await hasDarwinAccessibility(realExecutor)) return "installed";
|
|
23635
24005
|
if (!yesBatched) {
|
|
23636
|
-
const shouldOpen = await confirm({
|
|
24006
|
+
const shouldOpen = await confirm$1({
|
|
23637
24007
|
message: "Open System Settings at Privacy & Security → Accessibility?",
|
|
23638
24008
|
initialValue: true
|
|
23639
24009
|
});
|
|
23640
|
-
if (isCancel(shouldOpen) || !shouldOpen) return "manual";
|
|
24010
|
+
if (isCancel$1(shouldOpen) || !shouldOpen) return "manual";
|
|
23641
24011
|
}
|
|
23642
24012
|
if (!await openSettingsUrl(realExecutor, "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility")) {
|
|
23643
24013
|
log$1.warn("Could not open System Settings automatically.");
|
|
@@ -23645,11 +24015,11 @@ const runDarwinAccessibilityStep = async (yesBatched) => {
|
|
|
23645
24015
|
}
|
|
23646
24016
|
log$1.info(`Enable ${color.green(appNeedingAccessibility())} in the list that just opened.`);
|
|
23647
24017
|
if (yesBatched) return "manual";
|
|
23648
|
-
const granted = await confirm({
|
|
24018
|
+
const granted = await confirm$1({
|
|
23649
24019
|
message: "Granted? (re-checks the permission)",
|
|
23650
24020
|
initialValue: true
|
|
23651
24021
|
});
|
|
23652
|
-
if (isCancel(granted) || !granted) return "manual";
|
|
24022
|
+
if (isCancel$1(granted) || !granted) return "manual";
|
|
23653
24023
|
if (await hasDarwinAccessibility(realExecutor)) return "installed";
|
|
23654
24024
|
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
24025
|
return "manual";
|
|
@@ -23669,11 +24039,11 @@ const runInstallStep = async (step, yesBatched, logger, deps) => {
|
|
|
23669
24039
|
s.start(`Checking ${step.packages.join(", ")}`);
|
|
23670
24040
|
s.stop(`${step.packages.join(", ")} not found — install needed`);
|
|
23671
24041
|
if (!yesBatched) {
|
|
23672
|
-
const shouldRun = await confirm({
|
|
24042
|
+
const shouldRun = await confirm$1({
|
|
23673
24043
|
message: `Install ${step.title}?`,
|
|
23674
24044
|
initialValue: !step.sudo
|
|
23675
24045
|
});
|
|
23676
|
-
if (isCancel(shouldRun) || !shouldRun) return "skipped";
|
|
24046
|
+
if (isCancel$1(shouldRun) || !shouldRun) return "skipped";
|
|
23677
24047
|
}
|
|
23678
24048
|
let command;
|
|
23679
24049
|
let args;
|
|
@@ -23760,11 +24130,11 @@ const runInstallStep = async (step, yesBatched, logger, deps) => {
|
|
|
23760
24130
|
};
|
|
23761
24131
|
const runUdevStep = async (step, yesBatched, logger) => {
|
|
23762
24132
|
if (!yesBatched) {
|
|
23763
|
-
const shouldRun = await confirm({
|
|
24133
|
+
const shouldRun = await confirm$1({
|
|
23764
24134
|
message: `Install udev rules to ${process.platform === "linux" ? "/etc/udev/rules.d/70-sirenodeck.rules" : "system location"}?`,
|
|
23765
24135
|
initialValue: false
|
|
23766
24136
|
});
|
|
23767
|
-
if (isCancel(shouldRun) || !shouldRun) return "skipped";
|
|
24137
|
+
if (isCancel$1(shouldRun) || !shouldRun) return "skipped";
|
|
23768
24138
|
}
|
|
23769
24139
|
const nopasswd = await isSudoNopasswd();
|
|
23770
24140
|
let password = "";
|
|
@@ -23824,11 +24194,11 @@ const runConfigSeed = async (report, options, logger) => {
|
|
|
23824
24194
|
logger.warn({ path: report.config.path }, "config missing and non-interactive mode — skipping seed");
|
|
23825
24195
|
return false;
|
|
23826
24196
|
}
|
|
23827
|
-
const shouldSeed = await confirm({
|
|
24197
|
+
const shouldSeed = await confirm$1({
|
|
23828
24198
|
message: `Seed default config to ${report.config.path}?`,
|
|
23829
24199
|
initialValue: true
|
|
23830
24200
|
});
|
|
23831
|
-
if (isCancel(shouldSeed) || !shouldSeed) return false;
|
|
24201
|
+
if (isCancel$1(shouldSeed) || !shouldSeed) return false;
|
|
23832
24202
|
const s = spinner();
|
|
23833
24203
|
s.start(`Seeding ${report.config.path}`);
|
|
23834
24204
|
try {
|
|
@@ -24033,11 +24403,11 @@ const installConfigSkill = async (options = {}) => {
|
|
|
24033
24403
|
intro("sirenodeck skills");
|
|
24034
24404
|
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
24405
|
if (!yes && options.confirmed !== true) {
|
|
24036
|
-
const answer = await confirm({
|
|
24406
|
+
const answer = await confirm$1({
|
|
24037
24407
|
message: "Install the Sireno Deck config skill globally?",
|
|
24038
24408
|
initialValue: false
|
|
24039
24409
|
});
|
|
24040
|
-
if (isCancel(answer) || !answer) {
|
|
24410
|
+
if (isCancel$1(answer) || !answer) {
|
|
24041
24411
|
log$1.info("Skill installation cancelled.");
|
|
24042
24412
|
return false;
|
|
24043
24413
|
}
|
|
@@ -24088,11 +24458,11 @@ const offerPath = () => join(process.env["XDG_CONFIG_HOME"] ?? join(homedir(), "
|
|
|
24088
24458
|
const offerConfigSkillOnFirstRun = async () => {
|
|
24089
24459
|
if (process.stdin.isTTY !== true || existsSync(offerPath())) return;
|
|
24090
24460
|
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({
|
|
24461
|
+
const answer = await confirm$1({
|
|
24092
24462
|
message: "Install the Sireno Deck skill for your coding agent?",
|
|
24093
24463
|
initialValue: false
|
|
24094
24464
|
});
|
|
24095
|
-
if (isCancel(answer) || !answer) {
|
|
24465
|
+
if (isCancel$1(answer) || !answer) {
|
|
24096
24466
|
saveOfferChoice("declined");
|
|
24097
24467
|
return;
|
|
24098
24468
|
}
|
|
@@ -24374,24 +24744,6 @@ const killPortListeners = async (ports, logger) => {
|
|
|
24374
24744
|
}
|
|
24375
24745
|
await new Promise((r) => setTimeout(r, 500));
|
|
24376
24746
|
};
|
|
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
24747
|
const stopExisting = async (pid, logger) => {
|
|
24396
24748
|
if (!isRunning(pid)) {
|
|
24397
24749
|
logger.warn({ pid }, "existing pid file is stale, removing");
|
|
@@ -24404,28 +24756,16 @@ const stopExisting = async (pid, logger) => {
|
|
|
24404
24756
|
removeStartLock();
|
|
24405
24757
|
return;
|
|
24406
24758
|
}
|
|
24759
|
+
if (!isOurDaemon(pid)) throw new Error(`Refusing to stop unverified daemon PID ${pid}`);
|
|
24407
24760
|
logger.info({ pid }, "stopping existing daemon");
|
|
24408
24761
|
try {
|
|
24409
24762
|
process.kill(pid, "SIGTERM");
|
|
24410
24763
|
} catch (err) {
|
|
24411
|
-
|
|
24412
|
-
err,
|
|
24413
|
-
pid
|
|
24414
|
-
}, "failed to send SIGTERM to existing daemon");
|
|
24764
|
+
throw new Error(`Failed to stop existing daemon ${pid}`, { cause: err });
|
|
24415
24765
|
}
|
|
24416
|
-
const deadline = Date.now() +
|
|
24766
|
+
const deadline = Date.now() + 2e4;
|
|
24417
24767
|
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
|
-
}
|
|
24768
|
+
if (isRunning(pid)) throw new Error(`Existing daemon ${pid} did not exit after SIGTERM`);
|
|
24429
24769
|
await terminateChildren({
|
|
24430
24770
|
logger,
|
|
24431
24771
|
timeoutMs: 2e3
|
|
@@ -24719,7 +25059,7 @@ const runFirstRunCheckIfNeeded = async (options, logger) => {
|
|
|
24719
25059
|
process.exitCode = 1;
|
|
24720
25060
|
return false;
|
|
24721
25061
|
}
|
|
24722
|
-
if (!await confirm({
|
|
25062
|
+
if (!await confirm$1({
|
|
24723
25063
|
message: "It looks like this is your first run (missing config or system capabilities). Run the setup wizard now?",
|
|
24724
25064
|
initialValue: true
|
|
24725
25065
|
})) {
|
|
@@ -24754,36 +25094,17 @@ const start = async (options) => {
|
|
|
24754
25094
|
logger.warn({ err: error }, "start: agent skill offer failed, continuing");
|
|
24755
25095
|
}
|
|
24756
25096
|
await onboardCodingAgents(resolveConfigPath(options).path);
|
|
25097
|
+
if (isUnitInstalled()) await invokeManager({
|
|
25098
|
+
action: "stop",
|
|
25099
|
+
logger
|
|
25100
|
+
});
|
|
24757
25101
|
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
|
-
}
|
|
25102
|
+
const lockHeld = await isSocketLive(instanceLockPath(resolveDaemonPaths()));
|
|
25103
|
+
if (lockHeld || existing !== null && isRunning(existing)) {
|
|
25104
|
+
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
25105
|
if (existing !== null) await stopExisting(existing, logger);
|
|
24786
|
-
else
|
|
25106
|
+
else throw new Error("A daemon holds the instance lock but has no PID; refusing to stop an unidentified process");
|
|
25107
|
+
if (await isSocketLive(instanceLockPath(resolveDaemonPaths()))) throw new Error("The previous daemon still holds the instance lock");
|
|
24787
25108
|
removePidFile();
|
|
24788
25109
|
removeDaemonControl(resolveDaemonPaths());
|
|
24789
25110
|
removeRuntimeStateFile();
|
|
@@ -25118,6 +25439,10 @@ const killGracefully = async (pid, logger, label) => {
|
|
|
25118
25439
|
}
|
|
25119
25440
|
};
|
|
25120
25441
|
const stop = async ({ logger }) => {
|
|
25442
|
+
if (isUnitInstalled()) await invokeManager({
|
|
25443
|
+
action: "stop",
|
|
25444
|
+
logger
|
|
25445
|
+
});
|
|
25121
25446
|
const pid = readPid();
|
|
25122
25447
|
if (pid === null) {
|
|
25123
25448
|
logger.info("stop: no running daemon found");
|
|
@@ -25304,6 +25629,143 @@ const openBrowser = (url, logger, noOpen = false) => {
|
|
|
25304
25629
|
});
|
|
25305
25630
|
};
|
|
25306
25631
|
//#endregion
|
|
25632
|
+
//#region src/cli/commands/addon-setup-config.ts
|
|
25633
|
+
const saveAddonProvider = async (path, addonName, provider) => {
|
|
25634
|
+
const mutation = createConfigMutationService({ configPath: path });
|
|
25635
|
+
const candidates = [];
|
|
25636
|
+
for (const source of mutation.sources()) {
|
|
25637
|
+
const doc = parseDocument(readFileSync(source, "utf8"));
|
|
25638
|
+
if (doc.errors.length) continue;
|
|
25639
|
+
const addons = doc.get("addons");
|
|
25640
|
+
if (!isSeq(addons)) continue;
|
|
25641
|
+
addons.items.forEach((item, index) => {
|
|
25642
|
+
const value = isMap(item) ? item.get("src") : isScalar(item) ? item.value : void 0;
|
|
25643
|
+
if (typeof value !== "string") return;
|
|
25644
|
+
const base = basename(value.replace(/\/$/, ""));
|
|
25645
|
+
let name = base === addonName || base === `addon-${addonName}`;
|
|
25646
|
+
const manifestPath = resolve(dirname(source), value, "sirenodeck.json");
|
|
25647
|
+
if (!name && existsSync(manifestPath)) try {
|
|
25648
|
+
name = JSON.parse(readFileSync(manifestPath, "utf8")).name === addonName;
|
|
25649
|
+
} catch {}
|
|
25650
|
+
if (name) candidates.push({
|
|
25651
|
+
path: source,
|
|
25652
|
+
index
|
|
25653
|
+
});
|
|
25654
|
+
});
|
|
25655
|
+
}
|
|
25656
|
+
if (candidates.length !== 1) throw new Error(`Expected one ${addonName} addon entry; found ${candidates.length}`);
|
|
25657
|
+
const target = candidates[0];
|
|
25658
|
+
const document = parseDocument(mutation.readSource(target.path), { keepSourceTokens: true });
|
|
25659
|
+
const addonPath = ["addons", target.index];
|
|
25660
|
+
const item = document.getIn(addonPath);
|
|
25661
|
+
if (!isMap(item)) {
|
|
25662
|
+
const src = typeof item === "string" ? item : isScalar(item) ? item.value : void 0;
|
|
25663
|
+
if (typeof src !== "string") throw new Error("Invalid addon entry");
|
|
25664
|
+
document.setIn(addonPath, document.createNode({ src }));
|
|
25665
|
+
}
|
|
25666
|
+
const providersPath = [
|
|
25667
|
+
...addonPath,
|
|
25668
|
+
"config",
|
|
25669
|
+
"service",
|
|
25670
|
+
"providers"
|
|
25671
|
+
];
|
|
25672
|
+
let providers = document.getIn(providersPath);
|
|
25673
|
+
if (providers === void 0) {
|
|
25674
|
+
document.setIn(providersPath, []);
|
|
25675
|
+
providers = document.getIn(providersPath);
|
|
25676
|
+
}
|
|
25677
|
+
if (!isSeq(providers)) throw new Error("Calendar providers must be a list");
|
|
25678
|
+
const matches = providers.items.filter((entry) => isMap(entry) && entry.get("id") === provider.id);
|
|
25679
|
+
if (matches.length > 1) throw new Error("Duplicate calendar account IDs in config");
|
|
25680
|
+
if (matches.length === 1) {
|
|
25681
|
+
const existing = matches[0];
|
|
25682
|
+
if (!isMap(existing) || existing.get("type") !== provider.type) throw new Error("Account ID is already used by another provider");
|
|
25683
|
+
for (const [key, value] of Object.entries(provider)) existing.set(key, value);
|
|
25684
|
+
} else providers.add(provider);
|
|
25685
|
+
await mutation.apply({
|
|
25686
|
+
kind: "edit-source",
|
|
25687
|
+
path: target.path,
|
|
25688
|
+
content: document.toString()
|
|
25689
|
+
});
|
|
25690
|
+
};
|
|
25691
|
+
//#endregion
|
|
25692
|
+
//#region src/cli/commands/addon-setup.ts
|
|
25693
|
+
const addonSetupCommand = {
|
|
25694
|
+
command: "addon-setup <module>",
|
|
25695
|
+
describe: "Run an installed addon's interactive setup module",
|
|
25696
|
+
builder: (yargs) => yargs.positional("module", {
|
|
25697
|
+
type: "string",
|
|
25698
|
+
demandOption: true,
|
|
25699
|
+
description: "Path to the addon's setup module"
|
|
25700
|
+
}),
|
|
25701
|
+
handler: async ({ module }) => {
|
|
25702
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) throw new Error("Addon setup requires an interactive terminal");
|
|
25703
|
+
const setup = await import(pathToFileURL(resolve(module)).href);
|
|
25704
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(setup.addonName) || typeof setup.setupAddon !== "function") throw new Error("Invalid addon setup module");
|
|
25705
|
+
const logger = createLogger({});
|
|
25706
|
+
const pid = readPid();
|
|
25707
|
+
let configPath = pid !== null && isRunning(pid) ? readConfigPath() : null;
|
|
25708
|
+
await setup.setupAddon({
|
|
25709
|
+
credentials: scopeCredentials(createNativeCredentialBackend(), setup.addonName),
|
|
25710
|
+
openUrl: (url) => {
|
|
25711
|
+
console.log(`Open this URL if your browser does not start:\n${url}`);
|
|
25712
|
+
openBrowser(url, logger);
|
|
25713
|
+
},
|
|
25714
|
+
text: async (message, secret) => {
|
|
25715
|
+
const value = secret ? await password({ message }) : await text({ message });
|
|
25716
|
+
if (isCancel(value)) throw new Error("Addon setup cancelled");
|
|
25717
|
+
return value;
|
|
25718
|
+
},
|
|
25719
|
+
selectMany: async (message, options) => {
|
|
25720
|
+
const value = await multiselect({
|
|
25721
|
+
message,
|
|
25722
|
+
options: options.map(({ color, ...option }) => {
|
|
25723
|
+
const useColor = process.stdout.isTTY && process.env["NO_COLOR"] === void 0 && process.env["TERM"] !== "dumb";
|
|
25724
|
+
const hex = /^#[0-9a-f]{6}$/i.test(color ?? "") ? color.slice(1) : void 0;
|
|
25725
|
+
const rgb = hex === void 0 ? void 0 : [
|
|
25726
|
+
0,
|
|
25727
|
+
2,
|
|
25728
|
+
4
|
|
25729
|
+
].map((i) => parseInt(hex.slice(i, i + 2), 16));
|
|
25730
|
+
const marker = rgb && useColor ? `\x1b[38;2;${rgb.join(";")}m■\x1b[0m` : "■";
|
|
25731
|
+
return {
|
|
25732
|
+
...option,
|
|
25733
|
+
label: `${marker} ${useColor ? styleText("white", option.label) : option.label}`
|
|
25734
|
+
};
|
|
25735
|
+
}),
|
|
25736
|
+
required: true
|
|
25737
|
+
});
|
|
25738
|
+
if (isCancel(value)) throw new Error("Addon setup cancelled");
|
|
25739
|
+
return value;
|
|
25740
|
+
},
|
|
25741
|
+
confirm: async (message) => {
|
|
25742
|
+
const value = await confirm({
|
|
25743
|
+
message,
|
|
25744
|
+
initialValue: false
|
|
25745
|
+
});
|
|
25746
|
+
if (isCancel(value)) throw new Error("Addon setup cancelled");
|
|
25747
|
+
return value;
|
|
25748
|
+
},
|
|
25749
|
+
saveProvider: async (provider) => {
|
|
25750
|
+
if (!configPath) {
|
|
25751
|
+
const value = await text({ message: "Config file path (leave blank for manual instructions)" });
|
|
25752
|
+
if (isCancel(value)) throw new Error("Addon setup cancelled");
|
|
25753
|
+
if (!value.trim()) return null;
|
|
25754
|
+
configPath = resolveUserPath(value.trim());
|
|
25755
|
+
}
|
|
25756
|
+
try {
|
|
25757
|
+
await saveAddonProvider(configPath, setup.addonName, provider);
|
|
25758
|
+
return configPath;
|
|
25759
|
+
} catch (error) {
|
|
25760
|
+
console.error(`Could not update config: ${error instanceof Error ? error.message : String(error)}`);
|
|
25761
|
+
return null;
|
|
25762
|
+
}
|
|
25763
|
+
},
|
|
25764
|
+
print: (message) => console.log(message)
|
|
25765
|
+
});
|
|
25766
|
+
}
|
|
25767
|
+
};
|
|
25768
|
+
//#endregion
|
|
25307
25769
|
//#region src/cli/index.ts
|
|
25308
25770
|
const buildLogger = (argv) => {
|
|
25309
25771
|
const normalized = argv.logLevel === "none" ? "silent" : argv.logLevel;
|
|
@@ -25508,6 +25970,7 @@ const buildCli = async () => {
|
|
|
25508
25970
|
logsCommand,
|
|
25509
25971
|
systemRequirementsCommand,
|
|
25510
25972
|
installCommand,
|
|
25973
|
+
addonSetupCommand,
|
|
25511
25974
|
skillsCommand
|
|
25512
25975
|
],
|
|
25513
25976
|
packageName: PACKAGE_NAME,
|