kiosko 0.2.7 → 0.2.9
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/README.md +45 -3
- package/cli.js +1374 -190
- package/package.json +7 -1
- package/screen-thread.js +387 -11
- package/sdk.js +28 -5
- package/web/assets/app.js +69 -3
- package/web/assets/styles.css +1 -1
package/cli.js
CHANGED
|
@@ -1138,9 +1138,9 @@ var init_testing = __esm({
|
|
|
1138
1138
|
});
|
|
1139
1139
|
|
|
1140
1140
|
// packages/server/src/cli.ts
|
|
1141
|
-
import { spawn } from "node:child_process";
|
|
1142
|
-
import { existsSync as
|
|
1143
|
-
import { dirname as
|
|
1141
|
+
import { spawn as spawn3 } from "node:child_process";
|
|
1142
|
+
import { existsSync as existsSync18, readFileSync as readFileSync12, writeFileSync as writeFileSync13 } from "node:fs";
|
|
1143
|
+
import { dirname as dirname9, join as join20 } from "node:path";
|
|
1144
1144
|
|
|
1145
1145
|
// packages/core/src/config/model.ts
|
|
1146
1146
|
init_workday();
|
|
@@ -1228,6 +1228,11 @@ function inQuietHours(quiet, now) {
|
|
|
1228
1228
|
var READING_CM = { near: 40, normal: 60, far: 90 };
|
|
1229
1229
|
var TEXT_SCALE = { min: 0.75, max: 2, step: 0.05 };
|
|
1230
1230
|
var DEFAULT_MAX_BYTES = 48e4;
|
|
1231
|
+
var SETUP_STATES = ["pending", "done", "skipped"];
|
|
1232
|
+
var STARTER_NAMES = {
|
|
1233
|
+
screen: { en: "My panel", es: "Mi panel", de: "Mein Panel", "zh-Hant": "\u6211\u7684\u9762\u677F", "zh-Hans": "\u6211\u7684\u5C4F\u5E55" },
|
|
1234
|
+
page: { en: "Home", es: "Inicio", de: "Start", "zh-Hant": "\u9996\u9801", "zh-Hans": "\u9996\u9875" }
|
|
1235
|
+
};
|
|
1231
1236
|
var counter = 0;
|
|
1232
1237
|
function newId(prefix = "id") {
|
|
1233
1238
|
counter = (counter + 1) % 1296;
|
|
@@ -1367,14 +1372,14 @@ var CATEGORIES = [
|
|
|
1367
1372
|
{ id: "time", label: { en: "Time & calendar", es: "Tiempo y agenda", de: "Zeit & Kalender", "zh-Hant": "\u6642\u9593\u8207\u884C\u4E8B\u66C6", "zh-Hans": "\u65F6\u95F4\u4E0E\u65E5\u5386" } },
|
|
1368
1373
|
{ id: "productivity", label: { en: "Productivity", es: "Productividad", de: "Produktivit\xE4t", "zh-Hant": "\u751F\u7522\u529B", "zh-Hans": "\u6548\u7387" } },
|
|
1369
1374
|
{ id: "dev", label: { en: "Development", es: "Desarrollo", de: "Entwicklung", "zh-Hant": "\u958B\u767C", "zh-Hans": "\u5F00\u53D1" } },
|
|
1370
|
-
{ id: "info", label: { en: "News & world", es: "Noticias y mundo", de: "Nachrichten & Welt", "zh-Hant": "\
|
|
1375
|
+
{ id: "info", label: { en: "News & world", es: "Noticias y mundo", de: "Nachrichten & Welt", "zh-Hant": "\u8CC7\u8A0A\u8207\u751F\u6D3B", "zh-Hans": "\u8D44\u8BAF\u4E0E\u751F\u6D3B" } },
|
|
1371
1376
|
{ id: "media", label: { en: "Media", es: "Multimedia", de: "Medien", "zh-Hant": "\u591A\u5A92\u9AD4", "zh-Hans": "\u591A\u5A92\u4F53" } },
|
|
1372
1377
|
{ id: "scene", label: { en: "Scenes", es: "Escenas", de: "Szenen", "zh-Hant": "\u5834\u666F", "zh-Hans": "\u573A\u666F" } },
|
|
1373
1378
|
{ id: "fun", label: { en: "Fun", es: "Diversi\xF3n", de: "Spa\xDF", "zh-Hant": "\u8DA3\u5473", "zh-Hans": "\u8DA3\u5473" } }
|
|
1374
1379
|
];
|
|
1375
1380
|
var ALERT_LEVELS = ["info", "warn", "critical"];
|
|
1376
1381
|
var PAD_KEYS = ["up", "down", "left", "right", "a", "b", "x", "y", "l", "r", "start", "select"];
|
|
1377
|
-
var SDK_VERSION = "0.2.
|
|
1382
|
+
var SDK_VERSION = "0.2.9";
|
|
1378
1383
|
function defineWidget(w) {
|
|
1379
1384
|
return w;
|
|
1380
1385
|
}
|
|
@@ -1389,9 +1394,9 @@ init_i18n();
|
|
|
1389
1394
|
|
|
1390
1395
|
// packages/sdk/src/languages.ts
|
|
1391
1396
|
var MAINLAND_CHINA = {
|
|
1392
|
-
without: [
|
|
1393
|
-
first: ["llm", "gpu"],
|
|
1394
|
-
instead: { "
|
|
1397
|
+
without: [],
|
|
1398
|
+
first: ["llm", "gpu", "usage"],
|
|
1399
|
+
instead: { "usage/rail": "usage/balance", "usage/blocks": "usage/agents" }
|
|
1395
1400
|
};
|
|
1396
1401
|
var LANGUAGES = [
|
|
1397
1402
|
{ id: "en", name: "English", panel: "en", ogLocale: "en_US", hreflang: ["en", "x-default"], dir: "ltr" },
|
|
@@ -1734,7 +1739,7 @@ var paths = {
|
|
|
1734
1739
|
init_format();
|
|
1735
1740
|
init_workday();
|
|
1736
1741
|
function normalize(raw) {
|
|
1737
|
-
const { $schema, threads, ...c } = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
|
|
1742
|
+
const { $schema, threads, setup, bootAnimation, ...c } = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
|
|
1738
1743
|
const screens = Array.isArray(c.screens) ? c.screens.map(normalizeScreen) : [];
|
|
1739
1744
|
return {
|
|
1740
1745
|
...typeof $schema === "string" && $schema ? { $schema } : {},
|
|
@@ -1749,6 +1754,9 @@ function normalize(raw) {
|
|
|
1749
1754
|
server: { ...DEFAULT_CONFIG.server, ...c.server ?? {} },
|
|
1750
1755
|
...c.homeassistant && typeof c.homeassistant === "object" ? { homeassistant: normalizeHa(c.homeassistant) } : {},
|
|
1751
1756
|
...THREADS_MODES.includes(threads) ? { threads } : {},
|
|
1757
|
+
...SETUP_STATES.includes(setup) ? { setup } : {},
|
|
1758
|
+
// On unless switched off: only `false` is written.
|
|
1759
|
+
...bootAnimation === false ? { bootAnimation: false } : {},
|
|
1752
1760
|
screens
|
|
1753
1761
|
};
|
|
1754
1762
|
}
|
|
@@ -2094,6 +2102,11 @@ function configSchema(plugins) {
|
|
|
2094
2102
|
default: "auto",
|
|
2095
2103
|
description: `Paint each screen in a thread of its own, so a slow widget on one does not slow the others: "auto" (with two or more screens on and a core to spare for each), "always", or "never" (every screen on the main thread: less memory, for a small machine). A screen's "thread" overrides it.`
|
|
2096
2104
|
},
|
|
2105
|
+
setup: {
|
|
2106
|
+
enum: ["pending", "done", "skipped"],
|
|
2107
|
+
description: `The editor's first-run setup: "pending" as the first run writes it (the panels say how to open the editor), then "done" or "skipped", so it is not offered on its own again (Settings can always run it). Missing: offered while the config is still the first run's.`
|
|
2108
|
+
},
|
|
2109
|
+
bootAnimation: { type: "boolean", default: true, description: "A short animation of the Kiosko mark on every panel when Kiosko starts, before the pages." },
|
|
2097
2110
|
homeassistant: {
|
|
2098
2111
|
type: "object",
|
|
2099
2112
|
additionalProperties: false,
|
|
@@ -3002,11 +3015,11 @@ function mergeSecrets(incoming, current, schema2) {
|
|
|
3002
3015
|
changed = false;
|
|
3003
3016
|
kept.forEach((k, i) => {
|
|
3004
3017
|
if (reverted.has(i)) return;
|
|
3005
|
-
const
|
|
3006
|
-
if (!
|
|
3018
|
+
const why2 = hostMoved(schema2, out, k.a.path, current, k.from.path, k.from.holder);
|
|
3019
|
+
if (!why2) return;
|
|
3007
3020
|
setAt(out, k.a.path, "");
|
|
3008
3021
|
reverted.add(i);
|
|
3009
|
-
toFill.push(item(k.a,
|
|
3022
|
+
toFill.push(item(k.a, why2));
|
|
3010
3023
|
changed = true;
|
|
3011
3024
|
});
|
|
3012
3025
|
}
|
|
@@ -3072,6 +3085,69 @@ function localizeSample(cfg, locale) {
|
|
|
3072
3085
|
};
|
|
3073
3086
|
}
|
|
3074
3087
|
|
|
3088
|
+
// packages/core/src/config/starter.ts
|
|
3089
|
+
init_i18n();
|
|
3090
|
+
function marketOf(locale) {
|
|
3091
|
+
const market = languageById(pickLocale(LANGUAGE_IDS, locale ?? "en") ?? "en")?.plugins;
|
|
3092
|
+
return {
|
|
3093
|
+
offered: (t2) => !market?.without.includes(t2.split("/")[0]) && !market?.instead[t2],
|
|
3094
|
+
instead: (t2) => market?.instead[t2]
|
|
3095
|
+
};
|
|
3096
|
+
}
|
|
3097
|
+
function starterPage(has, o) {
|
|
3098
|
+
const { width, height } = o;
|
|
3099
|
+
const L = (t2) => localize(t2, o.locale ?? "en");
|
|
3100
|
+
const { offered } = marketOf(o.locale);
|
|
3101
|
+
const ok = (t2) => offered(t2) && has(t2) && (o.weather !== false || !t2.startsWith("weather/"));
|
|
3102
|
+
const page = newPage(o.name ?? L(STARTER_NAMES.page), width, height);
|
|
3103
|
+
page.grid = { cols: 24, rows: 6, gap: 10, padding: 10 };
|
|
3104
|
+
page.gravity = "left";
|
|
3105
|
+
const tiles = [];
|
|
3106
|
+
const add = (r, types2, title) => {
|
|
3107
|
+
const ws = types2.filter((t2) => ok(typeof t2 === "string" ? t2 : t2[0])).map((t2) => typeof t2 === "string" ? newWidget(t2, {}, title) : newWidget(t2[0], { ...t2[1] }, title));
|
|
3108
|
+
if (ws.length) tiles.push(newTile(r, ws));
|
|
3109
|
+
};
|
|
3110
|
+
const lead = "agents/sessions";
|
|
3111
|
+
const agents = o.agents !== false && ok(lead);
|
|
3112
|
+
if (agents) {
|
|
3113
|
+
add({ x: 0, y: 0, w: 11, h: 6 }, [lead]);
|
|
3114
|
+
add({ x: 11, y: 0, w: 5, h: 4 }, ["core/clock"]);
|
|
3115
|
+
} else {
|
|
3116
|
+
add({ x: 0, y: 0, w: 11, h: 6 }, [["core/clock", { showDate: true }]]);
|
|
3117
|
+
add({ x: 11, y: 0, w: 5, h: 4 }, ["core/date"]);
|
|
3118
|
+
}
|
|
3119
|
+
add({ x: 11, y: 4, w: 5, h: 2 }, ["weather/forecast", "mirror/compliments"]);
|
|
3120
|
+
add({ x: 16, y: 0, w: 8, h: 6 }, ["vitals/vitals", "system/health", "usage/rail", "mirror/countdown"].filter(ok).slice(0, 3));
|
|
3121
|
+
if (!tiles.length) {
|
|
3122
|
+
add({ x: 0, y: 0, w: 24, h: 6 }, ["core/text"], L({ en: "Welcome", es: "Bienvenida", de: "Willkommen", "zh-Hant": "\u6B61\u8FCE", "zh-Hans": "\u6B22\u8FCE" }));
|
|
3123
|
+
const welcome = tiles[0]?.widgets[0];
|
|
3124
|
+
if (welcome) welcome.options = { text: L({ en: "Hi there.\nDrag widgets from the library to build your panel.", es: "Hola.\nArrastra widgets desde la biblioteca para montar tu panel.", de: "Hallo!\nZieh Widgets aus der Bibliothek, um dein Panel zu gestalten.", "zh-Hant": "\u4F60\u597D\u3002\n\u5F9E\u5C0F\u5DE5\u5177\u5EAB\u62D6\u66F3\u5C0F\u5DE5\u5177\uFF0C\n\u6253\u9020\u4F60\u7684\u9762\u677F\u3002", "zh-Hans": "\u4F60\u597D\u3002\n\u4ECE\u7EC4\u4EF6\u5E93\u62D6\u52A8\u5C0F\u7EC4\u4EF6\uFF0C\n\u5E03\u7F6E\u4F60\u7684\u526F\u5C4F\u3002" }), maxSize: 54 };
|
|
3125
|
+
}
|
|
3126
|
+
page.tiles = tiles;
|
|
3127
|
+
if (height > width) transposePage(page, width, height);
|
|
3128
|
+
else {
|
|
3129
|
+
const grid = suggestGrid(width, height);
|
|
3130
|
+
page.tiles = rescale(page.tiles, page.grid, grid);
|
|
3131
|
+
page.grid = grid;
|
|
3132
|
+
}
|
|
3133
|
+
return page;
|
|
3134
|
+
}
|
|
3135
|
+
function starterInterludes(hasInterlude, locale) {
|
|
3136
|
+
return marketOf(locale).offered("agents/runner") && hasInterlude("agents/runner") ? [{ id: "interlude-runner", type: "agents/runner", enabled: false, everyMs: 15 * 6e4, maxSeconds: 30, options: {} }] : [];
|
|
3137
|
+
}
|
|
3138
|
+
var STARTER_TYPES = /* @__PURE__ */ new Set(["agents/sessions", "core/text", "core/clock", "core/date", "weather/forecast", "mirror/compliments", "usage/rail", "vitals/vitals", "system/health", "mirror/countdown"]);
|
|
3139
|
+
function looksLikeStarter(c) {
|
|
3140
|
+
if (c.screens.length !== 1) return false;
|
|
3141
|
+
const s = c.screens[0];
|
|
3142
|
+
const named = (name, names) => Object.values(names).includes(name);
|
|
3143
|
+
if (s.device.driver !== "virtual" || !named(s.name, STARTER_NAMES.screen) || s.pages.length !== 1) return false;
|
|
3144
|
+
const p = s.pages[0];
|
|
3145
|
+
return named(p.name, STARTER_NAMES.page) && p.tiles.length <= 4 && p.tiles.every((t2) => t2.widgets.every((w) => STARTER_TYPES.has(w.type)));
|
|
3146
|
+
}
|
|
3147
|
+
function offersSetup(c) {
|
|
3148
|
+
return c.setup === "pending" || !c.setup && (c.screens.length === 0 || looksLikeStarter(c));
|
|
3149
|
+
}
|
|
3150
|
+
|
|
3075
3151
|
// packages/core/src/layout/stack.ts
|
|
3076
3152
|
function pickInStack(entries, now, rotateMs) {
|
|
3077
3153
|
const urgent = entries.find((e) => e.visible && e.urgent);
|
|
@@ -3295,9 +3371,9 @@ var FontFallback = class {
|
|
|
3295
3371
|
memo = /* @__PURE__ */ new Map();
|
|
3296
3372
|
/** Sets the families; true if they changed (callers then forget measured widths). */
|
|
3297
3373
|
setFamilies(families) {
|
|
3298
|
-
const
|
|
3299
|
-
if (
|
|
3300
|
-
this.tail =
|
|
3374
|
+
const tail2 = families.map((f) => `, "${f.replace(/"/g, "")}"`).join("");
|
|
3375
|
+
if (tail2 === this.tail) return false;
|
|
3376
|
+
this.tail = tail2;
|
|
3301
3377
|
this.memo.clear();
|
|
3302
3378
|
return true;
|
|
3303
3379
|
}
|
|
@@ -4648,10 +4724,10 @@ Content-Type: image/${jpeg ? "jpeg" : "png"}\r
|
|
|
4648
4724
|
\r
|
|
4649
4725
|
`
|
|
4650
4726
|
);
|
|
4651
|
-
const
|
|
4727
|
+
const tail2 = Buffer.from(`\r
|
|
4652
4728
|
--${boundary}--\r
|
|
4653
4729
|
`);
|
|
4654
|
-
return { body: Buffer.concat([head, image2,
|
|
4730
|
+
return { body: Buffer.concat([head, image2, tail2]), contentType: `multipart/form-data; boundary=${boundary}` };
|
|
4655
4731
|
}
|
|
4656
4732
|
async function sendFrame(o, key, image2) {
|
|
4657
4733
|
const { body: body2, contentType } = multipartImage(image2);
|
|
@@ -4916,10 +4992,10 @@ var UsbDevice = class {
|
|
|
4916
4992
|
void p?.close().catch(() => void 0);
|
|
4917
4993
|
this.failures++;
|
|
4918
4994
|
this.retryAt = Date.now() + Math.min(30 * this.retryMs, this.retryMs * 2 ** Math.min(this.failures, 5));
|
|
4919
|
-
const
|
|
4920
|
-
const serial = this.cfg.serial && !
|
|
4995
|
+
const why2 = err instanceof Error ? err.message : String(err);
|
|
4996
|
+
const serial = this.cfg.serial && !why2.includes(this.cfg.serial) ? ` (serial ${this.cfg.serial})` : "";
|
|
4921
4997
|
const known = statusOfError(err);
|
|
4922
|
-
this.say(`${
|
|
4998
|
+
this.say(`${why2}${serial}; retrying`, false, "usbRetrying", { why: why2, reason: known.code && known.code !== "error" ? known.code : "", serial: this.cfg.serial ?? "" });
|
|
4923
4999
|
}
|
|
4924
5000
|
}
|
|
4925
5001
|
};
|
|
@@ -5193,6 +5269,247 @@ function paintAlert(g, w, h, shown, o) {
|
|
|
5193
5269
|
g.restore();
|
|
5194
5270
|
}
|
|
5195
5271
|
|
|
5272
|
+
// packages/core/src/welcome.ts
|
|
5273
|
+
init_src();
|
|
5274
|
+
init_i18n();
|
|
5275
|
+
var BOOT_MS = 2400;
|
|
5276
|
+
var BOOT_WINDOW_MS = 6e4;
|
|
5277
|
+
var CARD_EVERY_MS = 10 * 6e4;
|
|
5278
|
+
var CARD_MS = 15e3;
|
|
5279
|
+
var FIRST_CARD_MS = 3e4;
|
|
5280
|
+
var BOOT_FPS = 15;
|
|
5281
|
+
function welcomeDue(cfg, s) {
|
|
5282
|
+
const pending2 = offersSetup(cfg);
|
|
5283
|
+
if (!s.booted) {
|
|
5284
|
+
if (s.sinceStartMs < BOOT_WINDOW_MS && (cfg.bootAnimation !== false || pending2)) return "boot";
|
|
5285
|
+
return pending2 ? "card" : null;
|
|
5286
|
+
}
|
|
5287
|
+
if (!pending2) return null;
|
|
5288
|
+
const slot = Math.floor(s.now / CARD_EVERY_MS);
|
|
5289
|
+
return slot !== s.cardSlot && s.now - slot * CARD_EVERY_MS < 6e4 ? "card" : null;
|
|
5290
|
+
}
|
|
5291
|
+
var TEXTS = {
|
|
5292
|
+
running: { en: "Kiosko is running", es: "Kiosko est\xE1 en marcha", de: "Kiosko l\xE4uft", "zh-Hant": "Kiosko \u5DF2\u5728\u57F7\u884C", "zh-Hans": "Kiosko \u5DF2\u5728\u8FD0\u884C" },
|
|
5293
|
+
open: { en: "Open the editor to set up this panel:", es: "Abre el editor para configurar este panel:", de: "\xD6ffne den Editor, um dieses Panel einzurichten:", "zh-Hant": "\u958B\u555F\u7DE8\u8F2F\u5668\u4F86\u8A2D\u5B9A\u9019\u584A\u9762\u677F\uFF1A", "zh-Hans": "\u6253\u5F00\u7F16\u8F91\u5668\u6765\u8BBE\u7F6E\u8FD9\u5757\u526F\u5C4F\uFF1A" },
|
|
5294
|
+
or: { en: "or go to", es: "o entra en", de: "oder \xF6ffne", "zh-Hant": "\u6216\u524D\u5F80", "zh-Hans": "\u6216\u8BBF\u95EE" },
|
|
5295
|
+
hint: { en: "This card goes away once the setup is done.", es: "Esta tarjeta se va cuando termines la configuraci\xF3n.", de: "Diese Karte verschwindet, sobald die Einrichtung fertig ist.", "zh-Hant": "\u5B8C\u6210\u8A2D\u5B9A\u5F8C\uFF0C\u9019\u5F35\u5361\u7247\u5C31\u6703\u6D88\u5931\u3002", "zh-Hans": "\u5B8C\u6210\u8BBE\u7F6E\u540E\uFF0C\u8FD9\u5F20\u5361\u7247\u5C31\u4F1A\u6D88\u5931\u3002" }
|
|
5296
|
+
};
|
|
5297
|
+
function welcomeTexts(locale) {
|
|
5298
|
+
return Object.fromEntries(Object.entries(TEXTS).map(([k, v]) => [k, localize(v, locale)]));
|
|
5299
|
+
}
|
|
5300
|
+
function editorUrl(cfg) {
|
|
5301
|
+
const host = !cfg.server.host || cfg.server.host === "0.0.0.0" || cfg.server.host === "::" ? "127.0.0.1" : cfg.server.host;
|
|
5302
|
+
return `http://${host.includes(":") ? `[${host}]` : host}:${cfg.server.port}`;
|
|
5303
|
+
}
|
|
5304
|
+
function cardUrl(listening, cfg) {
|
|
5305
|
+
return listening ?? editorUrl(cfg);
|
|
5306
|
+
}
|
|
5307
|
+
var clamp01 = (x) => Math.max(0, Math.min(1, x));
|
|
5308
|
+
var easeOut = (x) => 1 - (1 - clamp01(x)) ** 3;
|
|
5309
|
+
var easeBack = (x) => {
|
|
5310
|
+
const t2 = clamp01(x) - 1;
|
|
5311
|
+
return 1 + 2.2 * t2 ** 3 + 1.2 * t2 ** 2;
|
|
5312
|
+
};
|
|
5313
|
+
var TILES = [
|
|
5314
|
+
{ x: 6, y: 6, w: 30, h: 22, grad: true, alpha: 1 },
|
|
5315
|
+
{ x: 40, y: 6, w: 18, h: 22, grad: false, tone: 1, alpha: 0.55 },
|
|
5316
|
+
{ x: 6, y: 32, w: 18, h: 26, grad: false, tone: 0, alpha: 0.55 },
|
|
5317
|
+
{ x: 28, y: 32, w: 30, h: 26, grad: true, alpha: 0.85 }
|
|
5318
|
+
];
|
|
5319
|
+
function brand(theme) {
|
|
5320
|
+
return [theme.colors.accent, theme.colors.info];
|
|
5321
|
+
}
|
|
5322
|
+
function paintMark(g, x, y, size, theme, t2 = 1, glint = -1) {
|
|
5323
|
+
const k = size / 64;
|
|
5324
|
+
const [c1, c2] = brand(theme);
|
|
5325
|
+
TILES.forEach((tile, i) => {
|
|
5326
|
+
const p = clamp01((t2 - i * 0.12) / 0.52);
|
|
5327
|
+
if (p <= 0) return;
|
|
5328
|
+
const s = 0.55 + 0.45 * easeBack(p);
|
|
5329
|
+
const cx = x + (tile.x + tile.w / 2) * k;
|
|
5330
|
+
const cy = y + (tile.y + tile.h / 2) * k;
|
|
5331
|
+
const dx = (tile.x + tile.w / 2 - 32) * k * 0.6 * (1 - easeOut(p));
|
|
5332
|
+
const dy = (tile.y + tile.h / 2 - 32) * k * 0.6 * (1 - easeOut(p));
|
|
5333
|
+
const w = tile.w * k * s;
|
|
5334
|
+
const h = tile.h * k * s;
|
|
5335
|
+
g.save();
|
|
5336
|
+
g.globalAlpha = tile.alpha * easeOut(p);
|
|
5337
|
+
if (tile.grad) {
|
|
5338
|
+
const gr = g.createLinearGradient(x, y, x + size, y + size);
|
|
5339
|
+
gr.addColorStop(0, c1);
|
|
5340
|
+
gr.addColorStop(1, c2);
|
|
5341
|
+
g.fillStyle = gr;
|
|
5342
|
+
} else g.fillStyle = "tone" in tile && tile.tone ? c2 : c1;
|
|
5343
|
+
g.beginPath();
|
|
5344
|
+
g.roundRect(cx + dx - w / 2, cy + dy - h / 2, w, h, 5 * k * s);
|
|
5345
|
+
g.fill();
|
|
5346
|
+
g.restore();
|
|
5347
|
+
});
|
|
5348
|
+
if (glint >= 0 && glint <= 1) {
|
|
5349
|
+
g.save();
|
|
5350
|
+
g.beginPath();
|
|
5351
|
+
for (const tile of TILES) g.roundRect(x + tile.x * k, y + tile.y * k, tile.w * k, tile.h * k, 5 * k);
|
|
5352
|
+
g.clip();
|
|
5353
|
+
const bx = x - size * 0.6 + glint * size * 2.2;
|
|
5354
|
+
const gr = g.createLinearGradient(bx, y, bx + size * 0.5, y + size);
|
|
5355
|
+
gr.addColorStop(0, "rgba(255,255,255,0)");
|
|
5356
|
+
gr.addColorStop(0.5, "rgba(255,255,255,0.45)");
|
|
5357
|
+
gr.addColorStop(1, "rgba(255,255,255,0)");
|
|
5358
|
+
g.fillStyle = gr;
|
|
5359
|
+
g.fillRect(x, y, size, size);
|
|
5360
|
+
g.restore();
|
|
5361
|
+
}
|
|
5362
|
+
}
|
|
5363
|
+
function paintBackground(g, w, h, theme, cx, cy, glow) {
|
|
5364
|
+
g.fillStyle = theme.colors.bg;
|
|
5365
|
+
g.fillRect(0, 0, w, h);
|
|
5366
|
+
if (glow <= 0) return;
|
|
5367
|
+
const r = Math.max(w, h) * 0.55;
|
|
5368
|
+
const gr = g.createRadialGradient(cx, cy, 0, cx, cy, r);
|
|
5369
|
+
const [c1] = brand(theme);
|
|
5370
|
+
gr.addColorStop(0, css(hex(c1), 0.16 * glow));
|
|
5371
|
+
gr.addColorStop(1, css(hex(c1), 0));
|
|
5372
|
+
g.fillStyle = gr;
|
|
5373
|
+
g.fillRect(0, 0, w, h);
|
|
5374
|
+
}
|
|
5375
|
+
function shapeOf(w, h) {
|
|
5376
|
+
const r = w / h;
|
|
5377
|
+
return r >= 1.6 ? "wide" : r <= 0.7 ? "tall" : "square";
|
|
5378
|
+
}
|
|
5379
|
+
function paintBoot(g, w, h, ms, look) {
|
|
5380
|
+
const { theme } = look;
|
|
5381
|
+
const shape = shapeOf(w, h);
|
|
5382
|
+
const bold2 = theme.fonts.sansBold;
|
|
5383
|
+
const word = "Kiosko";
|
|
5384
|
+
const mark = shape === "wide" ? Math.round(h * 0.5) : Math.round(Math.min(w * (shape === "tall" ? 0.62 : 0.42), h * 0.42));
|
|
5385
|
+
let size = Math.round(mark * (shape === "wide" ? 0.62 : 0.4));
|
|
5386
|
+
size = fitSize(g, word, shape === "wide" ? w * 0.5 : w * 0.86, { size, family: bold2 }, 10);
|
|
5387
|
+
const wordW = measureTracked(g, word, { size, family: bold2 });
|
|
5388
|
+
const gap = Math.round(mark * 0.22);
|
|
5389
|
+
const groupW = shape === "wide" ? mark + gap + wordW : Math.max(mark, wordW);
|
|
5390
|
+
const groupH = shape === "wide" ? mark : mark + gap + size;
|
|
5391
|
+
const gx = Math.round((w - groupW) / 2);
|
|
5392
|
+
const gy = Math.round((h - groupH) / 2);
|
|
5393
|
+
const mx = shape === "wide" ? gx : Math.round((w - mark) / 2);
|
|
5394
|
+
const fade = 1 - clamp01((ms - (BOOT_MS - 380)) / 380);
|
|
5395
|
+
paintBackground(g, w, h, theme, mx + mark / 2, gy + mark / 2, easeOut(ms / 900) * fade);
|
|
5396
|
+
g.save();
|
|
5397
|
+
g.globalAlpha = fade;
|
|
5398
|
+
paintMark(g, mx, gy, mark, theme, ms / 1e3, (ms - 1350) / 650);
|
|
5399
|
+
const p = easeOut((ms - 650) / 700);
|
|
5400
|
+
if (p > 0) {
|
|
5401
|
+
const wx = shape === "wide" ? gx + mark + gap : Math.round((w - wordW) / 2);
|
|
5402
|
+
const base3 = shape === "wide" ? gy + mark / 2 + size * 0.36 : gy + mark + gap + size * 0.82;
|
|
5403
|
+
g.save();
|
|
5404
|
+
g.beginPath();
|
|
5405
|
+
if (shape === "wide") g.rect(wx - 2, 0, (wordW + 4) * p, h);
|
|
5406
|
+
else g.rect(0, 0, w, h);
|
|
5407
|
+
g.clip();
|
|
5408
|
+
g.globalAlpha = fade * (shape === "wide" ? 1 : p);
|
|
5409
|
+
drawTracked(g, word, wx, base3 + (1 - p) * size * 0.25, { size, family: bold2, color: theme.colors.ink });
|
|
5410
|
+
g.restore();
|
|
5411
|
+
const u = easeOut((ms - 1150) / 600);
|
|
5412
|
+
if (u > 0) {
|
|
5413
|
+
const [c1, c2] = brand(theme);
|
|
5414
|
+
const gr = g.createLinearGradient(wx, 0, wx + wordW, 0);
|
|
5415
|
+
gr.addColorStop(0, c1);
|
|
5416
|
+
gr.addColorStop(1, c2);
|
|
5417
|
+
g.fillStyle = gr;
|
|
5418
|
+
const uh = Math.max(2, Math.round(size * 0.07));
|
|
5419
|
+
g.beginPath();
|
|
5420
|
+
g.roundRect(wx, base3 + size * 0.16, wordW * u, uh, uh / 2);
|
|
5421
|
+
g.fill();
|
|
5422
|
+
}
|
|
5423
|
+
}
|
|
5424
|
+
g.restore();
|
|
5425
|
+
}
|
|
5426
|
+
function paintCard(g, w, h, look) {
|
|
5427
|
+
const { theme } = look;
|
|
5428
|
+
const tx = welcomeTexts(look.locale);
|
|
5429
|
+
const shape = shapeOf(w, h);
|
|
5430
|
+
const pad = Math.round(Math.min(w, h) * 0.08);
|
|
5431
|
+
const mark = shape === "wide" ? Math.round(h * 0.42) : shape === "tall" ? Math.round(w * 0.5) : Math.round(Math.min(w * 0.3, h * 0.28));
|
|
5432
|
+
const gap = Math.round(pad * 0.8);
|
|
5433
|
+
const mx = shape === "wide" ? pad + Math.round(mark * 0.1) : Math.round((w - mark) / 2);
|
|
5434
|
+
const bx = shape === "wide" ? mx + mark + Math.round(mark * 0.35) : pad;
|
|
5435
|
+
const bw = w - bx - pad;
|
|
5436
|
+
const bh = shape === "wide" ? h - 2 * pad : h - 2 * pad - mark - gap;
|
|
5437
|
+
const bold2 = theme.fonts.sansBold;
|
|
5438
|
+
const sans = theme.fonts.sans;
|
|
5439
|
+
const mono = theme.fonts.monoBold;
|
|
5440
|
+
const center = shape !== "wide";
|
|
5441
|
+
const layout = (k2) => {
|
|
5442
|
+
const body2 = Math.max(9, Math.round(k2 * 0.5));
|
|
5443
|
+
const chip = Math.max(9, Math.round(k2 * 0.5));
|
|
5444
|
+
const hint = Math.max(8, Math.round(k2 * 0.34));
|
|
5445
|
+
const title = wrapLines(g, tx.running, bw, 2, { size: k2, family: bold2 });
|
|
5446
|
+
const open = wrapLines(g, tx.open, bw, 3, { size: body2, family: sans });
|
|
5447
|
+
const cmd2 = "kiosko editor";
|
|
5448
|
+
const cmdW = measureTracked(g, cmd2, { size: chip, family: mono }) + chip * 1.1;
|
|
5449
|
+
const orW = measureTracked(g, tx.or, { size: body2, family: sans });
|
|
5450
|
+
const urlW = measureTracked(g, look.url, { size: chip, family: mono });
|
|
5451
|
+
const oneLine2 = cmdW + body2 * 0.6 + orW + body2 * 0.6 + urlW <= bw;
|
|
5452
|
+
const hints = hint >= 10 ? wrapLines(g, tx.hint, bw, 2, { size: hint, family: sans }) : [];
|
|
5453
|
+
const lineH = (s) => Math.round(s * 1.3);
|
|
5454
|
+
const height = title.length * lineH(k2) + k2 * 0.25 + open.length * lineH(body2) + body2 * 0.35 + (oneLine2 ? chip * 1.9 : chip * 1.9 * 2 + lineH(body2)) + hint * 0.6 + hints.length * lineH(hint);
|
|
5455
|
+
const fits = urlW <= bw && cmdW <= bw && title.length === 1;
|
|
5456
|
+
return { k: k2, body: body2, chip, hint, title, open, cmd: cmd2, cmdW, orW, urlW, oneLine: oneLine2, hints, height, fits, lineH };
|
|
5457
|
+
};
|
|
5458
|
+
let k = Math.round(shape === "wide" ? h * 0.17 : shape === "tall" ? w * 0.12 : Math.min(w * 0.085, h * 0.11));
|
|
5459
|
+
let L = layout(k);
|
|
5460
|
+
while (k > 12 && (L.height > bh || !L.fits)) L = layout(--k);
|
|
5461
|
+
const my = shape === "wide" ? Math.round((h - mark) / 2) : Math.max(pad, Math.round((h - mark - gap - L.height) / 2));
|
|
5462
|
+
paintBackground(g, w, h, theme, mx + mark / 2, my + mark / 2, 1);
|
|
5463
|
+
paintMark(g, mx, my, mark, theme);
|
|
5464
|
+
let y = shape === "wide" ? pad + Math.max(0, Math.round((bh - L.height) / 2)) : my + mark + gap;
|
|
5465
|
+
const ax = center ? w / 2 : bx;
|
|
5466
|
+
const align = center ? "center" : "left";
|
|
5467
|
+
for (const line of L.title) {
|
|
5468
|
+
drawTracked(g, line, ax, y + L.k * 0.95, { size: L.k, family: bold2, color: theme.colors.ink, align });
|
|
5469
|
+
y += L.lineH(L.k);
|
|
5470
|
+
}
|
|
5471
|
+
y += L.k * 0.25;
|
|
5472
|
+
for (const line of L.open) {
|
|
5473
|
+
drawTracked(g, line, ax, y + L.body * 0.95, { size: L.body, family: sans, color: theme.colors.inkDim, align });
|
|
5474
|
+
y += L.lineH(L.body);
|
|
5475
|
+
}
|
|
5476
|
+
y += L.body * 0.35;
|
|
5477
|
+
const chipH = Math.round(L.chip * 1.6);
|
|
5478
|
+
const drawChip = (x, text3, cw) => {
|
|
5479
|
+
g.fillStyle = theme.colors.surface;
|
|
5480
|
+
g.strokeStyle = theme.colors.surfaceEdge;
|
|
5481
|
+
g.lineWidth = 1;
|
|
5482
|
+
g.beginPath();
|
|
5483
|
+
g.roundRect(x, y, cw, chipH, chipH / 3);
|
|
5484
|
+
g.fill();
|
|
5485
|
+
g.stroke();
|
|
5486
|
+
drawTracked(g, text3, x + cw / 2, y + chipH / 2 + L.chip * 0.36, { size: L.chip, family: mono, color: theme.colors.ink, align: "center" });
|
|
5487
|
+
};
|
|
5488
|
+
const drawUrl = (x) => drawTracked(g, look.url, x, y + chipH / 2 + L.chip * 0.36, { size: L.chip, family: mono, color: theme.colors.accent });
|
|
5489
|
+
if (L.oneLine) {
|
|
5490
|
+
const total = L.cmdW + L.body * 0.6 + L.orW + L.body * 0.6 + L.urlW;
|
|
5491
|
+
let x = center ? Math.round((w - total) / 2) : bx;
|
|
5492
|
+
drawChip(x, L.cmd, L.cmdW);
|
|
5493
|
+
x += L.cmdW + L.body * 0.6;
|
|
5494
|
+
drawTracked(g, tx.or, x, y + chipH / 2 + L.body * 0.36, { size: L.body, family: sans, color: theme.colors.inkDim });
|
|
5495
|
+
x += L.orW + L.body * 0.6;
|
|
5496
|
+
drawUrl(x);
|
|
5497
|
+
y += L.chip * 1.9;
|
|
5498
|
+
} else {
|
|
5499
|
+
drawChip(center ? Math.round((w - L.cmdW) / 2) : bx, L.cmd, L.cmdW);
|
|
5500
|
+
y += L.chip * 1.9;
|
|
5501
|
+
drawTracked(g, tx.or, ax, y + L.body * 0.95, { size: L.body, family: sans, color: theme.colors.inkDim, align });
|
|
5502
|
+
y += L.lineH(L.body);
|
|
5503
|
+
drawUrl(center ? Math.round((w - L.urlW) / 2) : bx);
|
|
5504
|
+
y += L.chip * 1.9;
|
|
5505
|
+
}
|
|
5506
|
+
y += L.hint * 0.6;
|
|
5507
|
+
for (const line of L.hints) {
|
|
5508
|
+
drawTracked(g, line, ax, y + L.hint * 0.95, { size: L.hint, family: sans, color: theme.colors.inkFaint, align });
|
|
5509
|
+
y += L.lineH(L.hint);
|
|
5510
|
+
}
|
|
5511
|
+
}
|
|
5512
|
+
|
|
5196
5513
|
// packages/core/src/frame-stats.ts
|
|
5197
5514
|
var FPS_WINDOW_MS = 5e3;
|
|
5198
5515
|
var round = (ms) => Math.round(ms * 10) / 10;
|
|
@@ -5286,6 +5603,12 @@ var ScreenRunner = class {
|
|
|
5286
5603
|
alertKey = null;
|
|
5287
5604
|
/** Real fps, paint and encode times (see frame-stats.ts). */
|
|
5288
5605
|
stats = new FrameStats();
|
|
5606
|
+
/** The start went by (the boot animation played, or wasn't due). */
|
|
5607
|
+
booted = false;
|
|
5608
|
+
/** The first run's card: the last slot it was shown in, and until when it stays. */
|
|
5609
|
+
cardSlot = -1;
|
|
5610
|
+
cardUntil = 0;
|
|
5611
|
+
cardKey = null;
|
|
5289
5612
|
screen;
|
|
5290
5613
|
rt;
|
|
5291
5614
|
/** `device`: one already open for this screen (handed over by a thread that stopped). */
|
|
@@ -5295,7 +5618,7 @@ var ScreenRunner = class {
|
|
|
5295
5618
|
this.deviceKey = JSON.stringify(screen.device);
|
|
5296
5619
|
this.device = device ?? rt.openDevice(screen, (m) => rt.log(`screen:${screen.name}`, m));
|
|
5297
5620
|
this.pinned = screen.pinnedPage ?? null;
|
|
5298
|
-
this.scheduler = new AnimationScheduler(() => rt.rnd(), (type,
|
|
5621
|
+
this.scheduler = new AnimationScheduler(() => rt.rnd(), (type, why2) => rt.log(type, `animation ignored: ${why2}`));
|
|
5299
5622
|
}
|
|
5300
5623
|
/** Encodes a frame within the screen's `maxBytes`, saying so in the log (at most every 10 min) when it had to shrink it. */
|
|
5301
5624
|
async fit(c, kind, quality, screen, paintMs = 0) {
|
|
@@ -5368,6 +5691,7 @@ var ScreenRunner = class {
|
|
|
5368
5691
|
const play = this.wantedPlay;
|
|
5369
5692
|
this.wanted = null;
|
|
5370
5693
|
this.wantedPlay = false;
|
|
5694
|
+
if (!this.off && !asked && await this.maybeWelcome(now)) return;
|
|
5371
5695
|
if (!this.off && await this.maybeInterlude(now, asked ?? void 0, play)) return;
|
|
5372
5696
|
const page = this.currentPage(now);
|
|
5373
5697
|
if (page?.id !== this.page?.id) {
|
|
@@ -5477,6 +5801,95 @@ var ScreenRunner = class {
|
|
|
5477
5801
|
this.last = out;
|
|
5478
5802
|
await this.send(out);
|
|
5479
5803
|
}
|
|
5804
|
+
/**
|
|
5805
|
+
* The boot animation and the first run's card (welcome.ts), before
|
|
5806
|
+
* anything else but an alert. True while one has the screen.
|
|
5807
|
+
*/
|
|
5808
|
+
async maybeWelcome(now) {
|
|
5809
|
+
if (!this.rt.welcome || this.rt.demoMode) return false;
|
|
5810
|
+
const cfg = this.rt.config;
|
|
5811
|
+
if (this.cardUntil) {
|
|
5812
|
+
if (now < this.cardUntil && offersSetup(cfg)) {
|
|
5813
|
+
await this.paintWelcomeCard(now);
|
|
5814
|
+
return true;
|
|
5815
|
+
}
|
|
5816
|
+
this.cardUntil = 0;
|
|
5817
|
+
this.cardKey = null;
|
|
5818
|
+
this.last = null;
|
|
5819
|
+
this.dirty = true;
|
|
5820
|
+
return false;
|
|
5821
|
+
}
|
|
5822
|
+
const due = welcomeDue(cfg, { sinceStartMs: now - this.rt.startedAt, now, booted: this.booted, cardSlot: this.cardSlot });
|
|
5823
|
+
const first = !this.booted;
|
|
5824
|
+
this.booted = true;
|
|
5825
|
+
if (!due) return false;
|
|
5826
|
+
if (due === "boot") {
|
|
5827
|
+
await this.playBoot();
|
|
5828
|
+
if (!offersSetup(cfg)) {
|
|
5829
|
+
this.last = null;
|
|
5830
|
+
this.dirty = true;
|
|
5831
|
+
return true;
|
|
5832
|
+
}
|
|
5833
|
+
}
|
|
5834
|
+
this.cardSlot = Math.floor(Date.now() / CARD_EVERY_MS);
|
|
5835
|
+
this.cardUntil = Date.now() + (first ? FIRST_CARD_MS : CARD_MS);
|
|
5836
|
+
await this.paintWelcomeCard(Date.now());
|
|
5837
|
+
return true;
|
|
5838
|
+
}
|
|
5839
|
+
welcomeLook() {
|
|
5840
|
+
const cfg = this.rt.config;
|
|
5841
|
+
return { theme: this.rt.theme(), locale: resolveLocale(cfg), url: cardUrl(this.rt.editorUrl, cfg) };
|
|
5842
|
+
}
|
|
5843
|
+
/** The boot animation, at the screen's fps (at most BOOT_FPS): a slower panel plays fewer frames, never longer. */
|
|
5844
|
+
async playBoot() {
|
|
5845
|
+
const { screen } = this;
|
|
5846
|
+
const look = this.welcomeLook();
|
|
5847
|
+
registerFonts();
|
|
5848
|
+
setFontLocale(look.locale);
|
|
5849
|
+
const fps = Math.max(1, Math.min(BOOT_FPS, screen.maxFps));
|
|
5850
|
+
const frames = Math.max(1, Math.round(BOOT_MS / 1e3 * fps));
|
|
5851
|
+
const kind = encodeFor(screen.device, screen.jpegQuality || 85);
|
|
5852
|
+
const canvas = CANVAS.createCanvas(screen.width, screen.height);
|
|
5853
|
+
const g = canvas.getContext("2d");
|
|
5854
|
+
const start = Date.now();
|
|
5855
|
+
for (let i = 0; i < frames && !this.alert && !this.closed; i++) {
|
|
5856
|
+
const ms = Math.min(BOOT_MS, Date.now() - start);
|
|
5857
|
+
if (ms >= BOOT_MS) break;
|
|
5858
|
+
const t0 = performance.now();
|
|
5859
|
+
g.save();
|
|
5860
|
+
paintBoot(g, screen.width, screen.height, ms, look);
|
|
5861
|
+
g.restore();
|
|
5862
|
+
const out = await this.fit(rotateCanvas(canvas, screen.rotate), kind, screen.jpegQuality || 85, screen, performance.now() - t0);
|
|
5863
|
+
await this.send(out);
|
|
5864
|
+
if (i % 4 === 0) {
|
|
5865
|
+
const snap = CANVAS.createCanvas(canvas.width, canvas.height);
|
|
5866
|
+
snap.getContext("2d").drawImage(canvas, 0, 0);
|
|
5867
|
+
this.lastInfo = { screenId: screen.id, pageId: this.page?.id ?? null, at: Date.now(), image: lazyJpeg(snap), tiles: [], interlude: "kiosko/boot", sleeping: false };
|
|
5868
|
+
this.rt.frame(this.lastInfo);
|
|
5869
|
+
}
|
|
5870
|
+
const wait = start + (i + 1) * 1e3 / fps - Date.now();
|
|
5871
|
+
await new Promise((r) => wait > 0 ? setTimeout(r, wait) : setImmediate(r));
|
|
5872
|
+
}
|
|
5873
|
+
}
|
|
5874
|
+
/** The first run's card: a still frame, sent again only when it changes (the theme, the language, the address). */
|
|
5875
|
+
async paintWelcomeCard(now) {
|
|
5876
|
+
const { screen } = this;
|
|
5877
|
+
const look = this.welcomeLook();
|
|
5878
|
+
const key = JSON.stringify([look.theme.id, look.locale, look.url, screen.width, screen.height, screen.rotate]);
|
|
5879
|
+
if (key === this.cardKey) return;
|
|
5880
|
+
this.cardKey = key;
|
|
5881
|
+
const t0 = performance.now();
|
|
5882
|
+
registerFonts();
|
|
5883
|
+
setFontLocale(look.locale);
|
|
5884
|
+
const canvas = CANVAS.createCanvas(screen.width, screen.height);
|
|
5885
|
+
paintCard(canvas.getContext("2d"), screen.width, screen.height, look);
|
|
5886
|
+
const kind = encodeFor(screen.device, screen.jpegQuality || 85);
|
|
5887
|
+
const out = await this.fit(rotateCanvas(canvas, screen.rotate), kind, screen.jpegQuality || 85, screen, performance.now() - t0);
|
|
5888
|
+
this.lastInfo = { screenId: screen.id, pageId: this.page?.id ?? null, at: now, image: lazyJpeg(canvas), tiles: [], interlude: "kiosko/welcome", sleeping: false };
|
|
5889
|
+
this.rt.frame(this.lastInfo);
|
|
5890
|
+
this.last = out;
|
|
5891
|
+
await this.send(out);
|
|
5892
|
+
}
|
|
5480
5893
|
/**
|
|
5481
5894
|
* Plays an interlude if one is due. Returns true while it played (no normal paint this tick).
|
|
5482
5895
|
* `play`: someone plays it from the Play page (an interlude with `input`): it gets their
|
|
@@ -5894,6 +6307,9 @@ var ThreadRunner = class {
|
|
|
5894
6307
|
demo: this.owner.demoMode,
|
|
5895
6308
|
maxConcurrent: this.owner.maxConcurrent,
|
|
5896
6309
|
playIdleMs: this.owner.playIdleMs,
|
|
6310
|
+
welcome: this.owner.welcome,
|
|
6311
|
+
startedAt: this.owner.startedAt,
|
|
6312
|
+
...this.owner.editorUrl ? { editorUrl: this.owner.editorUrl } : {},
|
|
5897
6313
|
pinned: this.pinned,
|
|
5898
6314
|
off: this.off
|
|
5899
6315
|
};
|
|
@@ -6159,10 +6575,18 @@ var Runtime = class extends EventEmitter {
|
|
|
6159
6575
|
* For trying Kiosko without any setup, screenshots and kiosks at fairs.
|
|
6160
6576
|
*/
|
|
6161
6577
|
demoMode;
|
|
6578
|
+
/** The boot animation and the first run's card on the panels (welcome.ts): the server's `start` asks for them; tests and the browser demo don't. */
|
|
6579
|
+
welcome;
|
|
6580
|
+
/** Where the editor really listens (`kiosko start` with its --host/--port), for the first run's card; else the config's. */
|
|
6581
|
+
editorUrl;
|
|
6582
|
+
/** When this runtime was made: the boot animation plays only soon after. */
|
|
6583
|
+
startedAt = Date.now();
|
|
6162
6584
|
constructor(registry2, config2, o = {}) {
|
|
6163
6585
|
super();
|
|
6164
6586
|
this.registry = registry2;
|
|
6165
6587
|
this.demoMode = !!o.demo;
|
|
6588
|
+
this.welcome = !!o.welcome && !o.demo;
|
|
6589
|
+
this.editorUrl = o.editorUrl;
|
|
6166
6590
|
this.threadEntry = o.threadEntry;
|
|
6167
6591
|
this.setMaxListeners(100);
|
|
6168
6592
|
this.config = config2;
|
|
@@ -6791,8 +7215,8 @@ var Registry = class {
|
|
|
6791
7215
|
this.problems.push({ origin, message: `invalid plugin id ${JSON.stringify(def?.id)}` });
|
|
6792
7216
|
return;
|
|
6793
7217
|
}
|
|
6794
|
-
const
|
|
6795
|
-
if (
|
|
7218
|
+
const why2 = incompatibility(def);
|
|
7219
|
+
if (why2) return this.refuse({ id: def.id, version: def.version, origin, reason: why2 });
|
|
6796
7220
|
if (this.plugins.has(def.id)) {
|
|
6797
7221
|
this.problems.push({ origin, message: `plugin "${def.id}" already loaded from ${this.plugins.get(def.id).origin}` });
|
|
6798
7222
|
return;
|
|
@@ -6940,8 +7364,8 @@ var Registry = class {
|
|
|
6940
7364
|
if (existsSync6(pkgPath)) {
|
|
6941
7365
|
const pkg = JSON.parse(readFileSync3(pkgPath, "utf8"));
|
|
6942
7366
|
const meta = packageMeta(pkg);
|
|
6943
|
-
const
|
|
6944
|
-
if (
|
|
7367
|
+
const why2 = incompatibility(meta);
|
|
7368
|
+
if (why2) return this.refuse({ id: meta.id, version: meta.version, origin: folder, reason: why2 });
|
|
6945
7369
|
const rel = pkg.kiosko?.plugin ?? pkg.main;
|
|
6946
7370
|
if (rel) entry = join6(folder, rel);
|
|
6947
7371
|
}
|
|
@@ -7302,8 +7726,82 @@ function lintPlugin(def) {
|
|
|
7302
7726
|
return out;
|
|
7303
7727
|
}
|
|
7304
7728
|
|
|
7729
|
+
// packages/core/src/plugin-updates.ts
|
|
7730
|
+
import { readFileSync as readFileSync4 } from "node:fs";
|
|
7731
|
+
import { homedir as homedir3 } from "node:os";
|
|
7732
|
+
import { join as join7 } from "node:path";
|
|
7733
|
+
|
|
7734
|
+
// packages/core/src/kiosko-release.ts
|
|
7735
|
+
var GITHUB_REPO = "kiosko-lcd/kiosko";
|
|
7736
|
+
var GITHUB_API = "https://api.github.com";
|
|
7737
|
+
var releasePage = (version) => `https://github.com/${GITHUB_REPO}/releases/tag/v${version}`;
|
|
7738
|
+
var windowsInstallerName = (version) => `Kiosko-Setup-${version}-x64.exe`;
|
|
7739
|
+
var releaseAsset = (version, name) => `https://github.com/${GITHUB_REPO}/releases/download/v${version}/${name}`;
|
|
7740
|
+
var NOTES_MAX_CHARS = 3e3;
|
|
7741
|
+
var NOTES_MAX_RELEASES = 10;
|
|
7742
|
+
var stable = (v) => {
|
|
7743
|
+
const x = parseVersion(v);
|
|
7744
|
+
return !!x && !x[3];
|
|
7745
|
+
};
|
|
7746
|
+
var tagVersion = (tag) => {
|
|
7747
|
+
const v = (tag ?? "").replace(/^v/, "");
|
|
7748
|
+
return parseVersion(v) ? v : null;
|
|
7749
|
+
};
|
|
7750
|
+
function trimNotes(body2, max = NOTES_MAX_CHARS) {
|
|
7751
|
+
const clean = body2.replace(/<!--[\s\S]*?-->/g, "").replace(/\r\n?/g, "\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
7752
|
+
if (clean.length <= max) return { body: clean, truncated: false };
|
|
7753
|
+
const cut = clean.lastIndexOf("\n", max);
|
|
7754
|
+
return { body: clean.slice(0, cut > max / 2 ? cut : max).trimEnd(), truncated: true };
|
|
7755
|
+
}
|
|
7756
|
+
function versionsBetween(all, current, latest) {
|
|
7757
|
+
return all.filter((v) => stable(v) && compareVersions(v, current) > 0 && compareVersions(v, latest) <= 0).sort((a, b) => compareVersions(b, a));
|
|
7758
|
+
}
|
|
7759
|
+
async function kioskoReleaseNotes(current, latest, o) {
|
|
7760
|
+
const fromNpm = versionsBetween(o.npmVersions ?? [latest], current, latest).slice(0, NOTES_MAX_RELEASES).map((version) => ({ version, url: releasePage(version) }));
|
|
7761
|
+
let list2;
|
|
7762
|
+
try {
|
|
7763
|
+
const r = await o.http.json(`${o.api ?? GITHUB_API}/repos/${GITHUB_REPO}/releases?per_page=30`, { headers: { Accept: "application/vnd.github+json", "X-GitHub-Api-Version": "2022-11-28" }, ...o.signal ? { signal: o.signal } : {} });
|
|
7764
|
+
if (!Array.isArray(r.data)) throw new Error("GitHub did not answer with a list of releases");
|
|
7765
|
+
list2 = r.data;
|
|
7766
|
+
} catch (err) {
|
|
7767
|
+
return { from: "npm", releases: fromNpm, error: err instanceof Error ? err.message : String(err) };
|
|
7768
|
+
}
|
|
7769
|
+
const byVersion = /* @__PURE__ */ new Map();
|
|
7770
|
+
for (const g of list2) {
|
|
7771
|
+
const v = tagVersion(g.tag_name);
|
|
7772
|
+
if (v && !g.draft && !g.prerelease && stable(v)) byVersion.set(v, g);
|
|
7773
|
+
}
|
|
7774
|
+
const versions = [.../* @__PURE__ */ new Set([...fromNpm.map((r) => r.version), ...versionsBetween([...byVersion.keys()], current, latest)])].sort((a, b) => compareVersions(b, a)).slice(0, NOTES_MAX_RELEASES);
|
|
7775
|
+
const releases2 = versions.map((version) => {
|
|
7776
|
+
const g = byVersion.get(version);
|
|
7777
|
+
if (!g) return { version, url: releasePage(version) };
|
|
7778
|
+
const notes = g.body ? trimNotes(g.body) : null;
|
|
7779
|
+
const url2 = g.html_url?.startsWith(`https://github.com/${GITHUB_REPO}/`) ? g.html_url : releasePage(version);
|
|
7780
|
+
return { version, ...g.name ? { name: g.name } : {}, ...notes?.body ? { body: notes.body, ...notes.truncated ? { truncated: true } : {} } : {}, url: url2, ...g.published_at ? { date: g.published_at } : {} };
|
|
7781
|
+
});
|
|
7782
|
+
const newest = byVersion.get(latest);
|
|
7783
|
+
const name = windowsInstallerName(latest);
|
|
7784
|
+
const asset = (n) => newest?.assets?.find((a) => a.name === n)?.browser_download_url;
|
|
7785
|
+
const exe = asset(name);
|
|
7786
|
+
const sha = asset(`${name}.sha256`);
|
|
7787
|
+
const ours = (u) => !!u && u.startsWith(`https://github.com/${GITHUB_REPO}/releases/download/`);
|
|
7788
|
+
return { from: "github", releases: releases2, ...ours(exe) && ours(sha) ? { windows: { name, exe, sha256: sha } } : {} };
|
|
7789
|
+
}
|
|
7790
|
+
|
|
7305
7791
|
// packages/core/src/plugin-updates.ts
|
|
7306
7792
|
var REGISTRY = "https://registry.npmjs.org";
|
|
7793
|
+
function npmRegistry(env = process.env, home = homedir3()) {
|
|
7794
|
+
const fromEnv = env.npm_config_registry ?? env.NPM_CONFIG_REGISTRY;
|
|
7795
|
+
if (fromEnv?.trim()) return fromEnv.trim().replace(/\/+$/, "");
|
|
7796
|
+
try {
|
|
7797
|
+
const rc = readFileSync4(env.npm_config_userconfig ?? env.NPM_CONFIG_USERCONFIG ?? join7(home, ".npmrc"), "utf8");
|
|
7798
|
+
const line = rc.split(/\r?\n/).map((l) => l.trim()).find((l) => /^registry\s*=/.test(l));
|
|
7799
|
+
const url2 = line?.slice(line.indexOf("=") + 1).trim().replace(/^["']|["']$/g, "");
|
|
7800
|
+
if (url2 && /^https?:\/\//.test(url2)) return url2.replace(/\/+$/, "");
|
|
7801
|
+
} catch {
|
|
7802
|
+
}
|
|
7803
|
+
return REGISTRY;
|
|
7804
|
+
}
|
|
7307
7805
|
var releases = (p) => Object.keys(p.versions ?? {}).filter((v) => {
|
|
7308
7806
|
const x = parseVersion(v);
|
|
7309
7807
|
return !!x && !x[3];
|
|
@@ -7311,15 +7809,17 @@ var releases = (p) => Object.keys(p.versions ?? {}).filter((v) => {
|
|
|
7311
7809
|
function pickUpdate(installed2, p, env) {
|
|
7312
7810
|
const latest = p["dist-tags"]?.latest;
|
|
7313
7811
|
if (!latest || compareVersions(latest, installed2.version) <= 0) return null;
|
|
7314
|
-
const
|
|
7315
|
-
const
|
|
7316
|
-
const
|
|
7317
|
-
|
|
7812
|
+
const meta = (v) => packageMeta(p.versions?.[v] ?? {});
|
|
7813
|
+
const why2 = (v) => incompatibility(meta(v), env);
|
|
7814
|
+
const blocked = p.versions?.[latest] ? why2(latest) : null;
|
|
7815
|
+
const version = releases(p).find((v) => compareVersions(v, installed2.version) > 0 && compareVersions(v, latest) <= 0 && !why2(v));
|
|
7816
|
+
const unlocks = blocked && env.kioskoLatest && compareVersions(env.kioskoLatest, env.sdk) > 0 && !incompatibility(meta(latest), { sdk: env.kioskoLatest, platform: env.platform });
|
|
7817
|
+
return { id: installed2.id, package: installed2.package, current: installed2.version, latest, ...version ? { version } : {}, ...blocked ? { blocked } : {}, ...unlocks ? { unlockedBy: env.kioskoLatest } : {} };
|
|
7318
7818
|
}
|
|
7319
7819
|
async function checkUpdates(plugins, o = {}) {
|
|
7320
7820
|
const http = o.http ?? createHttp({ agent: "kiosko-updates" });
|
|
7321
7821
|
const env = { sdk: o.sdk ?? SDK_VERSION, platform: o.platform ?? process.platform };
|
|
7322
|
-
const base3 = o.registry ??
|
|
7822
|
+
const base3 = o.registry ?? npmRegistry();
|
|
7323
7823
|
const headers2 = { Accept: "application/vnd.npm.install-v1+json" };
|
|
7324
7824
|
const errors = [];
|
|
7325
7825
|
const read = async (pkg) => {
|
|
@@ -7330,17 +7830,17 @@ async function checkUpdates(plugins, o = {}) {
|
|
|
7330
7830
|
return null;
|
|
7331
7831
|
}
|
|
7332
7832
|
};
|
|
7333
|
-
const found = await Promise.all(plugins.map(
|
|
7334
|
-
const p = await read(pl.package);
|
|
7335
|
-
return p ? pickUpdate(pl, p, env) : null;
|
|
7336
|
-
}));
|
|
7833
|
+
const [k, ...found] = await Promise.all([o.kioskoVersion ? read("kiosko") : Promise.resolve(null), ...plugins.map((pl) => read(pl.package))]);
|
|
7337
7834
|
let kiosko;
|
|
7338
|
-
|
|
7339
|
-
|
|
7340
|
-
const
|
|
7341
|
-
|
|
7835
|
+
const latest = k?.["dist-tags"]?.latest;
|
|
7836
|
+
if (o.kioskoVersion && latest && compareVersions(latest, o.kioskoVersion) > 0) {
|
|
7837
|
+
const all = Object.keys(k?.versions ?? {});
|
|
7838
|
+
const versions = versionsBetween(all.length ? all : [latest], o.kioskoVersion, latest);
|
|
7839
|
+
const notes = o.github === false ? void 0 : await kioskoReleaseNotes(o.kioskoVersion, latest, { http, npmVersions: versions, ...o.github ? { api: o.github } : {}, ...o.signal ? { signal: o.signal } : {} });
|
|
7840
|
+
kiosko = { current: o.kioskoVersion, latest, versions, ...notes ? { notes } : {} };
|
|
7342
7841
|
}
|
|
7343
|
-
|
|
7842
|
+
const picked = plugins.map((pl, i) => found[i] ? pickUpdate(pl, found[i], { ...env, ...kiosko ? { kioskoLatest: kiosko.latest } : {} }) : null);
|
|
7843
|
+
return { checkedAt: o.now ?? Date.now(), plugins: picked.filter((x) => !!x), ...kiosko ? { kiosko } : {}, errors };
|
|
7344
7844
|
}
|
|
7345
7845
|
|
|
7346
7846
|
// packages/core/src/store/client.ts
|
|
@@ -7369,7 +7869,7 @@ var MAX_TARBALL_BYTES = 20 * 1024 * 1024;
|
|
|
7369
7869
|
|
|
7370
7870
|
// plugins/core/src/index.ts
|
|
7371
7871
|
import { readdir, readFile, stat } from "node:fs/promises";
|
|
7372
|
-
import { join as
|
|
7872
|
+
import { join as join8 } from "node:path";
|
|
7373
7873
|
function fit2(g, text3, family, w, h, max = 400) {
|
|
7374
7874
|
let size = Math.min(max, h);
|
|
7375
7875
|
g.font = `${size}px "${family}"`;
|
|
@@ -7431,17 +7931,34 @@ var clock = defineWidget({
|
|
|
7431
7931
|
const at = wallClock(now, options2.timeZone);
|
|
7432
7932
|
const clock2 = options2.timeFormat === "inherit" ? fmt : createFormatters({ locale, timeFormat: options2.timeFormat, now });
|
|
7433
7933
|
const text3 = clock2.time(at, { seconds: options2.showSeconds, ampm: false });
|
|
7934
|
+
const full = clock2.hour12 ? clock2.time(at, { seconds: options2.showSeconds }) : text3;
|
|
7935
|
+
const mark = full === text3 ? "" : full.replace(text3, "").trim();
|
|
7936
|
+
const markFirst = !!mark && full.startsWith(mark);
|
|
7434
7937
|
const dateText = options2.showDate ? new Date(at).toLocaleDateString(locale, DATE_FORMATS[options2.dateFormat]) : "";
|
|
7435
7938
|
const dateH = options2.showDate ? Math.min(box.h * 0.2, 40) : 0;
|
|
7436
|
-
const size = fit2(g, text3, theme.fonts.monoBold, box.w * 0.96, (box.h - dateH * 1.3) * 0.95);
|
|
7939
|
+
const size = fit2(g, text3, theme.fonts.monoBold, box.w * (mark ? 0.76 : 0.96), (box.h - dateH * 1.3) * 0.95);
|
|
7437
7940
|
const color2 = options2.color === "accent" ? theme.colors.accent : options2.color === "dim" ? theme.colors.inkDim : theme.colors.ink;
|
|
7438
|
-
const x = options2.align === "left" ? box.x : options2.align === "right" ? box.x + box.w : box.x + box.w / 2;
|
|
7439
7941
|
const block = size * 0.78 + (dateH ? dateH * 1.4 : 0);
|
|
7440
7942
|
const base3 = box.y + (box.h - block) / 2 + size * 0.78;
|
|
7441
|
-
g.
|
|
7943
|
+
g.font = `${size}px "${theme.fonts.monoBold}"`;
|
|
7944
|
+
const digitsW = g.measureText(text3).width;
|
|
7945
|
+
const markSize = Math.max(8, Math.round(size * 0.26));
|
|
7946
|
+
g.font = `${markSize}px "${theme.fonts.sansBold}"`;
|
|
7947
|
+
const markW = mark ? g.measureText(mark).width + size * 0.08 : 0;
|
|
7948
|
+
const total = digitsW + markW;
|
|
7949
|
+
const left = options2.align === "left" ? box.x : options2.align === "right" ? box.x + box.w - total : box.x + (box.w - total) / 2;
|
|
7950
|
+
const digitsX = markFirst ? left + markW : left;
|
|
7951
|
+
g.textAlign = "left";
|
|
7442
7952
|
g.fillStyle = color2;
|
|
7443
7953
|
g.font = `${size}px "${theme.fonts.monoBold}"`;
|
|
7444
|
-
g.fillText(text3,
|
|
7954
|
+
g.fillText(text3, digitsX, base3);
|
|
7955
|
+
if (mark) {
|
|
7956
|
+
g.fillStyle = theme.colors.inkDim;
|
|
7957
|
+
g.font = `${markSize}px "${theme.fonts.sansBold}"`;
|
|
7958
|
+
g.fillText(mark, markFirst ? left : left + digitsW + size * 0.08, base3 - size * 0.78 + markSize * 0.92);
|
|
7959
|
+
}
|
|
7960
|
+
const x = options2.align === "left" ? box.x : options2.align === "right" ? box.x + box.w : box.x + box.w / 2;
|
|
7961
|
+
g.textAlign = options2.align;
|
|
7445
7962
|
if (dateH) {
|
|
7446
7963
|
const ds = Math.min(dateH, fit2(g, dateText, theme.fonts.sans, box.w * 0.96, dateH));
|
|
7447
7964
|
g.font = `${ds}px "${theme.fonts.sans}"`;
|
|
@@ -7621,7 +8138,7 @@ async function nextInFolder(dir) {
|
|
|
7621
8138
|
if (!files.length) return null;
|
|
7622
8139
|
const i = ((turns.get(dir) ?? -1) + 1) % files.length;
|
|
7623
8140
|
turns.set(dir, i);
|
|
7624
|
-
return
|
|
8141
|
+
return join8(dir, files[i]);
|
|
7625
8142
|
}
|
|
7626
8143
|
function imageUrl(src, now, addTimestamp = false) {
|
|
7627
8144
|
const filled = src.replace(/\{now\}/g, String(now)).replace(/\{unix\}/g, String(Math.floor(now / 1e3)));
|
|
@@ -7714,7 +8231,7 @@ var image = defineWidget({
|
|
|
7714
8231
|
var src_default = definePlugin({
|
|
7715
8232
|
id: "core",
|
|
7716
8233
|
name: { en: "Essentials", es: "B\xE1sicos", de: "Grundlagen", "zh-Hant": "\u57FA\u672C\u5DE5\u5177", "zh-Hans": "\u57FA\u7840\u7EC4\u4EF6" },
|
|
7717
|
-
version: "0.2.
|
|
8234
|
+
version: "0.2.9",
|
|
7718
8235
|
languages: ["en", "es", "de", "zh-Hant", "zh-Hans"],
|
|
7719
8236
|
sdk: "^0.2.0",
|
|
7720
8237
|
// The picture widget reads the image (or folder, or URL) you give it.
|
|
@@ -7728,13 +8245,13 @@ var src_default = definePlugin({
|
|
|
7728
8245
|
|
|
7729
8246
|
// plugins/legacy/src/index.ts
|
|
7730
8247
|
import { existsSync as existsSync7, statSync as statSync2 } from "node:fs";
|
|
7731
|
-
import { isAbsolute, join as
|
|
8248
|
+
import { isAbsolute, join as join9 } from "node:path";
|
|
7732
8249
|
import { pathToFileURL as pathToFileURL3 } from "node:url";
|
|
7733
8250
|
var loaded = /* @__PURE__ */ new Map();
|
|
7734
8251
|
function resolveModule(name, dir) {
|
|
7735
8252
|
const expanded = expandPath(name);
|
|
7736
|
-
const base3 = isAbsolute(expanded) ? expanded :
|
|
7737
|
-
for (const p of [base3, `${base3}.mjs`, `${base3}.js`,
|
|
8253
|
+
const base3 = isAbsolute(expanded) ? expanded : join9(expandPath(dir), expanded);
|
|
8254
|
+
for (const p of [base3, `${base3}.mjs`, `${base3}.js`, join9(base3, "index.mjs"), join9(base3, "index.js")]) {
|
|
7738
8255
|
if (existsSync7(p) && statSync2(p).isFile()) return p;
|
|
7739
8256
|
}
|
|
7740
8257
|
return null;
|
|
@@ -7810,7 +8327,7 @@ var module2 = defineWidget({
|
|
|
7810
8327
|
var src_default2 = definePlugin({
|
|
7811
8328
|
id: "legacy",
|
|
7812
8329
|
name: { en: "aimonitor compatibility", es: "Compatibilidad aimonitor", de: "aimonitor-Kompatibilit\xE4t", "zh-Hant": "aimonitor \u76F8\u5BB9\u6027", "zh-Hans": "aimonitor \u517C\u5BB9" },
|
|
7813
|
-
version: "0.2.
|
|
8330
|
+
version: "0.2.9",
|
|
7814
8331
|
languages: ["en", "es", "de", "zh-Hant", "zh-Hans"],
|
|
7815
8332
|
sdk: "^0.2.0",
|
|
7816
8333
|
// Runs the aimonitor modules you point it at, and reads their folder.
|
|
@@ -7824,7 +8341,7 @@ var src_default2 = definePlugin({
|
|
|
7824
8341
|
|
|
7825
8342
|
// packages/server/src/official.ts
|
|
7826
8343
|
var BUNDLED_PLUGIN_IDS = ["agents", "cats", "system", "vitals", "usage", "weather", "calendar", "news", "mirror", "gitlab", "github", "calls", "timesheet", "llm", "gpu", "homeassistant"];
|
|
7827
|
-
var OPTIONAL_PLUGIN_IDS = ["doom", "video", "fractals", "gaming", "logs", "hazards"];
|
|
8344
|
+
var OPTIONAL_PLUGIN_IDS = ["doom", "video", "fractals", "gaming", "logs", "hazards", "batteries"];
|
|
7828
8345
|
var OFFICIAL_PLUGINS = [
|
|
7829
8346
|
...BUNDLED_PLUGIN_IDS.map((id) => ({ id, npm: `kiosko-plugin-${id}`, bundled: true })),
|
|
7830
8347
|
...OPTIONAL_PLUGIN_IDS.map((id) => ({ id, npm: `kiosko-plugin-${id}`, bundled: false }))
|
|
@@ -7835,13 +8352,13 @@ var BUNDLED_PLUGINS = OFFICIAL_PLUGINS.filter((o) => o.bundled);
|
|
|
7835
8352
|
var BUILTIN_PLUGINS = [src_default, src_default2];
|
|
7836
8353
|
|
|
7837
8354
|
// packages/server/src/config-cli.ts
|
|
7838
|
-
import { copyFileSync as copyFileSync2, existsSync as existsSync9, mkdirSync as mkdirSync5, readFileSync as
|
|
8355
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync9, mkdirSync as mkdirSync5, readFileSync as readFileSync5, writeFileSync as writeFileSync6 } from "node:fs";
|
|
7839
8356
|
import { tmpdir } from "node:os";
|
|
7840
|
-
import { dirname as dirname4, isAbsolute as isAbsolute2, join as
|
|
8357
|
+
import { dirname as dirname4, isAbsolute as isAbsolute2, join as join11, relative, resolve as resolve2 } from "node:path";
|
|
7841
8358
|
|
|
7842
8359
|
// packages/server/src/preview.ts
|
|
7843
8360
|
import { existsSync as existsSync8, mkdirSync as mkdirSync4, writeFileSync as writeFileSync5 } from "node:fs";
|
|
7844
|
-
import { dirname as dirname3, join as
|
|
8361
|
+
import { dirname as dirname3, join as join10 } from "node:path";
|
|
7845
8362
|
function writePreview(rt, screen, page, out, o = {}) {
|
|
7846
8363
|
const r = rt.preview(screen, page, { demo: o.demo ?? true });
|
|
7847
8364
|
if (!existsSync8(dirname3(out))) mkdirSync4(dirname3(out), { recursive: true });
|
|
@@ -7859,7 +8376,7 @@ function renderPreviews(registry2, cfg, dir) {
|
|
|
7859
8376
|
try {
|
|
7860
8377
|
safe2.screens.forEach(
|
|
7861
8378
|
(s, si) => s.pages.forEach((p, pi) => {
|
|
7862
|
-
const file =
|
|
8379
|
+
const file = join10(dir, `${si + 1}-${slug(s.name || s.id)}--${pi + 1}-${slug(p.name || p.id)}.png`);
|
|
7863
8380
|
const problems = writePreview(rt, s, p, file);
|
|
7864
8381
|
out.push({ screen: s.name || s.id, page: p.name || p.id, file, size: `${s.width}\xD7${s.height}`, problems });
|
|
7865
8382
|
})
|
|
@@ -7917,7 +8434,7 @@ function readConfigText(text3) {
|
|
|
7917
8434
|
function readInput(file) {
|
|
7918
8435
|
const name = file === "-" ? "(stdin)" : file;
|
|
7919
8436
|
if (file !== "-" && !existsSync9(file)) return { error: `not found: ${file}`, notes: [], name };
|
|
7920
|
-
return { ...readConfigText(
|
|
8437
|
+
return { ...readConfigText(readFileSync5(file === "-" ? 0 : file, "utf8")), name };
|
|
7921
8438
|
}
|
|
7922
8439
|
var pluginDefs = (r) => r.list().map((p) => p.def);
|
|
7923
8440
|
async function findRunning(cfg, configPath, o) {
|
|
@@ -8074,7 +8591,7 @@ ${bold("Changes")}: ${summarizeDiff(plan.diff)}`);
|
|
|
8074
8591
|
}
|
|
8075
8592
|
if (plan.carried.length) console.log(dim(` kept from your current config (the file leaves them out): ${plan.carried.join(", ")}`));
|
|
8076
8593
|
if (!flags.has("--no-preview")) {
|
|
8077
|
-
const dir = opts.get("--preview") ||
|
|
8594
|
+
const dir = opts.get("--preview") || join11(tmpdir(), `kiosko-import-${stamp()}`);
|
|
8078
8595
|
try {
|
|
8079
8596
|
const files = renderPreviews(reg, c, dir);
|
|
8080
8597
|
console.log(`
|
|
@@ -8107,9 +8624,9 @@ ${dim("Dry run: nothing was written.")} Run again with --apply to back up the cu
|
|
|
8107
8624
|
signal: AbortSignal.timeout(15e3)
|
|
8108
8625
|
}).catch((err) => err);
|
|
8109
8626
|
if (r instanceof Error || !r.ok) {
|
|
8110
|
-
const
|
|
8627
|
+
const why2 = r instanceof Error ? r.message : r.status === 409 ? "the configuration changed in the editor meanwhile" : `HTTP ${r.status}`;
|
|
8111
8628
|
console.log(red(`
|
|
8112
|
-
Not applied: ${
|
|
8629
|
+
Not applied: ${why2}. Run the import again${saved}.`));
|
|
8113
8630
|
return 1;
|
|
8114
8631
|
}
|
|
8115
8632
|
console.log(`
|
|
@@ -8142,16 +8659,48 @@ async function configCommand(argv2, ctx) {
|
|
|
8142
8659
|
}
|
|
8143
8660
|
}
|
|
8144
8661
|
|
|
8662
|
+
// packages/server/src/editor-cli.ts
|
|
8663
|
+
function editorUrl2(server, over = {}) {
|
|
8664
|
+
let host = over.host ?? server.host;
|
|
8665
|
+
if (host === "0.0.0.0" || host === "") host = "127.0.0.1";
|
|
8666
|
+
if (host === "::") host = "::1";
|
|
8667
|
+
const port = Number(over.port ?? server.port);
|
|
8668
|
+
return `http://${host.includes(":") ? `[${host}]` : host}:${port}/`;
|
|
8669
|
+
}
|
|
8670
|
+
async function runningAt(url2, timeoutMs = 1500) {
|
|
8671
|
+
try {
|
|
8672
|
+
const res = await fetch(new URL("api/state", url2), { signal: AbortSignal.timeout(timeoutMs) });
|
|
8673
|
+
if (!res.ok) return null;
|
|
8674
|
+
const body2 = await res.json();
|
|
8675
|
+
return typeof body2.version === "string" ? body2.version : null;
|
|
8676
|
+
} catch {
|
|
8677
|
+
return null;
|
|
8678
|
+
}
|
|
8679
|
+
}
|
|
8680
|
+
async function editorCommand({ server, flags, open, log }) {
|
|
8681
|
+
const url2 = editorUrl2(server, flags);
|
|
8682
|
+
const version = await runningAt(url2);
|
|
8683
|
+
if (!version) {
|
|
8684
|
+
log(`Kiosko isn't running at ${url2}`);
|
|
8685
|
+
log(" start it: kiosko start --open");
|
|
8686
|
+
log(" or with your session, always: kiosko service install");
|
|
8687
|
+
return 1;
|
|
8688
|
+
}
|
|
8689
|
+
log(`Kiosko ${version} \u2014 editor at ${url2}`);
|
|
8690
|
+
if (!flags.print) open(url2);
|
|
8691
|
+
return 0;
|
|
8692
|
+
}
|
|
8693
|
+
|
|
8145
8694
|
// packages/server/src/plugins-cli.ts
|
|
8146
8695
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
8147
|
-
import { existsSync as existsSync10, lstatSync, mkdirSync as mkdirSync6, readdirSync as readdirSync4, readFileSync as
|
|
8148
|
-
import { basename, join as
|
|
8696
|
+
import { existsSync as existsSync10, lstatSync, mkdirSync as mkdirSync6, readdirSync as readdirSync4, readFileSync as readFileSync6, rmSync, symlinkSync, watch, writeFileSync as writeFileSync7 } from "node:fs";
|
|
8697
|
+
import { basename, join as join12, resolve as resolve4 } from "node:path";
|
|
8149
8698
|
import { pathToFileURL as pathToFileURL4 } from "node:url";
|
|
8150
8699
|
var npmName = (s) => /^[a-z0-9][\w.-]*$/.test(s) && !s.startsWith("kiosko-plugin-") && !s.includes("/") ? `kiosko-plugin-${s}` : s;
|
|
8151
8700
|
function ensureFolder() {
|
|
8152
8701
|
const dir = paths.plugins;
|
|
8153
8702
|
mkdirSync6(dir, { recursive: true });
|
|
8154
|
-
const pkg =
|
|
8703
|
+
const pkg = join12(dir, "package.json");
|
|
8155
8704
|
if (!existsSync10(pkg)) writeFileSync7(pkg, `${JSON.stringify({ name: "kiosko-user-plugins", private: true, type: "module" }, null, 2)}
|
|
8156
8705
|
`);
|
|
8157
8706
|
return dir;
|
|
@@ -8161,10 +8710,10 @@ function npm(args, cwd) {
|
|
|
8161
8710
|
}
|
|
8162
8711
|
async function loadPluginDir(dir, o = {}) {
|
|
8163
8712
|
const root = resolve4(dir);
|
|
8164
|
-
const pkgPath =
|
|
8165
|
-
const pkg = existsSync10(pkgPath) ? JSON.parse(
|
|
8166
|
-
const built = [pkg.kiosko?.plugin, pkg.main, "index.mjs", "index.js"].filter((x) => typeof x === "string").map((x) =>
|
|
8167
|
-
const src =
|
|
8713
|
+
const pkgPath = join12(root, "package.json");
|
|
8714
|
+
const pkg = existsSync10(pkgPath) ? JSON.parse(readFileSync6(pkgPath, "utf8")) : {};
|
|
8715
|
+
const built = [pkg.kiosko?.plugin, pkg.main, "index.mjs", "index.js"].filter((x) => typeof x === "string").map((x) => join12(root, x)).find(existsSync10);
|
|
8716
|
+
const src = join12(root, "src", "index.ts");
|
|
8168
8717
|
const entry = (o.src || !built) && existsSync10(src) ? src : built;
|
|
8169
8718
|
if (!entry) throw new Error(`no plugin in ${root}: no package.json "kiosko.plugin", index.js or src/index.ts`);
|
|
8170
8719
|
installSdkResolver();
|
|
@@ -8190,8 +8739,8 @@ async function check2(dir, argv2) {
|
|
|
8190
8739
|
else if (def.sdk && meta.sdk !== def.sdk) issues.push({ level: "warn", where: "package.json", message: `kiosko.sdk ${meta.sdk} differs from the definition's sdk ${def.sdk}` });
|
|
8191
8740
|
if (def.languages?.length && !meta.languages) issues.push({ level: "warn", where: "package.json", message: `add "kiosko": { "languages": ${JSON.stringify(def.languages)} } so a catalogue knows them without running it` });
|
|
8192
8741
|
else if (def.languages && meta.languages && def.languages.join() !== meta.languages.join()) issues.push({ level: "warn", where: "package.json", message: `kiosko.languages ${JSON.stringify(meta.languages)} differs from the definition's ${JSON.stringify(def.languages)}` });
|
|
8193
|
-
const
|
|
8194
|
-
if (
|
|
8742
|
+
const why2 = incompatibility({ sdk: def.sdk ?? meta.sdk, platforms: def.platforms ?? meta.platforms });
|
|
8743
|
+
if (why2) issues.push({ level: "warn", where: "plugin", message: `this Kiosko can't run it: ${why2}` });
|
|
8195
8744
|
if (pkg.version && pkg.version !== def.version) issues.push({ level: "warn", where: "package.json", message: `version ${pkg.version} differs from the definition's ${def.version}` });
|
|
8196
8745
|
const { checkPlugin: checkPlugin2 } = await Promise.resolve().then(() => (init_testing(), testing_exports));
|
|
8197
8746
|
const painted = /* @__PURE__ */ new Map();
|
|
@@ -8213,8 +8762,8 @@ ${errors.length} errors, ${issues.length - errors.length} warnings` : "\u2713 no
|
|
|
8213
8762
|
async function manifest(dir, argv2) {
|
|
8214
8763
|
const root = resolve4(dir);
|
|
8215
8764
|
const { def, pkg } = await loadPluginDir(root, { src: flagOf(argv2, "--src") });
|
|
8216
|
-
const screenshots = Object.fromEntries((def.widgets ?? []).map((w) => [w.id, `docs/${w.id}.png`]).filter(([, f]) => existsSync10(
|
|
8217
|
-
const out = optOf(argv2, "--out") ??
|
|
8765
|
+
const screenshots = Object.fromEntries((def.widgets ?? []).map((w) => [w.id, `docs/${w.id}.png`]).filter(([, f]) => existsSync10(join12(root, f))));
|
|
8766
|
+
const out = optOf(argv2, "--out") ?? join12(root, "kiosko-manifest.json");
|
|
8218
8767
|
writeFileSync7(out, `${JSON.stringify(pluginManifest(def, { pkg, screenshots }), null, 2)}
|
|
8219
8768
|
`);
|
|
8220
8769
|
console.log(out);
|
|
@@ -8453,8 +9002,8 @@ async function pluginsCommand(argv2, registry2) {
|
|
|
8453
9002
|
const dir = resolve4(where ?? `kiosko-plugin-${id}`);
|
|
8454
9003
|
if (existsSync10(dir) && readdirSync4(dir).length) throw new Error(`${dir} is not empty`);
|
|
8455
9004
|
for (const [file, body2] of Object.entries(newPluginFiles(id))) {
|
|
8456
|
-
mkdirSync6(
|
|
8457
|
-
writeFileSync7(
|
|
9005
|
+
mkdirSync6(join12(dir, file, ".."), { recursive: true });
|
|
9006
|
+
writeFileSync7(join12(dir, file), body2);
|
|
8458
9007
|
}
|
|
8459
9008
|
console.log(`${dir}
|
|
8460
9009
|
|
|
@@ -8486,12 +9035,12 @@ plugins folder: ${paths.plugins}`);
|
|
|
8486
9035
|
const dir = ensureFolder();
|
|
8487
9036
|
for (const n of names) {
|
|
8488
9037
|
const src = resolve4(n);
|
|
8489
|
-
const pkgPath =
|
|
9038
|
+
const pkgPath = join12(src, "package.json");
|
|
8490
9039
|
if (!existsSync10(pkgPath)) throw new Error(`${src} has no package.json`);
|
|
8491
|
-
const pkg = JSON.parse(
|
|
9040
|
+
const pkg = JSON.parse(readFileSync6(pkgPath, "utf8"));
|
|
8492
9041
|
const entry = pkg.kiosko?.plugin;
|
|
8493
|
-
if (entry && !existsSync10(
|
|
8494
|
-
const target =
|
|
9042
|
+
if (entry && !existsSync10(join12(src, entry))) console.warn(`warning: ${entry} doesn't exist yet in ${src} (run its build)`);
|
|
9043
|
+
const target = join12(dir, pkg.kiosko?.id ?? basename(src).replace(/^kiosko-plugin-/, ""));
|
|
8495
9044
|
const existing = (() => {
|
|
8496
9045
|
try {
|
|
8497
9046
|
return lstatSync(target);
|
|
@@ -8512,7 +9061,7 @@ plugins folder: ${paths.plugins}`);
|
|
|
8512
9061
|
const dir = ensureFolder();
|
|
8513
9062
|
for (const n of names) {
|
|
8514
9063
|
const id = n.replace(/^kiosko-plugin-/, "");
|
|
8515
|
-
const link =
|
|
9064
|
+
const link = join12(dir, id);
|
|
8516
9065
|
const st = (() => {
|
|
8517
9066
|
try {
|
|
8518
9067
|
return lstatSync(link);
|
|
@@ -8536,7 +9085,7 @@ plugins folder: ${paths.plugins}`);
|
|
|
8536
9085
|
|
|
8537
9086
|
// packages/server/src/gallery.ts
|
|
8538
9087
|
import { mkdirSync as mkdirSync7, writeFileSync as writeFileSync8 } from "node:fs";
|
|
8539
|
-
import { join as
|
|
9088
|
+
import { join as join13 } from "node:path";
|
|
8540
9089
|
var HOME_URL = "https://kioskolcd.dev/";
|
|
8541
9090
|
var RELEASES_URL = "https://github.com/kiosko-lcd/kiosko/releases/latest";
|
|
8542
9091
|
var MADRID = { latitude: 40.4168, longitude: -3.7038, name: "Madrid" };
|
|
@@ -8567,7 +9116,7 @@ function buildGallery(registry2, o) {
|
|
|
8567
9116
|
let count = 0;
|
|
8568
9117
|
const pluginsOf = registry2.list().filter(({ def, enabled }) => enabled && def.widgets?.length);
|
|
8569
9118
|
for (const lang of langs) {
|
|
8570
|
-
mkdirSync7(
|
|
9119
|
+
mkdirSync7(join13(o.out, "img", folder(lang.id)), { recursive: true });
|
|
8571
9120
|
const cfg = normalize({ locale: lang.locale, theme: theme.id, location: SAMPLE_PLACES[lang.id] ?? MADRID });
|
|
8572
9121
|
const L = (x) => localize(x, lang.locale);
|
|
8573
9122
|
const up = folder(lang.id) ? "../" : "";
|
|
@@ -8583,7 +9132,7 @@ function buildGallery(registry2, o) {
|
|
|
8583
9132
|
const height = Math.min(720, pref.h);
|
|
8584
9133
|
const file = `img/${folder(lang.id)}${def.id}-${w.id}.png`;
|
|
8585
9134
|
const r = composeWidget({ cfg, registry: registry2, theme, type: `${def.id}/${w.id}`, width, height, now, ...w.chrome === "bare" ? {} : { title: L(w.name) } });
|
|
8586
|
-
writeFileSync8(
|
|
9135
|
+
writeFileSync8(join13(o.out, file), r.canvas.toBuffer("image/png"));
|
|
8587
9136
|
let shot = listed.widgets.find((x) => x.type === `${def.id}/${w.id}`);
|
|
8588
9137
|
if (!shot) {
|
|
8589
9138
|
count++;
|
|
@@ -8596,10 +9145,10 @@ function buildGallery(registry2, o) {
|
|
|
8596
9145
|
if (!without.includes(def.id)) sections.push(`<section><h2>${esc(L(def.name))} <small>${esc(def.id)} \xB7 v${esc(def.version)}</small></h2><p>${esc(L(def.description))}</p><div class="grid">${cards.join("")}</div></section>`);
|
|
8597
9146
|
}
|
|
8598
9147
|
const home = `${HOME_URL}${folder(lang.id)}`;
|
|
8599
|
-
const usb =
|
|
8600
|
-
mkdirSync7(
|
|
9148
|
+
const usb = lang.id.startsWith("zh") ? `${HOME_URL}${lang.id}/docs/usb/` : "https://github.com/kiosko-lcd/kiosko/blob/main/docs/usb.md";
|
|
9149
|
+
mkdirSync7(join13(o.out, folder(lang.id)), { recursive: true });
|
|
8601
9150
|
writeFileSync8(
|
|
8602
|
-
|
|
9151
|
+
join13(o.out, folder(lang.id), "index.html"),
|
|
8603
9152
|
`<!doctype html><html lang="${lang.id}" dir="${lang.dir}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${esc(L(T.title))}</title>
|
|
8604
9153
|
<style>
|
|
8605
9154
|
:root{color-scheme:dark;--bg:#0a0d13;--panel:#121722;--line:rgba(255,255,255,.08);--text:#e7ecf4;--dim:#a3adbf}
|
|
@@ -8634,7 +9183,7 @@ a.try{display:inline-block;margin-top:10px;padding:8px 14px;border-radius:10px;b
|
|
|
8634
9183
|
try {
|
|
8635
9184
|
for (const listed of data.pages) {
|
|
8636
9185
|
const page = shown.pages.find((p) => p.id === listed.id);
|
|
8637
|
-
writeFileSync8(
|
|
9186
|
+
writeFileSync8(join13(o.out, listed.file[l.id]), rt.preview(shown, page, { now, demo: true }).canvas.toBuffer("image/jpeg", 88));
|
|
8638
9187
|
}
|
|
8639
9188
|
} finally {
|
|
8640
9189
|
rt.stop();
|
|
@@ -8642,7 +9191,7 @@ a.try{display:inline-block;margin-top:10px;padding:8px 14px;border-radius:10px;b
|
|
|
8642
9191
|
}
|
|
8643
9192
|
}
|
|
8644
9193
|
data.count = count;
|
|
8645
|
-
writeFileSync8(
|
|
9194
|
+
writeFileSync8(join13(o.out, "gallery.json"), `${JSON.stringify(data)}
|
|
8646
9195
|
`);
|
|
8647
9196
|
return count;
|
|
8648
9197
|
}
|
|
@@ -8810,8 +9359,8 @@ function importAimonitor(old, reg, modeOverride, o = {}) {
|
|
|
8810
9359
|
// packages/server/src/service.ts
|
|
8811
9360
|
import { execFileSync as execFileSync3 } from "node:child_process";
|
|
8812
9361
|
import { existsSync as existsSync11, mkdirSync as mkdirSync8, rmSync as rmSync2, writeFileSync as writeFileSync9 } from "node:fs";
|
|
8813
|
-
import { homedir as
|
|
8814
|
-
import { dirname as dirname5, join as
|
|
9362
|
+
import { homedir as homedir4, platform as platform2 } from "node:os";
|
|
9363
|
+
import { dirname as dirname5, join as join14, resolve as resolve5, win32 as win322 } from "node:path";
|
|
8815
9364
|
import { fileURLToPath } from "node:url";
|
|
8816
9365
|
var xml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
8817
9366
|
function servicePlan(o = {}) {
|
|
@@ -8821,10 +9370,10 @@ function servicePlan(o = {}) {
|
|
|
8821
9370
|
const args = [...nodeArgs, cli, "start", ...o.args ?? []];
|
|
8822
9371
|
const os = o.os ?? platform2();
|
|
8823
9372
|
const sep2 = os === "win32" ? ";" : ":";
|
|
8824
|
-
const path = [dirname5(node),
|
|
9373
|
+
const path = [dirname5(node), join14(homedir4(), ".local", "bin"), ...os === "darwin" ? ["/opt/homebrew/bin"] : [], "/usr/local/bin", "/usr/bin", "/bin"].join(sep2);
|
|
8825
9374
|
const env = { ...os === "win32" ? {} : { PATH: path }, ...o.env ?? {} };
|
|
8826
9375
|
if (os === "darwin") {
|
|
8827
|
-
const file2 =
|
|
9376
|
+
const file2 = join14(homedir4(), "Library", "LaunchAgents", "dev.kiosko.plist");
|
|
8828
9377
|
const content2 = `<?xml version="1.0" encoding="UTF-8"?>
|
|
8829
9378
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
8830
9379
|
<plist version="1.0">
|
|
@@ -8841,8 +9390,8 @@ ${Object.entries(env).map(([k, v]) => ` <key>${xml(k)}</key><string>${xml(v)}
|
|
|
8841
9390
|
<key>RunAtLoad</key><true/>
|
|
8842
9391
|
<key>KeepAlive</key><true/>
|
|
8843
9392
|
<key>ProcessType</key><string>Background</string>
|
|
8844
|
-
<key>StandardOutPath</key><string>${xml(
|
|
8845
|
-
<key>StandardErrorPath</key><string>${xml(
|
|
9393
|
+
<key>StandardOutPath</key><string>${xml(join14(homedir4(), "Library", "Logs", "kiosko.log"))}</string>
|
|
9394
|
+
<key>StandardErrorPath</key><string>${xml(join14(homedir4(), "Library", "Logs", "kiosko.log"))}</string>
|
|
8846
9395
|
</dict>
|
|
8847
9396
|
</plist>
|
|
8848
9397
|
`;
|
|
@@ -8870,7 +9419,7 @@ CreateObject("WScript.Shell").Run ${vbs(`cmd.exe /d /s /c "${inner}"`)}, 0, Fals
|
|
|
8870
9419
|
disable: [["schtasks", "/End", "/TN", "Kiosko"], stopProcesses(cli), ["schtasks", "/Delete", "/F", "/TN", "Kiosko"]]
|
|
8871
9420
|
};
|
|
8872
9421
|
}
|
|
8873
|
-
const file =
|
|
9422
|
+
const file = join14(process.env.XDG_CONFIG_HOME ?? join14(homedir4(), ".config"), "systemd", "user", "kiosko.service");
|
|
8874
9423
|
const q3 = (a) => /[\s"\\]/.test(a) ? `"${a.replace(/(["\\])/g, "\\$1")}"` : a;
|
|
8875
9424
|
const content = `[Unit]
|
|
8876
9425
|
Description=Kiosko: widgets for USB LCD panels
|
|
@@ -8928,20 +9477,23 @@ function runService(action, plan) {
|
|
|
8928
9477
|
}
|
|
8929
9478
|
|
|
8930
9479
|
// packages/server/src/server.ts
|
|
8931
|
-
import {
|
|
9480
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
9481
|
+
import { randomBytes } from "node:crypto";
|
|
9482
|
+
import { existsSync as existsSync16, openSync, readFileSync as readFileSync11, statSync as statSync3 } from "node:fs";
|
|
8932
9483
|
import { createServer } from "node:http";
|
|
9484
|
+
import { tmpdir as tmpdir2 } from "node:os";
|
|
8933
9485
|
import { createRequire as createRequire3 } from "node:module";
|
|
8934
|
-
import { dirname as
|
|
9486
|
+
import { dirname as dirname8, extname, join as join18, normalize as normPath, resolve as resolve7 } from "node:path";
|
|
8935
9487
|
|
|
8936
9488
|
// packages/server/src/plugins-manage.ts
|
|
8937
9489
|
import { execFile } from "node:child_process";
|
|
8938
|
-
import { existsSync as existsSync12, lstatSync as lstatSync2, mkdirSync as mkdirSync9, readFileSync as
|
|
8939
|
-
import { join as
|
|
9490
|
+
import { existsSync as existsSync12, lstatSync as lstatSync2, mkdirSync as mkdirSync9, readFileSync as readFileSync7, rmSync as rmSync3, writeFileSync as writeFileSync10 } from "node:fs";
|
|
9491
|
+
import { join as join15, relative as relative2, resolve as resolve6, sep } from "node:path";
|
|
8940
9492
|
var NPM_NAME = /^(@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*(@[\w.^~<>=*-]+)?$/i;
|
|
8941
9493
|
var packageName = (spec) => spec.startsWith("@") ? `@${spec.slice(1).split("@")[0]}` : spec.split("@")[0];
|
|
8942
9494
|
function ensureFolder2(dir) {
|
|
8943
9495
|
mkdirSync9(dir, { recursive: true });
|
|
8944
|
-
const pkg =
|
|
9496
|
+
const pkg = join15(dir, "package.json");
|
|
8945
9497
|
if (!existsSync12(pkg)) writeFileSync10(pkg, `${JSON.stringify({ name: "kiosko-user-plugins", private: true, type: "module" }, null, 2)}
|
|
8946
9498
|
`);
|
|
8947
9499
|
}
|
|
@@ -8954,7 +9506,7 @@ var realNpm = (args, cwd) => new Promise((ok, fail) => {
|
|
|
8954
9506
|
});
|
|
8955
9507
|
function installedIntegrity(dir, name) {
|
|
8956
9508
|
try {
|
|
8957
|
-
const lock = JSON.parse(
|
|
9509
|
+
const lock = JSON.parse(readFileSync7(join15(dir, "node_modules", ".package-lock.json"), "utf8"));
|
|
8958
9510
|
return lock.packages?.[`node_modules/${name}`]?.integrity;
|
|
8959
9511
|
} catch {
|
|
8960
9512
|
return void 0;
|
|
@@ -8966,8 +9518,8 @@ async function installPlugin(spec, o) {
|
|
|
8966
9518
|
ensureFolder2(dir);
|
|
8967
9519
|
const npm2 = o.npm ?? realNpm;
|
|
8968
9520
|
const r = o.registry;
|
|
8969
|
-
const folder =
|
|
8970
|
-
const readPkg = () => existsSync12(
|
|
9521
|
+
const folder = join15(dir, "node_modules", packageName(spec));
|
|
9522
|
+
const readPkg = () => existsSync12(join15(folder, "package.json")) ? JSON.parse(readFileSync7(join15(folder, "package.json"), "utf8")) : null;
|
|
8971
9523
|
const beforePkg = readPkg();
|
|
8972
9524
|
const beforeId = beforePkg ? packageMeta(beforePkg).id : void 0;
|
|
8973
9525
|
const output = await npm2(["install", "--no-audit", "--no-fund", "--ignore-scripts", "--save-exact", spec], dir);
|
|
@@ -9023,7 +9575,7 @@ async function removePlugin(id, o) {
|
|
|
9023
9575
|
const name = parts[1].startsWith("@") ? `${parts[1]}/${parts[2]}` : parts[1];
|
|
9024
9576
|
await (o.npm ?? realNpm)(["uninstall", "--no-audit", "--no-fund", name], dir);
|
|
9025
9577
|
} else {
|
|
9026
|
-
const top =
|
|
9578
|
+
const top = join15(dir, parts[0]);
|
|
9027
9579
|
if (!lstatSync2(top).isSymbolicLink()) return { removed: false, reason: `${top} is a folder you put there: delete it yourself if you mean it` };
|
|
9028
9580
|
rmSync3(top);
|
|
9029
9581
|
}
|
|
@@ -9038,17 +9590,17 @@ async function reloadPlugin(id, o) {
|
|
|
9038
9590
|
}
|
|
9039
9591
|
|
|
9040
9592
|
// packages/server/src/store.ts
|
|
9041
|
-
import { existsSync as existsSync13, mkdirSync as mkdirSync10, readFileSync as
|
|
9042
|
-
import { dirname as dirname6, join as
|
|
9593
|
+
import { existsSync as existsSync13, mkdirSync as mkdirSync10, readFileSync as readFileSync8, renameSync as renameSync4, writeFileSync as writeFileSync11 } from "node:fs";
|
|
9594
|
+
import { dirname as dirname6, join as join16 } from "node:path";
|
|
9043
9595
|
var STORE_URL = "https://kioskolcd.dev/store/v1/";
|
|
9044
9596
|
function shipped(...candidates) {
|
|
9045
9597
|
for (const c of candidates) if (existsSync13(c)) return c;
|
|
9046
9598
|
return null;
|
|
9047
9599
|
}
|
|
9048
9600
|
function snapshotIndex() {
|
|
9049
|
-
const file = shipped(
|
|
9601
|
+
const file = shipped(join16(import.meta.dirname, "../assets/store-index.json"), join16(import.meta.dirname, "assets/store-index.json"));
|
|
9050
9602
|
try {
|
|
9051
|
-
return file ? JSON.parse(
|
|
9603
|
+
return file ? JSON.parse(readFileSync8(file, "utf8")) : null;
|
|
9052
9604
|
} catch {
|
|
9053
9605
|
return null;
|
|
9054
9606
|
}
|
|
@@ -9056,8 +9608,8 @@ function snapshotIndex() {
|
|
|
9056
9608
|
var schema;
|
|
9057
9609
|
function indexSchema() {
|
|
9058
9610
|
if (schema !== void 0) return schema;
|
|
9059
|
-
const file = shipped(
|
|
9060
|
-
schema = file ? JSON.parse(
|
|
9611
|
+
const file = shipped(join16(import.meta.dirname, "../../core/schema/store-index.json"), join16(import.meta.dirname, "assets/store-index.schema.json"));
|
|
9612
|
+
schema = file ? JSON.parse(readFileSync8(file, "utf8")) : null;
|
|
9061
9613
|
return schema;
|
|
9062
9614
|
}
|
|
9063
9615
|
function indexProblem(x) {
|
|
@@ -9085,11 +9637,11 @@ var StoreCatalog = class {
|
|
|
9085
9637
|
} else if (snap) this.state = { index: snap, from: "snapshot", fetchedAt: null, error: null };
|
|
9086
9638
|
}
|
|
9087
9639
|
get file() {
|
|
9088
|
-
return
|
|
9640
|
+
return join16(this.o.cacheDir, "index.json");
|
|
9089
9641
|
}
|
|
9090
9642
|
readCache() {
|
|
9091
9643
|
try {
|
|
9092
|
-
const c = JSON.parse(
|
|
9644
|
+
const c = JSON.parse(readFileSync8(this.file, "utf8"));
|
|
9093
9645
|
return indexProblem(c.index) ? null : c;
|
|
9094
9646
|
} catch {
|
|
9095
9647
|
return null;
|
|
@@ -9343,14 +9895,14 @@ var MqttClient = class extends EventEmitter2 {
|
|
|
9343
9895
|
this.ping();
|
|
9344
9896
|
}, every);
|
|
9345
9897
|
}
|
|
9346
|
-
drop(
|
|
9898
|
+
drop(why2, refused = false) {
|
|
9347
9899
|
if (this.closed) return;
|
|
9348
9900
|
this.clear();
|
|
9349
9901
|
const s = this.sock;
|
|
9350
9902
|
this.sock = null;
|
|
9351
9903
|
s?.destroy();
|
|
9352
9904
|
this.awaitingPong = false;
|
|
9353
|
-
this.set("error",
|
|
9905
|
+
this.set("error", why2);
|
|
9354
9906
|
const ms = refused ? 5 * 6e4 : RETRY_MS2[Math.min(this.attempt++, RETRY_MS2.length - 1)];
|
|
9355
9907
|
this.later(() => this.open(), ms);
|
|
9356
9908
|
}
|
|
@@ -9614,6 +10166,483 @@ var HomeAssistantBridge = class {
|
|
|
9614
10166
|
}
|
|
9615
10167
|
};
|
|
9616
10168
|
|
|
10169
|
+
// packages/server/src/install-kind.ts
|
|
10170
|
+
import { existsSync as existsSync14, readFileSync as readFileSync9, realpathSync } from "node:fs";
|
|
10171
|
+
import { posix, win32 as win323 } from "node:path";
|
|
10172
|
+
function detectInstall(i) {
|
|
10173
|
+
const exists = i.exists ?? existsSync14;
|
|
10174
|
+
const read = i.readFile ?? ((p) => readFileSync9(p, "utf8"));
|
|
10175
|
+
const win = i.platform === "win32";
|
|
10176
|
+
const P = win ? win323 : posix;
|
|
10177
|
+
const cli = i.cli;
|
|
10178
|
+
const service = detectService(i.platform, i.env, read);
|
|
10179
|
+
const base3 = { cli, service, platform: i.platform };
|
|
10180
|
+
const norm = (p) => win ? p.toLowerCase() : p;
|
|
10181
|
+
const gitUp = (from) => {
|
|
10182
|
+
for (let d = from, n = 0; n < 8; n++) {
|
|
10183
|
+
if (exists(P.join(d, ".git"))) return d;
|
|
10184
|
+
const up = P.dirname(d);
|
|
10185
|
+
if (up === d) break;
|
|
10186
|
+
d = up;
|
|
10187
|
+
}
|
|
10188
|
+
return null;
|
|
10189
|
+
};
|
|
10190
|
+
if (cli.endsWith(".ts")) return { ...base3, kind: "source", dir: gitUp(P.dirname(cli)) ?? P.resolve(P.dirname(cli), "..", "..", "..") };
|
|
10191
|
+
const dir = P.dirname(cli);
|
|
10192
|
+
if (win && P.basename(dir).toLowerCase() === "app") {
|
|
10193
|
+
const app = P.dirname(dir);
|
|
10194
|
+
if (exists(P.join(app, "kiosko.cmd")) && exists(P.join(app, "unins000.exe")) && norm(i.execPath) === norm(P.join(app, "node.exe"))) {
|
|
10195
|
+
const local = i.env.LOCALAPPDATA && norm(app).startsWith(norm(P.join(i.env.LOCALAPPDATA, "Programs") + P.sep));
|
|
10196
|
+
return { ...base3, kind: "windows-installer", dir: app, perUser: !!local };
|
|
10197
|
+
}
|
|
10198
|
+
}
|
|
10199
|
+
const checkout = gitUp(dir);
|
|
10200
|
+
if (checkout && !/[\\/]node_modules[\\/]/.test(dir)) return { ...base3, kind: "source", dir: checkout };
|
|
10201
|
+
if (/[\\/]_npx[\\/]/.test(dir)) return { ...base3, kind: "npx", dir };
|
|
10202
|
+
if (P.basename(dir) === "kiosko" && P.basename(P.dirname(dir)) === "node_modules") {
|
|
10203
|
+
const nm = P.dirname(dir);
|
|
10204
|
+
const prefix = win ? P.dirname(nm) : P.basename(P.dirname(nm)) === "lib" ? P.dirname(P.dirname(nm)) : null;
|
|
10205
|
+
const shim = prefix && (win ? exists(P.join(prefix, "kiosko.cmd")) : exists(P.join(prefix, "bin", "kiosko")));
|
|
10206
|
+
if (prefix && shim) return { ...base3, kind: "npm-global", dir, prefix };
|
|
10207
|
+
}
|
|
10208
|
+
return { ...base3, kind: "other", dir };
|
|
10209
|
+
}
|
|
10210
|
+
function detectService(platform3, env, read) {
|
|
10211
|
+
if (platform3 === "linux") {
|
|
10212
|
+
try {
|
|
10213
|
+
if (/\/kiosko\.service(\/|$)/m.test(read("/proc/self/cgroup"))) return "systemd";
|
|
10214
|
+
} catch {
|
|
10215
|
+
}
|
|
10216
|
+
return null;
|
|
10217
|
+
}
|
|
10218
|
+
if (platform3 === "darwin") return env.XPC_SERVICE_NAME === "dev.kiosko" ? "launchd" : null;
|
|
10219
|
+
return null;
|
|
10220
|
+
}
|
|
10221
|
+
function currentInstall() {
|
|
10222
|
+
let cli = process.argv[1] ?? "";
|
|
10223
|
+
try {
|
|
10224
|
+
cli = realpathSync(cli);
|
|
10225
|
+
} catch {
|
|
10226
|
+
}
|
|
10227
|
+
return detectInstall({ cli, execPath: process.execPath, platform: process.platform, env: process.env });
|
|
10228
|
+
}
|
|
10229
|
+
var npmInstallCommand = (version, registry2) => `npm install -g kiosko@${version}${registry2 && registry2 !== REGISTRY ? ` --registry=${registry2}` : ""}`;
|
|
10230
|
+
function updateInstructions(info, version, registry2) {
|
|
10231
|
+
const url2 = releasePage(version);
|
|
10232
|
+
switch (info.kind) {
|
|
10233
|
+
case "windows-installer":
|
|
10234
|
+
return { kind: info.kind, version, url: url2, download: releaseAsset(version, windowsInstallerName(version)) };
|
|
10235
|
+
case "source":
|
|
10236
|
+
return { kind: info.kind, version, url: url2, command: "git pull && npm install && npm run web:build" };
|
|
10237
|
+
case "npx":
|
|
10238
|
+
return { kind: info.kind, version, url: url2, command: `npx kiosko@${version} start` };
|
|
10239
|
+
default:
|
|
10240
|
+
return { kind: info.kind, version, url: url2, command: npmInstallCommand(version, registry2), ...info.platform === "win32" ? { stopFirst: true } : {} };
|
|
10241
|
+
}
|
|
10242
|
+
}
|
|
10243
|
+
function updateBlocker(info, o = {}) {
|
|
10244
|
+
if (o.demo) return "demo";
|
|
10245
|
+
if (info.kind === "windows-installer") return null;
|
|
10246
|
+
if (info.kind !== "npm-global") return info.kind;
|
|
10247
|
+
if (info.platform === "win32") return "npmWindows";
|
|
10248
|
+
return null;
|
|
10249
|
+
}
|
|
10250
|
+
|
|
10251
|
+
// packages/server/src/self-update.ts
|
|
10252
|
+
import { spawn } from "node:child_process";
|
|
10253
|
+
import { createHash } from "node:crypto";
|
|
10254
|
+
import { createReadStream, createWriteStream, existsSync as existsSync15, mkdirSync as mkdirSync11, readFileSync as readFileSync10, realpathSync as realpathSync2, rmSync as rmSync4, writeFileSync as writeFileSync12 } from "node:fs";
|
|
10255
|
+
import { dirname as dirname7, join as join17, win32 as win324 } from "node:path";
|
|
10256
|
+
import { Readable, Transform } from "node:stream";
|
|
10257
|
+
import { pipeline } from "node:stream/promises";
|
|
10258
|
+
var UpdateError = class extends Error {
|
|
10259
|
+
code;
|
|
10260
|
+
constructor(code, message) {
|
|
10261
|
+
super(message);
|
|
10262
|
+
this.code = code;
|
|
10263
|
+
this.name = "UpdateError";
|
|
10264
|
+
}
|
|
10265
|
+
};
|
|
10266
|
+
var tail = (s, n = 600) => (s.length > n ? `\u2026${s.slice(-n)}` : s).trim();
|
|
10267
|
+
var why = (s, n = 300) => s.split(/\r?\n/).map((l) => l.trim()).find((l) => /^(\w*Error|npm (ERR|error))\b/.test(l))?.slice(0, n) ?? tail(s, n);
|
|
10268
|
+
var isVersion = (v) => typeof v === "string" && !!parseVersion(v) && /^\d+\.\d+\.\d+(-[\w.]+)?$/.test(v);
|
|
10269
|
+
function lastJson(out) {
|
|
10270
|
+
for (const line of out.split(/\r?\n/).reverse()) {
|
|
10271
|
+
const l = line.trim();
|
|
10272
|
+
if (!l.startsWith("{")) continue;
|
|
10273
|
+
try {
|
|
10274
|
+
return JSON.parse(l);
|
|
10275
|
+
} catch {
|
|
10276
|
+
}
|
|
10277
|
+
}
|
|
10278
|
+
return null;
|
|
10279
|
+
}
|
|
10280
|
+
function judgeSelfCheck(now, next, target) {
|
|
10281
|
+
if (next.version !== target) return { ok: false, why: `the new Kiosko says it is ${next.version}, not ${target}`, warnings: [] };
|
|
10282
|
+
const refusedIds = new Set(next.refused.map((r) => r.id).filter(Boolean));
|
|
10283
|
+
const has = new Set(next.plugins.map((p) => p.id));
|
|
10284
|
+
const missing = now.ids.filter((id) => !has.has(id) && !refusedIds.has(id));
|
|
10285
|
+
const fresh = next.problems.filter((p) => !now.problems.includes(p.message) && !next.refused.some((r) => r.origin === p.origin));
|
|
10286
|
+
const warnings = next.refused.filter((r) => r.id && now.ids.includes(r.id)).map((r) => `${r.id}: ${r.reason}`);
|
|
10287
|
+
if (missing.length || fresh.length) return { ok: false, why: [missing.length ? `plugins that would not load: ${missing.join(", ")}` : "", ...fresh.map((p) => `${p.origin}: ${p.message}`)].filter(Boolean).join("; "), warnings };
|
|
10288
|
+
return { ok: true, warnings };
|
|
10289
|
+
}
|
|
10290
|
+
function parseSha256File(text3, name) {
|
|
10291
|
+
for (const line of text3.split(/\r?\n/)) {
|
|
10292
|
+
const m = /^([a-f0-9]{64})(?:\s+\*?(.+?))?\s*$/i.exec(line.trim());
|
|
10293
|
+
if (m && (!m[2] || m[2] === name)) return m[1].toLowerCase();
|
|
10294
|
+
}
|
|
10295
|
+
return null;
|
|
10296
|
+
}
|
|
10297
|
+
async function sha256File(file) {
|
|
10298
|
+
const h = createHash("sha256");
|
|
10299
|
+
await pipeline(createReadStream(file), h);
|
|
10300
|
+
return h.digest("hex");
|
|
10301
|
+
}
|
|
10302
|
+
function restartHow(info, o) {
|
|
10303
|
+
if (info.kind === "windows-installer") return "installer";
|
|
10304
|
+
if (info.service === "systemd") return "systemd";
|
|
10305
|
+
if (info.service === "launchd") return "launchd";
|
|
10306
|
+
if (o.tty || o.pid === 1) return "manual";
|
|
10307
|
+
return "handover";
|
|
10308
|
+
}
|
|
10309
|
+
function installerArgs(perUser, log) {
|
|
10310
|
+
return [...perUser ? ["/VERYSILENT", "/SUPPRESSMSGBOXES", "/NORESTART", "/CURRENTUSER"] : [], `/LOG=${log}`];
|
|
10311
|
+
}
|
|
10312
|
+
function windowsUpgradeScript(o) {
|
|
10313
|
+
const q3 = (s) => `"${s}"`;
|
|
10314
|
+
const kcmd = win324.join(o.dir, "kiosko.cmd");
|
|
10315
|
+
const up = `curl.exe -s -o nul -m 2 http://127.0.0.1:${o.port}/api/version`;
|
|
10316
|
+
return [
|
|
10317
|
+
"@echo off",
|
|
10318
|
+
// Paths with accents (a user's name): the lines after this one are read as UTF-8.
|
|
10319
|
+
"chcp 65001 >nul",
|
|
10320
|
+
"rem Written by Kiosko to update itself: runs the installer, then starts Kiosko again.",
|
|
10321
|
+
`${q3(o.exe)} ${o.args.map((a) => a.startsWith("/LOG=") ? `/LOG=${q3(a.slice(5))}` : a).join(" ")}`,
|
|
10322
|
+
...o.service ? [`schtasks /Query /TN Kiosko >nul 2>&1 || call ${q3(kcmd)} service install >> ${q3(o.log)} 2>&1`] : [],
|
|
10323
|
+
"for /l %%i in (1,1,20) do (",
|
|
10324
|
+
` ${up} && goto :eof`,
|
|
10325
|
+
" ping -n 2 127.0.0.1 >nul",
|
|
10326
|
+
")",
|
|
10327
|
+
o.service ? "schtasks /Run /TN Kiosko >nul 2>&1" : `${q3(kcmd)} start >> ${q3(o.log)} 2>&1`,
|
|
10328
|
+
""
|
|
10329
|
+
].join("\r\n");
|
|
10330
|
+
}
|
|
10331
|
+
var idle = (from) => ({ state: "idle", target: null, from, method: null, steps: [], error: null, rolledBack: false, restart: null, sha256: null, warnings: [], logFile: null });
|
|
10332
|
+
var KioskoUpdater = class {
|
|
10333
|
+
status;
|
|
10334
|
+
file = null;
|
|
10335
|
+
/** This update's log lines, carried across the restart in the marker. */
|
|
10336
|
+
lines = [];
|
|
10337
|
+
d;
|
|
10338
|
+
constructor(d) {
|
|
10339
|
+
this.d = d;
|
|
10340
|
+
this.status = idle(d.current);
|
|
10341
|
+
}
|
|
10342
|
+
get now() {
|
|
10343
|
+
return (this.d.now ?? Date.now)();
|
|
10344
|
+
}
|
|
10345
|
+
set(patch) {
|
|
10346
|
+
this.status = { ...this.status, ...patch };
|
|
10347
|
+
this.d.changed(this.status);
|
|
10348
|
+
}
|
|
10349
|
+
step(code, ok, detail) {
|
|
10350
|
+
const steps = [...this.status.steps];
|
|
10351
|
+
const open = steps.findLastIndex((s2) => s2.code === code && s2.ok === null);
|
|
10352
|
+
const keep = detail ?? (open >= 0 ? steps[open].detail : void 0);
|
|
10353
|
+
const s = { at: this.now, code, ok, ...keep ? { detail: keep } : {} };
|
|
10354
|
+
if (open >= 0 && ok !== null) steps[open] = s;
|
|
10355
|
+
else steps.push(s);
|
|
10356
|
+
if (ok !== null || detail) this.say(`${code}${ok === false ? " failed" : ok ? " ok" : ""}${detail ? `: ${detail}` : ""}`);
|
|
10357
|
+
this.set({ steps });
|
|
10358
|
+
}
|
|
10359
|
+
say(line) {
|
|
10360
|
+
this.lines.push(line);
|
|
10361
|
+
this.d.log(line);
|
|
10362
|
+
}
|
|
10363
|
+
get busy() {
|
|
10364
|
+
return this.status.state === "working" || this.status.state === "restarting";
|
|
10365
|
+
}
|
|
10366
|
+
/** npm next to this Node (nvm, Homebrew…), else the one on the PATH. */
|
|
10367
|
+
npm() {
|
|
10368
|
+
const here = join17(dirname7(this.d.node), process.platform === "win32" ? "npm.cmd" : "npm");
|
|
10369
|
+
return existsSync15(here) ? here : process.platform === "win32" ? "npm.cmd" : "npm";
|
|
10370
|
+
}
|
|
10371
|
+
registryArgs() {
|
|
10372
|
+
return this.d.registry && this.d.registry !== REGISTRY ? [`--registry=${this.d.registry}`] : [];
|
|
10373
|
+
}
|
|
10374
|
+
/** Starts an update to `version` (the newest the check found). Resolves when it ends (or is ready to confirm, on Windows). */
|
|
10375
|
+
async start(version) {
|
|
10376
|
+
if (this.busy) throw new UpdateError("busy", "an update is already under way");
|
|
10377
|
+
if (!isVersion(version) || compareVersions(version, this.d.current) <= 0) throw new UpdateError("noUpdate", `${String(version)} is not newer than ${this.d.current}`);
|
|
10378
|
+
const method = this.d.install.kind === "windows-installer" ? "windows" : "npm";
|
|
10379
|
+
if (this.status.state === "ready" && this.status.target === version) return this.status;
|
|
10380
|
+
this.discard();
|
|
10381
|
+
this.status = { ...idle(this.d.current), state: "working", target: version, method };
|
|
10382
|
+
this.lines = [];
|
|
10383
|
+
this.say(`updating Kiosko ${this.d.current} \u2192 ${version} (${this.d.install.kind}, ${this.d.install.dir})`);
|
|
10384
|
+
this.d.changed(this.status);
|
|
10385
|
+
try {
|
|
10386
|
+
if (method === "windows") await this.downloadInstaller(version);
|
|
10387
|
+
else await this.viaNpm(version);
|
|
10388
|
+
} catch (err) {
|
|
10389
|
+
const e = err instanceof UpdateError ? err : new UpdateError("failed", err instanceof Error ? err.message : String(err));
|
|
10390
|
+
this.d.log(`update failed (${e.code}): ${e.message}`);
|
|
10391
|
+
this.set({ state: "failed", error: { code: e.code, detail: e.message } });
|
|
10392
|
+
}
|
|
10393
|
+
return this.status;
|
|
10394
|
+
}
|
|
10395
|
+
// ---------- npm ----------
|
|
10396
|
+
async viaNpm(version) {
|
|
10397
|
+
const { install, current } = this.d;
|
|
10398
|
+
if (install.kind !== "npm-global" || !install.prefix) throw new UpdateError("cantUpdate", `this Kiosko is not a global npm install (${install.kind})`);
|
|
10399
|
+
const npm2 = this.npm();
|
|
10400
|
+
this.step("prefix", null);
|
|
10401
|
+
const pr = await this.d.run(npm2, ["prefix", "-g"], { timeoutMs: 3e4 });
|
|
10402
|
+
const real = (p) => {
|
|
10403
|
+
try {
|
|
10404
|
+
return realpathSync2(p);
|
|
10405
|
+
} catch {
|
|
10406
|
+
return p;
|
|
10407
|
+
}
|
|
10408
|
+
};
|
|
10409
|
+
const prefix = pr.stdout.trim().split(/\r?\n/).at(-1) ?? "";
|
|
10410
|
+
if (pr.code !== 0 || real(prefix) !== real(install.prefix)) {
|
|
10411
|
+
this.step("prefix", false, `npm installs into ${prefix || "(npm did not say)"}, but this Kiosko runs from ${install.prefix}`);
|
|
10412
|
+
throw new UpdateError("prefixMismatch", `npm's global folder is ${prefix || "unknown"}, not ${install.prefix}: update it by hand with that npm`);
|
|
10413
|
+
}
|
|
10414
|
+
this.step("prefix", true, prefix);
|
|
10415
|
+
this.step("install", null, `npm install -g kiosko@${version}${this.registryArgs().length ? ` ${this.registryArgs()[0]}` : ""}`);
|
|
10416
|
+
const inst = await this.d.run(npm2, ["install", "-g", "--no-audit", "--no-fund", `kiosko@${version}`, ...this.registryArgs()], { timeoutMs: 15 * 6e4 });
|
|
10417
|
+
if (inst.code !== 0) {
|
|
10418
|
+
this.step("install", false, tail(inst.stderr || inst.stdout));
|
|
10419
|
+
await this.rollback(current, false);
|
|
10420
|
+
throw new UpdateError("installFailed", `npm could not install kiosko@${version}: ${why(inst.stderr || inst.stdout)}`);
|
|
10421
|
+
}
|
|
10422
|
+
this.step("install", true);
|
|
10423
|
+
const problem = await this.verify(version);
|
|
10424
|
+
if (problem) {
|
|
10425
|
+
await this.rollback(current, true);
|
|
10426
|
+
throw new UpdateError("verifyFailed", problem);
|
|
10427
|
+
}
|
|
10428
|
+
await this.restart(version);
|
|
10429
|
+
}
|
|
10430
|
+
/** null if the installed Kiosko is `version` and its dry run loads what runs now; else why not. */
|
|
10431
|
+
async verify(version) {
|
|
10432
|
+
const cli = this.d.install.cli;
|
|
10433
|
+
this.step("verify", null);
|
|
10434
|
+
const v = await this.d.run(this.d.node, [cli, "--version"], { timeoutMs: 6e4 });
|
|
10435
|
+
const said = v.stdout.trim().split(/\r?\n/).at(-1)?.trim() ?? "";
|
|
10436
|
+
if (v.code !== 0 || said !== version) {
|
|
10437
|
+
const problem = v.code !== 0 ? `the new Kiosko does not start: ${why(v.stderr || v.stdout)}` : `the installed Kiosko says ${said || "nothing"}, not ${version}`;
|
|
10438
|
+
this.step("verify", false, problem);
|
|
10439
|
+
return problem;
|
|
10440
|
+
}
|
|
10441
|
+
this.step("verify", true, `kiosko --version: ${said}`);
|
|
10442
|
+
this.step("selfCheck", null);
|
|
10443
|
+
const c = await this.d.run(this.d.node, [cli, "self-check", "--json"], { timeoutMs: 12e4, env: { ...process.env, KIOSKO_QUIET: "1" } });
|
|
10444
|
+
const report = lastJson(c.stdout);
|
|
10445
|
+
if (c.code !== 0 && !report) {
|
|
10446
|
+
const problem = `the new Kiosko failed loading its plugins: ${why(c.stderr || c.stdout)}`;
|
|
10447
|
+
this.step("selfCheck", false, problem);
|
|
10448
|
+
return problem;
|
|
10449
|
+
}
|
|
10450
|
+
if (report?.kiosko !== "self-check") {
|
|
10451
|
+
this.step("selfCheck", true, "no dry run in that version: checked its version only");
|
|
10452
|
+
return null;
|
|
10453
|
+
}
|
|
10454
|
+
const j = judgeSelfCheck(this.d.loaded(), report, version);
|
|
10455
|
+
if (j.warnings.length) this.set({ warnings: j.warnings });
|
|
10456
|
+
if (!j.ok) {
|
|
10457
|
+
this.step("selfCheck", false, j.why);
|
|
10458
|
+
return j.why ?? "the dry run failed";
|
|
10459
|
+
}
|
|
10460
|
+
this.step("selfCheck", true, `${report.plugins.length} plugins load${j.warnings.length ? `; not with this version: ${j.warnings.join("; ")}` : ""}`);
|
|
10461
|
+
return null;
|
|
10462
|
+
}
|
|
10463
|
+
/** Puts `version` back (after a failed install or check), and checks it is. */
|
|
10464
|
+
async rollback(version, needed) {
|
|
10465
|
+
if (!needed) {
|
|
10466
|
+
const v2 = await this.d.run(this.d.node, [this.d.install.cli, "--version"], { timeoutMs: 6e4 }).catch(() => ({ code: 1, stdout: "", stderr: "" }));
|
|
10467
|
+
if (v2.code === 0 && v2.stdout.trim().split(/\r?\n/).at(-1)?.trim() === version) return;
|
|
10468
|
+
}
|
|
10469
|
+
this.step("rollback", null, `npm install -g kiosko@${version}`);
|
|
10470
|
+
const r = await this.d.run(this.npm(), ["install", "-g", "--no-audit", "--no-fund", `kiosko@${version}`, ...this.registryArgs()], { timeoutMs: 15 * 6e4 });
|
|
10471
|
+
const v = r.code === 0 ? await this.d.run(this.d.node, [this.d.install.cli, "--version"], { timeoutMs: 6e4 }) : null;
|
|
10472
|
+
if (v && v.code === 0 && v.stdout.trim().split(/\r?\n/).at(-1)?.trim() === version) {
|
|
10473
|
+
this.step("rollback", true, `${version} is installed again`);
|
|
10474
|
+
this.set({ rolledBack: true });
|
|
10475
|
+
return;
|
|
10476
|
+
}
|
|
10477
|
+
this.step("rollback", false, tail(r.stderr || r.stdout || "the previous version did not come back"));
|
|
10478
|
+
throw new UpdateError("rollbackFailed", `the update failed and ${version} could not be installed again: this Kiosko keeps running, but before restarting it run: npm install -g kiosko@${version}`);
|
|
10479
|
+
}
|
|
10480
|
+
async restart(version) {
|
|
10481
|
+
const how = this.d.restartHow;
|
|
10482
|
+
this.d.mark?.({ from: this.d.current, to: version, at: this.now, how, lines: this.lines.slice(-30) });
|
|
10483
|
+
if (how === "manual") {
|
|
10484
|
+
this.step("restart", true, `installed; restart Kiosko to use ${version}`);
|
|
10485
|
+
this.set({ state: "done", restart: "manual" });
|
|
10486
|
+
return;
|
|
10487
|
+
}
|
|
10488
|
+
this.set({ state: "restarting", restart: how });
|
|
10489
|
+
if (how === "systemd" || how === "launchd") {
|
|
10490
|
+
const uid = process.getuid?.() ?? 0;
|
|
10491
|
+
const [cmd2, args] = how === "systemd" ? ["systemctl", ["--user", "--no-block", "restart", "kiosko.service"]] : ["launchctl", ["kickstart", "-k", `gui/${uid}/dev.kiosko`]];
|
|
10492
|
+
this.step("restart", null, `${cmd2} ${args.join(" ")}`);
|
|
10493
|
+
const r = await this.d.run(cmd2, args, { timeoutMs: 3e4 });
|
|
10494
|
+
if (r.code !== 0) {
|
|
10495
|
+
this.step("restart", false, tail(r.stderr || r.stdout));
|
|
10496
|
+
this.set({ state: "done", restart: "manual" });
|
|
10497
|
+
throw new UpdateError("restartFailed", `${version} is installed, but the service did not restart (${tail(r.stderr || r.stdout, 200)}): restart Kiosko yourself`);
|
|
10498
|
+
}
|
|
10499
|
+
return;
|
|
10500
|
+
}
|
|
10501
|
+
const h = this.d.handover;
|
|
10502
|
+
if (!h) throw new UpdateError("restartFailed", "no way to restart here");
|
|
10503
|
+
this.step("restart", null, `handing over to ${version}; its output goes to ${h.logFile}`);
|
|
10504
|
+
this.set({ logFile: h.logFile });
|
|
10505
|
+
await h.release();
|
|
10506
|
+
const child = h.spawn();
|
|
10507
|
+
let gone = false;
|
|
10508
|
+
void child.exited.then(() => gone = true);
|
|
10509
|
+
const sleep = this.d.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
10510
|
+
const until = this.now + (this.d.handoverTimeoutMs ?? 6e4);
|
|
10511
|
+
while (this.now < until && !gone) {
|
|
10512
|
+
await sleep(500);
|
|
10513
|
+
const p = await h.probe().catch(() => null);
|
|
10514
|
+
if (p && p.version === version && p.instance !== h.instance) {
|
|
10515
|
+
this.d.log(`Kiosko ${version} is running; this one (${this.d.current}) stops`);
|
|
10516
|
+
h.exit();
|
|
10517
|
+
return;
|
|
10518
|
+
}
|
|
10519
|
+
}
|
|
10520
|
+
child.kill();
|
|
10521
|
+
await h.reclaim();
|
|
10522
|
+
this.d.mark?.(null);
|
|
10523
|
+
this.step("restart", false, gone ? `the new Kiosko stopped right away (see ${h.logFile})` : "the new Kiosko did not answer in time");
|
|
10524
|
+
await this.rollback(this.d.current, true).catch((err) => this.d.log(String(err instanceof Error ? err.message : err)));
|
|
10525
|
+
throw new UpdateError("restartFailed", `Kiosko ${version} did not start (see ${h.logFile}); ${this.d.current} keeps running`);
|
|
10526
|
+
}
|
|
10527
|
+
// ---------- Windows ----------
|
|
10528
|
+
async downloadInstaller(version) {
|
|
10529
|
+
const name = windowsInstallerName(version);
|
|
10530
|
+
const exeUrl = releaseAsset(version, name);
|
|
10531
|
+
const dir = join17(this.d.tmpDir, `kiosko-update-${version}`);
|
|
10532
|
+
rmSync4(dir, { recursive: true, force: true });
|
|
10533
|
+
mkdirSync11(dir, { recursive: true });
|
|
10534
|
+
const file = join17(dir, name);
|
|
10535
|
+
this.step("download", null, exeUrl);
|
|
10536
|
+
let expected;
|
|
10537
|
+
try {
|
|
10538
|
+
const r = await this.d.fetch(`${exeUrl}.sha256`, { redirect: "follow" });
|
|
10539
|
+
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
|
10540
|
+
expected = parseSha256File((await r.text()).slice(0, 4096), name);
|
|
10541
|
+
} catch (err) {
|
|
10542
|
+
this.step("download", false, `${name}.sha256: ${err instanceof Error ? err.message : String(err)}`);
|
|
10543
|
+
throw new UpdateError("downloadFailed", `could not download ${name}.sha256 from GitHub: download the installer from the release page instead`);
|
|
10544
|
+
}
|
|
10545
|
+
if (!expected) {
|
|
10546
|
+
this.step("download", false, `${name}.sha256 names no checksum for ${name}`);
|
|
10547
|
+
throw new UpdateError("hashMissing", `the release has no usable checksum for ${name}: not running it`);
|
|
10548
|
+
}
|
|
10549
|
+
const hash = createHash("sha256");
|
|
10550
|
+
let size = 0;
|
|
10551
|
+
try {
|
|
10552
|
+
const r = await this.d.fetch(exeUrl, { redirect: "follow" });
|
|
10553
|
+
if (!r.ok || !r.body) throw new Error(`HTTP ${r.status}`);
|
|
10554
|
+
const count = new Transform({
|
|
10555
|
+
transform(chunk, _e, cb) {
|
|
10556
|
+
size += chunk.length;
|
|
10557
|
+
if (size > 500 * 1024 * 1024) return cb(new Error("larger than 500 MB: not an installer of ours"));
|
|
10558
|
+
hash.update(chunk);
|
|
10559
|
+
cb(null, chunk);
|
|
10560
|
+
}
|
|
10561
|
+
});
|
|
10562
|
+
await pipeline(Readable.fromWeb(r.body), count, createWriteStream(file));
|
|
10563
|
+
} catch (err) {
|
|
10564
|
+
rmSync4(dir, { recursive: true, force: true });
|
|
10565
|
+
this.step("download", false, err instanceof Error ? err.message : String(err));
|
|
10566
|
+
throw new UpdateError("downloadFailed", `could not download ${name}: ${err instanceof Error ? err.message : String(err)}`);
|
|
10567
|
+
}
|
|
10568
|
+
this.step("download", true, `${(size / 1024 / 1024).toFixed(1)} MB`);
|
|
10569
|
+
const got = hash.digest("hex");
|
|
10570
|
+
if (got !== expected) {
|
|
10571
|
+
rmSync4(dir, { recursive: true, force: true });
|
|
10572
|
+
this.step("hash", false, `sha256 ${got}, the release says ${expected}`);
|
|
10573
|
+
throw new UpdateError("hashMismatch", `${name} is not the file the release publishes (sha256 ${got.slice(0, 12)}\u2026, expected ${expected.slice(0, 12)}\u2026): deleted, not run`);
|
|
10574
|
+
}
|
|
10575
|
+
this.step("hash", true, `sha256 ${got}`);
|
|
10576
|
+
this.file = file;
|
|
10577
|
+
this.set({ state: "ready", sha256: got });
|
|
10578
|
+
}
|
|
10579
|
+
/** Windows, after the person confirms: checks the file once more and runs the installer. */
|
|
10580
|
+
async confirm(version) {
|
|
10581
|
+
if (this.status.state !== "ready" || this.status.target !== version || !this.file) throw new UpdateError("notReady", `no verified installer of ${String(version)} waiting`);
|
|
10582
|
+
const got = await sha256File(this.file).catch(() => null);
|
|
10583
|
+
if (got !== this.status.sha256) {
|
|
10584
|
+
this.discard();
|
|
10585
|
+
this.set({ state: "failed", error: { code: "hashMismatch", detail: "the downloaded installer changed since it was checked: deleted, not run" } });
|
|
10586
|
+
return this.status;
|
|
10587
|
+
}
|
|
10588
|
+
const info = this.d.install;
|
|
10589
|
+
const dir = dirname7(this.file);
|
|
10590
|
+
const service = await this.d.serviceTask?.().catch(() => false) ?? false;
|
|
10591
|
+
const script = join17(dir, "kiosko-upgrade.cmd");
|
|
10592
|
+
const log = win324.join(this.d.home, "kiosko.log");
|
|
10593
|
+
writeFileSync12(script, windowsUpgradeScript({ exe: this.file, args: installerArgs(!!info.perUser, join17(dir, "install.log")), dir: info.dir, service, port: this.d.port, log }));
|
|
10594
|
+
this.d.mark?.({ from: this.d.current, to: version, at: this.now, how: "installer", lines: this.lines.slice(-30) });
|
|
10595
|
+
this.step("launch", true, `${this.file} ${installerArgs(!!info.perUser, join17(dir, "install.log")).join(" ")}${info.perUser ? "" : " (the wizard: this Kiosko is not installed per user)"}`);
|
|
10596
|
+
this.set({ state: "restarting", restart: "installer" });
|
|
10597
|
+
this.d.launch?.(script);
|
|
10598
|
+
return this.status;
|
|
10599
|
+
}
|
|
10600
|
+
/** Forgets a downloaded installer (Cancel in the editor, or a new start). */
|
|
10601
|
+
discard() {
|
|
10602
|
+
if (this.file) rmSync4(dirname7(this.file), { recursive: true, force: true });
|
|
10603
|
+
this.file = null;
|
|
10604
|
+
if (this.status.state === "ready") this.set(idle(this.d.current));
|
|
10605
|
+
}
|
|
10606
|
+
};
|
|
10607
|
+
var realRun = (cmd2, args, o = {}) => new Promise((ok) => {
|
|
10608
|
+
const shell = process.platform === "win32" && /\.cmd$/i.test(cmd2);
|
|
10609
|
+
const child = spawn(shell && /\s/.test(cmd2) ? `"${cmd2}"` : cmd2, args, { env: o.env ?? process.env, shell, windowsHide: true, stdio: ["ignore", "pipe", "pipe"] });
|
|
10610
|
+
let stdout = "";
|
|
10611
|
+
let stderr = "";
|
|
10612
|
+
child.stdout.on("data", (d) => stdout = (stdout + d).slice(-2e4));
|
|
10613
|
+
child.stderr.on("data", (d) => stderr = (stderr + d).slice(-2e4));
|
|
10614
|
+
const t2 = setTimeout(() => child.kill(), o.timeoutMs ?? 12e4);
|
|
10615
|
+
child.on("error", (err) => {
|
|
10616
|
+
clearTimeout(t2);
|
|
10617
|
+
ok({ code: 127, stdout, stderr: stderr || err.message });
|
|
10618
|
+
});
|
|
10619
|
+
child.on("close", (code) => {
|
|
10620
|
+
clearTimeout(t2);
|
|
10621
|
+
ok({ code: code ?? 1, stdout, stderr });
|
|
10622
|
+
});
|
|
10623
|
+
});
|
|
10624
|
+
var markerFile = (home) => join17(home, "update.json");
|
|
10625
|
+
function writeMarker(home, m) {
|
|
10626
|
+
if (!m) return void rmSync4(markerFile(home), { force: true });
|
|
10627
|
+
mkdirSync11(home, { recursive: true });
|
|
10628
|
+
writeFileSync12(markerFile(home), `${JSON.stringify(m)}
|
|
10629
|
+
`);
|
|
10630
|
+
}
|
|
10631
|
+
function readMarker(home, version, now = Date.now()) {
|
|
10632
|
+
const f = markerFile(home);
|
|
10633
|
+
if (!existsSync15(f)) return null;
|
|
10634
|
+
let m = {};
|
|
10635
|
+
try {
|
|
10636
|
+
m = JSON.parse(readFileSync10(f, "utf8"));
|
|
10637
|
+
} catch {
|
|
10638
|
+
}
|
|
10639
|
+
rmSync4(f, { force: true });
|
|
10640
|
+
if (typeof m.at !== "number" || now - m.at > 36e5 || !m.to || !m.from) return null;
|
|
10641
|
+
const lines = Array.isArray(m.lines) ? m.lines.filter((l) => typeof l === "string").slice(-30) : [];
|
|
10642
|
+
if (m.to === version) return { ok: true, message: `Kiosko updated from ${m.from} to ${version}`, lines };
|
|
10643
|
+
return { ok: false, message: `the update to ${m.to} did not happen: this is Kiosko ${version}`, lines };
|
|
10644
|
+
}
|
|
10645
|
+
|
|
9617
10646
|
// packages/server/src/server.ts
|
|
9618
10647
|
var require3 = createRequire3(import.meta.url);
|
|
9619
10648
|
var MIME = {
|
|
@@ -9627,11 +10656,12 @@ var MIME = {
|
|
|
9627
10656
|
".woff2": "font/woff2",
|
|
9628
10657
|
".ico": "image/x-icon"
|
|
9629
10658
|
};
|
|
10659
|
+
var realDiscover = async (url2, tokenFile) => ({ trcc: await discoverTrcc(url2, tokenFile), usb: await discoverUsb() });
|
|
9630
10660
|
function webRoot() {
|
|
9631
|
-
const bundled =
|
|
9632
|
-
if (
|
|
10661
|
+
const bundled = join18(import.meta.dirname, "web");
|
|
10662
|
+
if (existsSync16(join18(bundled, "index.html"))) return bundled;
|
|
9633
10663
|
try {
|
|
9634
|
-
return
|
|
10664
|
+
return join18(dirname8(require3.resolve("@kiosko/web/package.json")), "dist");
|
|
9635
10665
|
} catch {
|
|
9636
10666
|
return resolve7(import.meta.dirname, "../../web/dist");
|
|
9637
10667
|
}
|
|
@@ -9673,9 +10703,95 @@ function startServer(o) {
|
|
|
9673
10703
|
const checking = o.checkUpdates ?? (!runtime.demoMode && process.env.KIOSKO_NO_UPDATE_CHECK !== "1");
|
|
9674
10704
|
const updateTimers = checking ? [setTimeout(() => void refreshUpdates().catch(() => void 0), 2e4), setInterval(() => void refreshUpdates().catch(() => void 0), 24 * 36e5)] : [];
|
|
9675
10705
|
for (const t2 of updateTimers) t2.unref?.();
|
|
9676
|
-
const store = o.store ?? new StoreCatalog({ cacheDir:
|
|
10706
|
+
const store = o.store ?? new StoreCatalog({ cacheDir: join18(paths.home, "store") });
|
|
9677
10707
|
const storeTimers = checking ? [setTimeout(() => void store.refresh(), 15e3), setInterval(() => void store.refresh(), 24 * 36e5)] : [];
|
|
9678
10708
|
for (const t2 of storeTimers) t2.unref?.();
|
|
10709
|
+
const home = o.home ?? paths.home;
|
|
10710
|
+
const install = o.install ?? currentInstall();
|
|
10711
|
+
const registryUrl = o.selfUpdate?.registry ?? npmRegistry();
|
|
10712
|
+
const blocker = updateBlocker(install, { demo: runtime.demoMode });
|
|
10713
|
+
const instance = randomBytes(8).toString("hex");
|
|
10714
|
+
const how = o.selfUpdate?.restartHow ?? restartHow(install, { tty: !!process.stdout.isTTY, pid: process.pid });
|
|
10715
|
+
const probeHost = o.host === "0.0.0.0" || o.host === "::" ? "127.0.0.1" : o.host.includes(":") ? `[${o.host}]` : o.host;
|
|
10716
|
+
const handover = {
|
|
10717
|
+
instance,
|
|
10718
|
+
logFile: join18(home, "kiosko.log"),
|
|
10719
|
+
release: async () => {
|
|
10720
|
+
runtime.stop();
|
|
10721
|
+
for (const c of clients) c.end();
|
|
10722
|
+
clients.clear();
|
|
10723
|
+
await new Promise((ok) => {
|
|
10724
|
+
server.close(() => ok());
|
|
10725
|
+
server.closeAllConnections();
|
|
10726
|
+
setTimeout(ok, 3e3).unref();
|
|
10727
|
+
});
|
|
10728
|
+
},
|
|
10729
|
+
reclaim: async () => {
|
|
10730
|
+
await new Promise((ok, fail) => {
|
|
10731
|
+
server.once("error", fail);
|
|
10732
|
+
server.listen(o.port, o.host, () => {
|
|
10733
|
+
server.off("error", fail);
|
|
10734
|
+
ok();
|
|
10735
|
+
});
|
|
10736
|
+
});
|
|
10737
|
+
runtime.start();
|
|
10738
|
+
},
|
|
10739
|
+
spawn: () => {
|
|
10740
|
+
const out = openSync(join18(home, "kiosko.log"), "a");
|
|
10741
|
+
const args = process.argv.slice(2).filter((a) => a !== "--open");
|
|
10742
|
+
const child = spawn2(process.execPath, [...process.execArgv, install.cli, ...args], { detached: true, stdio: ["ignore", out, out], env: process.env, cwd: process.cwd(), windowsHide: true });
|
|
10743
|
+
const exited = new Promise((ok) => {
|
|
10744
|
+
child.once("exit", ok);
|
|
10745
|
+
child.once("error", ok);
|
|
10746
|
+
});
|
|
10747
|
+
child.unref();
|
|
10748
|
+
return { exited, kill: () => void child.kill() };
|
|
10749
|
+
},
|
|
10750
|
+
probe: async () => {
|
|
10751
|
+
const r = await fetch(`http://${probeHost}:${o.port}/api/version`, { signal: AbortSignal.timeout(1500) });
|
|
10752
|
+
return r.ok ? await r.json() : null;
|
|
10753
|
+
},
|
|
10754
|
+
exit: () => {
|
|
10755
|
+
close();
|
|
10756
|
+
runtime.stop();
|
|
10757
|
+
setTimeout(() => process.exit(0), 100);
|
|
10758
|
+
}
|
|
10759
|
+
};
|
|
10760
|
+
const updater = new KioskoUpdater({
|
|
10761
|
+
install,
|
|
10762
|
+
current: o.version,
|
|
10763
|
+
registry: registryUrl,
|
|
10764
|
+
node: process.execPath,
|
|
10765
|
+
run: realRun,
|
|
10766
|
+
fetch: (u, i) => fetch(u, i),
|
|
10767
|
+
loaded: () => ({ ids: runtime.registry.list().map((p) => p.def.id), problems: runtime.registry.problems.map((p) => p.message) }),
|
|
10768
|
+
log: (m) => runtime.log("kiosko-update", m),
|
|
10769
|
+
changed: (st) => send("kiosko-update", st),
|
|
10770
|
+
tmpDir: tmpdir2(),
|
|
10771
|
+
restartHow: how,
|
|
10772
|
+
handover,
|
|
10773
|
+
mark: (m) => writeMarker(home, m),
|
|
10774
|
+
launch: (script) => spawn2("cmd.exe", ["/d", "/c", script], { detached: true, stdio: "ignore", windowsHide: true }).unref(),
|
|
10775
|
+
serviceTask: async () => (await realRun("schtasks", ["/Query", "/TN", "Kiosko"], { timeoutMs: 15e3 })).code === 0,
|
|
10776
|
+
port: o.port,
|
|
10777
|
+
home,
|
|
10778
|
+
...o.selfUpdate
|
|
10779
|
+
});
|
|
10780
|
+
if (!runtime.demoMode) {
|
|
10781
|
+
const m = readMarker(home, o.version);
|
|
10782
|
+
if (m) {
|
|
10783
|
+
for (const l of m.lines) runtime.log("kiosko-update", `(before the restart) ${l}`);
|
|
10784
|
+
runtime.log("kiosko-update", m.message);
|
|
10785
|
+
}
|
|
10786
|
+
}
|
|
10787
|
+
const kioskoUpdateState = () => ({
|
|
10788
|
+
install: { kind: install.kind, service: install.service, dir: install.dir, perUser: install.perUser ?? false, platform: install.platform },
|
|
10789
|
+
canUpdate: blocker === null,
|
|
10790
|
+
blocker,
|
|
10791
|
+
restart: how,
|
|
10792
|
+
instructions: updates?.kiosko ? updateInstructions(install, updates.kiosko.latest, registryUrl) : null,
|
|
10793
|
+
status: updater.status
|
|
10794
|
+
});
|
|
9679
10795
|
const installFromStore = async (p, version) => {
|
|
9680
10796
|
const index = store.current().index;
|
|
9681
10797
|
const release = p.releases.find((r) => r.version === version);
|
|
@@ -9708,16 +10824,23 @@ data: ${JSON.stringify(data)}
|
|
|
9708
10824
|
const fullStatus = () => ({ ...runtime.status(), homeassistant: bridge?.status() ?? { enabled: false, state: "off", error: null } });
|
|
9709
10825
|
const statusTimer = setInterval(() => send("status", fullStatus()), 3e3);
|
|
9710
10826
|
const allowedHosts = /* @__PURE__ */ new Set([`127.0.0.1:${o.port}`, `localhost:${o.port}`, `[::1]:${o.port}`, `${o.host}:${o.port}`]);
|
|
9711
|
-
function
|
|
10827
|
+
function uiLocale(req) {
|
|
10828
|
+
const l = runtime.config.locale;
|
|
10829
|
+
if (l && l !== "auto") return l;
|
|
10830
|
+
const first = String(req?.headers["accept-language"] ?? "").split(",")[0]?.split(";")[0]?.trim();
|
|
10831
|
+
return first && first !== "*" ? first : resolveLocale(runtime.config);
|
|
10832
|
+
}
|
|
10833
|
+
function state(req) {
|
|
9712
10834
|
const locale = resolveLocale(runtime.config);
|
|
9713
10835
|
return {
|
|
9714
10836
|
version: o.version,
|
|
9715
10837
|
rev,
|
|
9716
10838
|
locale,
|
|
9717
10839
|
config: runtime.config,
|
|
9718
|
-
catalog: runtime.registry.catalog(
|
|
10840
|
+
catalog: runtime.registry.catalog(uiLocale(req)),
|
|
9719
10841
|
refused: runtime.registry.refused,
|
|
9720
10842
|
updates: updates && { checkedAt: updates.checkedAt, plugins: updates.plugins, kiosko: updates.kiosko ?? null },
|
|
10843
|
+
kioskoUpdate: kioskoUpdateState(),
|
|
9721
10844
|
categories: CATEGORIES,
|
|
9722
10845
|
themes: THEMES,
|
|
9723
10846
|
presets: PANEL_PRESETS,
|
|
@@ -9737,7 +10860,7 @@ data: ${JSON.stringify(data)}
|
|
|
9737
10860
|
const p = url2.pathname;
|
|
9738
10861
|
const m = req.method ?? "GET";
|
|
9739
10862
|
if (m !== "GET" && req.headers["x-kiosko"] !== "1") return json(res, 403, { error: "missing X-Kiosko header" });
|
|
9740
|
-
if (p === "/api/state" && m === "GET") return json(res, 200, state());
|
|
10863
|
+
if (p === "/api/state" && m === "GET") return json(res, 200, state(req));
|
|
9741
10864
|
if (p === "/api/config" && m === "PUT") {
|
|
9742
10865
|
const b = await body(req);
|
|
9743
10866
|
const raw = b && typeof b === "object" && "config" in b ? b.config : b;
|
|
@@ -9858,13 +10981,38 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
9858
10981
|
}
|
|
9859
10982
|
if (p === "/api/devices/discover" && m === "GET") {
|
|
9860
10983
|
const url0 = url2.searchParams.get("url") ?? "http://127.0.0.1:8099";
|
|
9861
|
-
return json(res, 200,
|
|
10984
|
+
return json(res, 200, await (o.discover ?? realDiscover)(url0, url2.searchParams.get("tokenFile") ?? void 0));
|
|
10985
|
+
}
|
|
10986
|
+
if (p === "/api/version" && m === "GET") return json(res, 200, { version: o.version, instance });
|
|
10987
|
+
if (p === "/api/kiosko/update" && m === "GET") return json(res, 200, kioskoUpdateState());
|
|
10988
|
+
if (p === "/api/kiosko/update" && m === "POST") {
|
|
10989
|
+
const b = await body(req, 4096);
|
|
10990
|
+
if (runtime.demoMode) return json(res, 409, { error: "not in demo mode", code: "demo" });
|
|
10991
|
+
if (blocker) return json(res, 409, { error: `this Kiosko can't update itself (${blocker}): follow the instructions`, code: "cantUpdateKiosko", params: { why: blocker } });
|
|
10992
|
+
const latest = updates?.kiosko?.latest;
|
|
10993
|
+
if (!latest || b.version !== latest) return json(res, 409, { error: `no update of Kiosko to ${String(b.version)}`, code: "noKioskoUpdate", params: { version: String(b.version) } });
|
|
10994
|
+
if (updater.busy) return json(res, 409, { error: "an update is already under way", code: "updateBusy" });
|
|
10995
|
+
updater.start(latest).catch((err) => runtime.log("kiosko-update", String(err instanceof Error ? err.message : err)));
|
|
10996
|
+
return json(res, 202, kioskoUpdateState());
|
|
10997
|
+
}
|
|
10998
|
+
if (p === "/api/kiosko/update/confirm" && m === "POST") {
|
|
10999
|
+
const b = await body(req, 4096);
|
|
11000
|
+
try {
|
|
11001
|
+
await updater.confirm(String(b.version));
|
|
11002
|
+
return json(res, 200, kioskoUpdateState());
|
|
11003
|
+
} catch (err) {
|
|
11004
|
+
return json(res, 409, { error: err instanceof Error ? err.message : String(err), code: err instanceof UpdateError ? err.code : "failed" });
|
|
11005
|
+
}
|
|
11006
|
+
}
|
|
11007
|
+
if (p === "/api/kiosko/update/cancel" && m === "POST") {
|
|
11008
|
+
updater.discard();
|
|
11009
|
+
return json(res, 200, kioskoUpdateState());
|
|
9862
11010
|
}
|
|
9863
11011
|
if (p === "/api/logs" && m === "GET") return json(res, 200, runtime.logs.slice(-200));
|
|
9864
11012
|
if (p === "/api/choices" && m === "GET") {
|
|
9865
11013
|
const source = url2.searchParams.get("source") ?? "";
|
|
9866
11014
|
const list2 = url2.searchParams.get("list") ?? "";
|
|
9867
|
-
return json(res, 200, runtime.registry.choices(source, list2, runtime.hub.data(source),
|
|
11015
|
+
return json(res, 200, runtime.registry.choices(source, list2, runtime.hub.data(source), uiLocale(req)));
|
|
9868
11016
|
}
|
|
9869
11017
|
if (p === "/api/plugins/install" && m === "POST") {
|
|
9870
11018
|
const b = await body(req);
|
|
@@ -9874,7 +11022,7 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
9874
11022
|
if (r.restart) restartNeeded = true;
|
|
9875
11023
|
rev++;
|
|
9876
11024
|
send("config", { rev, by: null });
|
|
9877
|
-
return json(res, 200, { ok: true, output: r.output, ids: r.ids, problem: r.problem ?? null, rolledBack: !!r.rolledBack, addedPermissions: r.addedPermissions ?? null, restartNeeded, state: state() });
|
|
11025
|
+
return json(res, 200, { ok: true, output: r.output, ids: r.ids, problem: r.problem ?? null, rolledBack: !!r.rolledBack, addedPermissions: r.addedPermissions ?? null, restartNeeded, state: state(req) });
|
|
9878
11026
|
} catch (err) {
|
|
9879
11027
|
return json(res, /valid npm/.test(String(err)) ? 400 : 500, { error: err instanceof Error ? err.message : String(err) });
|
|
9880
11028
|
}
|
|
@@ -9910,8 +11058,8 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
9910
11058
|
const release = sp.releases.find((r) => r.version === b.version);
|
|
9911
11059
|
if (!release) return json(res, 409, { error: `${sp.package} has no release ${String(b.version)} in the store`, code: "noRelease", params: { id, version: String(b.version) } });
|
|
9912
11060
|
if (release.withdrawn) return json(res, 409, { error: `${sp.package}@${release.version} was withdrawn`, code: "withdrawn", params: { id, version: release.version } });
|
|
9913
|
-
const
|
|
9914
|
-
if (
|
|
11061
|
+
const why2 = releaseProblem({ sdk: release.sdk, platforms: release.platforms ?? sp.platforms }, { sdk: SDK_VERSION, platform: process.platform });
|
|
11062
|
+
if (why2) return json(res, 409, { error: why2.code === "sdk" ? `written for the plugin API ${why2.range}; this Kiosko has ${SDK_VERSION}` : `works on ${why2.platforms.join(", ")}, not ${process.platform}`, code: "cantInstall", params: { id } });
|
|
9915
11063
|
if (sp.tier === "found" && b.acceptRisk !== true) return json(res, 409, { error: `${sp.package} is unreviewed: confirm you accept the risk`, code: "acceptRisk", params: { id } });
|
|
9916
11064
|
try {
|
|
9917
11065
|
const results = await installFromStore(sp, release.version);
|
|
@@ -9919,7 +11067,7 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
9919
11067
|
rev++;
|
|
9920
11068
|
send("config", { rev, by: null });
|
|
9921
11069
|
const problem = results.map((r) => r.problem).filter(Boolean).join("; ") || null;
|
|
9922
|
-
return json(res, 200, { ok: !problem, ids: results.flatMap((r) => r.ids), problem, rolledBack: results.some((r) => r.rolledBack), addedPermissions: results.at(-1)?.addedPermissions ?? null, version: release.version, restartNeeded, state: state() });
|
|
11070
|
+
return json(res, 200, { ok: !problem, ids: results.flatMap((r) => r.ids), problem, rolledBack: results.some((r) => r.rolledBack), addedPermissions: results.at(-1)?.addedPermissions ?? null, version: release.version, restartNeeded, state: state(req) });
|
|
9923
11071
|
} catch (err) {
|
|
9924
11072
|
return json(res, err instanceof IntegrityError ? 409 : 500, { error: err instanceof Error ? err.message : String(err), ...err instanceof IntegrityError ? { code: "integrity", params: { id } } : {} });
|
|
9925
11073
|
}
|
|
@@ -9932,7 +11080,7 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
9932
11080
|
if (!r.removed) return json(res, 409, { error: `can't remove "${id}": ${r.reason}`, code: "cantRemove", params: { id, why: r.reason } });
|
|
9933
11081
|
rev++;
|
|
9934
11082
|
send("config", { rev, by: null });
|
|
9935
|
-
return json(res, 200, state());
|
|
11083
|
+
return json(res, 200, state(req));
|
|
9936
11084
|
} catch (err) {
|
|
9937
11085
|
return json(res, 500, { error: err instanceof Error ? err.message : String(err) });
|
|
9938
11086
|
}
|
|
@@ -9958,7 +11106,7 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
9958
11106
|
if (r.restart) restartNeeded = true;
|
|
9959
11107
|
rev++;
|
|
9960
11108
|
send("config", { rev, by: null });
|
|
9961
|
-
return json(res, 200, { ok: !r.problem, ids: r.ids, problem: r.problem ?? null, rolledBack: !!r.rolledBack, addedPermissions: r.addedPermissions ?? null, version: u.version, state: state() });
|
|
11109
|
+
return json(res, 200, { ok: !r.problem, ids: r.ids, problem: r.problem ?? null, rolledBack: !!r.rolledBack, addedPermissions: r.addedPermissions ?? null, version: u.version, state: state(req) });
|
|
9962
11110
|
} catch (err) {
|
|
9963
11111
|
return json(res, 500, { error: err instanceof Error ? err.message : String(err) });
|
|
9964
11112
|
}
|
|
@@ -9970,7 +11118,7 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
9970
11118
|
if (problem) return json(res, 409, { error: problem, code: "reloadFailed", params: { id, why: problem } });
|
|
9971
11119
|
rev++;
|
|
9972
11120
|
send("config", { rev, by: null });
|
|
9973
|
-
return json(res, 200, state());
|
|
11121
|
+
return json(res, 200, state(req));
|
|
9974
11122
|
}
|
|
9975
11123
|
mm = /^\/api\/plugins\/([^/]+)\/enabled$/.exec(p);
|
|
9976
11124
|
if (mm && m === "POST") {
|
|
@@ -9984,7 +11132,7 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
9984
11132
|
rev++;
|
|
9985
11133
|
runtime.apply(cfg);
|
|
9986
11134
|
send("config", { rev, by: null });
|
|
9987
|
-
return json(res, 200, state());
|
|
11135
|
+
return json(res, 200, state(req));
|
|
9988
11136
|
}
|
|
9989
11137
|
if (p === "/api/screens/export" && m === "GET") {
|
|
9990
11138
|
const id = url2.searchParams.get("id") ?? "";
|
|
@@ -9997,16 +11145,16 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
9997
11145
|
}
|
|
9998
11146
|
function serveStatic(res, pathname) {
|
|
9999
11147
|
const rel = normPath(decodeURIComponent(pathname)).replace(/^([/\\])+/, "");
|
|
10000
|
-
let file =
|
|
11148
|
+
let file = join18(root, rel || "index.html");
|
|
10001
11149
|
if (!file.startsWith(root)) return void json(res, 400, { error: "bad path" });
|
|
10002
|
-
if (!
|
|
10003
|
-
if (!
|
|
11150
|
+
if (!existsSync16(file) || statSync3(file).isDirectory()) file = join18(root, "index.html");
|
|
11151
|
+
if (!existsSync16(file)) {
|
|
10004
11152
|
res.writeHead(500, { "content-type": "text/plain" });
|
|
10005
11153
|
return void res.end("The editor is not built. Run `npm run web:build`.");
|
|
10006
11154
|
}
|
|
10007
11155
|
const ext = extname(file);
|
|
10008
11156
|
res.writeHead(200, { "content-type": MIME[ext] ?? "application/octet-stream", "cache-control": ext === ".html" ? "no-cache" : "max-age=300" });
|
|
10009
|
-
res.end(
|
|
11157
|
+
res.end(readFileSync11(file));
|
|
10010
11158
|
}
|
|
10011
11159
|
const server = createServer((req, res) => {
|
|
10012
11160
|
const host = req.headers.host ?? "";
|
|
@@ -10028,64 +11176,79 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
10028
11176
|
serveStatic(res, url2.pathname);
|
|
10029
11177
|
});
|
|
10030
11178
|
server.listen(o.port, o.host);
|
|
10031
|
-
|
|
10032
|
-
|
|
10033
|
-
|
|
10034
|
-
|
|
10035
|
-
|
|
10036
|
-
|
|
10037
|
-
|
|
10038
|
-
|
|
10039
|
-
|
|
10040
|
-
|
|
10041
|
-
|
|
10042
|
-
|
|
10043
|
-
|
|
10044
|
-
}
|
|
10045
|
-
};
|
|
11179
|
+
function close() {
|
|
11180
|
+
clearInterval(statusTimer);
|
|
11181
|
+
bridge?.stop();
|
|
11182
|
+
for (const t2 of updateTimers) clearTimeout(t2);
|
|
11183
|
+
for (const t2 of storeTimers) clearTimeout(t2);
|
|
11184
|
+
runtime.off("frame", onFrame);
|
|
11185
|
+
runtime.off("alerts", onAlerts);
|
|
11186
|
+
runtime.off("log", onLog);
|
|
11187
|
+
for (const c of clients) c.end();
|
|
11188
|
+
clients.clear();
|
|
11189
|
+
server.close();
|
|
11190
|
+
}
|
|
11191
|
+
return { server, close, updater };
|
|
10046
11192
|
}
|
|
10047
11193
|
|
|
10048
11194
|
// packages/server/src/starter.ts
|
|
11195
|
+
import { existsSync as existsSync17, readdirSync as readdirSync5 } from "node:fs";
|
|
11196
|
+
import { homedir as homedir5 } from "node:os";
|
|
11197
|
+
import { join as join19 } from "node:path";
|
|
11198
|
+
var ROTATIONS = [0, 90, 180, 270];
|
|
11199
|
+
function starterPanels(found, trccUrl = "http://127.0.0.1:8099") {
|
|
11200
|
+
const out = [];
|
|
11201
|
+
const named = (width, height) => {
|
|
11202
|
+
const base3 = PANEL_PRESETS.find((p) => p.width === width && p.height === height || p.width === height && p.height === width)?.name ?? `${width}\xD7${height}`;
|
|
11203
|
+
const same3 = out.filter((p) => p.name === base3 || p.name.startsWith(`${base3} `)).length;
|
|
11204
|
+
if (same3 === 1) out.find((p) => p.name === base3).name = `${base3} 1`;
|
|
11205
|
+
return same3 ? `${base3} ${same3 + 1}` : base3;
|
|
11206
|
+
};
|
|
11207
|
+
for (const u of found.usb) {
|
|
11208
|
+
const width = u.width || 1920;
|
|
11209
|
+
const height = u.height || 462;
|
|
11210
|
+
out.push({ name: named(width, height), width, height, rotate: ROTATIONS.includes(u.rotate ?? 0) ? u.rotate ?? 0 : 0, device: { driver: "usb", ...u.serial ? { serial: u.serial } : {} } });
|
|
11211
|
+
}
|
|
11212
|
+
for (const t2 of found.trcc) out.push({ name: named(t2.width, t2.height), width: t2.width, height: t2.height, rotate: 0, device: { driver: "trcc", url: trccUrl, deviceKey: t2.key } });
|
|
11213
|
+
return out;
|
|
11214
|
+
}
|
|
11215
|
+
function agentTraces(env = process.env, home = homedir5()) {
|
|
11216
|
+
const dirs = [env.AGENT_SESSIONS_DIR ?? join19(env.AIMONITOR_DIR ?? join19(home, ".aimonitor"), "sessions"), join19(home, ".codex", "sessions"), join19(home, ".qwen", "projects"), join19(home, ".kimi", "sessions")];
|
|
11217
|
+
return dirs.some((d) => {
|
|
11218
|
+
try {
|
|
11219
|
+
return existsSync17(d) && readdirSync5(d).length > 0;
|
|
11220
|
+
} catch {
|
|
11221
|
+
return false;
|
|
11222
|
+
}
|
|
11223
|
+
});
|
|
11224
|
+
}
|
|
11225
|
+
var CATS_PAGE = { en: "Cats room", es: "Sala de los gatos", de: "Katzenzimmer", "zh-Hant": "\u8C93\u54AA\u623F\u9593", "zh-Hans": "\u732B\u54AA\u623F\u95F4" };
|
|
10049
11226
|
function starterConfig(registry2, o = {}) {
|
|
10050
|
-
const
|
|
10051
|
-
const height = o.height ?? 462;
|
|
10052
|
-
const L = (t2) => localize(t2, o.locale ?? "en");
|
|
10053
|
-
const screen = newScreen(L({ en: "My panel", es: "Mi panel", de: "Mein Panel", "zh-Hant": "\u6211\u7684\u9762\u677F", "zh-Hans": "\u6211\u7684\u5C4F\u5E55" }), width, height);
|
|
11227
|
+
const locale = o.locale ?? "en";
|
|
10054
11228
|
const has = (t2) => !!registry2.widget(t2);
|
|
10055
|
-
const
|
|
10056
|
-
|
|
10057
|
-
|
|
10058
|
-
|
|
10059
|
-
|
|
10060
|
-
|
|
10061
|
-
|
|
11229
|
+
const one = (name, width, height, device, rotate = 0) => {
|
|
11230
|
+
const screen = newScreen(name, width, height, device);
|
|
11231
|
+
screen.rotate = rotate;
|
|
11232
|
+
screen.pages = [starterPage(has, { width, height, locale, agents: o.agents ?? true, weather: o.weather ?? true })];
|
|
11233
|
+
if ((o.agents ?? true) && has("cats/room")) {
|
|
11234
|
+
const cats = newPage(localize(CATS_PAGE, locale), width, height);
|
|
11235
|
+
cats.tiles = [newTile({ x: 0, y: 0, w: cats.grid.cols, h: cats.grid.rows }, [newWidget("cats/room")])];
|
|
11236
|
+
cats.tiles[0].chrome = "bare";
|
|
11237
|
+
screen.pages.push(cats);
|
|
11238
|
+
}
|
|
11239
|
+
screen.interludes = starterInterludes((t2) => !!registry2.interlude(t2), locale);
|
|
11240
|
+
return screen;
|
|
10062
11241
|
};
|
|
10063
|
-
|
|
10064
|
-
|
|
10065
|
-
add({ x: 11, y: 0, w: 5, h: 4 }, ["core/clock"]);
|
|
10066
|
-
add({ x: 11, y: 4, w: 5, h: 2 }, ["weather/forecast", "mirror/compliments"]);
|
|
10067
|
-
add({ x: 16, y: 0, w: 8, h: 6 }, ["usage/rail", "vitals/vitals", "system/health", "mirror/countdown"].filter(has).slice(0, 3));
|
|
10068
|
-
if (!has("agents/sessions")) {
|
|
10069
|
-
const welcome = tiles[0]?.widgets[0];
|
|
10070
|
-
if (welcome) welcome.options = { text: L({ en: "Hi there.\nDrag widgets from the library to build your panel.", es: "Hola.\nArrastra widgets desde la biblioteca para montar tu panel.", de: "Hallo!\nZieh Widgets aus der Bibliothek, um dein Panel zu gestalten.", "zh-Hant": "\u4F60\u597D\u3002\n\u5F9E\u5C0F\u5DE5\u5177\u5EAB\u62D6\u66F3\u5C0F\u5DE5\u5177\uFF0C\u6253\u9020\u4F60\u7684\u9762\u677F\u3002", "zh-Hans": "\u4F60\u597D\u3002\n\u4ECE\u7EC4\u4EF6\u5E93\u62D6\u52A8\u5C0F\u7EC4\u4EF6\uFF0C\u642D\u5EFA\u4F60\u7684\u5C4F\u5E55\u3002" }), maxSize: 54 };
|
|
10071
|
-
}
|
|
10072
|
-
page.tiles = tiles;
|
|
10073
|
-
if (height > width) transposePage(page, width, height);
|
|
10074
|
-
else {
|
|
10075
|
-
const grid = suggestGrid(width, height);
|
|
10076
|
-
page.tiles = rescale(page.tiles, page.grid, grid);
|
|
10077
|
-
page.grid = grid;
|
|
10078
|
-
}
|
|
10079
|
-
screen.pages = [page];
|
|
10080
|
-
screen.interludes = registry2.interlude("agents/runner") ? [{ id: "interlude-runner", type: "agents/runner", enabled: false, everyMs: 15 * 6e4, maxSeconds: 30, options: {} }] : [];
|
|
10081
|
-
return normalize({ screens: [screen], locale: "auto" });
|
|
11242
|
+
const screens = o.panels?.length ? o.panels.map((p) => one(p.name, p.width, p.height, p.device, p.rotate)) : [one(localize(STARTER_NAMES.screen, locale), o.width ?? 1920, o.height ?? 462)];
|
|
11243
|
+
return normalize({ screens, locale: "auto", setup: "pending" });
|
|
10082
11244
|
}
|
|
10083
11245
|
|
|
10084
11246
|
// packages/server/src/cli.ts
|
|
10085
|
-
var VERSION = "0.2.
|
|
11247
|
+
var VERSION = "0.2.9";
|
|
10086
11248
|
var USAGE2 = `Kiosko ${VERSION}: a widget mosaic for USB LCD panels
|
|
10087
11249
|
|
|
10088
11250
|
kiosko start [--port 7420] [--host 127.0.0.1] [--config file] [--open] [--demo]
|
|
11251
|
+
kiosko editor [--print] open the editor of the Kiosko running here
|
|
10089
11252
|
kiosko render [--screen id|name] [--page id|name] [--out frame.png] [--live]
|
|
10090
11253
|
kiosko import-aimonitor [--from ~/.aimonitor/config.json] [--with-secrets] [--write]
|
|
10091
11254
|
kiosko config schema [--out file] JSON Schema of config.json, with your plugins
|
|
@@ -10098,6 +11261,7 @@ var USAGE2 = `Kiosko ${VERSION}: a widget mosaic for USB LCD panels
|
|
|
10098
11261
|
kiosko gallery [--out gallery] [--locale en | --all-languages] [--theme midnight] [--pages config.json]
|
|
10099
11262
|
kiosko plugins [list|add <id>\u2026|link <folder>\u2026|remove <id>\u2026]
|
|
10100
11263
|
kiosko service install|uninstall|print (start with your session)
|
|
11264
|
+
kiosko self-check [--json] load the plugins as start would and say what loads (the updater's dry run)
|
|
10101
11265
|
kiosko version`;
|
|
10102
11266
|
var argv = process.argv.slice(2);
|
|
10103
11267
|
var FLAG_COMMANDS = /* @__PURE__ */ new Set(["--help", "-h", "--version", "-v"]);
|
|
@@ -10107,7 +11271,7 @@ var opt = (name) => {
|
|
|
10107
11271
|
const i = argv.indexOf(name);
|
|
10108
11272
|
return i >= 0 ? argv[i + 1] : void 0;
|
|
10109
11273
|
};
|
|
10110
|
-
var SCREEN_THREAD = ["./screen-thread.js", "./screen-thread.ts"].map((f) => new URL(f, import.meta.url)).find((u) =>
|
|
11274
|
+
var SCREEN_THREAD = ["./screen-thread.js", "./screen-thread.ts"].map((f) => new URL(f, import.meta.url)).find((u) => existsSync18(u));
|
|
10111
11275
|
var THREADS = SCREEN_THREAD ? { threadEntry: SCREEN_THREAD } : {};
|
|
10112
11276
|
async function registry() {
|
|
10113
11277
|
installSdkResolver();
|
|
@@ -10133,15 +11297,17 @@ async function config(reg, path) {
|
|
|
10133
11297
|
process.exit(1);
|
|
10134
11298
|
}
|
|
10135
11299
|
if (exists) return cfg;
|
|
10136
|
-
const
|
|
11300
|
+
const found = await realDiscover("http://127.0.0.1:8099");
|
|
11301
|
+
const panels = starterPanels(found);
|
|
11302
|
+
const starter = starterConfig(reg, { locale: Intl.DateTimeFormat().resolvedOptions().locale, panels, agents: agentTraces(), weather: false });
|
|
10137
11303
|
saveConfig(starter, path);
|
|
10138
|
-
console.log(`created ${path} with a starter screen`);
|
|
11304
|
+
console.log(`created ${path} with ${panels.length ? `a screen for each panel found: ${panels.map((p) => `${p.name} (${p.width}\xD7${p.height})`).join(", ")}` : "a starter screen (no panel found)"}`);
|
|
10139
11305
|
return starter;
|
|
10140
11306
|
}
|
|
10141
11307
|
function openBrowser(url2) {
|
|
10142
11308
|
const [bin, args] = process.platform === "darwin" ? ["open", [url2]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", url2]] : ["xdg-open", [url2]];
|
|
10143
11309
|
try {
|
|
10144
|
-
|
|
11310
|
+
spawn3(bin, args, { stdio: "ignore", detached: true }).unref();
|
|
10145
11311
|
} catch {
|
|
10146
11312
|
}
|
|
10147
11313
|
}
|
|
@@ -10153,7 +11319,9 @@ async function main() {
|
|
|
10153
11319
|
const cfg = await config(reg, path);
|
|
10154
11320
|
const host = opt("--host") ?? cfg.server.host;
|
|
10155
11321
|
const port = Number(opt("--port") ?? cfg.server.port);
|
|
10156
|
-
const
|
|
11322
|
+
const shown = host === "0.0.0.0" || host === "::" || !host ? "127.0.0.1" : host;
|
|
11323
|
+
const editorAt = `http://${shown.includes(":") ? `[${shown}]` : shown}:${port}`;
|
|
11324
|
+
const rt = new Runtime(reg, cfg, { demo: flag("--demo"), welcome: true, editorUrl: editorAt, ...THREADS });
|
|
10157
11325
|
if (flag("--demo")) console.log("demo mode: every widget shows sample data, nothing is read");
|
|
10158
11326
|
rt.start();
|
|
10159
11327
|
const srv = startServer({ runtime: rt, host, port, configPath: path, version: VERSION });
|
|
@@ -10177,6 +11345,11 @@ async function main() {
|
|
|
10177
11345
|
process.on("SIGTERM", stop);
|
|
10178
11346
|
return;
|
|
10179
11347
|
}
|
|
11348
|
+
case "editor": {
|
|
11349
|
+
const { config: cfg } = loadConfig(path);
|
|
11350
|
+
process.exitCode = await editorCommand({ server: cfg.server, flags: { host: opt("--host"), port: opt("--port"), print: flag("--print") }, open: openBrowser, log: (l) => console.log(l) });
|
|
11351
|
+
return;
|
|
11352
|
+
}
|
|
10180
11353
|
case "render": {
|
|
10181
11354
|
process.env.KIOSKO_QUIET ??= "1";
|
|
10182
11355
|
const reg = await registry();
|
|
@@ -10204,20 +11377,20 @@ async function main() {
|
|
|
10204
11377
|
}
|
|
10205
11378
|
case "import-aimonitor": {
|
|
10206
11379
|
const from = opt("--from") ?? `${process.env.HOME ?? ""}/.aimonitor/config.json`;
|
|
10207
|
-
if (!
|
|
11380
|
+
if (!existsSync18(from)) {
|
|
10208
11381
|
console.error(`not found: ${from}`);
|
|
10209
11382
|
process.exit(1);
|
|
10210
11383
|
}
|
|
10211
11384
|
const reg = await registry();
|
|
10212
|
-
const modePath =
|
|
10213
|
-
const modeOverride =
|
|
10214
|
-
const { config: imported, notes } = importAimonitor(JSON.parse(
|
|
11385
|
+
const modePath = join20(dirname9(from), "modo");
|
|
11386
|
+
const modeOverride = existsSync18(modePath) ? readFileSync12(modePath, "utf8") : null;
|
|
11387
|
+
const { config: imported, notes } = importAimonitor(JSON.parse(readFileSync12(from, "utf8")), reg, modeOverride, { withSecrets: flag("--with-secrets") });
|
|
10215
11388
|
if (modeOverride) notes.push(`mode from ${modePath}: ${modeOverride.trim()}`);
|
|
10216
11389
|
for (const n of notes) console.log(`- ${n}`);
|
|
10217
11390
|
if (flag("--write")) {
|
|
10218
|
-
if (
|
|
11391
|
+
if (existsSync18(path)) writeFileSync13(`${path}.bak`, readFileSync12(path));
|
|
10219
11392
|
saveConfig(imported, path);
|
|
10220
|
-
console.log(`written ${path}${
|
|
11393
|
+
console.log(`written ${path}${existsSync18(`${path}.bak`) ? ` (previous one in ${path}.bak)` : ""}`);
|
|
10221
11394
|
} else {
|
|
10222
11395
|
console.log(JSON.stringify(imported, null, 2));
|
|
10223
11396
|
console.log("\n(dry run: add --write to save it)");
|
|
@@ -10287,7 +11460,7 @@ async function main() {
|
|
|
10287
11460
|
const reg = await registry();
|
|
10288
11461
|
const out = opt("--out") ?? "gallery";
|
|
10289
11462
|
const sample = opt("--pages");
|
|
10290
|
-
const n = buildGallery(reg, { out, locale: opt("--locale") ?? "en", languages: flag("--all-languages"), theme: opt("--theme") ?? "midnight", ...sample ? { pages: JSON.parse(
|
|
11463
|
+
const n = buildGallery(reg, { out, locale: opt("--locale") ?? "en", languages: flag("--all-languages"), theme: opt("--theme") ?? "midnight", ...sample ? { pages: JSON.parse(readFileSync12(sample, "utf8")) } : {} });
|
|
10291
11464
|
console.log(`${n} widgets \u2192 ${out}/index.html`);
|
|
10292
11465
|
return;
|
|
10293
11466
|
}
|
|
@@ -10301,6 +11474,17 @@ async function main() {
|
|
|
10301
11474
|
process.exitCode = await configCommand(argv.slice(1), { registry, configPath: path });
|
|
10302
11475
|
return;
|
|
10303
11476
|
}
|
|
11477
|
+
case "self-check": {
|
|
11478
|
+
process.env.KIOSKO_QUIET ??= "1";
|
|
11479
|
+
const reg = await registry();
|
|
11480
|
+
const report = { kiosko: "self-check", version: VERSION, node: process.version, plugins: reg.list().map((p) => ({ id: p.def.id, version: p.def.version })), problems: reg.problems, refused: reg.refused };
|
|
11481
|
+
if (flag("--json")) console.log(JSON.stringify(report));
|
|
11482
|
+
else {
|
|
11483
|
+
console.log(`Kiosko ${VERSION}, Node ${process.version}: ${report.plugins.length} plugins load (${report.plugins.map((p) => p.id).join(", ")})`);
|
|
11484
|
+
for (const pr of report.problems) console.log(` \u2717 ${pr.origin}: ${pr.message}`);
|
|
11485
|
+
}
|
|
11486
|
+
process.exit(0);
|
|
11487
|
+
}
|
|
10304
11488
|
case "help":
|
|
10305
11489
|
case "--help":
|
|
10306
11490
|
case "-h":
|