kiosko 0.2.8 → 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 +44 -3
- package/cli.js +1241 -130
- package/package.json +1 -1
- package/screen-thread.js +363 -4
- package/sdk.js +1 -1
- 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;
|
|
@@ -1374,7 +1379,7 @@ var CATEGORIES = [
|
|
|
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
|
}
|
|
@@ -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
|
}
|
|
@@ -7306,6 +7730,65 @@ function lintPlugin(def) {
|
|
|
7306
7730
|
import { readFileSync as readFileSync4 } from "node:fs";
|
|
7307
7731
|
import { homedir as homedir3 } from "node:os";
|
|
7308
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
|
+
|
|
7791
|
+
// packages/core/src/plugin-updates.ts
|
|
7309
7792
|
var REGISTRY = "https://registry.npmjs.org";
|
|
7310
7793
|
function npmRegistry(env = process.env, home = homedir3()) {
|
|
7311
7794
|
const fromEnv = env.npm_config_registry ?? env.NPM_CONFIG_REGISTRY;
|
|
@@ -7326,10 +7809,12 @@ var releases = (p) => Object.keys(p.versions ?? {}).filter((v) => {
|
|
|
7326
7809
|
function pickUpdate(installed2, p, env) {
|
|
7327
7810
|
const latest = p["dist-tags"]?.latest;
|
|
7328
7811
|
if (!latest || compareVersions(latest, installed2.version) <= 0) return null;
|
|
7329
|
-
const
|
|
7330
|
-
const
|
|
7331
|
-
const
|
|
7332
|
-
|
|
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 } : {} };
|
|
7333
7818
|
}
|
|
7334
7819
|
async function checkUpdates(plugins, o = {}) {
|
|
7335
7820
|
const http = o.http ?? createHttp({ agent: "kiosko-updates" });
|
|
@@ -7345,17 +7830,17 @@ async function checkUpdates(plugins, o = {}) {
|
|
|
7345
7830
|
return null;
|
|
7346
7831
|
}
|
|
7347
7832
|
};
|
|
7348
|
-
const found = await Promise.all(plugins.map(
|
|
7349
|
-
const p = await read(pl.package);
|
|
7350
|
-
return p ? pickUpdate(pl, p, env) : null;
|
|
7351
|
-
}));
|
|
7833
|
+
const [k, ...found] = await Promise.all([o.kioskoVersion ? read("kiosko") : Promise.resolve(null), ...plugins.map((pl) => read(pl.package))]);
|
|
7352
7834
|
let kiosko;
|
|
7353
|
-
|
|
7354
|
-
|
|
7355
|
-
const
|
|
7356
|
-
|
|
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 } : {} };
|
|
7357
7841
|
}
|
|
7358
|
-
|
|
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 };
|
|
7359
7844
|
}
|
|
7360
7845
|
|
|
7361
7846
|
// packages/core/src/store/client.ts
|
|
@@ -7746,7 +8231,7 @@ var image = defineWidget({
|
|
|
7746
8231
|
var src_default = definePlugin({
|
|
7747
8232
|
id: "core",
|
|
7748
8233
|
name: { en: "Essentials", es: "B\xE1sicos", de: "Grundlagen", "zh-Hant": "\u57FA\u672C\u5DE5\u5177", "zh-Hans": "\u57FA\u7840\u7EC4\u4EF6" },
|
|
7749
|
-
version: "0.2.
|
|
8234
|
+
version: "0.2.9",
|
|
7750
8235
|
languages: ["en", "es", "de", "zh-Hant", "zh-Hans"],
|
|
7751
8236
|
sdk: "^0.2.0",
|
|
7752
8237
|
// The picture widget reads the image (or folder, or URL) you give it.
|
|
@@ -7842,7 +8327,7 @@ var module2 = defineWidget({
|
|
|
7842
8327
|
var src_default2 = definePlugin({
|
|
7843
8328
|
id: "legacy",
|
|
7844
8329
|
name: { en: "aimonitor compatibility", es: "Compatibilidad aimonitor", de: "aimonitor-Kompatibilit\xE4t", "zh-Hant": "aimonitor \u76F8\u5BB9\u6027", "zh-Hans": "aimonitor \u517C\u5BB9" },
|
|
7845
|
-
version: "0.2.
|
|
8330
|
+
version: "0.2.9",
|
|
7846
8331
|
languages: ["en", "es", "de", "zh-Hant", "zh-Hans"],
|
|
7847
8332
|
sdk: "^0.2.0",
|
|
7848
8333
|
// Runs the aimonitor modules you point it at, and reads their folder.
|
|
@@ -7856,7 +8341,7 @@ var src_default2 = definePlugin({
|
|
|
7856
8341
|
|
|
7857
8342
|
// packages/server/src/official.ts
|
|
7858
8343
|
var BUNDLED_PLUGIN_IDS = ["agents", "cats", "system", "vitals", "usage", "weather", "calendar", "news", "mirror", "gitlab", "github", "calls", "timesheet", "llm", "gpu", "homeassistant"];
|
|
7859
|
-
var OPTIONAL_PLUGIN_IDS = ["doom", "video", "fractals", "gaming", "logs", "hazards"];
|
|
8344
|
+
var OPTIONAL_PLUGIN_IDS = ["doom", "video", "fractals", "gaming", "logs", "hazards", "batteries"];
|
|
7860
8345
|
var OFFICIAL_PLUGINS = [
|
|
7861
8346
|
...BUNDLED_PLUGIN_IDS.map((id) => ({ id, npm: `kiosko-plugin-${id}`, bundled: true })),
|
|
7862
8347
|
...OPTIONAL_PLUGIN_IDS.map((id) => ({ id, npm: `kiosko-plugin-${id}`, bundled: false }))
|
|
@@ -8139,9 +8624,9 @@ ${dim("Dry run: nothing was written.")} Run again with --apply to back up the cu
|
|
|
8139
8624
|
signal: AbortSignal.timeout(15e3)
|
|
8140
8625
|
}).catch((err) => err);
|
|
8141
8626
|
if (r instanceof Error || !r.ok) {
|
|
8142
|
-
const
|
|
8627
|
+
const why2 = r instanceof Error ? r.message : r.status === 409 ? "the configuration changed in the editor meanwhile" : `HTTP ${r.status}`;
|
|
8143
8628
|
console.log(red(`
|
|
8144
|
-
Not applied: ${
|
|
8629
|
+
Not applied: ${why2}. Run the import again${saved}.`));
|
|
8145
8630
|
return 1;
|
|
8146
8631
|
}
|
|
8147
8632
|
console.log(`
|
|
@@ -8175,7 +8660,7 @@ async function configCommand(argv2, ctx) {
|
|
|
8175
8660
|
}
|
|
8176
8661
|
|
|
8177
8662
|
// packages/server/src/editor-cli.ts
|
|
8178
|
-
function
|
|
8663
|
+
function editorUrl2(server, over = {}) {
|
|
8179
8664
|
let host = over.host ?? server.host;
|
|
8180
8665
|
if (host === "0.0.0.0" || host === "") host = "127.0.0.1";
|
|
8181
8666
|
if (host === "::") host = "::1";
|
|
@@ -8193,7 +8678,7 @@ async function runningAt(url2, timeoutMs = 1500) {
|
|
|
8193
8678
|
}
|
|
8194
8679
|
}
|
|
8195
8680
|
async function editorCommand({ server, flags, open, log }) {
|
|
8196
|
-
const url2 =
|
|
8681
|
+
const url2 = editorUrl2(server, flags);
|
|
8197
8682
|
const version = await runningAt(url2);
|
|
8198
8683
|
if (!version) {
|
|
8199
8684
|
log(`Kiosko isn't running at ${url2}`);
|
|
@@ -8254,8 +8739,8 @@ async function check2(dir, argv2) {
|
|
|
8254
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}` });
|
|
8255
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` });
|
|
8256
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)}` });
|
|
8257
|
-
const
|
|
8258
|
-
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}` });
|
|
8259
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}` });
|
|
8260
8745
|
const { checkPlugin: checkPlugin2 } = await Promise.resolve().then(() => (init_testing(), testing_exports));
|
|
8261
8746
|
const painted = /* @__PURE__ */ new Map();
|
|
@@ -8992,10 +9477,13 @@ function runService(action, plan) {
|
|
|
8992
9477
|
}
|
|
8993
9478
|
|
|
8994
9479
|
// packages/server/src/server.ts
|
|
8995
|
-
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";
|
|
8996
9483
|
import { createServer } from "node:http";
|
|
9484
|
+
import { tmpdir as tmpdir2 } from "node:os";
|
|
8997
9485
|
import { createRequire as createRequire3 } from "node:module";
|
|
8998
|
-
import { dirname as
|
|
9486
|
+
import { dirname as dirname8, extname, join as join18, normalize as normPath, resolve as resolve7 } from "node:path";
|
|
8999
9487
|
|
|
9000
9488
|
// packages/server/src/plugins-manage.ts
|
|
9001
9489
|
import { execFile } from "node:child_process";
|
|
@@ -9407,14 +9895,14 @@ var MqttClient = class extends EventEmitter2 {
|
|
|
9407
9895
|
this.ping();
|
|
9408
9896
|
}, every);
|
|
9409
9897
|
}
|
|
9410
|
-
drop(
|
|
9898
|
+
drop(why2, refused = false) {
|
|
9411
9899
|
if (this.closed) return;
|
|
9412
9900
|
this.clear();
|
|
9413
9901
|
const s = this.sock;
|
|
9414
9902
|
this.sock = null;
|
|
9415
9903
|
s?.destroy();
|
|
9416
9904
|
this.awaitingPong = false;
|
|
9417
|
-
this.set("error",
|
|
9905
|
+
this.set("error", why2);
|
|
9418
9906
|
const ms = refused ? 5 * 6e4 : RETRY_MS2[Math.min(this.attempt++, RETRY_MS2.length - 1)];
|
|
9419
9907
|
this.later(() => this.open(), ms);
|
|
9420
9908
|
}
|
|
@@ -9678,6 +10166,483 @@ var HomeAssistantBridge = class {
|
|
|
9678
10166
|
}
|
|
9679
10167
|
};
|
|
9680
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
|
+
|
|
9681
10646
|
// packages/server/src/server.ts
|
|
9682
10647
|
var require3 = createRequire3(import.meta.url);
|
|
9683
10648
|
var MIME = {
|
|
@@ -9691,11 +10656,12 @@ var MIME = {
|
|
|
9691
10656
|
".woff2": "font/woff2",
|
|
9692
10657
|
".ico": "image/x-icon"
|
|
9693
10658
|
};
|
|
10659
|
+
var realDiscover = async (url2, tokenFile) => ({ trcc: await discoverTrcc(url2, tokenFile), usb: await discoverUsb() });
|
|
9694
10660
|
function webRoot() {
|
|
9695
|
-
const bundled =
|
|
9696
|
-
if (
|
|
10661
|
+
const bundled = join18(import.meta.dirname, "web");
|
|
10662
|
+
if (existsSync16(join18(bundled, "index.html"))) return bundled;
|
|
9697
10663
|
try {
|
|
9698
|
-
return
|
|
10664
|
+
return join18(dirname8(require3.resolve("@kiosko/web/package.json")), "dist");
|
|
9699
10665
|
} catch {
|
|
9700
10666
|
return resolve7(import.meta.dirname, "../../web/dist");
|
|
9701
10667
|
}
|
|
@@ -9737,9 +10703,95 @@ function startServer(o) {
|
|
|
9737
10703
|
const checking = o.checkUpdates ?? (!runtime.demoMode && process.env.KIOSKO_NO_UPDATE_CHECK !== "1");
|
|
9738
10704
|
const updateTimers = checking ? [setTimeout(() => void refreshUpdates().catch(() => void 0), 2e4), setInterval(() => void refreshUpdates().catch(() => void 0), 24 * 36e5)] : [];
|
|
9739
10705
|
for (const t2 of updateTimers) t2.unref?.();
|
|
9740
|
-
const store = o.store ?? new StoreCatalog({ cacheDir:
|
|
10706
|
+
const store = o.store ?? new StoreCatalog({ cacheDir: join18(paths.home, "store") });
|
|
9741
10707
|
const storeTimers = checking ? [setTimeout(() => void store.refresh(), 15e3), setInterval(() => void store.refresh(), 24 * 36e5)] : [];
|
|
9742
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
|
+
});
|
|
9743
10795
|
const installFromStore = async (p, version) => {
|
|
9744
10796
|
const index = store.current().index;
|
|
9745
10797
|
const release = p.releases.find((r) => r.version === version);
|
|
@@ -9772,16 +10824,23 @@ data: ${JSON.stringify(data)}
|
|
|
9772
10824
|
const fullStatus = () => ({ ...runtime.status(), homeassistant: bridge?.status() ?? { enabled: false, state: "off", error: null } });
|
|
9773
10825
|
const statusTimer = setInterval(() => send("status", fullStatus()), 3e3);
|
|
9774
10826
|
const allowedHosts = /* @__PURE__ */ new Set([`127.0.0.1:${o.port}`, `localhost:${o.port}`, `[::1]:${o.port}`, `${o.host}:${o.port}`]);
|
|
9775
|
-
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) {
|
|
9776
10834
|
const locale = resolveLocale(runtime.config);
|
|
9777
10835
|
return {
|
|
9778
10836
|
version: o.version,
|
|
9779
10837
|
rev,
|
|
9780
10838
|
locale,
|
|
9781
10839
|
config: runtime.config,
|
|
9782
|
-
catalog: runtime.registry.catalog(
|
|
10840
|
+
catalog: runtime.registry.catalog(uiLocale(req)),
|
|
9783
10841
|
refused: runtime.registry.refused,
|
|
9784
10842
|
updates: updates && { checkedAt: updates.checkedAt, plugins: updates.plugins, kiosko: updates.kiosko ?? null },
|
|
10843
|
+
kioskoUpdate: kioskoUpdateState(),
|
|
9785
10844
|
categories: CATEGORIES,
|
|
9786
10845
|
themes: THEMES,
|
|
9787
10846
|
presets: PANEL_PRESETS,
|
|
@@ -9801,7 +10860,7 @@ data: ${JSON.stringify(data)}
|
|
|
9801
10860
|
const p = url2.pathname;
|
|
9802
10861
|
const m = req.method ?? "GET";
|
|
9803
10862
|
if (m !== "GET" && req.headers["x-kiosko"] !== "1") return json(res, 403, { error: "missing X-Kiosko header" });
|
|
9804
|
-
if (p === "/api/state" && m === "GET") return json(res, 200, state());
|
|
10863
|
+
if (p === "/api/state" && m === "GET") return json(res, 200, state(req));
|
|
9805
10864
|
if (p === "/api/config" && m === "PUT") {
|
|
9806
10865
|
const b = await body(req);
|
|
9807
10866
|
const raw = b && typeof b === "object" && "config" in b ? b.config : b;
|
|
@@ -9922,13 +10981,38 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
9922
10981
|
}
|
|
9923
10982
|
if (p === "/api/devices/discover" && m === "GET") {
|
|
9924
10983
|
const url0 = url2.searchParams.get("url") ?? "http://127.0.0.1:8099";
|
|
9925
|
-
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());
|
|
9926
11010
|
}
|
|
9927
11011
|
if (p === "/api/logs" && m === "GET") return json(res, 200, runtime.logs.slice(-200));
|
|
9928
11012
|
if (p === "/api/choices" && m === "GET") {
|
|
9929
11013
|
const source = url2.searchParams.get("source") ?? "";
|
|
9930
11014
|
const list2 = url2.searchParams.get("list") ?? "";
|
|
9931
|
-
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)));
|
|
9932
11016
|
}
|
|
9933
11017
|
if (p === "/api/plugins/install" && m === "POST") {
|
|
9934
11018
|
const b = await body(req);
|
|
@@ -9938,7 +11022,7 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
9938
11022
|
if (r.restart) restartNeeded = true;
|
|
9939
11023
|
rev++;
|
|
9940
11024
|
send("config", { rev, by: null });
|
|
9941
|
-
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) });
|
|
9942
11026
|
} catch (err) {
|
|
9943
11027
|
return json(res, /valid npm/.test(String(err)) ? 400 : 500, { error: err instanceof Error ? err.message : String(err) });
|
|
9944
11028
|
}
|
|
@@ -9974,8 +11058,8 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
9974
11058
|
const release = sp.releases.find((r) => r.version === b.version);
|
|
9975
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) } });
|
|
9976
11060
|
if (release.withdrawn) return json(res, 409, { error: `${sp.package}@${release.version} was withdrawn`, code: "withdrawn", params: { id, version: release.version } });
|
|
9977
|
-
const
|
|
9978
|
-
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 } });
|
|
9979
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 } });
|
|
9980
11064
|
try {
|
|
9981
11065
|
const results = await installFromStore(sp, release.version);
|
|
@@ -9983,7 +11067,7 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
9983
11067
|
rev++;
|
|
9984
11068
|
send("config", { rev, by: null });
|
|
9985
11069
|
const problem = results.map((r) => r.problem).filter(Boolean).join("; ") || null;
|
|
9986
|
-
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) });
|
|
9987
11071
|
} catch (err) {
|
|
9988
11072
|
return json(res, err instanceof IntegrityError ? 409 : 500, { error: err instanceof Error ? err.message : String(err), ...err instanceof IntegrityError ? { code: "integrity", params: { id } } : {} });
|
|
9989
11073
|
}
|
|
@@ -9996,7 +11080,7 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
9996
11080
|
if (!r.removed) return json(res, 409, { error: `can't remove "${id}": ${r.reason}`, code: "cantRemove", params: { id, why: r.reason } });
|
|
9997
11081
|
rev++;
|
|
9998
11082
|
send("config", { rev, by: null });
|
|
9999
|
-
return json(res, 200, state());
|
|
11083
|
+
return json(res, 200, state(req));
|
|
10000
11084
|
} catch (err) {
|
|
10001
11085
|
return json(res, 500, { error: err instanceof Error ? err.message : String(err) });
|
|
10002
11086
|
}
|
|
@@ -10022,7 +11106,7 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
10022
11106
|
if (r.restart) restartNeeded = true;
|
|
10023
11107
|
rev++;
|
|
10024
11108
|
send("config", { rev, by: null });
|
|
10025
|
-
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) });
|
|
10026
11110
|
} catch (err) {
|
|
10027
11111
|
return json(res, 500, { error: err instanceof Error ? err.message : String(err) });
|
|
10028
11112
|
}
|
|
@@ -10034,7 +11118,7 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
10034
11118
|
if (problem) return json(res, 409, { error: problem, code: "reloadFailed", params: { id, why: problem } });
|
|
10035
11119
|
rev++;
|
|
10036
11120
|
send("config", { rev, by: null });
|
|
10037
|
-
return json(res, 200, state());
|
|
11121
|
+
return json(res, 200, state(req));
|
|
10038
11122
|
}
|
|
10039
11123
|
mm = /^\/api\/plugins\/([^/]+)\/enabled$/.exec(p);
|
|
10040
11124
|
if (mm && m === "POST") {
|
|
@@ -10048,7 +11132,7 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
10048
11132
|
rev++;
|
|
10049
11133
|
runtime.apply(cfg);
|
|
10050
11134
|
send("config", { rev, by: null });
|
|
10051
|
-
return json(res, 200, state());
|
|
11135
|
+
return json(res, 200, state(req));
|
|
10052
11136
|
}
|
|
10053
11137
|
if (p === "/api/screens/export" && m === "GET") {
|
|
10054
11138
|
const id = url2.searchParams.get("id") ?? "";
|
|
@@ -10061,16 +11145,16 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
10061
11145
|
}
|
|
10062
11146
|
function serveStatic(res, pathname) {
|
|
10063
11147
|
const rel = normPath(decodeURIComponent(pathname)).replace(/^([/\\])+/, "");
|
|
10064
|
-
let file =
|
|
11148
|
+
let file = join18(root, rel || "index.html");
|
|
10065
11149
|
if (!file.startsWith(root)) return void json(res, 400, { error: "bad path" });
|
|
10066
|
-
if (!
|
|
10067
|
-
if (!
|
|
11150
|
+
if (!existsSync16(file) || statSync3(file).isDirectory()) file = join18(root, "index.html");
|
|
11151
|
+
if (!existsSync16(file)) {
|
|
10068
11152
|
res.writeHead(500, { "content-type": "text/plain" });
|
|
10069
11153
|
return void res.end("The editor is not built. Run `npm run web:build`.");
|
|
10070
11154
|
}
|
|
10071
11155
|
const ext = extname(file);
|
|
10072
11156
|
res.writeHead(200, { "content-type": MIME[ext] ?? "application/octet-stream", "cache-control": ext === ".html" ? "no-cache" : "max-age=300" });
|
|
10073
|
-
res.end(
|
|
11157
|
+
res.end(readFileSync11(file));
|
|
10074
11158
|
}
|
|
10075
11159
|
const server = createServer((req, res) => {
|
|
10076
11160
|
const host = req.headers.host ?? "";
|
|
@@ -10092,64 +11176,75 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
10092
11176
|
serveStatic(res, url2.pathname);
|
|
10093
11177
|
});
|
|
10094
11178
|
server.listen(o.port, o.host);
|
|
10095
|
-
|
|
10096
|
-
|
|
10097
|
-
|
|
10098
|
-
|
|
10099
|
-
|
|
10100
|
-
|
|
10101
|
-
|
|
10102
|
-
|
|
10103
|
-
|
|
10104
|
-
|
|
10105
|
-
|
|
10106
|
-
|
|
10107
|
-
|
|
10108
|
-
}
|
|
10109
|
-
};
|
|
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 };
|
|
10110
11192
|
}
|
|
10111
11193
|
|
|
10112
11194
|
// packages/server/src/starter.ts
|
|
10113
|
-
|
|
10114
|
-
|
|
10115
|
-
|
|
10116
|
-
|
|
10117
|
-
|
|
10118
|
-
const
|
|
10119
|
-
const
|
|
10120
|
-
|
|
10121
|
-
|
|
10122
|
-
|
|
10123
|
-
|
|
10124
|
-
const tiles = [];
|
|
10125
|
-
const add = (r, types2, title) => {
|
|
10126
|
-
const ws = types2.filter(has).map((t2) => newWidget(t2, {}, title));
|
|
10127
|
-
if (ws.length) tiles.push(newTile(r, ws));
|
|
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;
|
|
10128
11206
|
};
|
|
10129
|
-
const
|
|
10130
|
-
|
|
10131
|
-
|
|
10132
|
-
|
|
10133
|
-
add({ x: 11, y: 4, w: 5, h: 2 }, ["weather/forecast", "mirror/compliments"]);
|
|
10134
|
-
add({ x: 16, y: 0, w: 8, h: 6 }, ["usage/rail", "vitals/vitals", "system/health", "mirror/countdown"].filter(has).slice(0, 3));
|
|
10135
|
-
if (!has(lead)) {
|
|
10136
|
-
const welcome = tiles[0]?.widgets[0];
|
|
10137
|
-
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 };
|
|
10138
|
-
}
|
|
10139
|
-
page.tiles = tiles;
|
|
10140
|
-
if (height > width) transposePage(page, width, height);
|
|
10141
|
-
else {
|
|
10142
|
-
const grid = suggestGrid(width, height);
|
|
10143
|
-
page.tiles = rescale(page.tiles, page.grid, grid);
|
|
10144
|
-
page.grid = grid;
|
|
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 } : {} } });
|
|
10145
11211
|
}
|
|
10146
|
-
|
|
10147
|
-
|
|
10148
|
-
|
|
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" };
|
|
11226
|
+
function starterConfig(registry2, o = {}) {
|
|
11227
|
+
const locale = o.locale ?? "en";
|
|
11228
|
+
const has = (t2) => !!registry2.widget(t2);
|
|
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;
|
|
11241
|
+
};
|
|
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" });
|
|
10149
11244
|
}
|
|
10150
11245
|
|
|
10151
11246
|
// packages/server/src/cli.ts
|
|
10152
|
-
var VERSION = "0.2.
|
|
11247
|
+
var VERSION = "0.2.9";
|
|
10153
11248
|
var USAGE2 = `Kiosko ${VERSION}: a widget mosaic for USB LCD panels
|
|
10154
11249
|
|
|
10155
11250
|
kiosko start [--port 7420] [--host 127.0.0.1] [--config file] [--open] [--demo]
|
|
@@ -10166,6 +11261,7 @@ var USAGE2 = `Kiosko ${VERSION}: a widget mosaic for USB LCD panels
|
|
|
10166
11261
|
kiosko gallery [--out gallery] [--locale en | --all-languages] [--theme midnight] [--pages config.json]
|
|
10167
11262
|
kiosko plugins [list|add <id>\u2026|link <folder>\u2026|remove <id>\u2026]
|
|
10168
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)
|
|
10169
11265
|
kiosko version`;
|
|
10170
11266
|
var argv = process.argv.slice(2);
|
|
10171
11267
|
var FLAG_COMMANDS = /* @__PURE__ */ new Set(["--help", "-h", "--version", "-v"]);
|
|
@@ -10175,7 +11271,7 @@ var opt = (name) => {
|
|
|
10175
11271
|
const i = argv.indexOf(name);
|
|
10176
11272
|
return i >= 0 ? argv[i + 1] : void 0;
|
|
10177
11273
|
};
|
|
10178
|
-
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));
|
|
10179
11275
|
var THREADS = SCREEN_THREAD ? { threadEntry: SCREEN_THREAD } : {};
|
|
10180
11276
|
async function registry() {
|
|
10181
11277
|
installSdkResolver();
|
|
@@ -10201,15 +11297,17 @@ async function config(reg, path) {
|
|
|
10201
11297
|
process.exit(1);
|
|
10202
11298
|
}
|
|
10203
11299
|
if (exists) return cfg;
|
|
10204
|
-
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 });
|
|
10205
11303
|
saveConfig(starter, path);
|
|
10206
|
-
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)"}`);
|
|
10207
11305
|
return starter;
|
|
10208
11306
|
}
|
|
10209
11307
|
function openBrowser(url2) {
|
|
10210
11308
|
const [bin, args] = process.platform === "darwin" ? ["open", [url2]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", url2]] : ["xdg-open", [url2]];
|
|
10211
11309
|
try {
|
|
10212
|
-
|
|
11310
|
+
spawn3(bin, args, { stdio: "ignore", detached: true }).unref();
|
|
10213
11311
|
} catch {
|
|
10214
11312
|
}
|
|
10215
11313
|
}
|
|
@@ -10221,7 +11319,9 @@ async function main() {
|
|
|
10221
11319
|
const cfg = await config(reg, path);
|
|
10222
11320
|
const host = opt("--host") ?? cfg.server.host;
|
|
10223
11321
|
const port = Number(opt("--port") ?? cfg.server.port);
|
|
10224
|
-
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 });
|
|
10225
11325
|
if (flag("--demo")) console.log("demo mode: every widget shows sample data, nothing is read");
|
|
10226
11326
|
rt.start();
|
|
10227
11327
|
const srv = startServer({ runtime: rt, host, port, configPath: path, version: VERSION });
|
|
@@ -10277,20 +11377,20 @@ async function main() {
|
|
|
10277
11377
|
}
|
|
10278
11378
|
case "import-aimonitor": {
|
|
10279
11379
|
const from = opt("--from") ?? `${process.env.HOME ?? ""}/.aimonitor/config.json`;
|
|
10280
|
-
if (!
|
|
11380
|
+
if (!existsSync18(from)) {
|
|
10281
11381
|
console.error(`not found: ${from}`);
|
|
10282
11382
|
process.exit(1);
|
|
10283
11383
|
}
|
|
10284
11384
|
const reg = await registry();
|
|
10285
|
-
const modePath =
|
|
10286
|
-
const modeOverride =
|
|
10287
|
-
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") });
|
|
10288
11388
|
if (modeOverride) notes.push(`mode from ${modePath}: ${modeOverride.trim()}`);
|
|
10289
11389
|
for (const n of notes) console.log(`- ${n}`);
|
|
10290
11390
|
if (flag("--write")) {
|
|
10291
|
-
if (
|
|
11391
|
+
if (existsSync18(path)) writeFileSync13(`${path}.bak`, readFileSync12(path));
|
|
10292
11392
|
saveConfig(imported, path);
|
|
10293
|
-
console.log(`written ${path}${
|
|
11393
|
+
console.log(`written ${path}${existsSync18(`${path}.bak`) ? ` (previous one in ${path}.bak)` : ""}`);
|
|
10294
11394
|
} else {
|
|
10295
11395
|
console.log(JSON.stringify(imported, null, 2));
|
|
10296
11396
|
console.log("\n(dry run: add --write to save it)");
|
|
@@ -10360,7 +11460,7 @@ async function main() {
|
|
|
10360
11460
|
const reg = await registry();
|
|
10361
11461
|
const out = opt("--out") ?? "gallery";
|
|
10362
11462
|
const sample = opt("--pages");
|
|
10363
|
-
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")) } : {} });
|
|
10364
11464
|
console.log(`${n} widgets \u2192 ${out}/index.html`);
|
|
10365
11465
|
return;
|
|
10366
11466
|
}
|
|
@@ -10374,6 +11474,17 @@ async function main() {
|
|
|
10374
11474
|
process.exitCode = await configCommand(argv.slice(1), { registry, configPath: path });
|
|
10375
11475
|
return;
|
|
10376
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
|
+
}
|
|
10377
11488
|
case "help":
|
|
10378
11489
|
case "--help":
|
|
10379
11490
|
case "-h":
|