kiosko 0.2.9 → 0.2.10
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 +2 -1
- package/cli.js +1786 -347
- package/package.json +1 -1
- package/screen-thread.js +36 -23
- package/sdk.js +1 -1
- package/web/assets/app.js +41 -41
- package/web/assets/styles.css +1 -1
package/cli.js
CHANGED
|
@@ -6,8 +6,8 @@ var __esm = (fn, res) => function __init() {
|
|
|
6
6
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
7
7
|
};
|
|
8
8
|
var __export = (target, all) => {
|
|
9
|
-
for (var
|
|
10
|
-
__defProp(target,
|
|
9
|
+
for (var name2 in all)
|
|
10
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
// packages/sdk/src/workday.ts
|
|
@@ -86,12 +86,12 @@ function pickLocale(available2, locale) {
|
|
|
86
86
|
function plural(n, forms, locale = "en") {
|
|
87
87
|
const key = pickLocale(Object.keys(forms), locale) ?? (forms.en ? "en" : Object.keys(forms)[0]);
|
|
88
88
|
const f = forms[key];
|
|
89
|
-
let
|
|
89
|
+
let rule2 = "other";
|
|
90
90
|
try {
|
|
91
|
-
|
|
91
|
+
rule2 = new Intl.PluralRules(key).select(n);
|
|
92
92
|
} catch {
|
|
93
93
|
}
|
|
94
|
-
const text3 = f[
|
|
94
|
+
const text3 = f[rule2] ?? f.other;
|
|
95
95
|
let num = String(n);
|
|
96
96
|
try {
|
|
97
97
|
num = new Intl.NumberFormat(key).format(n);
|
|
@@ -787,8 +787,8 @@ function moon(ctx, cx, cy, s) {
|
|
|
787
787
|
const r = s * 0.24;
|
|
788
788
|
const pad = 2;
|
|
789
789
|
const side = Math.ceil(r * 2 + pad * 2);
|
|
790
|
-
const
|
|
791
|
-
const o =
|
|
790
|
+
const off2 = createCanvas(side, side);
|
|
791
|
+
const o = off2.getContext("2d");
|
|
792
792
|
const c = side / 2;
|
|
793
793
|
o.fillStyle = ctx.fillStyle;
|
|
794
794
|
o.beginPath();
|
|
@@ -798,7 +798,7 @@ function moon(ctx, cx, cy, s) {
|
|
|
798
798
|
o.beginPath();
|
|
799
799
|
o.arc(c + r * 0.55, c - r * 0.42, r * 0.92, 0, Math.PI * 2);
|
|
800
800
|
o.fill();
|
|
801
|
-
ctx.drawImage(
|
|
801
|
+
ctx.drawImage(off2, cx - c, cy - c);
|
|
802
802
|
}
|
|
803
803
|
function drops(ctx, cx, cy, s, len) {
|
|
804
804
|
ctx.lineWidth = Math.max(1.5, s * 0.05);
|
|
@@ -896,8 +896,8 @@ function drawMoonPhase(ctx, moon2, cx, cy, size, color2) {
|
|
|
896
896
|
const r = size / 2;
|
|
897
897
|
const pad = 2;
|
|
898
898
|
const side = Math.ceil(size + pad * 2);
|
|
899
|
-
const
|
|
900
|
-
const o =
|
|
899
|
+
const off2 = createCanvas(side, side);
|
|
900
|
+
const o = off2.getContext("2d");
|
|
901
901
|
const c = side / 2;
|
|
902
902
|
o.fillStyle = color2;
|
|
903
903
|
o.beginPath();
|
|
@@ -919,7 +919,7 @@ function drawMoonPhase(ctx, moon2, cx, cy, size, color2) {
|
|
|
919
919
|
o.closePath();
|
|
920
920
|
o.fill();
|
|
921
921
|
ctx.save();
|
|
922
|
-
ctx.drawImage(
|
|
922
|
+
ctx.drawImage(off2, cx - c, cy - c);
|
|
923
923
|
ctx.strokeStyle = "rgba(255,255,255,0.22)";
|
|
924
924
|
ctx.lineWidth = Math.max(1, size * 0.02);
|
|
925
925
|
ctx.beginPath();
|
|
@@ -1103,13 +1103,13 @@ function checkPlugin(p, o = {}) {
|
|
|
1103
1103
|
for (const size of sizes) {
|
|
1104
1104
|
for (const theme of themes) {
|
|
1105
1105
|
for (const locale of locales) {
|
|
1106
|
-
const
|
|
1106
|
+
const where2 = `${size.w}x${size.h} ${theme} ${locale}`;
|
|
1107
1107
|
const r2 = renderWidget(w, { size, theme, locale });
|
|
1108
|
-
if (r2.error) issues.push({ type, where, problem: `render threw: ${r2.error}` });
|
|
1109
|
-
else if (r2.outside > 0) issues.push({ type, where, problem: `painted ${r2.outside} px outside its box` });
|
|
1108
|
+
if (r2.error) issues.push({ type, where: where2, problem: `render threw: ${r2.error}` });
|
|
1109
|
+
else if (r2.outside > 0) issues.push({ type, where: where2, problem: `painted ${r2.outside} px outside its box` });
|
|
1110
1110
|
if (r2.ms > slow && !r2.error) {
|
|
1111
1111
|
const ms = Math.min(r2.ms, renderWidget(w, { size, theme, locale }).ms, renderWidget(w, { size, theme, locale }).ms);
|
|
1112
|
-
if (ms > slow) issues.push({ type, where, problem: `render took ${Math.round(ms)} ms` });
|
|
1112
|
+
if (ms > slow) issues.push({ type, where: where2, problem: `render took ${Math.round(ms)} ms` });
|
|
1113
1113
|
}
|
|
1114
1114
|
}
|
|
1115
1115
|
}
|
|
@@ -1139,7 +1139,7 @@ var init_testing = __esm({
|
|
|
1139
1139
|
|
|
1140
1140
|
// packages/server/src/cli.ts
|
|
1141
1141
|
import { spawn as spawn3 } from "node:child_process";
|
|
1142
|
-
import { existsSync as existsSync18, readFileSync as
|
|
1142
|
+
import { existsSync as existsSync18, readFileSync as readFileSync13, writeFileSync as writeFileSync13 } from "node:fs";
|
|
1143
1143
|
import { dirname as dirname9, join as join20 } from "node:path";
|
|
1144
1144
|
|
|
1145
1145
|
// packages/core/src/config/model.ts
|
|
@@ -1149,9 +1149,9 @@ init_workday();
|
|
|
1149
1149
|
function suggestGrid(width, height, target = 80) {
|
|
1150
1150
|
const rows = Math.max(2, Math.round(height / target));
|
|
1151
1151
|
const cellH = height / rows;
|
|
1152
|
-
const
|
|
1153
|
-
const near2 = [
|
|
1154
|
-
const cols = [12, 6, 4].map((d) => near2.find((n) => n % d === 0)).find((n) => n !== void 0) ??
|
|
1152
|
+
const raw2 = Math.max(2, Math.round(width / cellH));
|
|
1153
|
+
const near2 = [raw2, raw2 - 1, raw2 + 1].filter((n) => n >= 2);
|
|
1154
|
+
const cols = [12, 6, 4].map((d) => near2.find((n) => n % d === 0)).find((n) => n !== void 0) ?? raw2;
|
|
1155
1155
|
const short2 = Math.min(width, height);
|
|
1156
1156
|
const gap = short2 >= 400 ? 10 : short2 >= 240 ? 6 : 4;
|
|
1157
1157
|
return { cols, rows, gap, padding: gap };
|
|
@@ -1202,6 +1202,12 @@ function rescale(items, from, to) {
|
|
|
1202
1202
|
// packages/core/src/config/model.ts
|
|
1203
1203
|
var CONFIG_VERSION = 1;
|
|
1204
1204
|
var CONFIG_SCHEMA_ID = "https://kioskolcd.dev/schema/v1/config.json";
|
|
1205
|
+
function deviceRotates(d) {
|
|
1206
|
+
return d.driver === "remote";
|
|
1207
|
+
}
|
|
1208
|
+
function paintTurn(s) {
|
|
1209
|
+
return deviceRotates(s.device) ? 0 : s.rotate;
|
|
1210
|
+
}
|
|
1205
1211
|
var ZOOM = { min: 0.5, max: 2, step: 0.1 };
|
|
1206
1212
|
function zoomOf(inst) {
|
|
1207
1213
|
const z = inst.zoom;
|
|
@@ -1238,9 +1244,9 @@ function newId(prefix = "id") {
|
|
|
1238
1244
|
counter = (counter + 1) % 1296;
|
|
1239
1245
|
return `${prefix}-${Date.now().toString(36).slice(-5)}${counter.toString(36).padStart(2, "0")}${Math.floor(Math.random() * 1296).toString(36).padStart(2, "0")}`;
|
|
1240
1246
|
}
|
|
1241
|
-
function newPage(
|
|
1247
|
+
function newPage(name2, width, height, tiles = []) {
|
|
1242
1248
|
const grid = suggestGrid(width, height);
|
|
1243
|
-
return { id: newId("page"), name, enabled: true, durationMs: 10 * 6e4, when: "always", grid, gravity: width / height > 2.2 ? "left" : "up", background: {}, tiles };
|
|
1249
|
+
return { id: newId("page"), name: name2, enabled: true, durationMs: 10 * 6e4, when: "always", grid, gravity: width / height > 2.2 ? "left" : "up", background: {}, tiles };
|
|
1244
1250
|
}
|
|
1245
1251
|
function newTile(r, widgets = []) {
|
|
1246
1252
|
return { id: newId("tile"), ...r, widgets, rotateMs: 3e4, chrome: "auto" };
|
|
@@ -1248,10 +1254,10 @@ function newTile(r, widgets = []) {
|
|
|
1248
1254
|
function newWidget(type, options2 = {}, title) {
|
|
1249
1255
|
return { id: newId("w"), type, options: options2, ...title ? { title } : {} };
|
|
1250
1256
|
}
|
|
1251
|
-
function newScreen(
|
|
1257
|
+
function newScreen(name2, width = 1920, height = 462, device = { driver: "virtual" }) {
|
|
1252
1258
|
return {
|
|
1253
1259
|
id: newId("screen"),
|
|
1254
|
-
name,
|
|
1260
|
+
name: name2,
|
|
1255
1261
|
enabled: true,
|
|
1256
1262
|
width,
|
|
1257
1263
|
height,
|
|
@@ -1379,7 +1385,7 @@ var CATEGORIES = [
|
|
|
1379
1385
|
];
|
|
1380
1386
|
var ALERT_LEVELS = ["info", "warn", "critical"];
|
|
1381
1387
|
var PAD_KEYS = ["up", "down", "left", "right", "a", "b", "x", "y", "l", "r", "start", "select"];
|
|
1382
|
-
var SDK_VERSION = "0.2.
|
|
1388
|
+
var SDK_VERSION = "0.2.10";
|
|
1383
1389
|
function defineWidget(w) {
|
|
1384
1390
|
return w;
|
|
1385
1391
|
}
|
|
@@ -1522,7 +1528,7 @@ import { join, win32 } from "node:path";
|
|
|
1522
1528
|
function expandPath(p, o = {}) {
|
|
1523
1529
|
const env = o.env ?? process.env;
|
|
1524
1530
|
let v = p.replace(/\$(?:\{(\w+)\}|(\w+))/g, (whole, a, b) => env[a ?? b ?? ""] ?? whole);
|
|
1525
|
-
if ((o.os ?? process.platform) === "win32") v = v.replace(/%([^%\r\n]+)%/g, (whole,
|
|
1531
|
+
if ((o.os ?? process.platform) === "win32") v = v.replace(/%([^%\r\n]+)%/g, (whole, name2) => env[name2] ?? whole);
|
|
1526
1532
|
const home = o.home ?? homedir();
|
|
1527
1533
|
if (v === "~") return home;
|
|
1528
1534
|
return v.startsWith("~/") || v.startsWith("~\\") ? join(home, v.slice(2)) : v;
|
|
@@ -1738,8 +1744,8 @@ var paths = {
|
|
|
1738
1744
|
// packages/core/src/config/normalize.ts
|
|
1739
1745
|
init_format();
|
|
1740
1746
|
init_workday();
|
|
1741
|
-
function normalize(
|
|
1742
|
-
const { $schema, threads, setup, bootAnimation, ...c } =
|
|
1747
|
+
function normalize(raw2) {
|
|
1748
|
+
const { $schema, threads, setup, bootAnimation, ...c } = raw2 && typeof raw2 === "object" && !Array.isArray(raw2) ? raw2 : {};
|
|
1743
1749
|
const screens = Array.isArray(c.screens) ? c.screens.map(normalizeScreen) : [];
|
|
1744
1750
|
return {
|
|
1745
1751
|
...typeof $schema === "string" && $schema ? { $schema } : {},
|
|
@@ -1809,9 +1815,9 @@ function normalizeScreen(s, i) {
|
|
|
1809
1815
|
};
|
|
1810
1816
|
}
|
|
1811
1817
|
var HHMM = /^([01][0-9]|2[0-3]):[0-5][0-9]$/;
|
|
1812
|
-
function normalizeAlerts(
|
|
1813
|
-
if (!
|
|
1814
|
-
const a =
|
|
1818
|
+
function normalizeAlerts(raw2) {
|
|
1819
|
+
if (!raw2 || typeof raw2 !== "object") return {};
|
|
1820
|
+
const a = raw2;
|
|
1815
1821
|
const minLevel = ALERT_THRESHOLDS.includes(a.minLevel) ? a.minLevel : "info";
|
|
1816
1822
|
const q3 = a.quiet;
|
|
1817
1823
|
const quiet = q3 && typeof q3 === "object" && HHMM.test(String(q3.start)) && HHMM.test(String(q3.end)) && q3.start !== q3.end ? { start: q3.start, end: q3.end } : void 0;
|
|
@@ -2177,6 +2183,21 @@ function configSchema(plugins) {
|
|
|
2177
2183
|
keepalive: { type: "number", minimum: 0.1, maximum: 2, default: 1, description: "Seconds between re-sends of an unchanged frame; the firmware drops the picture after 2-3 s without one." }
|
|
2178
2184
|
}
|
|
2179
2185
|
},
|
|
2186
|
+
{
|
|
2187
|
+
title: "Kiosko remote screen",
|
|
2188
|
+
description: "A screen on the network running Kiosko's screen firmware (firmware/esp32-screen: the Waveshare ESP32-C6-LCD-1.47 and others). Kiosko finds it by mDNS, pairs with it once with the code it shows, and sends it frames over an authenticated, encrypted session; the screen turns the picture to the screen's rotation itself. See docs/remote-screen.md.",
|
|
2189
|
+
type: "object",
|
|
2190
|
+
additionalProperties: false,
|
|
2191
|
+
required: ["driver", "uid"],
|
|
2192
|
+
properties: {
|
|
2193
|
+
driver: { const: "remote" },
|
|
2194
|
+
uid: { type: "string", pattern: "^[0-9a-f]{12}$", description: "The screen's unique id (12 hex digits, from its MAC), as it announces itself. It never changes, even when the screen is renamed." },
|
|
2195
|
+
id: { type: "string", description: "The name the screen had when it was added (it may be renamed on the screen's setup page); shown until the screen says its own." },
|
|
2196
|
+
key: { type: "string", pattern: "^[0-9a-f]{64}$", description: "The pairing key (64 hex digits), set by pairing in the editor. Empty: not paired yet.", "x-secret": true },
|
|
2197
|
+
host: { type: "string", description: "Address to use instead of finding it by mDNS (another subnet, a network without multicast).", "x-risk": "network" },
|
|
2198
|
+
port: { type: "integer", minimum: 1, maximum: 65535, default: 7428 }
|
|
2199
|
+
}
|
|
2200
|
+
},
|
|
2180
2201
|
{
|
|
2181
2202
|
title: "Frame file",
|
|
2182
2203
|
description: "Writes frame.jpg atomically into a folder; an external sender takes it to the panel.",
|
|
@@ -2319,8 +2340,8 @@ function toPointer(segs) {
|
|
|
2319
2340
|
function resolvePointer(root, ref) {
|
|
2320
2341
|
if (!ref.startsWith("#")) throw new Error(`only local $ref are supported (${ref})`);
|
|
2321
2342
|
let cur = root;
|
|
2322
|
-
for (const
|
|
2323
|
-
const key = decodeURIComponent(
|
|
2343
|
+
for (const raw2 of ref.slice(1).split("/").slice(1)) {
|
|
2344
|
+
const key = decodeURIComponent(raw2).replace(/~1/g, "/").replace(/~0/g, "~");
|
|
2324
2345
|
cur = Array.isArray(cur) ? cur[Number(key)] : isObj(cur) ? cur[key] : void 0;
|
|
2325
2346
|
}
|
|
2326
2347
|
if (cur === void 0) throw new Error(`$ref ${ref} points nowhere`);
|
|
@@ -2606,13 +2627,13 @@ function repeated(items, path, what2, out) {
|
|
|
2606
2627
|
else seen.set(x.id, i);
|
|
2607
2628
|
});
|
|
2608
2629
|
}
|
|
2609
|
-
function checkConfig(
|
|
2630
|
+
function checkConfig(raw2, plugins) {
|
|
2610
2631
|
const errors = [];
|
|
2611
2632
|
const warnings = [];
|
|
2612
|
-
if (!isObj2(
|
|
2633
|
+
if (!isObj2(raw2)) return { errors: [issue([], "the config must be a JSON object")], warnings };
|
|
2613
2634
|
let cfg;
|
|
2614
2635
|
try {
|
|
2615
|
-
cfg = normalize(
|
|
2636
|
+
cfg = normalize(raw2);
|
|
2616
2637
|
} catch {
|
|
2617
2638
|
return { errors, warnings };
|
|
2618
2639
|
}
|
|
@@ -2697,9 +2718,9 @@ function checkConfig(raw, plugins) {
|
|
|
2697
2718
|
}
|
|
2698
2719
|
return { errors, warnings };
|
|
2699
2720
|
}
|
|
2700
|
-
function validateConfig(
|
|
2701
|
-
const shape = validateJson(schema2,
|
|
2702
|
-
const more = checkConfig(
|
|
2721
|
+
function validateConfig(raw2, plugins, schema2 = configSchema(plugins)) {
|
|
2722
|
+
const shape = validateJson(schema2, raw2);
|
|
2723
|
+
const more = checkConfig(raw2, plugins);
|
|
2703
2724
|
return { errors: [...shape, ...more.errors], warnings: more.warnings };
|
|
2704
2725
|
}
|
|
2705
2726
|
|
|
@@ -2736,7 +2757,7 @@ var pageText = (p) => {
|
|
|
2736
2757
|
const ts = pageTypes(p);
|
|
2737
2758
|
return `page ${q2(p.name)}: ${plural2(p.tiles.length, "tile")}${ts.length ? ` (${ts.slice(0, 6).join(", ")}${ts.length > 6 ? `, +${ts.length - 6} more` : ""})` : ""}`;
|
|
2738
2759
|
};
|
|
2739
|
-
var deviceText = (d) => d.driver === "trcc" ? `trcc ${d.url}` : d.driver === "file" ? `file ${d.dir}` : d.driver === "usb" ? `usb${d.serial ? ` ${d.serial}` : ""}` : d.driver;
|
|
2760
|
+
var deviceText = (d) => d.driver === "trcc" ? `trcc ${d.url}` : d.driver === "file" ? `file ${d.dir}` : d.driver === "usb" ? `usb${d.serial ? ` ${d.serial}` : ""}` : d.driver === "remote" ? `remote ${d.id ?? d.uid}` : d.driver;
|
|
2740
2761
|
var changedKeys = (a, b) => [.../* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)])].filter((k) => !same(a[k], b[k]));
|
|
2741
2762
|
function diffTiles(before, after, depth, out) {
|
|
2742
2763
|
const m = match(before.tiles, after.tiles, rect);
|
|
@@ -2854,7 +2875,7 @@ function annotatedValues(config2, schema2) {
|
|
|
2854
2875
|
const risks = risksOf(v.schema);
|
|
2855
2876
|
const secret = v.schema["x-secret"] === true;
|
|
2856
2877
|
if (!risks.length && !secret) return;
|
|
2857
|
-
const
|
|
2878
|
+
const add2 = (path, value) => {
|
|
2858
2879
|
if (isObj3(value) || Array.isArray(value)) return;
|
|
2859
2880
|
const ptr = toPointer(path);
|
|
2860
2881
|
const prev = out.get(ptr);
|
|
@@ -2870,8 +2891,8 @@ function annotatedValues(config2, schema2) {
|
|
|
2870
2891
|
...v.parent && isObj3(v.parent.value) ? { holder: v.parent.schema } : prev?.holder ? { holder: prev.holder } : {}
|
|
2871
2892
|
});
|
|
2872
2893
|
};
|
|
2873
|
-
if (Array.isArray(v.value)) v.value.forEach((x, i) =>
|
|
2874
|
-
else
|
|
2894
|
+
if (Array.isArray(v.value)) v.value.forEach((x, i) => add2([...v.path, i], x));
|
|
2895
|
+
else add2(v.path, v.value);
|
|
2875
2896
|
});
|
|
2876
2897
|
return [...out.values()];
|
|
2877
2898
|
}
|
|
@@ -3002,10 +3023,10 @@ function mergeSecrets(incoming, current, schema2) {
|
|
|
3002
3023
|
if (!restored.has(parentKey)) {
|
|
3003
3024
|
if (incContainers.has(parentKey)) continue;
|
|
3004
3025
|
const holder = incContainers.get(stableKey(current, parentPath.slice(0, -1)));
|
|
3005
|
-
const
|
|
3006
|
-
if (!holder || !isObj3(getAt(out, holder)) || typeof
|
|
3007
|
-
setAt(out, [...holder,
|
|
3008
|
-
incContainers.set(parentKey, [...holder,
|
|
3026
|
+
const name2 = parentPath[parentPath.length - 1];
|
|
3027
|
+
if (!holder || !isObj3(getAt(out, holder)) || typeof name2 !== "string") continue;
|
|
3028
|
+
setAt(out, [...holder, name2], clone2(getAt(current, parentPath)));
|
|
3029
|
+
incContainers.set(parentKey, [...holder, name2]);
|
|
3009
3030
|
restored.add(parentKey);
|
|
3010
3031
|
}
|
|
3011
3032
|
kept.push({ a: { ...c, path: [...incContainers.get(parentKey), last2] }, from: c });
|
|
@@ -3029,24 +3050,24 @@ var CARRIED = ["locale", "timeFormat", "theme", "location", "workday", "plugins"
|
|
|
3029
3050
|
function planImport(incoming, current, plugins, schema2 = configSchema(plugins)) {
|
|
3030
3051
|
const report = validateConfig(incoming, plugins, schema2);
|
|
3031
3052
|
const { config: merged2, ...secrets } = mergeSecrets(incoming, current, schema2);
|
|
3032
|
-
const
|
|
3053
|
+
const raw2 = isObj3(merged2) ? { ...merged2 } : {};
|
|
3033
3054
|
const carried = [];
|
|
3034
3055
|
for (const k of CARRIED) {
|
|
3035
|
-
if (
|
|
3036
|
-
|
|
3056
|
+
if (raw2[k] === void 0 && current[k] !== void 0) {
|
|
3057
|
+
raw2[k] = clone2(current[k]);
|
|
3037
3058
|
carried.push(k);
|
|
3038
3059
|
}
|
|
3039
3060
|
}
|
|
3040
|
-
if (
|
|
3041
|
-
const sources = isObj3(
|
|
3061
|
+
if (raw2.$schema === void 0 && current.$schema) raw2.$schema = current.$schema;
|
|
3062
|
+
const sources = isObj3(raw2.sources) ? { ...raw2.sources } : {};
|
|
3042
3063
|
for (const [k, v] of Object.entries(current.sources)) {
|
|
3043
3064
|
if (sources[k] === void 0) {
|
|
3044
3065
|
sources[k] = clone2(v);
|
|
3045
3066
|
carried.push(`sources[${JSON.stringify(k)}]`);
|
|
3046
3067
|
}
|
|
3047
3068
|
}
|
|
3048
|
-
|
|
3049
|
-
const config2 = normalize(
|
|
3069
|
+
raw2.sources = sources;
|
|
3070
|
+
const config2 = normalize(raw2);
|
|
3050
3071
|
return { report, config: config2, carried, diff: diffConfigs(current, config2), risks: listRisks(config2, schema2, current), secrets };
|
|
3051
3072
|
}
|
|
3052
3073
|
|
|
@@ -3103,23 +3124,23 @@ function starterPage(has, o) {
|
|
|
3103
3124
|
page.grid = { cols: 24, rows: 6, gap: 10, padding: 10 };
|
|
3104
3125
|
page.gravity = "left";
|
|
3105
3126
|
const tiles = [];
|
|
3106
|
-
const
|
|
3127
|
+
const add2 = (r, types2, title) => {
|
|
3107
3128
|
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
3129
|
if (ws.length) tiles.push(newTile(r, ws));
|
|
3109
3130
|
};
|
|
3110
3131
|
const lead = "agents/sessions";
|
|
3111
3132
|
const agents = o.agents !== false && ok(lead);
|
|
3112
3133
|
if (agents) {
|
|
3113
|
-
|
|
3114
|
-
|
|
3134
|
+
add2({ x: 0, y: 0, w: 11, h: 6 }, [lead]);
|
|
3135
|
+
add2({ x: 11, y: 0, w: 5, h: 4 }, ["core/clock"]);
|
|
3115
3136
|
} else {
|
|
3116
|
-
|
|
3117
|
-
|
|
3137
|
+
add2({ x: 0, y: 0, w: 11, h: 6 }, [["core/clock", { showDate: true }]]);
|
|
3138
|
+
add2({ x: 11, y: 0, w: 5, h: 4 }, ["core/date"]);
|
|
3118
3139
|
}
|
|
3119
|
-
|
|
3120
|
-
|
|
3140
|
+
add2({ x: 11, y: 4, w: 5, h: 2 }, ["weather/forecast", "mirror/compliments"]);
|
|
3141
|
+
add2({ x: 16, y: 0, w: 8, h: 6 }, ["vitals/vitals", "system/health", "usage/rail", "mirror/countdown"].filter(ok).slice(0, 3));
|
|
3121
3142
|
if (!tiles.length) {
|
|
3122
|
-
|
|
3143
|
+
add2({ 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
3144
|
const welcome = tiles[0]?.widgets[0];
|
|
3124
3145
|
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
3146
|
}
|
|
@@ -3139,7 +3160,7 @@ var STARTER_TYPES = /* @__PURE__ */ new Set(["agents/sessions", "core/text", "co
|
|
|
3139
3160
|
function looksLikeStarter(c) {
|
|
3140
3161
|
if (c.screens.length !== 1) return false;
|
|
3141
3162
|
const s = c.screens[0];
|
|
3142
|
-
const named = (
|
|
3163
|
+
const named = (name2, names) => Object.values(names).includes(name2);
|
|
3143
3164
|
if (s.device.driver !== "virtual" || !named(s.name, STARTER_NAMES.screen) || s.pages.length !== 1) return false;
|
|
3144
3165
|
const p = s.pages[0];
|
|
3145
3166
|
return named(p.name, STARTER_NAMES.page) && p.tiles.length <= 4 && p.tiles.every((t2) => t2.widgets.every((w) => STARTER_TYPES.has(w.type)));
|
|
@@ -3460,7 +3481,7 @@ var PROBE = "\u9AD4";
|
|
|
3460
3481
|
var missingPixels = /* @__PURE__ */ new Map();
|
|
3461
3482
|
var available = /* @__PURE__ */ new Map();
|
|
3462
3483
|
var probeCanvas = null;
|
|
3463
|
-
function pixelsOf(font,
|
|
3484
|
+
function pixelsOf(font, probe2 = PROBE) {
|
|
3464
3485
|
probeCanvas ??= createCanvas4(40, 40);
|
|
3465
3486
|
const g = probeCanvas.getContext("2d");
|
|
3466
3487
|
g.clearRect(0, 0, 40, 40);
|
|
@@ -3468,16 +3489,16 @@ function pixelsOf(font, probe = PROBE) {
|
|
|
3468
3489
|
else g.font = font;
|
|
3469
3490
|
g.fillStyle = "#000";
|
|
3470
3491
|
g.textBaseline = "top";
|
|
3471
|
-
g.fillText(
|
|
3492
|
+
g.fillText(probe2, 4, 4);
|
|
3472
3493
|
return Buffer.from(g.getImageData(0, 0, 40, 40).data.buffer).toString("base64");
|
|
3473
3494
|
}
|
|
3474
|
-
function hasFontFamily(family,
|
|
3475
|
-
const key = `${family}\0${
|
|
3495
|
+
function hasFontFamily(family, probe2 = PROBE) {
|
|
3496
|
+
const key = `${family}\0${probe2}`;
|
|
3476
3497
|
let yes = available.get(key);
|
|
3477
3498
|
if (yes === void 0) {
|
|
3478
|
-
let missing = missingPixels.get(
|
|
3479
|
-
if (missing === void 0) missingPixels.set(
|
|
3480
|
-
yes = pixelsOf(`28px "${family.replace(/"/g, "")}"`,
|
|
3499
|
+
let missing = missingPixels.get(probe2);
|
|
3500
|
+
if (missing === void 0) missingPixels.set(probe2, missing = pixelsOf('28px "Kiosko Missing Font"', probe2));
|
|
3501
|
+
yes = pixelsOf(`28px "${family.replace(/"/g, "")}"`, probe2) !== missing;
|
|
3481
3502
|
available.set(key, yes);
|
|
3482
3503
|
}
|
|
3483
3504
|
return yes;
|
|
@@ -3929,7 +3950,7 @@ var AnimationScheduler = class {
|
|
|
3929
3950
|
};
|
|
3930
3951
|
|
|
3931
3952
|
// packages/core/src/runtime.ts
|
|
3932
|
-
import { EventEmitter } from "node:events";
|
|
3953
|
+
import { EventEmitter as EventEmitter2 } from "node:events";
|
|
3933
3954
|
import { availableParallelism as availableParallelism2 } from "node:os";
|
|
3934
3955
|
|
|
3935
3956
|
// packages/core/src/alerts.ts
|
|
@@ -3956,9 +3977,9 @@ function text(x, locale) {
|
|
|
3956
3977
|
if (x && typeof x === "object" && typeof x.en === "string") return oneLine(localize(x, locale));
|
|
3957
3978
|
return "";
|
|
3958
3979
|
}
|
|
3959
|
-
function parseAlert(
|
|
3960
|
-
if (!
|
|
3961
|
-
const a =
|
|
3980
|
+
function parseAlert(raw2, now, locale) {
|
|
3981
|
+
if (!raw2 || typeof raw2 !== "object") throw new AlertError("an alert is an object", "badAlert");
|
|
3982
|
+
const a = raw2;
|
|
3962
3983
|
const id = typeof a.id === "string" ? a.id.trim() : "";
|
|
3963
3984
|
if (!id || id.length > 120) throw new AlertError("an alert needs an id", "badAlert");
|
|
3964
3985
|
if (!ALERT_LEVELS.includes(a.level)) throw new AlertError(`level must be one of ${ALERT_LEVELS.join(", ")}`, "badAlert");
|
|
@@ -4021,8 +4042,8 @@ var AlertBoard = class {
|
|
|
4021
4042
|
this.fromPlugins = next;
|
|
4022
4043
|
}
|
|
4023
4044
|
/** An alert from outside (`POST /api/alerts`). The same id again replaces it, and it shows again. */
|
|
4024
|
-
post(
|
|
4025
|
-
const body2 =
|
|
4045
|
+
post(raw2, now, locale, screenIds = []) {
|
|
4046
|
+
const body2 = raw2 && typeof raw2 === "object" ? { ...raw2 } : raw2;
|
|
4026
4047
|
if (body2 && typeof body2 === "object" && !body2.id) body2.id = `alert-${now.toString(36)}${Math.floor(Math.random() * 1296).toString(36)}`;
|
|
4027
4048
|
for (const k of ["source", "detail"]) {
|
|
4028
4049
|
const v = body2 && typeof body2 === "object" ? body2[k] : void 0;
|
|
@@ -4030,7 +4051,7 @@ var AlertBoard = class {
|
|
|
4030
4051
|
}
|
|
4031
4052
|
const a = parseAlert(body2, now, locale);
|
|
4032
4053
|
if (!EXTERNAL_ID.test(a.id)) throw new AlertError('the id may have only letters, digits, ".", "_" and "-" (up to 80)', "badAlert");
|
|
4033
|
-
const screens =
|
|
4054
|
+
const screens = raw2.screens;
|
|
4034
4055
|
let only;
|
|
4035
4056
|
if (screens !== void 0) {
|
|
4036
4057
|
if (!Array.isArray(screens) || !screens.every((s) => typeof s === "string")) throw new AlertError("screens is a list of screen ids", "badAlert");
|
|
@@ -4101,9 +4122,9 @@ var AlertBoard = class {
|
|
|
4101
4122
|
* settings let through (level, quiet hours; only `critical` while `off`),
|
|
4102
4123
|
* with the count of the others. Its test alert always does.
|
|
4103
4124
|
*/
|
|
4104
|
-
forScreen(screen, now,
|
|
4125
|
+
forScreen(screen, now, off2 = false) {
|
|
4105
4126
|
const cfg = screenAlerts(screen);
|
|
4106
|
-
const onlyCritical =
|
|
4127
|
+
const onlyCritical = off2 || inQuietHours(cfg.quiet, now);
|
|
4107
4128
|
const min = Math.max(levelRank(cfg.minLevel), onlyCritical ? levelRank("critical") : 0);
|
|
4108
4129
|
const here = this.list(now).filter((a) => !a.snoozedUntil && (!a.screens || a.screens.includes(screen.id)) && (a.origin === "test" || levelRank(a.level) >= min));
|
|
4109
4130
|
return here.length ? { top: here[0], more: here.length - 1 } : null;
|
|
@@ -4408,12 +4429,12 @@ function parseHandshake(resp, pid) {
|
|
|
4408
4429
|
const at = (i) => resp.length > i ? String(resp[i]) : "N/A";
|
|
4409
4430
|
throw new UnrecognisedReply(`handshake validation failed (length ${resp.length}, [0]=${at(0)}, [1]=${at(1)}, [8]=${at(8)})`);
|
|
4410
4431
|
}
|
|
4411
|
-
const
|
|
4432
|
+
const raw2 = resp.subarray(0, Math.min(resp.length, 64));
|
|
4412
4433
|
if (variantOf(pid) === "ly") {
|
|
4413
4434
|
const r = resp[20] <= 3 ? 1 : resp[20];
|
|
4414
|
-
return { pm: 64 + r, sub: (resp[22] ?? 0) + 1, raw };
|
|
4435
|
+
return { pm: 64 + r, sub: (resp[22] ?? 0) + 1, raw: raw2 };
|
|
4415
4436
|
}
|
|
4416
|
-
return { pm: 49 + resp[20], sub: resp[22] ?? 0, raw };
|
|
4437
|
+
return { pm: 49 + resp[20], sub: resp[22] ?? 0, raw: raw2 };
|
|
4417
4438
|
}
|
|
4418
4439
|
var ANGLES_1920 = [180, 180, 0, 0, 0, 180, 180, 180, 180];
|
|
4419
4440
|
var MODELS = {
|
|
@@ -4473,9 +4494,9 @@ var UsbUnavailable = class extends Error {
|
|
|
4473
4494
|
async function loadUsb() {
|
|
4474
4495
|
try {
|
|
4475
4496
|
const m = await import("usb");
|
|
4476
|
-
const
|
|
4477
|
-
if (!
|
|
4478
|
-
return
|
|
4497
|
+
const mod2 = m.getDeviceList ? m : m.default?.getDeviceList ? m.default : m.usb;
|
|
4498
|
+
if (!mod2?.getDeviceList) throw new Error("the usb module has no getDeviceList");
|
|
4499
|
+
return mod2;
|
|
4479
4500
|
} catch (err) {
|
|
4480
4501
|
throw new UsbUnavailable(`cannot load the "usb" package (libusb): ${err instanceof Error ? err.message : String(err)}. Install it with: npm install usb`);
|
|
4481
4502
|
}
|
|
@@ -4643,10 +4664,10 @@ function usbPathForSerial(serial, root = "/sys/bus/usb/devices") {
|
|
|
4643
4664
|
} catch {
|
|
4644
4665
|
return null;
|
|
4645
4666
|
}
|
|
4646
|
-
for (const
|
|
4647
|
-
if (!/^\d+-[\d.]+$/.test(
|
|
4667
|
+
for (const name2 of entries) {
|
|
4668
|
+
if (!/^\d+-[\d.]+$/.test(name2)) continue;
|
|
4648
4669
|
try {
|
|
4649
|
-
if (readFileSync2(`${root}/${
|
|
4670
|
+
if (readFileSync2(`${root}/${name2}/serial`, "utf8").trim() === serial) return name2;
|
|
4650
4671
|
} catch {
|
|
4651
4672
|
}
|
|
4652
4673
|
}
|
|
@@ -4819,6 +4840,996 @@ function pinFrame(o, key, intervalS, onError) {
|
|
|
4819
4840
|
};
|
|
4820
4841
|
}
|
|
4821
4842
|
|
|
4843
|
+
// packages/core/src/remote/crypto.ts
|
|
4844
|
+
import { createCipheriv, createDecipheriv, createHash, createHmac, hkdfSync, randomBytes, timingSafeEqual } from "node:crypto";
|
|
4845
|
+
|
|
4846
|
+
// packages/core/src/remote/p256.ts
|
|
4847
|
+
var P = 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffffn;
|
|
4848
|
+
var N = 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551n;
|
|
4849
|
+
var B = 0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604bn;
|
|
4850
|
+
var GX = 0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296n;
|
|
4851
|
+
var GY = 0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5n;
|
|
4852
|
+
var G = { x: GX, y: GY };
|
|
4853
|
+
var mod = (a, m = P) => (a % m + m) % m;
|
|
4854
|
+
function pow(a, e, m = P) {
|
|
4855
|
+
let r = 1n;
|
|
4856
|
+
a = mod(a, m);
|
|
4857
|
+
while (e > 0n) {
|
|
4858
|
+
if (e & 1n) r = r * a % m;
|
|
4859
|
+
a = a * a % m;
|
|
4860
|
+
e >>= 1n;
|
|
4861
|
+
}
|
|
4862
|
+
return r;
|
|
4863
|
+
}
|
|
4864
|
+
var inv = (a, m = P) => pow(a, m - 2n, m);
|
|
4865
|
+
function onCurve(p) {
|
|
4866
|
+
if (!p) return false;
|
|
4867
|
+
if (p.x < 0n || p.x >= P || p.y < 0n || p.y >= P) return false;
|
|
4868
|
+
return mod(p.y * p.y - (p.x * p.x * p.x - 3n * p.x + B)) === 0n;
|
|
4869
|
+
}
|
|
4870
|
+
var toJac = (p) => p ? { x: p.x, y: p.y, z: 1n } : { x: 1n, y: 1n, z: 0n };
|
|
4871
|
+
function toAffine(j) {
|
|
4872
|
+
if (j.z === 0n) return null;
|
|
4873
|
+
const zi = inv(j.z);
|
|
4874
|
+
const zi2 = zi * zi % P;
|
|
4875
|
+
return { x: mod(j.x * zi2), y: mod(j.y * zi2 * zi) };
|
|
4876
|
+
}
|
|
4877
|
+
function dbl(p) {
|
|
4878
|
+
if (p.z === 0n || p.y === 0n) return { x: 1n, y: 1n, z: 0n };
|
|
4879
|
+
const z2 = mod(p.z * p.z);
|
|
4880
|
+
const m = mod(3n * (p.x - z2) * (p.x + z2));
|
|
4881
|
+
const y2 = mod(p.y * p.y);
|
|
4882
|
+
const s = mod(4n * p.x * y2);
|
|
4883
|
+
const x = mod(m * m - 2n * s);
|
|
4884
|
+
const y = mod(m * (s - x) - 8n * y2 * y2);
|
|
4885
|
+
return { x, y, z: mod(2n * p.y * p.z) };
|
|
4886
|
+
}
|
|
4887
|
+
function add(p, q3) {
|
|
4888
|
+
if (p.z === 0n) return q3;
|
|
4889
|
+
if (q3.z === 0n) return p;
|
|
4890
|
+
const z1 = mod(p.z * p.z), z2 = mod(q3.z * q3.z);
|
|
4891
|
+
const u1 = mod(p.x * z2), u2 = mod(q3.x * z1);
|
|
4892
|
+
const s1 = mod(p.y * z2 * q3.z), s2 = mod(q3.y * z1 * p.z);
|
|
4893
|
+
if (u1 === u2) return s1 === s2 ? dbl(p) : { x: 1n, y: 1n, z: 0n };
|
|
4894
|
+
const h = mod(u2 - u1), r = mod(s2 - s1);
|
|
4895
|
+
const h2 = mod(h * h), h3 = mod(h2 * h);
|
|
4896
|
+
const x = mod(r * r - h3 - 2n * u1 * h2);
|
|
4897
|
+
const y = mod(r * (u1 * h2 - x) - s1 * h3);
|
|
4898
|
+
return { x, y, z: mod(h * p.z * q3.z) };
|
|
4899
|
+
}
|
|
4900
|
+
function pointAdd(a, b) {
|
|
4901
|
+
return toAffine(add(toJac(a), toJac(b)));
|
|
4902
|
+
}
|
|
4903
|
+
function pointNeg(a) {
|
|
4904
|
+
return a ? { x: a.x, y: mod(-a.y) } : null;
|
|
4905
|
+
}
|
|
4906
|
+
function mul(k, p) {
|
|
4907
|
+
k = mod(k, N);
|
|
4908
|
+
let r = { x: 1n, y: 1n, z: 0n };
|
|
4909
|
+
let q3 = toJac(p);
|
|
4910
|
+
let r1 = q3;
|
|
4911
|
+
for (let i = 255; i >= 0; i--) {
|
|
4912
|
+
if (k >> BigInt(i) & 1n) {
|
|
4913
|
+
r = add(r, r1);
|
|
4914
|
+
r1 = dbl(r1);
|
|
4915
|
+
} else {
|
|
4916
|
+
r1 = add(r, r1);
|
|
4917
|
+
r = dbl(r);
|
|
4918
|
+
}
|
|
4919
|
+
}
|
|
4920
|
+
q3 = r;
|
|
4921
|
+
return toAffine(q3);
|
|
4922
|
+
}
|
|
4923
|
+
var hex32 = (n) => n.toString(16).padStart(64, "0");
|
|
4924
|
+
function encodePoint(p) {
|
|
4925
|
+
if (!p) throw new Error("cannot encode the point at infinity");
|
|
4926
|
+
return Buffer.from("04" + hex32(p.x) + hex32(p.y), "hex");
|
|
4927
|
+
}
|
|
4928
|
+
function decodePoint(b) {
|
|
4929
|
+
const buf = Buffer.from(b);
|
|
4930
|
+
let p;
|
|
4931
|
+
if (buf.length === 65 && buf[0] === 4) {
|
|
4932
|
+
p = { x: BigInt("0x" + buf.subarray(1, 33).toString("hex")), y: BigInt("0x" + buf.subarray(33).toString("hex")) };
|
|
4933
|
+
} else if (buf.length === 33 && (buf[0] === 2 || buf[0] === 3)) {
|
|
4934
|
+
const x = BigInt("0x" + buf.subarray(1).toString("hex"));
|
|
4935
|
+
const rhs = mod(x * x * x - 3n * x + B);
|
|
4936
|
+
let y = pow(rhs, (P + 1n) / 4n);
|
|
4937
|
+
if (mod(y * y) !== rhs) throw new Error("not a point of P-256");
|
|
4938
|
+
if ((y & 1n) !== BigInt(buf[0] - 2)) y = mod(-y);
|
|
4939
|
+
p = { x, y };
|
|
4940
|
+
} else throw new Error("bad point encoding");
|
|
4941
|
+
if (!onCurve(p)) throw new Error("not a point of P-256");
|
|
4942
|
+
return p;
|
|
4943
|
+
}
|
|
4944
|
+
var scalarFrom = (b) => BigInt("0x" + (Buffer.from(b).toString("hex") || "0"));
|
|
4945
|
+
var scalarBytes = (n) => Buffer.from(hex32(n), "hex");
|
|
4946
|
+
|
|
4947
|
+
// packages/core/src/remote/crypto.ts
|
|
4948
|
+
var PROTO = 1;
|
|
4949
|
+
var PORT = 7428;
|
|
4950
|
+
var NONCE_LEN = 32;
|
|
4951
|
+
var KEY_LEN = 32;
|
|
4952
|
+
var TAG_LEN = 16;
|
|
4953
|
+
var ID_A = "kiosko";
|
|
4954
|
+
var mn = null;
|
|
4955
|
+
function spakePoints() {
|
|
4956
|
+
mn ??= {
|
|
4957
|
+
M: decodePoint(Buffer.from("02886e2f97ace46e55ba9dd7242579f2993b64e16ef3dcab95afd497333d8fa12f", "hex")),
|
|
4958
|
+
N: decodePoint(Buffer.from("03d8bbd6c639c62937b04d997f38c3770719c629d7014d49a24b4f98baa1292b49", "hex"))
|
|
4959
|
+
};
|
|
4960
|
+
return mn;
|
|
4961
|
+
}
|
|
4962
|
+
var LABEL_AUTH_K = "KSv1 auth kiosko";
|
|
4963
|
+
var LABEL_AUTH_D = "KSv1 auth screen";
|
|
4964
|
+
var hkdf = (ikm, salt, info, len) => Buffer.from(hkdfSync("sha256", ikm, salt, Buffer.from(info), len));
|
|
4965
|
+
var hmac = (key, ...parts) => {
|
|
4966
|
+
const h = createHmac("sha256", key);
|
|
4967
|
+
for (const p of parts) h.update(p);
|
|
4968
|
+
return h.digest();
|
|
4969
|
+
};
|
|
4970
|
+
function equal2(a, b) {
|
|
4971
|
+
return a.length === b.length && timingSafeEqual(a, b);
|
|
4972
|
+
}
|
|
4973
|
+
function authMac(key, label, nk, nd, uid) {
|
|
4974
|
+
return hmac(key, label, nk, nd, uid);
|
|
4975
|
+
}
|
|
4976
|
+
function sessionKeys(key, nk, nd, side) {
|
|
4977
|
+
const okm = hkdf(key, Buffer.concat([nk, nd]), "KSv1 session", 64);
|
|
4978
|
+
const k2d = okm.subarray(0, 32), d2k = okm.subarray(32);
|
|
4979
|
+
return side === "kiosko" ? { tx: { key: Buffer.from(k2d), seq: 0n }, rx: { key: Buffer.from(d2k), seq: 0n } } : { tx: { key: Buffer.from(d2k), seq: 0n }, rx: { key: Buffer.from(k2d), seq: 0n } };
|
|
4980
|
+
}
|
|
4981
|
+
function nonceOf(seq) {
|
|
4982
|
+
const n = Buffer.alloc(12);
|
|
4983
|
+
n.writeBigUInt64BE(seq, 4);
|
|
4984
|
+
return n;
|
|
4985
|
+
}
|
|
4986
|
+
function seal(d, type, payload) {
|
|
4987
|
+
const len = 1 + payload.length + TAG_LEN;
|
|
4988
|
+
const hdr = Buffer.alloc(4);
|
|
4989
|
+
hdr.writeUInt32BE(len);
|
|
4990
|
+
const c = createCipheriv("chacha20-poly1305", d.key, nonceOf(d.seq), { authTagLength: TAG_LEN });
|
|
4991
|
+
c.setAAD(hdr, { plaintextLength: len - TAG_LEN });
|
|
4992
|
+
const out = Buffer.concat([hdr, c.update(Buffer.from([type])), c.update(payload), c.final(), c.getAuthTag()]);
|
|
4993
|
+
d.seq++;
|
|
4994
|
+
return out;
|
|
4995
|
+
}
|
|
4996
|
+
function open(d, hdr, body2) {
|
|
4997
|
+
if (body2.length < TAG_LEN + 1) throw new Error("sealed message too short");
|
|
4998
|
+
const dc = createDecipheriv("chacha20-poly1305", d.key, nonceOf(d.seq), { authTagLength: TAG_LEN });
|
|
4999
|
+
dc.setAAD(hdr, { plaintextLength: body2.length - TAG_LEN });
|
|
5000
|
+
dc.setAuthTag(body2.subarray(body2.length - TAG_LEN));
|
|
5001
|
+
const pt = Buffer.concat([dc.update(body2.subarray(0, body2.length - TAG_LEN)), dc.final()]);
|
|
5002
|
+
d.seq++;
|
|
5003
|
+
return { type: pt[0], payload: pt.subarray(1) };
|
|
5004
|
+
}
|
|
5005
|
+
function spakeW(uid, code) {
|
|
5006
|
+
const h = createHash("sha256").update("KSv1 pake w").update(uid).update(":").update(code).digest();
|
|
5007
|
+
return scalarFrom(h) % N;
|
|
5008
|
+
}
|
|
5009
|
+
function le64(n) {
|
|
5010
|
+
const b = Buffer.alloc(8);
|
|
5011
|
+
b.writeBigUInt64LE(BigInt(n));
|
|
5012
|
+
return b;
|
|
5013
|
+
}
|
|
5014
|
+
function transcript(uid, X, Y, K, w) {
|
|
5015
|
+
const parts = [Buffer.from(ID_A), Buffer.from(uid), X, Y, K, scalarBytes(w)];
|
|
5016
|
+
return Buffer.concat(parts.flatMap((p) => [le64(p.length), p]));
|
|
5017
|
+
}
|
|
5018
|
+
function spakeKeys(tt) {
|
|
5019
|
+
const h = createHash("sha256").update(tt).digest();
|
|
5020
|
+
const kc = hkdf(h, Buffer.alloc(0), "KSv1 confirm", 64);
|
|
5021
|
+
return { key: hkdf(h, Buffer.alloc(0), "KSv1 pair key", 32), cA: hmac(kc.subarray(0, 32), tt), cB: hmac(kc.subarray(32), tt) };
|
|
5022
|
+
}
|
|
5023
|
+
var randomScalar = () => {
|
|
5024
|
+
for (; ; ) {
|
|
5025
|
+
const k = scalarFrom(randomBytes(32));
|
|
5026
|
+
if (k > 0n && k < N) return k;
|
|
5027
|
+
}
|
|
5028
|
+
};
|
|
5029
|
+
var SpakeA = class {
|
|
5030
|
+
X;
|
|
5031
|
+
x;
|
|
5032
|
+
w;
|
|
5033
|
+
uid;
|
|
5034
|
+
constructor(uid, code, x) {
|
|
5035
|
+
this.uid = uid;
|
|
5036
|
+
this.w = spakeW(uid, code);
|
|
5037
|
+
this.x = x ?? randomScalar();
|
|
5038
|
+
this.X = encodePoint(pointAdd(mul(this.x, G), mul(this.w, spakePoints().M)));
|
|
5039
|
+
}
|
|
5040
|
+
finish(Yb) {
|
|
5041
|
+
const Y = decodePoint(Yb);
|
|
5042
|
+
const K = mul(this.x, pointAdd(Y, pointNeg(mul(this.w, spakePoints().N))));
|
|
5043
|
+
if (!K) throw new Error("bad Y");
|
|
5044
|
+
const Kb = encodePoint(K);
|
|
5045
|
+
return { ...spakeKeys(transcript(this.uid, this.X, encodePoint(Y), Kb, this.w)), K: Kb };
|
|
5046
|
+
}
|
|
5047
|
+
};
|
|
5048
|
+
|
|
5049
|
+
// packages/core/src/remote/link.ts
|
|
5050
|
+
import { connect } from "node:net";
|
|
5051
|
+
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
5052
|
+
var T = {
|
|
5053
|
+
HELLO: 1,
|
|
5054
|
+
INFO: 2,
|
|
5055
|
+
AUTH: 3,
|
|
5056
|
+
AUTH_OK: 4,
|
|
5057
|
+
ERROR: 5,
|
|
5058
|
+
PAIR_START: 6,
|
|
5059
|
+
PAIR_READY: 7,
|
|
5060
|
+
PAIR_X: 8,
|
|
5061
|
+
PAIR_Y: 9,
|
|
5062
|
+
PAIR_CONFIRM: 10,
|
|
5063
|
+
PAIR_OK: 11,
|
|
5064
|
+
FRAME: 16,
|
|
5065
|
+
ACK: 17,
|
|
5066
|
+
SET: 18,
|
|
5067
|
+
STATE: 19,
|
|
5068
|
+
LED: 20,
|
|
5069
|
+
PING: 21,
|
|
5070
|
+
PONG: 22,
|
|
5071
|
+
UNPAIR: 23,
|
|
5072
|
+
OTA_BEGIN: 24,
|
|
5073
|
+
OTA_ACK: 25,
|
|
5074
|
+
OTA_DATA: 26,
|
|
5075
|
+
OTA_END: 27,
|
|
5076
|
+
OTA_DONE: 28,
|
|
5077
|
+
LOGS: 29
|
|
5078
|
+
};
|
|
5079
|
+
var ScreenError = class extends Error {
|
|
5080
|
+
code;
|
|
5081
|
+
constructor(code, message) {
|
|
5082
|
+
super(message);
|
|
5083
|
+
this.code = code;
|
|
5084
|
+
this.name = "ScreenError";
|
|
5085
|
+
}
|
|
5086
|
+
};
|
|
5087
|
+
var MAX_MSG = 1 << 20;
|
|
5088
|
+
var Wire = class _Wire {
|
|
5089
|
+
buf = Buffer.alloc(0);
|
|
5090
|
+
waiting = null;
|
|
5091
|
+
queue = [];
|
|
5092
|
+
ended = null;
|
|
5093
|
+
sock;
|
|
5094
|
+
constructor(sock) {
|
|
5095
|
+
this.sock = sock;
|
|
5096
|
+
sock.setNoDelay(true);
|
|
5097
|
+
sock.on("data", (d) => this.onData(d));
|
|
5098
|
+
const end = (e) => this.fail(e ?? new Error("connection closed"));
|
|
5099
|
+
sock.on("error", end);
|
|
5100
|
+
sock.on("close", () => end());
|
|
5101
|
+
}
|
|
5102
|
+
static open(host, port = PORT, timeoutMs = 4e3) {
|
|
5103
|
+
return new Promise((resolve8, reject) => {
|
|
5104
|
+
const s = connect({ host, port });
|
|
5105
|
+
const t2 = setTimeout(() => {
|
|
5106
|
+
s.destroy();
|
|
5107
|
+
reject(Object.assign(new Error(`no answer from ${host}:${port}`), { code: "ETIMEDOUT" }));
|
|
5108
|
+
}, timeoutMs);
|
|
5109
|
+
s.once("connect", () => {
|
|
5110
|
+
clearTimeout(t2);
|
|
5111
|
+
s.setKeepAlive(true, 1e4);
|
|
5112
|
+
resolve8(new _Wire(s));
|
|
5113
|
+
});
|
|
5114
|
+
s.once("error", (e) => {
|
|
5115
|
+
clearTimeout(t2);
|
|
5116
|
+
reject(e);
|
|
5117
|
+
});
|
|
5118
|
+
});
|
|
5119
|
+
}
|
|
5120
|
+
onData(d) {
|
|
5121
|
+
this.buf = this.buf.length ? Buffer.concat([this.buf, d]) : d;
|
|
5122
|
+
while (this.buf.length >= 4) {
|
|
5123
|
+
const len = this.buf.readUInt32BE(0);
|
|
5124
|
+
if (len < 1 || len > MAX_MSG) return this.fail(new Error(`bad message length ${len}`));
|
|
5125
|
+
if (this.buf.length < 4 + len) break;
|
|
5126
|
+
const m = { hdr: Buffer.from(this.buf.subarray(0, 4)), body: Buffer.from(this.buf.subarray(4, 4 + len)) };
|
|
5127
|
+
this.buf = this.buf.subarray(4 + len);
|
|
5128
|
+
if (this.waiting) {
|
|
5129
|
+
const w = this.waiting;
|
|
5130
|
+
this.waiting = null;
|
|
5131
|
+
w.resolve(m);
|
|
5132
|
+
} else this.queue.push(m);
|
|
5133
|
+
}
|
|
5134
|
+
}
|
|
5135
|
+
fail(e) {
|
|
5136
|
+
if (this.ended) return;
|
|
5137
|
+
this.ended = e;
|
|
5138
|
+
this.sock.destroy();
|
|
5139
|
+
const w = this.waiting;
|
|
5140
|
+
this.waiting = null;
|
|
5141
|
+
w?.reject(e);
|
|
5142
|
+
}
|
|
5143
|
+
get closed() {
|
|
5144
|
+
return !!this.ended;
|
|
5145
|
+
}
|
|
5146
|
+
/** The next message, raw; rejects on close or after `timeoutMs`. */
|
|
5147
|
+
next(timeoutMs = 1e4) {
|
|
5148
|
+
const q3 = this.queue.shift();
|
|
5149
|
+
if (q3) return Promise.resolve(q3);
|
|
5150
|
+
if (this.ended) return Promise.reject(this.ended);
|
|
5151
|
+
return new Promise((resolve8, reject) => {
|
|
5152
|
+
const t2 = setTimeout(() => {
|
|
5153
|
+
this.waiting = null;
|
|
5154
|
+
reject(Object.assign(new Error("the screen stopped answering"), { code: "ETIMEDOUT" }));
|
|
5155
|
+
}, timeoutMs);
|
|
5156
|
+
this.waiting = {
|
|
5157
|
+
resolve: (m) => {
|
|
5158
|
+
clearTimeout(t2);
|
|
5159
|
+
resolve8(m);
|
|
5160
|
+
},
|
|
5161
|
+
reject: (e) => {
|
|
5162
|
+
clearTimeout(t2);
|
|
5163
|
+
reject(e);
|
|
5164
|
+
}
|
|
5165
|
+
};
|
|
5166
|
+
});
|
|
5167
|
+
}
|
|
5168
|
+
write(b) {
|
|
5169
|
+
if (!this.ended) this.sock.write(b);
|
|
5170
|
+
}
|
|
5171
|
+
sendPlain(type, obj) {
|
|
5172
|
+
const p = Buffer.from(JSON.stringify(obj));
|
|
5173
|
+
const h = Buffer.alloc(5);
|
|
5174
|
+
h.writeUInt32BE(p.length + 1);
|
|
5175
|
+
h[4] = type;
|
|
5176
|
+
this.write(Buffer.concat([h, p]));
|
|
5177
|
+
}
|
|
5178
|
+
/** A plain message of type `want` (JSON); an ERROR from the screen becomes a ScreenError. */
|
|
5179
|
+
async plain(want, timeoutMs = 1e4) {
|
|
5180
|
+
const { body: body2 } = await this.next(timeoutMs);
|
|
5181
|
+
let j;
|
|
5182
|
+
try {
|
|
5183
|
+
j = JSON.parse(body2.subarray(1).toString("utf8"));
|
|
5184
|
+
} catch {
|
|
5185
|
+
throw new Error("the screen sent something unreadable");
|
|
5186
|
+
}
|
|
5187
|
+
if (body2[0] === T.ERROR) throw new ScreenError(String(j.code ?? "error"), String(j.msg ?? "refused"));
|
|
5188
|
+
if (body2[0] !== want) throw new Error(`unexpected message 0x${body2[0].toString(16)} from the screen`);
|
|
5189
|
+
return j;
|
|
5190
|
+
}
|
|
5191
|
+
close() {
|
|
5192
|
+
this.fail(new Error("closed"));
|
|
5193
|
+
}
|
|
5194
|
+
};
|
|
5195
|
+
function toInfo(j) {
|
|
5196
|
+
const num = (v, d = 0) => typeof v === "number" && Number.isFinite(v) ? v : d;
|
|
5197
|
+
return { proto: num(j.proto), uid: String(j.uid ?? ""), id: String(j.id ?? ""), model: String(j.model ?? ""), w: num(j.w), h: num(j.h), rot: num(j.rot), fw: String(j.fw ?? ""), paired: j.paired === true, ...typeof j.pairing === "boolean" ? { pairing: j.pairing } : {}, max: num(j.max, 64 * 1024) };
|
|
5198
|
+
}
|
|
5199
|
+
async function hello(w, want) {
|
|
5200
|
+
const nk = randomBytes2(NONCE_LEN);
|
|
5201
|
+
w.sendPlain(T.HELLO, { proto: PROTO, nonce: nk.toString("hex"), want });
|
|
5202
|
+
const j = await w.plain(T.INFO);
|
|
5203
|
+
const nd = Buffer.from(String(j.nonce ?? ""), "hex");
|
|
5204
|
+
if (nd.length !== NONCE_LEN) throw new Error("the screen sent no nonce");
|
|
5205
|
+
const info = toInfo(j);
|
|
5206
|
+
if (info.proto !== PROTO) {
|
|
5207
|
+
throw new ScreenError("proto", `the screen speaks protocol ${info.proto}, this Kiosko ${PROTO}: update one of them`);
|
|
5208
|
+
}
|
|
5209
|
+
return { info, nk, nd };
|
|
5210
|
+
}
|
|
5211
|
+
async function probe(host, port = PORT) {
|
|
5212
|
+
const w = await Wire.open(host, port);
|
|
5213
|
+
try {
|
|
5214
|
+
return (await hello(w, "info")).info;
|
|
5215
|
+
} finally {
|
|
5216
|
+
w.close();
|
|
5217
|
+
}
|
|
5218
|
+
}
|
|
5219
|
+
async function openSession(host, port, key, expectUid) {
|
|
5220
|
+
if (key.length !== KEY_LEN) throw new ScreenError("notPaired", "no pairing key for this screen");
|
|
5221
|
+
const wire = await Wire.open(host, port);
|
|
5222
|
+
try {
|
|
5223
|
+
const { info, nk, nd } = await hello(wire, "session");
|
|
5224
|
+
if (expectUid && info.uid !== expectUid) throw new ScreenError("otherScreen", `another screen (${info.id}, ${info.uid}) answers at ${host}`);
|
|
5225
|
+
wire.sendPlain(T.AUTH, { mac: authMac(key, LABEL_AUTH_K, nk, nd, info.uid).toString("hex") });
|
|
5226
|
+
const ok = await wire.plain(T.AUTH_OK);
|
|
5227
|
+
const want = authMac(key, LABEL_AUTH_D, nk, nd, info.uid);
|
|
5228
|
+
if (!equal2(Buffer.from(String(ok.mac ?? ""), "hex"), want)) throw new ScreenError("badScreen", "the screen could not prove it has the key: not the paired one");
|
|
5229
|
+
return { wire, info, session: sessionKeys(key, nk, nd, "kiosko") };
|
|
5230
|
+
} catch (err) {
|
|
5231
|
+
wire.close();
|
|
5232
|
+
throw err;
|
|
5233
|
+
}
|
|
5234
|
+
}
|
|
5235
|
+
function sendSealed(wire, s, type, payload = {}) {
|
|
5236
|
+
wire.write(seal(s.tx, type, Buffer.isBuffer(payload) ? payload : Buffer.from(JSON.stringify(payload))));
|
|
5237
|
+
}
|
|
5238
|
+
async function nextSealed(wire, s, timeoutMs = 15e3) {
|
|
5239
|
+
const { hdr, body: body2 } = await wire.next(timeoutMs);
|
|
5240
|
+
const m = open(s.rx, hdr, body2);
|
|
5241
|
+
return { ...m, json: () => JSON.parse(m.payload.toString("utf8") || "{}") };
|
|
5242
|
+
}
|
|
5243
|
+
var Pairing = class _Pairing {
|
|
5244
|
+
info;
|
|
5245
|
+
ttl;
|
|
5246
|
+
wire;
|
|
5247
|
+
done = false;
|
|
5248
|
+
constructor(wire, info, ttl) {
|
|
5249
|
+
this.wire = wire;
|
|
5250
|
+
this.info = info;
|
|
5251
|
+
this.ttl = ttl;
|
|
5252
|
+
}
|
|
5253
|
+
static async start(host, port, name2) {
|
|
5254
|
+
const wire = await Wire.open(host, port);
|
|
5255
|
+
try {
|
|
5256
|
+
const { info } = await hello(wire, "pair");
|
|
5257
|
+
wire.sendPlain(T.PAIR_START, { name: name2.slice(0, 40) });
|
|
5258
|
+
const r = await wire.plain(T.PAIR_READY);
|
|
5259
|
+
return new _Pairing(wire, info, typeof r.ttl === "number" ? r.ttl : 120);
|
|
5260
|
+
} catch (err) {
|
|
5261
|
+
wire.close();
|
|
5262
|
+
throw err;
|
|
5263
|
+
}
|
|
5264
|
+
}
|
|
5265
|
+
async finish(code) {
|
|
5266
|
+
if (this.done) throw new ScreenError("pairingOver", "this pairing is over: start again");
|
|
5267
|
+
this.done = true;
|
|
5268
|
+
try {
|
|
5269
|
+
const clean = code.replace(/\D/g, "");
|
|
5270
|
+
if (clean.length !== 6) throw new ScreenError("badCode", "the code has 6 digits");
|
|
5271
|
+
const a = new SpakeA(this.info.uid, clean);
|
|
5272
|
+
this.wire.sendPlain(T.PAIR_X, { X: a.X.toString("hex") });
|
|
5273
|
+
const y = await this.wire.plain(T.PAIR_Y, 15e3);
|
|
5274
|
+
const k = a.finish(Buffer.from(String(y.Y ?? ""), "hex"));
|
|
5275
|
+
if (!equal2(Buffer.from(String(y.c ?? ""), "hex"), k.cB)) {
|
|
5276
|
+
this.wire.sendPlain(T.PAIR_CONFIRM, { c: "00".repeat(32) });
|
|
5277
|
+
throw new ScreenError("badCode", "the code does not match the one on the screen");
|
|
5278
|
+
}
|
|
5279
|
+
this.wire.sendPlain(T.PAIR_CONFIRM, { c: k.cA.toString("hex") });
|
|
5280
|
+
await this.wire.plain(T.PAIR_OK, 15e3);
|
|
5281
|
+
return k.key;
|
|
5282
|
+
} finally {
|
|
5283
|
+
this.wire.close();
|
|
5284
|
+
}
|
|
5285
|
+
}
|
|
5286
|
+
cancel() {
|
|
5287
|
+
this.done = true;
|
|
5288
|
+
this.wire.close();
|
|
5289
|
+
}
|
|
5290
|
+
};
|
|
5291
|
+
|
|
5292
|
+
// packages/core/src/remote/mdns.ts
|
|
5293
|
+
import { createSocket } from "node:dgram";
|
|
5294
|
+
import { EventEmitter } from "node:events";
|
|
5295
|
+
import { networkInterfaces } from "node:os";
|
|
5296
|
+
var SERVICE = "_kiosko-screen._tcp.local";
|
|
5297
|
+
var service = SERVICE;
|
|
5298
|
+
var GROUP = "224.0.0.251";
|
|
5299
|
+
var MDNS_PORT = 5353;
|
|
5300
|
+
var TYPE = { A: 1, PTR: 12, TXT: 16, SRV: 33, ANY: 255 };
|
|
5301
|
+
function encodeName(name2) {
|
|
5302
|
+
const parts = name2.replace(/\.$/, "").split(".");
|
|
5303
|
+
return Buffer.concat([...parts.map((p) => Buffer.concat([Buffer.from([Buffer.byteLength(p)]), Buffer.from(p)])), Buffer.from([0])]);
|
|
5304
|
+
}
|
|
5305
|
+
function buildQuery(name2, type, unicast = false) {
|
|
5306
|
+
const h = Buffer.alloc(12);
|
|
5307
|
+
h.writeUInt16BE(1, 4);
|
|
5308
|
+
const q3 = Buffer.alloc(4);
|
|
5309
|
+
q3.writeUInt16BE(type, 0);
|
|
5310
|
+
q3.writeUInt16BE(unicast ? 32769 : 1, 2);
|
|
5311
|
+
return Buffer.concat([h, encodeName(name2), q3]);
|
|
5312
|
+
}
|
|
5313
|
+
function readName(b, at) {
|
|
5314
|
+
const labels = [];
|
|
5315
|
+
let next = -1;
|
|
5316
|
+
for (let hops = 0; hops < 32; hops++) {
|
|
5317
|
+
if (at >= b.length) throw new Error("truncated name");
|
|
5318
|
+
const len = b[at];
|
|
5319
|
+
if (len === 0) {
|
|
5320
|
+
if (next < 0) next = at + 1;
|
|
5321
|
+
return { name: labels.join("."), next };
|
|
5322
|
+
}
|
|
5323
|
+
if ((len & 192) === 192) {
|
|
5324
|
+
if (next < 0) next = at + 2;
|
|
5325
|
+
at = (len & 63) << 8 | b[at + 1];
|
|
5326
|
+
continue;
|
|
5327
|
+
}
|
|
5328
|
+
labels.push(b.toString("utf8", at + 1, at + 1 + len));
|
|
5329
|
+
at += 1 + len;
|
|
5330
|
+
}
|
|
5331
|
+
throw new Error("name loop");
|
|
5332
|
+
}
|
|
5333
|
+
function parseResponse(b) {
|
|
5334
|
+
if (b.length < 12) return [];
|
|
5335
|
+
const flags = b.readUInt16BE(2);
|
|
5336
|
+
if (!(flags & 32768)) return [];
|
|
5337
|
+
const qd = b.readUInt16BE(4);
|
|
5338
|
+
const total = b.readUInt16BE(6) + b.readUInt16BE(8) + b.readUInt16BE(10);
|
|
5339
|
+
let at = 12;
|
|
5340
|
+
for (let i = 0; i < qd; i++) at = readName(b, at).next + 4;
|
|
5341
|
+
const out = [];
|
|
5342
|
+
for (let i = 0; i < total && at < b.length; i++) {
|
|
5343
|
+
const { name: name2, next } = readName(b, at);
|
|
5344
|
+
at = next;
|
|
5345
|
+
if (at + 10 > b.length) break;
|
|
5346
|
+
const type = b.readUInt16BE(at);
|
|
5347
|
+
const ttl = b.readUInt32BE(at + 4);
|
|
5348
|
+
const len = b.readUInt16BE(at + 8);
|
|
5349
|
+
const rd = at + 10;
|
|
5350
|
+
at = rd + len;
|
|
5351
|
+
if (at > b.length) break;
|
|
5352
|
+
const r = { name: name2.toLowerCase(), type, ttl, data: {} };
|
|
5353
|
+
if (type === TYPE.PTR) r.data.ptr = readName(b, rd).name;
|
|
5354
|
+
else if (type === TYPE.SRV) r.data.srv = { port: b.readUInt16BE(rd + 4), target: readName(b, rd + 6).name.toLowerCase() };
|
|
5355
|
+
else if (type === TYPE.A && len === 4) r.data.a = `${b[rd]}.${b[rd + 1]}.${b[rd + 2]}.${b[rd + 3]}`;
|
|
5356
|
+
else if (type === TYPE.TXT) {
|
|
5357
|
+
const txt = {};
|
|
5358
|
+
for (let p = rd; p < rd + len; ) {
|
|
5359
|
+
const l = b[p];
|
|
5360
|
+
const s = b.toString("utf8", p + 1, p + 1 + l);
|
|
5361
|
+
const eq = s.indexOf("=");
|
|
5362
|
+
if (eq > 0) txt[s.slice(0, eq).toLowerCase()] = s.slice(eq + 1);
|
|
5363
|
+
p += 1 + l;
|
|
5364
|
+
}
|
|
5365
|
+
r.data.txt = txt;
|
|
5366
|
+
} else continue;
|
|
5367
|
+
out.push(r);
|
|
5368
|
+
}
|
|
5369
|
+
return out;
|
|
5370
|
+
}
|
|
5371
|
+
var ScreenBrowser = class extends EventEmitter {
|
|
5372
|
+
sock = null;
|
|
5373
|
+
starting = null;
|
|
5374
|
+
instances = /* @__PURE__ */ new Map();
|
|
5375
|
+
hosts = /* @__PURE__ */ new Map();
|
|
5376
|
+
found = /* @__PURE__ */ new Map();
|
|
5377
|
+
timer = null;
|
|
5378
|
+
users = 0;
|
|
5379
|
+
shared = true;
|
|
5380
|
+
/** Starts listening (idempotent). */
|
|
5381
|
+
start() {
|
|
5382
|
+
this.starting ??= new Promise((resolve8) => {
|
|
5383
|
+
const s = createSocket({ type: "udp4", reuseAddr: true });
|
|
5384
|
+
let bound = false;
|
|
5385
|
+
s.on("message", (m) => this.onMessage(m));
|
|
5386
|
+
s.on("error", () => void 0);
|
|
5387
|
+
s.once("error", () => {
|
|
5388
|
+
if (bound) return;
|
|
5389
|
+
s.close();
|
|
5390
|
+
this.shared = false;
|
|
5391
|
+
const e = createSocket({ type: "udp4" });
|
|
5392
|
+
e.on("message", (m) => this.onMessage(m));
|
|
5393
|
+
e.on("error", () => void 0);
|
|
5394
|
+
e.bind(0, () => {
|
|
5395
|
+
e.unref();
|
|
5396
|
+
this.sock = e;
|
|
5397
|
+
resolve8();
|
|
5398
|
+
});
|
|
5399
|
+
});
|
|
5400
|
+
s.bind(MDNS_PORT, () => {
|
|
5401
|
+
bound = true;
|
|
5402
|
+
s.unref();
|
|
5403
|
+
try {
|
|
5404
|
+
let joined = false;
|
|
5405
|
+
for (const list2 of Object.values(networkInterfaces())) {
|
|
5406
|
+
for (const i of list2 ?? []) {
|
|
5407
|
+
if (i.family !== "IPv4" || i.internal) continue;
|
|
5408
|
+
try {
|
|
5409
|
+
s.addMembership(GROUP, i.address);
|
|
5410
|
+
joined = true;
|
|
5411
|
+
} catch {
|
|
5412
|
+
}
|
|
5413
|
+
}
|
|
5414
|
+
}
|
|
5415
|
+
if (!joined) s.addMembership(GROUP);
|
|
5416
|
+
s.setMulticastTTL(255);
|
|
5417
|
+
} catch {
|
|
5418
|
+
}
|
|
5419
|
+
this.sock = s;
|
|
5420
|
+
resolve8();
|
|
5421
|
+
});
|
|
5422
|
+
});
|
|
5423
|
+
return this.starting;
|
|
5424
|
+
}
|
|
5425
|
+
send(name2, type) {
|
|
5426
|
+
if (!this.sock) return;
|
|
5427
|
+
try {
|
|
5428
|
+
this.sock.send(buildQuery(name2, type, !this.shared), MDNS_PORT, GROUP);
|
|
5429
|
+
} catch {
|
|
5430
|
+
}
|
|
5431
|
+
}
|
|
5432
|
+
/** Asks the LAN for screens now; answers come as `found`. */
|
|
5433
|
+
query() {
|
|
5434
|
+
this.send(service, TYPE.PTR);
|
|
5435
|
+
}
|
|
5436
|
+
onMessage(m) {
|
|
5437
|
+
let recs;
|
|
5438
|
+
try {
|
|
5439
|
+
recs = parseResponse(m);
|
|
5440
|
+
} catch {
|
|
5441
|
+
return;
|
|
5442
|
+
}
|
|
5443
|
+
if (!recs.length) return;
|
|
5444
|
+
const now = Date.now();
|
|
5445
|
+
const touched = /* @__PURE__ */ new Set();
|
|
5446
|
+
for (const r of recs) {
|
|
5447
|
+
if (r.type === TYPE.PTR && r.name === service && r.data.ptr) {
|
|
5448
|
+
const inst = r.data.ptr.toLowerCase();
|
|
5449
|
+
if (!this.instances.has(inst)) this.instances.set(inst, { instance: inst });
|
|
5450
|
+
touched.add(inst);
|
|
5451
|
+
} else if (r.type === TYPE.SRV && r.name.endsWith(`.${service}`)) {
|
|
5452
|
+
const p = this.instances.get(r.name) ?? { instance: r.name };
|
|
5453
|
+
p.srv = r.data.srv;
|
|
5454
|
+
this.instances.set(r.name, p);
|
|
5455
|
+
touched.add(r.name);
|
|
5456
|
+
} else if (r.type === TYPE.TXT && r.name.endsWith(`.${service}`)) {
|
|
5457
|
+
const p = this.instances.get(r.name) ?? { instance: r.name };
|
|
5458
|
+
p.txt = r.data.txt;
|
|
5459
|
+
this.instances.set(r.name, p);
|
|
5460
|
+
touched.add(r.name);
|
|
5461
|
+
} else if (r.type === TYPE.A && r.data.a) {
|
|
5462
|
+
this.hosts.set(r.name, { a: r.data.a, at: now });
|
|
5463
|
+
for (const [k, p] of this.instances) if (p.srv?.target === r.name) touched.add(k);
|
|
5464
|
+
}
|
|
5465
|
+
}
|
|
5466
|
+
for (const k of touched) {
|
|
5467
|
+
const p = this.instances.get(k);
|
|
5468
|
+
if (!p) continue;
|
|
5469
|
+
if (!p.srv || !p.txt) this.send(k, TYPE.ANY);
|
|
5470
|
+
else if (!this.hosts.has(p.srv.target)) this.send(p.srv.target, TYPE.A);
|
|
5471
|
+
const s = this.complete(p, now);
|
|
5472
|
+
if (!s) continue;
|
|
5473
|
+
const before = this.found.get(s.uid);
|
|
5474
|
+
this.found.set(s.uid, s);
|
|
5475
|
+
this.emit("found", s, before);
|
|
5476
|
+
}
|
|
5477
|
+
}
|
|
5478
|
+
complete(p, now) {
|
|
5479
|
+
const t2 = p.txt;
|
|
5480
|
+
if (!t2?.uid || !p.srv) return null;
|
|
5481
|
+
const host = this.hosts.get(p.srv.target);
|
|
5482
|
+
if (!host) return null;
|
|
5483
|
+
const n = (v) => v && /^\d+$/.test(v) ? Number(v) : 0;
|
|
5484
|
+
return { uid: t2.uid, id: t2.id ?? "", model: t2.model ?? "", w: n(t2.w), h: n(t2.h), rot: n(t2.rot), fw: t2.fw ?? "", proto: n(t2.proto), paired: t2.paired === "1", address: host.a, port: p.srv.port, hostname: p.srv.target, seenAt: now };
|
|
5485
|
+
}
|
|
5486
|
+
/** The screen with this uid, if heard of in the last `maxAgeMs`. */
|
|
5487
|
+
get(uid, maxAgeMs = 30 * 6e4) {
|
|
5488
|
+
const s = this.found.get(uid);
|
|
5489
|
+
return s && Date.now() - s.seenAt <= maxAgeMs ? s : void 0;
|
|
5490
|
+
}
|
|
5491
|
+
/** Screens heard of recently. */
|
|
5492
|
+
list(maxAgeMs = 10 * 6e4) {
|
|
5493
|
+
const now = Date.now();
|
|
5494
|
+
return [...this.found.values()].filter((s) => now - s.seenAt <= maxAgeMs).sort((a, b) => a.id.localeCompare(b.id));
|
|
5495
|
+
}
|
|
5496
|
+
/** Asks, waits `ms` for answers, and gives what it heard in that time (and before). */
|
|
5497
|
+
async browse(ms = 1500) {
|
|
5498
|
+
await this.start();
|
|
5499
|
+
const since = Date.now();
|
|
5500
|
+
this.query();
|
|
5501
|
+
await new Promise((r) => setTimeout(r, ms / 2));
|
|
5502
|
+
this.query();
|
|
5503
|
+
await new Promise((r) => setTimeout(r, ms / 2));
|
|
5504
|
+
return this.list().filter((s) => s.seenAt >= since - 6e4);
|
|
5505
|
+
}
|
|
5506
|
+
/** A remote screen holds it: asks again every minute while someone does. */
|
|
5507
|
+
retain() {
|
|
5508
|
+
this.users++;
|
|
5509
|
+
void this.start().then(() => this.query());
|
|
5510
|
+
if (!this.timer) {
|
|
5511
|
+
this.timer = setInterval(() => this.query(), 6e4);
|
|
5512
|
+
this.timer.unref();
|
|
5513
|
+
}
|
|
5514
|
+
}
|
|
5515
|
+
release() {
|
|
5516
|
+
if (--this.users > 0) return;
|
|
5517
|
+
this.users = 0;
|
|
5518
|
+
if (this.timer) clearInterval(this.timer);
|
|
5519
|
+
this.timer = null;
|
|
5520
|
+
}
|
|
5521
|
+
close() {
|
|
5522
|
+
this.release();
|
|
5523
|
+
this.sock?.close();
|
|
5524
|
+
this.sock = null;
|
|
5525
|
+
this.starting = null;
|
|
5526
|
+
}
|
|
5527
|
+
};
|
|
5528
|
+
var shared = null;
|
|
5529
|
+
function browser() {
|
|
5530
|
+
shared ??= new ScreenBrowser();
|
|
5531
|
+
shared.setMaxListeners(64);
|
|
5532
|
+
return shared;
|
|
5533
|
+
}
|
|
5534
|
+
|
|
5535
|
+
// packages/core/src/remote/device.ts
|
|
5536
|
+
var ROTATIONS = [0, 90, 180, 270];
|
|
5537
|
+
var RemoteDevice = class {
|
|
5538
|
+
status;
|
|
5539
|
+
cfg;
|
|
5540
|
+
log;
|
|
5541
|
+
rotate;
|
|
5542
|
+
rotDirty = false;
|
|
5543
|
+
deps;
|
|
5544
|
+
key;
|
|
5545
|
+
mdns;
|
|
5546
|
+
latest = null;
|
|
5547
|
+
latestNum = 0;
|
|
5548
|
+
fresh = false;
|
|
5549
|
+
led = null;
|
|
5550
|
+
ledDirty = false;
|
|
5551
|
+
closed = false;
|
|
5552
|
+
paused = 0;
|
|
5553
|
+
wire = null;
|
|
5554
|
+
failures = 0;
|
|
5555
|
+
lastSay = "";
|
|
5556
|
+
frameTimes = [];
|
|
5557
|
+
running = null;
|
|
5558
|
+
idle = [];
|
|
5559
|
+
connected = false;
|
|
5560
|
+
waiters = /* @__PURE__ */ new Set();
|
|
5561
|
+
onFound = (s) => {
|
|
5562
|
+
if (s.uid === this.cfg.uid) this.notify("found");
|
|
5563
|
+
};
|
|
5564
|
+
constructor(cfg, log, rotate = 0, deps = {}) {
|
|
5565
|
+
this.cfg = cfg;
|
|
5566
|
+
this.log = log;
|
|
5567
|
+
this.rotate = ROTATIONS.includes(rotate) ? rotate : 0;
|
|
5568
|
+
this.deps = { retryMs: 1e3, maxRetryMs: 3e4, pingMs: 5e3, ...deps };
|
|
5569
|
+
this.key = /^[0-9a-f]{64}$/i.test(cfg.key ?? "") ? Buffer.from(cfg.key, "hex") : null;
|
|
5570
|
+
this.mdns = deps.browser ?? browser();
|
|
5571
|
+
this.status = {
|
|
5572
|
+
driver: "remote",
|
|
5573
|
+
ok: false,
|
|
5574
|
+
message: "connecting\u2026",
|
|
5575
|
+
code: "connecting",
|
|
5576
|
+
framesSent: 0,
|
|
5577
|
+
lastSentAt: null,
|
|
5578
|
+
remote: { online: false, id: cfg.id ?? cfg.uid, host: cfg.host ?? null, fw: "", model: "", w: 0, h: 0, rot: this.rotate, fps: 0, rttMs: null, decodeMs: null, lastFrameAt: null, dropped: 0, since: null }
|
|
5579
|
+
};
|
|
5580
|
+
this.mdns.retain();
|
|
5581
|
+
this.mdns.on("found", this.onFound);
|
|
5582
|
+
if (!this.key) this.say(`${this.name()}: not paired yet (pair it in the editor: Screens \u2192 Detect panels)`, false, "remoteNotPaired", { id: this.name() });
|
|
5583
|
+
else this.running = this.run();
|
|
5584
|
+
}
|
|
5585
|
+
name() {
|
|
5586
|
+
return this.status?.remote.id || this.cfg.id || this.cfg.uid;
|
|
5587
|
+
}
|
|
5588
|
+
say(message, ok, code, params) {
|
|
5589
|
+
Object.assign(this.status, { ok, message, code, params });
|
|
5590
|
+
if (code !== this.lastSay) {
|
|
5591
|
+
this.lastSay = code;
|
|
5592
|
+
this.log(message);
|
|
5593
|
+
}
|
|
5594
|
+
}
|
|
5595
|
+
notify(why2) {
|
|
5596
|
+
for (const w of [...this.waiters]) w(why2);
|
|
5597
|
+
}
|
|
5598
|
+
/** Waits up to `ms` for one of `on` (or close). */
|
|
5599
|
+
wait(ms, on) {
|
|
5600
|
+
return new Promise((resolve8) => {
|
|
5601
|
+
const done2 = (why2) => {
|
|
5602
|
+
clearTimeout(t2);
|
|
5603
|
+
this.waiters.delete(hook);
|
|
5604
|
+
resolve8(why2);
|
|
5605
|
+
};
|
|
5606
|
+
const hook = (why2) => {
|
|
5607
|
+
if (why2 === "close" || on.includes(why2)) done2(why2);
|
|
5608
|
+
};
|
|
5609
|
+
const t2 = setTimeout(() => done2("time"), Math.max(0, ms));
|
|
5610
|
+
this.waiters.add(hook);
|
|
5611
|
+
if (this.closed) done2("close");
|
|
5612
|
+
});
|
|
5613
|
+
}
|
|
5614
|
+
/** JPEG of the logical (unrotated) picture: the screen turns it. Returns at once. */
|
|
5615
|
+
async send(frame) {
|
|
5616
|
+
if (this.latest && this.fresh) this.status.remote.dropped++;
|
|
5617
|
+
this.latest = frame;
|
|
5618
|
+
this.latestNum = this.latestNum + 1 >>> 0;
|
|
5619
|
+
this.fresh = true;
|
|
5620
|
+
this.notify("frame");
|
|
5621
|
+
}
|
|
5622
|
+
/** The screen's rotation changed in Kiosko's config: the screen turns at once (and on every reconnection). */
|
|
5623
|
+
setRotation(rotate) {
|
|
5624
|
+
const r = ROTATIONS.includes(rotate) ? rotate : 0;
|
|
5625
|
+
if (r === this.rotate) return;
|
|
5626
|
+
this.rotate = r;
|
|
5627
|
+
this.rotDirty = true;
|
|
5628
|
+
this.notify("frame");
|
|
5629
|
+
}
|
|
5630
|
+
/** Lights the screen's LED (`rgb` "rrggbb", "000000" off), e.g. for a full-screen alert. */
|
|
5631
|
+
setLed(rgb, blinkMs = 0) {
|
|
5632
|
+
const next = { rgb: /^[0-9a-f]{6}$/i.test(rgb) ? rgb.toLowerCase() : "000000", blink: Math.max(0, Math.round(blinkMs)) };
|
|
5633
|
+
if (this.led && this.led.rgb === next.rgb && this.led.blink === next.blink) return;
|
|
5634
|
+
this.led = next;
|
|
5635
|
+
this.ledDirty = true;
|
|
5636
|
+
this.notify("frame");
|
|
5637
|
+
}
|
|
5638
|
+
close() {
|
|
5639
|
+
if (this.closed) return;
|
|
5640
|
+
this.closed = true;
|
|
5641
|
+
this.mdns.off("found", this.onFound);
|
|
5642
|
+
this.mdns.release();
|
|
5643
|
+
this.wire?.close();
|
|
5644
|
+
this.notify("close");
|
|
5645
|
+
}
|
|
5646
|
+
/** Resolves when the loop is done (tests). */
|
|
5647
|
+
async closed_() {
|
|
5648
|
+
await this.running;
|
|
5649
|
+
}
|
|
5650
|
+
where() {
|
|
5651
|
+
if (this.cfg.host) return { host: this.cfg.host, port: this.cfg.port ?? PORT };
|
|
5652
|
+
const f = this.mdns.get(this.cfg.uid);
|
|
5653
|
+
return f ? { host: f.address, port: f.port || PORT } : null;
|
|
5654
|
+
}
|
|
5655
|
+
async run() {
|
|
5656
|
+
while (!this.closed) {
|
|
5657
|
+
if (this.paused) {
|
|
5658
|
+
for (const f of this.idle.splice(0)) f();
|
|
5659
|
+
await this.wait(6e4, ["resume"]);
|
|
5660
|
+
continue;
|
|
5661
|
+
}
|
|
5662
|
+
const at = this.where();
|
|
5663
|
+
if (!at) {
|
|
5664
|
+
this.offline(`${this.name()} is not on the network (no mDNS announcement yet)`, "remoteOffline");
|
|
5665
|
+
this.mdns.query();
|
|
5666
|
+
await this.backoff();
|
|
5667
|
+
continue;
|
|
5668
|
+
}
|
|
5669
|
+
let conn;
|
|
5670
|
+
try {
|
|
5671
|
+
conn = await (this.deps.open ?? openSession)(at.host, at.port, this.key, this.cfg.uid);
|
|
5672
|
+
} catch (err) {
|
|
5673
|
+
this.failed(err, at.host);
|
|
5674
|
+
await this.backoff(err);
|
|
5675
|
+
continue;
|
|
5676
|
+
}
|
|
5677
|
+
this.failures = 0;
|
|
5678
|
+
this.connected = true;
|
|
5679
|
+
try {
|
|
5680
|
+
await this.serve(conn, at.host);
|
|
5681
|
+
} catch (err) {
|
|
5682
|
+
if (!this.closed && !this.paused) this.failed(err, at.host);
|
|
5683
|
+
} finally {
|
|
5684
|
+
conn.wire.close();
|
|
5685
|
+
this.wire = null;
|
|
5686
|
+
this.connected = false;
|
|
5687
|
+
this.status.remote.online = false;
|
|
5688
|
+
this.status.remote.fps = 0;
|
|
5689
|
+
}
|
|
5690
|
+
if (!this.closed && !this.paused) await this.backoff();
|
|
5691
|
+
}
|
|
5692
|
+
for (const f of this.idle.splice(0)) f();
|
|
5693
|
+
}
|
|
5694
|
+
failed(err, host) {
|
|
5695
|
+
const e = err;
|
|
5696
|
+
const why2 = e?.message ?? String(err);
|
|
5697
|
+
if (err instanceof ScreenError && (e.code === "badKey" || e.code === "notPaired")) this.offline(`${this.name()} refuses this Kiosko's key: pair it again`, "remoteBadKey");
|
|
5698
|
+
else if (err instanceof ScreenError && e.code === "otherScreen") this.offline(`${host}: ${why2}`, "remoteOtherScreen", { host });
|
|
5699
|
+
else if (err instanceof ScreenError && e.code === "busy") this.offline(`${this.name()} is busy (updating?)`, "remoteBusy");
|
|
5700
|
+
else if (err instanceof ScreenError && e.code === "proto") this.offline(why2, "remoteProto", { why: why2 });
|
|
5701
|
+
else this.offline(`${this.name()} is offline (${why2})`, "remoteOffline");
|
|
5702
|
+
}
|
|
5703
|
+
offline(message, code, params = {}) {
|
|
5704
|
+
this.status.remote.online = false;
|
|
5705
|
+
this.status.remote.since = null;
|
|
5706
|
+
this.say(message, false, code, { id: this.name(), ...params });
|
|
5707
|
+
}
|
|
5708
|
+
/** A growing pause (with a little jitter); the screen announcing itself cuts it short. */
|
|
5709
|
+
async backoff(err) {
|
|
5710
|
+
this.failures++;
|
|
5711
|
+
const hopeless = err instanceof ScreenError && ["badKey", "notPaired", "proto"].includes(err.code);
|
|
5712
|
+
const base3 = hopeless ? 6e4 : Math.min(this.deps.maxRetryMs, this.deps.retryMs * 2 ** Math.min(this.failures - 1, 8));
|
|
5713
|
+
await this.wait(Math.round(base3 * (0.85 + Math.random() * 0.3)), ["found", "resume", "pause"]);
|
|
5714
|
+
}
|
|
5715
|
+
async serve(conn, host) {
|
|
5716
|
+
const { wire, info, session: session2 } = conn;
|
|
5717
|
+
this.wire = wire;
|
|
5718
|
+
const r = this.status.remote;
|
|
5719
|
+
Object.assign(r, { id: info.id || r.id, fw: info.fw, model: info.model, w: info.w, h: info.h, rot: info.rot, host, since: Date.now() });
|
|
5720
|
+
const st = await nextSealed(wire, session2);
|
|
5721
|
+
if (st.type !== T.STATE) throw new Error("the screen did not say its state");
|
|
5722
|
+
this.applyState(st.json());
|
|
5723
|
+
const extra = this.deps.settings?.() ?? {};
|
|
5724
|
+
sendSealed(wire, session2, T.SET, { rot: this.rotate, ...extra });
|
|
5725
|
+
this.rotDirty = false;
|
|
5726
|
+
this.ledDirty = !!this.led;
|
|
5727
|
+
this.fresh = !!this.latest;
|
|
5728
|
+
r.online = true;
|
|
5729
|
+
this.say(`${r.id}: online at ${host} (${info.model} ${info.fw})`, true, "remoteOnline", { id: r.id, host });
|
|
5730
|
+
let inflight = null;
|
|
5731
|
+
let lastTx = Date.now();
|
|
5732
|
+
let lastRx = Date.now();
|
|
5733
|
+
let reply = null;
|
|
5734
|
+
while (!this.closed && !wire.closed && !this.paused) {
|
|
5735
|
+
if (this.rotDirty) {
|
|
5736
|
+
this.rotDirty = false;
|
|
5737
|
+
sendSealed(wire, session2, T.SET, { rot: this.rotate });
|
|
5738
|
+
lastTx = Date.now();
|
|
5739
|
+
}
|
|
5740
|
+
if (this.ledDirty && this.led) {
|
|
5741
|
+
this.ledDirty = false;
|
|
5742
|
+
sendSealed(wire, session2, T.LED, this.led);
|
|
5743
|
+
lastTx = Date.now();
|
|
5744
|
+
}
|
|
5745
|
+
if (!inflight && this.fresh && this.latest) {
|
|
5746
|
+
const frame = this.latest;
|
|
5747
|
+
if (frame.length + 64 > info.max) {
|
|
5748
|
+
this.fresh = false;
|
|
5749
|
+
this.say(`${r.id}: a ${Math.round(frame.length / 1024)} KB frame is over the screen's ${Math.round(info.max / 1024)} KB: lower the JPEG quality`, true, "remoteTooBig", { id: r.id, kb: Math.round(frame.length / 1024), max: Math.round(info.max / 1024) });
|
|
5750
|
+
} else {
|
|
5751
|
+
this.fresh = false;
|
|
5752
|
+
const num = this.latestNum;
|
|
5753
|
+
const head = Buffer.alloc(4);
|
|
5754
|
+
head.writeUInt32BE(num);
|
|
5755
|
+
sendSealed(wire, session2, T.FRAME, Buffer.concat([head, frame]));
|
|
5756
|
+
inflight = { num, at: Date.now() };
|
|
5757
|
+
lastTx = inflight.at;
|
|
5758
|
+
}
|
|
5759
|
+
}
|
|
5760
|
+
if (Date.now() - lastTx >= this.deps.pingMs) {
|
|
5761
|
+
sendSealed(wire, session2, T.PING, {});
|
|
5762
|
+
lastTx = Date.now();
|
|
5763
|
+
}
|
|
5764
|
+
if (Date.now() - lastRx > 3 * this.deps.pingMs + 1e3) throw Object.assign(new Error("the screen stopped answering"), { code: "ETIMEDOUT" });
|
|
5765
|
+
reply ??= nextSealed(wire, session2, 3 * this.deps.pingMs + 1e3);
|
|
5766
|
+
const waitMs = Math.max(10, this.deps.pingMs - (Date.now() - lastTx));
|
|
5767
|
+
const got = await Promise.race([reply.then((m2) => ({ m: m2 })), this.wait(waitMs, inflight ? ["pause"] : ["frame", "pause"]).then(() => null)]);
|
|
5768
|
+
if (this.paused) return;
|
|
5769
|
+
if (!got) continue;
|
|
5770
|
+
reply = null;
|
|
5771
|
+
lastRx = Date.now();
|
|
5772
|
+
const { m } = got;
|
|
5773
|
+
if (m.type === T.ACK) {
|
|
5774
|
+
const a = m.json();
|
|
5775
|
+
if (inflight && a.n === inflight.num) {
|
|
5776
|
+
const now = Date.now();
|
|
5777
|
+
r.rttMs = now - inflight.at;
|
|
5778
|
+
r.decodeMs = typeof a.dec === "number" ? a.dec : null;
|
|
5779
|
+
if (a.ok !== false) {
|
|
5780
|
+
this.status.framesSent++;
|
|
5781
|
+
this.status.lastSentAt = now;
|
|
5782
|
+
r.lastFrameAt = now;
|
|
5783
|
+
this.frameTimes.push(now);
|
|
5784
|
+
while (this.frameTimes.length && now - this.frameTimes[0] > 5e3) this.frameTimes.shift();
|
|
5785
|
+
r.fps = this.frameTimes.length > 1 ? Math.round((this.frameTimes.length - 1) * 1e4 / (now - this.frameTimes[0])) / 10 : 0;
|
|
5786
|
+
} else this.log(`${r.id}: the screen could not show frame ${a.n}`);
|
|
5787
|
+
inflight = null;
|
|
5788
|
+
}
|
|
5789
|
+
} else if (m.type === T.STATE) {
|
|
5790
|
+
const j = m.json();
|
|
5791
|
+
this.applyState(j);
|
|
5792
|
+
if (j.resend === true && this.latest) this.fresh = true;
|
|
5793
|
+
} else if (m.type === T.PING) {
|
|
5794
|
+
sendSealed(wire, session2, T.PONG, {});
|
|
5795
|
+
}
|
|
5796
|
+
}
|
|
5797
|
+
}
|
|
5798
|
+
applyState(j) {
|
|
5799
|
+
const r = this.status.remote;
|
|
5800
|
+
if (typeof j.id === "string" && j.id) r.id = j.id;
|
|
5801
|
+
if (typeof j.rot === "number") r.rot = j.rot;
|
|
5802
|
+
if (typeof j.fw === "string") r.fw = j.fw;
|
|
5803
|
+
if (typeof j.w === "number") r.w = j.w;
|
|
5804
|
+
if (typeof j.h === "number") r.h = j.h;
|
|
5805
|
+
}
|
|
5806
|
+
/**
|
|
5807
|
+
* Runs `fn` while this driver stands aside: its session is closed and it
|
|
5808
|
+
* doesn't reconnect until `fn` is done (an update, the logs, unpairing open
|
|
5809
|
+
* their own session; the screen takes one at a time).
|
|
5810
|
+
*/
|
|
5811
|
+
async exclusive(fn) {
|
|
5812
|
+
const at = this.where();
|
|
5813
|
+
if (!at) throw new ScreenError("offline", `${this.name()} is not on the network`);
|
|
5814
|
+
this.paused++;
|
|
5815
|
+
try {
|
|
5816
|
+
if (this.running) {
|
|
5817
|
+
const idle2 = new Promise((r) => this.idle.push(r));
|
|
5818
|
+
this.wire?.close();
|
|
5819
|
+
this.notify("pause");
|
|
5820
|
+
await idle2;
|
|
5821
|
+
}
|
|
5822
|
+
return await fn(at.host, at.port);
|
|
5823
|
+
} finally {
|
|
5824
|
+
this.paused--;
|
|
5825
|
+
this.notify("resume");
|
|
5826
|
+
}
|
|
5827
|
+
}
|
|
5828
|
+
get isConnected() {
|
|
5829
|
+
return this.connected;
|
|
5830
|
+
}
|
|
5831
|
+
};
|
|
5832
|
+
|
|
4822
5833
|
// packages/core/src/devices.ts
|
|
4823
5834
|
function coded(message, code, params) {
|
|
4824
5835
|
return Object.assign(new Error(message), { code, params });
|
|
@@ -4834,7 +5845,7 @@ function statusOfError(err) {
|
|
|
4834
5845
|
}
|
|
4835
5846
|
function encodeFor(device, jpegQuality) {
|
|
4836
5847
|
if (device.driver === "file") return device.format ?? "jpeg";
|
|
4837
|
-
if (device.driver === "usb") return "jpeg";
|
|
5848
|
+
if (device.driver === "usb" || device.driver === "remote") return "jpeg";
|
|
4838
5849
|
return jpegQuality > 0 ? "jpeg" : "png";
|
|
4839
5850
|
}
|
|
4840
5851
|
var VirtualDevice = class {
|
|
@@ -5060,8 +6071,10 @@ async function discoverUsb() {
|
|
|
5060
6071
|
return [];
|
|
5061
6072
|
}
|
|
5062
6073
|
}
|
|
5063
|
-
function openDevice(cfg, log, rotate) {
|
|
6074
|
+
function openDevice(cfg, log, rotate, remote) {
|
|
5064
6075
|
switch (cfg.driver) {
|
|
6076
|
+
case "remote":
|
|
6077
|
+
return new RemoteDevice(cfg, log, rotate ?? 0, remote);
|
|
5065
6078
|
case "trcc":
|
|
5066
6079
|
return new TrccDevice(cfg, log);
|
|
5067
6080
|
case "usb":
|
|
@@ -5082,6 +6095,73 @@ async function discoverTrcc(url2 = "http://127.0.0.1:8099", tokenFile) {
|
|
|
5082
6095
|
return [];
|
|
5083
6096
|
}
|
|
5084
6097
|
}
|
|
6098
|
+
async function discoverRemote(ms = 1500) {
|
|
6099
|
+
try {
|
|
6100
|
+
const found = await browser().browse(ms);
|
|
6101
|
+
return found.map((f) => ({ uid: f.uid, id: f.id, model: f.model, width: f.w, height: f.h, rotate: f.rot, fw: f.fw, paired: f.paired, address: f.address, port: f.port, hostname: f.hostname }));
|
|
6102
|
+
} catch {
|
|
6103
|
+
return [];
|
|
6104
|
+
}
|
|
6105
|
+
}
|
|
6106
|
+
function ledFor(level) {
|
|
6107
|
+
if (level === "critical") return ["ff0000", 400];
|
|
6108
|
+
if (level === "warn") return ["ffa000", 1e3];
|
|
6109
|
+
if (level === "info") return ["0060ff", 0];
|
|
6110
|
+
return ["000000", 0];
|
|
6111
|
+
}
|
|
6112
|
+
|
|
6113
|
+
// packages/core/src/remote/tz.ts
|
|
6114
|
+
var formats = /* @__PURE__ */ new Map();
|
|
6115
|
+
function offsetMinutes(tz, at) {
|
|
6116
|
+
let f = formats.get(tz);
|
|
6117
|
+
if (!f) formats.set(tz, f = new Intl.DateTimeFormat("en-US", { timeZone: tz, hourCycle: "h23", year: "numeric", month: "numeric", day: "numeric", hour: "numeric", minute: "numeric" }));
|
|
6118
|
+
const p = Object.fromEntries(f.formatToParts(new Date(at)).map((x) => [x.type, x.value]));
|
|
6119
|
+
const local = Date.UTC(Number(p.year), Number(p.month) - 1, Number(p.day), Number(p.hour), Number(p.minute));
|
|
6120
|
+
return Math.round((local - Math.floor(at / 6e4) * 6e4) / 6e4);
|
|
6121
|
+
}
|
|
6122
|
+
var name = (min) => {
|
|
6123
|
+
const s = min < 0 ? "-" : "+";
|
|
6124
|
+
const a = Math.abs(min);
|
|
6125
|
+
return `<${s}${String(Math.floor(a / 60)).padStart(2, "0")}${a % 60 ? String(a % 60).padStart(2, "0") : ""}>`;
|
|
6126
|
+
};
|
|
6127
|
+
var off = (min) => {
|
|
6128
|
+
const a = Math.abs(min);
|
|
6129
|
+
return `${min > 0 ? "-" : ""}${Math.floor(a / 60)}${a % 60 ? `:${String(a % 60).padStart(2, "0")}` : ""}`;
|
|
6130
|
+
};
|
|
6131
|
+
function rule(localMs) {
|
|
6132
|
+
const d = new Date(localMs);
|
|
6133
|
+
const day = d.getUTCDate();
|
|
6134
|
+
const days = new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth() + 1, 0)).getUTCDate();
|
|
6135
|
+
const week = day + 7 > days ? 5 : Math.ceil(day / 7);
|
|
6136
|
+
const mins = d.getUTCHours() * 60 + d.getUTCMinutes();
|
|
6137
|
+
return `M${d.getUTCMonth() + 1}.${week}.${d.getUTCDay()}${mins === 120 ? "" : `/${Math.floor(mins / 60)}${mins % 60 ? `:${String(mins % 60).padStart(2, "0")}` : ""}`}`;
|
|
6138
|
+
}
|
|
6139
|
+
function posixTz(tz = Intl.DateTimeFormat().resolvedOptions().timeZone, year = (/* @__PURE__ */ new Date()).getUTCFullYear()) {
|
|
6140
|
+
try {
|
|
6141
|
+
const start = Date.UTC(year, 0, 1);
|
|
6142
|
+
const changes = [];
|
|
6143
|
+
let prev = offsetMinutes(tz, start);
|
|
6144
|
+
const DAY = 864e5;
|
|
6145
|
+
for (let t2 = start + DAY; t2 <= Date.UTC(year + 1, 0, 1); t2 += DAY) {
|
|
6146
|
+
const o = offsetMinutes(tz, t2);
|
|
6147
|
+
if (o === prev) continue;
|
|
6148
|
+
let lo = t2 - DAY, hi = t2;
|
|
6149
|
+
while (hi - lo > 6e4) {
|
|
6150
|
+
const mid = Math.floor((lo + hi) / 12e4) * 6e4;
|
|
6151
|
+
if (offsetMinutes(tz, mid) === prev) lo = mid;
|
|
6152
|
+
else hi = mid;
|
|
6153
|
+
}
|
|
6154
|
+
changes.push({ at: hi, from: prev, to: o });
|
|
6155
|
+
prev = o;
|
|
6156
|
+
}
|
|
6157
|
+
if (changes.length !== 2) return `${name(prev)}${off(prev)}`;
|
|
6158
|
+
const on = changes.find((c) => c.to > c.from), offc = changes.find((c) => c.to < c.from);
|
|
6159
|
+
const std = on.from, dst = on.to;
|
|
6160
|
+
return `${name(std)}${off(std)}${name(dst)}${dst - std === 60 ? "" : off(dst)},${rule(on.at + std * 6e4)},${rule(offc.at + dst * 6e4)}`;
|
|
6161
|
+
} catch {
|
|
6162
|
+
return "UTC0";
|
|
6163
|
+
}
|
|
6164
|
+
}
|
|
5085
6165
|
|
|
5086
6166
|
// packages/core/src/screen-runner.ts
|
|
5087
6167
|
init_src();
|
|
@@ -5138,11 +6218,11 @@ var ALERT_ICONS = {
|
|
|
5138
6218
|
mail: ["m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7", "M4 4h16a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z"]
|
|
5139
6219
|
};
|
|
5140
6220
|
var paths2 = /* @__PURE__ */ new Map();
|
|
5141
|
-
function iconPaths(
|
|
5142
|
-
const d = ALERT_ICONS[
|
|
6221
|
+
function iconPaths(name2) {
|
|
6222
|
+
const d = ALERT_ICONS[name2];
|
|
5143
6223
|
if (!d) return null;
|
|
5144
|
-
let p = paths2.get(
|
|
5145
|
-
if (!p) paths2.set(
|
|
6224
|
+
let p = paths2.get(name2);
|
|
6225
|
+
if (!p) paths2.set(name2, p = d.map((x) => new Path2D(x)));
|
|
5146
6226
|
return p;
|
|
5147
6227
|
}
|
|
5148
6228
|
function iconFor(a) {
|
|
@@ -5443,7 +6523,7 @@ function paintCard(g, w, h, look) {
|
|
|
5443
6523
|
const chip = Math.max(9, Math.round(k2 * 0.5));
|
|
5444
6524
|
const hint = Math.max(8, Math.round(k2 * 0.34));
|
|
5445
6525
|
const title = wrapLines(g, tx.running, bw, 2, { size: k2, family: bold2 });
|
|
5446
|
-
const
|
|
6526
|
+
const open2 = wrapLines(g, tx.open, bw, 3, { size: body2, family: sans });
|
|
5447
6527
|
const cmd2 = "kiosko editor";
|
|
5448
6528
|
const cmdW = measureTracked(g, cmd2, { size: chip, family: mono }) + chip * 1.1;
|
|
5449
6529
|
const orW = measureTracked(g, tx.or, { size: body2, family: sans });
|
|
@@ -5451,9 +6531,9 @@ function paintCard(g, w, h, look) {
|
|
|
5451
6531
|
const oneLine2 = cmdW + body2 * 0.6 + orW + body2 * 0.6 + urlW <= bw;
|
|
5452
6532
|
const hints = hint >= 10 ? wrapLines(g, tx.hint, bw, 2, { size: hint, family: sans }) : [];
|
|
5453
6533
|
const lineH = (s) => Math.round(s * 1.3);
|
|
5454
|
-
const height = title.length * lineH(k2) + k2 * 0.25 +
|
|
6534
|
+
const height = title.length * lineH(k2) + k2 * 0.25 + open2.length * lineH(body2) + body2 * 0.35 + (oneLine2 ? chip * 1.9 : chip * 1.9 * 2 + lineH(body2)) + hint * 0.6 + hints.length * lineH(hint);
|
|
5455
6535
|
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 };
|
|
6536
|
+
return { k: k2, body: body2, chip, hint, title, open: open2, cmd: cmd2, cmdW, orW, urlW, oneLine: oneLine2, hints, height, fits, lineH };
|
|
5457
6537
|
};
|
|
5458
6538
|
let k = Math.round(shape === "wide" ? h * 0.17 : shape === "tall" ? w * 0.12 : Math.min(w * 0.085, h * 0.11));
|
|
5459
6539
|
let L = layout(k);
|
|
@@ -5737,7 +6817,7 @@ var ScreenRunner = class {
|
|
|
5737
6817
|
log: this.rt.log,
|
|
5738
6818
|
demo: this.rt.demoMode,
|
|
5739
6819
|
cache: this.tiles,
|
|
5740
|
-
rotate: screen
|
|
6820
|
+
rotate: paintTurn(screen)
|
|
5741
6821
|
});
|
|
5742
6822
|
canvas = result.canvas;
|
|
5743
6823
|
this.animatable = result.animatable;
|
|
@@ -5748,7 +6828,8 @@ var ScreenRunner = class {
|
|
|
5748
6828
|
this.rt.paintTime(t2.shown, type, t2.renderMs, now);
|
|
5749
6829
|
}
|
|
5750
6830
|
} else {
|
|
5751
|
-
const
|
|
6831
|
+
const turn = paintTurn(screen);
|
|
6832
|
+
const swap = turn === 90 || turn === 270;
|
|
5752
6833
|
canvas = CANVAS.createCanvas(swap ? screen.height : screen.width, swap ? screen.width : screen.height);
|
|
5753
6834
|
this.animatable = [];
|
|
5754
6835
|
this.nextAt = now + 6e4;
|
|
@@ -5764,7 +6845,7 @@ var ScreenRunner = class {
|
|
|
5764
6845
|
}
|
|
5765
6846
|
const kind = encodeFor(screen.device, screen.jpegQuality);
|
|
5766
6847
|
const out = await this.fit(canvas, kind, screen.jpegQuality, screen, performance.now() - t0);
|
|
5767
|
-
this.lastInfo = { screenId: screen.id, pageId: page?.id ?? null, at: now, image: lazyJpeg(canvas, screen
|
|
6848
|
+
this.lastInfo = { screenId: screen.id, pageId: page?.id ?? null, at: now, image: lazyJpeg(canvas, paintTurn(screen)), tiles: result?.tiles ?? [], interlude: null, sleeping };
|
|
5768
6849
|
this.rt.frame(this.lastInfo);
|
|
5769
6850
|
if (this.last?.equals(out)) return;
|
|
5770
6851
|
this.last = out;
|
|
@@ -5793,7 +6874,7 @@ var ScreenRunner = class {
|
|
|
5793
6874
|
const canvas = CANVAS.createCanvas(screen.width, screen.height);
|
|
5794
6875
|
paintAlert(canvas.getContext("2d"), screen.width, screen.height, shown, { intensity, fonts: this.rt.theme().fonts, minPx, sinceText, shift });
|
|
5795
6876
|
const kind = encodeFor(screen.device, screen.jpegQuality || 85);
|
|
5796
|
-
const turned = rotateCanvas(canvas, screen
|
|
6877
|
+
const turned = rotateCanvas(canvas, paintTurn(screen));
|
|
5797
6878
|
const out = await this.fit(turned, kind, screen.jpegQuality || 85, screen, performance.now() - t0);
|
|
5798
6879
|
this.lastInfo = { screenId: screen.id, pageId: this.page?.id ?? null, at: now, image: lazyJpeg(canvas), tiles: [], interlude: null, alert: a.id, sleeping: false };
|
|
5799
6880
|
this.rt.frame(this.lastInfo);
|
|
@@ -5859,7 +6940,7 @@ var ScreenRunner = class {
|
|
|
5859
6940
|
g.save();
|
|
5860
6941
|
paintBoot(g, screen.width, screen.height, ms, look);
|
|
5861
6942
|
g.restore();
|
|
5862
|
-
const out = await this.fit(rotateCanvas(canvas, screen
|
|
6943
|
+
const out = await this.fit(rotateCanvas(canvas, paintTurn(screen)), kind, screen.jpegQuality || 85, screen, performance.now() - t0);
|
|
5863
6944
|
await this.send(out);
|
|
5864
6945
|
if (i % 4 === 0) {
|
|
5865
6946
|
const snap = CANVAS.createCanvas(canvas.width, canvas.height);
|
|
@@ -5884,7 +6965,7 @@ var ScreenRunner = class {
|
|
|
5884
6965
|
const canvas = CANVAS.createCanvas(screen.width, screen.height);
|
|
5885
6966
|
paintCard(canvas.getContext("2d"), screen.width, screen.height, look);
|
|
5886
6967
|
const kind = encodeFor(screen.device, screen.jpegQuality || 85);
|
|
5887
|
-
const out = await this.fit(rotateCanvas(canvas, screen
|
|
6968
|
+
const out = await this.fit(rotateCanvas(canvas, paintTurn(screen)), kind, screen.jpegQuality || 85, screen, performance.now() - t0);
|
|
5888
6969
|
this.lastInfo = { screenId: screen.id, pageId: this.page?.id ?? null, at: now, image: lazyJpeg(canvas), tiles: [], interlude: "kiosko/welcome", sleeping: false };
|
|
5889
6970
|
this.rt.frame(this.lastInfo);
|
|
5890
6971
|
this.last = out;
|
|
@@ -5960,7 +7041,7 @@ var ScreenRunner = class {
|
|
|
5960
7041
|
} finally {
|
|
5961
7042
|
g.restore();
|
|
5962
7043
|
}
|
|
5963
|
-
const turned = rotateCanvas(canvas, this.screen
|
|
7044
|
+
const turned = rotateCanvas(canvas, paintTurn(this.screen));
|
|
5964
7045
|
const out = await this.fit(turned, kind, this.screen.jpegQuality || 85, this.screen, performance.now() - t0);
|
|
5965
7046
|
await this.send(out);
|
|
5966
7047
|
if (i % 3 === 0) {
|
|
@@ -6058,7 +7139,7 @@ var ScreenRunner = class {
|
|
|
6058
7139
|
demo: this.rt.demoMode,
|
|
6059
7140
|
cache: this.tiles,
|
|
6060
7141
|
animate,
|
|
6061
|
-
rotate: screen
|
|
7142
|
+
rotate: paintTurn(screen)
|
|
6062
7143
|
});
|
|
6063
7144
|
sent.push({ out: this.fit(result.canvas, kind, screen.jpegQuality || 85, screen, performance.now() - t02), snap: s % 3 === 1 ? result.canvas : null });
|
|
6064
7145
|
await new Promise((r) => setImmediate(r));
|
|
@@ -6075,7 +7156,7 @@ var ScreenRunner = class {
|
|
|
6075
7156
|
await this.send(outs[k]);
|
|
6076
7157
|
const snap = sent[k].snap;
|
|
6077
7158
|
if (snap) {
|
|
6078
|
-
this.lastInfo = { screenId: screen.id, pageId: page.id, at: Date.now(), image: lazyJpeg(snap, screen
|
|
7159
|
+
this.lastInfo = { screenId: screen.id, pageId: page.id, at: Date.now(), image: lazyJpeg(snap, paintTurn(screen)), tiles: [], interlude: null, animation: items.map((x) => x.animatable.type).join(", "), sleeping: false };
|
|
6079
7160
|
this.rt.frame(this.lastInfo);
|
|
6080
7161
|
}
|
|
6081
7162
|
if (hold && k === holdAt) {
|
|
@@ -6119,9 +7200,9 @@ var ScreenRunner = class {
|
|
|
6119
7200
|
this.pinned = pageId;
|
|
6120
7201
|
this.dirty = true;
|
|
6121
7202
|
}
|
|
6122
|
-
setOff(
|
|
6123
|
-
this.off =
|
|
6124
|
-
if (
|
|
7203
|
+
setOff(off2) {
|
|
7204
|
+
this.off = off2;
|
|
7205
|
+
if (off2) this.stopInterlude();
|
|
6125
7206
|
this.dirty = true;
|
|
6126
7207
|
}
|
|
6127
7208
|
/** A button from the Play page, for the interlude being played; false when none is. */
|
|
@@ -6176,8 +7257,8 @@ var Unclonable = class extends Error {
|
|
|
6176
7257
|
};
|
|
6177
7258
|
function what(v) {
|
|
6178
7259
|
if (typeof v === "function") return "a function";
|
|
6179
|
-
const
|
|
6180
|
-
return
|
|
7260
|
+
const name2 = Object.getPrototypeOf(v)?.constructor?.name;
|
|
7261
|
+
return name2 ? `a ${name2} (an object of a class)` : "an object of a class";
|
|
6181
7262
|
}
|
|
6182
7263
|
var CLONED_AS_IS = [Date, RegExp, ArrayBuffer, Error, DataView];
|
|
6183
7264
|
function isCanvas(v) {
|
|
@@ -6474,10 +7555,10 @@ var ThreadRunner = class {
|
|
|
6474
7555
|
this.pinned = pageId;
|
|
6475
7556
|
this.post({ t: "pin", page: pageId });
|
|
6476
7557
|
}
|
|
6477
|
-
setOff(
|
|
6478
|
-
this.off =
|
|
6479
|
-
if (
|
|
6480
|
-
this.post({ t: "off", off });
|
|
7558
|
+
setOff(off2) {
|
|
7559
|
+
this.off = off2;
|
|
7560
|
+
if (off2) this.state = { ...this.state, interlude: null };
|
|
7561
|
+
this.post({ t: "off", off: off2 });
|
|
6481
7562
|
}
|
|
6482
7563
|
async playNow(slotId, play = false) {
|
|
6483
7564
|
if (this.off || this.alert) return;
|
|
@@ -6537,7 +7618,7 @@ var TEST_ALERT_TEXT = {
|
|
|
6537
7618
|
"zh-Hant": "\u9019\u662F\u8B66\u5831\u5728\u300C{screen}\u300D\u4E0A\u7684\u6A23\u5B50\u3002\u5F9E\u4F60\u7684\u5EA7\u4F4D\u770B\u5F97\u6E05\u695A\u55CE\uFF1F",
|
|
6538
7619
|
"zh-Hans": "\u8FD9\u662F\u8B66\u62A5\u5728\u201C{screen}\u201D\u4E0A\u7684\u6837\u5B50\u3002\u4ECE\u4F60\u7684\u5EA7\u4F4D\u770B\u5F97\u6E05\u5417\uFF1F"
|
|
6539
7620
|
};
|
|
6540
|
-
var Runtime = class extends
|
|
7621
|
+
var Runtime = class extends EventEmitter2 {
|
|
6541
7622
|
config;
|
|
6542
7623
|
hub;
|
|
6543
7624
|
fetches;
|
|
@@ -6626,7 +7707,7 @@ var Runtime = class extends EventEmitter {
|
|
|
6626
7707
|
this.refreshWanted();
|
|
6627
7708
|
}
|
|
6628
7709
|
openDevice(screen, log) {
|
|
6629
|
-
return openDevice(screen.device, log, screen.rotate);
|
|
7710
|
+
return openDevice(screen.device, log, screen.rotate, { settings: () => ({ lang: resolveLocale(this.config).slice(0, 5), tz: posixTz() }) });
|
|
6630
7711
|
}
|
|
6631
7712
|
onData(change) {
|
|
6632
7713
|
this.alertsDirty = true;
|
|
@@ -6700,6 +7781,7 @@ var Runtime = class extends EventEmitter {
|
|
|
6700
7781
|
this.runners.get(s.id)?.reconfigure(s);
|
|
6701
7782
|
}
|
|
6702
7783
|
this.placeRunners();
|
|
7784
|
+
for (const s of config2.screens) this.runners.get(s.id)?.device.setRotation?.(s.rotate);
|
|
6703
7785
|
this.refreshWanted();
|
|
6704
7786
|
this.emit("config", config2);
|
|
6705
7787
|
}
|
|
@@ -6736,6 +7818,10 @@ var Runtime = class extends EventEmitter {
|
|
|
6736
7818
|
}
|
|
6737
7819
|
return r;
|
|
6738
7820
|
}
|
|
7821
|
+
/** The device a screen sends to now (its remote screen, for pairing, updates, logs). */
|
|
7822
|
+
deviceOf(screenId) {
|
|
7823
|
+
return this.runners.get(screenId)?.device;
|
|
7824
|
+
}
|
|
6739
7825
|
threadFailed(screenId, reason) {
|
|
6740
7826
|
const s = this.config.screens.find((x) => x.id === screenId);
|
|
6741
7827
|
const r = this.runners.get(screenId);
|
|
@@ -6784,11 +7870,11 @@ var Runtime = class extends EventEmitter {
|
|
|
6784
7870
|
this.runners.get(screenId)?.stopInterlude();
|
|
6785
7871
|
}
|
|
6786
7872
|
/** Switches a screen's picture off (black) or back on, until the next restart. */
|
|
6787
|
-
setOff(screenId,
|
|
7873
|
+
setOff(screenId, off2) {
|
|
6788
7874
|
const r = this.runners.get(screenId);
|
|
6789
|
-
if (!r || r.off ===
|
|
6790
|
-
r.setOff(
|
|
6791
|
-
this.emit("screen", { screenId, off });
|
|
7875
|
+
if (!r || r.off === off2) return;
|
|
7876
|
+
r.setOff(off2);
|
|
7877
|
+
this.emit("screen", { screenId, off: off2 });
|
|
6792
7878
|
}
|
|
6793
7879
|
refreshWidget(instanceId) {
|
|
6794
7880
|
this.fetches.refresh(instanceId);
|
|
@@ -6838,7 +7924,11 @@ var Runtime = class extends EventEmitter {
|
|
|
6838
7924
|
refreshAlerts(now = Date.now()) {
|
|
6839
7925
|
this.alerts.prune(now);
|
|
6840
7926
|
const list2 = this.alerts.list(now);
|
|
6841
|
-
for (const r of this.runners.values())
|
|
7927
|
+
for (const r of this.runners.values()) {
|
|
7928
|
+
const shown = r.screen.enabled ? this.alerts.forScreen(r.screen, now, r.off) : null;
|
|
7929
|
+
r.setAlert(shown, now);
|
|
7930
|
+
r.device.setLed?.(...ledFor(shown?.top.level ?? null));
|
|
7931
|
+
}
|
|
6842
7932
|
const sig = JSON.stringify(list2);
|
|
6843
7933
|
if (sig === this.alertsSig) return;
|
|
6844
7934
|
this.alertsSig = sig;
|
|
@@ -6849,9 +7939,9 @@ var Runtime = class extends EventEmitter {
|
|
|
6849
7939
|
return this.alerts.list(now);
|
|
6850
7940
|
}
|
|
6851
7941
|
/** An alert from outside (`POST /api/alerts`); throws `AlertError` if it is not one. */
|
|
6852
|
-
postAlert(
|
|
7942
|
+
postAlert(raw2) {
|
|
6853
7943
|
const now = Date.now();
|
|
6854
|
-
const a = this.alerts.post(
|
|
7944
|
+
const a = this.alerts.post(raw2, now, resolveLocale(this.config), this.config.screens.map((s) => s.id));
|
|
6855
7945
|
this.log("alerts", `${a.level}: ${a.title} (${a.id})`);
|
|
6856
7946
|
this.refreshAlerts(now);
|
|
6857
7947
|
return a;
|
|
@@ -7166,14 +8256,14 @@ function installSdkResolver() {
|
|
|
7166
8256
|
if (installed) return;
|
|
7167
8257
|
installed = true;
|
|
7168
8258
|
const urls = /* @__PURE__ */ new Map();
|
|
7169
|
-
for (const
|
|
7170
|
-
const local = BUNDLED[
|
|
8259
|
+
for (const name2 of SHARED) {
|
|
8260
|
+
const local = BUNDLED[name2] ? join5(import.meta.dirname, BUNDLED[name2]) : null;
|
|
7171
8261
|
if (local && existsSync5(local)) {
|
|
7172
|
-
urls.set(
|
|
8262
|
+
urls.set(name2, pathToFileURL(local).href);
|
|
7173
8263
|
continue;
|
|
7174
8264
|
}
|
|
7175
8265
|
try {
|
|
7176
|
-
urls.set(
|
|
8266
|
+
urls.set(name2, import.meta.resolve(name2));
|
|
7177
8267
|
} catch {
|
|
7178
8268
|
}
|
|
7179
8269
|
}
|
|
@@ -7339,16 +8429,16 @@ var Registry = class {
|
|
|
7339
8429
|
}
|
|
7340
8430
|
}
|
|
7341
8431
|
const candidates = [];
|
|
7342
|
-
for (const
|
|
7343
|
-
if (
|
|
7344
|
-
candidates.push(join6(dir,
|
|
8432
|
+
for (const name2 of readdirSync3(dir)) {
|
|
8433
|
+
if (name2 === "node_modules" || name2.startsWith(".")) continue;
|
|
8434
|
+
candidates.push(join6(dir, name2));
|
|
7345
8435
|
}
|
|
7346
8436
|
const nm = join6(dir, "node_modules");
|
|
7347
8437
|
if (existsSync6(nm)) {
|
|
7348
|
-
for (const
|
|
7349
|
-
if (
|
|
7350
|
-
for (const sub of readdirSync3(join6(nm,
|
|
7351
|
-
} else if (
|
|
8438
|
+
for (const name2 of readdirSync3(nm)) {
|
|
8439
|
+
if (name2.startsWith("@")) {
|
|
8440
|
+
for (const sub of readdirSync3(join6(nm, name2))) if (sub.startsWith("kiosko-plugin-")) candidates.push(join6(nm, name2, sub));
|
|
8441
|
+
} else if (name2.startsWith("kiosko-plugin-")) candidates.push(join6(nm, name2));
|
|
7352
8442
|
}
|
|
7353
8443
|
}
|
|
7354
8444
|
for (const folder of candidates) await this.loadFolder(folder);
|
|
@@ -7380,15 +8470,15 @@ var Registry = class {
|
|
|
7380
8470
|
}
|
|
7381
8471
|
async loadEntry(entry, origin, version) {
|
|
7382
8472
|
const url2 = pathToFileURL2(entry).href + (version ? `?v=${version}` : "");
|
|
7383
|
-
const
|
|
7384
|
-
if (!
|
|
8473
|
+
const mod2 = await import(url2);
|
|
8474
|
+
if (!mod2.default) {
|
|
7385
8475
|
this.problems.push({ origin, message: "the module has no default export (use `export default definePlugin({...})`)" });
|
|
7386
8476
|
return void 0;
|
|
7387
8477
|
}
|
|
7388
8478
|
const before = this.plugins.size;
|
|
7389
|
-
this.add(
|
|
7390
|
-
if (this.plugins.size > before) this.entries.set(
|
|
7391
|
-
return
|
|
8479
|
+
this.add(mod2.default, origin, url2);
|
|
8480
|
+
if (this.plugins.size > before) this.entries.set(mod2.default.id, { entry, origin });
|
|
8481
|
+
return mod2.default;
|
|
7392
8482
|
}
|
|
7393
8483
|
/**
|
|
7394
8484
|
* The values a source offers for an option (see `SourceDefinition.choices`),
|
|
@@ -7566,34 +8656,34 @@ function* fieldsOf(f, prefix = "") {
|
|
|
7566
8656
|
}
|
|
7567
8657
|
}
|
|
7568
8658
|
var last = (path) => path.split(/[.[\]]+/).filter(Boolean).pop() ?? path;
|
|
7569
|
-
function lintOptions(
|
|
8659
|
+
function lintOptions(where2, f, kind) {
|
|
7570
8660
|
const out = [];
|
|
7571
|
-
const warn = (path, message) => out.push({ level: "warn", where: `${
|
|
7572
|
-
const err = (path, message) => out.push({ level: "error", where: `${
|
|
8661
|
+
const warn = (path, message) => out.push({ level: "warn", where: `${where2} options.${path}`, message });
|
|
8662
|
+
const err = (path, message) => out.push({ level: "error", where: `${where2} options.${path}`, message });
|
|
7573
8663
|
const names = new Set([...fieldsOf(f)].map(([p]) => p));
|
|
7574
8664
|
for (const [path, x] of fieldsOf(f)) {
|
|
7575
|
-
const
|
|
7576
|
-
if (x.kind === "number" && x.unit === "ms" && !/Ms$/.test(
|
|
7577
|
-
if (x.kind === "number" && /Ms$/.test(
|
|
7578
|
-
if (x.kind === "number" && (/(Minutes|Hours|Secs|Seconds)$/.test(
|
|
7579
|
-
if (/(Crit|Critical)$/.test(
|
|
7580
|
-
if (/Warn$/.test(
|
|
7581
|
-
if (/Alert$/.test(
|
|
8665
|
+
const name2 = last(path);
|
|
8666
|
+
if (x.kind === "number" && x.unit === "ms" && !/Ms$/.test(name2)) warn(path, "a duration: name it \u2026Ms (rotateMs, maxAgeMs)");
|
|
8667
|
+
if (x.kind === "number" && /Ms$/.test(name2) && x.unit !== "ms") warn(path, "named \u2026Ms but not a duration: use t.duration()");
|
|
8668
|
+
if (x.kind === "number" && (/(Minutes|Hours|Secs|Seconds)$/.test(name2) || /Mins?$/.test(name2) && (!x.unit || x.unit === "min"))) warn(path, "durations are milliseconds with t.duration() and a name ending in Ms");
|
|
8669
|
+
if (/(Crit|Critical)$/.test(name2)) warn(path, "thresholds are \u2026Warn (amber) and \u2026Alert (red), never \u2026Crit");
|
|
8670
|
+
if (/Warn$/.test(name2) && !names.has(path.replace(/Warn$/, "Alert"))) warn(path, `thresholds come in pairs: add ${name2.replace(/Warn$/, "Alert")}`);
|
|
8671
|
+
if (/Alert$/.test(name2) && !names.has(path.replace(/Alert$/, "Warn"))) warn(path, `thresholds come in pairs: add ${name2.replace(/Alert$/, "Warn")}`);
|
|
7582
8672
|
if (x.kind === "number" && x.unit === "%" && (!x.integer || x.max !== void 0 && x.max > 100 || x.max !== void 0 && x.max <= 1)) warn(path, 'percentages are integers 0\u2013100: t.integer({ min: 0, max: 100, unit: "%" })');
|
|
7583
8673
|
if (x.kind === "number" && x.unit === "\xB0C" && !x.integer) warn(path, "temperatures are integer \xB0C");
|
|
7584
|
-
if (x.kind === "boolean" && /Only$/.test(
|
|
7585
|
-
if (x.kind === "boolean" && ["seconds", "moon", "cores", "date", "title"].includes(
|
|
7586
|
-
if (
|
|
7587
|
-
if (
|
|
7588
|
-
if (kind === "source" && (
|
|
7589
|
-
if (kind === "source" &&
|
|
7590
|
-
if (
|
|
7591
|
-
if ((
|
|
8674
|
+
if (x.kind === "boolean" && /Only$/.test(name2)) warn(path, "no \u2026Only suffix: only<Condition> (onlyLatest)");
|
|
8675
|
+
if (x.kind === "boolean" && ["seconds", "moon", "cores", "date", "title"].includes(name2)) warn(path, `a part shown or hidden is show<Part>: show${name2[0].toUpperCase()}${name2.slice(1)}`);
|
|
8676
|
+
if (name2 === "takeOver") err(path, "takeOver is the instance's switch, not an option: declare `takeOver` on the definition");
|
|
8677
|
+
if (name2 === "hideWhenEmpty") err(path, "hideWhenEmpty is the instance's switch: declare `empty(ctx)` (and `hideWhenEmpty` on the definition)");
|
|
8678
|
+
if (kind === "source" && (name2 === "intervalMs" || name2 === "timeoutMs") && !path.includes(".")) err(path, "refresh and timeout are not options: declare intervalMs / timeoutMs on the source");
|
|
8679
|
+
if (kind === "source" && name2 === "background" && !path.includes(".")) err(path, "running with no widget is not an option: declare `background: true` on the source, and Kiosko gives the user the switch");
|
|
8680
|
+
if (name2 === "max" || name2 === "count") warn(path, "a cap is max<Things> (maxProcesses); a list length is `rows` through listOptions()");
|
|
8681
|
+
if ((name2 === "latitude" || name2 === "longitude") && !(x.kind === "number" && x.advanced)) warn(path, "use ctx.location, with locationOptions() as an advanced override");
|
|
7592
8682
|
if (x.kind === "string") {
|
|
7593
|
-
const looks = x.format === "url" || x.format === "path" || /^(url|host|endpoint|command|cmd|bin|path|dir|file|ssh)$/i.test(
|
|
8683
|
+
const looks = x.format === "url" || x.format === "path" || /^(url|host|endpoint|command|cmd|bin|path|dir|file|ssh)$/i.test(name2) || /(Url|Host|Path|Dir|Command)$/.test(name2);
|
|
7594
8684
|
if (looks && !x.risk && !x.secret) warn(path, "its value contacts a host, runs a program or reads a path: mark it with `risk`");
|
|
7595
8685
|
}
|
|
7596
|
-
if (kind === "widget" && x.kind === "list" && x.item.kind === "string" && !x.filter && /^(repos|projects|calendars|servers|people|outlets|entities|gpus|branches|users)$/.test(
|
|
8686
|
+
if (kind === "widget" && x.kind === "list" && x.item.kind === "string" && !x.filter && /^(repos|projects|calendars|servers|people|outlets|entities|gpus|branches|users)$/.test(name2)) warn(path, "a list of names to show is a filter: t.filter() with matchFilter");
|
|
7597
8687
|
}
|
|
7598
8688
|
return out;
|
|
7599
8689
|
}
|
|
@@ -7613,53 +8703,53 @@ function knownLanguage(tag) {
|
|
|
7613
8703
|
var bare = (x) => ({ ...x, options: void 0 });
|
|
7614
8704
|
function lintPlugin(def) {
|
|
7615
8705
|
const out = [];
|
|
7616
|
-
const
|
|
7617
|
-
if (!ID2.test(def.id ?? ""))
|
|
7618
|
-
if (!/^\d+\.\d+\.\d+/.test(def.version ?? ""))
|
|
7619
|
-
if (!def.sdk)
|
|
8706
|
+
const add2 = (level, where2, message) => out.push({ level, where: where2, message });
|
|
8707
|
+
if (!ID2.test(def.id ?? "")) add2("error", "plugin", `id ${JSON.stringify(def.id)}: lowercase letters, digits and dashes`);
|
|
8708
|
+
if (!/^\d+\.\d+\.\d+/.test(def.version ?? "")) add2("error", "plugin", `version ${JSON.stringify(def.version)} is not semver`);
|
|
8709
|
+
if (!def.sdk) add2("warn", "plugin", 'say which plugin API it is written for: `sdk: "^0.2.0"` (and `kiosko.sdk` in package.json, so an incompatible Kiosko never runs it)');
|
|
7620
8710
|
const reaches = (def.sources ?? []).length > 0 || (def.widgets ?? []).some((w) => w.fetch);
|
|
7621
|
-
if (reaches && !def.permissions)
|
|
7622
|
-
if (!def.description)
|
|
8711
|
+
if (reaches && !def.permissions) add2("warn", "plugin", "it reads data: declare `permissions` (hosts, programs, files, devices) so people know before installing");
|
|
8712
|
+
if (!def.description) add2("warn", "plugin", "a description, for the Plugins page and the store");
|
|
7623
8713
|
if (def.license) {
|
|
7624
8714
|
try {
|
|
7625
8715
|
const lic = parseLicense(def.license);
|
|
7626
|
-
for (const f of lic.fix)
|
|
7627
|
-
for (const u of lic.unknown)
|
|
8716
|
+
for (const f of lic.fix) add2("warn", "plugin", `license: write "${f.from}" as "${f.to}" (SPDX identifiers are case-sensitive)`);
|
|
8717
|
+
for (const u of lic.unknown) add2("warn", "plugin", `license: "${u}" is not an SPDX identifier Kiosko knows (https://spdx.org/licenses/); the store lists it as "other"`);
|
|
7628
8718
|
} catch (err) {
|
|
7629
|
-
|
|
8719
|
+
add2("error", "plugin", `license ${JSON.stringify(def.license)}: ${err.message}`);
|
|
7630
8720
|
}
|
|
7631
8721
|
}
|
|
7632
8722
|
for (const k of ["only", "without"]) {
|
|
7633
|
-
for (const code of def.markets?.[k] ?? []) if (!isRegion(code))
|
|
8723
|
+
for (const code of def.markets?.[k] ?? []) if (!isRegion(code)) add2("error", "plugin", `markets.${k}: "${code}" is not an ISO 3166-1 alpha-2 country code (ES, TW\u2026) nor EU`);
|
|
7634
8724
|
}
|
|
7635
|
-
if (def.markets?.only?.length && def.markets.without?.length)
|
|
7636
|
-
if (def.pricing && def.pricing.model !== "free")
|
|
7637
|
-
if (def.category && (def.widgets ?? []).length)
|
|
7638
|
-
for (const [k, url2] of [...Object.entries(def.support ?? {}), ["funding", def.funding]]) if (url2 && !/^https:\/\//.test(url2))
|
|
7639
|
-
for (const r of [...def.requires ?? [], ...def.optional ?? []]) if (!/^[a-z0-9][a-z0-9-]*\/[a-zA-Z0-9-]+$/.test(r))
|
|
8725
|
+
if (def.markets?.only?.length && def.markets.without?.length) add2("warn", "plugin", "markets: `only` and `without` together; `only` alone says it");
|
|
8726
|
+
if (def.pricing && def.pricing.model !== "free") add2("error", "plugin", `pricing.model ${JSON.stringify(def.pricing.model)}: only "free" for now (paid plugins are not supported yet)`);
|
|
8727
|
+
if (def.category && (def.widgets ?? []).length) add2("warn", "plugin", "`category` is for plugins without widgets: the store takes the widgets' own");
|
|
8728
|
+
for (const [k, url2] of [...Object.entries(def.support ?? {}), ["funding", def.funding]]) if (url2 && !/^https:\/\//.test(url2)) add2("warn", "plugin", `${k === "funding" ? "funding" : `support.${k}`}: an https:// address`);
|
|
8729
|
+
for (const r of [...def.requires ?? [], ...def.optional ?? []]) if (!/^[a-z0-9][a-z0-9-]*\/[a-zA-Z0-9-]+$/.test(r)) add2("error", "plugin", `requires/optional ${JSON.stringify(r)}: a type, plugin/thing`);
|
|
7640
8730
|
const used = languagesOf(def);
|
|
7641
8731
|
const declared = def.languages;
|
|
7642
|
-
if (!declared?.length)
|
|
8732
|
+
if (!declared?.length) add2("warn", "plugin", `declare the languages its texts come in: \`languages: [${used.map((l) => `'${l}'`).join(", ")}]\` (and "kiosko": { "languages": [...] } in package.json)`);
|
|
7643
8733
|
else {
|
|
7644
8734
|
for (const tag of declared) {
|
|
7645
8735
|
let canon;
|
|
7646
8736
|
try {
|
|
7647
8737
|
canon = Intl.getCanonicalLocales(tag)[0];
|
|
7648
8738
|
} catch {
|
|
7649
|
-
|
|
8739
|
+
add2("error", "plugin", `languages: "${tag}" is not a language tag (en, es, zh-Hant\u2026)`);
|
|
7650
8740
|
continue;
|
|
7651
8741
|
}
|
|
7652
|
-
if (canon !== tag)
|
|
7653
|
-
else if (!knownLanguage(tag))
|
|
8742
|
+
if (canon !== tag) add2("warn", "plugin", `languages: write "${tag}" as "${canon}"`);
|
|
8743
|
+
else if (!knownLanguage(tag)) add2("warn", "plugin", `languages: "${tag}" is not a language Intl knows`);
|
|
7654
8744
|
}
|
|
7655
|
-
if (!declared.includes("en"))
|
|
7656
|
-
if (new Set(declared).size !== declared.length)
|
|
8745
|
+
if (!declared.includes("en")) add2("error", "plugin", "languages: English (`en`) is the one every text falls back to: list it, and write every text in it");
|
|
8746
|
+
if (new Set(declared).size !== declared.length) add2("warn", "plugin", "languages: a language is listed twice");
|
|
7657
8747
|
const own = languagesOf({ ...def, widgets: def.widgets?.map(bare), sources: def.sources?.map(bare), interludes: def.interludes?.map(bare) });
|
|
7658
8748
|
const unlisted = own.filter((l) => !declared.includes(l));
|
|
7659
|
-
if (unlisted.length)
|
|
8749
|
+
if (unlisted.length) add2("warn", "plugin", `its texts come in ${unlisted.join(", ")} too, which \`languages\` doesn't list`);
|
|
7660
8750
|
}
|
|
7661
8751
|
const langs = declared?.length ? declared : used;
|
|
7662
|
-
if (langs.includes("zh") || used.includes("zh"))
|
|
8752
|
+
if (langs.includes("zh") || used.includes("zh")) add2("warn", "plugin", "a bare `zh` is read as Simplified and never shown in Taiwan or Hong Kong: write `zh-Hans` (mainland China) and `zh-Hant` (Taiwan, Hong Kong)");
|
|
7663
8753
|
const valid = langs.filter((l) => {
|
|
7664
8754
|
try {
|
|
7665
8755
|
return Intl.getCanonicalLocales(l)[0] === l && knownLanguage(l);
|
|
@@ -7667,60 +8757,60 @@ function lintPlugin(def) {
|
|
|
7667
8757
|
return false;
|
|
7668
8758
|
}
|
|
7669
8759
|
});
|
|
7670
|
-
const texts = (
|
|
8760
|
+
const texts = (where2, ...ts) => {
|
|
7671
8761
|
for (const tx of ts) {
|
|
7672
8762
|
const miss = missingLanguages(tx, valid);
|
|
7673
|
-
if (miss.length)
|
|
8763
|
+
if (miss.length) add2("warn", where2, `"${typeof tx === "string" ? tx : tx?.en}" has no ${miss.join(", ")} (the plugin speaks ${langs.join(", ")})`);
|
|
7674
8764
|
}
|
|
7675
8765
|
};
|
|
7676
8766
|
texts("plugin", def.name, def.description);
|
|
7677
8767
|
const ids2 = /* @__PURE__ */ new Set();
|
|
7678
8768
|
const part = (kind, x) => {
|
|
7679
|
-
const
|
|
7680
|
-
if (!PART_ID.test(x.id ?? ""))
|
|
7681
|
-
if (ids2.has(`${kind}:${x.id}`))
|
|
8769
|
+
const where2 = `${def.id}/${x.id}`;
|
|
8770
|
+
if (!PART_ID.test(x.id ?? "")) add2("error", where2, `${kind} id ${JSON.stringify(x.id)}`);
|
|
8771
|
+
if (ids2.has(`${kind}:${x.id}`)) add2("error", where2, `two ${kind}s with the id "${x.id}"`);
|
|
7682
8772
|
ids2.add(`${kind}:${x.id}`);
|
|
7683
|
-
texts(
|
|
7684
|
-
if (!x.description)
|
|
7685
|
-
return
|
|
8773
|
+
texts(where2, x.name, x.description);
|
|
8774
|
+
if (!x.description) add2("warn", where2, "a description, for the library and the store");
|
|
8775
|
+
return where2;
|
|
7686
8776
|
};
|
|
7687
|
-
const optionTexts = (
|
|
8777
|
+
const optionTexts = (where2, f) => {
|
|
7688
8778
|
for (const [path, x] of fieldsOf(f)) {
|
|
7689
8779
|
const o = x;
|
|
7690
|
-
texts(`${
|
|
8780
|
+
texts(`${where2} options.${path}`, ...[o.label, o.help, ...Object.values(o.labels ?? {})].filter((x2) => typeof x2 !== "string"));
|
|
7691
8781
|
}
|
|
7692
8782
|
};
|
|
7693
8783
|
for (const w of def.widgets ?? []) optionTexts(`${def.id}/${w.id}`, w.options);
|
|
7694
8784
|
for (const s of def.sources ?? []) optionTexts(`${def.id}/${s.id}`, s.options);
|
|
7695
8785
|
for (const i of def.interludes ?? []) optionTexts(`${def.id}/${i.id}`, i.options);
|
|
7696
8786
|
for (const w of def.widgets ?? []) {
|
|
7697
|
-
const
|
|
7698
|
-
out.push(...lintOptions(
|
|
7699
|
-
if (!w.demo)
|
|
7700
|
-
if (!w.icon)
|
|
8787
|
+
const where2 = part("widget", w);
|
|
8788
|
+
out.push(...lintOptions(where2, w.options, "widget"));
|
|
8789
|
+
if (!w.demo) add2("warn", where2, "no `demo`: the gallery, the editor and the store show it empty");
|
|
8790
|
+
if (!w.icon) add2("warn", where2, "an icon (a Lucide name)");
|
|
7701
8791
|
const min = w.size?.min, pref = w.size?.preferred;
|
|
7702
|
-
if (min && pref && (min.w > pref.w || min.h > pref.h))
|
|
7703
|
-
if (!pref)
|
|
8792
|
+
if (min && pref && (min.w > pref.w || min.h > pref.h)) add2("error", where2, `size.min ${min.w}\xD7${min.h} is bigger than size.preferred ${pref.w}\xD7${pref.h}`);
|
|
8793
|
+
if (!pref) add2("warn", where2, "a size.preferred, what it is dropped at");
|
|
7704
8794
|
for (const s of w.sources ?? []) {
|
|
7705
8795
|
const [pid] = s.split("/");
|
|
7706
|
-
if (pid !== def.id && !(def.requires ?? []).includes(s) && !(def.optional ?? []).includes(s))
|
|
8796
|
+
if (pid !== def.id && !(def.requires ?? []).includes(s) && !(def.optional ?? []).includes(s)) add2("warn", where2, `uses ${s} from another plugin: list it in \`requires\` (or \`optional\`, if it does without)`);
|
|
7707
8797
|
}
|
|
7708
8798
|
}
|
|
7709
8799
|
for (const s of def.sources ?? []) {
|
|
7710
|
-
const
|
|
7711
|
-
out.push(...lintOptions(
|
|
7712
|
-
if (!s.read && !s.watch)
|
|
7713
|
-
if (!s.demo)
|
|
7714
|
-
if (s.background && !s.alerts)
|
|
8800
|
+
const where2 = part("source", s);
|
|
8801
|
+
out.push(...lintOptions(where2, s.options, "source"));
|
|
8802
|
+
if (!s.read && !s.watch) add2("error", where2, "a source needs `read` or `watch`");
|
|
8803
|
+
if (!s.demo) add2("warn", where2, "no `demo`: widgets using it show nothing in the gallery");
|
|
8804
|
+
if (s.background && !s.alerts) add2("warn", where2, "`background` without `alerts`: it would run for nothing, so Kiosko offers no switch");
|
|
7715
8805
|
}
|
|
7716
8806
|
for (const i of def.interludes ?? []) {
|
|
7717
|
-
const
|
|
7718
|
-
out.push(...lintOptions(
|
|
8807
|
+
const where2 = part("interlude", i);
|
|
8808
|
+
out.push(...lintOptions(where2, i.options, "interlude"));
|
|
7719
8809
|
}
|
|
7720
8810
|
for (const tp of def.templates ?? []) {
|
|
7721
|
-
const
|
|
8811
|
+
const where2 = `${def.id}/${tp.id} template`;
|
|
7722
8812
|
for (const tile of [...tp.wide, ...tp.square ?? [], ...tp.tall ?? []]) {
|
|
7723
|
-
if ([tile.x, tile.y, tile.w, tile.h].some((v) => v < 0 || v > 1) || tile.x + tile.w > 1.0001 || tile.y + tile.h > 1.0001)
|
|
8813
|
+
if ([tile.x, tile.y, tile.w, tile.h].some((v) => v < 0 || v > 1) || tile.x + tile.w > 1.0001 || tile.y + tile.h > 1.0001) add2("error", where2, "tiles are fractions of the page (0..1) and stay inside it");
|
|
7724
8814
|
}
|
|
7725
8815
|
}
|
|
7726
8816
|
return out;
|
|
@@ -7736,7 +8826,7 @@ var GITHUB_REPO = "kiosko-lcd/kiosko";
|
|
|
7736
8826
|
var GITHUB_API = "https://api.github.com";
|
|
7737
8827
|
var releasePage = (version) => `https://github.com/${GITHUB_REPO}/releases/tag/v${version}`;
|
|
7738
8828
|
var windowsInstallerName = (version) => `Kiosko-Setup-${version}-x64.exe`;
|
|
7739
|
-
var releaseAsset = (version,
|
|
8829
|
+
var releaseAsset = (version, name2) => `https://github.com/${GITHUB_REPO}/releases/download/v${version}/${name2}`;
|
|
7740
8830
|
var NOTES_MAX_CHARS = 3e3;
|
|
7741
8831
|
var NOTES_MAX_RELEASES = 10;
|
|
7742
8832
|
var stable = (v) => {
|
|
@@ -7780,12 +8870,12 @@ async function kioskoReleaseNotes(current, latest, o) {
|
|
|
7780
8870
|
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
8871
|
});
|
|
7782
8872
|
const newest = byVersion.get(latest);
|
|
7783
|
-
const
|
|
8873
|
+
const name2 = windowsInstallerName(latest);
|
|
7784
8874
|
const asset = (n) => newest?.assets?.find((a) => a.name === n)?.browser_download_url;
|
|
7785
|
-
const exe = asset(
|
|
7786
|
-
const sha = asset(`${
|
|
8875
|
+
const exe = asset(name2);
|
|
8876
|
+
const sha = asset(`${name2}.sha256`);
|
|
7787
8877
|
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 } } : {} };
|
|
8878
|
+
return { from: "github", releases: releases2, ...ours(exe) && ours(sha) ? { windows: { name: name2, exe, sha256: sha } } : {} };
|
|
7789
8879
|
}
|
|
7790
8880
|
|
|
7791
8881
|
// packages/core/src/plugin-updates.ts
|
|
@@ -7867,6 +8957,71 @@ function addedPermissions(before, after) {
|
|
|
7867
8957
|
// packages/core/src/store/tar.ts
|
|
7868
8958
|
var MAX_TARBALL_BYTES = 20 * 1024 * 1024;
|
|
7869
8959
|
|
|
8960
|
+
// packages/core/src/remote/ops.ts
|
|
8961
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
8962
|
+
var CHUNK = 16 * 1024;
|
|
8963
|
+
async function session(host, port, key, uid) {
|
|
8964
|
+
const s = await openSession(host, port, key, uid);
|
|
8965
|
+
const st = await nextSealed(s.wire, s.session);
|
|
8966
|
+
if (st.type !== T.STATE) throw new Error("the screen did not say its state");
|
|
8967
|
+
return s;
|
|
8968
|
+
}
|
|
8969
|
+
async function otaUpdate(host, port, key, uid, image2, progress) {
|
|
8970
|
+
if (image2[0] !== 233) throw new ScreenError("notFirmware", "not an ESP32 firmware image (.bin)");
|
|
8971
|
+
const { wire, session: s } = await session(host, port, key, uid);
|
|
8972
|
+
try {
|
|
8973
|
+
sendSealed(wire, s, T.OTA_BEGIN, { size: image2.length, sha256: createHash2("sha256").update(image2).digest("hex") });
|
|
8974
|
+
const next = async () => {
|
|
8975
|
+
for (; ; ) {
|
|
8976
|
+
const m = await nextSealed(wire, s, 3e4);
|
|
8977
|
+
if (m.type === T.OTA_ACK) return m.json().off;
|
|
8978
|
+
if (m.type === T.OTA_DONE) {
|
|
8979
|
+
const j = m.json();
|
|
8980
|
+
if (!j.ok) throw new ScreenError("otaFailed", `the screen refused the update: ${j.err ?? "error"}`);
|
|
8981
|
+
return -1;
|
|
8982
|
+
}
|
|
8983
|
+
if (m.type === T.PING) sendSealed(wire, s, T.PONG, {});
|
|
8984
|
+
}
|
|
8985
|
+
};
|
|
8986
|
+
let off2 = await next();
|
|
8987
|
+
while (off2 >= 0 && off2 < image2.length) {
|
|
8988
|
+
sendSealed(wire, s, T.OTA_DATA, image2.subarray(off2, off2 + CHUNK));
|
|
8989
|
+
const got = await next();
|
|
8990
|
+
if (got !== Math.min(image2.length, off2 + CHUNK)) throw new ScreenError("otaFailed", `the screen lost the update at ${off2}`);
|
|
8991
|
+
off2 = got;
|
|
8992
|
+
progress?.(off2, image2.length);
|
|
8993
|
+
}
|
|
8994
|
+
sendSealed(wire, s, T.OTA_END, {});
|
|
8995
|
+
if (await next() !== -1) throw new ScreenError("otaFailed", "the screen did not confirm the update");
|
|
8996
|
+
} finally {
|
|
8997
|
+
wire.close();
|
|
8998
|
+
}
|
|
8999
|
+
}
|
|
9000
|
+
async function screenLogs(host, port, key, uid) {
|
|
9001
|
+
const { wire, session: s } = await session(host, port, key, uid);
|
|
9002
|
+
try {
|
|
9003
|
+
sendSealed(wire, s, T.LOGS, {});
|
|
9004
|
+
for (; ; ) {
|
|
9005
|
+
const m = await nextSealed(wire, s);
|
|
9006
|
+
if (m.type === T.LOGS) return String(m.json().text ?? "");
|
|
9007
|
+
}
|
|
9008
|
+
} finally {
|
|
9009
|
+
wire.close();
|
|
9010
|
+
}
|
|
9011
|
+
}
|
|
9012
|
+
async function unpairScreen(host, port, key, uid) {
|
|
9013
|
+
const { wire, session: s } = await session(host, port, key, uid);
|
|
9014
|
+
try {
|
|
9015
|
+
sendSealed(wire, s, T.UNPAIR, {});
|
|
9016
|
+
for (; ; ) {
|
|
9017
|
+
const m = await nextSealed(wire, s).catch(() => null);
|
|
9018
|
+
if (!m || m.type === T.UNPAIR) return;
|
|
9019
|
+
}
|
|
9020
|
+
} finally {
|
|
9021
|
+
wire.close();
|
|
9022
|
+
}
|
|
9023
|
+
}
|
|
9024
|
+
|
|
7870
9025
|
// plugins/core/src/index.ts
|
|
7871
9026
|
import { readdir, readFile, stat } from "node:fs/promises";
|
|
7872
9027
|
import { join as join8 } from "node:path";
|
|
@@ -8231,7 +9386,7 @@ var image = defineWidget({
|
|
|
8231
9386
|
var src_default = definePlugin({
|
|
8232
9387
|
id: "core",
|
|
8233
9388
|
name: { en: "Essentials", es: "B\xE1sicos", de: "Grundlagen", "zh-Hant": "\u57FA\u672C\u5DE5\u5177", "zh-Hans": "\u57FA\u7840\u7EC4\u4EF6" },
|
|
8234
|
-
version: "0.2.
|
|
9389
|
+
version: "0.2.10",
|
|
8235
9390
|
languages: ["en", "es", "de", "zh-Hant", "zh-Hans"],
|
|
8236
9391
|
sdk: "^0.2.0",
|
|
8237
9392
|
// The picture widget reads the image (or folder, or URL) you give it.
|
|
@@ -8248,8 +9403,8 @@ import { existsSync as existsSync7, statSync as statSync2 } from "node:fs";
|
|
|
8248
9403
|
import { isAbsolute, join as join9 } from "node:path";
|
|
8249
9404
|
import { pathToFileURL as pathToFileURL3 } from "node:url";
|
|
8250
9405
|
var loaded = /* @__PURE__ */ new Map();
|
|
8251
|
-
function resolveModule(
|
|
8252
|
-
const expanded = expandPath(
|
|
9406
|
+
function resolveModule(name2, dir) {
|
|
9407
|
+
const expanded = expandPath(name2);
|
|
8253
9408
|
const base3 = isAbsolute(expanded) ? expanded : join9(expandPath(dir), expanded);
|
|
8254
9409
|
for (const p of [base3, `${base3}.mjs`, `${base3}.js`, join9(base3, "index.mjs"), join9(base3, "index.js")]) {
|
|
8255
9410
|
if (existsSync7(p) && statSync2(p).isFile()) return p;
|
|
@@ -8276,14 +9431,14 @@ var optionsSchema = t.object({
|
|
|
8276
9431
|
config: t.map({ label: { en: "Module config (key \u2192 value)", es: "Config del m\xF3dulo (clave \u2192 valor)", de: "Modulkonfiguration (Schl\xFCssel \u2192 Wert)", "zh-Hant": "\u6A21\u7D44\u8A2D\u5B9A\uFF08\u9375 \u2192 \u503C\uFF09", "zh-Hans": "\u6A21\u5757\u914D\u7F6E\uFF08\u952E \u2192 \u503C\uFF09" }, help: { en: "Simple values only; numbers and true/false are converted.", es: "S\xF3lo valores simples; n\xFAmeros y true/false se convierten.", de: "Nur einfache Werte; Zahlen und true/false werden umgewandelt.", "zh-Hant": "\u50C5\u9650\u7C21\u55AE\u503C\uFF1B\u6578\u5B57\u548C true/false \u6703\u81EA\u52D5\u8F49\u63DB\u3002", "zh-Hans": "\u4EC5\u9650\u7B80\u5355\u503C\uFF1B\u6570\u5B57\u548C true/false \u4F1A\u81EA\u52A8\u8F6C\u6362\u3002" } }),
|
|
8277
9432
|
json: t.string({ multiline: true, label: { en: "Module config as JSON", es: "Config del m\xF3dulo en JSON", de: "Modulkonfiguration als JSON", "zh-Hant": "JSON \u683C\u5F0F\u7684\u6A21\u7D44\u8A2D\u5B9A", "zh-Hans": "JSON \u683C\u5F0F\u7684\u6A21\u5757\u914D\u7F6E" }, help: { en: "For lists and nested values. Wins over the table above.", es: "Para listas y valores anidados. Manda sobre la tabla de arriba.", de: "F\xFCr Listen und verschachtelte Werte. Hat Vorrang vor der Tabelle oben.", "zh-Hant": "\u7528\u65BC\u6E05\u55AE\u548C\u5DE2\u72C0\u503C\uFF0C\u512A\u5148\u65BC\u4E0A\u65B9\u7684\u8868\u683C\u3002", "zh-Hans": "\u7528\u4E8E\u5217\u8868\u548C\u5D4C\u5957\u503C\uFF0C\u4F18\u5148\u4E8E\u4E0A\u65B9\u7684\u8868\u683C\u3002" }, advanced: true })
|
|
8278
9433
|
});
|
|
8279
|
-
function moduleConfig(
|
|
9434
|
+
function moduleConfig(mod2, o) {
|
|
8280
9435
|
const kv = Object.fromEntries(Object.entries(o.config).map(([k, v]) => [k, v === "true" ? true : v === "false" ? false : v.trim() !== "" && !Number.isNaN(Number(v)) ? Number(v) : v]));
|
|
8281
9436
|
let js = {};
|
|
8282
9437
|
try {
|
|
8283
9438
|
js = o.json.trim() ? JSON.parse(o.json) : {};
|
|
8284
9439
|
} catch {
|
|
8285
9440
|
}
|
|
8286
|
-
return { ...
|
|
9441
|
+
return { ...mod2?.defaults ?? {}, ...kv, ...js };
|
|
8287
9442
|
}
|
|
8288
9443
|
var module2 = defineWidget({
|
|
8289
9444
|
id: "module",
|
|
@@ -8298,36 +9453,36 @@ var module2 = defineWidget({
|
|
|
8298
9453
|
if (!options2.module) throw new Error("no module set");
|
|
8299
9454
|
const path = resolveModule(options2.module, options2.dir);
|
|
8300
9455
|
if (!path) throw new Error(`module "${options2.module}" not found in ${options2.dir}`);
|
|
8301
|
-
const
|
|
9456
|
+
const mod2 = await load2(path);
|
|
8302
9457
|
if (options2.json.trim()) JSON.parse(options2.json);
|
|
8303
|
-
const data =
|
|
9458
|
+
const data = mod2.fetch ? await mod2.fetch({ config: moduleConfig(mod2, options2), now, log, canvas }) : void 0;
|
|
8304
9459
|
return { path, data };
|
|
8305
9460
|
},
|
|
8306
9461
|
// The module's own `updateMs`, as in aimonitor.
|
|
8307
9462
|
intervalOf: ({ data }) => data ? loaded.get(data.path)?.updateMs : void 0,
|
|
8308
9463
|
render(g, ctx) {
|
|
8309
|
-
const
|
|
8310
|
-
if (!
|
|
9464
|
+
const mod2 = ctx.data ? loaded.get(ctx.data.path) : void 0;
|
|
9465
|
+
if (!mod2) {
|
|
8311
9466
|
ctx.kit.drawTracked(g, ctx.options.module ? "\u2026" : ctx.t({ en: "Pick a module in the options", es: "Elige un m\xF3dulo en las opciones", de: "W\xE4hle ein Modul in den Optionen", "zh-Hant": "\u8ACB\u5728\u9078\u9805\u4E2D\u9078\u64C7\u6A21\u7D44", "zh-Hans": "\u8BF7\u5728\u9009\u9879\u4E2D\u9009\u62E9\u6A21\u5757" }), ctx.box.x, ctx.box.y + 30, { size: 22, family: ctx.theme.fonts.sans, color: ctx.theme.colors.inkDim });
|
|
8312
9467
|
return;
|
|
8313
9468
|
}
|
|
8314
9469
|
const box = ctx.box;
|
|
8315
|
-
|
|
9470
|
+
mod2.draw(g, { config: moduleConfig(mod2, ctx.options), data: ctx.data?.data, now: ctx.now, box, ...legacyLook(ctx.theme), kit: ctx.kit, canvas: ctx.canvas });
|
|
8316
9471
|
},
|
|
8317
9472
|
redraw: "minute",
|
|
8318
9473
|
visible({ options: options2, data, now }) {
|
|
8319
|
-
const
|
|
8320
|
-
return
|
|
9474
|
+
const mod2 = data ? loaded.get(data.path) : void 0;
|
|
9475
|
+
return mod2?.visible?.({ config: moduleConfig(mod2, options2), data: data?.data, now }) ?? true;
|
|
8321
9476
|
},
|
|
8322
9477
|
urgent({ options: options2, data, now }) {
|
|
8323
|
-
const
|
|
8324
|
-
return
|
|
9478
|
+
const mod2 = data ? loaded.get(data.path) : void 0;
|
|
9479
|
+
return mod2?.urgent?.({ config: moduleConfig(mod2, options2), data: data?.data, now }) ?? false;
|
|
8325
9480
|
}
|
|
8326
9481
|
});
|
|
8327
9482
|
var src_default2 = definePlugin({
|
|
8328
9483
|
id: "legacy",
|
|
8329
9484
|
name: { en: "aimonitor compatibility", es: "Compatibilidad aimonitor", de: "aimonitor-Kompatibilit\xE4t", "zh-Hant": "aimonitor \u76F8\u5BB9\u6027", "zh-Hans": "aimonitor \u517C\u5BB9" },
|
|
8330
|
-
version: "0.2.
|
|
9485
|
+
version: "0.2.10",
|
|
8331
9486
|
languages: ["en", "es", "de", "zh-Hant", "zh-Hans"],
|
|
8332
9487
|
sdk: "^0.2.0",
|
|
8333
9488
|
// Runs the aimonitor modules you point it at, and reads their folder.
|
|
@@ -8432,9 +9587,9 @@ function readConfigText(text3) {
|
|
|
8432
9587
|
}
|
|
8433
9588
|
}
|
|
8434
9589
|
function readInput(file) {
|
|
8435
|
-
const
|
|
8436
|
-
if (file !== "-" && !existsSync9(file)) return { error: `not found: ${file}`, notes: [], name };
|
|
8437
|
-
return { ...readConfigText(readFileSync5(file === "-" ? 0 : file, "utf8")), name };
|
|
9590
|
+
const name2 = file === "-" ? "(stdin)" : file;
|
|
9591
|
+
if (file !== "-" && !existsSync9(file)) return { error: `not found: ${file}`, notes: [], name: name2 };
|
|
9592
|
+
return { ...readConfigText(readFileSync5(file === "-" ? 0 : file, "utf8")), name: name2 };
|
|
8438
9593
|
}
|
|
8439
9594
|
var pluginDefs = (r) => r.list().map((p) => p.def);
|
|
8440
9595
|
async function findRunning(cfg, configPath, o) {
|
|
@@ -8677,7 +9832,7 @@ async function runningAt(url2, timeoutMs = 1500) {
|
|
|
8677
9832
|
return null;
|
|
8678
9833
|
}
|
|
8679
9834
|
}
|
|
8680
|
-
async function editorCommand({ server, flags, open, log }) {
|
|
9835
|
+
async function editorCommand({ server, flags, open: open2, log }) {
|
|
8681
9836
|
const url2 = editorUrl2(server, flags);
|
|
8682
9837
|
const version = await runningAt(url2);
|
|
8683
9838
|
if (!version) {
|
|
@@ -8687,7 +9842,7 @@ async function editorCommand({ server, flags, open, log }) {
|
|
|
8687
9842
|
return 1;
|
|
8688
9843
|
}
|
|
8689
9844
|
log(`Kiosko ${version} \u2014 editor at ${url2}`);
|
|
8690
|
-
if (!flags.print)
|
|
9845
|
+
if (!flags.print) open2(url2);
|
|
8691
9846
|
return 0;
|
|
8692
9847
|
}
|
|
8693
9848
|
|
|
@@ -8717,12 +9872,12 @@ async function loadPluginDir(dir, o = {}) {
|
|
|
8717
9872
|
const entry = (o.src || !built) && existsSync10(src) ? src : built;
|
|
8718
9873
|
if (!entry) throw new Error(`no plugin in ${root}: no package.json "kiosko.plugin", index.js or src/index.ts`);
|
|
8719
9874
|
installSdkResolver();
|
|
8720
|
-
const
|
|
8721
|
-
if (!
|
|
8722
|
-
return { def:
|
|
9875
|
+
const mod2 = await import(`${pathToFileURL4(entry).href}?v=${Date.now()}`);
|
|
9876
|
+
if (!mod2.default) throw new Error(`${entry} has no default export (export default definePlugin({...}))`);
|
|
9877
|
+
return { def: mod2.default, pkg, entry };
|
|
8723
9878
|
}
|
|
8724
|
-
var flagOf = (argv2,
|
|
8725
|
-
var optOf = (argv2,
|
|
9879
|
+
var flagOf = (argv2, name2) => argv2.includes(name2);
|
|
9880
|
+
var optOf = (argv2, name2) => argv2.includes(name2) ? argv2[argv2.indexOf(name2) + 1] : void 0;
|
|
8726
9881
|
var positional = (argv2) => argv2.filter((a, i) => !a.startsWith("--") && !["--out", "--port"].includes(argv2[i - 1] ?? ""));
|
|
8727
9882
|
function lookList(looks) {
|
|
8728
9883
|
const parts = looks.map((l) => l.split(" "));
|
|
@@ -8794,11 +9949,11 @@ async function dev(dir, argv2) {
|
|
|
8794
9949
|
}
|
|
8795
9950
|
function newPluginFiles(id) {
|
|
8796
9951
|
const sdk = `^${SDK_VERSION.split(".").slice(0, 2).join(".")}.0`;
|
|
8797
|
-
const
|
|
9952
|
+
const name2 = id.replace(/(^|-)(\w)/g, (_m, _d, c) => ` ${c.toUpperCase()}`).trim();
|
|
8798
9953
|
const pkg = {
|
|
8799
9954
|
name: `kiosko-plugin-${id}`,
|
|
8800
9955
|
version: "0.1.0",
|
|
8801
|
-
description: `${
|
|
9956
|
+
description: `${name2} for Kiosko.`,
|
|
8802
9957
|
type: "module",
|
|
8803
9958
|
license: "MIT",
|
|
8804
9959
|
keywords: ["kiosko", "kiosko-plugin", "lcd", "widgets"],
|
|
@@ -8823,7 +9978,7 @@ function newPluginFiles(id) {
|
|
|
8823
9978
|
devDependencies: { "@kiosko/sdk": sdk, "@loksly/lcd-canvas-kit": "^0.2.0", "@napi-rs/canvas": "^1.0.10", "@types/node": "^24.0.0", esbuild: "^0.25.0", typescript: "^5.9.3" }
|
|
8824
9979
|
};
|
|
8825
9980
|
const index = `/**
|
|
8826
|
-
* ${
|
|
9981
|
+
* ${name2}: a widget fed by a shared source. Rename, then fill in \`read\` and \`render\`.
|
|
8827
9982
|
* The guide: https://github.com/kiosko-lcd/kiosko/blob/main/docs/plugins.md
|
|
8828
9983
|
*/
|
|
8829
9984
|
import { createHttp, definePlugin, defineSource, defineWidget, t } from '@kiosko/sdk';
|
|
@@ -8837,7 +9992,7 @@ export interface Reading {
|
|
|
8837
9992
|
|
|
8838
9993
|
export const reading = defineSource({
|
|
8839
9994
|
id: 'reading',
|
|
8840
|
-
name: { en: '${
|
|
9995
|
+
name: { en: '${name2}', es: '${name2}' },
|
|
8841
9996
|
description: { en: 'What the widgets show, read once for all of them.', es: 'Lo que muestran los widgets, le\xEDdo una vez para todos.' },
|
|
8842
9997
|
options: t.object({
|
|
8843
9998
|
url: t.string({ format: 'url', risk: 'network', placeholder: 'https://api.example.com/value', label: { en: 'Address', es: 'Direcci\xF3n' } }),
|
|
@@ -8853,14 +10008,14 @@ export const reading = defineSource({
|
|
|
8853
10008
|
|
|
8854
10009
|
export const card = defineWidget({
|
|
8855
10010
|
id: 'card',
|
|
8856
|
-
name: { en: '${
|
|
10011
|
+
name: { en: '${name2}', es: '${name2}' },
|
|
8857
10012
|
description: { en: 'The latest value, in big.', es: 'El \xFAltimo valor, en grande.' },
|
|
8858
10013
|
icon: 'gauge',
|
|
8859
10014
|
category: 'info',
|
|
8860
10015
|
size: { min: { w: 160, h: 80 }, preferred: { w: 320, h: 160 } },
|
|
8861
10016
|
sources: ['${id}/reading'],
|
|
8862
10017
|
options: t.object({
|
|
8863
|
-
label: t.string({ default: '${
|
|
10018
|
+
label: t.string({ default: '${name2}', label: { en: 'Label', es: 'Etiqueta' } }),
|
|
8864
10019
|
}),
|
|
8865
10020
|
redraw: 'minute',
|
|
8866
10021
|
render(g, { box, options, sources, theme, kit, fmt }) {
|
|
@@ -8881,9 +10036,9 @@ export const card = defineWidget({
|
|
|
8881
10036
|
|
|
8882
10037
|
export default definePlugin({
|
|
8883
10038
|
id: '${id}',
|
|
8884
|
-
name: { en: '${
|
|
10039
|
+
name: { en: '${name2}', es: '${name2}' },
|
|
8885
10040
|
version: '0.1.0',
|
|
8886
|
-
description: { en: '${
|
|
10041
|
+
description: { en: '${name2} for Kiosko.', es: '${name2} para Kiosko.' },
|
|
8887
10042
|
sdk: '${sdk}',
|
|
8888
10043
|
// The languages its texts come in (Chinese by script: 'zh-Hant', 'zh-Hans').
|
|
8889
10044
|
languages: ['en', 'es'],
|
|
@@ -8900,7 +10055,7 @@ import plugin, { card } from './index.ts';
|
|
|
8900
10055
|
|
|
8901
10056
|
test('the card shows the label and the value', () => {
|
|
8902
10057
|
const r = renderWidget(card, { size: { w: 320, h: 160 } });
|
|
8903
|
-
assert.deepEqual(r.texts.slice(0, 2), ['${
|
|
10058
|
+
assert.deepEqual(r.texts.slice(0, 2), ['${name2}', '42']);
|
|
8904
10059
|
assert.equal(r.outside, 0);
|
|
8905
10060
|
});
|
|
8906
10061
|
|
|
@@ -8927,7 +10082,7 @@ console.log('dist/index.js');
|
|
|
8927
10082
|
const tsconfig = { compilerOptions: { target: "ES2023", module: "nodenext", moduleResolution: "nodenext", lib: ["ES2023"], strict: true, noEmit: true, allowImportingTsExtensions: true, skipLibCheck: true, types: ["node"], customConditions: ["source"] }, include: ["src/**/*.ts"] };
|
|
8928
10083
|
const readme = `# kiosko-plugin-${id}
|
|
8929
10084
|
|
|
8930
|
-
${
|
|
10085
|
+
${name2} for [Kiosko](https://github.com/kiosko-lcd/kiosko).
|
|
8931
10086
|
|
|
8932
10087
|
\`\`\`sh
|
|
8933
10088
|
npm install
|
|
@@ -8997,9 +10152,9 @@ async function pluginsCommand(argv2, registry2) {
|
|
|
8997
10152
|
case "dev":
|
|
8998
10153
|
return dev(positional(names)[0] ?? ".", names);
|
|
8999
10154
|
case "new": {
|
|
9000
|
-
const [id,
|
|
10155
|
+
const [id, where2] = positional(names);
|
|
9001
10156
|
if (!id || !/^[a-z0-9][a-z0-9-]*$/.test(id)) throw new Error("usage: kiosko plugins new <id> [folder] (id: lowercase letters, digits and dashes)");
|
|
9002
|
-
const dir = resolve4(
|
|
10157
|
+
const dir = resolve4(where2 ?? `kiosko-plugin-${id}`);
|
|
9003
10158
|
if (existsSync10(dir) && readdirSync4(dir).length) throw new Error(`${dir} is not empty`);
|
|
9004
10159
|
for (const [file, body2] of Object.entries(newPluginFiles(id))) {
|
|
9005
10160
|
mkdirSync6(join12(dir, file, ".."), { recursive: true });
|
|
@@ -9007,7 +10162,7 @@ async function pluginsCommand(argv2, registry2) {
|
|
|
9007
10162
|
}
|
|
9008
10163
|
console.log(`${dir}
|
|
9009
10164
|
|
|
9010
|
-
cd ${
|
|
10165
|
+
cd ${where2 ?? `kiosko-plugin-${id}`} && npm install && npm test
|
|
9011
10166
|
npm run kiosko:check then: npm run build && npm run dev`);
|
|
9012
10167
|
return;
|
|
9013
10168
|
}
|
|
@@ -9083,13 +10238,266 @@ plugins folder: ${paths.plugins}`);
|
|
|
9083
10238
|
}
|
|
9084
10239
|
}
|
|
9085
10240
|
|
|
10241
|
+
// packages/server/src/remote-cli.ts
|
|
10242
|
+
import { readFileSync as readFileSync7 } from "node:fs";
|
|
10243
|
+
import { hostname as hostname2 } from "node:os";
|
|
10244
|
+
import { createInterface } from "node:readline/promises";
|
|
10245
|
+
|
|
10246
|
+
// packages/server/src/remote-api.ts
|
|
10247
|
+
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
10248
|
+
import { hostname } from "node:os";
|
|
10249
|
+
var PAIR_TTL_MS = 3 * 6e4;
|
|
10250
|
+
async function raw(req, limit) {
|
|
10251
|
+
const chunks = [];
|
|
10252
|
+
let size = 0;
|
|
10253
|
+
for await (const c of req) {
|
|
10254
|
+
size += c.length;
|
|
10255
|
+
if (size > limit) throw new ScreenError("tooBig", "body too large");
|
|
10256
|
+
chunks.push(c);
|
|
10257
|
+
}
|
|
10258
|
+
return Buffer.concat(chunks);
|
|
10259
|
+
}
|
|
10260
|
+
function remoteScreen(registry2, info, key, locale, host) {
|
|
10261
|
+
const rot = [0, 90, 180, 270].includes(info.rot) ? info.rot : 0;
|
|
10262
|
+
const quarter = rot === 90 || rot === 270;
|
|
10263
|
+
const width = (quarter ? info.h : info.w) || 320, height = (quarter ? info.w : info.h) || 172;
|
|
10264
|
+
const s = newScreen(info.id || "Remote screen", width, height, { driver: "remote", uid: info.uid, ...info.id ? { id: info.id } : {}, key, ...host ? { host } : {} });
|
|
10265
|
+
s.rotate = rot;
|
|
10266
|
+
s.jpegQuality = 85;
|
|
10267
|
+
s.maxBytes = Math.max(16 * 1024, Math.min(info.max - 1024, 90 * 1024));
|
|
10268
|
+
s.pages = [starterPage((t2) => !!registry2.widget(t2), { width, height, locale, agents: false })];
|
|
10269
|
+
return s;
|
|
10270
|
+
}
|
|
10271
|
+
function remoteApi(ctx) {
|
|
10272
|
+
const pending2 = /* @__PURE__ */ new Map();
|
|
10273
|
+
const locate = async (uid, host, port) => {
|
|
10274
|
+
if (host) return { host, port: port ?? 7428 };
|
|
10275
|
+
const t2 = ctx.locate?.(uid);
|
|
10276
|
+
if (t2) return t2;
|
|
10277
|
+
const b = browser();
|
|
10278
|
+
const f = b.get(uid) ?? (uid ? (await b.browse(2500)).find((x) => x.uid === uid) : void 0);
|
|
10279
|
+
return f ? { host: f.address, port: f.port } : void 0;
|
|
10280
|
+
};
|
|
10281
|
+
const fail = (res, err) => {
|
|
10282
|
+
if (err instanceof ScreenError) return ctx.json(res, err.code === "offline" ? 404 : 409, { error: err.message, code: `remote.${err.code}` });
|
|
10283
|
+
const e = err;
|
|
10284
|
+
return ctx.json(res, 502, { error: e?.message ?? String(err), code: "remote.unreachable" });
|
|
10285
|
+
};
|
|
10286
|
+
const screenOf = (id) => ctx.runtime.config.screens.find((s) => s.id === id);
|
|
10287
|
+
const remoteOf = (id) => {
|
|
10288
|
+
const s = screenOf(id);
|
|
10289
|
+
if (!s || s.device.driver !== "remote") return null;
|
|
10290
|
+
const d = ctx.runtime.deviceOf(id);
|
|
10291
|
+
return { screen: s, device: s.device, driver: d instanceof RemoteDevice ? d : null };
|
|
10292
|
+
};
|
|
10293
|
+
return async function handle(req, res, p, m) {
|
|
10294
|
+
if (p === "/api/remote/pair" && m === "POST") {
|
|
10295
|
+
const b = await ctx.body(req, 4096);
|
|
10296
|
+
const uid = String(b.uid ?? "");
|
|
10297
|
+
const at = await locate(uid, b.host, b.port);
|
|
10298
|
+
if (!at) return ctx.json(res, 404, { error: "that screen is not on the network", code: "remote.offline" }), true;
|
|
10299
|
+
try {
|
|
10300
|
+
const pairing = await Pairing.start(at.host, at.port, `Kiosko on ${hostname()}`.slice(0, 40));
|
|
10301
|
+
if (uid && pairing.info.uid !== uid) {
|
|
10302
|
+
pairing.cancel();
|
|
10303
|
+
return ctx.json(res, 409, { error: "another screen answers there", code: "remote.otherScreen" }), true;
|
|
10304
|
+
}
|
|
10305
|
+
const pairId = randomBytes3(12).toString("hex");
|
|
10306
|
+
const timer = setTimeout(() => {
|
|
10307
|
+
pending2.get(pairId)?.pairing.cancel();
|
|
10308
|
+
pending2.delete(pairId);
|
|
10309
|
+
}, PAIR_TTL_MS);
|
|
10310
|
+
timer.unref();
|
|
10311
|
+
pending2.set(pairId, { pairing, uid: pairing.info.uid, host: at.host, port: at.port, timer });
|
|
10312
|
+
ctx.json(res, 200, { pairId, ttl: pairing.ttl, screen: pairing.info });
|
|
10313
|
+
} catch (err) {
|
|
10314
|
+
fail(res, err);
|
|
10315
|
+
}
|
|
10316
|
+
return true;
|
|
10317
|
+
}
|
|
10318
|
+
let mm = /^\/api\/remote\/pair\/([0-9a-f]{24})$/.exec(p);
|
|
10319
|
+
if (mm && (m === "POST" || m === "DELETE")) {
|
|
10320
|
+
const job = pending2.get(mm[1]);
|
|
10321
|
+
if (!job) return ctx.json(res, 404, { error: "no such pairing (it expired?)", code: "remote.pairingOver" }), true;
|
|
10322
|
+
pending2.delete(mm[1]);
|
|
10323
|
+
clearTimeout(job.timer);
|
|
10324
|
+
if (m === "DELETE") {
|
|
10325
|
+
job.pairing.cancel();
|
|
10326
|
+
return ctx.json(res, 200, { ok: true }), true;
|
|
10327
|
+
}
|
|
10328
|
+
const b = await ctx.body(req, 4096);
|
|
10329
|
+
let key;
|
|
10330
|
+
try {
|
|
10331
|
+
key = await job.pairing.finish(String(b.code ?? ""));
|
|
10332
|
+
} catch (err) {
|
|
10333
|
+
return fail(res, err), true;
|
|
10334
|
+
}
|
|
10335
|
+
const info = job.pairing.info;
|
|
10336
|
+
const cfg = structuredClone(ctx.runtime.config);
|
|
10337
|
+
let s = b.screenId && cfg.screens.find((x) => x.id === b.screenId) || cfg.screens.find((x) => x.device.driver === "remote" && x.device.uid === info.uid);
|
|
10338
|
+
const hex2 = key.toString("hex");
|
|
10339
|
+
if (s) {
|
|
10340
|
+
const keepHost = s.device.driver === "remote" ? s.device.host : void 0;
|
|
10341
|
+
const keepPort = s.device.driver === "remote" ? s.device.port : void 0;
|
|
10342
|
+
s.device = { driver: "remote", uid: info.uid, id: info.id, key: hex2, ...keepHost ? { host: keepHost } : {}, ...keepPort ? { port: keepPort } : {} };
|
|
10343
|
+
} else {
|
|
10344
|
+
s = remoteScreen(ctx.runtime.registry, info, hex2, ctx.runtime.config.locale === "auto" ? "en" : ctx.runtime.config.locale);
|
|
10345
|
+
cfg.screens.push(s);
|
|
10346
|
+
}
|
|
10347
|
+
ctx.commit(cfg);
|
|
10348
|
+
return ctx.json(res, 200, { ok: true, screenId: s.id }), true;
|
|
10349
|
+
}
|
|
10350
|
+
mm = /^\/api\/screens\/([^/]+)\/remote\/(unpair|ota|logs)$/.exec(p);
|
|
10351
|
+
if (mm) {
|
|
10352
|
+
const id = decodeURIComponent(mm[1]);
|
|
10353
|
+
const r = remoteOf(id);
|
|
10354
|
+
if (!r) return ctx.json(res, 404, { error: "not a remote screen", code: "unknownScreen" }), true;
|
|
10355
|
+
const key = /^[0-9a-f]{64}$/.test(r.device.key ?? "") ? Buffer.from(r.device.key, "hex") : null;
|
|
10356
|
+
const run = async (fn) => {
|
|
10357
|
+
if (r.driver) return r.driver.exclusive(fn);
|
|
10358
|
+
const at = await locate(r.device.uid, r.device.host, r.device.port);
|
|
10359
|
+
if (!at) throw new ScreenError("offline", "that screen is not on the network");
|
|
10360
|
+
return fn(at.host, at.port);
|
|
10361
|
+
};
|
|
10362
|
+
try {
|
|
10363
|
+
if (mm[2] === "unpair" && m === "POST") {
|
|
10364
|
+
let told = false;
|
|
10365
|
+
if (key) {
|
|
10366
|
+
try {
|
|
10367
|
+
await run((h, port) => unpairScreen(h, port, key, r.device.uid));
|
|
10368
|
+
told = true;
|
|
10369
|
+
} catch {
|
|
10370
|
+
}
|
|
10371
|
+
}
|
|
10372
|
+
const cfg = structuredClone(ctx.runtime.config);
|
|
10373
|
+
const s = cfg.screens.find((x) => x.id === id);
|
|
10374
|
+
if (s.device.driver === "remote") delete s.device.key;
|
|
10375
|
+
ctx.commit(cfg);
|
|
10376
|
+
return ctx.json(res, 200, { ok: true, told }), true;
|
|
10377
|
+
}
|
|
10378
|
+
if (!key) return ctx.json(res, 409, { error: "not paired", code: "remote.notPaired" }), true;
|
|
10379
|
+
if (mm[2] === "logs" && m === "GET") return ctx.json(res, 200, { text: await run((h, port) => screenLogs(h, port, key, r.device.uid)) }), true;
|
|
10380
|
+
if (mm[2] === "ota" && m === "POST") {
|
|
10381
|
+
const image2 = await raw(req, 4 * 1024 * 1024);
|
|
10382
|
+
await run((h, port) => otaUpdate(h, port, key, r.device.uid, image2));
|
|
10383
|
+
return ctx.json(res, 200, { ok: true }), true;
|
|
10384
|
+
}
|
|
10385
|
+
} catch (err) {
|
|
10386
|
+
return fail(res, err), true;
|
|
10387
|
+
}
|
|
10388
|
+
}
|
|
10389
|
+
return false;
|
|
10390
|
+
};
|
|
10391
|
+
}
|
|
10392
|
+
|
|
10393
|
+
// packages/server/src/remote-cli.ts
|
|
10394
|
+
var say = (s) => console.log(s);
|
|
10395
|
+
function screenArg(cfg, q3) {
|
|
10396
|
+
const s = cfg.screens.find((x) => x.id === q3 || x.name === q3 || x.device.driver === "remote" && (x.device.uid === q3 || x.device.id === q3));
|
|
10397
|
+
if (!s || s.device.driver !== "remote") throw new Error(`no remote screen "${q3 ?? ""}" in the config (kiosko remote list)`);
|
|
10398
|
+
return s;
|
|
10399
|
+
}
|
|
10400
|
+
async function where(d) {
|
|
10401
|
+
if (d.host) return { host: d.host, port: d.port ?? PORT };
|
|
10402
|
+
const b = browser();
|
|
10403
|
+
const f = b.get(d.uid) ?? (await b.browse(2500)).find((x) => x.uid === d.uid);
|
|
10404
|
+
if (!f) throw new Error(`screen ${d.uid} is not on the network (no mDNS answer)`);
|
|
10405
|
+
return { host: f.address, port: f.port };
|
|
10406
|
+
}
|
|
10407
|
+
async function viaServer(port, path, init) {
|
|
10408
|
+
try {
|
|
10409
|
+
return await fetch(`http://127.0.0.1:${port}${path}`, { ...init, headers: { "x-kiosko": "1", ...init.headers ?? {} } });
|
|
10410
|
+
} catch {
|
|
10411
|
+
return null;
|
|
10412
|
+
}
|
|
10413
|
+
}
|
|
10414
|
+
async function remoteCommand(args, o) {
|
|
10415
|
+
const [sub = "list", a, b] = args.filter((x, i, all) => !x.startsWith("--") && !(i > 0 && all[i - 1].startsWith("--")));
|
|
10416
|
+
const opt2 = (n) => {
|
|
10417
|
+
const i = args.indexOf(n);
|
|
10418
|
+
return i >= 0 ? args[i + 1] : void 0;
|
|
10419
|
+
};
|
|
10420
|
+
const { config: cfg } = loadConfig(o.configPath);
|
|
10421
|
+
try {
|
|
10422
|
+
if (sub === "list") {
|
|
10423
|
+
const found = await browser().browse(2500);
|
|
10424
|
+
if (!found.length) say("no Kiosko remote screen answered on this network (mDNS _kiosko-screen._tcp)");
|
|
10425
|
+
for (const f of found) {
|
|
10426
|
+
const used = cfg.screens.find((s) => s.device.driver === "remote" && s.device.uid === f.uid);
|
|
10427
|
+
say(`${f.id.padEnd(16)} uid ${f.uid} ${f.model} ${f.w}\xD7${f.h} at ${f.rot}\xB0 fw ${f.fw} ${f.paired ? "paired" : "not paired"} ${f.address}:${f.port} (${f.hostname})${used ? ` \u2192 screen "${used.name}"` : ""}`);
|
|
10428
|
+
}
|
|
10429
|
+
for (const s of cfg.screens) if (s.device.driver === "remote" && !found.some((f) => f.uid === s.device.uid)) say(`(screen "${s.name}": ${s.device.id ?? s.device.uid} did not answer)`);
|
|
10430
|
+
return 0;
|
|
10431
|
+
}
|
|
10432
|
+
if (sub === "pair") {
|
|
10433
|
+
if (!a) throw new Error("usage: kiosko remote pair <uid|host> [--screen id]");
|
|
10434
|
+
const isUid = /^[0-9a-f]{12}$/i.test(a);
|
|
10435
|
+
const at = isUid ? await where({ uid: a.toLowerCase() }) : { host: a, port: Number(opt2("--port-screen")) || PORT };
|
|
10436
|
+
const info = await probe(at.host, at.port);
|
|
10437
|
+
say(`${info.id} (${info.model}, uid ${info.uid}) at ${at.host}`);
|
|
10438
|
+
const p = await Pairing.start(at.host, at.port, `Kiosko on ${hostname2()}`.slice(0, 40));
|
|
10439
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
10440
|
+
const code = await rl.question("Code shown on the screen: ");
|
|
10441
|
+
rl.close();
|
|
10442
|
+
const key = (await p.finish(code)).toString("hex");
|
|
10443
|
+
const next = structuredClone(cfg);
|
|
10444
|
+
const target = opt2("--screen") && next.screens.find((s) => s.id === opt2("--screen")) || next.screens.find((s) => s.device.driver === "remote" && s.device.uid === info.uid);
|
|
10445
|
+
if (target) target.device = { driver: "remote", uid: info.uid, id: info.id, key, ...isUid ? {} : { host: at.host } };
|
|
10446
|
+
else next.screens.push(remoteScreen(await o.registry(), info, key, "en", isUid ? void 0 : at.host));
|
|
10447
|
+
saveConfig(normalize(next), o.configPath);
|
|
10448
|
+
say(`paired; saved in ${o.configPath}${target ? ` (screen "${target.name}")` : " as a new screen"}. A Kiosko running here picks it up when it restarts.`);
|
|
10449
|
+
return 0;
|
|
10450
|
+
}
|
|
10451
|
+
if (sub === "ota" || sub === "logs" || sub === "unpair") {
|
|
10452
|
+
const s = screenArg(cfg, a);
|
|
10453
|
+
const id = encodeURIComponent(s.id);
|
|
10454
|
+
const image2 = sub === "ota" ? readFileSync7(b ?? "") : null;
|
|
10455
|
+
if (sub === "ota" && !b) throw new Error("usage: kiosko remote ota <screen> <firmware.bin>");
|
|
10456
|
+
const r = await viaServer(o.port, `/api/screens/${id}/remote/${sub}`, sub === "logs" ? {} : { method: "POST", ...image2 ? { body: new Uint8Array(image2) } : {} });
|
|
10457
|
+
if (r && r.status !== 404) {
|
|
10458
|
+
const j = await r.json();
|
|
10459
|
+
if (!r.ok) throw new Error(j.error ?? `HTTP ${r.status}`);
|
|
10460
|
+
say(sub === "logs" ? j.text ?? "" : sub === "ota" ? "updated: the screen restarts into it (and goes back by itself if this Kiosko cannot talk to it)" : "unpaired");
|
|
10461
|
+
return 0;
|
|
10462
|
+
}
|
|
10463
|
+
const key = /^[0-9a-f]{64}$/.test(s.device.key ?? "") ? Buffer.from(s.device.key, "hex") : null;
|
|
10464
|
+
if (!key) throw new Error(`screen "${s.name}" is not paired`);
|
|
10465
|
+
const at = await where(s.device);
|
|
10466
|
+
if (sub === "logs") say(await screenLogs(at.host, at.port, key, s.device.uid));
|
|
10467
|
+
else if (sub === "ota") {
|
|
10468
|
+
let last2 = -1;
|
|
10469
|
+
await otaUpdate(at.host, at.port, key, s.device.uid, image2, (sent, total) => {
|
|
10470
|
+
const pct = Math.floor(sent * 100 / total);
|
|
10471
|
+
if (pct >= last2 + 10) process.stdout.write(`${last2 = pct}% `);
|
|
10472
|
+
});
|
|
10473
|
+
say("\nupdated: the screen restarts into it (and goes back by itself if this Kiosko cannot talk to it)");
|
|
10474
|
+
} else {
|
|
10475
|
+
await unpairScreen(at.host, at.port, key, s.device.uid);
|
|
10476
|
+
const next = structuredClone(cfg);
|
|
10477
|
+
const t2 = next.screens.find((x) => x.id === s.id);
|
|
10478
|
+
if (t2.device.driver === "remote") delete t2.device.key;
|
|
10479
|
+
saveConfig(normalize(next), o.configPath);
|
|
10480
|
+
say("unpaired");
|
|
10481
|
+
}
|
|
10482
|
+
return 0;
|
|
10483
|
+
}
|
|
10484
|
+
say("usage: kiosko remote [list] | pair <uid|host> [--screen id] | ota <screen> <file.bin> | logs <screen> | unpair <screen>");
|
|
10485
|
+
return 2;
|
|
10486
|
+
} catch (err) {
|
|
10487
|
+
console.error(`\u2717 ${err instanceof Error ? err.message : String(err)}`);
|
|
10488
|
+
return 1;
|
|
10489
|
+
} finally {
|
|
10490
|
+
browser().close();
|
|
10491
|
+
}
|
|
10492
|
+
}
|
|
10493
|
+
|
|
9086
10494
|
// packages/server/src/gallery.ts
|
|
9087
10495
|
import { mkdirSync as mkdirSync7, writeFileSync as writeFileSync8 } from "node:fs";
|
|
9088
10496
|
import { join as join13 } from "node:path";
|
|
9089
10497
|
var HOME_URL = "https://kioskolcd.dev/";
|
|
9090
10498
|
var RELEASES_URL = "https://github.com/kiosko-lcd/kiosko/releases/latest";
|
|
9091
10499
|
var MADRID = { latitude: 40.4168, longitude: -3.7038, name: "Madrid" };
|
|
9092
|
-
var
|
|
10500
|
+
var T2 = {
|
|
9093
10501
|
title: { en: "Kiosko widget gallery", es: "Galer\xEDa de widgets de Kiosko", de: "Kiosko-Widget-Galerie", "zh-Hant": "Kiosko \u5C0F\u5DE5\u5177\u5C55\u793A", "zh-Hans": "Kiosko \u5C0F\u7EC4\u4EF6\u5C55\u793A" },
|
|
9094
10502
|
lede: { en: "{n} widgets, painted with their demo data by the same code that drives the panels.", es: "{n} widgets, pintados con sus datos de muestra por el mismo c\xF3digo que mueve los paneles.", de: "{n} Widgets, mit ihren Demodaten gezeichnet, vom selben Code, der die Panels steuert.", "zh-Hant": "{n} \u500B\u5C0F\u5DE5\u5177\uFF0C\u4EE5\u7BC4\u4F8B\u8CC7\u6599\u7E6A\u88FD\uFF0C\u7528\u7684\u6B63\u662F\u9A45\u52D5\u9762\u677F\u7684\u540C\u4E00\u5957\u7A0B\u5F0F\u78BC\u3002", "zh-Hans": "{n} \u4E2A\u5C0F\u7EC4\u4EF6\uFF0C\u7528\u793A\u4F8B\u6570\u636E\u7ED8\u5236\uFF0C\u7528\u7684\u6B63\u662F\u9A71\u52A8\u526F\u5C4F\u7684\u540C\u4E00\u5957\u4EE3\u7801\u3002" },
|
|
9095
10503
|
github: { en: "Kiosko on GitHub", es: "Kiosko en GitHub", de: "Kiosko auf GitHub", "zh-Hant": "GitHub \u4E0A\u7684 Kiosko", "zh-Hans": "GitHub \u4E0A\u7684 Kiosko" },
|
|
@@ -9149,7 +10557,7 @@ function buildGallery(registry2, o) {
|
|
|
9149
10557
|
mkdirSync7(join13(o.out, folder(lang.id)), { recursive: true });
|
|
9150
10558
|
writeFileSync8(
|
|
9151
10559
|
join13(o.out, folder(lang.id), "index.html"),
|
|
9152
|
-
`<!doctype html><html lang="${lang.id}" dir="${lang.dir}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${esc(L(
|
|
10560
|
+
`<!doctype html><html lang="${lang.id}" dir="${lang.dir}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${esc(L(T2.title))}</title>
|
|
9153
10561
|
<style>
|
|
9154
10562
|
:root{color-scheme:dark;--bg:#0a0d13;--panel:#121722;--line:rgba(255,255,255,.08);--text:#e7ecf4;--dim:#a3adbf}
|
|
9155
10563
|
body{margin:0;background:var(--bg);color:var(--text);font:15px/1.5 ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif}
|
|
@@ -9166,15 +10574,15 @@ figcaption code{color:#22d3ee;font-size:12px}figcaption span{flex-basis:100%;col
|
|
|
9166
10574
|
a{color:#22d3ee}
|
|
9167
10575
|
p.os{margin-top:14px}p.os b{color:var(--text)}
|
|
9168
10576
|
a.try{display:inline-block;margin-top:10px;padding:8px 14px;border-radius:10px;background:linear-gradient(135deg,#8b5cf6,#22d3ee);color:#fff;font-weight:600;text-decoration:none}
|
|
9169
|
-
</style></head><body><header><p><a href="${home}">\u2190 Kiosko</a></p><h1>${esc(L(
|
|
10577
|
+
</style></head><body><header><p><a href="${home}">\u2190 Kiosko</a></p><h1>${esc(L(T2.title))}</h1><p>${esc(L(T2.lede).replace("{n}", String(listedHere.reduce((n, p) => n + p.def.widgets.length, 0))))} <a href="https://github.com/kiosko-lcd/kiosko">${esc(L(T2.github))}</a></p><p><a class="try" href="${HOME_URL}demo/?lang=${lang.locale}">${esc(L(T2.editor))}</a> <a class="try" href="${HOME_URL}demo/3d/?lang=${lang.locale}">${esc(L(T2.in3d))}</a></p><p class="os">${L(T2.os).replace("{releases}", RELEASES_URL).replace("{usb}", usb)}</p></header><main>${sections.join("")}</main></body></html>`
|
|
9170
10578
|
);
|
|
9171
10579
|
}
|
|
9172
10580
|
if (o.pages) {
|
|
9173
10581
|
const sample = normalize(o.pages);
|
|
9174
10582
|
const screen = [...sample.screens].sort((a, b) => b.width / b.height - a.width / a.height)[0];
|
|
9175
10583
|
for (const page of screen?.pages.filter((p) => p.enabled !== false) ?? []) {
|
|
9176
|
-
const
|
|
9177
|
-
data.pages.push({ id: page.id, name: page.name, file: Object.fromEntries(langs.map((l) => [l.id, l.id === first ? `${
|
|
10584
|
+
const name2 = `img/page-${slug2(page.name || page.id)}`;
|
|
10585
|
+
data.pages.push({ id: page.id, name: page.name, file: Object.fromEntries(langs.map((l) => [l.id, l.id === first ? `${name2}.jpg` : `${name2}.${l.id}.jpg`])), width: screen.width, height: screen.height });
|
|
9178
10586
|
}
|
|
9179
10587
|
for (const l of langs) {
|
|
9180
10588
|
const local = normalize({ ...localizeSample(sample, l.locale), locale: l.locale });
|
|
@@ -9244,7 +10652,7 @@ function widgetFor(m, reg, notes, modulesDir) {
|
|
|
9244
10652
|
}
|
|
9245
10653
|
return { ...base3, type: "legacy/module", options: { module: m.module, dir: modulesDir, json: m.config ? JSON.stringify(m.config, null, 2) : "" } };
|
|
9246
10654
|
}
|
|
9247
|
-
function columnsPage(
|
|
10655
|
+
function columnsPage(name2, width, height, mods, rotateMs, reg, notes, modulesDir) {
|
|
9248
10656
|
const groups = [];
|
|
9249
10657
|
const byColumn = /* @__PURE__ */ new Map();
|
|
9250
10658
|
for (const m of mods) {
|
|
@@ -9266,7 +10674,7 @@ function columnsPage(name, width, height, mods, rotateMs, reg, notes, modulesDir
|
|
|
9266
10674
|
x += w;
|
|
9267
10675
|
return t2;
|
|
9268
10676
|
});
|
|
9269
|
-
return { id: newId("page"), name, enabled: true, durationMs: 10 * 6e4, when: "always", grid, gravity: "left", background: {}, tiles };
|
|
10677
|
+
return { id: newId("page"), name: name2, enabled: true, durationMs: 10 * 6e4, when: "always", grid, gravity: "left", background: {}, tiles };
|
|
9270
10678
|
}
|
|
9271
10679
|
function importAimonitor(old, reg, modeOverride, o = {}) {
|
|
9272
10680
|
const notes = [];
|
|
@@ -9277,19 +10685,19 @@ function importAimonitor(old, reg, modeOverride, o = {}) {
|
|
|
9277
10685
|
const device = trcc.frameDir ? { driver: "file", dir: trcc.frameDir, format: "jpeg" } : { driver: "trcc", url: trcc.api?.url ?? "http://127.0.0.1:8099", ...trcc.api?.tokenFile ? { tokenFile: trcc.api.tokenFile } : {}, ...trcc.serial ? { serial: trcc.serial } : {}, ...trcc.deviceKey ? { deviceKey: trcc.deviceKey } : {} };
|
|
9278
10686
|
const grid = { cols: 24, rows: 6, gap: 10, padding: 10 };
|
|
9279
10687
|
const W = (type, options2 = {}, title) => ({ id: newId("w"), type, options: options2, ...title ? { title } : {} });
|
|
9280
|
-
const
|
|
10688
|
+
const T3 = (x, y, w, h, widgets, chrome = "auto", rotateMs = 3e4) => ({ id: newId("tile"), x, y, w, h, widgets, rotateMs, chrome });
|
|
9281
10689
|
const railOn = old.rail?.enabled !== false && old.usage?.enabled !== false;
|
|
9282
10690
|
const sysOn = old.system?.enabled !== false;
|
|
9283
10691
|
const sessionsOpts = { ...old.tile ? { tileMin: old.tile.min, tileMax: old.tile.max, gap: old.tile.gap, detailLines: old.tile.detailLines } : {}, ...old.spineWidth ? { spineWidth: old.spineWidth } : {} };
|
|
9284
|
-
const dashTiles = [
|
|
9285
|
-
if (sysOn) dashTiles.push(
|
|
9286
|
-
if (railOn) dashTiles.push(
|
|
10692
|
+
const dashTiles = [T3(0, 0, 24, 1, [W("agents/summary")], "bare"), T3(0, 1, railOn ? sysOn ? 13 : 19 : sysOn ? 18 : 24, 5, [W("agents/sessions", sessionsOpts)], "bare")];
|
|
10693
|
+
if (sysOn) dashTiles.push(T3(railOn ? 13 : 18, 1, 6, 5, [W("vitals/vitals")], "bare"));
|
|
10694
|
+
if (railOn) dashTiles.push(T3(19, 1, 5, 5, [W("usage/rail")], "bare"));
|
|
9287
10695
|
const dashboard = { id: newId("page"), name: "Dashboard", enabled: true, durationMs: old.scene?.alternateMs ?? 10 * 6e4, when: "always", grid, gravity: "none", background: {}, tiles: dashTiles };
|
|
9288
10696
|
const cardWidgets = (old.modules ?? []).map((m) => widgetFor(m, reg, notes, modulesDir)).filter((w) => !!w);
|
|
9289
10697
|
if (railOn) cardWidgets.push(W("usage/rail", {}, "Consumo"));
|
|
9290
10698
|
const side = old.scene?.side === "izquierda" ? "left" : "right";
|
|
9291
|
-
const catsTiles = [
|
|
9292
|
-
if (cardWidgets.length) catsTiles.push(
|
|
10699
|
+
const catsTiles = [T3(side === "right" ? 0 : 7, 0, 17, 6, [W("cats/room", { room: old.scene?.room === "rotar" || !old.scene?.room ? "rotate" : old.scene.room })], "bare")];
|
|
10700
|
+
if (cardWidgets.length) catsTiles.push(T3(side === "right" ? 17 : 0, 0, 7, 6, cardWidgets, "card", old.timesheet?.alternateMs || 3e4));
|
|
9293
10701
|
const cats = { id: newId("page"), name: "Cats", enabled: true, durationMs: old.scene?.alternateMs ?? 10 * 6e4, when: "always", grid, gravity: "none", background: {}, tiles: catsTiles };
|
|
9294
10702
|
const override = (modeOverride ?? "").trim().toLowerCase();
|
|
9295
10703
|
const mode = ["gatos", "tablero", "alternar"].includes(override) ? override : old.scene?.mode ?? "tablero";
|
|
@@ -9478,8 +10886,8 @@ function runService(action, plan) {
|
|
|
9478
10886
|
|
|
9479
10887
|
// packages/server/src/server.ts
|
|
9480
10888
|
import { spawn as spawn2 } from "node:child_process";
|
|
9481
|
-
import { randomBytes } from "node:crypto";
|
|
9482
|
-
import { existsSync as existsSync16, openSync, readFileSync as
|
|
10889
|
+
import { randomBytes as randomBytes4 } from "node:crypto";
|
|
10890
|
+
import { existsSync as existsSync16, openSync, readFileSync as readFileSync12, statSync as statSync3 } from "node:fs";
|
|
9483
10891
|
import { createServer } from "node:http";
|
|
9484
10892
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
9485
10893
|
import { createRequire as createRequire3 } from "node:module";
|
|
@@ -9487,7 +10895,7 @@ import { dirname as dirname8, extname, join as join18, normalize as normPath, re
|
|
|
9487
10895
|
|
|
9488
10896
|
// packages/server/src/plugins-manage.ts
|
|
9489
10897
|
import { execFile } from "node:child_process";
|
|
9490
|
-
import { existsSync as existsSync12, lstatSync as lstatSync2, mkdirSync as mkdirSync9, readFileSync as
|
|
10898
|
+
import { existsSync as existsSync12, lstatSync as lstatSync2, mkdirSync as mkdirSync9, readFileSync as readFileSync8, rmSync as rmSync3, writeFileSync as writeFileSync10 } from "node:fs";
|
|
9491
10899
|
import { join as join15, relative as relative2, resolve as resolve6, sep } from "node:path";
|
|
9492
10900
|
var NPM_NAME = /^(@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*(@[\w.^~<>=*-]+)?$/i;
|
|
9493
10901
|
var packageName = (spec) => spec.startsWith("@") ? `@${spec.slice(1).split("@")[0]}` : spec.split("@")[0];
|
|
@@ -9504,10 +10912,10 @@ var realNpm = (args, cwd) => new Promise((ok, fail) => {
|
|
|
9504
10912
|
const npm2 = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
9505
10913
|
execFile(npm2, args, { cwd, timeout: 18e4, shell: process.platform === "win32" }, (err, stdout, stderr) => err ? fail(new Error((stderr || err.message).slice(-2e3))) : ok(stdout.slice(-2e3)));
|
|
9506
10914
|
});
|
|
9507
|
-
function installedIntegrity(dir,
|
|
10915
|
+
function installedIntegrity(dir, name2) {
|
|
9508
10916
|
try {
|
|
9509
|
-
const lock = JSON.parse(
|
|
9510
|
-
return lock.packages?.[`node_modules/${
|
|
10917
|
+
const lock = JSON.parse(readFileSync8(join15(dir, "node_modules", ".package-lock.json"), "utf8"));
|
|
10918
|
+
return lock.packages?.[`node_modules/${name2}`]?.integrity;
|
|
9511
10919
|
} catch {
|
|
9512
10920
|
return void 0;
|
|
9513
10921
|
}
|
|
@@ -9519,7 +10927,7 @@ async function installPlugin(spec, o) {
|
|
|
9519
10927
|
const npm2 = o.npm ?? realNpm;
|
|
9520
10928
|
const r = o.registry;
|
|
9521
10929
|
const folder = join15(dir, "node_modules", packageName(spec));
|
|
9522
|
-
const readPkg = () => existsSync12(join15(folder, "package.json")) ? JSON.parse(
|
|
10930
|
+
const readPkg = () => existsSync12(join15(folder, "package.json")) ? JSON.parse(readFileSync8(join15(folder, "package.json"), "utf8")) : null;
|
|
9523
10931
|
const beforePkg = readPkg();
|
|
9524
10932
|
const beforeId = beforePkg ? packageMeta(beforePkg).id : void 0;
|
|
9525
10933
|
const output = await npm2(["install", "--no-audit", "--no-fund", "--ignore-scripts", "--save-exact", spec], dir);
|
|
@@ -9572,8 +10980,8 @@ async function removePlugin(id, o) {
|
|
|
9572
10980
|
if (rel.startsWith("..") || rel === "") return { removed: false, reason: `it was loaded from ${origin}, outside the plugins folder` };
|
|
9573
10981
|
const parts = rel.split(sep);
|
|
9574
10982
|
if (parts[0] === "node_modules") {
|
|
9575
|
-
const
|
|
9576
|
-
await (o.npm ?? realNpm)(["uninstall", "--no-audit", "--no-fund",
|
|
10983
|
+
const name2 = parts[1].startsWith("@") ? `${parts[1]}/${parts[2]}` : parts[1];
|
|
10984
|
+
await (o.npm ?? realNpm)(["uninstall", "--no-audit", "--no-fund", name2], dir);
|
|
9577
10985
|
} else {
|
|
9578
10986
|
const top = join15(dir, parts[0]);
|
|
9579
10987
|
if (!lstatSync2(top).isSymbolicLink()) return { removed: false, reason: `${top} is a folder you put there: delete it yourself if you mean it` };
|
|
@@ -9590,7 +10998,7 @@ async function reloadPlugin(id, o) {
|
|
|
9590
10998
|
}
|
|
9591
10999
|
|
|
9592
11000
|
// packages/server/src/store.ts
|
|
9593
|
-
import { existsSync as existsSync13, mkdirSync as mkdirSync10, readFileSync as
|
|
11001
|
+
import { existsSync as existsSync13, mkdirSync as mkdirSync10, readFileSync as readFileSync9, renameSync as renameSync4, writeFileSync as writeFileSync11 } from "node:fs";
|
|
9594
11002
|
import { dirname as dirname6, join as join16 } from "node:path";
|
|
9595
11003
|
var STORE_URL = "https://kioskolcd.dev/store/v1/";
|
|
9596
11004
|
function shipped(...candidates) {
|
|
@@ -9600,7 +11008,7 @@ function shipped(...candidates) {
|
|
|
9600
11008
|
function snapshotIndex() {
|
|
9601
11009
|
const file = shipped(join16(import.meta.dirname, "../assets/store-index.json"), join16(import.meta.dirname, "assets/store-index.json"));
|
|
9602
11010
|
try {
|
|
9603
|
-
return file ? JSON.parse(
|
|
11011
|
+
return file ? JSON.parse(readFileSync9(file, "utf8")) : null;
|
|
9604
11012
|
} catch {
|
|
9605
11013
|
return null;
|
|
9606
11014
|
}
|
|
@@ -9609,7 +11017,7 @@ var schema;
|
|
|
9609
11017
|
function indexSchema() {
|
|
9610
11018
|
if (schema !== void 0) return schema;
|
|
9611
11019
|
const file = shipped(join16(import.meta.dirname, "../../core/schema/store-index.json"), join16(import.meta.dirname, "assets/store-index.schema.json"));
|
|
9612
|
-
schema = file ? JSON.parse(
|
|
11020
|
+
schema = file ? JSON.parse(readFileSync9(file, "utf8")) : null;
|
|
9613
11021
|
return schema;
|
|
9614
11022
|
}
|
|
9615
11023
|
function indexProblem(x) {
|
|
@@ -9641,7 +11049,7 @@ var StoreCatalog = class {
|
|
|
9641
11049
|
}
|
|
9642
11050
|
readCache() {
|
|
9643
11051
|
try {
|
|
9644
|
-
const c = JSON.parse(
|
|
11052
|
+
const c = JSON.parse(readFileSync9(this.file, "utf8"));
|
|
9645
11053
|
return indexProblem(c.index) ? null : c;
|
|
9646
11054
|
} catch {
|
|
9647
11055
|
return null;
|
|
@@ -9706,10 +11114,10 @@ var StoreCatalog = class {
|
|
|
9706
11114
|
};
|
|
9707
11115
|
|
|
9708
11116
|
// packages/server/src/homeassistant.ts
|
|
9709
|
-
import { hostname } from "node:os";
|
|
11117
|
+
import { hostname as hostname3 } from "node:os";
|
|
9710
11118
|
|
|
9711
11119
|
// packages/server/src/mqtt.ts
|
|
9712
|
-
import { EventEmitter as
|
|
11120
|
+
import { EventEmitter as EventEmitter3 } from "node:events";
|
|
9713
11121
|
import { connect as tcp } from "node:net";
|
|
9714
11122
|
import { connect as tls } from "node:tls";
|
|
9715
11123
|
var RETRY_MS2 = [2e3, 5e3, 1e4, 3e4, 6e4];
|
|
@@ -9782,7 +11190,7 @@ var CONNACK_ERRORS = {
|
|
|
9782
11190
|
4: "wrong user name or password",
|
|
9783
11191
|
5: "not authorised"
|
|
9784
11192
|
};
|
|
9785
|
-
var MqttClient = class extends
|
|
11193
|
+
var MqttClient = class extends EventEmitter3 {
|
|
9786
11194
|
state = "connecting";
|
|
9787
11195
|
error = null;
|
|
9788
11196
|
sock = null;
|
|
@@ -9923,10 +11331,10 @@ function pageOptions(screen, auto) {
|
|
|
9923
11331
|
const byName = /* @__PURE__ */ new Map([[auto, null]]);
|
|
9924
11332
|
const nameOf = /* @__PURE__ */ new Map();
|
|
9925
11333
|
for (const p of screen.pages.filter((x) => x.enabled)) {
|
|
9926
|
-
let
|
|
9927
|
-
for (let i = 2; byName.has(
|
|
9928
|
-
byName.set(
|
|
9929
|
-
nameOf.set(p.id,
|
|
11334
|
+
let name2 = p.name.trim() || p.id;
|
|
11335
|
+
for (let i = 2; byName.has(name2); i++) name2 = `${p.name} (${i})`;
|
|
11336
|
+
byName.set(name2, p.id);
|
|
11337
|
+
nameOf.set(p.id, name2);
|
|
9930
11338
|
}
|
|
9931
11339
|
return { options: [...byName.keys()], byName, nameOf };
|
|
9932
11340
|
}
|
|
@@ -9989,7 +11397,7 @@ var HomeAssistantBridge = class {
|
|
|
9989
11397
|
const base3 = `kiosko/${want.nodeId}`;
|
|
9990
11398
|
const c = this.makeClient({
|
|
9991
11399
|
url: want.broker,
|
|
9992
|
-
clientId: `kiosko-${want.nodeId}-${
|
|
11400
|
+
clientId: `kiosko-${want.nodeId}-${hostname3().slice(0, 20)}`.slice(0, 23),
|
|
9993
11401
|
...want.username ? { username: want.username } : {},
|
|
9994
11402
|
...want.password ? { password: want.password } : {},
|
|
9995
11403
|
keepalive: 30,
|
|
@@ -10089,9 +11497,9 @@ var HomeAssistantBridge = class {
|
|
|
10089
11497
|
});
|
|
10090
11498
|
for (const slot of screen.interludes) {
|
|
10091
11499
|
const def = this.runtime.registry.interlude(slot.type);
|
|
10092
|
-
const
|
|
11500
|
+
const name2 = def ? this.loc(def.name) || slot.type : slot.type;
|
|
10093
11501
|
put("button", `${sid}_${slug3(slot.id)}`, {
|
|
10094
|
-
name: `${this.loc(NAMES.interlude)}: ${
|
|
11502
|
+
name: `${this.loc(NAMES.interlude)}: ${name2}`,
|
|
10095
11503
|
unique_id: id(slug3(slot.id)),
|
|
10096
11504
|
icon: "mdi:play-circle-outline",
|
|
10097
11505
|
command_topic: `${this.base}/${sid}/interlude/${slot.id}/press`,
|
|
@@ -10167,42 +11575,42 @@ var HomeAssistantBridge = class {
|
|
|
10167
11575
|
};
|
|
10168
11576
|
|
|
10169
11577
|
// packages/server/src/install-kind.ts
|
|
10170
|
-
import { existsSync as existsSync14, readFileSync as
|
|
11578
|
+
import { existsSync as existsSync14, readFileSync as readFileSync10, realpathSync } from "node:fs";
|
|
10171
11579
|
import { posix, win32 as win323 } from "node:path";
|
|
10172
11580
|
function detectInstall(i) {
|
|
10173
11581
|
const exists = i.exists ?? existsSync14;
|
|
10174
|
-
const read = i.readFile ?? ((p) =>
|
|
11582
|
+
const read = i.readFile ?? ((p) => readFileSync10(p, "utf8"));
|
|
10175
11583
|
const win = i.platform === "win32";
|
|
10176
|
-
const
|
|
11584
|
+
const P2 = win ? win323 : posix;
|
|
10177
11585
|
const cli = i.cli;
|
|
10178
|
-
const
|
|
10179
|
-
const base3 = { cli, service, platform: i.platform };
|
|
11586
|
+
const service2 = detectService(i.platform, i.env, read);
|
|
11587
|
+
const base3 = { cli, service: service2, platform: i.platform };
|
|
10180
11588
|
const norm = (p) => win ? p.toLowerCase() : p;
|
|
10181
11589
|
const gitUp = (from) => {
|
|
10182
11590
|
for (let d = from, n = 0; n < 8; n++) {
|
|
10183
|
-
if (exists(
|
|
10184
|
-
const up =
|
|
11591
|
+
if (exists(P2.join(d, ".git"))) return d;
|
|
11592
|
+
const up = P2.dirname(d);
|
|
10185
11593
|
if (up === d) break;
|
|
10186
11594
|
d = up;
|
|
10187
11595
|
}
|
|
10188
11596
|
return null;
|
|
10189
11597
|
};
|
|
10190
|
-
if (cli.endsWith(".ts")) return { ...base3, kind: "source", dir: gitUp(
|
|
10191
|
-
const dir =
|
|
10192
|
-
if (win &&
|
|
10193
|
-
const app =
|
|
10194
|
-
if (exists(
|
|
10195
|
-
const local = i.env.LOCALAPPDATA && norm(app).startsWith(norm(
|
|
11598
|
+
if (cli.endsWith(".ts")) return { ...base3, kind: "source", dir: gitUp(P2.dirname(cli)) ?? P2.resolve(P2.dirname(cli), "..", "..", "..") };
|
|
11599
|
+
const dir = P2.dirname(cli);
|
|
11600
|
+
if (win && P2.basename(dir).toLowerCase() === "app") {
|
|
11601
|
+
const app = P2.dirname(dir);
|
|
11602
|
+
if (exists(P2.join(app, "kiosko.cmd")) && exists(P2.join(app, "unins000.exe")) && norm(i.execPath) === norm(P2.join(app, "node.exe"))) {
|
|
11603
|
+
const local = i.env.LOCALAPPDATA && norm(app).startsWith(norm(P2.join(i.env.LOCALAPPDATA, "Programs") + P2.sep));
|
|
10196
11604
|
return { ...base3, kind: "windows-installer", dir: app, perUser: !!local };
|
|
10197
11605
|
}
|
|
10198
11606
|
}
|
|
10199
11607
|
const checkout = gitUp(dir);
|
|
10200
11608
|
if (checkout && !/[\\/]node_modules[\\/]/.test(dir)) return { ...base3, kind: "source", dir: checkout };
|
|
10201
11609
|
if (/[\\/]_npx[\\/]/.test(dir)) return { ...base3, kind: "npx", dir };
|
|
10202
|
-
if (
|
|
10203
|
-
const nm =
|
|
10204
|
-
const prefix = win ?
|
|
10205
|
-
const shim = prefix && (win ? exists(
|
|
11610
|
+
if (P2.basename(dir) === "kiosko" && P2.basename(P2.dirname(dir)) === "node_modules") {
|
|
11611
|
+
const nm = P2.dirname(dir);
|
|
11612
|
+
const prefix = win ? P2.dirname(nm) : P2.basename(P2.dirname(nm)) === "lib" ? P2.dirname(P2.dirname(nm)) : null;
|
|
11613
|
+
const shim = prefix && (win ? exists(P2.join(prefix, "kiosko.cmd")) : exists(P2.join(prefix, "bin", "kiosko")));
|
|
10206
11614
|
if (prefix && shim) return { ...base3, kind: "npm-global", dir, prefix };
|
|
10207
11615
|
}
|
|
10208
11616
|
return { ...base3, kind: "other", dir };
|
|
@@ -10250,8 +11658,8 @@ function updateBlocker(info, o = {}) {
|
|
|
10250
11658
|
|
|
10251
11659
|
// packages/server/src/self-update.ts
|
|
10252
11660
|
import { spawn } from "node:child_process";
|
|
10253
|
-
import { createHash } from "node:crypto";
|
|
10254
|
-
import { createReadStream, createWriteStream, existsSync as existsSync15, mkdirSync as mkdirSync11, readFileSync as
|
|
11661
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
11662
|
+
import { createReadStream, createWriteStream, existsSync as existsSync15, mkdirSync as mkdirSync11, readFileSync as readFileSync11, realpathSync as realpathSync2, rmSync as rmSync4, writeFileSync as writeFileSync12 } from "node:fs";
|
|
10255
11663
|
import { dirname as dirname7, join as join17, win32 as win324 } from "node:path";
|
|
10256
11664
|
import { Readable, Transform } from "node:stream";
|
|
10257
11665
|
import { pipeline } from "node:stream/promises";
|
|
@@ -10287,15 +11695,15 @@ function judgeSelfCheck(now, next, target) {
|
|
|
10287
11695
|
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
11696
|
return { ok: true, warnings };
|
|
10289
11697
|
}
|
|
10290
|
-
function parseSha256File(text3,
|
|
11698
|
+
function parseSha256File(text3, name2) {
|
|
10291
11699
|
for (const line of text3.split(/\r?\n/)) {
|
|
10292
11700
|
const m = /^([a-f0-9]{64})(?:\s+\*?(.+?))?\s*$/i.exec(line.trim());
|
|
10293
|
-
if (m && (!m[2] || m[2] ===
|
|
11701
|
+
if (m && (!m[2] || m[2] === name2)) return m[1].toLowerCase();
|
|
10294
11702
|
}
|
|
10295
11703
|
return null;
|
|
10296
11704
|
}
|
|
10297
11705
|
async function sha256File(file) {
|
|
10298
|
-
const h =
|
|
11706
|
+
const h = createHash3("sha256");
|
|
10299
11707
|
await pipeline(createReadStream(file), h);
|
|
10300
11708
|
return h.digest("hex");
|
|
10301
11709
|
}
|
|
@@ -10348,10 +11756,10 @@ var KioskoUpdater = class {
|
|
|
10348
11756
|
}
|
|
10349
11757
|
step(code, ok, detail) {
|
|
10350
11758
|
const steps = [...this.status.steps];
|
|
10351
|
-
const
|
|
10352
|
-
const keep = detail ?? (
|
|
11759
|
+
const open2 = steps.findLastIndex((s2) => s2.code === code && s2.ok === null);
|
|
11760
|
+
const keep = detail ?? (open2 >= 0 ? steps[open2].detail : void 0);
|
|
10353
11761
|
const s = { at: this.now, code, ok, ...keep ? { detail: keep } : {} };
|
|
10354
|
-
if (
|
|
11762
|
+
if (open2 >= 0 && ok !== null) steps[open2] = s;
|
|
10355
11763
|
else steps.push(s);
|
|
10356
11764
|
if (ok !== null || detail) this.say(`${code}${ok === false ? " failed" : ok ? " ok" : ""}${detail ? `: ${detail}` : ""}`);
|
|
10357
11765
|
this.set({ steps });
|
|
@@ -10526,27 +11934,27 @@ var KioskoUpdater = class {
|
|
|
10526
11934
|
}
|
|
10527
11935
|
// ---------- Windows ----------
|
|
10528
11936
|
async downloadInstaller(version) {
|
|
10529
|
-
const
|
|
10530
|
-
const exeUrl = releaseAsset(version,
|
|
11937
|
+
const name2 = windowsInstallerName(version);
|
|
11938
|
+
const exeUrl = releaseAsset(version, name2);
|
|
10531
11939
|
const dir = join17(this.d.tmpDir, `kiosko-update-${version}`);
|
|
10532
11940
|
rmSync4(dir, { recursive: true, force: true });
|
|
10533
11941
|
mkdirSync11(dir, { recursive: true });
|
|
10534
|
-
const file = join17(dir,
|
|
11942
|
+
const file = join17(dir, name2);
|
|
10535
11943
|
this.step("download", null, exeUrl);
|
|
10536
11944
|
let expected;
|
|
10537
11945
|
try {
|
|
10538
11946
|
const r = await this.d.fetch(`${exeUrl}.sha256`, { redirect: "follow" });
|
|
10539
11947
|
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
|
10540
|
-
expected = parseSha256File((await r.text()).slice(0, 4096),
|
|
11948
|
+
expected = parseSha256File((await r.text()).slice(0, 4096), name2);
|
|
10541
11949
|
} catch (err) {
|
|
10542
|
-
this.step("download", false, `${
|
|
10543
|
-
throw new UpdateError("downloadFailed", `could not download ${
|
|
11950
|
+
this.step("download", false, `${name2}.sha256: ${err instanceof Error ? err.message : String(err)}`);
|
|
11951
|
+
throw new UpdateError("downloadFailed", `could not download ${name2}.sha256 from GitHub: download the installer from the release page instead`);
|
|
10544
11952
|
}
|
|
10545
11953
|
if (!expected) {
|
|
10546
|
-
this.step("download", false, `${
|
|
10547
|
-
throw new UpdateError("hashMissing", `the release has no usable checksum for ${
|
|
11954
|
+
this.step("download", false, `${name2}.sha256 names no checksum for ${name2}`);
|
|
11955
|
+
throw new UpdateError("hashMissing", `the release has no usable checksum for ${name2}: not running it`);
|
|
10548
11956
|
}
|
|
10549
|
-
const hash =
|
|
11957
|
+
const hash = createHash3("sha256");
|
|
10550
11958
|
let size = 0;
|
|
10551
11959
|
try {
|
|
10552
11960
|
const r = await this.d.fetch(exeUrl, { redirect: "follow" });
|
|
@@ -10563,14 +11971,14 @@ var KioskoUpdater = class {
|
|
|
10563
11971
|
} catch (err) {
|
|
10564
11972
|
rmSync4(dir, { recursive: true, force: true });
|
|
10565
11973
|
this.step("download", false, err instanceof Error ? err.message : String(err));
|
|
10566
|
-
throw new UpdateError("downloadFailed", `could not download ${
|
|
11974
|
+
throw new UpdateError("downloadFailed", `could not download ${name2}: ${err instanceof Error ? err.message : String(err)}`);
|
|
10567
11975
|
}
|
|
10568
11976
|
this.step("download", true, `${(size / 1024 / 1024).toFixed(1)} MB`);
|
|
10569
11977
|
const got = hash.digest("hex");
|
|
10570
11978
|
if (got !== expected) {
|
|
10571
11979
|
rmSync4(dir, { recursive: true, force: true });
|
|
10572
11980
|
this.step("hash", false, `sha256 ${got}, the release says ${expected}`);
|
|
10573
|
-
throw new UpdateError("hashMismatch", `${
|
|
11981
|
+
throw new UpdateError("hashMismatch", `${name2} is not the file the release publishes (sha256 ${got.slice(0, 12)}\u2026, expected ${expected.slice(0, 12)}\u2026): deleted, not run`);
|
|
10574
11982
|
}
|
|
10575
11983
|
this.step("hash", true, `sha256 ${got}`);
|
|
10576
11984
|
this.file = file;
|
|
@@ -10587,10 +11995,10 @@ var KioskoUpdater = class {
|
|
|
10587
11995
|
}
|
|
10588
11996
|
const info = this.d.install;
|
|
10589
11997
|
const dir = dirname7(this.file);
|
|
10590
|
-
const
|
|
11998
|
+
const service2 = await this.d.serviceTask?.().catch(() => false) ?? false;
|
|
10591
11999
|
const script = join17(dir, "kiosko-upgrade.cmd");
|
|
10592
12000
|
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 }));
|
|
12001
|
+
writeFileSync12(script, windowsUpgradeScript({ exe: this.file, args: installerArgs(!!info.perUser, join17(dir, "install.log")), dir: info.dir, service: service2, port: this.d.port, log }));
|
|
10594
12002
|
this.d.mark?.({ from: this.d.current, to: version, at: this.now, how: "installer", lines: this.lines.slice(-30) });
|
|
10595
12003
|
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
12004
|
this.set({ state: "restarting", restart: "installer" });
|
|
@@ -10633,7 +12041,7 @@ function readMarker(home, version, now = Date.now()) {
|
|
|
10633
12041
|
if (!existsSync15(f)) return null;
|
|
10634
12042
|
let m = {};
|
|
10635
12043
|
try {
|
|
10636
|
-
m = JSON.parse(
|
|
12044
|
+
m = JSON.parse(readFileSync11(f, "utf8"));
|
|
10637
12045
|
} catch {
|
|
10638
12046
|
}
|
|
10639
12047
|
rmSync4(f, { force: true });
|
|
@@ -10656,7 +12064,10 @@ var MIME = {
|
|
|
10656
12064
|
".woff2": "font/woff2",
|
|
10657
12065
|
".ico": "image/x-icon"
|
|
10658
12066
|
};
|
|
10659
|
-
var realDiscover = async (url2, tokenFile) =>
|
|
12067
|
+
var realDiscover = async (url2, tokenFile) => {
|
|
12068
|
+
const [trcc, usb, remote] = await Promise.all([discoverTrcc(url2, tokenFile), discoverUsb(), discoverRemote()]);
|
|
12069
|
+
return { trcc, usb, remote };
|
|
12070
|
+
};
|
|
10660
12071
|
function webRoot() {
|
|
10661
12072
|
const bundled = join18(import.meta.dirname, "web");
|
|
10662
12073
|
if (existsSync16(join18(bundled, "index.html"))) return bundled;
|
|
@@ -10710,7 +12121,7 @@ function startServer(o) {
|
|
|
10710
12121
|
const install = o.install ?? currentInstall();
|
|
10711
12122
|
const registryUrl = o.selfUpdate?.registry ?? npmRegistry();
|
|
10712
12123
|
const blocker = updateBlocker(install, { demo: runtime.demoMode });
|
|
10713
|
-
const instance =
|
|
12124
|
+
const instance = randomBytes4(8).toString("hex");
|
|
10714
12125
|
const how = o.selfUpdate?.restartHow ?? restartHow(install, { tty: !!process.stdout.isTTY, pid: process.pid });
|
|
10715
12126
|
const probeHost = o.host === "0.0.0.0" || o.host === "::" ? "127.0.0.1" : o.host.includes(":") ? `[${o.host}]` : o.host;
|
|
10716
12127
|
const handover = {
|
|
@@ -10853,6 +12264,18 @@ data: ${JSON.stringify(data)}
|
|
|
10853
12264
|
platform: process.platform
|
|
10854
12265
|
};
|
|
10855
12266
|
}
|
|
12267
|
+
const remote = remoteApi({
|
|
12268
|
+
runtime,
|
|
12269
|
+
json,
|
|
12270
|
+
body,
|
|
12271
|
+
commit: (cfg) => {
|
|
12272
|
+
const c = normalize(cfg);
|
|
12273
|
+
saveConfig(c, o.configPath);
|
|
12274
|
+
rev++;
|
|
12275
|
+
runtime.apply(c);
|
|
12276
|
+
send("config", { rev, by: null });
|
|
12277
|
+
}
|
|
12278
|
+
});
|
|
10856
12279
|
function findScreen(cfg, id) {
|
|
10857
12280
|
return cfg.screens.find((s) => s.id === id);
|
|
10858
12281
|
}
|
|
@@ -10863,9 +12286,9 @@ data: ${JSON.stringify(data)}
|
|
|
10863
12286
|
if (p === "/api/state" && m === "GET") return json(res, 200, state(req));
|
|
10864
12287
|
if (p === "/api/config" && m === "PUT") {
|
|
10865
12288
|
const b = await body(req);
|
|
10866
|
-
const
|
|
12289
|
+
const raw2 = b && typeof b === "object" && "config" in b ? b.config : b;
|
|
10867
12290
|
if (typeof b?.baseRev === "number" && b.baseRev !== rev) return json(res, 409, { error: "the configuration changed elsewhere", code: "conflict", rev, config: runtime.config });
|
|
10868
|
-
const cfg = normalize(
|
|
12291
|
+
const cfg = normalize(raw2);
|
|
10869
12292
|
saveConfig(cfg, o.configPath);
|
|
10870
12293
|
rev++;
|
|
10871
12294
|
runtime.apply(cfg);
|
|
@@ -10979,6 +12402,7 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
10979
12402
|
runtime.refreshWidget(decodeURIComponent(mm[1]));
|
|
10980
12403
|
return json(res, 200, { ok: true });
|
|
10981
12404
|
}
|
|
12405
|
+
if ((p.startsWith("/api/remote/") || /^\/api\/screens\/[^/]+\/remote\//.test(p)) && await remote(req, res, p, m)) return;
|
|
10982
12406
|
if (p === "/api/devices/discover" && m === "GET") {
|
|
10983
12407
|
const url0 = url2.searchParams.get("url") ?? "http://127.0.0.1:8099";
|
|
10984
12408
|
return json(res, 200, await (o.discover ?? realDiscover)(url0, url2.searchParams.get("tokenFile") ?? void 0));
|
|
@@ -11016,9 +12440,9 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
11016
12440
|
}
|
|
11017
12441
|
if (p === "/api/plugins/install" && m === "POST") {
|
|
11018
12442
|
const b = await body(req);
|
|
11019
|
-
const
|
|
12443
|
+
const name2 = String(b.name ?? "").trim();
|
|
11020
12444
|
try {
|
|
11021
|
-
const r = await installPlugin(
|
|
12445
|
+
const r = await installPlugin(name2, { registry: runtime.registry, runtime });
|
|
11022
12446
|
if (r.restart) restartNeeded = true;
|
|
11023
12447
|
rev++;
|
|
11024
12448
|
send("config", { rev, by: null });
|
|
@@ -11154,7 +12578,7 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
11154
12578
|
}
|
|
11155
12579
|
const ext = extname(file);
|
|
11156
12580
|
res.writeHead(200, { "content-type": MIME[ext] ?? "application/octet-stream", "cache-control": ext === ".html" ? "no-cache" : "max-age=300" });
|
|
11157
|
-
res.end(
|
|
12581
|
+
res.end(readFileSync12(file));
|
|
11158
12582
|
}
|
|
11159
12583
|
const server = createServer((req, res) => {
|
|
11160
12584
|
const host = req.headers.host ?? "";
|
|
@@ -11195,7 +12619,7 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
11195
12619
|
import { existsSync as existsSync17, readdirSync as readdirSync5 } from "node:fs";
|
|
11196
12620
|
import { homedir as homedir5 } from "node:os";
|
|
11197
12621
|
import { join as join19 } from "node:path";
|
|
11198
|
-
var
|
|
12622
|
+
var ROTATIONS2 = [0, 90, 180, 270];
|
|
11199
12623
|
function starterPanels(found, trccUrl = "http://127.0.0.1:8099") {
|
|
11200
12624
|
const out = [];
|
|
11201
12625
|
const named = (width, height) => {
|
|
@@ -11207,7 +12631,7 @@ function starterPanels(found, trccUrl = "http://127.0.0.1:8099") {
|
|
|
11207
12631
|
for (const u of found.usb) {
|
|
11208
12632
|
const width = u.width || 1920;
|
|
11209
12633
|
const height = u.height || 462;
|
|
11210
|
-
out.push({ name: named(width, height), width, height, rotate:
|
|
12634
|
+
out.push({ name: named(width, height), width, height, rotate: ROTATIONS2.includes(u.rotate ?? 0) ? u.rotate ?? 0 : 0, device: { driver: "usb", ...u.serial ? { serial: u.serial } : {} } });
|
|
11211
12635
|
}
|
|
11212
12636
|
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
12637
|
return out;
|
|
@@ -11226,8 +12650,8 @@ var CATS_PAGE = { en: "Cats room", es: "Sala de los gatos", de: "Katzenzimmer",
|
|
|
11226
12650
|
function starterConfig(registry2, o = {}) {
|
|
11227
12651
|
const locale = o.locale ?? "en";
|
|
11228
12652
|
const has = (t2) => !!registry2.widget(t2);
|
|
11229
|
-
const one = (
|
|
11230
|
-
const screen = newScreen(
|
|
12653
|
+
const one = (name2, width, height, device, rotate = 0) => {
|
|
12654
|
+
const screen = newScreen(name2, width, height, device);
|
|
11231
12655
|
screen.rotate = rotate;
|
|
11232
12656
|
screen.pages = [starterPage(has, { width, height, locale, agents: o.agents ?? true, weather: o.weather ?? true })];
|
|
11233
12657
|
if ((o.agents ?? true) && has("cats/room")) {
|
|
@@ -11244,7 +12668,7 @@ function starterConfig(registry2, o = {}) {
|
|
|
11244
12668
|
}
|
|
11245
12669
|
|
|
11246
12670
|
// packages/server/src/cli.ts
|
|
11247
|
-
var VERSION = "0.2.
|
|
12671
|
+
var VERSION = "0.2.10";
|
|
11248
12672
|
var USAGE2 = `Kiosko ${VERSION}: a widget mosaic for USB LCD panels
|
|
11249
12673
|
|
|
11250
12674
|
kiosko start [--port 7420] [--host 127.0.0.1] [--config file] [--open] [--demo]
|
|
@@ -11258,6 +12682,9 @@ var USAGE2 = `Kiosko ${VERSION}: a widget mosaic for USB LCD panels
|
|
|
11258
12682
|
kiosko usb [list] the LY panels libusb sees, with their serial numbers
|
|
11259
12683
|
kiosko usb test [--serial S] [--seconds 10] [--size 1920x462] [--rotate 180]
|
|
11260
12684
|
drive a panel with the sample screen (experimental)
|
|
12685
|
+
kiosko remote [list] Kiosko remote screens on the network (mDNS)
|
|
12686
|
+
kiosko remote pair <uid|host> [--screen id] pair one (type the code it shows)
|
|
12687
|
+
kiosko remote ota|logs|unpair <screen> [firmware.bin]
|
|
11261
12688
|
kiosko gallery [--out gallery] [--locale en | --all-languages] [--theme midnight] [--pages config.json]
|
|
11262
12689
|
kiosko plugins [list|add <id>\u2026|link <folder>\u2026|remove <id>\u2026]
|
|
11263
12690
|
kiosko service install|uninstall|print (start with your session)
|
|
@@ -11266,9 +12693,9 @@ var USAGE2 = `Kiosko ${VERSION}: a widget mosaic for USB LCD panels
|
|
|
11266
12693
|
var argv = process.argv.slice(2);
|
|
11267
12694
|
var FLAG_COMMANDS = /* @__PURE__ */ new Set(["--help", "-h", "--version", "-v"]);
|
|
11268
12695
|
var cmd = argv.includes("--help") || argv.includes("-h") ? "help" : argv[0] && (!argv[0].startsWith("-") || FLAG_COMMANDS.has(argv[0])) ? argv[0] : "start";
|
|
11269
|
-
var flag = (
|
|
11270
|
-
var opt = (
|
|
11271
|
-
const i = argv.indexOf(
|
|
12696
|
+
var flag = (name2) => argv.includes(name2);
|
|
12697
|
+
var opt = (name2) => {
|
|
12698
|
+
const i = argv.indexOf(name2);
|
|
11272
12699
|
return i >= 0 ? argv[i + 1] : void 0;
|
|
11273
12700
|
};
|
|
11274
12701
|
var SCREEN_THREAD = ["./screen-thread.js", "./screen-thread.ts"].map((f) => new URL(f, import.meta.url)).find((u) => existsSync18(u));
|
|
@@ -11282,8 +12709,8 @@ async function registry() {
|
|
|
11282
12709
|
if (r.plugin(o.id)) continue;
|
|
11283
12710
|
try {
|
|
11284
12711
|
const url2 = import.meta.resolve(o.npm);
|
|
11285
|
-
const
|
|
11286
|
-
if (
|
|
12712
|
+
const mod2 = await import(url2);
|
|
12713
|
+
if (mod2.default) r.add(mod2.default, `npm:${o.npm}`, url2);
|
|
11287
12714
|
} catch {
|
|
11288
12715
|
}
|
|
11289
12716
|
}
|
|
@@ -11383,12 +12810,12 @@ async function main() {
|
|
|
11383
12810
|
}
|
|
11384
12811
|
const reg = await registry();
|
|
11385
12812
|
const modePath = join20(dirname9(from), "modo");
|
|
11386
|
-
const modeOverride = existsSync18(modePath) ?
|
|
11387
|
-
const { config: imported, notes } = importAimonitor(JSON.parse(
|
|
12813
|
+
const modeOverride = existsSync18(modePath) ? readFileSync13(modePath, "utf8") : null;
|
|
12814
|
+
const { config: imported, notes } = importAimonitor(JSON.parse(readFileSync13(from, "utf8")), reg, modeOverride, { withSecrets: flag("--with-secrets") });
|
|
11388
12815
|
if (modeOverride) notes.push(`mode from ${modePath}: ${modeOverride.trim()}`);
|
|
11389
12816
|
for (const n of notes) console.log(`- ${n}`);
|
|
11390
12817
|
if (flag("--write")) {
|
|
11391
|
-
if (existsSync18(path)) writeFileSync13(`${path}.bak`,
|
|
12818
|
+
if (existsSync18(path)) writeFileSync13(`${path}.bak`, readFileSync13(path));
|
|
11392
12819
|
saveConfig(imported, path);
|
|
11393
12820
|
console.log(`written ${path}${existsSync18(`${path}.bak`) ? ` (previous one in ${path}.bak)` : ""}`);
|
|
11394
12821
|
} else {
|
|
@@ -11441,12 +12868,24 @@ async function main() {
|
|
|
11441
12868
|
if (!usb.ok) console.log(`usb not available: ${usb.error}`);
|
|
11442
12869
|
else if (!usb.panels.length) console.log("usb no LY panel (0416:5408/5409) plugged in");
|
|
11443
12870
|
for (const p of usb.panels) console.log(`usb LY panel ${p.pid.toString(16)} at ${p.location}, serial ${p.serial ?? "(unreadable)"}${p.error ? ` \u2717 ${p.error}` : ""}`);
|
|
12871
|
+
const remote = await discoverRemote(2e3);
|
|
12872
|
+
if (!remote.length) console.log("remote no Kiosko remote screen answered on this network (mDNS)");
|
|
12873
|
+
for (const r of remote) {
|
|
12874
|
+
const used = cfg.screens.find((s) => s.device.driver === "remote" && s.device.uid === r.uid);
|
|
12875
|
+
console.log(`remote ${r.id} (${r.model} ${r.width}\xD7${r.height}, fw ${r.fw}, uid ${r.uid}) at ${r.address}, ${r.paired ? "paired" : "not paired"}${used ? `, screen "${used.name}"` : ""}`);
|
|
12876
|
+
}
|
|
12877
|
+
for (const s of cfg.screens) if (s.device.driver === "remote" && !s.device.key) console.log(`remote \u2717 screen "${s.name}" is not paired: Screens \u2192 Detect panels \u2192 Pair`);
|
|
11444
12878
|
for (const s of cfg.screens) {
|
|
11445
12879
|
const missing = s.pages.flatMap((p) => p.tiles.flatMap((t2) => t2.widgets.filter((w) => !reg.widget(w.type)).map((w) => w.type)));
|
|
11446
12880
|
console.log(`screen ${s.name} ${s.width}\xD7${s.height} ${s.device.driver}${missing.length ? ` \u2717 unknown widgets: ${[...new Set(missing)].join(", ")}` : ""}`);
|
|
11447
12881
|
}
|
|
11448
12882
|
return;
|
|
11449
12883
|
}
|
|
12884
|
+
case "remote": {
|
|
12885
|
+
process.env.KIOSKO_QUIET ??= "1";
|
|
12886
|
+
process.exitCode = await remoteCommand(argv.slice(1), { configPath: path, port: Number(opt("--port")) || 7420, registry });
|
|
12887
|
+
return;
|
|
12888
|
+
}
|
|
11450
12889
|
case "service": {
|
|
11451
12890
|
const pass = ["--port", "--host", "--config"].flatMap((f) => opt(f) ? [f, opt(f)] : []);
|
|
11452
12891
|
const env = process.env.KIOSKO_HOME ? { KIOSKO_HOME: process.env.KIOSKO_HOME } : {};
|
|
@@ -11460,7 +12899,7 @@ async function main() {
|
|
|
11460
12899
|
const reg = await registry();
|
|
11461
12900
|
const out = opt("--out") ?? "gallery";
|
|
11462
12901
|
const sample = opt("--pages");
|
|
11463
|
-
const n = buildGallery(reg, { out, locale: opt("--locale") ?? "en", languages: flag("--all-languages"), theme: opt("--theme") ?? "midnight", ...sample ? { pages: JSON.parse(
|
|
12902
|
+
const n = buildGallery(reg, { out, locale: opt("--locale") ?? "en", languages: flag("--all-languages"), theme: opt("--theme") ?? "midnight", ...sample ? { pages: JSON.parse(readFileSync13(sample, "utf8")) } : {} });
|
|
11464
12903
|
console.log(`${n} widgets \u2192 ${out}/index.html`);
|
|
11465
12904
|
return;
|
|
11466
12905
|
}
|