kiosko 0.2.6 → 0.2.7
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 +6 -1
- package/assets/store-index.json +1 -0
- package/assets/store-index.schema.json +167 -0
- package/cli.js +1999 -293
- package/package.json +2 -1
- package/screen-thread.js +3937 -0
- package/sdk.js +5 -1
- package/web/assets/app.js +3 -3
- package/web/assets/styles.css +1 -1
package/cli.js
CHANGED
|
@@ -91,19 +91,19 @@ function plural(n, forms, locale = "en") {
|
|
|
91
91
|
rule = new Intl.PluralRules(key).select(n);
|
|
92
92
|
} catch {
|
|
93
93
|
}
|
|
94
|
-
const
|
|
94
|
+
const text3 = f[rule] ?? f.other;
|
|
95
95
|
let num = String(n);
|
|
96
96
|
try {
|
|
97
97
|
num = new Intl.NumberFormat(key).format(n);
|
|
98
98
|
} catch {
|
|
99
99
|
}
|
|
100
|
-
return
|
|
100
|
+
return text3.replaceAll("{n}", num);
|
|
101
101
|
}
|
|
102
|
-
function localize(
|
|
103
|
-
if (
|
|
104
|
-
if (typeof
|
|
105
|
-
const key = pickLocale(Object.keys(
|
|
106
|
-
return (key ?
|
|
102
|
+
function localize(text3, locale = "en") {
|
|
103
|
+
if (text3 === void 0) return "";
|
|
104
|
+
if (typeof text3 === "string") return text3;
|
|
105
|
+
const key = pickLocale(Object.keys(text3), locale);
|
|
106
|
+
return (key ? text3[key] : void 0) ?? text3.en ?? Object.values(text3).find((v) => typeof v === "string") ?? "";
|
|
107
107
|
}
|
|
108
108
|
function hanScript(locale) {
|
|
109
109
|
const l = parseLocale(locale || "en");
|
|
@@ -380,10 +380,10 @@ function createFormatters(o) {
|
|
|
380
380
|
return suffix ? w.ago(v, n) : v;
|
|
381
381
|
},
|
|
382
382
|
duration(ms, opts = {}) {
|
|
383
|
-
const
|
|
383
|
+
const round3 = opts.round === "up" ? Math.ceil : opts.round === "nearest" ? Math.round : Math.floor;
|
|
384
384
|
const safe2 = Number.isFinite(ms) ? Math.max(0, ms) : 0;
|
|
385
|
-
if (opts.seconds && safe2 < 6e4) return w.s(
|
|
386
|
-
const min =
|
|
385
|
+
if (opts.seconds && safe2 < 6e4) return w.s(round3(safe2 / 1e3));
|
|
386
|
+
const min = round3(safe2 / 6e4);
|
|
387
387
|
if (min < 60) return w.min(min);
|
|
388
388
|
const h = Math.floor(min / 60);
|
|
389
389
|
if (h < 24) return opts.compact && min % 60 === 0 ? w.h(h) : w.hm(h, min % 60);
|
|
@@ -450,7 +450,7 @@ function createBaseContext(o) {
|
|
|
450
450
|
return {
|
|
451
451
|
now: o.now,
|
|
452
452
|
locale,
|
|
453
|
-
t: (
|
|
453
|
+
t: (text3) => localize(text3, locale),
|
|
454
454
|
plural: (n, forms) => plural(n, forms, locale),
|
|
455
455
|
pickLanguage: (available2) => pickLocale(available2, locale) ?? (available2.includes("en") ? "en" : available2[0] ?? "en"),
|
|
456
456
|
fmt: createFormatters({ locale, timeFormat: o.timeFormat ?? "auto", now: o.now }),
|
|
@@ -497,11 +497,11 @@ function widthOf(ctx, font, ch) {
|
|
|
497
497
|
function clearTextCache() {
|
|
498
498
|
widths.clear();
|
|
499
499
|
}
|
|
500
|
-
function hasCjk(
|
|
501
|
-
return CJK.test(
|
|
500
|
+
function hasCjk(text3) {
|
|
501
|
+
return CJK.test(text3);
|
|
502
502
|
}
|
|
503
|
-
function trackingOf(
|
|
504
|
-
return o.tracking && hasCjk(
|
|
503
|
+
function trackingOf(text3, o) {
|
|
504
|
+
return o.tracking && hasCjk(text3) ? 0 : o.tracking ?? 0;
|
|
505
505
|
}
|
|
506
506
|
function setMinCjkPx(px) {
|
|
507
507
|
if (px !== minCjkPx) widths.clear();
|
|
@@ -516,9 +516,9 @@ function scaleOf(ctx) {
|
|
|
516
516
|
const t2 = ctx.getTransform?.();
|
|
517
517
|
return t2 ? Math.hypot(t2.a, t2.b) || 1 : 1;
|
|
518
518
|
}
|
|
519
|
-
function glyphs(ctx,
|
|
519
|
+
function glyphs(ctx, text3, o) {
|
|
520
520
|
const family = o.family ?? defaultFamily;
|
|
521
|
-
const cjk = hasCjk(
|
|
521
|
+
const cjk = hasCjk(text3);
|
|
522
522
|
const small = o.smallCaps === true && !cjk;
|
|
523
523
|
const capSize = o.size * (o.capRatio ?? 0.76);
|
|
524
524
|
const out = [];
|
|
@@ -533,7 +533,7 @@ function glyphs(ctx, text2, o) {
|
|
|
533
533
|
}
|
|
534
534
|
}
|
|
535
535
|
const cjkFont = `${cjkSize}px "${family}"`;
|
|
536
|
-
for (const ch of
|
|
536
|
+
for (const ch of text3) {
|
|
537
537
|
if (cjkSize !== o.size && CJK.test(ch)) {
|
|
538
538
|
out.push({ ch, size: cjkSize, width: widthOf(ctx, cjkFont, ch) });
|
|
539
539
|
continue;
|
|
@@ -549,13 +549,13 @@ function advance(gs, tracking) {
|
|
|
549
549
|
if (!gs.length) return 0;
|
|
550
550
|
return gs.reduce((a, g) => a + g.width, 0) + tracking * (gs.length - 1);
|
|
551
551
|
}
|
|
552
|
-
function measureTracked(ctx,
|
|
553
|
-
return advance(glyphs(ctx,
|
|
552
|
+
function measureTracked(ctx, text3, o) {
|
|
553
|
+
return advance(glyphs(ctx, text3, o), trackingOf(text3, o));
|
|
554
554
|
}
|
|
555
|
-
function drawTracked(ctx,
|
|
555
|
+
function drawTracked(ctx, text3, x, y, o) {
|
|
556
556
|
const family = o.family ?? defaultFamily;
|
|
557
|
-
const tracking = trackingOf(
|
|
558
|
-
const gs = glyphs(ctx,
|
|
557
|
+
const tracking = trackingOf(text3, o);
|
|
558
|
+
const gs = glyphs(ctx, text3, o);
|
|
559
559
|
const total = advance(gs, tracking);
|
|
560
560
|
let cursor = o.align === "right" ? x - total : o.align === "center" ? x - total / 2 : x;
|
|
561
561
|
if (o.color) ctx.fillStyle = o.color;
|
|
@@ -571,9 +571,9 @@ function drawTracked(ctx, text2, x, y, o) {
|
|
|
571
571
|
}
|
|
572
572
|
return total;
|
|
573
573
|
}
|
|
574
|
-
function truncate(ctx,
|
|
575
|
-
if (measureTracked(ctx,
|
|
576
|
-
const chars = [...
|
|
574
|
+
function truncate(ctx, text3, maxWidth, o) {
|
|
575
|
+
if (measureTracked(ctx, text3, o) <= maxWidth) return text3;
|
|
576
|
+
const chars = [...text3];
|
|
577
577
|
const candidate = (n) => `${chars.slice(0, n).join("").trimEnd()}\u2026`;
|
|
578
578
|
let lo = 0;
|
|
579
579
|
let hi = chars.length;
|
|
@@ -584,17 +584,17 @@ function truncate(ctx, text2, maxWidth, o) {
|
|
|
584
584
|
}
|
|
585
585
|
return lo > 0 ? candidate(lo) : "\u2026";
|
|
586
586
|
}
|
|
587
|
-
function fitSize(ctx,
|
|
587
|
+
function fitSize(ctx, text3, maxWidth, o, minSize) {
|
|
588
588
|
let size = o.size;
|
|
589
|
-
while (size > minSize && measureTracked(ctx,
|
|
589
|
+
while (size > minSize && measureTracked(ctx, text3, { ...o, size }) > maxWidth) size -= 1;
|
|
590
590
|
return size;
|
|
591
591
|
}
|
|
592
|
-
function drawClipped(ctx,
|
|
593
|
-
return drawTracked(ctx, truncate(ctx,
|
|
592
|
+
function drawClipped(ctx, text3, x, y, maxWidth, o) {
|
|
593
|
+
return drawTracked(ctx, truncate(ctx, text3, maxWidth, o), x, y, o);
|
|
594
594
|
}
|
|
595
|
-
function fitPrefix(ctx,
|
|
596
|
-
if (measureTracked(ctx,
|
|
597
|
-
const chars = [...
|
|
595
|
+
function fitPrefix(ctx, text3, maxWidth, o) {
|
|
596
|
+
if (measureTracked(ctx, text3, o) <= maxWidth) return text3.length;
|
|
597
|
+
const chars = [...text3];
|
|
598
598
|
let lo = 1;
|
|
599
599
|
let hi = chars.length;
|
|
600
600
|
while (lo < hi) {
|
|
@@ -602,7 +602,7 @@ function fitPrefix(ctx, text2, maxWidth, o) {
|
|
|
602
602
|
if (measureTracked(ctx, chars.slice(0, mid).join(""), o) <= maxWidth) lo = mid;
|
|
603
603
|
else hi = mid - 1;
|
|
604
604
|
}
|
|
605
|
-
const cjk = hasCjk(
|
|
605
|
+
const cjk = hasCjk(text3);
|
|
606
606
|
const fits = (i) => !NO_START.has(chars[i]) && !NO_END.has(chars[i - 1]);
|
|
607
607
|
let cut = 0;
|
|
608
608
|
for (let i = lo; i >= 1; i--) {
|
|
@@ -619,8 +619,8 @@ function fitPrefix(ctx, text2, maxWidth, o) {
|
|
|
619
619
|
}
|
|
620
620
|
return chars.slice(0, cut).join("").length;
|
|
621
621
|
}
|
|
622
|
-
function wrapLines(ctx,
|
|
623
|
-
const clean =
|
|
622
|
+
function wrapLines(ctx, text3, maxWidth, maxLines, o) {
|
|
623
|
+
const clean = text3.replace(/\s+/g, " ").trim();
|
|
624
624
|
if (!clean || maxLines < 1 || maxWidth <= 0) return [];
|
|
625
625
|
const lines = [];
|
|
626
626
|
let rest = clean;
|
|
@@ -1003,9 +1003,11 @@ var testing_exports = {};
|
|
|
1003
1003
|
__export(testing_exports, {
|
|
1004
1004
|
checkPlugin: () => checkPlugin,
|
|
1005
1005
|
renderWidget: () => renderWidget,
|
|
1006
|
+
sourceAlerts: () => sourceAlerts,
|
|
1007
|
+
widgetAlerts: () => widgetAlerts,
|
|
1006
1008
|
widgetState: () => widgetState
|
|
1007
1009
|
});
|
|
1008
|
-
import { createCanvas as
|
|
1010
|
+
import { createCanvas as createCanvas7, loadImage as loadImage4 } from "@napi-rs/canvas";
|
|
1009
1011
|
function resolve3(w, o) {
|
|
1010
1012
|
const now = o.now ?? Date.UTC(2026, 10, 5, 9, 42);
|
|
1011
1013
|
const locale = o.locale ?? "en";
|
|
@@ -1022,7 +1024,7 @@ function renderWidget(w, o = {}) {
|
|
|
1022
1024
|
const theme = typeof o.theme === "object" ? o.theme : themeById(o.theme);
|
|
1023
1025
|
const texts = [];
|
|
1024
1026
|
const spy = { ...src_exports, drawTracked: (...a) => (texts.push(a[1]), drawTracked(...a)) };
|
|
1025
|
-
const canvas =
|
|
1027
|
+
const canvas = createCanvas7(size.w + 2 * MARGIN, size.h + 2 * MARGIN);
|
|
1026
1028
|
const g = canvas.getContext("2d");
|
|
1027
1029
|
const box = { x: MARGIN, y: MARGIN, w: size.w, h: size.h };
|
|
1028
1030
|
const ctx = {
|
|
@@ -1035,7 +1037,7 @@ function renderWidget(w, o = {}) {
|
|
|
1035
1037
|
theme,
|
|
1036
1038
|
fonts: theme.fonts,
|
|
1037
1039
|
kit: spy,
|
|
1038
|
-
canvas: { createCanvas:
|
|
1040
|
+
canvas: { createCanvas: createCanvas7, loadImage: loadImage4 },
|
|
1039
1041
|
preview: !!o.preview
|
|
1040
1042
|
};
|
|
1041
1043
|
const t0 = performance.now();
|
|
@@ -1063,7 +1065,7 @@ function renderWidget(w, o = {}) {
|
|
|
1063
1065
|
ms,
|
|
1064
1066
|
...error !== void 0 ? { error } : {},
|
|
1065
1067
|
png() {
|
|
1066
|
-
const out =
|
|
1068
|
+
const out = createCanvas7(box.w, box.h);
|
|
1067
1069
|
out.getContext("2d").drawImage(canvas, -box.x, -box.y);
|
|
1068
1070
|
return out.toBuffer("image/png");
|
|
1069
1071
|
}
|
|
@@ -1076,6 +1078,18 @@ function widgetState(w, hook, o = {}) {
|
|
|
1076
1078
|
const ctx = { options: options2, data, sources, now, working: true, workday: DEFAULT_WORKDAY };
|
|
1077
1079
|
return fn(ctx);
|
|
1078
1080
|
}
|
|
1081
|
+
function widgetAlerts(w, o = {}) {
|
|
1082
|
+
if (!w.alerts) return [];
|
|
1083
|
+
const { now, options: options2, data, sources } = resolve3(w, o);
|
|
1084
|
+
return w.alerts({ options: options2, data, sources, now, working: true, workday: DEFAULT_WORKDAY });
|
|
1085
|
+
}
|
|
1086
|
+
function sourceAlerts(s, o = {}) {
|
|
1087
|
+
if (!s.alerts) return [];
|
|
1088
|
+
const now = o.now ?? Date.UTC(2026, 10, 5, 9, 42);
|
|
1089
|
+
const options2 = s.options ? validate(s.options, o.options ?? {}).value : {};
|
|
1090
|
+
const data = "data" in o ? o.data : o.demo === false ? void 0 : s.demo?.({ now, locale: o.locale ?? "en" });
|
|
1091
|
+
return s.alerts({ data, options: options2, now });
|
|
1092
|
+
}
|
|
1079
1093
|
function checkPlugin(p, o = {}) {
|
|
1080
1094
|
const issues = [];
|
|
1081
1095
|
const locales = o.locales ?? (p.languages?.length ? p.languages : ["en", "es"]);
|
|
@@ -1125,8 +1139,8 @@ var init_testing = __esm({
|
|
|
1125
1139
|
|
|
1126
1140
|
// packages/server/src/cli.ts
|
|
1127
1141
|
import { spawn } from "node:child_process";
|
|
1128
|
-
import { existsSync as
|
|
1129
|
-
import { dirname as
|
|
1142
|
+
import { existsSync as existsSync15, readFileSync as readFileSync9, writeFileSync as writeFileSync12 } from "node:fs";
|
|
1143
|
+
import { dirname as dirname8, join as join17 } from "node:path";
|
|
1130
1144
|
|
|
1131
1145
|
// packages/core/src/config/model.ts
|
|
1132
1146
|
init_workday();
|
|
@@ -1194,6 +1208,23 @@ function zoomOf(inst) {
|
|
|
1194
1208
|
if (typeof z !== "number" || !Number.isFinite(z)) return 1;
|
|
1195
1209
|
return Math.round(Math.min(ZOOM.max, Math.max(ZOOM.min, z)) * 100) / 100;
|
|
1196
1210
|
}
|
|
1211
|
+
var THREADS_MODES = ["auto", "always", "never"];
|
|
1212
|
+
var ALERT_THRESHOLDS = ["info", "warn", "critical", "off"];
|
|
1213
|
+
function screenAlerts(s) {
|
|
1214
|
+
return { minLevel: s.alerts?.minLevel ?? "info", ...s.alerts?.quiet ? { quiet: s.alerts.quiet } : {} };
|
|
1215
|
+
}
|
|
1216
|
+
var minutesOf2 = (hhmm) => {
|
|
1217
|
+
const m = /^(\d{1,2}):(\d{2})$/.exec(hhmm);
|
|
1218
|
+
return m ? Number(m[1]) * 60 + Number(m[2]) : NaN;
|
|
1219
|
+
};
|
|
1220
|
+
function inQuietHours(quiet, now) {
|
|
1221
|
+
if (!quiet) return false;
|
|
1222
|
+
const a = minutesOf2(quiet.start), b = minutesOf2(quiet.end);
|
|
1223
|
+
if (!Number.isFinite(a) || !Number.isFinite(b) || a === b) return false;
|
|
1224
|
+
const d = new Date(now);
|
|
1225
|
+
const t2 = d.getHours() * 60 + d.getMinutes();
|
|
1226
|
+
return a < b ? t2 >= a && t2 < b : t2 >= a || t2 < b;
|
|
1227
|
+
}
|
|
1197
1228
|
var READING_CM = { near: 40, normal: 60, far: 90 };
|
|
1198
1229
|
var TEXT_SCALE = { min: 0.75, max: 2, step: 0.05 };
|
|
1199
1230
|
var DEFAULT_MAX_BYTES = 48e4;
|
|
@@ -1254,7 +1285,7 @@ var PANEL_PRESETS = [
|
|
|
1254
1285
|
{ id: "square-480", name: "Square 480\xD7480", width: 480, height: 480, diagonalIn: 3.4 },
|
|
1255
1286
|
{ id: "square-320", name: "Square 320\xD7320", width: 320, height: 320, diagonalIn: 2.1 },
|
|
1256
1287
|
{ id: "small-320x240", name: "Small 320\xD7240", width: 320, height: 240, diagonalIn: 2.4 },
|
|
1257
|
-
{ id: "round-480", name: "Round 480\xD7480 (AIO)", width: 480, height: 480, diagonalIn: 2.8 }
|
|
1288
|
+
{ id: "round-480", name: "Round 480\xD7480 (AIO)", width: 480, height: 480, diagonalIn: 2.8, shape: "round" }
|
|
1258
1289
|
];
|
|
1259
1290
|
function mmPerPx(s) {
|
|
1260
1291
|
const known = PANEL_PRESETS.find((p) => p.width === s.width && p.height === s.height || p.width === s.height && p.height === s.width);
|
|
@@ -1341,7 +1372,9 @@ var CATEGORIES = [
|
|
|
1341
1372
|
{ id: "scene", label: { en: "Scenes", es: "Escenas", de: "Szenen", "zh-Hant": "\u5834\u666F", "zh-Hans": "\u573A\u666F" } },
|
|
1342
1373
|
{ id: "fun", label: { en: "Fun", es: "Diversi\xF3n", de: "Spa\xDF", "zh-Hant": "\u8DA3\u5473", "zh-Hans": "\u8DA3\u5473" } }
|
|
1343
1374
|
];
|
|
1344
|
-
var
|
|
1375
|
+
var ALERT_LEVELS = ["info", "warn", "critical"];
|
|
1376
|
+
var PAD_KEYS = ["up", "down", "left", "right", "a", "b", "x", "y", "l", "r", "start", "select"];
|
|
1377
|
+
var SDK_VERSION = "0.2.7";
|
|
1345
1378
|
function defineWidget(w) {
|
|
1346
1379
|
return w;
|
|
1347
1380
|
}
|
|
@@ -1426,11 +1459,11 @@ function listLayout(box, count, options2, spec) {
|
|
|
1426
1459
|
const min = Math.max(1, size.min);
|
|
1427
1460
|
const max = Math.max(min, size.max);
|
|
1428
1461
|
const h = Math.max(0, box.h);
|
|
1429
|
-
const
|
|
1462
|
+
const text3 = (rowH2) => {
|
|
1430
1463
|
const textSize = Math.round(rowH2 * (layout === "detailed" ? 0.42 : 0.6));
|
|
1431
1464
|
return { textSize, detailSize: Math.round(layout === "detailed" ? rowH2 * 0.3 : textSize * 0.8) };
|
|
1432
1465
|
};
|
|
1433
|
-
if (h <= 0) return { layout, rowH: 0, rows: [], shown: 0, hidden: n, more: null, ...
|
|
1466
|
+
if (h <= 0) return { layout, rowH: 0, rows: [], shown: 0, hidden: n, more: null, ...text3(0) };
|
|
1434
1467
|
const target = fixed > 0 ? Math.min(fixed, n) : n;
|
|
1435
1468
|
const divisor = fixed > 0 ? fixed : Math.max(n, spec.minRows ?? 1, 1);
|
|
1436
1469
|
const fits = (space, rowH2) => Math.floor(space / rowH2 + TOLERANCE);
|
|
@@ -1449,7 +1482,7 @@ function listLayout(box, count, options2, spec) {
|
|
|
1449
1482
|
if (moreH >= MIN_MORE_H) more = { x: box.x, y: box.y + shown * rowH, w: box.w, h: moreH };
|
|
1450
1483
|
}
|
|
1451
1484
|
const rows = Array.from({ length: shown }, (_, i) => ({ x: box.x, y: box.y + i * rowH, w: box.w, h: rowH }));
|
|
1452
|
-
return { layout, rowH, rows, shown, hidden: n - shown, more, ...
|
|
1485
|
+
return { layout, rowH, rows, shown, hidden: n - shown, more, ...text3(rowH) };
|
|
1453
1486
|
}
|
|
1454
1487
|
function moreLabel(n, tr) {
|
|
1455
1488
|
return tr({ en: `+${n} more`, es: `+${n} m\xE1s`, de: `+${n} weitere`, "zh-Hant": `\u9084\u6709 ${n} \u500B`, "zh-Hans": `\u8FD8\u6709 ${n} \u4E2A` });
|
|
@@ -1460,10 +1493,10 @@ function drawMore(g, ctx, plan, o = {}) {
|
|
|
1460
1493
|
const size = Math.max(8, Math.round(m.h * 0.62));
|
|
1461
1494
|
const indent = o.indent ?? 0;
|
|
1462
1495
|
const font = { size, family: ctx.theme.fonts.sans, color: ctx.theme.colors.inkDim };
|
|
1463
|
-
const
|
|
1496
|
+
const text3 = ctx.kit.truncate(g, moreLabel(plan.hidden, ctx.t), Math.max(1, m.w - indent), font);
|
|
1464
1497
|
const y = m.y + (m.h + size * 0.7) / 2;
|
|
1465
|
-
if (o.align === "right") ctx.kit.drawTracked(g,
|
|
1466
|
-
else ctx.kit.drawTracked(g,
|
|
1498
|
+
if (o.align === "right") ctx.kit.drawTracked(g, text3, m.x + m.w, y, { ...font, align: "right" });
|
|
1499
|
+
else ctx.kit.drawTracked(g, text3, m.x + indent, y, font);
|
|
1467
1500
|
}
|
|
1468
1501
|
function drawEmpty(g, ctx, message) {
|
|
1469
1502
|
const { box, kit, theme } = ctx;
|
|
@@ -1701,7 +1734,7 @@ var paths = {
|
|
|
1701
1734
|
init_format();
|
|
1702
1735
|
init_workday();
|
|
1703
1736
|
function normalize(raw) {
|
|
1704
|
-
const { $schema, ...c } = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
|
|
1737
|
+
const { $schema, threads, ...c } = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
|
|
1705
1738
|
const screens = Array.isArray(c.screens) ? c.screens.map(normalizeScreen) : [];
|
|
1706
1739
|
return {
|
|
1707
1740
|
...typeof $schema === "string" && $schema ? { $schema } : {},
|
|
@@ -1715,6 +1748,7 @@ function normalize(raw) {
|
|
|
1715
1748
|
plugins: { disabled: c.plugins?.disabled ?? [] },
|
|
1716
1749
|
server: { ...DEFAULT_CONFIG.server, ...c.server ?? {} },
|
|
1717
1750
|
...c.homeassistant && typeof c.homeassistant === "object" ? { homeassistant: normalizeHa(c.homeassistant) } : {},
|
|
1751
|
+
...THREADS_MODES.includes(threads) ? { threads } : {},
|
|
1718
1752
|
screens
|
|
1719
1753
|
};
|
|
1720
1754
|
}
|
|
@@ -1760,9 +1794,22 @@ function normalizeScreen(s, i) {
|
|
|
1760
1794
|
maxFps: s.maxFps ?? 12,
|
|
1761
1795
|
...s.readingDistance === "near" || s.readingDistance === "far" ? { readingDistance: s.readingDistance } : {},
|
|
1762
1796
|
...typeof s.textScale === "number" && Number.isFinite(s.textScale) && s.textScale !== 1 ? { textScale: Math.min(TEXT_SCALE.max, Math.max(TEXT_SCALE.min, s.textScale)) } : {},
|
|
1763
|
-
...typeof s.diagonalIn === "number" && s.diagonalIn > 0 ? { diagonalIn: s.diagonalIn } : {}
|
|
1797
|
+
...typeof s.diagonalIn === "number" && s.diagonalIn > 0 ? { diagonalIn: s.diagonalIn } : {},
|
|
1798
|
+
...normalizeAlerts(s.alerts),
|
|
1799
|
+
// `auto` (or anything else) is the same as leaving it out: as the config's `threads` says.
|
|
1800
|
+
...s.thread === "always" || s.thread === "never" ? { thread: s.thread } : {}
|
|
1764
1801
|
};
|
|
1765
1802
|
}
|
|
1803
|
+
var HHMM = /^([01][0-9]|2[0-3]):[0-5][0-9]$/;
|
|
1804
|
+
function normalizeAlerts(raw) {
|
|
1805
|
+
if (!raw || typeof raw !== "object") return {};
|
|
1806
|
+
const a = raw;
|
|
1807
|
+
const minLevel = ALERT_THRESHOLDS.includes(a.minLevel) ? a.minLevel : "info";
|
|
1808
|
+
const q3 = a.quiet;
|
|
1809
|
+
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;
|
|
1810
|
+
if (minLevel === "info" && !quiet) return {};
|
|
1811
|
+
return { alerts: { minLevel, ...quiet ? { quiet } : {} } };
|
|
1812
|
+
}
|
|
1766
1813
|
|
|
1767
1814
|
// packages/core/src/config/store.ts
|
|
1768
1815
|
function loadConfig(path = paths.config) {
|
|
@@ -1798,6 +1845,14 @@ var DEFAULT_TIMEOUT_MS = 2 * 6e4;
|
|
|
1798
1845
|
var MAX_INTERVAL_MS = 24 * 36e5;
|
|
1799
1846
|
var MIN_TIMEOUT_MS = 1e3;
|
|
1800
1847
|
var MAX_TIMEOUT_MS = 10 * 6e4;
|
|
1848
|
+
var canRunInBackground = (def) => def.background === true && typeof def.alerts === "function" && !("background" in (def.options?.props ?? {}));
|
|
1849
|
+
function backgroundSources(cfg, source) {
|
|
1850
|
+
return Object.keys(cfg.sources).filter((type) => {
|
|
1851
|
+
if (cfg.sources[type]?.background !== true) return false;
|
|
1852
|
+
const def = source(type);
|
|
1853
|
+
return !!def && canRunInBackground(def);
|
|
1854
|
+
});
|
|
1855
|
+
}
|
|
1801
1856
|
function human(ms) {
|
|
1802
1857
|
if (ms % 36e5 === 0) return `${ms / 36e5} h`;
|
|
1803
1858
|
if (ms % 6e4 === 0) return `${ms / 6e4} min`;
|
|
@@ -1809,15 +1864,29 @@ function sourceTiming(def) {
|
|
|
1809
1864
|
return { intervalMs: Math.max(intervalMs, minIntervalMs), minIntervalMs, timeoutMs: def.timeoutMs ?? DEFAULT_TIMEOUT_MS };
|
|
1810
1865
|
}
|
|
1811
1866
|
function sourceCommonFields(def) {
|
|
1812
|
-
|
|
1867
|
+
const fields = {};
|
|
1868
|
+
if (canRunInBackground(def)) {
|
|
1869
|
+
fields.background = t.boolean({
|
|
1870
|
+
default: false,
|
|
1871
|
+
label: { en: "Watch for alerts without a widget", es: "Vigilar avisos sin widget", de: "Ohne Widget auf Alarme achten", "zh-Hant": "\u7121\u9700\u5C0F\u5DE5\u5177\u4E5F\u76E3\u770B\u8B66\u5831", "zh-Hans": "\u65E0\u9700\u5C0F\u7EC4\u4EF6\u4E5F\u76D1\u770B\u8B66\u62A5" },
|
|
1872
|
+
help: {
|
|
1873
|
+
en: "Kiosko reads it even when no tile uses it, and its alerts take the panel over like any other. Off: it runs only while a widget uses it.",
|
|
1874
|
+
es: "Kiosko la lee aunque ninguna tesela la use, y sus avisos ocupan el panel como cualquier otro. Apagado: solo corre mientras alg\xFAn widget la usa.",
|
|
1875
|
+
de: "Kiosko liest sie, auch wenn keine Kachel sie verwendet, und ihre Alarme \xFCbernehmen das Panel wie jeder andere. Aus: Sie l\xE4uft nur, solange ein Widget sie verwendet.",
|
|
1876
|
+
"zh-Hant": "\u5373\u4F7F\u6C92\u6709\u5716\u584A\u4F7F\u7528\uFF0CKiosko \u4E5F\u6703\u8B80\u53D6\u5B83\uFF0C\u5176\u8B66\u5831\u6703\u50CF\u5176\u4ED6\u8B66\u5831\u4E00\u6A23\u4F54\u6EFF\u9762\u677F\u3002\u95DC\u9589\u6642\uFF1A\u53EA\u5728\u6709\u5C0F\u5DE5\u5177\u4F7F\u7528\u6642\u624D\u57F7\u884C\u3002",
|
|
1877
|
+
"zh-Hans": "\u5373\u4F7F\u6CA1\u6709\u56FE\u5757\u4F7F\u7528\uFF0CKiosko \u4E5F\u4F1A\u8BFB\u53D6\u5B83\uFF0C\u5176\u8B66\u62A5\u4F1A\u50CF\u5176\u4ED6\u8B66\u62A5\u4E00\u6837\u5360\u6EE1\u526F\u5C4F\u3002\u5173\u95ED\u65F6\uFF1A\u53EA\u5728\u6709\u5C0F\u7EC4\u4EF6\u4F7F\u7528\u65F6\u624D\u8FD0\u884C\u3002"
|
|
1878
|
+
}
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
if (!def.read) return fields;
|
|
1813
1882
|
const { intervalMs, minIntervalMs, timeoutMs } = sourceTiming(def);
|
|
1814
|
-
|
|
1883
|
+
Object.assign(fields, {
|
|
1815
1884
|
intervalMs: t.duration({
|
|
1816
1885
|
default: intervalMs,
|
|
1817
1886
|
min: minIntervalMs,
|
|
1818
1887
|
max: Math.max(MAX_INTERVAL_MS, intervalMs),
|
|
1819
1888
|
label: { en: "Read every", es: "Leer cada", de: "Lesen alle", "zh-Hant": "\u8B80\u53D6\u9593\u9694", "zh-Hans": "\u8BFB\u53D6\u95F4\u9694" },
|
|
1820
|
-
help: { en: `How often Kiosko reads it while a widget uses it. At least ${human(minIntervalMs)}.`, es: `Cada cu\xE1nto lo lee Kiosko mientras alg\xFAn widget lo usa. Como m\xEDnimo, ${human(minIntervalMs)}.`, de: `Wie oft Kiosko sie liest, solange ein Widget sie verwendet. Mindestens ${human(minIntervalMs)}.`, "zh-Hant": `\u5C0F\u5DE5\u5177\u4F7F\u7528\u6642\uFF0CKiosko \u8B80\u53D6\u5B83\u7684\u983B\u7387\u3002\u6700\u5C11 ${human(minIntervalMs)}\u3002`, "zh-Hans": `\u6709\u5C0F\u7EC4\u4EF6\u4F7F\u7528\u65F6 Kiosko \u8BFB\u53D6\u5B83\u7684\u9891\u7387\u3002\u6700\u5C11 ${human(minIntervalMs)}\u3002` }
|
|
1889
|
+
help: fields.background ? { en: `How often Kiosko reads it while it runs. At least ${human(minIntervalMs)}.`, es: `Cada cu\xE1nto lo lee Kiosko mientras corre. Como m\xEDnimo, ${human(minIntervalMs)}.`, de: `Wie oft Kiosko sie liest, solange sie l\xE4uft. Mindestens ${human(minIntervalMs)}.`, "zh-Hant": `\u57F7\u884C\u6642 Kiosko \u8B80\u53D6\u5B83\u7684\u983B\u7387\u3002\u6700\u5C11 ${human(minIntervalMs)}\u3002`, "zh-Hans": `\u8FD0\u884C\u65F6 Kiosko \u8BFB\u53D6\u5B83\u7684\u9891\u7387\u3002\u6700\u5C11 ${human(minIntervalMs)}\u3002` } : { en: `How often Kiosko reads it while a widget uses it. At least ${human(minIntervalMs)}.`, es: `Cada cu\xE1nto lo lee Kiosko mientras alg\xFAn widget lo usa. Como m\xEDnimo, ${human(minIntervalMs)}.`, de: `Wie oft Kiosko sie liest, solange ein Widget sie verwendet. Mindestens ${human(minIntervalMs)}.`, "zh-Hant": `\u5C0F\u5DE5\u5177\u4F7F\u7528\u6642\uFF0CKiosko \u8B80\u53D6\u5B83\u7684\u983B\u7387\u3002\u6700\u5C11 ${human(minIntervalMs)}\u3002`, "zh-Hans": `\u6709\u5C0F\u7EC4\u4EF6\u4F7F\u7528\u65F6 Kiosko \u8BFB\u53D6\u5B83\u7684\u9891\u7387\u3002\u6700\u5C11 ${human(minIntervalMs)}\u3002` }
|
|
1821
1890
|
}),
|
|
1822
1891
|
timeoutMs: t.duration({
|
|
1823
1892
|
default: timeoutMs,
|
|
@@ -1827,7 +1896,7 @@ function sourceCommonFields(def) {
|
|
|
1827
1896
|
label: { en: "Give up a reading after", es: "Abandonar una lectura tras", de: "Lesen abbrechen nach", "zh-Hant": "\u8B80\u53D6\u903E\u6642", "zh-Hans": "\u8BFB\u53D6\u8D85\u65F6" },
|
|
1828
1897
|
help: { en: "A reading that takes longer is cancelled and counts as failed; the next try comes sooner.", es: "Una lectura que tarde m\xE1s se cancela y cuenta como fallida; el siguiente intento llega antes.", de: "Ein Lesevorgang, der l\xE4nger dauert, wird abgebrochen und z\xE4hlt als fehlgeschlagen; der n\xE4chste Versuch kommt fr\xFCher.", "zh-Hant": "\u8D85\u904E\u6B64\u6642\u9593\u7684\u8B80\u53D6\u6703\u88AB\u53D6\u6D88\u4E26\u8996\u70BA\u5931\u6557\uFF1B\u4E0B\u6B21\u6703\u63D0\u65E9\u91CD\u8A66\u3002", "zh-Hans": "\u8D85\u8FC7\u6B64\u65F6\u95F4\u7684\u8BFB\u53D6\u4F1A\u88AB\u53D6\u6D88\u5E76\u89C6\u4E3A\u5931\u8D25\uFF1B\u4E0B\u6B21\u4F1A\u63D0\u524D\u91CD\u8BD5\u3002" }
|
|
1829
1898
|
})
|
|
1830
|
-
};
|
|
1899
|
+
});
|
|
1831
1900
|
const own = def.options?.props ?? {};
|
|
1832
1901
|
return Object.fromEntries(Object.entries(fields).filter(([k]) => !(k in own)));
|
|
1833
1902
|
}
|
|
@@ -1864,9 +1933,9 @@ var HIDE_WHEN_EMPTY = {
|
|
|
1864
1933
|
"x-ui": { label: { en: "Hide when empty", es: "Ocultar si est\xE1 vac\xEDo", de: "Ausblenden, wenn leer", "zh-Hant": "\u6C92\u6709\u5167\u5BB9\u6642\u96B1\u85CF", "zh-Hans": "\u6CA1\u6709\u5185\u5BB9\u65F6\u9690\u85CF" } }
|
|
1865
1934
|
};
|
|
1866
1935
|
var TIME_PATTERN = "^([01][0-9]|2[0-3]):[0-5][0-9]$";
|
|
1867
|
-
function options(f,
|
|
1868
|
-
if (!f) return { type: "object", description: `This ${
|
|
1869
|
-
return { ...toJsonSchema(f), description: `Options of this ${
|
|
1936
|
+
function options(f, what2) {
|
|
1937
|
+
if (!f) return { type: "object", description: `This ${what2} has no options.`, default: {} };
|
|
1938
|
+
return { ...toJsonSchema(f), description: `Options of this ${what2}. Leave out any option to use its default.` };
|
|
1870
1939
|
}
|
|
1871
1940
|
function sizeHint(size) {
|
|
1872
1941
|
if (!size) return "";
|
|
@@ -2020,6 +2089,11 @@ function configSchema(plugins) {
|
|
|
2020
2089
|
port: { type: "integer", minimum: 1, maximum: 65535, default: DEFAULT_CONFIG.server.port }
|
|
2021
2090
|
}
|
|
2022
2091
|
},
|
|
2092
|
+
threads: {
|
|
2093
|
+
enum: ["auto", "always", "never"],
|
|
2094
|
+
default: "auto",
|
|
2095
|
+
description: `Paint each screen in a thread of its own, so a slow widget on one does not slow the others: "auto" (with two or more screens on and a core to spare for each), "always", or "never" (every screen on the main thread: less memory, for a small machine). A screen's "thread" overrides it.`
|
|
2096
|
+
},
|
|
2023
2097
|
homeassistant: {
|
|
2024
2098
|
type: "object",
|
|
2025
2099
|
additionalProperties: false,
|
|
@@ -2190,7 +2264,23 @@ function configSchema(plugins) {
|
|
|
2190
2264
|
maxFps: { type: "integer", minimum: 1, maximum: 30, default: 12, description: "Frames per second ceiling for animations." },
|
|
2191
2265
|
readingDistance: { enum: ["near", "normal", "far"], default: "normal", description: "How far the readers sit (40, 60, 90 cm): with the pixel size it sets the smallest Chinese, Japanese or Korean text painted." },
|
|
2192
2266
|
textScale: { type: "number", minimum: 0.75, maximum: 2, default: 1, description: "Every widget's text size times this." },
|
|
2193
|
-
diagonalIn: { type: "number", minimum: 0.5, maximum: 60, description: "The panel's diagonal in inches, when it isn't a known model." }
|
|
2267
|
+
diagonalIn: { type: "number", minimum: 0.5, maximum: 60, description: "The panel's diagonal in inches, when it isn't a known model." },
|
|
2268
|
+
thread: { enum: ["always", "never"], description: `Paint this screen in a thread of its own (always) or on the main thread (never), whatever the config's "threads" says. Missing: as it says.` },
|
|
2269
|
+
alerts: {
|
|
2270
|
+
type: "object",
|
|
2271
|
+
additionalProperties: false,
|
|
2272
|
+
description: "How alerts (smoke, a leak, the doorbell, CI broken\u2026) take this panel over: full-screen, with a flashing frame. Missing: every level, at any hour.",
|
|
2273
|
+
properties: {
|
|
2274
|
+
minLevel: { enum: ["info", "warn", "critical", "off"], default: "info", description: "The least level shown full-screen here; off: none (they stay in the editor's band)." },
|
|
2275
|
+
quiet: {
|
|
2276
|
+
type: "object",
|
|
2277
|
+
additionalProperties: false,
|
|
2278
|
+
required: ["start", "end"],
|
|
2279
|
+
description: "Hours when only critical alerts take the panel over, local time; start after end goes across midnight.",
|
|
2280
|
+
properties: { start: { $ref: "#/$defs/time" }, end: { $ref: "#/$defs/time" } }
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2194
2284
|
}
|
|
2195
2285
|
}
|
|
2196
2286
|
},
|
|
@@ -2349,15 +2439,15 @@ function validDate(s) {
|
|
|
2349
2439
|
function push(run, path, message, context) {
|
|
2350
2440
|
run.issues.push({ path: formatPath(path), pointer: toPointer(path), message, ...context ? { context } : {} });
|
|
2351
2441
|
}
|
|
2352
|
-
function trial(run,
|
|
2442
|
+
function trial(run, schema2, value, path, context) {
|
|
2353
2443
|
const sub = { root: run.root, issues: [] };
|
|
2354
|
-
check(sub,
|
|
2444
|
+
check(sub, schema2, value, path, context);
|
|
2355
2445
|
return sub.issues;
|
|
2356
2446
|
}
|
|
2357
|
-
function check(run,
|
|
2358
|
-
if (
|
|
2359
|
-
if (
|
|
2360
|
-
const s = deref(run.root,
|
|
2447
|
+
function check(run, schema2, value, path, context) {
|
|
2448
|
+
if (schema2 === true) return;
|
|
2449
|
+
if (schema2 === false) return push(run, path, "is not allowed here", context);
|
|
2450
|
+
const s = deref(run.root, schema2);
|
|
2361
2451
|
if (s === void 0 || typeof s !== "object") return;
|
|
2362
2452
|
if (Array.isArray(s.allOf)) for (const sub of s.allOf) check(run, sub, value, path, context);
|
|
2363
2453
|
for (const key of ["oneOf", "anyOf"]) {
|
|
@@ -2402,6 +2492,7 @@ function check(run, schema, value, path, context) {
|
|
|
2402
2492
|
push(run, path, `must be ${hint}; got ${describe(value)}`, context);
|
|
2403
2493
|
}
|
|
2404
2494
|
if (s.format === "date" && !validDate(value)) push(run, path, `must be a date as YYYY-MM-DD; got ${describe(value)}`, context);
|
|
2495
|
+
if (s.format === "date-time" && !(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/.test(value) && validDate(value.slice(0, 10)))) push(run, path, `must be a date and time as YYYY-MM-DDTHH:MM:SSZ; got ${describe(value)}`, context);
|
|
2405
2496
|
}
|
|
2406
2497
|
if (Array.isArray(value)) {
|
|
2407
2498
|
if (typeof s.minItems === "number" && value.length < s.minItems) push(run, path, `must have at least ${s.minItems} item${s.minItems === 1 ? "" : "s"}; has ${value.length}`, context);
|
|
@@ -2435,9 +2526,9 @@ function check(run, schema, value, path, context) {
|
|
|
2435
2526
|
}
|
|
2436
2527
|
}
|
|
2437
2528
|
}
|
|
2438
|
-
function validateJson(
|
|
2439
|
-
const run = { root:
|
|
2440
|
-
check(run,
|
|
2529
|
+
function validateJson(schema2, value) {
|
|
2530
|
+
const run = { root: schema2, issues: [] };
|
|
2531
|
+
check(run, schema2, value, []);
|
|
2441
2532
|
const seen = /* @__PURE__ */ new Set();
|
|
2442
2533
|
return run.issues.filter((i) => {
|
|
2443
2534
|
const k = `${i.pointer}\0${i.message}`;
|
|
@@ -2447,9 +2538,9 @@ function validateJson(schema, value) {
|
|
|
2447
2538
|
});
|
|
2448
2539
|
}
|
|
2449
2540
|
function walkWithSchema(root, value, visit) {
|
|
2450
|
-
const go = (
|
|
2451
|
-
if (typeof
|
|
2452
|
-
const s = deref(root,
|
|
2541
|
+
const go = (schema2, v, path, parent, context) => {
|
|
2542
|
+
if (typeof schema2 !== "object") return;
|
|
2543
|
+
const s = deref(root, schema2);
|
|
2453
2544
|
if (!isObj(s)) return;
|
|
2454
2545
|
visit({ path, value: v, schema: s, ...parent ? { parent } : {}, ...context ? { context } : {} });
|
|
2455
2546
|
if (Array.isArray(s.allOf)) for (const sub of s.allOf) go(sub, v, path, parent, context);
|
|
@@ -2493,12 +2584,12 @@ function unknownOptions(f, v, path, out, owner) {
|
|
|
2493
2584
|
}
|
|
2494
2585
|
var validGrid = (g) => isObj2(g) && ["cols", "rows", "gap", "padding"].every((k) => Number.isInteger(g[k])) && g.cols >= 1 && g.rows >= 1;
|
|
2495
2586
|
var validRect = (t2) => isObj2(t2) && ["x", "y", "w", "h"].every((k) => Number.isInteger(t2[k]));
|
|
2496
|
-
function repeated(items, path,
|
|
2587
|
+
function repeated(items, path, what2, out) {
|
|
2497
2588
|
const seen = /* @__PURE__ */ new Map();
|
|
2498
2589
|
items.forEach((x, i) => {
|
|
2499
2590
|
if (!isObj2(x) || typeof x.id !== "string") return;
|
|
2500
2591
|
const first = seen.get(x.id);
|
|
2501
|
-
if (first !== void 0) out.push(issue([...path, i, "id"], `repeats the id ${JSON.stringify(x.id)} of ${formatPath([...path, first])}: ${
|
|
2592
|
+
if (first !== void 0) out.push(issue([...path, i, "id"], `repeats the id ${JSON.stringify(x.id)} of ${formatPath([...path, first])}: ${what2} ids must be unique`));
|
|
2502
2593
|
else seen.set(x.id, i);
|
|
2503
2594
|
});
|
|
2504
2595
|
}
|
|
@@ -2593,8 +2684,8 @@ function checkConfig(raw, plugins) {
|
|
|
2593
2684
|
}
|
|
2594
2685
|
return { errors, warnings };
|
|
2595
2686
|
}
|
|
2596
|
-
function validateConfig(raw, plugins,
|
|
2597
|
-
const shape = validateJson(
|
|
2687
|
+
function validateConfig(raw, plugins, schema2 = configSchema(plugins)) {
|
|
2688
|
+
const shape = validateJson(schema2, raw);
|
|
2598
2689
|
const more = checkConfig(raw, plugins);
|
|
2599
2690
|
return { errors: [...shape, ...more.errors], warnings: more.warnings };
|
|
2600
2691
|
}
|
|
@@ -2639,18 +2730,18 @@ function diffTiles(before, after, depth, out) {
|
|
|
2639
2730
|
for (const t2 of m.removed) out.push({ depth, op: "-", kind: "tile", text: tileText(t2) });
|
|
2640
2731
|
for (const t2 of m.added) out.push({ depth, op: "+", kind: "tile", text: tileText(t2) });
|
|
2641
2732
|
for (const [b, a] of m.pairs) {
|
|
2642
|
-
const
|
|
2643
|
-
if (rect(b) !== rect(a))
|
|
2733
|
+
const what2 = [];
|
|
2734
|
+
if (rect(b) !== rect(a)) what2.push(`moved/resized from ${rect(b)}`);
|
|
2644
2735
|
const w = match(b.widgets, a.widgets, (x) => x.type);
|
|
2645
|
-
if (w.added.length)
|
|
2646
|
-
if (w.removed.length)
|
|
2736
|
+
if (w.added.length) what2.push(`+ ${w.added.map((x) => x.type).join(", ")}`);
|
|
2737
|
+
if (w.removed.length) what2.push(`- ${w.removed.map((x) => x.type).join(", ")}`);
|
|
2647
2738
|
const opts = w.pairs.filter(([x, y]) => !same(x.options, y.options) && x.type === y.type).map(([x, y]) => `${y.type} (${changedKeys(x.options, y.options).join(", ")})`);
|
|
2648
|
-
if (opts.length)
|
|
2739
|
+
if (opts.length) what2.push(`options of ${opts.join(", ")}`);
|
|
2649
2740
|
const swapped = w.pairs.filter(([x, y]) => x.type !== y.type).map(([x, y]) => `${x.type} \u2192 ${y.type}`);
|
|
2650
|
-
if (swapped.length)
|
|
2741
|
+
if (swapped.length) what2.push(swapped.join(", "));
|
|
2651
2742
|
const rest = w.pairs.filter(([x, y]) => x.type === y.type && same(x.options, y.options) && !same(x, y));
|
|
2652
|
-
if (rest.length || b.rotateMs !== a.rotateMs || b.chrome !== a.chrome || !!b.locked !== !!a.locked)
|
|
2653
|
-
if (
|
|
2743
|
+
if (rest.length || b.rotateMs !== a.rotateMs || b.chrome !== a.chrome || !!b.locked !== !!a.locked) what2.push("settings");
|
|
2744
|
+
if (what2.length) out.push({ depth, op: "~", kind: "tile", text: `tile ${rect(a)}: ${what2.join("; ")}` });
|
|
2654
2745
|
}
|
|
2655
2746
|
}
|
|
2656
2747
|
function diffPages(before, after, depth, out) {
|
|
@@ -2658,13 +2749,13 @@ function diffPages(before, after, depth, out) {
|
|
|
2658
2749
|
for (const p of m.removed) out.push({ depth, op: "-", kind: "page", text: pageText(p) });
|
|
2659
2750
|
for (const p of m.added) out.push({ depth, op: "+", kind: "page", text: pageText(p) });
|
|
2660
2751
|
for (const [b, a] of m.pairs) {
|
|
2661
|
-
const
|
|
2662
|
-
if (b.name !== a.name)
|
|
2663
|
-
if (!same(b.grid, a.grid))
|
|
2664
|
-
for (const k of ["enabled", "when", "durationMs", "gravity", "background"]) if (!same(b[k], a[k]))
|
|
2752
|
+
const what2 = [];
|
|
2753
|
+
if (b.name !== a.name) what2.push(`renamed from ${q2(b.name)}`);
|
|
2754
|
+
if (!same(b.grid, a.grid)) what2.push(`grid ${b.grid.cols}\xD7${b.grid.rows} \u2192 ${a.grid.cols}\xD7${a.grid.rows}`);
|
|
2755
|
+
for (const k of ["enabled", "when", "durationMs", "gravity", "background"]) if (!same(b[k], a[k])) what2.push(`${k} ${short(b[k])} \u2192 ${short(a[k])}`);
|
|
2665
2756
|
const tiles = [];
|
|
2666
2757
|
diffTiles(b, a, depth + 1, tiles);
|
|
2667
|
-
if (
|
|
2758
|
+
if (what2.length || tiles.length) out.push({ depth, op: "~", kind: "page", text: `page ${q2(a.name)}${what2.length ? `: ${what2.join("; ")}` : ""}` }, ...tiles);
|
|
2668
2759
|
}
|
|
2669
2760
|
}
|
|
2670
2761
|
var slotText = (s) => `interlude ${s.type} every ${Math.round(s.everyMs / 6e4)} min${s.enabled ? "" : " (off)"}`;
|
|
@@ -2688,18 +2779,18 @@ function diffConfigs(before, after) {
|
|
|
2688
2779
|
for (const x of s.interludes) out.push({ depth: 1, op: "+", kind: "interlude", text: slotText(x) });
|
|
2689
2780
|
}
|
|
2690
2781
|
for (const [b, a] of m.pairs) {
|
|
2691
|
-
const
|
|
2692
|
-
if (b.name !== a.name)
|
|
2693
|
-
if (b.width !== a.width || b.height !== a.height)
|
|
2694
|
-
if (!same(b.device, a.device))
|
|
2695
|
-
for (const k of ["enabled", "rotate", "pinnedPage", "pixelShift", "sleepWhenIdle", "jpegQuality", "maxFps"]) if (!same(b[k], a[k]))
|
|
2782
|
+
const what2 = [];
|
|
2783
|
+
if (b.name !== a.name) what2.push(`renamed from ${q2(b.name)}`);
|
|
2784
|
+
if (b.width !== a.width || b.height !== a.height) what2.push(`size ${b.width}\xD7${b.height} \u2192 ${a.width}\xD7${a.height}`);
|
|
2785
|
+
if (!same(b.device, a.device)) what2.push(`device ${deviceText(b.device)} \u2192 ${deviceText(a.device)}`);
|
|
2786
|
+
for (const k of ["enabled", "rotate", "pinnedPage", "pixelShift", "sleepWhenIdle", "jpegQuality", "maxFps", "alerts"]) if (!same(b[k], a[k])) what2.push(`${k} ${short(b[k])} \u2192 ${short(a[k])}`);
|
|
2696
2787
|
const sub = [];
|
|
2697
2788
|
diffPages(b, a, 1, sub);
|
|
2698
2789
|
const xs = match(b.interludes, a.interludes, (x) => x.type);
|
|
2699
2790
|
for (const x of xs.removed) sub.push({ depth: 1, op: "-", kind: "interlude", text: slotText(x) });
|
|
2700
2791
|
for (const x of xs.added) sub.push({ depth: 1, op: "+", kind: "interlude", text: slotText(x) });
|
|
2701
2792
|
for (const [x, y] of xs.pairs) if (!same(x, y)) sub.push({ depth: 1, op: "~", kind: "interlude", text: slotText(y) });
|
|
2702
|
-
if (
|
|
2793
|
+
if (what2.length || sub.length) out.push({ depth: 0, op: "~", kind: "screen", text: `screen ${q2(a.name)}${what2.length ? `: ${what2.join("; ")}` : ""}` }, ...sub);
|
|
2703
2794
|
}
|
|
2704
2795
|
return out;
|
|
2705
2796
|
}
|
|
@@ -2744,9 +2835,9 @@ function setAt(root, path, value) {
|
|
|
2744
2835
|
if (Array.isArray(parent)) parent[last2] = value;
|
|
2745
2836
|
else if (isObj3(parent)) parent[last2] = value;
|
|
2746
2837
|
}
|
|
2747
|
-
function annotatedValues(config2,
|
|
2838
|
+
function annotatedValues(config2, schema2) {
|
|
2748
2839
|
const out = /* @__PURE__ */ new Map();
|
|
2749
|
-
walkWithSchema(
|
|
2840
|
+
walkWithSchema(schema2, config2, (v) => {
|
|
2750
2841
|
const risks = risksOf(v.schema);
|
|
2751
2842
|
const secret = v.schema["x-secret"] === true;
|
|
2752
2843
|
if (!risks.length && !secret) return;
|
|
@@ -2788,8 +2879,8 @@ function redact(value) {
|
|
|
2788
2879
|
}
|
|
2789
2880
|
return "(secret, hidden)";
|
|
2790
2881
|
}
|
|
2791
|
-
function listRisks(config2,
|
|
2792
|
-
const items = (cfg) => annotatedValues(cfg,
|
|
2882
|
+
function listRisks(config2, schema2, before) {
|
|
2883
|
+
const items = (cfg) => annotatedValues(cfg, schema2).filter((a) => a.risks.length && typeof a.value === "string" && !isPlaceholder(a.value)).map((a) => ({ a, value: a.value, risk: riskOf(a.risks, a.value) }));
|
|
2793
2884
|
const known = new Set(before === void 0 ? [] : items(before).map((x) => `${x.risk}\0${x.value.trim()}`));
|
|
2794
2885
|
return items(config2).map(({ a, value, risk }) => ({
|
|
2795
2886
|
risk,
|
|
@@ -2817,7 +2908,7 @@ function containers(root) {
|
|
|
2817
2908
|
}
|
|
2818
2909
|
var item = (a, note) => ({ path: formatPath(a.path), pointer: toPointer(a.path), ...a.title ? { title: a.title } : {}, ...a.context ? { context: a.context } : {}, ...note ? { note } : {} });
|
|
2819
2910
|
var HOSTISH = /^(host(name)?|server|ur[il]|endpoint|address|base_?url)$|(url|host|endpoint)$/i;
|
|
2820
|
-
function hostMoved(
|
|
2911
|
+
function hostMoved(schema2, merged2, mergedPath, current, currentPath, holder) {
|
|
2821
2912
|
if (!holder || !isObj3(holder.properties)) return null;
|
|
2822
2913
|
const a = getAt(merged2, mergedPath.slice(0, -1));
|
|
2823
2914
|
const b = getAt(current, currentPath.slice(0, -1));
|
|
@@ -2825,7 +2916,7 @@ function hostMoved(schema, merged2, mergedPath, current, currentPath, holder) {
|
|
|
2825
2916
|
const own = mergedPath[mergedPath.length - 1];
|
|
2826
2917
|
for (const [k, sub] of Object.entries(holder.properties)) {
|
|
2827
2918
|
if (k === own) continue;
|
|
2828
|
-
const s = deref(
|
|
2919
|
+
const s = deref(schema2, sub);
|
|
2829
2920
|
if (typeof s !== "object" || !(risksOf(s).includes("network") || HOSTISH.test(k) && s.type === "string")) continue;
|
|
2830
2921
|
const was = String(b[k] ?? "").trim();
|
|
2831
2922
|
const now = String(a[k] ?? "").trim();
|
|
@@ -2836,17 +2927,17 @@ function hostMoved(schema, merged2, mergedPath, current, currentPath, holder) {
|
|
|
2836
2927
|
}
|
|
2837
2928
|
return null;
|
|
2838
2929
|
}
|
|
2839
|
-
function mergeSecrets(incoming, current,
|
|
2930
|
+
function mergeSecrets(incoming, current, schema2) {
|
|
2840
2931
|
const out = clone2(incoming);
|
|
2841
2932
|
const real = (a) => a.secret && typeof a.value === "string" && !isPlaceholder(a.value);
|
|
2842
|
-
const cur = annotatedValues(current,
|
|
2933
|
+
const cur = annotatedValues(current, schema2).filter(real);
|
|
2843
2934
|
const curByKey = new Map(cur.map((a) => [a.key, a]));
|
|
2844
2935
|
const curContainers = containers(current);
|
|
2845
2936
|
const kept = [];
|
|
2846
2937
|
const toFill = [];
|
|
2847
2938
|
const provided = [];
|
|
2848
2939
|
const done2 = /* @__PURE__ */ new Set();
|
|
2849
|
-
const inc = annotatedValues(out,
|
|
2940
|
+
const inc = annotatedValues(out, schema2).filter((a) => a.secret);
|
|
2850
2941
|
const lists = /* @__PURE__ */ new Map();
|
|
2851
2942
|
for (const a of inc) if (typeof a.path[a.path.length - 1] === "number") lists.set(toPointer(a.path.slice(0, -1)), [...lists.get(toPointer(a.path.slice(0, -1))) ?? [], a]);
|
|
2852
2943
|
for (const items of lists.values()) {
|
|
@@ -2881,7 +2972,7 @@ function mergeSecrets(incoming, current, schema) {
|
|
|
2881
2972
|
}
|
|
2882
2973
|
}
|
|
2883
2974
|
const incContainers = containers(out);
|
|
2884
|
-
const incKeys = new Set(annotatedValues(out,
|
|
2975
|
+
const incKeys = new Set(annotatedValues(out, schema2).map((a) => a.key));
|
|
2885
2976
|
const restored = /* @__PURE__ */ new Set();
|
|
2886
2977
|
for (const c of cur) {
|
|
2887
2978
|
if (incKeys.has(c.key)) continue;
|
|
@@ -2911,7 +3002,7 @@ function mergeSecrets(incoming, current, schema) {
|
|
|
2911
3002
|
changed = false;
|
|
2912
3003
|
kept.forEach((k, i) => {
|
|
2913
3004
|
if (reverted.has(i)) return;
|
|
2914
|
-
const why = hostMoved(
|
|
3005
|
+
const why = hostMoved(schema2, out, k.a.path, current, k.from.path, k.from.holder);
|
|
2915
3006
|
if (!why) return;
|
|
2916
3007
|
setAt(out, k.a.path, "");
|
|
2917
3008
|
reverted.add(i);
|
|
@@ -2922,9 +3013,9 @@ function mergeSecrets(incoming, current, schema) {
|
|
|
2922
3013
|
return { config: out, kept: kept.filter((_, i) => !reverted.has(i)).map((k) => item(k.a)), toFill, provided };
|
|
2923
3014
|
}
|
|
2924
3015
|
var CARRIED = ["locale", "timeFormat", "theme", "location", "workday", "plugins", "server"];
|
|
2925
|
-
function planImport(incoming, current, plugins,
|
|
2926
|
-
const report = validateConfig(incoming, plugins,
|
|
2927
|
-
const { config: merged2, ...secrets } = mergeSecrets(incoming, current,
|
|
3016
|
+
function planImport(incoming, current, plugins, schema2 = configSchema(plugins)) {
|
|
3017
|
+
const report = validateConfig(incoming, plugins, schema2);
|
|
3018
|
+
const { config: merged2, ...secrets } = mergeSecrets(incoming, current, schema2);
|
|
2928
3019
|
const raw = isObj3(merged2) ? { ...merged2 } : {};
|
|
2929
3020
|
const carried = [];
|
|
2930
3021
|
for (const k of CARRIED) {
|
|
@@ -2943,7 +3034,7 @@ function planImport(incoming, current, plugins, schema = configSchema(plugins))
|
|
|
2943
3034
|
}
|
|
2944
3035
|
raw.sources = sources;
|
|
2945
3036
|
const config2 = normalize(raw);
|
|
2946
|
-
return { report, config: config2, carried, diff: diffConfigs(current, config2), risks: listRisks(config2,
|
|
3037
|
+
return { report, config: config2, carried, diff: diffConfigs(current, config2), risks: listRisks(config2, schema2, current), secrets };
|
|
2947
3038
|
}
|
|
2948
3039
|
|
|
2949
3040
|
// packages/core/src/config/sample.ts
|
|
@@ -3451,9 +3542,9 @@ function redrawStep(def, state) {
|
|
|
3451
3542
|
if (r === "never") return 0;
|
|
3452
3543
|
return r === "second" ? 1e3 : r === "minute" ? 6e4 : Math.max(250, r.everyMs);
|
|
3453
3544
|
}
|
|
3454
|
-
function fitText(g,
|
|
3455
|
-
if (g.measureText(
|
|
3456
|
-
const chars = [...
|
|
3545
|
+
function fitText(g, text3, maxW) {
|
|
3546
|
+
if (g.measureText(text3).width <= maxW) return text3;
|
|
3547
|
+
const chars = [...text3];
|
|
3457
3548
|
let lo = 0;
|
|
3458
3549
|
let hi = chars.length;
|
|
3459
3550
|
while (lo < hi) {
|
|
@@ -3763,6 +3854,185 @@ var AnimationScheduler = class {
|
|
|
3763
3854
|
|
|
3764
3855
|
// packages/core/src/runtime.ts
|
|
3765
3856
|
import { EventEmitter } from "node:events";
|
|
3857
|
+
import { availableParallelism as availableParallelism2 } from "node:os";
|
|
3858
|
+
|
|
3859
|
+
// packages/core/src/alerts.ts
|
|
3860
|
+
var AlertError = class extends Error {
|
|
3861
|
+
code;
|
|
3862
|
+
constructor(message, code) {
|
|
3863
|
+
super(message);
|
|
3864
|
+
this.code = code;
|
|
3865
|
+
}
|
|
3866
|
+
};
|
|
3867
|
+
var EXTERNAL_ID = /^[A-Za-z0-9_.-]{1,80}$/;
|
|
3868
|
+
var MAX_TITLE = 120;
|
|
3869
|
+
var MAX_TEXT = 240;
|
|
3870
|
+
var MAX_SOURCE = 40;
|
|
3871
|
+
var MAX_DETAIL = 240;
|
|
3872
|
+
var TEST_ALERT_MS = 2e4;
|
|
3873
|
+
var DEFAULT_SNOOZE_MS = 10 * 6e4;
|
|
3874
|
+
var levelRank = (l) => l === "off" ? Infinity : ALERT_LEVELS.indexOf(l);
|
|
3875
|
+
var clip = (s, n) => s.length > n ? `${s.slice(0, n - 1).trimEnd()}\u2026` : s;
|
|
3876
|
+
var oneLine = (s) => s.replace(/\s+/g, " ").trim();
|
|
3877
|
+
var isText = (x) => typeof x === "string" || !!x && typeof x === "object" && !Array.isArray(x) && typeof x.en === "string";
|
|
3878
|
+
function text(x, locale) {
|
|
3879
|
+
if (typeof x === "string") return oneLine(x);
|
|
3880
|
+
if (x && typeof x === "object" && typeof x.en === "string") return oneLine(localize(x, locale));
|
|
3881
|
+
return "";
|
|
3882
|
+
}
|
|
3883
|
+
function parseAlert(raw, now, locale) {
|
|
3884
|
+
if (!raw || typeof raw !== "object") throw new AlertError("an alert is an object", "badAlert");
|
|
3885
|
+
const a = raw;
|
|
3886
|
+
const id = typeof a.id === "string" ? a.id.trim() : "";
|
|
3887
|
+
if (!id || id.length > 120) throw new AlertError("an alert needs an id", "badAlert");
|
|
3888
|
+
if (!ALERT_LEVELS.includes(a.level)) throw new AlertError(`level must be one of ${ALERT_LEVELS.join(", ")}`, "badAlert");
|
|
3889
|
+
const title = clip(text(a.title, locale), MAX_TITLE);
|
|
3890
|
+
if (!title) throw new AlertError("an alert needs a title", "badAlert");
|
|
3891
|
+
const expiresAt = typeof a.expiresAt === "number" && Number.isFinite(a.expiresAt) ? a.expiresAt : typeof a.ttlMs === "number" && a.ttlMs > 0 ? now + a.ttlMs : null;
|
|
3892
|
+
const icon = typeof a.icon === "string" && a.icon.trim() ? a.icon.trim().slice(0, 40) : void 0;
|
|
3893
|
+
const source = clip(text(a.source, locale), MAX_SOURCE);
|
|
3894
|
+
const detail = clip(text(a.detail, locale), MAX_DETAIL);
|
|
3895
|
+
return {
|
|
3896
|
+
id,
|
|
3897
|
+
level: a.level,
|
|
3898
|
+
title,
|
|
3899
|
+
text: clip(text(a.text, locale), MAX_TEXT),
|
|
3900
|
+
...source ? { source } : {},
|
|
3901
|
+
...detail ? { detail } : {},
|
|
3902
|
+
...icon ? { icon } : {},
|
|
3903
|
+
expiresAt,
|
|
3904
|
+
dismissible: a.dismissible !== false
|
|
3905
|
+
};
|
|
3906
|
+
}
|
|
3907
|
+
var order = (a, b) => levelRank(b.level) - levelRank(a.level) || b.since - a.since;
|
|
3908
|
+
var AlertBoard = class {
|
|
3909
|
+
/** From plugins: rebuilt by `sync`. */
|
|
3910
|
+
fromPlugins = /* @__PURE__ */ new Map();
|
|
3911
|
+
/** Posted from outside, and tests: until seen, removed or expired. */
|
|
3912
|
+
posted = /* @__PURE__ */ new Map();
|
|
3913
|
+
/** Plugin alerts seen: hidden while the plugin keeps returning them. */
|
|
3914
|
+
seen = /* @__PURE__ */ new Set();
|
|
3915
|
+
snoozed = /* @__PURE__ */ new Map();
|
|
3916
|
+
log;
|
|
3917
|
+
constructor(log = () => void 0) {
|
|
3918
|
+
this.log = log;
|
|
3919
|
+
}
|
|
3920
|
+
/**
|
|
3921
|
+
* What the plugins return now. A plugin's alert keeps the `since` (and the
|
|
3922
|
+
* `expiresAt` of its `ttlMs`) of when it first came; one that is no longer
|
|
3923
|
+
* returned is gone, and so is its "seen".
|
|
3924
|
+
*/
|
|
3925
|
+
sync(list2, now, locale) {
|
|
3926
|
+
const next = /* @__PURE__ */ new Map();
|
|
3927
|
+
for (const { alert, origin, from } of list2) {
|
|
3928
|
+
let a;
|
|
3929
|
+
try {
|
|
3930
|
+
a = parseAlert(alert, now, locale);
|
|
3931
|
+
} catch (err) {
|
|
3932
|
+
this.log(`${from}: alert ignored: ${err instanceof Error ? err.message : String(err)}`);
|
|
3933
|
+
continue;
|
|
3934
|
+
}
|
|
3935
|
+
const id = `${from}:${a.id}`;
|
|
3936
|
+
if (next.has(id)) continue;
|
|
3937
|
+
const prev = this.fromPlugins.get(id);
|
|
3938
|
+
next.set(id, { ...a, id, origin, from, since: prev?.since ?? now, expiresAt: alert.expiresAt !== void 0 ? a.expiresAt : prev?.expiresAt ?? a.expiresAt });
|
|
3939
|
+
}
|
|
3940
|
+
for (const id of this.fromPlugins.keys()) {
|
|
3941
|
+
if (next.has(id)) continue;
|
|
3942
|
+
this.seen.delete(id);
|
|
3943
|
+
this.snoozed.delete(id);
|
|
3944
|
+
}
|
|
3945
|
+
this.fromPlugins = next;
|
|
3946
|
+
}
|
|
3947
|
+
/** An alert from outside (`POST /api/alerts`). The same id again replaces it, and it shows again. */
|
|
3948
|
+
post(raw, now, locale, screenIds = []) {
|
|
3949
|
+
const body2 = raw && typeof raw === "object" ? { ...raw } : raw;
|
|
3950
|
+
if (body2 && typeof body2 === "object" && !body2.id) body2.id = `alert-${now.toString(36)}${Math.floor(Math.random() * 1296).toString(36)}`;
|
|
3951
|
+
for (const k of ["source", "detail"]) {
|
|
3952
|
+
const v = body2 && typeof body2 === "object" ? body2[k] : void 0;
|
|
3953
|
+
if (v !== void 0 && v !== null && !isText(v)) throw new AlertError(`${k} is a text, or an object of texts by language with at least "en"`, "badAlert");
|
|
3954
|
+
}
|
|
3955
|
+
const a = parseAlert(body2, now, locale);
|
|
3956
|
+
if (!EXTERNAL_ID.test(a.id)) throw new AlertError('the id may have only letters, digits, ".", "_" and "-" (up to 80)', "badAlert");
|
|
3957
|
+
const screens = raw.screens;
|
|
3958
|
+
let only;
|
|
3959
|
+
if (screens !== void 0) {
|
|
3960
|
+
if (!Array.isArray(screens) || !screens.every((s) => typeof s === "string")) throw new AlertError("screens is a list of screen ids", "badAlert");
|
|
3961
|
+
only = screens.filter((s) => screenIds.includes(s));
|
|
3962
|
+
if (!only.length) throw new AlertError("none of those screens exists", "badAlert");
|
|
3963
|
+
}
|
|
3964
|
+
const kept = { ...a, origin: "api", since: now, ...only ? { screens: only } : {} };
|
|
3965
|
+
this.posted.set(a.id, kept);
|
|
3966
|
+
this.snoozed.delete(a.id);
|
|
3967
|
+
return kept;
|
|
3968
|
+
}
|
|
3969
|
+
/** The test alert of a screen: shown there whatever its settings, for `TEST_ALERT_MS`. */
|
|
3970
|
+
test(screen, level, now, words) {
|
|
3971
|
+
const id = `test:${screen.id}`;
|
|
3972
|
+
const a = { id, level, title: words.title, text: words.text, icon: level === "info" ? "info" : "triangle-alert", origin: "test", since: now, expiresAt: now + TEST_ALERT_MS, dismissible: true, screens: [screen.id] };
|
|
3973
|
+
this.posted.set(id, a);
|
|
3974
|
+
this.snoozed.delete(id);
|
|
3975
|
+
return a;
|
|
3976
|
+
}
|
|
3977
|
+
find(id) {
|
|
3978
|
+
return this.posted.get(id) ?? this.fromPlugins.get(id);
|
|
3979
|
+
}
|
|
3980
|
+
/** "Seen": a posted one is gone, a plugin's is hidden while the plugin returns it. */
|
|
3981
|
+
ack(id) {
|
|
3982
|
+
const a = this.find(id);
|
|
3983
|
+
if (!a) return "unknown";
|
|
3984
|
+
if (!a.dismissible) return "notDismissible";
|
|
3985
|
+
if (this.posted.delete(id)) this.snoozed.delete(id);
|
|
3986
|
+
else this.seen.add(id);
|
|
3987
|
+
return "ok";
|
|
3988
|
+
}
|
|
3989
|
+
/** Every alert that can be, seen at once (Home Assistant's button). How many. */
|
|
3990
|
+
ackAll(now) {
|
|
3991
|
+
let n = 0;
|
|
3992
|
+
for (const a of this.list(now)) if (a.dismissible && this.ack(a.id) === "ok") n++;
|
|
3993
|
+
return n;
|
|
3994
|
+
}
|
|
3995
|
+
/** Hidden for `ms`, then back (if still there). */
|
|
3996
|
+
snooze(id, ms, now) {
|
|
3997
|
+
const a = this.find(id);
|
|
3998
|
+
if (!a || this.seen.has(id)) return "unknown";
|
|
3999
|
+
if (!a.dismissible) return "notDismissible";
|
|
4000
|
+
this.snoozed.set(id, now + Math.max(6e4, Math.min(24 * 36e5, ms)));
|
|
4001
|
+
return "ok";
|
|
4002
|
+
}
|
|
4003
|
+
/** Takes a posted alert away (its cause is over). */
|
|
4004
|
+
remove(id) {
|
|
4005
|
+
this.snoozed.delete(id);
|
|
4006
|
+
return this.posted.delete(id);
|
|
4007
|
+
}
|
|
4008
|
+
/** Drops what has expired. */
|
|
4009
|
+
prune(now) {
|
|
4010
|
+
for (const [id, a] of this.posted) if (a.expiresAt !== null && a.expiresAt <= now) this.posted.delete(id);
|
|
4011
|
+
for (const [id, until] of this.snoozed) if (until <= now) this.snoozed.delete(id);
|
|
4012
|
+
}
|
|
4013
|
+
/** Every alert not seen nor expired, the snoozed ones too (with `snoozedUntil`), highest first. */
|
|
4014
|
+
list(now) {
|
|
4015
|
+
const out = [];
|
|
4016
|
+
for (const a of [...this.posted.values(), ...this.fromPlugins.values()]) {
|
|
4017
|
+
if (this.seen.has(a.id) || a.expiresAt !== null && a.expiresAt <= now) continue;
|
|
4018
|
+
const until = this.snoozed.get(a.id);
|
|
4019
|
+
out.push(until && until > now ? { ...a, snoozedUntil: until } : a);
|
|
4020
|
+
}
|
|
4021
|
+
return out.sort(order);
|
|
4022
|
+
}
|
|
4023
|
+
/**
|
|
4024
|
+
* The alert that takes `screen` over now, if any: the highest of those its
|
|
4025
|
+
* settings let through (level, quiet hours; only `critical` while `off`),
|
|
4026
|
+
* with the count of the others. Its test alert always does.
|
|
4027
|
+
*/
|
|
4028
|
+
forScreen(screen, now, off = false) {
|
|
4029
|
+
const cfg = screenAlerts(screen);
|
|
4030
|
+
const onlyCritical = off || inQuietHours(cfg.quiet, now);
|
|
4031
|
+
const min = Math.max(levelRank(cfg.minLevel), onlyCritical ? levelRank("critical") : 0);
|
|
4032
|
+
const here = this.list(now).filter((a) => !a.snoozedUntil && (!a.screens || a.screens.includes(screen.id)) && (a.origin === "test" || levelRank(a.level) >= min));
|
|
4033
|
+
return here.length ? { top: here[0], more: here.length - 1 } : null;
|
|
4034
|
+
}
|
|
4035
|
+
};
|
|
3766
4036
|
|
|
3767
4037
|
// packages/core/src/data.ts
|
|
3768
4038
|
var DEFAULT_FETCH_MS = 10 * 6e4;
|
|
@@ -3897,6 +4167,10 @@ var SourceHub = class {
|
|
|
3897
4167
|
data(type) {
|
|
3898
4168
|
return this.states.get(type)?.data;
|
|
3899
4169
|
}
|
|
4170
|
+
/** The sources running now, with their options. */
|
|
4171
|
+
running() {
|
|
4172
|
+
return [...this.states.values()].map((s) => ({ type: s.type, options: s.options }));
|
|
4173
|
+
}
|
|
3900
4174
|
pick(types2) {
|
|
3901
4175
|
const out = {};
|
|
3902
4176
|
for (const t2 of types2 ?? []) out[t2] = this.data(t2);
|
|
@@ -4733,19 +5007,235 @@ async function discoverTrcc(url2 = "http://127.0.0.1:8099", tokenFile) {
|
|
|
4733
5007
|
}
|
|
4734
5008
|
}
|
|
4735
5009
|
|
|
4736
|
-
// packages/core/src/
|
|
5010
|
+
// packages/core/src/screen-runner.ts
|
|
5011
|
+
init_src();
|
|
5012
|
+
|
|
5013
|
+
// packages/core/src/alert-paint.ts
|
|
5014
|
+
init_src();
|
|
5015
|
+
import { Path2D } from "@napi-rs/canvas";
|
|
5016
|
+
var FLASH_MS = 1e4;
|
|
5017
|
+
var PULSE_MS = 4e3;
|
|
5018
|
+
var MAX_FRAME_AREA = 0.16;
|
|
5019
|
+
var LEVEL_COLORS = {
|
|
5020
|
+
info: { color: "#38bdf8", bg: "#04101a" },
|
|
5021
|
+
warn: { color: "#f59e0b", bg: "#160f02" },
|
|
5022
|
+
critical: { color: "#ef4444", bg: "#190405" }
|
|
5023
|
+
};
|
|
5024
|
+
function alertStepMs(maxFps) {
|
|
5025
|
+
return Math.max(500, Math.ceil(1e3 / Math.max(1, maxFps || 1)));
|
|
5026
|
+
}
|
|
5027
|
+
function alertIntensity(level, elapsed, step) {
|
|
5028
|
+
const k = Math.floor(Math.max(0, elapsed) / step);
|
|
5029
|
+
if (level !== "info" && elapsed < FLASH_MS) return k % 2 === 0 ? 1 : 0.15;
|
|
5030
|
+
const t2 = k * step % PULSE_MS / PULSE_MS;
|
|
5031
|
+
const depth = level === "info" ? 0.3 : 0.45;
|
|
5032
|
+
return Math.round((1 - depth * (0.5 - 0.5 * Math.cos(2 * Math.PI * t2))) * 100) / 100;
|
|
5033
|
+
}
|
|
5034
|
+
function frameWidth(w, h) {
|
|
5035
|
+
const want = Math.max(4, Math.round(Math.min(w, h) * 0.055));
|
|
5036
|
+
const cap = Math.floor(MAX_FRAME_AREA * w * h / (2 * (w + h)));
|
|
5037
|
+
return Math.max(2, Math.min(want, cap));
|
|
5038
|
+
}
|
|
5039
|
+
var circle = (cx, cy, r) => `M${cx - r} ${cy}a${r} ${r} 0 1 0 ${2 * r} 0a${r} ${r} 0 1 0 ${-2 * r} 0`;
|
|
5040
|
+
var ALERT_ICONS = {
|
|
5041
|
+
"triangle-alert": ["m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3", "M12 9v4", "M12 17h.01"],
|
|
5042
|
+
"octagon-alert": ["M12 16h.01", "M12 8v4", "M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z"],
|
|
5043
|
+
info: [circle(12, 12, 10), "M12 16v-4", "M12 8h.01"],
|
|
5044
|
+
bell: ["M10.268 21a2 2 0 0 0 3.464 0", "M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326"],
|
|
5045
|
+
"bell-ring": ["M10.268 21a2 2 0 0 0 3.464 0", "M22 8c0-2.3-.8-4.3-2-6", "M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326", "M4 2C2.8 3.7 2 5.7 2 8"],
|
|
5046
|
+
flame: ["M12 3q1 4 4 6.5t3 5.5a1 1 0 0 1-14 0 5 5 0 0 1 1-3 1 1 0 0 0 5 0c0-2-1.5-3-1.5-5q0-2 2.5-4"],
|
|
5047
|
+
droplet: ["M12 22a7 7 0 0 0 7-7c0-2-1-3.9-3-5.5s-3.5-4-4-6.5c-.5 2.5-2 4.9-4 6.5C6 11.1 5 13 5 15a7 7 0 0 0 7 7z"],
|
|
5048
|
+
phone: ["M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384"],
|
|
5049
|
+
"phone-incoming": ["M16 2v6h6", "m22 2-6 6", "M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384"],
|
|
5050
|
+
activity: ["M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2"],
|
|
5051
|
+
zap: ["M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z"],
|
|
5052
|
+
"cloud-lightning": ["M6 16.326A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 .5 8.973", "m13 12-3 5h4l-3 5"],
|
|
5053
|
+
wind: ["M12.8 19.6A2 2 0 1 0 14 16H2", "M17.5 8a2.5 2.5 0 1 1 2 4H2", "M9.8 4.4A2 2 0 1 1 11 8H2"],
|
|
5054
|
+
waves: ["M2 12q2.5 2 5 0t5 0 5 0 5 0", "M2 19q2.5 2 5 0t5 0 5 0 5 0", "M2 5q2.5 2 5 0t5 0 5 0 5 0"],
|
|
5055
|
+
thermometer: ["M14 4v10.54a4 4 0 1 1-4 0V4a2 2 0 0 1 4 0Z"],
|
|
5056
|
+
siren: ["M7 18v-6a5 5 0 1 1 10 0v6", "M5 21a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-1a2 2 0 0 0-2-2H7a2 2 0 0 0-2 2z", "M21 12h1", "M18.5 4.5 18 5", "M2 12h1", "M12 2v1", "m4.929 4.929.707.707", "M12 12v6"],
|
|
5057
|
+
"shield-alert": ["M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z", "M12 8v4", "M12 16h.01"],
|
|
5058
|
+
"door-open": ["M10 21H2", "M10 3H7a2 2 0 00-2 2v16", "M14 12h.01", "M19 21V5a2 2 0 00-1.675-1.974l-6.163-1.013A1 1 0 0010 3v18a1 1 0 001.124.992z", "M22 21h-3"],
|
|
5059
|
+
"git-branch": ["M15 6a9 9 0 0 0-9 9V3", circle(18, 6, 3), circle(6, 18, 3)],
|
|
5060
|
+
"circle-x": [circle(12, 12, 10), "m15 9-6 6", "m9 9 6 6"],
|
|
5061
|
+
bug: ["M12 20v-9", "M14 7a4 4 0 0 1 4 4v3a6 6 0 0 1-12 0v-3a4 4 0 0 1 4-4z", "M14.12 3.88 16 2", "M21 21a4 4 0 0 0-3.81-4", "M21 5a4 4 0 0 1-3.55 3.97", "M22 13h-4", "M3 21a4 4 0 0 1 3.81-4", "M3 5a4 4 0 0 0 3.55 3.97", "M6 13H2", "m8 2 1.88 1.88", "M9 7.13V6a3 3 0 1 1 6 0v1.13"],
|
|
5062
|
+
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"]
|
|
5063
|
+
};
|
|
5064
|
+
var paths2 = /* @__PURE__ */ new Map();
|
|
5065
|
+
function iconPaths(name) {
|
|
5066
|
+
const d = ALERT_ICONS[name];
|
|
5067
|
+
if (!d) return null;
|
|
5068
|
+
let p = paths2.get(name);
|
|
5069
|
+
if (!p) paths2.set(name, p = d.map((x) => new Path2D(x)));
|
|
5070
|
+
return p;
|
|
5071
|
+
}
|
|
5072
|
+
function iconFor(a) {
|
|
5073
|
+
const icon = a.icon?.trim();
|
|
5074
|
+
if (icon && ALERT_ICONS[icon]) return { path: icon };
|
|
5075
|
+
if (icon && [...icon].length <= 2 && !/^[a-z-]+$/.test(icon)) return { glyph: icon };
|
|
5076
|
+
return { path: a.level === "info" ? "info" : a.level === "critical" ? "octagon-alert" : "triangle-alert" };
|
|
5077
|
+
}
|
|
5078
|
+
function drawIcon(g, a, x, y, size, color2, family) {
|
|
5079
|
+
const which = iconFor(a);
|
|
5080
|
+
g.save();
|
|
5081
|
+
if ("glyph" in which) {
|
|
5082
|
+
drawTracked(g, which.glyph, x + size / 2, y + size * 0.82, { size: Math.round(size * 0.86), family, color: color2, align: "center" });
|
|
5083
|
+
} else {
|
|
5084
|
+
g.translate(x, y);
|
|
5085
|
+
g.scale(size / 24, size / 24);
|
|
5086
|
+
g.strokeStyle = color2;
|
|
5087
|
+
g.lineWidth = 2;
|
|
5088
|
+
g.lineCap = "round";
|
|
5089
|
+
g.lineJoin = "round";
|
|
5090
|
+
for (const p of iconPaths(which.path)) g.stroke(p);
|
|
5091
|
+
}
|
|
5092
|
+
g.restore();
|
|
5093
|
+
}
|
|
5094
|
+
var mixHex = (a, b, t2) => css(mix(hex(a), hex(b), clamp3(t2)));
|
|
5095
|
+
function paintAlert(g, w, h, shown, o) {
|
|
5096
|
+
const a = shown.top;
|
|
5097
|
+
const { color: color2, bg } = LEVEL_COLORS[a.level];
|
|
5098
|
+
g.save();
|
|
5099
|
+
g.fillStyle = bg;
|
|
5100
|
+
g.fillRect(0, 0, w, h);
|
|
5101
|
+
const b = frameWidth(w, h);
|
|
5102
|
+
g.fillStyle = mixHex(bg, color2, 0.12 + 0.88 * o.intensity);
|
|
5103
|
+
g.fillRect(0, 0, w, b);
|
|
5104
|
+
g.fillRect(0, h - b, w, b);
|
|
5105
|
+
g.fillRect(0, b, b, h - 2 * b);
|
|
5106
|
+
g.fillRect(w - b, b, b, h - 2 * b);
|
|
5107
|
+
const shift = o.shift ?? { x: 0, y: 0 };
|
|
5108
|
+
const pad = Math.round(Math.min(w, h) * 0.07);
|
|
5109
|
+
const box = { x: b + pad + shift.x, y: b + pad + shift.y, w: w - 2 * (b + pad), h: h - 2 * (b + pad) };
|
|
5110
|
+
const minPx = Math.max(12, o.minPx);
|
|
5111
|
+
const bold2 = o.fonts.sansBold;
|
|
5112
|
+
const regular = o.fonts.sans;
|
|
5113
|
+
const small = Math.max(minPx, Math.round(Math.min(box.h, box.w) * 0.12));
|
|
5114
|
+
let counterW = 0;
|
|
5115
|
+
if (shown.more > 0) {
|
|
5116
|
+
const label = `+${shown.more}`;
|
|
5117
|
+
const tw = measureTracked(g, label, { size: small, family: bold2 });
|
|
5118
|
+
const ph = Math.round(small * 1.35);
|
|
5119
|
+
counterW = Math.round(tw + small);
|
|
5120
|
+
const cx = box.x + box.w - counterW;
|
|
5121
|
+
g.fillStyle = color2;
|
|
5122
|
+
g.beginPath();
|
|
5123
|
+
g.roundRect(cx, box.y, counterW, ph, ph / 2);
|
|
5124
|
+
g.fill();
|
|
5125
|
+
drawTracked(g, label, cx + counterW / 2, box.y + ph * 0.5 + small * 0.36, { size: small, family: bold2, color: "#0b0b0b", align: "center" });
|
|
5126
|
+
}
|
|
5127
|
+
let sinceW = 0;
|
|
5128
|
+
const sinceSize = Math.max(minPx, Math.round(small * 0.8));
|
|
5129
|
+
const cornerFont = { size: sinceSize, family: regular, color: mixHex(bg, "#ffffff", 0.62) };
|
|
5130
|
+
const cornerMax = Math.round(box.w * (w / h >= 1.5 ? 0.2 : 0.9));
|
|
5131
|
+
let corner = [a.source && o.sinceText ? `${a.source} \xB7 ${o.sinceText}` : a.source ?? o.sinceText].filter((x) => !!x);
|
|
5132
|
+
if (a.source && o.sinceText && measureTracked(g, corner[0], cornerFont) > cornerMax) corner = [a.source, o.sinceText];
|
|
5133
|
+
corner = corner.map((line) => truncate(g, line, cornerMax, cornerFont));
|
|
5134
|
+
corner.forEach((line, i) => {
|
|
5135
|
+
const y2 = box.y + box.h - (corner.length - 1 - i) * Math.round(sinceSize * 1.2);
|
|
5136
|
+
sinceW = Math.max(sinceW, drawTracked(g, line, box.x + box.w, y2, { ...cornerFont, align: "right" }));
|
|
5137
|
+
});
|
|
5138
|
+
const wide = w / h >= 1.5;
|
|
5139
|
+
let col;
|
|
5140
|
+
const iconSize = Math.round(wide ? Math.min(box.h * 0.78, box.w * 0.2) : Math.min(box.w * 0.4, box.h * 0.3));
|
|
5141
|
+
if (wide) {
|
|
5142
|
+
drawIcon(g, a, box.x, box.y + (box.h - iconSize) / 2, iconSize, color2, bold2);
|
|
5143
|
+
const gap = Math.round(iconSize * 0.3);
|
|
5144
|
+
const side = Math.max(counterW, sinceW);
|
|
5145
|
+
col = { x: box.x + iconSize + gap, y: box.y, w: box.w - iconSize - gap - (side ? side + gap / 2 : 0), h: box.h };
|
|
5146
|
+
} else {
|
|
5147
|
+
drawIcon(g, a, box.x + (box.w - iconSize) / 2, box.y, iconSize, color2, bold2);
|
|
5148
|
+
const gap = Math.round(iconSize * 0.15);
|
|
5149
|
+
const below = corner.length ? Math.round(sinceSize * (0.1 + 1.2 * corner.length)) : 0;
|
|
5150
|
+
col = { x: box.x, y: box.y + iconSize + gap, w: box.w, h: box.h - iconSize - gap - below };
|
|
5151
|
+
}
|
|
5152
|
+
const align = wide ? "left" : "center";
|
|
5153
|
+
const ax = wide ? col.x : col.x + col.w / 2;
|
|
5154
|
+
const hasText = !!a.text;
|
|
5155
|
+
const hasDetail = !!a.detail;
|
|
5156
|
+
const lower = hasText && hasDetail ? 2 : hasText || hasDetail ? 1 : 0;
|
|
5157
|
+
let size = Math.round(col.h * [0.55, 0.4, 0.34][lower]);
|
|
5158
|
+
const floor = Math.max(minPx * 2, Math.round(col.h * 0.2));
|
|
5159
|
+
size = fitSize(g, a.title, col.w, { size, family: bold2 }, floor);
|
|
5160
|
+
let titleLines = [a.title];
|
|
5161
|
+
if (measureTracked(g, a.title, { size, family: bold2 }) > col.w) {
|
|
5162
|
+
size = Math.max(minPx * 1.5, Math.round(col.h * [0.36, 0.27, 0.24][lower]));
|
|
5163
|
+
titleLines = wrapLines(g, a.title, col.w, 2, { size, family: bold2 });
|
|
5164
|
+
}
|
|
5165
|
+
const tLine = size * 1.08;
|
|
5166
|
+
const textSize = Math.max(minPx, Math.min(Math.round(size * 0.5), Math.round(size * 0.42 + minPx * 0.4)));
|
|
5167
|
+
const lineH = textSize * 1.25;
|
|
5168
|
+
const gapH = textSize * 0.4;
|
|
5169
|
+
const detailGap = hasText && hasDetail ? textSize * 0.25 : 0;
|
|
5170
|
+
const room = col.h - titleLines.length * tLine - gapH - detailGap;
|
|
5171
|
+
const fits = Math.max(1, Math.min(3, Math.floor(room / lineH)));
|
|
5172
|
+
const font = { size: textSize, family: regular };
|
|
5173
|
+
const textLines = hasText ? wrapLines(g, a.text, col.w, hasDetail ? Math.max(1, fits - 1) : fits, font) : [];
|
|
5174
|
+
const detailLines = hasDetail ? wrapLines(g, a.detail, col.w, fits - textLines.length, font) : [];
|
|
5175
|
+
const lowerLines = textLines.length + detailLines.length;
|
|
5176
|
+
const blockH = titleLines.length * tLine + (lowerLines ? gapH + lowerLines * lineH + (textLines.length && detailLines.length ? detailGap : 0) : 0);
|
|
5177
|
+
let y = col.y + Math.max(0, (col.h - blockH) / 2);
|
|
5178
|
+
for (const line of titleLines) {
|
|
5179
|
+
drawTracked(g, line, ax, y + size * 0.86, { size, family: bold2, color: "#ffffff", align });
|
|
5180
|
+
y += tLine;
|
|
5181
|
+
}
|
|
5182
|
+
if (lowerLines) y += gapH;
|
|
5183
|
+
for (const line of textLines) {
|
|
5184
|
+
drawTracked(g, line, ax, y + textSize * 0.95, { ...font, color: "#e4e4e7", align });
|
|
5185
|
+
y += lineH;
|
|
5186
|
+
}
|
|
5187
|
+
if (textLines.length && detailLines.length) y += detailGap;
|
|
5188
|
+
const detailColor = mixHex(color2, "#ffffff", 0.45);
|
|
5189
|
+
for (const line of detailLines) {
|
|
5190
|
+
drawTracked(g, line, ax, y + textSize * 0.95, { ...font, color: detailColor, align });
|
|
5191
|
+
y += lineH;
|
|
5192
|
+
}
|
|
5193
|
+
g.restore();
|
|
5194
|
+
}
|
|
5195
|
+
|
|
5196
|
+
// packages/core/src/frame-stats.ts
|
|
5197
|
+
var FPS_WINDOW_MS = 5e3;
|
|
5198
|
+
var round = (ms) => Math.round(ms * 10) / 10;
|
|
5199
|
+
var FrameStats = class {
|
|
5200
|
+
sent = [];
|
|
5201
|
+
paint = 0;
|
|
5202
|
+
encode = 0;
|
|
5203
|
+
frames = 0;
|
|
5204
|
+
/** A frame painted (`paintMs` on this thread) and encoded (`encodeMs` in the thread pool, waiting included). */
|
|
5205
|
+
painted(paintMs, encodeMs) {
|
|
5206
|
+
this.paint = this.frames ? this.paint * 0.9 + paintMs * 0.1 : paintMs;
|
|
5207
|
+
this.encode = this.frames ? this.encode * 0.9 + encodeMs * 0.1 : encodeMs;
|
|
5208
|
+
this.frames++;
|
|
5209
|
+
}
|
|
5210
|
+
/** A frame sent to the panel at `at`. */
|
|
5211
|
+
sentAt(at) {
|
|
5212
|
+
this.sent.push(at);
|
|
5213
|
+
if (this.sent.length > 600) this.sent.splice(0, this.sent.length - 600);
|
|
5214
|
+
}
|
|
5215
|
+
read(now = Date.now()) {
|
|
5216
|
+
const from = now - FPS_WINDOW_MS;
|
|
5217
|
+
while (this.sent.length && this.sent[0] < from) this.sent.shift();
|
|
5218
|
+
return { fps: round(this.sent.length * 1e3 / FPS_WINDOW_MS), paintMs: round(this.paint), encodeMs: round(this.encode), frames: this.frames };
|
|
5219
|
+
}
|
|
5220
|
+
};
|
|
5221
|
+
|
|
5222
|
+
// packages/core/src/screen-runner.ts
|
|
4737
5223
|
var TICK_MS = 250;
|
|
5224
|
+
var PLAY_IDLE_MS = 6e4;
|
|
4738
5225
|
function lazyJpeg(c, turned = 0) {
|
|
4739
5226
|
let b = null;
|
|
4740
5227
|
return () => b ??= (turned ? rotateCanvas(c, (360 - turned) % 360) : c).toBuffer("image/jpeg", 88);
|
|
4741
5228
|
}
|
|
4742
|
-
function encode(c, kind, quality) {
|
|
4743
|
-
|
|
5229
|
+
function encode(c, kind, quality, raster) {
|
|
5230
|
+
const t0 = performance.now();
|
|
5231
|
+
const p = kind === "jpeg" ? c.encode("jpeg", Math.max(1, Math.min(100, quality || 90))) : c.encode("png");
|
|
5232
|
+
if (raster) raster.ms += performance.now() - t0;
|
|
5233
|
+
return p;
|
|
4744
5234
|
}
|
|
4745
5235
|
var MIN_FIT_QUALITY = 20;
|
|
4746
|
-
async function encodeFit(c, kind, quality, maxBytes) {
|
|
5236
|
+
async function encodeFit(c, kind, quality, maxBytes, raster) {
|
|
4747
5237
|
const q0 = Math.max(1, Math.min(100, quality || 90));
|
|
4748
|
-
let out = await encode(c, kind, q0);
|
|
5238
|
+
let out = await encode(c, kind, q0, raster);
|
|
4749
5239
|
if (kind !== "jpeg" || !(maxBytes > 0) || out.length <= maxBytes) return { out, quality: q0, over: false };
|
|
4750
5240
|
let q3 = q0;
|
|
4751
5241
|
while (q3 > MIN_FIT_QUALITY) {
|
|
@@ -4767,10 +5257,13 @@ var ScreenRunner = class {
|
|
|
4767
5257
|
pinned = null;
|
|
4768
5258
|
playedSlot = /* @__PURE__ */ new Map();
|
|
4769
5259
|
interlude = null;
|
|
5260
|
+
/** The buttons of whoever plays the interlude now (Play page). */
|
|
5261
|
+
pad = null;
|
|
4770
5262
|
/** Switched off from outside (Home Assistant, the API): black until switched on. Not saved. */
|
|
4771
5263
|
off = false;
|
|
4772
5264
|
/** An interlude asked for now (the editor, Home Assistant): played as soon as the screen is free. */
|
|
4773
5265
|
wanted = null;
|
|
5266
|
+
wantedPlay = false;
|
|
4774
5267
|
/** When `fit` last told the log that frames were shrunk, to say it now and then, not every frame. */
|
|
4775
5268
|
fitLoggedAt = 0;
|
|
4776
5269
|
/** Instance ids on the current page, to know if a data change concerns us. */
|
|
@@ -4785,19 +5278,31 @@ var ScreenRunner = class {
|
|
|
4785
5278
|
/** Set while a widget's animation plays: its widget type. */
|
|
4786
5279
|
animating = null;
|
|
4787
5280
|
closed = false;
|
|
5281
|
+
/** The alert that has the screen now, over everything (set by the runtime, see `setAlert`). */
|
|
5282
|
+
alert = null;
|
|
5283
|
+
/** When the alert on top came up here: it flashes from then. */
|
|
5284
|
+
alertStart = 0;
|
|
5285
|
+
/** What the last alert frame showed, so an equal one isn't painted again. */
|
|
5286
|
+
alertKey = null;
|
|
5287
|
+
/** Real fps, paint and encode times (see frame-stats.ts). */
|
|
5288
|
+
stats = new FrameStats();
|
|
4788
5289
|
screen;
|
|
4789
5290
|
rt;
|
|
4790
|
-
|
|
5291
|
+
/** `device`: one already open for this screen (handed over by a thread that stopped). */
|
|
5292
|
+
constructor(screen, rt, device) {
|
|
4791
5293
|
this.screen = screen;
|
|
4792
5294
|
this.rt = rt;
|
|
4793
5295
|
this.deviceKey = JSON.stringify(screen.device);
|
|
4794
|
-
this.device = openDevice(screen
|
|
5296
|
+
this.device = device ?? rt.openDevice(screen, (m) => rt.log(`screen:${screen.name}`, m));
|
|
4795
5297
|
this.pinned = screen.pinnedPage ?? null;
|
|
4796
5298
|
this.scheduler = new AnimationScheduler(() => rt.rnd(), (type, why) => rt.log(type, `animation ignored: ${why}`));
|
|
4797
5299
|
}
|
|
4798
5300
|
/** Encodes a frame within the screen's `maxBytes`, saying so in the log (at most every 10 min) when it had to shrink it. */
|
|
4799
|
-
async fit(c, kind, quality, screen) {
|
|
4800
|
-
const
|
|
5301
|
+
async fit(c, kind, quality, screen, paintMs = 0) {
|
|
5302
|
+
const t0 = performance.now();
|
|
5303
|
+
const raster = { ms: 0 };
|
|
5304
|
+
const r = await encodeFit(c, kind, quality, screen.maxBytes, raster);
|
|
5305
|
+
this.stats.painted(paintMs + raster.ms, performance.now() - t0 - raster.ms);
|
|
4801
5306
|
if ((r.quality !== Math.max(1, Math.min(100, quality || 90)) || r.over) && Date.now() - this.fitLoggedAt > 10 * 6e4) {
|
|
4802
5307
|
this.fitLoggedAt = Date.now();
|
|
4803
5308
|
this.rt.log(
|
|
@@ -4817,7 +5322,7 @@ var ScreenRunner = class {
|
|
|
4817
5322
|
const key = JSON.stringify(screen.device);
|
|
4818
5323
|
if (key !== this.deviceKey) {
|
|
4819
5324
|
this.device.close();
|
|
4820
|
-
this.device = openDevice(screen
|
|
5325
|
+
this.device = this.rt.openDevice(screen, (m) => this.rt.log(`screen:${screen.name}`, m));
|
|
4821
5326
|
this.deviceKey = key;
|
|
4822
5327
|
this.last = null;
|
|
4823
5328
|
}
|
|
@@ -4831,18 +5336,44 @@ var ScreenRunner = class {
|
|
|
4831
5336
|
const pages = this.screen.pages.filter((p) => whenMatches(p.when, working));
|
|
4832
5337
|
return pickPage(pages, now, this.pinned);
|
|
4833
5338
|
}
|
|
5339
|
+
/**
|
|
5340
|
+
* The alert for this screen now (or none). One coming up stops what plays
|
|
5341
|
+
* (an interlude, a game, an animation: they check `alert`) and the next
|
|
5342
|
+
* update paints it; one going away gives the pages back.
|
|
5343
|
+
*/
|
|
5344
|
+
setAlert(shown, now) {
|
|
5345
|
+
const was = this.alert;
|
|
5346
|
+
this.alert = shown;
|
|
5347
|
+
if (shown && shown.top.id !== was?.top.id) this.alertStart = now;
|
|
5348
|
+
if (shown && !was && this.interlude) {
|
|
5349
|
+
this.rt.log(`screen:${this.screen.name}`, `${this.interlude.type} stopped: an alert`);
|
|
5350
|
+
this.stopInterlude();
|
|
5351
|
+
}
|
|
5352
|
+
if (!shown && was) {
|
|
5353
|
+
this.alertKey = null;
|
|
5354
|
+
this.last = null;
|
|
5355
|
+
this.dirty = true;
|
|
5356
|
+
}
|
|
5357
|
+
}
|
|
4834
5358
|
async update(now) {
|
|
4835
5359
|
if (this.busy || !this.screen.enabled) return;
|
|
4836
5360
|
this.busy = true;
|
|
4837
5361
|
try {
|
|
5362
|
+
if (this.alert) {
|
|
5363
|
+
this.wanted = null;
|
|
5364
|
+
await this.paintAlert(this.alert, now);
|
|
5365
|
+
return;
|
|
5366
|
+
}
|
|
4838
5367
|
const asked = this.wanted;
|
|
5368
|
+
const play = this.wantedPlay;
|
|
4839
5369
|
this.wanted = null;
|
|
4840
|
-
|
|
5370
|
+
this.wantedPlay = false;
|
|
5371
|
+
if (!this.off && await this.maybeInterlude(now, asked ?? void 0, play)) return;
|
|
4841
5372
|
const page = this.currentPage(now);
|
|
4842
5373
|
if (page?.id !== this.page?.id) {
|
|
4843
5374
|
this.page = page;
|
|
4844
5375
|
this.dirty = true;
|
|
4845
|
-
this.rt.
|
|
5376
|
+
this.rt.pageChanged();
|
|
4846
5377
|
}
|
|
4847
5378
|
if (!this.dirty && now < this.nextAt) {
|
|
4848
5379
|
await this.maybeAnimate(now);
|
|
@@ -4857,9 +5388,15 @@ var ScreenRunner = class {
|
|
|
4857
5388
|
this.busy = false;
|
|
4858
5389
|
}
|
|
4859
5390
|
}
|
|
5391
|
+
/** Sends a frame and counts it. */
|
|
5392
|
+
async send(out) {
|
|
5393
|
+
await this.device.send(out);
|
|
5394
|
+
this.stats.sentAt(Date.now());
|
|
5395
|
+
}
|
|
4860
5396
|
async paint(page, now) {
|
|
4861
5397
|
const { screen } = this;
|
|
4862
5398
|
const theme = this.rt.theme();
|
|
5399
|
+
const t0 = performance.now();
|
|
4863
5400
|
let result = null;
|
|
4864
5401
|
let canvas;
|
|
4865
5402
|
if (page && !this.off) {
|
|
@@ -4871,8 +5408,8 @@ var ScreenRunner = class {
|
|
|
4871
5408
|
registry: this.rt.registry,
|
|
4872
5409
|
now,
|
|
4873
5410
|
working: this.rt.working(now),
|
|
4874
|
-
dataOf: (inst) => this.rt.
|
|
4875
|
-
sourcesOf: (types2) => this.rt.
|
|
5411
|
+
dataOf: (inst) => this.rt.dataOf(inst.id),
|
|
5412
|
+
sourcesOf: (types2) => this.rt.sourcesOf(types2),
|
|
4876
5413
|
log: this.rt.log,
|
|
4877
5414
|
demo: this.rt.demoMode,
|
|
4878
5415
|
cache: this.tiles,
|
|
@@ -4884,7 +5421,7 @@ var ScreenRunner = class {
|
|
|
4884
5421
|
for (const t2 of result.tiles) {
|
|
4885
5422
|
if (t2.renderMs === void 0 || !t2.shown) continue;
|
|
4886
5423
|
const type = page.tiles.find((x) => x.id === t2.id)?.widgets.find((w) => w.id === t2.shown)?.type ?? "?";
|
|
4887
|
-
this.rt.
|
|
5424
|
+
this.rt.paintTime(t2.shown, type, t2.renderMs, now);
|
|
4888
5425
|
}
|
|
4889
5426
|
} else {
|
|
4890
5427
|
const swap = screen.rotate === 90 || screen.rotate === 270;
|
|
@@ -4902,15 +5439,50 @@ var ScreenRunner = class {
|
|
|
4902
5439
|
g.restore();
|
|
4903
5440
|
}
|
|
4904
5441
|
const kind = encodeFor(screen.device, screen.jpegQuality);
|
|
4905
|
-
const out = await this.fit(canvas, kind, screen.jpegQuality, screen);
|
|
5442
|
+
const out = await this.fit(canvas, kind, screen.jpegQuality, screen, performance.now() - t0);
|
|
4906
5443
|
this.lastInfo = { screenId: screen.id, pageId: page?.id ?? null, at: now, image: lazyJpeg(canvas, screen.rotate), tiles: result?.tiles ?? [], interlude: null, sleeping };
|
|
4907
|
-
this.rt.
|
|
5444
|
+
this.rt.frame(this.lastInfo);
|
|
4908
5445
|
if (this.last?.equals(out)) return;
|
|
4909
5446
|
this.last = out;
|
|
4910
|
-
await this.
|
|
5447
|
+
await this.send(out);
|
|
5448
|
+
}
|
|
5449
|
+
/**
|
|
5450
|
+
* A frame of the alert: only when it would differ from the last one (the
|
|
5451
|
+
* frame's brightness steps every half second at most, see alert-paint.ts),
|
|
5452
|
+
* so a flashing alert costs 2 frames a second and no more.
|
|
5453
|
+
*/
|
|
5454
|
+
async paintAlert(shown, now) {
|
|
5455
|
+
const { screen } = this;
|
|
5456
|
+
const a = shown.top;
|
|
5457
|
+
const intensity = alertIntensity(a.level, now - this.alertStart, alertStepMs(screen.maxFps));
|
|
5458
|
+
const shift = screen.pixelShift.enabled ? pixelShift(now, screen.pixelShift) : { x: 0, y: 0 };
|
|
5459
|
+
const cfg = this.rt.config;
|
|
5460
|
+
const sinceText = createFormatters({ locale: resolveLocale(cfg), timeFormat: cfg.timeFormat, now }).time(a.since);
|
|
5461
|
+
const minPx = legibleCjkPx(screen);
|
|
5462
|
+
const key = JSON.stringify([a.id, a.level, a.title, a.text, a.source, a.detail, a.icon, shown.more, intensity, shift, sinceText, minPx, screen.width, screen.height, screen.rotate]);
|
|
5463
|
+
if (key === this.alertKey) return;
|
|
5464
|
+
this.alertKey = key;
|
|
5465
|
+
const t0 = performance.now();
|
|
5466
|
+
registerFonts();
|
|
5467
|
+
setFontLocale(resolveLocale(cfg));
|
|
5468
|
+
src_exports.setMinCjkPx(minPx);
|
|
5469
|
+
const canvas = CANVAS.createCanvas(screen.width, screen.height);
|
|
5470
|
+
paintAlert(canvas.getContext("2d"), screen.width, screen.height, shown, { intensity, fonts: this.rt.theme().fonts, minPx, sinceText, shift });
|
|
5471
|
+
const kind = encodeFor(screen.device, screen.jpegQuality || 85);
|
|
5472
|
+
const turned = rotateCanvas(canvas, screen.rotate);
|
|
5473
|
+
const out = await this.fit(turned, kind, screen.jpegQuality || 85, screen, performance.now() - t0);
|
|
5474
|
+
this.lastInfo = { screenId: screen.id, pageId: this.page?.id ?? null, at: now, image: lazyJpeg(canvas), tiles: [], interlude: null, alert: a.id, sleeping: false };
|
|
5475
|
+
this.rt.frame(this.lastInfo);
|
|
5476
|
+
if (this.last?.equals(out)) return;
|
|
5477
|
+
this.last = out;
|
|
5478
|
+
await this.send(out);
|
|
4911
5479
|
}
|
|
4912
|
-
/**
|
|
4913
|
-
|
|
5480
|
+
/**
|
|
5481
|
+
* Plays an interlude if one is due. Returns true while it played (no normal paint this tick).
|
|
5482
|
+
* `play`: someone plays it from the Play page (an interlude with `input`): it gets their
|
|
5483
|
+
* buttons and lasts while they press them, not `maxSeconds`.
|
|
5484
|
+
*/
|
|
5485
|
+
async maybeInterlude(now, force, play = false) {
|
|
4914
5486
|
const due = this.screen.interludes.find((s) => {
|
|
4915
5487
|
if (force) return s.id === force;
|
|
4916
5488
|
if (!s.enabled || s.everyMs < 6e4) return false;
|
|
@@ -4921,7 +5493,7 @@ var ScreenRunner = class {
|
|
|
4921
5493
|
this.playedSlot.set(due.id, Math.floor(now / Math.max(1, due.everyMs)));
|
|
4922
5494
|
const def = this.rt.registry.interlude(due.type);
|
|
4923
5495
|
if (!def) return false;
|
|
4924
|
-
const sources = this.rt.
|
|
5496
|
+
const sources = this.rt.sourcesOf(def.sources);
|
|
4925
5497
|
const options2 = def.options ? validate(def.options, due.options).value : {};
|
|
4926
5498
|
if (!force && def.skip?.({ sources, now, options: options2 })) {
|
|
4927
5499
|
this.rt.log(`screen:${this.screen.name}`, `interlude ${due.type} skipped (busy)`);
|
|
@@ -4929,17 +5501,43 @@ var ScreenRunner = class {
|
|
|
4929
5501
|
}
|
|
4930
5502
|
const [plugin] = due.type.split("/");
|
|
4931
5503
|
const seed = Math.floor(now / Math.max(6e4, due.everyMs));
|
|
4932
|
-
const
|
|
4933
|
-
|
|
5504
|
+
const playing = play && !!def.input;
|
|
5505
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
5506
|
+
let lastPress = Date.now();
|
|
5507
|
+
const input = playing ? { on: (l) => (listeners.add(l), () => void listeners.delete(l)) } : void 0;
|
|
5508
|
+
const player = await def.prepare({ ...baseContext(this.rt.config, plugin, this.rt.log, now), options: options2, width: this.screen.width, height: this.screen.height, seed, theme: this.rt.theme(), canvas: CANVAS, sources, ...input ? { input } : {} });
|
|
5509
|
+
if (!player || !(player.frames > 0)) return false;
|
|
4934
5510
|
const fps = Math.max(1, Math.min(def.fps, this.screen.maxFps));
|
|
4935
|
-
const frames = Math.min(player.frames, Math.round(due.maxSeconds * fps));
|
|
4936
|
-
this.interlude = { slotId: due.id, type: due.type, stopAt: now + frames / fps * 1e3 };
|
|
4937
|
-
|
|
5511
|
+
const frames = playing ? player.frames : Math.min(player.frames, Math.round(due.maxSeconds * fps));
|
|
5512
|
+
this.interlude = { slotId: due.id, type: due.type, stopAt: playing ? Infinity : now + frames / fps * 1e3, play: playing };
|
|
5513
|
+
if (playing) {
|
|
5514
|
+
lastPress = Date.now();
|
|
5515
|
+
this.pad = {
|
|
5516
|
+
send: (e) => {
|
|
5517
|
+
lastPress = Date.now();
|
|
5518
|
+
for (const l of listeners) {
|
|
5519
|
+
try {
|
|
5520
|
+
l(e);
|
|
5521
|
+
} catch (err) {
|
|
5522
|
+
this.rt.log(due.type, `input failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
5523
|
+
}
|
|
5524
|
+
}
|
|
5525
|
+
}
|
|
5526
|
+
};
|
|
5527
|
+
}
|
|
5528
|
+
this.rt.log(`screen:${this.screen.name}`, playing ? `${due.type} being played (ends after ${this.rt.playIdleMs / 1e3} s without a button)` : `playing ${due.type}: ${frames} frames at ${fps} fps`);
|
|
4938
5529
|
const kind = encodeFor(this.screen.device, this.screen.jpegQuality || 85);
|
|
4939
5530
|
const canvas = CANVAS.createCanvas(this.screen.width, this.screen.height);
|
|
4940
5531
|
const g = canvas.getContext("2d");
|
|
4941
5532
|
let start = Date.now();
|
|
4942
|
-
|
|
5533
|
+
const until = playing ? Infinity : Date.now() + due.maxSeconds * 1e3;
|
|
5534
|
+
for (let i = 0; i < frames && this.interlude && !this.alert; i++) {
|
|
5535
|
+
if (Date.now() >= until) break;
|
|
5536
|
+
if (playing && Date.now() - lastPress > this.rt.playIdleMs) {
|
|
5537
|
+
this.rt.log(`screen:${this.screen.name}`, `${due.type}: nobody playing, back to the pages`);
|
|
5538
|
+
break;
|
|
5539
|
+
}
|
|
5540
|
+
const t0 = performance.now();
|
|
4943
5541
|
g.save();
|
|
4944
5542
|
try {
|
|
4945
5543
|
await player.draw(g, i);
|
|
@@ -4949,13 +5547,14 @@ var ScreenRunner = class {
|
|
|
4949
5547
|
} finally {
|
|
4950
5548
|
g.restore();
|
|
4951
5549
|
}
|
|
4952
|
-
const
|
|
4953
|
-
await this.
|
|
5550
|
+
const turned = rotateCanvas(canvas, this.screen.rotate);
|
|
5551
|
+
const out = await this.fit(turned, kind, this.screen.jpegQuality || 85, this.screen, performance.now() - t0);
|
|
5552
|
+
await this.send(out);
|
|
4954
5553
|
if (i % 3 === 0) {
|
|
4955
5554
|
const snap = CANVAS.createCanvas(canvas.width, canvas.height);
|
|
4956
5555
|
snap.getContext("2d").drawImage(canvas, 0, 0);
|
|
4957
5556
|
this.lastInfo = { screenId: this.screen.id, pageId: this.page?.id ?? null, at: Date.now(), image: lazyJpeg(snap), tiles: [], interlude: due.type, sleeping: false };
|
|
4958
|
-
this.rt.
|
|
5557
|
+
this.rt.frame(this.lastInfo);
|
|
4959
5558
|
}
|
|
4960
5559
|
const wait = start + (i + 1) * 1e3 / fps - Date.now();
|
|
4961
5560
|
if (wait > 0) await new Promise((r) => setTimeout(r, wait));
|
|
@@ -4965,6 +5564,7 @@ var ScreenRunner = class {
|
|
|
4965
5564
|
}
|
|
4966
5565
|
}
|
|
4967
5566
|
this.interlude = null;
|
|
5567
|
+
this.pad = null;
|
|
4968
5568
|
this.last = null;
|
|
4969
5569
|
this.dirty = true;
|
|
4970
5570
|
return true;
|
|
@@ -5009,7 +5609,7 @@ var ScreenRunner = class {
|
|
|
5009
5609
|
const frames = Math.round(seconds * fps) + 1;
|
|
5010
5610
|
const interruptible = items.every((x) => x.play.interruptible);
|
|
5011
5611
|
const hold = items.length === 1 ? items[0].play.hold : void 0;
|
|
5012
|
-
const abort = () => this.closed || interruptible && this.dirty || !this.screen.enabled;
|
|
5612
|
+
const abort = () => this.closed || !!this.alert || interruptible && this.dirty || !this.screen.enabled;
|
|
5013
5613
|
this.dirty = false;
|
|
5014
5614
|
const memoData = /* @__PURE__ */ new Map();
|
|
5015
5615
|
const memoSources = /* @__PURE__ */ new Map();
|
|
@@ -5023,6 +5623,7 @@ var ScreenRunner = class {
|
|
|
5023
5623
|
const i = Math.round(s / fps * play.fps);
|
|
5024
5624
|
return i <= 0 || i >= play.frames - 1 ? [] : [{ tileId: a.tileId, instanceId: a.instanceId, frame: { plan: play.plan, i, t: i / (play.frames - 1) } }];
|
|
5025
5625
|
});
|
|
5626
|
+
const t02 = performance.now();
|
|
5026
5627
|
const result = composePage({
|
|
5027
5628
|
cfg: this.rt.config,
|
|
5028
5629
|
screen,
|
|
@@ -5032,12 +5633,12 @@ var ScreenRunner = class {
|
|
|
5032
5633
|
now,
|
|
5033
5634
|
working,
|
|
5034
5635
|
dataOf: (inst) => {
|
|
5035
|
-
if (!memoData.has(inst.id)) memoData.set(inst.id, this.rt.
|
|
5636
|
+
if (!memoData.has(inst.id)) memoData.set(inst.id, this.rt.dataOf(inst.id));
|
|
5036
5637
|
return memoData.get(inst.id);
|
|
5037
5638
|
},
|
|
5038
5639
|
sourcesOf: (types2) => {
|
|
5039
5640
|
const k = JSON.stringify(types2 ?? []);
|
|
5040
|
-
if (!memoSources.has(k)) memoSources.set(k, this.rt.
|
|
5641
|
+
if (!memoSources.has(k)) memoSources.set(k, this.rt.sourcesOf(types2));
|
|
5041
5642
|
return memoSources.get(k);
|
|
5042
5643
|
},
|
|
5043
5644
|
log: this.rt.log,
|
|
@@ -5046,23 +5647,23 @@ var ScreenRunner = class {
|
|
|
5046
5647
|
animate,
|
|
5047
5648
|
rotate: screen.rotate
|
|
5048
5649
|
});
|
|
5049
|
-
sent.push({ out: this.fit(result.canvas, kind, screen.jpegQuality || 85, screen), snap: s % 3 === 1 ? result.canvas : null });
|
|
5650
|
+
sent.push({ out: this.fit(result.canvas, kind, screen.jpegQuality || 85, screen, performance.now() - t02), snap: s % 3 === 1 ? result.canvas : null });
|
|
5050
5651
|
await new Promise((r) => setImmediate(r));
|
|
5051
5652
|
}
|
|
5052
5653
|
const outs = await Promise.all(sent.map((x) => x.out));
|
|
5053
|
-
const
|
|
5054
|
-
this.rt.log(`screen:${screen.name}`, `animating ${
|
|
5654
|
+
const what2 = items.map((x) => `${x.animatable.type} ${x.play.plan.id}`).join(" + ");
|
|
5655
|
+
this.rt.log(`screen:${screen.name}`, `animating ${what2}: ${sent.length} frames at ${fps} fps (painted in ${Date.now() - t0} ms)`);
|
|
5055
5656
|
const holdAt = hold ? Math.max(0, Math.min(sent.length - 1, hold.index - 1)) : -1;
|
|
5056
5657
|
let start = Date.now();
|
|
5057
5658
|
for (let k = 0; k < sent.length; k++) {
|
|
5058
5659
|
if (abort()) return false;
|
|
5059
5660
|
const due = Math.floor((Date.now() - start) * fps / 1e3);
|
|
5060
5661
|
if (k < due - 1 && k !== holdAt && k < sent.length - 1) continue;
|
|
5061
|
-
await this.
|
|
5662
|
+
await this.send(outs[k]);
|
|
5062
5663
|
const snap = sent[k].snap;
|
|
5063
5664
|
if (snap) {
|
|
5064
5665
|
this.lastInfo = { screenId: screen.id, pageId: page.id, at: Date.now(), image: lazyJpeg(snap, screen.rotate), tiles: [], interlude: null, animation: items.map((x) => x.animatable.type).join(", "), sleeping: false };
|
|
5065
|
-
this.rt.
|
|
5666
|
+
this.rt.frame(this.lastInfo);
|
|
5066
5667
|
}
|
|
5067
5668
|
if (hold && k === holdAt) {
|
|
5068
5669
|
const until = Date.now() + hold.ms;
|
|
@@ -5080,27 +5681,410 @@ var ScreenRunner = class {
|
|
|
5080
5681
|
* after the paint or animation under way (asked in the middle of one, it
|
|
5081
5682
|
* used to be dropped without a word).
|
|
5082
5683
|
*/
|
|
5083
|
-
async playNow(slotId) {
|
|
5084
|
-
if (this.off) return;
|
|
5684
|
+
async playNow(slotId, play = false) {
|
|
5685
|
+
if (this.off || this.alert) return;
|
|
5085
5686
|
this.wanted = slotId;
|
|
5687
|
+
this.wantedPlay = play;
|
|
5086
5688
|
if (this.busy) return;
|
|
5087
5689
|
this.busy = true;
|
|
5088
5690
|
try {
|
|
5089
5691
|
this.wanted = null;
|
|
5090
|
-
|
|
5692
|
+
this.wantedPlay = false;
|
|
5693
|
+
await this.maybeInterlude(Date.now(), slotId, play);
|
|
5091
5694
|
} finally {
|
|
5092
5695
|
this.busy = false;
|
|
5093
5696
|
}
|
|
5094
5697
|
}
|
|
5095
5698
|
stopInterlude() {
|
|
5096
5699
|
this.interlude = null;
|
|
5700
|
+
this.pad = null;
|
|
5701
|
+
}
|
|
5702
|
+
dataChanged(change) {
|
|
5703
|
+
if (change.instance && this.visibleIds.has(change.instance) || change.source && this.sourceTypes.has(change.source)) this.dirty = true;
|
|
5704
|
+
}
|
|
5705
|
+
setPinned(pageId) {
|
|
5706
|
+
this.pinned = pageId;
|
|
5707
|
+
this.dirty = true;
|
|
5708
|
+
}
|
|
5709
|
+
setOff(off) {
|
|
5710
|
+
this.off = off;
|
|
5711
|
+
if (off) this.stopInterlude();
|
|
5712
|
+
this.dirty = true;
|
|
5713
|
+
}
|
|
5714
|
+
/** A button from the Play page, for the interlude being played; false when none is. */
|
|
5715
|
+
press(e) {
|
|
5716
|
+
if (!this.pad || !PAD_KEYS.includes(e.key)) return false;
|
|
5717
|
+
this.pad.send({ key: e.key, pressed: !!e.pressed });
|
|
5718
|
+
return true;
|
|
5719
|
+
}
|
|
5720
|
+
deviceTaken = false;
|
|
5721
|
+
takeDevice() {
|
|
5722
|
+
this.deviceTaken = true;
|
|
5723
|
+
return this.device;
|
|
5097
5724
|
}
|
|
5098
5725
|
close() {
|
|
5099
5726
|
this.closed = true;
|
|
5100
5727
|
this.interlude = null;
|
|
5101
|
-
this.device.close();
|
|
5728
|
+
if (!this.deviceTaken) this.device.close();
|
|
5729
|
+
}
|
|
5730
|
+
};
|
|
5731
|
+
|
|
5732
|
+
// packages/core/src/threads/plan.ts
|
|
5733
|
+
import { availableParallelism } from "node:os";
|
|
5734
|
+
function threadsMode(cfg) {
|
|
5735
|
+
return cfg.threads ?? "auto";
|
|
5736
|
+
}
|
|
5737
|
+
function planThreads(cfg, cores = availableParallelism()) {
|
|
5738
|
+
const mode = threadsMode(cfg);
|
|
5739
|
+
const out = /* @__PURE__ */ new Map();
|
|
5740
|
+
const on = cfg.screens.filter((s) => s.enabled);
|
|
5741
|
+
const own = (s) => s.thread ?? (mode === "auto" ? null : mode);
|
|
5742
|
+
const sure = on.filter((s) => own(s) === "always").length;
|
|
5743
|
+
const auto = on.filter((s) => own(s) === null);
|
|
5744
|
+
const autoWhy = on.length < 2 ? "fewScreens" : cores < sure + auto.length + 1 ? "fewCores" : "auto";
|
|
5745
|
+
for (const s of cfg.screens) {
|
|
5746
|
+
if (!s.enabled) out.set(s.id, { thread: false, why: "off" });
|
|
5747
|
+
else if (s.thread) out.set(s.id, { thread: s.thread === "always", why: s.thread });
|
|
5748
|
+
else if (mode !== "auto") out.set(s.id, { thread: mode === "always", why: "setting" });
|
|
5749
|
+
else out.set(s.id, { thread: autoWhy === "auto", why: autoWhy });
|
|
5750
|
+
}
|
|
5751
|
+
return out;
|
|
5752
|
+
}
|
|
5753
|
+
|
|
5754
|
+
// packages/core/src/threads/thread-runner.ts
|
|
5755
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
5756
|
+
import { Worker as Worker2 } from "node:worker_threads";
|
|
5757
|
+
|
|
5758
|
+
// packages/core/src/threads/clone.ts
|
|
5759
|
+
import { Image, createCanvas as createCanvas6 } from "@napi-rs/canvas";
|
|
5760
|
+
var PICTURE = "\0kioskoPicture";
|
|
5761
|
+
var BUFFER = "\0kioskoBuffer";
|
|
5762
|
+
var Unclonable = class extends Error {
|
|
5763
|
+
};
|
|
5764
|
+
function what(v) {
|
|
5765
|
+
if (typeof v === "function") return "a function";
|
|
5766
|
+
const name = Object.getPrototypeOf(v)?.constructor?.name;
|
|
5767
|
+
return name ? `a ${name} (an object of a class)` : "an object of a class";
|
|
5768
|
+
}
|
|
5769
|
+
var CLONED_AS_IS = [Date, RegExp, ArrayBuffer, Error, DataView];
|
|
5770
|
+
function isCanvas(v) {
|
|
5771
|
+
return typeof v.getContext === "function" && typeof v.encode === "function" && typeof v.width === "number";
|
|
5772
|
+
}
|
|
5773
|
+
var ids = /* @__PURE__ */ new WeakMap();
|
|
5774
|
+
var nextId2 = 0;
|
|
5775
|
+
function packPicture(v) {
|
|
5776
|
+
const known = ids.get(v);
|
|
5777
|
+
if (known) return known;
|
|
5778
|
+
let p;
|
|
5779
|
+
if (v instanceof Image && v.src instanceof Uint8Array && v.src.length) {
|
|
5780
|
+
p = { [PICTURE]: "image", id: ++nextId2, width: v.width, height: v.height, bytes: v.src };
|
|
5781
|
+
} else {
|
|
5782
|
+
const w = Math.max(1, v.width);
|
|
5783
|
+
const h = Math.max(1, v.height);
|
|
5784
|
+
let pixels;
|
|
5785
|
+
if (isCanvas(v)) pixels = v.getContext("2d").getImageData(0, 0, w, h).data;
|
|
5786
|
+
else {
|
|
5787
|
+
const c = createCanvas6(w, h);
|
|
5788
|
+
c.getContext("2d").drawImage(v, 0, 0);
|
|
5789
|
+
pixels = c.getContext("2d").getImageData(0, 0, w, h).data;
|
|
5790
|
+
}
|
|
5791
|
+
p = { [PICTURE]: "canvas", id: ++nextId2, width: w, height: h, bytes: new Uint8Array(pixels.buffer, pixels.byteOffset, pixels.byteLength) };
|
|
5792
|
+
}
|
|
5793
|
+
ids.set(v, p);
|
|
5794
|
+
return p;
|
|
5795
|
+
}
|
|
5796
|
+
function pack(value) {
|
|
5797
|
+
const seen = /* @__PURE__ */ new Map();
|
|
5798
|
+
const walk = (v, path) => {
|
|
5799
|
+
if (v === null || typeof v !== "object") {
|
|
5800
|
+
if (typeof v === "function" || typeof v === "symbol") throw new Unclonable(`${path || "the data"} is ${typeof v === "function" ? "a function" : "a symbol"}`);
|
|
5801
|
+
return v;
|
|
5802
|
+
}
|
|
5803
|
+
if (seen.has(v)) return seen.get(v);
|
|
5804
|
+
if (v instanceof Image || isCanvas(v)) return packPicture(v);
|
|
5805
|
+
if (Buffer.isBuffer(v)) return { [BUFFER]: v };
|
|
5806
|
+
if (ArrayBuffer.isView(v) || CLONED_AS_IS.some((c) => v instanceof c)) return v;
|
|
5807
|
+
if (Array.isArray(v)) {
|
|
5808
|
+
const out2 = [];
|
|
5809
|
+
seen.set(v, out2);
|
|
5810
|
+
v.forEach((x, i) => out2.push(walk(x, `${path}[${i}]`)));
|
|
5811
|
+
return out2;
|
|
5812
|
+
}
|
|
5813
|
+
if (v instanceof Map) {
|
|
5814
|
+
const out2 = /* @__PURE__ */ new Map();
|
|
5815
|
+
seen.set(v, out2);
|
|
5816
|
+
for (const [k, x] of v) out2.set(walk(k, `${path}.<key>`), walk(x, `${path}.get(${JSON.stringify(String(k))})`));
|
|
5817
|
+
return out2;
|
|
5818
|
+
}
|
|
5819
|
+
if (v instanceof Set) {
|
|
5820
|
+
const out2 = /* @__PURE__ */ new Set();
|
|
5821
|
+
seen.set(v, out2);
|
|
5822
|
+
for (const x of v) out2.add(walk(x, `${path}.<item>`));
|
|
5823
|
+
return out2;
|
|
5824
|
+
}
|
|
5825
|
+
const proto = Object.getPrototypeOf(v);
|
|
5826
|
+
if (proto !== Object.prototype && proto !== null) throw new Unclonable(`${path || "the data"} is ${what(v)}`);
|
|
5827
|
+
const out = {};
|
|
5828
|
+
seen.set(v, out);
|
|
5829
|
+
for (const [k, x] of Object.entries(v)) out[k] = walk(x, `${path}.${k}`);
|
|
5830
|
+
return out;
|
|
5831
|
+
};
|
|
5832
|
+
return walk(value, "");
|
|
5833
|
+
}
|
|
5834
|
+
|
|
5835
|
+
// packages/core/src/threads/thread-runner.ts
|
|
5836
|
+
function defaultThreadEntry() {
|
|
5837
|
+
return ["./screen-thread.js", "./screen-thread.ts"].map((f) => new URL(f, import.meta.url)).find((u) => existsSync4(u)) ?? new URL("./screen-thread.ts", import.meta.url);
|
|
5838
|
+
}
|
|
5839
|
+
var NO_STATS = { fps: 0, paintMs: 0, encodeMs: 0, frames: 0 };
|
|
5840
|
+
var ThreadRunner = class {
|
|
5841
|
+
screen;
|
|
5842
|
+
device;
|
|
5843
|
+
deviceKey;
|
|
5844
|
+
pinned;
|
|
5845
|
+
off = false;
|
|
5846
|
+
alert = null;
|
|
5847
|
+
lastInfo = null;
|
|
5848
|
+
visibleIds = /* @__PURE__ */ new Set();
|
|
5849
|
+
sourceTypes = /* @__PURE__ */ new Set();
|
|
5850
|
+
state = { page: null, interlude: null, animating: null, stats: NO_STATS, heapBytes: 0 };
|
|
5851
|
+
alertKey = "null";
|
|
5852
|
+
worker = null;
|
|
5853
|
+
/** Bumped with each worker started: messages from an older one are ignored. */
|
|
5854
|
+
generation = 0;
|
|
5855
|
+
closed = false;
|
|
5856
|
+
failed = false;
|
|
5857
|
+
need = { ids: /* @__PURE__ */ new Set(), sources: /* @__PURE__ */ new Set() };
|
|
5858
|
+
images = /* @__PURE__ */ new Map();
|
|
5859
|
+
nextReq = 0;
|
|
5860
|
+
stats = { read: () => this.state.stats };
|
|
5861
|
+
owner;
|
|
5862
|
+
entry;
|
|
5863
|
+
constructor(screen, owner, entry = defaultThreadEntry(), device) {
|
|
5864
|
+
this.screen = screen;
|
|
5865
|
+
this.owner = owner;
|
|
5866
|
+
this.entry = entry;
|
|
5867
|
+
this.pinned = screen.pinnedPage ?? null;
|
|
5868
|
+
this.deviceKey = JSON.stringify(screen.device);
|
|
5869
|
+
this.device = device ?? owner.openDevice(screen, (m) => owner.log(`screen:${screen.name}`, m));
|
|
5870
|
+
this.start();
|
|
5871
|
+
}
|
|
5872
|
+
get page() {
|
|
5873
|
+
return this.state.page ? this.screen.pages.find((p) => p.id === this.state.page) ?? null : null;
|
|
5874
|
+
}
|
|
5875
|
+
get interlude() {
|
|
5876
|
+
return this.state.interlude;
|
|
5877
|
+
}
|
|
5878
|
+
get animating() {
|
|
5879
|
+
return this.state.animating;
|
|
5880
|
+
}
|
|
5881
|
+
/** What the thread's JavaScript holds, in bytes (see `ThreadState.heapBytes`). */
|
|
5882
|
+
get heapBytes() {
|
|
5883
|
+
return this.state.heapBytes;
|
|
5884
|
+
}
|
|
5885
|
+
post(m) {
|
|
5886
|
+
if (this.worker && !this.failed) this.worker.postMessage(m);
|
|
5887
|
+
}
|
|
5888
|
+
start() {
|
|
5889
|
+
const generation = ++this.generation;
|
|
5890
|
+
const init = {
|
|
5891
|
+
config: this.owner.config,
|
|
5892
|
+
screen: this.screen,
|
|
5893
|
+
plugins: this.owner.registry.threadPlugins(),
|
|
5894
|
+
demo: this.owner.demoMode,
|
|
5895
|
+
maxConcurrent: this.owner.maxConcurrent,
|
|
5896
|
+
playIdleMs: this.owner.playIdleMs,
|
|
5897
|
+
pinned: this.pinned,
|
|
5898
|
+
off: this.off
|
|
5899
|
+
};
|
|
5900
|
+
const w = new Worker2(this.entry, { workerData: init, name: `kiosko screen ${this.screen.id}` });
|
|
5901
|
+
this.worker = w;
|
|
5902
|
+
w.on("message", (m) => generation === this.generation && this.onMessage(m));
|
|
5903
|
+
w.on("error", (err) => generation === this.generation && this.fail(`the thread failed: ${err instanceof Error ? err.message : String(err)}`));
|
|
5904
|
+
w.on("exit", (code) => {
|
|
5905
|
+
if (generation !== this.generation || this.closed || this.failed) return;
|
|
5906
|
+
this.fail(`the thread stopped (exit code ${code})`);
|
|
5907
|
+
});
|
|
5908
|
+
this.need = { ids: /* @__PURE__ */ new Set(), sources: /* @__PURE__ */ new Set() };
|
|
5909
|
+
this.sendNeeded();
|
|
5910
|
+
if (this.alert) this.post({ t: "alert", shown: this.alert });
|
|
5911
|
+
}
|
|
5912
|
+
/** What the screen shows, on any page or interlude: the data its thread must have. */
|
|
5913
|
+
needed() {
|
|
5914
|
+
const ids2 = /* @__PURE__ */ new Set();
|
|
5915
|
+
const sources = /* @__PURE__ */ new Set();
|
|
5916
|
+
const reg = this.owner.registry;
|
|
5917
|
+
for (const { widget } of widgetsOf(this.screen)) {
|
|
5918
|
+
const def = reg.widget(widget.type);
|
|
5919
|
+
if (!def || widget.disabled) continue;
|
|
5920
|
+
ids2.add(widget.id);
|
|
5921
|
+
for (const s of def.sources ?? []) sources.add(s);
|
|
5922
|
+
}
|
|
5923
|
+
for (const slot of this.screen.interludes) for (const s of reg.interlude(slot.type)?.sources ?? []) sources.add(s);
|
|
5924
|
+
return { ids: ids2, sources };
|
|
5925
|
+
}
|
|
5926
|
+
/** Sends what is needed now and wasn't before. */
|
|
5927
|
+
sendNeeded() {
|
|
5928
|
+
const now = this.needed();
|
|
5929
|
+
const old = this.need;
|
|
5930
|
+
this.need = now;
|
|
5931
|
+
for (const id of now.ids) if (!old.ids.has(id)) this.sendData({ instance: id }, true);
|
|
5932
|
+
for (const s of now.sources) if (!old.sources.has(s)) this.sendData({ source: s }, true);
|
|
5933
|
+
}
|
|
5934
|
+
/** `fresh`: the thread has nothing for it yet, so nothing need be said when there is nothing. */
|
|
5935
|
+
sendData(change, fresh = false) {
|
|
5936
|
+
if (this.failed) return;
|
|
5937
|
+
const value = change.instance ? this.owner.dataOf(change.instance) : this.owner.sourceData(change.source);
|
|
5938
|
+
if (value === void 0 && fresh) return;
|
|
5939
|
+
let packed;
|
|
5940
|
+
try {
|
|
5941
|
+
packed = pack(value);
|
|
5942
|
+
} catch (err) {
|
|
5943
|
+
if (!(err instanceof Unclonable)) throw err;
|
|
5944
|
+
this.fail(`the data of ${change.instance ? `widget ${change.instance}` : change.source} can't go to another thread: ${err.message}`);
|
|
5945
|
+
return;
|
|
5946
|
+
}
|
|
5947
|
+
this.post({ t: "data", ...change, value: packed });
|
|
5948
|
+
}
|
|
5949
|
+
onMessage(m) {
|
|
5950
|
+
switch (m.t) {
|
|
5951
|
+
case "ready": {
|
|
5952
|
+
const used = new Set([...[...widgetsOf(this.screen)].map((x) => x.widget.type), ...this.screen.interludes.map((s) => s.type)].map((t2) => t2.split("/")[0]));
|
|
5953
|
+
const bad = m.problems.find((p) => used.has(p.split(":")[0]));
|
|
5954
|
+
if (bad) this.fail(`plugin ${bad}`);
|
|
5955
|
+
return;
|
|
5956
|
+
}
|
|
5957
|
+
case "log":
|
|
5958
|
+
this.owner.log(m.scope, m.message);
|
|
5959
|
+
return;
|
|
5960
|
+
case "paintTime":
|
|
5961
|
+
this.owner.paintTime(m.instance, m.type, m.ms, m.now);
|
|
5962
|
+
return;
|
|
5963
|
+
case "frame": {
|
|
5964
|
+
const info = { ...m.info, image: () => this.image() };
|
|
5965
|
+
this.lastInfo = info;
|
|
5966
|
+
this.owner.frame(info);
|
|
5967
|
+
return;
|
|
5968
|
+
}
|
|
5969
|
+
case "state": {
|
|
5970
|
+
const pageBefore = this.state.page;
|
|
5971
|
+
this.state = m.state;
|
|
5972
|
+
if (m.state.page !== pageBefore) this.owner.pageChanged();
|
|
5973
|
+
return;
|
|
5974
|
+
}
|
|
5975
|
+
case "send": {
|
|
5976
|
+
const frame = Buffer.from(m.frame.buffer, m.frame.byteOffset, m.frame.byteLength);
|
|
5977
|
+
const seq = m.seq;
|
|
5978
|
+
void this.device.send(frame).finally(() => this.post({ t: "sent", seq }));
|
|
5979
|
+
return;
|
|
5980
|
+
}
|
|
5981
|
+
case "image": {
|
|
5982
|
+
const done2 = this.images.get(m.req);
|
|
5983
|
+
this.images.delete(m.req);
|
|
5984
|
+
done2?.(m.image ? Buffer.from(m.image.buffer, m.image.byteOffset, m.image.byteLength) : null);
|
|
5985
|
+
return;
|
|
5986
|
+
}
|
|
5987
|
+
}
|
|
5988
|
+
}
|
|
5989
|
+
/** The last frame's picture, asked of the thread, which has it. */
|
|
5990
|
+
image() {
|
|
5991
|
+
return new Promise((resolve8, reject) => {
|
|
5992
|
+
if (!this.worker || this.failed) return reject(new Error("the screen's thread is gone"));
|
|
5993
|
+
const req = ++this.nextReq;
|
|
5994
|
+
this.images.set(req, (b) => b ? resolve8(b) : reject(new Error("no frame yet")));
|
|
5995
|
+
this.post({ t: "image", req });
|
|
5996
|
+
});
|
|
5997
|
+
}
|
|
5998
|
+
fail(reason) {
|
|
5999
|
+
if (this.failed || this.closed) return;
|
|
6000
|
+
this.failed = true;
|
|
6001
|
+
this.stopWorker();
|
|
6002
|
+
this.owner.threadFailed(this.screen.id, reason);
|
|
6003
|
+
}
|
|
6004
|
+
stopWorker() {
|
|
6005
|
+
const w = this.worker;
|
|
6006
|
+
this.worker = null;
|
|
6007
|
+
this.generation++;
|
|
6008
|
+
for (const done2 of this.images.values()) done2(null);
|
|
6009
|
+
this.images.clear();
|
|
6010
|
+
if (!w) return;
|
|
6011
|
+
try {
|
|
6012
|
+
w.postMessage({ t: "close" });
|
|
6013
|
+
} catch {
|
|
6014
|
+
}
|
|
6015
|
+
const t2 = setTimeout(() => void w.terminate(), 1e3);
|
|
6016
|
+
t2.unref();
|
|
6017
|
+
w.once("exit", () => clearTimeout(t2));
|
|
6018
|
+
w.unref();
|
|
6019
|
+
}
|
|
6020
|
+
/** The panel, for whoever paints the screen next (the main thread, when this one failed); closing this runner leaves it open. */
|
|
6021
|
+
takeDevice() {
|
|
6022
|
+
const d = this.device;
|
|
6023
|
+
this.deviceKey = "";
|
|
6024
|
+
return d;
|
|
6025
|
+
}
|
|
6026
|
+
update() {
|
|
6027
|
+
return Promise.resolve();
|
|
6028
|
+
}
|
|
6029
|
+
reconfigure(screen) {
|
|
6030
|
+
const key = JSON.stringify(screen.device);
|
|
6031
|
+
if (key !== this.deviceKey) {
|
|
6032
|
+
if (this.deviceKey) this.device.close();
|
|
6033
|
+
this.device = this.owner.openDevice(screen, (m) => this.owner.log(`screen:${screen.name}`, m));
|
|
6034
|
+
this.deviceKey = key;
|
|
6035
|
+
}
|
|
6036
|
+
if (screen.pinnedPage !== this.screen.pinnedPage) this.pinned = screen.pinnedPage ?? null;
|
|
6037
|
+
this.screen = screen;
|
|
6038
|
+
this.post({ t: "apply", config: this.owner.config, screen });
|
|
6039
|
+
this.sendNeeded();
|
|
6040
|
+
}
|
|
6041
|
+
/** A plugin's code changed: a new thread loads them all again (an ES module can't be unloaded). */
|
|
6042
|
+
invalidate() {
|
|
6043
|
+
if (this.closed || this.failed) return;
|
|
6044
|
+
this.stopWorker();
|
|
6045
|
+
this.start();
|
|
6046
|
+
}
|
|
6047
|
+
dataChanged(change) {
|
|
6048
|
+
if (change.instance && this.need.ids.has(change.instance) || change.source && this.need.sources.has(change.source)) this.sendData(change);
|
|
6049
|
+
}
|
|
6050
|
+
setAlert(shown) {
|
|
6051
|
+
const key = JSON.stringify(shown);
|
|
6052
|
+
this.alert = shown;
|
|
6053
|
+
if (key === this.alertKey) return;
|
|
6054
|
+
this.alertKey = key;
|
|
6055
|
+
this.post({ t: "alert", shown });
|
|
6056
|
+
}
|
|
6057
|
+
setPinned(pageId) {
|
|
6058
|
+
this.pinned = pageId;
|
|
6059
|
+
this.post({ t: "pin", page: pageId });
|
|
6060
|
+
}
|
|
6061
|
+
setOff(off) {
|
|
6062
|
+
this.off = off;
|
|
6063
|
+
if (off) this.state = { ...this.state, interlude: null };
|
|
6064
|
+
this.post({ t: "off", off });
|
|
6065
|
+
}
|
|
6066
|
+
async playNow(slotId, play = false) {
|
|
6067
|
+
if (this.off || this.alert) return;
|
|
6068
|
+
this.post({ t: "play", slot: slotId, play });
|
|
6069
|
+
}
|
|
6070
|
+
stopInterlude() {
|
|
6071
|
+
this.state = { ...this.state, interlude: null };
|
|
6072
|
+
this.post({ t: "stop" });
|
|
6073
|
+
}
|
|
6074
|
+
press(e) {
|
|
6075
|
+
if (!this.state.interlude?.play || !PAD_KEYS.includes(e.key)) return false;
|
|
6076
|
+
this.post({ t: "press", e: { key: e.key, pressed: !!e.pressed } });
|
|
6077
|
+
return true;
|
|
6078
|
+
}
|
|
6079
|
+
close() {
|
|
6080
|
+
if (this.closed) return;
|
|
6081
|
+
this.closed = true;
|
|
6082
|
+
this.stopWorker();
|
|
6083
|
+
if (this.deviceKey) this.device.close();
|
|
5102
6084
|
}
|
|
5103
6085
|
};
|
|
6086
|
+
|
|
6087
|
+
// packages/core/src/runtime.ts
|
|
5104
6088
|
var SLOW_PAINT_MS = 50;
|
|
5105
6089
|
var SLOW_WARN_EVERY_MS = 10 * 6e4;
|
|
5106
6090
|
var PaintTimes = class {
|
|
@@ -5120,14 +6104,23 @@ var PaintTimes = class {
|
|
|
5120
6104
|
}
|
|
5121
6105
|
/** Every instance measured, slowest (on average) first. */
|
|
5122
6106
|
list() {
|
|
5123
|
-
return [...this.times.values()].map(({ warnedAt: _, ...t2 }) => ({ ...t2, lastMs:
|
|
6107
|
+
return [...this.times.values()].map(({ warnedAt: _, ...t2 }) => ({ ...t2, lastMs: round2(t2.lastMs), avgMs: round2(t2.avgMs), maxMs: round2(t2.maxMs) })).sort((a, b) => b.avgMs - a.avgMs);
|
|
5124
6108
|
}
|
|
5125
6109
|
/** Forgets instances that are gone. */
|
|
5126
|
-
retain(
|
|
5127
|
-
for (const id of this.times.keys()) if (!
|
|
6110
|
+
retain(ids2) {
|
|
6111
|
+
for (const id of this.times.keys()) if (!ids2.has(id)) this.times.delete(id);
|
|
5128
6112
|
}
|
|
5129
6113
|
};
|
|
5130
|
-
var
|
|
6114
|
+
var round2 = (ms) => Math.round(ms * 10) / 10;
|
|
6115
|
+
var ALERTS_EVERY_MS = 5e3;
|
|
6116
|
+
var TEST_ALERT_TITLE = { en: "Test alert", es: "Alerta de prueba", de: "Testalarm", "zh-Hant": "\u6E2C\u8A66\u8B66\u5831", "zh-Hans": "\u6D4B\u8BD5\u8B66\u62A5" };
|
|
6117
|
+
var TEST_ALERT_TEXT = {
|
|
6118
|
+
en: "This is how an alert looks on {screen}. Can you read it from where you sit?",
|
|
6119
|
+
es: "As\xED se ve una alerta en {screen}. \xBFSe lee desde donde te sientas?",
|
|
6120
|
+
de: "So sieht ein Alarm auf {screen} aus. Lesbar von deinem Platz aus?",
|
|
6121
|
+
"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",
|
|
6122
|
+
"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"
|
|
6123
|
+
};
|
|
5131
6124
|
var Runtime = class extends EventEmitter {
|
|
5132
6125
|
config;
|
|
5133
6126
|
hub;
|
|
@@ -5139,8 +6132,27 @@ var Runtime = class extends EventEmitter {
|
|
|
5139
6132
|
logs = [];
|
|
5140
6133
|
/** How many animations play together on a screen (see animation.ts). */
|
|
5141
6134
|
maxConcurrent = MAX_CONCURRENT;
|
|
6135
|
+
/** An interlude being played from the Play page ends after this long without a button. */
|
|
6136
|
+
playIdleMs = PLAY_IDLE_MS;
|
|
5142
6137
|
/** Random numbers for the animations; tests replace it with a seeded one. */
|
|
5143
6138
|
rnd = Math.random;
|
|
6139
|
+
/** Alerts from the plugins, from outside and the screens' tests (see alerts.ts). */
|
|
6140
|
+
alerts = new AlertBoard((m) => this.log("alerts", m));
|
|
6141
|
+
/** Data changed since the plugins' alerts were last asked. */
|
|
6142
|
+
alertsDirty = true;
|
|
6143
|
+
alertsAskedAt = 0;
|
|
6144
|
+
/** What the editor was last told, to tell it only changes. */
|
|
6145
|
+
alertsSig = "";
|
|
6146
|
+
/** A plugin's `alerts` failing, said once per message. */
|
|
6147
|
+
alertErrors = /* @__PURE__ */ new Map();
|
|
6148
|
+
/** The cores `threads: auto` counts on (see threads/plan.ts); tests set it. */
|
|
6149
|
+
cores = cpuCount();
|
|
6150
|
+
/** Where each screen is painted, and why (see threads/plan.ts). */
|
|
6151
|
+
threadWhy = /* @__PURE__ */ new Map();
|
|
6152
|
+
/** Screens whose thread failed, with why: they paint here until their config or the plugins change. */
|
|
6153
|
+
threadless = /* @__PURE__ */ new Map();
|
|
6154
|
+
/** The entry point of the screens' threads (the server brings one with the built-in plugins). */
|
|
6155
|
+
threadEntry;
|
|
5144
6156
|
registry;
|
|
5145
6157
|
/**
|
|
5146
6158
|
* Demo mode: no source or fetch runs, every widget paints its sample data.
|
|
@@ -5151,6 +6163,7 @@ var Runtime = class extends EventEmitter {
|
|
|
5151
6163
|
super();
|
|
5152
6164
|
this.registry = registry2;
|
|
5153
6165
|
this.demoMode = !!o.demo;
|
|
6166
|
+
this.threadEntry = o.threadEntry;
|
|
5154
6167
|
this.setMaxListeners(100);
|
|
5155
6168
|
this.config = config2;
|
|
5156
6169
|
this.hub = new SourceHub(registry2, this.log, (type) => this.onData({ source: type }));
|
|
@@ -5169,10 +6182,31 @@ var Runtime = class extends EventEmitter {
|
|
|
5169
6182
|
working(now) {
|
|
5170
6183
|
return isWorking(this.config.workday, now);
|
|
5171
6184
|
}
|
|
6185
|
+
// The runners' host (see screen-runner.ts), for the screens painted on this thread.
|
|
6186
|
+
dataOf(instanceId) {
|
|
6187
|
+
return this.fetches.data(instanceId);
|
|
6188
|
+
}
|
|
6189
|
+
sourceData(type) {
|
|
6190
|
+
return this.hub.data(type);
|
|
6191
|
+
}
|
|
6192
|
+
sourcesOf(types2) {
|
|
6193
|
+
return this.hub.pick(types2);
|
|
6194
|
+
}
|
|
6195
|
+
paintTime(instance, type, ms, now) {
|
|
6196
|
+
this.paintTimes.record(instance, type, ms, now, this.log);
|
|
6197
|
+
}
|
|
6198
|
+
frame(info) {
|
|
6199
|
+
this.emit("frame", info);
|
|
6200
|
+
}
|
|
6201
|
+
pageChanged() {
|
|
6202
|
+
this.refreshWanted();
|
|
6203
|
+
}
|
|
6204
|
+
openDevice(screen, log) {
|
|
6205
|
+
return openDevice(screen.device, log, screen.rotate);
|
|
6206
|
+
}
|
|
5172
6207
|
onData(change) {
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
}
|
|
6208
|
+
this.alertsDirty = true;
|
|
6209
|
+
for (const r of this.runners.values()) r.dataChanged(change);
|
|
5176
6210
|
this.emit("data", change);
|
|
5177
6211
|
}
|
|
5178
6212
|
/**
|
|
@@ -5198,6 +6232,7 @@ var Runtime = class extends EventEmitter {
|
|
|
5198
6232
|
}
|
|
5199
6233
|
for (const slot of r.screen.interludes) for (const s of this.registry.interlude(slot.type)?.sources ?? []) if (slot.enabled) sources.add(s);
|
|
5200
6234
|
}
|
|
6235
|
+
for (const s of backgroundSources(this.config, (type) => this.registry.source(type))) sources.add(s);
|
|
5201
6236
|
this.paintTimes.retain(new Set(instances.map((i) => i.inst.id)));
|
|
5202
6237
|
if (this.demoMode) {
|
|
5203
6238
|
sources.clear();
|
|
@@ -5211,43 +6246,92 @@ var Runtime = class extends EventEmitter {
|
|
|
5211
6246
|
* and fetches start again with the new code and every screen repaints
|
|
5212
6247
|
* from scratch.
|
|
5213
6248
|
*/
|
|
5214
|
-
pluginsChanged(
|
|
5215
|
-
for (const id of
|
|
6249
|
+
pluginsChanged(ids2) {
|
|
6250
|
+
for (const id of ids2) {
|
|
5216
6251
|
this.hub.forget(id);
|
|
5217
6252
|
this.fetches.forget(id);
|
|
5218
6253
|
}
|
|
6254
|
+
const retry = this.threadless.size > 0;
|
|
6255
|
+
this.threadless.clear();
|
|
5219
6256
|
for (const r of this.runners.values()) r.invalidate();
|
|
6257
|
+
if (retry) this.placeRunners();
|
|
5220
6258
|
this.refreshWanted();
|
|
5221
6259
|
this.emit("config", this.config);
|
|
5222
6260
|
}
|
|
5223
6261
|
/** Applies a new config: screens added, removed or changed; data kept where possible. */
|
|
5224
6262
|
apply(config2) {
|
|
5225
6263
|
this.config = config2;
|
|
6264
|
+
this.alertsDirty = true;
|
|
5226
6265
|
this.registry.setDisabled(config2.plugins.disabled);
|
|
5227
|
-
const
|
|
6266
|
+
const ids2 = new Set(config2.screens.map((s) => s.id));
|
|
5228
6267
|
for (const [id, r] of this.runners) {
|
|
5229
|
-
if (!
|
|
6268
|
+
if (!ids2.has(id)) {
|
|
5230
6269
|
r.close();
|
|
5231
6270
|
this.runners.delete(id);
|
|
5232
6271
|
}
|
|
5233
6272
|
}
|
|
5234
6273
|
for (const s of config2.screens) {
|
|
5235
|
-
const
|
|
5236
|
-
if (
|
|
5237
|
-
|
|
6274
|
+
const failed = this.threadless.get(s.id);
|
|
6275
|
+
if (failed && failed.key !== JSON.stringify(s)) this.threadless.delete(s.id);
|
|
6276
|
+
this.runners.get(s.id)?.reconfigure(s);
|
|
5238
6277
|
}
|
|
6278
|
+
this.placeRunners();
|
|
5239
6279
|
this.refreshWanted();
|
|
5240
6280
|
this.emit("config", config2);
|
|
5241
6281
|
}
|
|
6282
|
+
/**
|
|
6283
|
+
* Each screen's runner where the config says (see threads/plan.ts): a new
|
|
6284
|
+
* one where there was none, and moved, panel and all, when it changed
|
|
6285
|
+
* between the main thread and one of its own.
|
|
6286
|
+
*/
|
|
6287
|
+
placeRunners() {
|
|
6288
|
+
const plan = planThreads(this.config, this.cores);
|
|
6289
|
+
for (const s of this.config.screens) {
|
|
6290
|
+
const choice = plan.get(s.id);
|
|
6291
|
+
const thread = choice.thread && !this.threadless.has(s.id) && this.timer !== null;
|
|
6292
|
+
this.threadWhy.set(s.id, choice.why);
|
|
6293
|
+
const r = this.runners.get(s.id);
|
|
6294
|
+
if (r && r instanceof ThreadRunner === thread) continue;
|
|
6295
|
+
this.runners.set(s.id, this.makeRunner(s, thread, r));
|
|
6296
|
+
}
|
|
6297
|
+
}
|
|
6298
|
+
/** A runner for `s` here or in a thread; `old`: the one it replaces, whose panel it keeps (and state). */
|
|
6299
|
+
makeRunner(s, thread, old) {
|
|
6300
|
+
let device;
|
|
6301
|
+
if (old) {
|
|
6302
|
+
const taken = old.takeDevice();
|
|
6303
|
+
old.close();
|
|
6304
|
+
if (JSON.stringify(old.screen.device) === JSON.stringify(s.device)) device = taken;
|
|
6305
|
+
else taken.close();
|
|
6306
|
+
}
|
|
6307
|
+
const r = thread ? new ThreadRunner(s, this, this.threadEntry ?? defaultThreadEntry(), device) : new ScreenRunner(s, this, device);
|
|
6308
|
+
if (old) {
|
|
6309
|
+
if (old.pinned !== r.pinned) r.setPinned(old.pinned);
|
|
6310
|
+
if (old.off) r.setOff(true);
|
|
6311
|
+
if (old.alert) r.setAlert(old.alert, Date.now());
|
|
6312
|
+
}
|
|
6313
|
+
return r;
|
|
6314
|
+
}
|
|
6315
|
+
threadFailed(screenId, reason) {
|
|
6316
|
+
const s = this.config.screens.find((x) => x.id === screenId);
|
|
6317
|
+
const r = this.runners.get(screenId);
|
|
6318
|
+
if (!s || !r) return;
|
|
6319
|
+
this.log(`screen:${s.name}`, `painting on the main thread: ${reason}`);
|
|
6320
|
+
this.threadless.set(screenId, { reason, key: JSON.stringify(s) });
|
|
6321
|
+
this.runners.set(screenId, this.makeRunner(s, false, r));
|
|
6322
|
+
this.refreshWanted();
|
|
6323
|
+
}
|
|
5242
6324
|
start() {
|
|
5243
|
-
this.apply(this.config);
|
|
5244
6325
|
const loop = async () => {
|
|
5245
6326
|
const now = Date.now();
|
|
5246
6327
|
this.hub.tick(this.config, now);
|
|
5247
6328
|
this.fetches.tick(this.config, now);
|
|
6329
|
+
if (this.alertsDirty || now - this.alertsAskedAt >= ALERTS_EVERY_MS) this.askAlerts(now);
|
|
6330
|
+
this.refreshAlerts(now);
|
|
5248
6331
|
await Promise.all([...this.runners.values()].map((r) => r.update(now)));
|
|
5249
6332
|
};
|
|
5250
6333
|
this.timer = setInterval(() => void loop(), TICK_MS);
|
|
6334
|
+
this.apply(this.config);
|
|
5251
6335
|
void loop();
|
|
5252
6336
|
}
|
|
5253
6337
|
stop() {
|
|
@@ -5262,12 +6346,15 @@ var Runtime = class extends EventEmitter {
|
|
|
5262
6346
|
}
|
|
5263
6347
|
pin(screenId, pageId) {
|
|
5264
6348
|
const r = this.runners.get(screenId);
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
6349
|
+
r?.setPinned(pageId);
|
|
6350
|
+
}
|
|
6351
|
+
/** `play`: someone plays it from the Play page (see `maybeInterlude`). */
|
|
6352
|
+
playInterlude(screenId, slotId, play = false) {
|
|
6353
|
+
void this.runners.get(screenId)?.playNow(slotId, play);
|
|
5268
6354
|
}
|
|
5269
|
-
|
|
5270
|
-
|
|
6355
|
+
/** A button for the interlude being played on a screen; false when none is. */
|
|
6356
|
+
press(screenId, e) {
|
|
6357
|
+
return this.runners.get(screenId)?.press(e) ?? false;
|
|
5271
6358
|
}
|
|
5272
6359
|
stopInterlude(screenId) {
|
|
5273
6360
|
this.runners.get(screenId)?.stopInterlude();
|
|
@@ -5276,14 +6363,114 @@ var Runtime = class extends EventEmitter {
|
|
|
5276
6363
|
setOff(screenId, off) {
|
|
5277
6364
|
const r = this.runners.get(screenId);
|
|
5278
6365
|
if (!r || r.off === off) return;
|
|
5279
|
-
r.off
|
|
5280
|
-
if (off) r.stopInterlude();
|
|
5281
|
-
r.dirty = true;
|
|
6366
|
+
r.setOff(off);
|
|
5282
6367
|
this.emit("screen", { screenId, off });
|
|
5283
6368
|
}
|
|
5284
6369
|
refreshWidget(instanceId) {
|
|
5285
6370
|
this.fetches.refresh(instanceId);
|
|
5286
6371
|
}
|
|
6372
|
+
/** Asks every widget instance of the enabled screens (any page) and every running source for its alerts. */
|
|
6373
|
+
askAlerts(now = Date.now()) {
|
|
6374
|
+
this.alertsDirty = false;
|
|
6375
|
+
this.alertsAskedAt = now;
|
|
6376
|
+
const out = [];
|
|
6377
|
+
const call2 = (from, fn, origin) => {
|
|
6378
|
+
let list2;
|
|
6379
|
+
try {
|
|
6380
|
+
list2 = fn();
|
|
6381
|
+
this.alertErrors.delete(from);
|
|
6382
|
+
} catch (err) {
|
|
6383
|
+
const m = err instanceof Error ? err.message : String(err);
|
|
6384
|
+
if (this.alertErrors.get(from) !== m) this.log(from, `alerts failed: ${m}`);
|
|
6385
|
+
this.alertErrors.set(from, m);
|
|
6386
|
+
return;
|
|
6387
|
+
}
|
|
6388
|
+
if (Array.isArray(list2)) for (const alert of list2) out.push({ alert, origin, from });
|
|
6389
|
+
};
|
|
6390
|
+
if (!this.demoMode) {
|
|
6391
|
+
const working = this.working(now);
|
|
6392
|
+
const cfg = this.config;
|
|
6393
|
+
const done2 = /* @__PURE__ */ new Set();
|
|
6394
|
+
for (const r of this.runners.values()) {
|
|
6395
|
+
if (!r.screen.enabled) continue;
|
|
6396
|
+
for (const { widget } of widgetsOf(r.screen)) {
|
|
6397
|
+
const def = this.registry.widget(widget.type);
|
|
6398
|
+
if (!def?.alerts || widget.disabled || done2.has(widget.id)) continue;
|
|
6399
|
+
done2.add(widget.id);
|
|
6400
|
+
call2(widget.type, () => {
|
|
6401
|
+
const options2 = def.options ? validate(def.options, widget.options).value : {};
|
|
6402
|
+
return def.alerts({ options: options2, data: this.fetches.data(widget.id), sources: this.hub.pick(def.sources), now, working, workday: cfg.workday, ...cfg.location ? { location: cfg.location } : {} });
|
|
6403
|
+
}, "widget");
|
|
6404
|
+
}
|
|
6405
|
+
}
|
|
6406
|
+
for (const { type, options: options2 } of this.hub.running()) {
|
|
6407
|
+
const def = this.registry.source(type);
|
|
6408
|
+
if (def?.alerts) call2(type, () => def.alerts({ data: this.hub.data(type), options: options2, now }), "source");
|
|
6409
|
+
}
|
|
6410
|
+
}
|
|
6411
|
+
this.alerts.sync(out, now, resolveLocale(this.config));
|
|
6412
|
+
}
|
|
6413
|
+
/** Every screen gets the alert it must show now, and the editor hears of any change. */
|
|
6414
|
+
refreshAlerts(now = Date.now()) {
|
|
6415
|
+
this.alerts.prune(now);
|
|
6416
|
+
const list2 = this.alerts.list(now);
|
|
6417
|
+
for (const r of this.runners.values()) r.setAlert(r.screen.enabled ? this.alerts.forScreen(r.screen, now, r.off) : null, now);
|
|
6418
|
+
const sig = JSON.stringify(list2);
|
|
6419
|
+
if (sig === this.alertsSig) return;
|
|
6420
|
+
this.alertsSig = sig;
|
|
6421
|
+
this.emit("alerts", list2);
|
|
6422
|
+
}
|
|
6423
|
+
/** Alerts not seen nor expired, highest first; the snoozed ones too. */
|
|
6424
|
+
listAlerts(now = Date.now()) {
|
|
6425
|
+
return this.alerts.list(now);
|
|
6426
|
+
}
|
|
6427
|
+
/** An alert from outside (`POST /api/alerts`); throws `AlertError` if it is not one. */
|
|
6428
|
+
postAlert(raw) {
|
|
6429
|
+
const now = Date.now();
|
|
6430
|
+
const a = this.alerts.post(raw, now, resolveLocale(this.config), this.config.screens.map((s) => s.id));
|
|
6431
|
+
this.log("alerts", `${a.level}: ${a.title} (${a.id})`);
|
|
6432
|
+
this.refreshAlerts(now);
|
|
6433
|
+
return a;
|
|
6434
|
+
}
|
|
6435
|
+
ackAlert(id) {
|
|
6436
|
+
const r = this.alerts.ack(id);
|
|
6437
|
+
if (r === "ok") this.refreshAlerts();
|
|
6438
|
+
return r;
|
|
6439
|
+
}
|
|
6440
|
+
/** Every dismissible alert seen at once; how many. */
|
|
6441
|
+
ackAllAlerts() {
|
|
6442
|
+
const n = this.alerts.ackAll(Date.now());
|
|
6443
|
+
this.refreshAlerts();
|
|
6444
|
+
return n;
|
|
6445
|
+
}
|
|
6446
|
+
snoozeAlert(id, ms) {
|
|
6447
|
+
const r = this.alerts.snooze(id, ms, Date.now());
|
|
6448
|
+
if (r === "ok") this.refreshAlerts();
|
|
6449
|
+
return r;
|
|
6450
|
+
}
|
|
6451
|
+
removeAlert(id) {
|
|
6452
|
+
const r = this.alerts.remove(id);
|
|
6453
|
+
if (r) this.refreshAlerts();
|
|
6454
|
+
return r;
|
|
6455
|
+
}
|
|
6456
|
+
/** The screen's test alert ("Test alert" in Screens): shown there for a while, whatever its settings. */
|
|
6457
|
+
testAlert(screenId, level = "critical") {
|
|
6458
|
+
const screen = this.config.screens.find((s) => s.id === screenId);
|
|
6459
|
+
if (!screen) return null;
|
|
6460
|
+
const locale = resolveLocale(this.config);
|
|
6461
|
+
const a = this.alerts.test(screen, level, Date.now(), { title: localize(TEST_ALERT_TITLE, locale), text: localize(TEST_ALERT_TEXT, locale).replace("{screen}", screen.name) });
|
|
6462
|
+
this.refreshAlerts();
|
|
6463
|
+
return a;
|
|
6464
|
+
}
|
|
6465
|
+
/** The main thread's event loop use, sampled every few seconds (whoever asks for the status). */
|
|
6466
|
+
elu = { mark: loopUse(), at: Date.now(), value: 0 };
|
|
6467
|
+
mainLoad() {
|
|
6468
|
+
if (Date.now() - this.elu.at >= 2e3) {
|
|
6469
|
+
const mark = loopUse();
|
|
6470
|
+
this.elu = { mark, at: Date.now(), value: mark && this.elu.mark ? Math.round(nodePerf.eventLoopUtilization(mark, this.elu.mark).utilization * 100) / 100 : 0 };
|
|
6471
|
+
}
|
|
6472
|
+
return this.elu.value;
|
|
6473
|
+
}
|
|
5287
6474
|
status() {
|
|
5288
6475
|
return {
|
|
5289
6476
|
screens: [...this.runners.values()].map((r) => ({
|
|
@@ -5292,12 +6479,33 @@ var Runtime = class extends EventEmitter {
|
|
|
5292
6479
|
page: r.page?.id ?? null,
|
|
5293
6480
|
pinned: r.pinned,
|
|
5294
6481
|
interlude: r.interlude?.type ?? null,
|
|
6482
|
+
/** The interlude is being played from the Play page. */
|
|
6483
|
+
playing: r.interlude?.play ?? false,
|
|
5295
6484
|
animation: r.animating,
|
|
5296
6485
|
device: r.device.status,
|
|
5297
6486
|
lastFrameAt: r.lastInfo?.at ?? null,
|
|
5298
6487
|
sleeping: r.lastInfo?.sleeping ?? false,
|
|
5299
|
-
off: r.off
|
|
6488
|
+
off: r.off,
|
|
6489
|
+
/** The alert that has the screen, if any. */
|
|
6490
|
+
alert: r.alert?.top.id ?? null,
|
|
6491
|
+
/** Real fps, paint and encode times. */
|
|
6492
|
+
frames: r.stats.read(),
|
|
6493
|
+
/** Painted in a thread of its own or here, why, and what its thread holds in memory. */
|
|
6494
|
+
thread: {
|
|
6495
|
+
on: r instanceof ThreadRunner,
|
|
6496
|
+
why: this.threadless.has(r.screen.id) ? "failed" : this.threadWhy.get(r.screen.id) ?? "setting",
|
|
6497
|
+
error: this.threadless.get(r.screen.id)?.reason ?? null,
|
|
6498
|
+
heapBytes: r instanceof ThreadRunner ? r.heapBytes : null
|
|
6499
|
+
}
|
|
5300
6500
|
})),
|
|
6501
|
+
threads: {
|
|
6502
|
+
mode: threadsMode(this.config),
|
|
6503
|
+
cores: this.cores,
|
|
6504
|
+
/** The main thread's JavaScript heap and the whole process' memory, in bytes. */
|
|
6505
|
+
...memory()
|
|
6506
|
+
},
|
|
6507
|
+
/** How busy the main thread was since the last status (0–1). */
|
|
6508
|
+
mainLoad: this.mainLoad(),
|
|
5301
6509
|
sources: this.hub.status(),
|
|
5302
6510
|
fetches: this.fetches.status(),
|
|
5303
6511
|
/** Paint times of the widgets on the panels, slowest first. */
|
|
@@ -5336,12 +6544,28 @@ var Runtime = class extends EventEmitter {
|
|
|
5336
6544
|
return composeWidget({ cfg, registry: this.registry, theme: themeById(cfg.theme), type, width, height, options: options2, ...title ? { title } : {} }).canvas.toBuffer("image/png");
|
|
5337
6545
|
}
|
|
5338
6546
|
};
|
|
6547
|
+
var nodePerf = globalThis.performance;
|
|
6548
|
+
var loopUse = () => nodePerf.eventLoopUtilization?.() ?? null;
|
|
6549
|
+
function cpuCount() {
|
|
6550
|
+
try {
|
|
6551
|
+
return availableParallelism2();
|
|
6552
|
+
} catch {
|
|
6553
|
+
return 1;
|
|
6554
|
+
}
|
|
6555
|
+
}
|
|
6556
|
+
function memory() {
|
|
6557
|
+
try {
|
|
6558
|
+
return { heapBytes: process.memoryUsage().heapUsed, rssBytes: process.memoryUsage.rss() };
|
|
6559
|
+
} catch {
|
|
6560
|
+
return { heapBytes: 0, rssBytes: 0 };
|
|
6561
|
+
}
|
|
6562
|
+
}
|
|
5339
6563
|
function withLook(cfg, look) {
|
|
5340
6564
|
return { ...cfg, ...look.theme ? { theme: look.theme } : {}, ...look.locale ? { locale: look.locale } : {} };
|
|
5341
6565
|
}
|
|
5342
6566
|
|
|
5343
6567
|
// packages/core/src/registry.ts
|
|
5344
|
-
import { existsSync as
|
|
6568
|
+
import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync3, statSync, writeFileSync as writeFileSync4 } from "node:fs";
|
|
5345
6569
|
import { join as join6 } from "node:path";
|
|
5346
6570
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
5347
6571
|
|
|
@@ -5373,6 +6597,15 @@ function incompatibility(o, env = { sdk: SDK_VERSION, platform: process.platform
|
|
|
5373
6597
|
var platformName = (p) => p === "darwin" ? "macOS" : p === "win32" ? "Windows" : p === "linux" ? "Linux" : p;
|
|
5374
6598
|
var pluginOf = (type) => type.split("/")[0] ?? type;
|
|
5375
6599
|
var fullType = (pluginId, type) => type.includes("/") ? type : `${pluginId}/${type}`;
|
|
6600
|
+
function fundingUrl(f) {
|
|
6601
|
+
const one = Array.isArray(f) ? f[0] : f;
|
|
6602
|
+
const url2 = typeof one === "string" ? one : one && typeof one === "object" ? one.url : void 0;
|
|
6603
|
+
return typeof url2 === "string" && url2 ? url2 : void 0;
|
|
6604
|
+
}
|
|
6605
|
+
function bugsUrl(b) {
|
|
6606
|
+
const url2 = typeof b === "string" ? b : b && typeof b === "object" ? b.url : void 0;
|
|
6607
|
+
return typeof url2 === "string" && /^https?:/.test(url2) ? url2 : void 0;
|
|
6608
|
+
}
|
|
5376
6609
|
function isLanguageTag(k) {
|
|
5377
6610
|
if (!/^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$/.test(k)) return false;
|
|
5378
6611
|
try {
|
|
@@ -5429,6 +6662,9 @@ function pluginManifest(def, o = {}) {
|
|
|
5429
6662
|
const sdk = def.sdk ?? meta.sdk;
|
|
5430
6663
|
const homepage = def.homepage ?? o.pkg?.homepage;
|
|
5431
6664
|
const repository = def.repository ?? (typeof repo === "string" ? repo.replace(/^git\+/, "") : void 0);
|
|
6665
|
+
const support = { ...bugsUrl(o.pkg?.bugs) ? { issues: bugsUrl(o.pkg?.bugs) } : {}, ...homepage ? { docs: homepage } : {}, ...def.support ?? {} };
|
|
6666
|
+
const funding = def.funding ?? fundingUrl(o.pkg?.funding);
|
|
6667
|
+
const categories = [.../* @__PURE__ */ new Set([...widgets.map((w) => w.category ?? "info"), ...def.category ? [def.category] : []])];
|
|
5432
6668
|
return {
|
|
5433
6669
|
manifest: 1,
|
|
5434
6670
|
id: def.id,
|
|
@@ -5444,7 +6680,7 @@ function pluginManifest(def, o = {}) {
|
|
|
5444
6680
|
...sdk ? { sdk } : {},
|
|
5445
6681
|
platforms: def.platforms ?? meta.platforms ?? [...PLATFORMS],
|
|
5446
6682
|
languages: declaredLanguages(def, meta),
|
|
5447
|
-
categories
|
|
6683
|
+
categories,
|
|
5448
6684
|
tags: [...new Set(widgets.flatMap((w) => w.tags ?? []))],
|
|
5449
6685
|
permissions: def.permissions ?? {},
|
|
5450
6686
|
riskyOptions: [
|
|
@@ -5466,6 +6702,7 @@ function pluginManifest(def, o = {}) {
|
|
|
5466
6702
|
sources: w.sources ?? [],
|
|
5467
6703
|
options: w.options ? toJsonSchema(w.options) : null,
|
|
5468
6704
|
...o.screenshots?.[w.id] ? { screenshot: o.screenshots[w.id] } : {},
|
|
6705
|
+
...o.shots?.[w.id]?.length ? { screenshots: o.shots[w.id] } : {},
|
|
5469
6706
|
animated: !!w.animation,
|
|
5470
6707
|
urgent: !!w.urgent
|
|
5471
6708
|
})),
|
|
@@ -5477,18 +6714,24 @@ function pluginManifest(def, o = {}) {
|
|
|
5477
6714
|
...s.read && s.intervalMs ? { intervalMs: s.intervalMs } : {},
|
|
5478
6715
|
options: s.options ? toJsonSchema(s.options) : null
|
|
5479
6716
|
})),
|
|
5480
|
-
interludes: (def.interludes ?? []).map((i) => ({ type: `${def.id}/${i.id}`, name: i.name, ...i.description ? { description: i.description } : {}, ...i.icon ? { icon: i.icon } : {}, fps: i.fps })),
|
|
6717
|
+
interludes: (def.interludes ?? []).map((i) => ({ type: `${def.id}/${i.id}`, name: i.name, ...i.description ? { description: i.description } : {}, ...i.icon ? { icon: i.icon } : {}, fps: i.fps, ...i.input ? { input: true } : {}, ...i.preview ? { preview: i.preview } : {} })),
|
|
5481
6718
|
templates: (def.templates ?? []).map((tp) => ({
|
|
5482
6719
|
id: tp.id,
|
|
5483
6720
|
name: tp.name,
|
|
5484
6721
|
...tp.icon ? { icon: tp.icon } : {},
|
|
5485
|
-
widgets: [...new Set([...tp.wide, ...tp.square ?? [], ...tp.tall ?? []].flatMap((tile) => tile.widgets.map((w) => fullType(def.id, typeof w === "string" ? w : w[0]))))]
|
|
5486
|
-
|
|
6722
|
+
widgets: [...new Set([...tp.wide, ...tp.square ?? [], ...tp.tall ?? []].flatMap((tile) => tile.widgets.map((w) => fullType(def.id, typeof w === "string" ? w : w[0]))))],
|
|
6723
|
+
layouts: ["wide", "square", "tall"].filter((k) => tp[k]?.length)
|
|
6724
|
+
})),
|
|
6725
|
+
...def.markets ? { markets: def.markets } : {},
|
|
6726
|
+
...Object.keys(support).length ? { support } : {},
|
|
6727
|
+
...def.pricing ? { pricing: def.pricing } : {},
|
|
6728
|
+
...funding ? { funding } : {},
|
|
6729
|
+
...def.resources ? { resources: def.resources } : {}
|
|
5487
6730
|
};
|
|
5488
6731
|
}
|
|
5489
6732
|
|
|
5490
6733
|
// packages/core/src/sdk-resolver.ts
|
|
5491
|
-
import { existsSync as
|
|
6734
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
5492
6735
|
import module from "node:module";
|
|
5493
6736
|
import { join as join5 } from "node:path";
|
|
5494
6737
|
import { pathToFileURL } from "node:url";
|
|
@@ -5501,7 +6744,7 @@ function installSdkResolver() {
|
|
|
5501
6744
|
const urls = /* @__PURE__ */ new Map();
|
|
5502
6745
|
for (const name of SHARED) {
|
|
5503
6746
|
const local = BUNDLED[name] ? join5(import.meta.dirname, BUNDLED[name]) : null;
|
|
5504
|
-
if (local &&
|
|
6747
|
+
if (local && existsSync5(local)) {
|
|
5505
6748
|
urls.set(name, pathToFileURL(local).href);
|
|
5506
6749
|
continue;
|
|
5507
6750
|
}
|
|
@@ -5535,12 +6778,15 @@ var Registry = class {
|
|
|
5535
6778
|
refused = [];
|
|
5536
6779
|
/** Where a plugin's code came from, to load it again (`reload`). */
|
|
5537
6780
|
entries = /* @__PURE__ */ new Map();
|
|
6781
|
+
/** The module each plugin's code came from (its URL), for a screen's thread to load it too. */
|
|
6782
|
+
modules = /* @__PURE__ */ new Map();
|
|
5538
6783
|
reloads = 0;
|
|
5539
6784
|
refuse(r) {
|
|
5540
6785
|
this.refused.push({ origin: r.origin, reason: r.reason, ...r.id ? { id: r.id } : {}, ...r.version ? { version: r.version } : {} });
|
|
5541
6786
|
this.problems.push({ origin: r.origin, message: `${r.id ? `"${r.id}" ` : ""}not loaded: ${r.reason}` });
|
|
5542
6787
|
}
|
|
5543
|
-
|
|
6788
|
+
/** `module`: the URL its code can be imported from again (see `threadPlugins`). */
|
|
6789
|
+
add(def, origin = "builtin", module3) {
|
|
5544
6790
|
if (!def || typeof def !== "object" || !ID.test(def.id ?? "")) {
|
|
5545
6791
|
this.problems.push({ origin, message: `invalid plugin id ${JSON.stringify(def?.id)}` });
|
|
5546
6792
|
return;
|
|
@@ -5552,10 +6798,13 @@ var Registry = class {
|
|
|
5552
6798
|
return;
|
|
5553
6799
|
}
|
|
5554
6800
|
this.plugins.set(def.id, { def, origin, enabled: true });
|
|
6801
|
+
if (module3) this.modules.set(def.id, module3);
|
|
6802
|
+
else this.modules.delete(def.id);
|
|
5555
6803
|
}
|
|
5556
6804
|
/** Forgets a plugin (removed, or about to be loaded again). Its module stays in memory: ES modules can't be unloaded. */
|
|
5557
6805
|
remove(id) {
|
|
5558
6806
|
this.entries.delete(id);
|
|
6807
|
+
this.modules.delete(id);
|
|
5559
6808
|
return this.plugins.delete(id);
|
|
5560
6809
|
}
|
|
5561
6810
|
/**
|
|
@@ -5612,12 +6861,21 @@ var Registry = class {
|
|
|
5612
6861
|
}
|
|
5613
6862
|
return out;
|
|
5614
6863
|
}
|
|
6864
|
+
/**
|
|
6865
|
+
* What a screen's thread loads to have the same plugins, in the same
|
|
6866
|
+
* order: the built-in ones by id (the thread brings its own copies) and the
|
|
6867
|
+
* rest by the URL of their module (the version reloaded last, if it was).
|
|
6868
|
+
* Plugins added with no module (a test's) can't be loaded there.
|
|
6869
|
+
*/
|
|
6870
|
+
threadPlugins() {
|
|
6871
|
+
return this.list().map(({ def, origin }) => ({ id: def.id, origin, module: this.modules.get(def.id) ?? null }));
|
|
6872
|
+
}
|
|
5615
6873
|
/** Where a loaded plugin came from (its folder), or undefined for a built-in one. */
|
|
5616
6874
|
originOf(id) {
|
|
5617
6875
|
return this.entries.get(id)?.origin;
|
|
5618
6876
|
}
|
|
5619
|
-
setDisabled(
|
|
5620
|
-
for (const p of this.plugins.values()) p.enabled = !
|
|
6877
|
+
setDisabled(ids2) {
|
|
6878
|
+
for (const p of this.plugins.values()) p.enabled = !ids2.includes(p.def.id);
|
|
5621
6879
|
}
|
|
5622
6880
|
list() {
|
|
5623
6881
|
return [...this.plugins.values()];
|
|
@@ -5646,10 +6904,10 @@ var Registry = class {
|
|
|
5646
6904
|
* installed there with npm (`node_modules/kiosko-plugin-*`).
|
|
5647
6905
|
*/
|
|
5648
6906
|
async loadDir(dir) {
|
|
5649
|
-
if (!
|
|
6907
|
+
if (!existsSync6(dir)) return;
|
|
5650
6908
|
installSdkResolver();
|
|
5651
6909
|
const marker = join6(dir, "package.json");
|
|
5652
|
-
if (!
|
|
6910
|
+
if (!existsSync6(marker)) {
|
|
5653
6911
|
try {
|
|
5654
6912
|
writeFileSync4(marker, `${JSON.stringify({ name: "kiosko-user-plugins", private: true, type: "module" }, null, 2)}
|
|
5655
6913
|
`);
|
|
@@ -5662,7 +6920,7 @@ var Registry = class {
|
|
|
5662
6920
|
candidates.push(join6(dir, name));
|
|
5663
6921
|
}
|
|
5664
6922
|
const nm = join6(dir, "node_modules");
|
|
5665
|
-
if (
|
|
6923
|
+
if (existsSync6(nm)) {
|
|
5666
6924
|
for (const name of readdirSync3(nm)) {
|
|
5667
6925
|
if (name.startsWith("@")) {
|
|
5668
6926
|
for (const sub of readdirSync3(join6(nm, name))) if (sub.startsWith("kiosko-plugin-")) candidates.push(join6(nm, name, sub));
|
|
@@ -5678,8 +6936,8 @@ var Registry = class {
|
|
|
5678
6936
|
return;
|
|
5679
6937
|
}
|
|
5680
6938
|
const pkgPath = join6(folder, "package.json");
|
|
5681
|
-
let entry = ["index.mjs", "index.js"].map((f) => join6(folder, f)).find(
|
|
5682
|
-
if (
|
|
6939
|
+
let entry = ["index.mjs", "index.js"].map((f) => join6(folder, f)).find(existsSync6);
|
|
6940
|
+
if (existsSync6(pkgPath)) {
|
|
5683
6941
|
const pkg = JSON.parse(readFileSync3(pkgPath, "utf8"));
|
|
5684
6942
|
const meta = packageMeta(pkg);
|
|
5685
6943
|
const why = incompatibility(meta);
|
|
@@ -5687,7 +6945,7 @@ var Registry = class {
|
|
|
5687
6945
|
const rel = pkg.kiosko?.plugin ?? pkg.main;
|
|
5688
6946
|
if (rel) entry = join6(folder, rel);
|
|
5689
6947
|
}
|
|
5690
|
-
if (!entry || !
|
|
6948
|
+
if (!entry || !existsSync6(entry)) {
|
|
5691
6949
|
this.problems.push({ origin: folder, message: 'no entry point (package.json "kiosko.plugin", "main" or index.js)' });
|
|
5692
6950
|
return;
|
|
5693
6951
|
}
|
|
@@ -5704,7 +6962,7 @@ var Registry = class {
|
|
|
5704
6962
|
return void 0;
|
|
5705
6963
|
}
|
|
5706
6964
|
const before = this.plugins.size;
|
|
5707
|
-
this.add(mod.default, origin);
|
|
6965
|
+
this.add(mod.default, origin, url2);
|
|
5708
6966
|
if (this.plugins.size > before) this.entries.set(mod.default.id, { entry, origin });
|
|
5709
6967
|
return mod.default;
|
|
5710
6968
|
}
|
|
@@ -5779,13 +7037,98 @@ var Registry = class {
|
|
|
5779
7037
|
})),
|
|
5780
7038
|
sources: (def.sources ?? []).map((s) => {
|
|
5781
7039
|
const field = sourceOptionsField(s);
|
|
5782
|
-
return { type: `${def.id}/${s.id}`, name: L(s.name), description: L(s.description), options: field ? toJsonSchema(field) : null, intervalMs: s.read ? sourceTiming(s).intervalMs : null, polled: !!s.read };
|
|
7040
|
+
return { type: `${def.id}/${s.id}`, name: L(s.name), description: L(s.description), options: field ? toJsonSchema(field) : null, intervalMs: s.read ? sourceTiming(s).intervalMs : null, polled: !!s.read, background: canRunInBackground(s) };
|
|
5783
7041
|
}),
|
|
5784
|
-
interludes: (def.interludes ?? []).map((i) => ({ type: `${def.id}/${i.id}`, name: L(i.name), description: L(i.description), icon: i.icon, fps: i.fps, options: i.options ? toJsonSchema(i.options) : null }))
|
|
7042
|
+
interludes: (def.interludes ?? []).map((i) => ({ type: `${def.id}/${i.id}`, name: L(i.name), description: L(i.description), icon: i.icon, fps: i.fps, input: !!i.input, options: i.options ? toJsonSchema(i.options) : null }))
|
|
5785
7043
|
}));
|
|
5786
7044
|
}
|
|
5787
7045
|
};
|
|
5788
7046
|
|
|
7047
|
+
// packages/core/src/licenses.ts
|
|
7048
|
+
var PERMISSIVE = ["MIT", "MIT-0", "ISC", "BSD-2-Clause", "BSD-3-Clause", "BSD-3-Clause-Clear", "0BSD", "Apache-2.0", "Zlib", "Unlicense", "CC0-1.0", "BSL-1.0", "PostgreSQL", "NCSA", "X11", "Python-2.0", "BlueOak-1.0.0", "UPL-1.0", "Artistic-2.0", "WTFPL", "CC-BY-4.0"];
|
|
7049
|
+
var COPYLEFT = [
|
|
7050
|
+
"GPL-2.0-only",
|
|
7051
|
+
"GPL-2.0-or-later",
|
|
7052
|
+
"GPL-3.0-only",
|
|
7053
|
+
"GPL-3.0-or-later",
|
|
7054
|
+
"LGPL-2.1-only",
|
|
7055
|
+
"LGPL-2.1-or-later",
|
|
7056
|
+
"LGPL-3.0-only",
|
|
7057
|
+
"LGPL-3.0-or-later",
|
|
7058
|
+
"AGPL-3.0-only",
|
|
7059
|
+
"AGPL-3.0-or-later",
|
|
7060
|
+
"MPL-2.0",
|
|
7061
|
+
"EPL-2.0",
|
|
7062
|
+
"EUPL-1.2",
|
|
7063
|
+
"CDDL-1.0",
|
|
7064
|
+
"OSL-3.0",
|
|
7065
|
+
"CC-BY-SA-4.0",
|
|
7066
|
+
// Deprecated spellings npm still accepts.
|
|
7067
|
+
"GPL-2.0",
|
|
7068
|
+
"GPL-3.0",
|
|
7069
|
+
"LGPL-2.1",
|
|
7070
|
+
"LGPL-3.0",
|
|
7071
|
+
"AGPL-3.0"
|
|
7072
|
+
];
|
|
7073
|
+
var OTHER = ["CC-BY-NC-4.0", "CC-BY-NC-SA-4.0", "CC-BY-ND-4.0", "BUSL-1.1", "Elastic-2.0", "SSPL-1.0"];
|
|
7074
|
+
var EXCEPTIONS = ["Classpath-exception-2.0", "LLVM-exception", "GCC-exception-3.1", "Autoconf-exception-3.0", "Bison-exception-2.2", "Font-exception-2.0"];
|
|
7075
|
+
var KNOWN = new Map([...PERMISSIVE.map((id) => [id, "permissive"]), ...COPYLEFT.map((id) => [id, "copyleft"]), ...OTHER.map((id) => [id, "other"])]);
|
|
7076
|
+
var LOWER = new Map([...KNOWN.keys()].map((id) => [id.toLowerCase(), id]));
|
|
7077
|
+
function parseLicense(expr) {
|
|
7078
|
+
const tokens = expr.trim().match(/\(|\)|[^\s()]+/g) ?? [];
|
|
7079
|
+
if (!tokens.length) throw new Error("an empty licence");
|
|
7080
|
+
const out = { ids: [], unknown: [], fix: [] };
|
|
7081
|
+
let i = 0;
|
|
7082
|
+
const id = (t2, exception = false) => {
|
|
7083
|
+
if (!t2 || /^(AND|OR|WITH|\(|\))$/i.test(t2)) throw new Error(`a licence identifier was expected${t2 ? ` before "${t2}"` : " at the end"}`);
|
|
7084
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9.+-]*$/.test(t2)) throw new Error(`"${t2}" is not an SPDX identifier (write "MIT OR Apache-2.0", not "MIT/Apache-2.0")`);
|
|
7085
|
+
if (exception) {
|
|
7086
|
+
if (!EXCEPTIONS.includes(t2)) out.unknown.push(t2);
|
|
7087
|
+
return;
|
|
7088
|
+
}
|
|
7089
|
+
const plus = t2.endsWith("+") ? t2.slice(0, -1) : t2;
|
|
7090
|
+
out.ids.push(t2);
|
|
7091
|
+
if (/^(LicenseRef|DocumentRef)-/.test(plus) || KNOWN.has(plus)) return;
|
|
7092
|
+
const right = LOWER.get(plus.toLowerCase());
|
|
7093
|
+
if (right) out.fix.push({ from: t2, to: right });
|
|
7094
|
+
else out.unknown.push(t2);
|
|
7095
|
+
};
|
|
7096
|
+
const primary = () => {
|
|
7097
|
+
const t2 = tokens[i];
|
|
7098
|
+
if (t2 === "(") {
|
|
7099
|
+
i++;
|
|
7100
|
+
expression();
|
|
7101
|
+
if (tokens[i++] !== ")") throw new Error('a "(" is never closed');
|
|
7102
|
+
return;
|
|
7103
|
+
}
|
|
7104
|
+
id(tokens[i++]);
|
|
7105
|
+
if (tokens[i]?.toUpperCase() === "WITH") {
|
|
7106
|
+
i++;
|
|
7107
|
+
id(tokens[i++], true);
|
|
7108
|
+
}
|
|
7109
|
+
};
|
|
7110
|
+
const expression = () => {
|
|
7111
|
+
primary();
|
|
7112
|
+
while (tokens[i] && /^(AND|OR)$/i.test(tokens[i])) {
|
|
7113
|
+
i++;
|
|
7114
|
+
primary();
|
|
7115
|
+
}
|
|
7116
|
+
};
|
|
7117
|
+
if (/^UNLICENSED$/i.test(expr.trim())) return { ids: ["UNLICENSED"], unknown: [], fix: [] };
|
|
7118
|
+
expression();
|
|
7119
|
+
if (i < tokens.length) throw new Error(`"${tokens[i]}" is out of place (join licences with AND or OR)`);
|
|
7120
|
+
return out;
|
|
7121
|
+
}
|
|
7122
|
+
function isRegion(code) {
|
|
7123
|
+
if (code === "EU") return true;
|
|
7124
|
+
if (!/^[A-Z]{2}$/.test(code)) return false;
|
|
7125
|
+
try {
|
|
7126
|
+
return new Intl.DisplayNames(["en"], { type: "region", fallback: "none" }).of(code) !== void 0;
|
|
7127
|
+
} catch {
|
|
7128
|
+
return false;
|
|
7129
|
+
}
|
|
7130
|
+
}
|
|
7131
|
+
|
|
5789
7132
|
// packages/core/src/plugin-lint.ts
|
|
5790
7133
|
var ID2 = /^[a-z0-9][a-z0-9-]*$/;
|
|
5791
7134
|
var PART_ID = /^[a-z0-9][a-zA-Z0-9-]*$/;
|
|
@@ -5819,6 +7162,7 @@ function lintOptions(where, f, kind) {
|
|
|
5819
7162
|
if (name === "takeOver") err(path, "takeOver is the instance's switch, not an option: declare `takeOver` on the definition");
|
|
5820
7163
|
if (name === "hideWhenEmpty") err(path, "hideWhenEmpty is the instance's switch: declare `empty(ctx)` (and `hideWhenEmpty` on the definition)");
|
|
5821
7164
|
if (kind === "source" && (name === "intervalMs" || name === "timeoutMs") && !path.includes(".")) err(path, "refresh and timeout are not options: declare intervalMs / timeoutMs on the source");
|
|
7165
|
+
if (kind === "source" && name === "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");
|
|
5822
7166
|
if (name === "max" || name === "count") warn(path, "a cap is max<Things> (maxProcesses); a list length is `rows` through listOptions()");
|
|
5823
7167
|
if ((name === "latitude" || name === "longitude") && !(x.kind === "number" && x.advanced)) warn(path, "use ctx.location, with locationOptions() as an advanced override");
|
|
5824
7168
|
if (x.kind === "string") {
|
|
@@ -5829,10 +7173,10 @@ function lintOptions(where, f, kind) {
|
|
|
5829
7173
|
}
|
|
5830
7174
|
return out;
|
|
5831
7175
|
}
|
|
5832
|
-
function missingLanguages(
|
|
5833
|
-
if (
|
|
5834
|
-
if (typeof
|
|
5835
|
-
return langs.filter((l) => !(l in
|
|
7176
|
+
function missingLanguages(text3, langs) {
|
|
7177
|
+
if (text3 === void 0) return [];
|
|
7178
|
+
if (typeof text3 === "string") return langs.filter((l) => l !== "en");
|
|
7179
|
+
return langs.filter((l) => !(l in text3));
|
|
5836
7180
|
}
|
|
5837
7181
|
function knownLanguage(tag) {
|
|
5838
7182
|
try {
|
|
@@ -5852,6 +7196,22 @@ function lintPlugin(def) {
|
|
|
5852
7196
|
const reaches = (def.sources ?? []).length > 0 || (def.widgets ?? []).some((w) => w.fetch);
|
|
5853
7197
|
if (reaches && !def.permissions) add("warn", "plugin", "it reads data: declare `permissions` (hosts, programs, files, devices) so people know before installing");
|
|
5854
7198
|
if (!def.description) add("warn", "plugin", "a description, for the Plugins page and the store");
|
|
7199
|
+
if (def.license) {
|
|
7200
|
+
try {
|
|
7201
|
+
const lic = parseLicense(def.license);
|
|
7202
|
+
for (const f of lic.fix) add("warn", "plugin", `license: write "${f.from}" as "${f.to}" (SPDX identifiers are case-sensitive)`);
|
|
7203
|
+
for (const u of lic.unknown) add("warn", "plugin", `license: "${u}" is not an SPDX identifier Kiosko knows (https://spdx.org/licenses/); the store lists it as "other"`);
|
|
7204
|
+
} catch (err) {
|
|
7205
|
+
add("error", "plugin", `license ${JSON.stringify(def.license)}: ${err.message}`);
|
|
7206
|
+
}
|
|
7207
|
+
}
|
|
7208
|
+
for (const k of ["only", "without"]) {
|
|
7209
|
+
for (const code of def.markets?.[k] ?? []) if (!isRegion(code)) add("error", "plugin", `markets.${k}: "${code}" is not an ISO 3166-1 alpha-2 country code (ES, TW\u2026) nor EU`);
|
|
7210
|
+
}
|
|
7211
|
+
if (def.markets?.only?.length && def.markets.without?.length) add("warn", "plugin", "markets: `only` and `without` together; `only` alone says it");
|
|
7212
|
+
if (def.pricing && def.pricing.model !== "free") add("error", "plugin", `pricing.model ${JSON.stringify(def.pricing.model)}: only "free" for now (paid plugins are not supported yet)`);
|
|
7213
|
+
if (def.category && (def.widgets ?? []).length) add("warn", "plugin", "`category` is for plugins without widgets: the store takes the widgets' own");
|
|
7214
|
+
for (const [k, url2] of [...Object.entries(def.support ?? {}), ["funding", def.funding]]) if (url2 && !/^https:\/\//.test(url2)) add("warn", "plugin", `${k === "funding" ? "funding" : `support.${k}`}: an https:// address`);
|
|
5855
7215
|
for (const r of [...def.requires ?? [], ...def.optional ?? []]) if (!/^[a-z0-9][a-z0-9-]*\/[a-zA-Z0-9-]+$/.test(r)) add("error", "plugin", `requires/optional ${JSON.stringify(r)}: a type, plugin/thing`);
|
|
5856
7216
|
const used = languagesOf(def);
|
|
5857
7217
|
const declared = def.languages;
|
|
@@ -5890,12 +7250,12 @@ function lintPlugin(def) {
|
|
|
5890
7250
|
}
|
|
5891
7251
|
};
|
|
5892
7252
|
texts("plugin", def.name, def.description);
|
|
5893
|
-
const
|
|
7253
|
+
const ids2 = /* @__PURE__ */ new Set();
|
|
5894
7254
|
const part = (kind, x) => {
|
|
5895
7255
|
const where = `${def.id}/${x.id}`;
|
|
5896
7256
|
if (!PART_ID.test(x.id ?? "")) add("error", where, `${kind} id ${JSON.stringify(x.id)}`);
|
|
5897
|
-
if (
|
|
5898
|
-
|
|
7257
|
+
if (ids2.has(`${kind}:${x.id}`)) add("error", where, `two ${kind}s with the id "${x.id}"`);
|
|
7258
|
+
ids2.add(`${kind}:${x.id}`);
|
|
5899
7259
|
texts(where, x.name, x.description);
|
|
5900
7260
|
if (!x.description) add("warn", where, "a description, for the library and the store");
|
|
5901
7261
|
return where;
|
|
@@ -5927,6 +7287,7 @@ function lintPlugin(def) {
|
|
|
5927
7287
|
out.push(...lintOptions(where, s.options, "source"));
|
|
5928
7288
|
if (!s.read && !s.watch) add("error", where, "a source needs `read` or `watch`");
|
|
5929
7289
|
if (!s.demo) add("warn", where, "no `demo`: widgets using it show nothing in the gallery");
|
|
7290
|
+
if (s.background && !s.alerts) add("warn", where, "`background` without `alerts`: it would run for nothing, so Kiosko offers no switch");
|
|
5930
7291
|
}
|
|
5931
7292
|
for (const i of def.interludes ?? []) {
|
|
5932
7293
|
const where = part("interlude", i);
|
|
@@ -5982,13 +7343,37 @@ async function checkUpdates(plugins, o = {}) {
|
|
|
5982
7343
|
return { checkedAt: o.now ?? Date.now(), plugins: found.filter((x) => !!x), ...kiosko ? { kiosko } : {}, errors };
|
|
5983
7344
|
}
|
|
5984
7345
|
|
|
7346
|
+
// packages/core/src/store/client.ts
|
|
7347
|
+
function releaseProblem(r, env) {
|
|
7348
|
+
if (r.sdk && !satisfies(env.sdk, r.sdk)) return { code: "sdk", range: r.sdk };
|
|
7349
|
+
if (r.platforms?.length && !r.platforms.includes(env.platform)) return { code: "os", platforms: r.platforms };
|
|
7350
|
+
return null;
|
|
7351
|
+
}
|
|
7352
|
+
function installableRelease(p, env) {
|
|
7353
|
+
const ok = p.releases.filter((r) => !r.withdrawn && !releaseProblem({ sdk: r.sdk ?? void 0, platforms: r.platforms ?? p.platforms }, env));
|
|
7354
|
+
return ok.find((r) => !r.deprecated) ?? ok[0] ?? null;
|
|
7355
|
+
}
|
|
7356
|
+
|
|
7357
|
+
// packages/core/src/store/build.ts
|
|
7358
|
+
function addedPermissions(before, after) {
|
|
7359
|
+
const out = {};
|
|
7360
|
+
for (const k of ["network", "exec", "files", "devices"]) {
|
|
7361
|
+
const added = (after?.[k] ?? []).filter((v) => !(before?.[k] ?? []).includes(v));
|
|
7362
|
+
if (added.length) out[k] = added;
|
|
7363
|
+
}
|
|
7364
|
+
return out;
|
|
7365
|
+
}
|
|
7366
|
+
|
|
7367
|
+
// packages/core/src/store/tar.ts
|
|
7368
|
+
var MAX_TARBALL_BYTES = 20 * 1024 * 1024;
|
|
7369
|
+
|
|
5985
7370
|
// plugins/core/src/index.ts
|
|
5986
7371
|
import { readdir, readFile, stat } from "node:fs/promises";
|
|
5987
7372
|
import { join as join7 } from "node:path";
|
|
5988
|
-
function fit2(g,
|
|
7373
|
+
function fit2(g, text3, family, w, h, max = 400) {
|
|
5989
7374
|
let size = Math.min(max, h);
|
|
5990
7375
|
g.font = `${size}px "${family}"`;
|
|
5991
|
-
const width = g.measureText(
|
|
7376
|
+
const width = g.measureText(text3).width;
|
|
5992
7377
|
if (width > w) size = Math.floor(size * w / width);
|
|
5993
7378
|
return Math.max(8, size);
|
|
5994
7379
|
}
|
|
@@ -6045,10 +7430,10 @@ var clock = defineWidget({
|
|
|
6045
7430
|
render(g, { box, now, options: options2, theme, locale, fmt }) {
|
|
6046
7431
|
const at = wallClock(now, options2.timeZone);
|
|
6047
7432
|
const clock2 = options2.timeFormat === "inherit" ? fmt : createFormatters({ locale, timeFormat: options2.timeFormat, now });
|
|
6048
|
-
const
|
|
7433
|
+
const text3 = clock2.time(at, { seconds: options2.showSeconds, ampm: false });
|
|
6049
7434
|
const dateText = options2.showDate ? new Date(at).toLocaleDateString(locale, DATE_FORMATS[options2.dateFormat]) : "";
|
|
6050
7435
|
const dateH = options2.showDate ? Math.min(box.h * 0.2, 40) : 0;
|
|
6051
|
-
const size = fit2(g,
|
|
7436
|
+
const size = fit2(g, text3, theme.fonts.monoBold, box.w * 0.96, (box.h - dateH * 1.3) * 0.95);
|
|
6052
7437
|
const color2 = options2.color === "accent" ? theme.colors.accent : options2.color === "dim" ? theme.colors.inkDim : theme.colors.ink;
|
|
6053
7438
|
const x = options2.align === "left" ? box.x : options2.align === "right" ? box.x + box.w : box.x + box.w / 2;
|
|
6054
7439
|
const block = size * 0.78 + (dateH ? dateH * 1.4 : 0);
|
|
@@ -6056,7 +7441,7 @@ var clock = defineWidget({
|
|
|
6056
7441
|
g.textAlign = options2.align;
|
|
6057
7442
|
g.fillStyle = color2;
|
|
6058
7443
|
g.font = `${size}px "${theme.fonts.monoBold}"`;
|
|
6059
|
-
g.fillText(
|
|
7444
|
+
g.fillText(text3, x, base3);
|
|
6060
7445
|
if (dateH) {
|
|
6061
7446
|
const ds = Math.min(dateH, fit2(g, dateText, theme.fonts.sans, box.w * 0.96, dateH));
|
|
6062
7447
|
g.font = `${ds}px "${theme.fonts.sans}"`;
|
|
@@ -6113,7 +7498,7 @@ function expandHome(path) {
|
|
|
6113
7498
|
return expandPath(path.trim());
|
|
6114
7499
|
}
|
|
6115
7500
|
var MAX_FILE_CHARS = 2e4;
|
|
6116
|
-
var
|
|
7501
|
+
var text2 = defineWidget({
|
|
6117
7502
|
id: "text",
|
|
6118
7503
|
name: { en: "Text note", es: "Nota de texto", de: "Textnotiz", "zh-Hant": "\u6587\u5B57\u4FBF\u689D", "zh-Hans": "\u6587\u5B57\u4FBF\u7B7E" },
|
|
6119
7504
|
description: { en: "A note or a motto, auto-sized to fill its tile; or the contents of a file a script writes.", es: "Una nota o un lema, con la letra ajustada a la tesela; o lo que un script escribe en un fichero.", de: "Eine Notiz oder ein Motto, in der Gr\xF6\xDFe an die Kachel angepasst; oder der Inhalt einer Datei, die ein Skript schreibt.", "zh-Hant": "\u4E00\u5247\u4FBF\u689D\u6216\u5EA7\u53F3\u9298\uFF0C\u5B57\u9AD4\u81EA\u52D5\u7E2E\u653E\u586B\u6EFF\u65B9\u683C\uFF1B\u6216\u662F\u986F\u793A\u8173\u672C\u5BEB\u5165\u6A94\u6848\u7684\u5167\u5BB9\u3002", "zh-Hans": "\u4E00\u6761\u4FBF\u7B7E\u6216\u5EA7\u53F3\u94ED\uFF0C\u5B57\u53F7\u81EA\u52A8\u7F29\u653E\u586B\u6EE1\u683C\u5B50\uFF1B\u6216\u8005\u663E\u793A\u811A\u672C\u5199\u5165\u6587\u4EF6\u7684\u5185\u5BB9\u3002" },
|
|
@@ -6174,8 +7559,8 @@ var text = defineWidget({
|
|
|
6174
7559
|
function noteOf(options2, data) {
|
|
6175
7560
|
return options2.file.trim() && typeof data?.text === "string" ? data.text : options2.text;
|
|
6176
7561
|
}
|
|
6177
|
-
function parseItems(
|
|
6178
|
-
return
|
|
7562
|
+
function parseItems(text3) {
|
|
7563
|
+
return text3.split("\n").map((line) => {
|
|
6179
7564
|
const [head = "", ...rest] = line.split("|");
|
|
6180
7565
|
return { text: head.trim(), detail: rest.join("|").trim() };
|
|
6181
7566
|
}).filter((x) => x.text);
|
|
@@ -6329,7 +7714,7 @@ var image = defineWidget({
|
|
|
6329
7714
|
var src_default = definePlugin({
|
|
6330
7715
|
id: "core",
|
|
6331
7716
|
name: { en: "Essentials", es: "B\xE1sicos", de: "Grundlagen", "zh-Hant": "\u57FA\u672C\u5DE5\u5177", "zh-Hans": "\u57FA\u7840\u7EC4\u4EF6" },
|
|
6332
|
-
version: "0.2.
|
|
7717
|
+
version: "0.2.7",
|
|
6333
7718
|
languages: ["en", "es", "de", "zh-Hant", "zh-Hans"],
|
|
6334
7719
|
sdk: "^0.2.0",
|
|
6335
7720
|
// The picture widget reads the image (or folder, or URL) you give it.
|
|
@@ -6338,11 +7723,11 @@ var src_default = definePlugin({
|
|
|
6338
7723
|
author: "Kiosko",
|
|
6339
7724
|
license: "MIT",
|
|
6340
7725
|
icon: "box",
|
|
6341
|
-
widgets: [clock, date,
|
|
7726
|
+
widgets: [clock, date, text2, list, image]
|
|
6342
7727
|
});
|
|
6343
7728
|
|
|
6344
7729
|
// plugins/legacy/src/index.ts
|
|
6345
|
-
import { existsSync as
|
|
7730
|
+
import { existsSync as existsSync7, statSync as statSync2 } from "node:fs";
|
|
6346
7731
|
import { isAbsolute, join as join8 } from "node:path";
|
|
6347
7732
|
import { pathToFileURL as pathToFileURL3 } from "node:url";
|
|
6348
7733
|
var loaded = /* @__PURE__ */ new Map();
|
|
@@ -6350,7 +7735,7 @@ function resolveModule(name, dir) {
|
|
|
6350
7735
|
const expanded = expandPath(name);
|
|
6351
7736
|
const base3 = isAbsolute(expanded) ? expanded : join8(expandPath(dir), expanded);
|
|
6352
7737
|
for (const p of [base3, `${base3}.mjs`, `${base3}.js`, join8(base3, "index.mjs"), join8(base3, "index.js")]) {
|
|
6353
|
-
if (
|
|
7738
|
+
if (existsSync7(p) && statSync2(p).isFile()) return p;
|
|
6354
7739
|
}
|
|
6355
7740
|
return null;
|
|
6356
7741
|
}
|
|
@@ -6425,7 +7810,7 @@ var module2 = defineWidget({
|
|
|
6425
7810
|
var src_default2 = definePlugin({
|
|
6426
7811
|
id: "legacy",
|
|
6427
7812
|
name: { en: "aimonitor compatibility", es: "Compatibilidad aimonitor", de: "aimonitor-Kompatibilit\xE4t", "zh-Hant": "aimonitor \u76F8\u5BB9\u6027", "zh-Hans": "aimonitor \u517C\u5BB9" },
|
|
6428
|
-
version: "0.2.
|
|
7813
|
+
version: "0.2.7",
|
|
6429
7814
|
languages: ["en", "es", "de", "zh-Hant", "zh-Hans"],
|
|
6430
7815
|
sdk: "^0.2.0",
|
|
6431
7816
|
// Runs the aimonitor modules you point it at, and reads their folder.
|
|
@@ -6439,7 +7824,7 @@ var src_default2 = definePlugin({
|
|
|
6439
7824
|
|
|
6440
7825
|
// packages/server/src/official.ts
|
|
6441
7826
|
var BUNDLED_PLUGIN_IDS = ["agents", "cats", "system", "vitals", "usage", "weather", "calendar", "news", "mirror", "gitlab", "github", "calls", "timesheet", "llm", "gpu", "homeassistant"];
|
|
6442
|
-
var OPTIONAL_PLUGIN_IDS = ["doom"];
|
|
7827
|
+
var OPTIONAL_PLUGIN_IDS = ["doom", "video", "fractals", "gaming", "logs", "hazards"];
|
|
6443
7828
|
var OFFICIAL_PLUGINS = [
|
|
6444
7829
|
...BUNDLED_PLUGIN_IDS.map((id) => ({ id, npm: `kiosko-plugin-${id}`, bundled: true })),
|
|
6445
7830
|
...OPTIONAL_PLUGIN_IDS.map((id) => ({ id, npm: `kiosko-plugin-${id}`, bundled: false }))
|
|
@@ -6450,16 +7835,16 @@ var BUNDLED_PLUGINS = OFFICIAL_PLUGINS.filter((o) => o.bundled);
|
|
|
6450
7835
|
var BUILTIN_PLUGINS = [src_default, src_default2];
|
|
6451
7836
|
|
|
6452
7837
|
// packages/server/src/config-cli.ts
|
|
6453
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
7838
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync9, mkdirSync as mkdirSync5, readFileSync as readFileSync4, writeFileSync as writeFileSync6 } from "node:fs";
|
|
6454
7839
|
import { tmpdir } from "node:os";
|
|
6455
7840
|
import { dirname as dirname4, isAbsolute as isAbsolute2, join as join10, relative, resolve as resolve2 } from "node:path";
|
|
6456
7841
|
|
|
6457
7842
|
// packages/server/src/preview.ts
|
|
6458
|
-
import { existsSync as
|
|
7843
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync4, writeFileSync as writeFileSync5 } from "node:fs";
|
|
6459
7844
|
import { dirname as dirname3, join as join9 } from "node:path";
|
|
6460
7845
|
function writePreview(rt, screen, page, out, o = {}) {
|
|
6461
7846
|
const r = rt.preview(screen, page, { demo: o.demo ?? true });
|
|
6462
|
-
if (!
|
|
7847
|
+
if (!existsSync8(dirname3(out))) mkdirSync4(dirname3(out), { recursive: true });
|
|
6463
7848
|
writeFileSync5(out, r.canvas.toBuffer("image/png"));
|
|
6464
7849
|
return r.tiles.filter((t2) => t2.error).map((t2) => `tile ${t2.id}: ${t2.error}`);
|
|
6465
7850
|
}
|
|
@@ -6514,9 +7899,9 @@ function issueLine(i) {
|
|
|
6514
7899
|
const ctx = i.context && !i.message.includes(i.context) && !i.path.includes(i.context) ? ` (${i.context})` : "";
|
|
6515
7900
|
return `${i.path}${ctx}: ${i.message}`;
|
|
6516
7901
|
}
|
|
6517
|
-
function readConfigText(
|
|
7902
|
+
function readConfigText(text3) {
|
|
6518
7903
|
const notes = [];
|
|
6519
|
-
let t2 =
|
|
7904
|
+
let t2 = text3.charCodeAt(0) === 65279 ? text3.slice(1) : text3;
|
|
6520
7905
|
const fence = /^\s*```[\w-]*[ \t]*\r?\n([\s\S]*?)\r?\n[ \t]*```\s*$/.exec(t2);
|
|
6521
7906
|
if (fence) {
|
|
6522
7907
|
t2 = fence[1];
|
|
@@ -6531,7 +7916,7 @@ function readConfigText(text2) {
|
|
|
6531
7916
|
}
|
|
6532
7917
|
function readInput(file) {
|
|
6533
7918
|
const name = file === "-" ? "(stdin)" : file;
|
|
6534
|
-
if (file !== "-" && !
|
|
7919
|
+
if (file !== "-" && !existsSync9(file)) return { error: `not found: ${file}`, notes: [], name };
|
|
6535
7920
|
return { ...readConfigText(readFileSync4(file === "-" ? 0 : file, "utf8")), name };
|
|
6536
7921
|
}
|
|
6537
7922
|
var pluginDefs = (r) => r.list().map((p) => p.def);
|
|
@@ -6558,16 +7943,16 @@ var stamp = (d = /* @__PURE__ */ new Date()) => {
|
|
|
6558
7943
|
async function schemaCommand(ctx, opts) {
|
|
6559
7944
|
const reg = await ctx.registry();
|
|
6560
7945
|
const plugins = pluginDefs(reg);
|
|
6561
|
-
const
|
|
6562
|
-
const
|
|
7946
|
+
const schema2 = configSchema(plugins);
|
|
7947
|
+
const text3 = `${JSON.stringify(schema2, null, 2)}
|
|
6563
7948
|
`;
|
|
6564
7949
|
const out = opts.get("--out");
|
|
6565
7950
|
if (!out) {
|
|
6566
|
-
process.stdout.write(
|
|
7951
|
+
process.stdout.write(text3);
|
|
6567
7952
|
return 0;
|
|
6568
7953
|
}
|
|
6569
7954
|
mkdirSync5(dirname4(resolve2(out)), { recursive: true });
|
|
6570
|
-
writeFileSync6(out,
|
|
7955
|
+
writeFileSync6(out, text3);
|
|
6571
7956
|
const count = (k) => plugins.reduce((n, p) => n + (p[k]?.length ?? 0), 0);
|
|
6572
7957
|
console.error(`${out}: schema of config.json with ${plural3(count("widgets"), "widget")}, ${plural3(count("sources"), "source")} and ${plural3(count("interludes"), "interlude")} from ${plural3(plugins.length, "plugin")}`);
|
|
6573
7958
|
const rel = relative(dirname4(resolve2(ctx.configPath)), resolve2(out));
|
|
@@ -6709,11 +8094,11 @@ ${dim("Dry run: nothing was written.")} Run again with --apply to back up the cu
|
|
|
6709
8094
|
return 0;
|
|
6710
8095
|
}
|
|
6711
8096
|
const backup = `${path}.bak-${stamp()}`;
|
|
6712
|
-
if (
|
|
8097
|
+
if (existsSync9(path)) {
|
|
6713
8098
|
copyFileSync2(path, backup);
|
|
6714
8099
|
restrictToOwner(backup);
|
|
6715
8100
|
}
|
|
6716
|
-
const saved =
|
|
8101
|
+
const saved = existsSync9(backup) ? `; the previous one is in ${backup}` : "";
|
|
6717
8102
|
if (running?.same) {
|
|
6718
8103
|
const r = await fetch(`${running.base}/api/config`, {
|
|
6719
8104
|
method: "PUT",
|
|
@@ -6759,7 +8144,7 @@ async function configCommand(argv2, ctx) {
|
|
|
6759
8144
|
|
|
6760
8145
|
// packages/server/src/plugins-cli.ts
|
|
6761
8146
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
6762
|
-
import { existsSync as
|
|
8147
|
+
import { existsSync as existsSync10, lstatSync, mkdirSync as mkdirSync6, readdirSync as readdirSync4, readFileSync as readFileSync5, rmSync, symlinkSync, watch, writeFileSync as writeFileSync7 } from "node:fs";
|
|
6763
8148
|
import { basename, join as join11, resolve as resolve4 } from "node:path";
|
|
6764
8149
|
import { pathToFileURL as pathToFileURL4 } from "node:url";
|
|
6765
8150
|
var npmName = (s) => /^[a-z0-9][\w.-]*$/.test(s) && !s.startsWith("kiosko-plugin-") && !s.includes("/") ? `kiosko-plugin-${s}` : s;
|
|
@@ -6767,7 +8152,7 @@ function ensureFolder() {
|
|
|
6767
8152
|
const dir = paths.plugins;
|
|
6768
8153
|
mkdirSync6(dir, { recursive: true });
|
|
6769
8154
|
const pkg = join11(dir, "package.json");
|
|
6770
|
-
if (!
|
|
8155
|
+
if (!existsSync10(pkg)) writeFileSync7(pkg, `${JSON.stringify({ name: "kiosko-user-plugins", private: true, type: "module" }, null, 2)}
|
|
6771
8156
|
`);
|
|
6772
8157
|
return dir;
|
|
6773
8158
|
}
|
|
@@ -6777,10 +8162,10 @@ function npm(args, cwd) {
|
|
|
6777
8162
|
async function loadPluginDir(dir, o = {}) {
|
|
6778
8163
|
const root = resolve4(dir);
|
|
6779
8164
|
const pkgPath = join11(root, "package.json");
|
|
6780
|
-
const pkg =
|
|
6781
|
-
const built = [pkg.kiosko?.plugin, pkg.main, "index.mjs", "index.js"].filter((x) => typeof x === "string").map((x) => join11(root, x)).find(
|
|
8165
|
+
const pkg = existsSync10(pkgPath) ? JSON.parse(readFileSync5(pkgPath, "utf8")) : {};
|
|
8166
|
+
const built = [pkg.kiosko?.plugin, pkg.main, "index.mjs", "index.js"].filter((x) => typeof x === "string").map((x) => join11(root, x)).find(existsSync10);
|
|
6782
8167
|
const src = join11(root, "src", "index.ts");
|
|
6783
|
-
const entry = (o.src || !built) &&
|
|
8168
|
+
const entry = (o.src || !built) && existsSync10(src) ? src : built;
|
|
6784
8169
|
if (!entry) throw new Error(`no plugin in ${root}: no package.json "kiosko.plugin", index.js or src/index.ts`);
|
|
6785
8170
|
installSdkResolver();
|
|
6786
8171
|
const mod = await import(`${pathToFileURL4(entry).href}?v=${Date.now()}`);
|
|
@@ -6828,7 +8213,7 @@ ${errors.length} errors, ${issues.length - errors.length} warnings` : "\u2713 no
|
|
|
6828
8213
|
async function manifest(dir, argv2) {
|
|
6829
8214
|
const root = resolve4(dir);
|
|
6830
8215
|
const { def, pkg } = await loadPluginDir(root, { src: flagOf(argv2, "--src") });
|
|
6831
|
-
const screenshots = Object.fromEntries((def.widgets ?? []).map((w) => [w.id, `docs/${w.id}.png`]).filter(([, f]) =>
|
|
8216
|
+
const screenshots = Object.fromEntries((def.widgets ?? []).map((w) => [w.id, `docs/${w.id}.png`]).filter(([, f]) => existsSync10(join11(root, f))));
|
|
6832
8217
|
const out = optOf(argv2, "--out") ?? join11(root, "kiosko-manifest.json");
|
|
6833
8218
|
writeFileSync7(out, `${JSON.stringify(pluginManifest(def, { pkg, screenshots }), null, 2)}
|
|
6834
8219
|
`);
|
|
@@ -6868,6 +8253,10 @@ function newPluginFiles(id) {
|
|
|
6868
8253
|
type: "module",
|
|
6869
8254
|
license: "MIT",
|
|
6870
8255
|
keywords: ["kiosko", "kiosko-plugin", "lcd", "widgets"],
|
|
8256
|
+
// Where the plugin store links to (its source, where to report a problem): put your own repository.
|
|
8257
|
+
repository: { type: "git", url: `git+https://github.com/YOUR-NAME/kiosko-plugin-${id}.git` },
|
|
8258
|
+
bugs: { url: `https://github.com/YOUR-NAME/kiosko-plugin-${id}/issues` },
|
|
8259
|
+
homepage: `https://github.com/YOUR-NAME/kiosko-plugin-${id}#readme`,
|
|
6871
8260
|
exports: { ".": { source: "./src/index.ts", default: "./dist/index.js" } },
|
|
6872
8261
|
kiosko: { plugin: "./dist/index.js", id, sdk, languages: ["en", "es"], manifest: "./kiosko-manifest.json" },
|
|
6873
8262
|
files: ["dist", "docs", "kiosko-manifest.json", "README.md", "LICENSE"],
|
|
@@ -6999,6 +8388,39 @@ npm run dev # link it into your Kiosko and reload it on every build
|
|
|
6999
8388
|
\`\`\`
|
|
7000
8389
|
|
|
7001
8390
|
Publish with \`npm publish\`: it builds and writes \`kiosko-manifest.json\`, the record a plugin store reads.
|
|
8391
|
+
Better, from GitHub: set this repository up as a *trusted publisher* of the package on npmjs.com
|
|
8392
|
+
(Settings \u2192 Trusted publishing \u2192 GitHub Actions, workflow \`release.yml\`), then push a tag (\`git tag v0.1.0 && git push --tags\`).
|
|
8393
|
+
\`.github/workflows/release.yml\` tests it and publishes it with provenance, no token needed, and the Kiosko plugin
|
|
8394
|
+
store shows it within a day. Put your repository in \`package.json\` (\`repository\`, \`bugs\`, \`homepage\`) and, if you
|
|
8395
|
+
want, a \`funding\` link: the store shows them.
|
|
8396
|
+
`;
|
|
8397
|
+
const release = `name: Release
|
|
8398
|
+
|
|
8399
|
+
on:
|
|
8400
|
+
push:
|
|
8401
|
+
tags: ['v*']
|
|
8402
|
+
|
|
8403
|
+
permissions:
|
|
8404
|
+
contents: write
|
|
8405
|
+
id-token: write
|
|
8406
|
+
|
|
8407
|
+
jobs:
|
|
8408
|
+
publish:
|
|
8409
|
+
runs-on: ubuntu-latest
|
|
8410
|
+
steps:
|
|
8411
|
+
- uses: actions/checkout@v5
|
|
8412
|
+
- uses: actions/setup-node@v5
|
|
8413
|
+
with:
|
|
8414
|
+
node-version: 24
|
|
8415
|
+
registry-url: https://registry.npmjs.org
|
|
8416
|
+
- run: npm install --no-audit --no-fund
|
|
8417
|
+
- run: npm test
|
|
8418
|
+
# prepublishOnly writes kiosko-manifest.json with the kiosko command.
|
|
8419
|
+
- run: npm install --global kiosko --no-audit --no-fund
|
|
8420
|
+
- run: npm publish --access public
|
|
8421
|
+
- run: gh release create "$GITHUB_REF_NAME" --generate-notes
|
|
8422
|
+
env:
|
|
8423
|
+
GH_TOKEN: \${{ github.token }}
|
|
7002
8424
|
`;
|
|
7003
8425
|
return {
|
|
7004
8426
|
"package.json": `${JSON.stringify(pkg, null, 2)}
|
|
@@ -7009,7 +8431,8 @@ Publish with \`npm publish\`: it builds and writes \`kiosko-manifest.json\`, the
|
|
|
7009
8431
|
"tsconfig.json": `${JSON.stringify(tsconfig, null, 2)}
|
|
7010
8432
|
`,
|
|
7011
8433
|
"README.md": readme,
|
|
7012
|
-
".gitignore": "node_modules/\ndist/\n*.log\n"
|
|
8434
|
+
".gitignore": "node_modules/\ndist/\n*.log\n",
|
|
8435
|
+
".github/workflows/release.yml": release
|
|
7013
8436
|
};
|
|
7014
8437
|
}
|
|
7015
8438
|
async function pluginsCommand(argv2, registry2) {
|
|
@@ -7028,7 +8451,7 @@ async function pluginsCommand(argv2, registry2) {
|
|
|
7028
8451
|
const [id, where] = positional(names);
|
|
7029
8452
|
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)");
|
|
7030
8453
|
const dir = resolve4(where ?? `kiosko-plugin-${id}`);
|
|
7031
|
-
if (
|
|
8454
|
+
if (existsSync10(dir) && readdirSync4(dir).length) throw new Error(`${dir} is not empty`);
|
|
7032
8455
|
for (const [file, body2] of Object.entries(newPluginFiles(id))) {
|
|
7033
8456
|
mkdirSync6(join11(dir, file, ".."), { recursive: true });
|
|
7034
8457
|
writeFileSync7(join11(dir, file), body2);
|
|
@@ -7064,10 +8487,10 @@ plugins folder: ${paths.plugins}`);
|
|
|
7064
8487
|
for (const n of names) {
|
|
7065
8488
|
const src = resolve4(n);
|
|
7066
8489
|
const pkgPath = join11(src, "package.json");
|
|
7067
|
-
if (!
|
|
8490
|
+
if (!existsSync10(pkgPath)) throw new Error(`${src} has no package.json`);
|
|
7068
8491
|
const pkg = JSON.parse(readFileSync5(pkgPath, "utf8"));
|
|
7069
8492
|
const entry = pkg.kiosko?.plugin;
|
|
7070
|
-
if (entry && !
|
|
8493
|
+
if (entry && !existsSync10(join11(src, entry))) console.warn(`warning: ${entry} doesn't exist yet in ${src} (run its build)`);
|
|
7071
8494
|
const target = join11(dir, pkg.kiosko?.id ?? basename(src).replace(/^kiosko-plugin-/, ""));
|
|
7072
8495
|
const existing = (() => {
|
|
7073
8496
|
try {
|
|
@@ -7386,7 +8809,7 @@ function importAimonitor(old, reg, modeOverride, o = {}) {
|
|
|
7386
8809
|
|
|
7387
8810
|
// packages/server/src/service.ts
|
|
7388
8811
|
import { execFileSync as execFileSync3 } from "node:child_process";
|
|
7389
|
-
import { existsSync as
|
|
8812
|
+
import { existsSync as existsSync11, mkdirSync as mkdirSync8, rmSync as rmSync2, writeFileSync as writeFileSync9 } from "node:fs";
|
|
7390
8813
|
import { homedir as homedir3, platform as platform2 } from "node:os";
|
|
7391
8814
|
import { dirname as dirname5, join as join13, resolve as resolve5, win32 as win322 } from "node:path";
|
|
7392
8815
|
import { fileURLToPath } from "node:url";
|
|
@@ -7497,7 +8920,7 @@ function runService(action, plan) {
|
|
|
7497
8920
|
} catch {
|
|
7498
8921
|
}
|
|
7499
8922
|
}
|
|
7500
|
-
if (plan.file &&
|
|
8923
|
+
if (plan.file && existsSync11(plan.file)) rmSync2(plan.file);
|
|
7501
8924
|
console.log("removed");
|
|
7502
8925
|
return;
|
|
7503
8926
|
}
|
|
@@ -7505,34 +8928,37 @@ function runService(action, plan) {
|
|
|
7505
8928
|
}
|
|
7506
8929
|
|
|
7507
8930
|
// packages/server/src/server.ts
|
|
7508
|
-
import { existsSync as
|
|
8931
|
+
import { existsSync as existsSync14, readFileSync as readFileSync8, statSync as statSync3 } from "node:fs";
|
|
7509
8932
|
import { createServer } from "node:http";
|
|
7510
8933
|
import { createRequire as createRequire3 } from "node:module";
|
|
7511
|
-
import { dirname as
|
|
8934
|
+
import { dirname as dirname7, extname, join as join16, normalize as normPath, resolve as resolve7 } from "node:path";
|
|
7512
8935
|
|
|
7513
8936
|
// packages/server/src/plugins-manage.ts
|
|
7514
8937
|
import { execFile } from "node:child_process";
|
|
7515
|
-
import { existsSync as
|
|
8938
|
+
import { existsSync as existsSync12, lstatSync as lstatSync2, mkdirSync as mkdirSync9, readFileSync as readFileSync6, rmSync as rmSync3, writeFileSync as writeFileSync10 } from "node:fs";
|
|
7516
8939
|
import { join as join14, relative as relative2, resolve as resolve6, sep } from "node:path";
|
|
7517
8940
|
var NPM_NAME = /^(@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*(@[\w.^~<>=*-]+)?$/i;
|
|
7518
8941
|
var packageName = (spec) => spec.startsWith("@") ? `@${spec.slice(1).split("@")[0]}` : spec.split("@")[0];
|
|
7519
8942
|
function ensureFolder2(dir) {
|
|
7520
8943
|
mkdirSync9(dir, { recursive: true });
|
|
7521
8944
|
const pkg = join14(dir, "package.json");
|
|
7522
|
-
if (!
|
|
8945
|
+
if (!existsSync12(pkg)) writeFileSync10(pkg, `${JSON.stringify({ name: "kiosko-user-plugins", private: true, type: "module" }, null, 2)}
|
|
7523
8946
|
`);
|
|
7524
8947
|
}
|
|
8948
|
+
var IntegrityError = class extends Error {
|
|
8949
|
+
name = "IntegrityError";
|
|
8950
|
+
};
|
|
7525
8951
|
var realNpm = (args, cwd) => new Promise((ok, fail) => {
|
|
7526
8952
|
const npm2 = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
7527
8953
|
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)));
|
|
7528
8954
|
});
|
|
7529
|
-
function
|
|
7530
|
-
|
|
7531
|
-
|
|
7532
|
-
|
|
7533
|
-
|
|
8955
|
+
function installedIntegrity(dir, name) {
|
|
8956
|
+
try {
|
|
8957
|
+
const lock = JSON.parse(readFileSync6(join14(dir, "node_modules", ".package-lock.json"), "utf8"));
|
|
8958
|
+
return lock.packages?.[`node_modules/${name}`]?.integrity;
|
|
8959
|
+
} catch {
|
|
8960
|
+
return void 0;
|
|
7534
8961
|
}
|
|
7535
|
-
return out;
|
|
7536
8962
|
}
|
|
7537
8963
|
async function installPlugin(spec, o) {
|
|
7538
8964
|
if (!NPM_NAME.test(spec)) throw new Error("not a valid npm package name");
|
|
@@ -7541,29 +8967,37 @@ async function installPlugin(spec, o) {
|
|
|
7541
8967
|
const npm2 = o.npm ?? realNpm;
|
|
7542
8968
|
const r = o.registry;
|
|
7543
8969
|
const folder = join14(dir, "node_modules", packageName(spec));
|
|
7544
|
-
const readPkg = () =>
|
|
8970
|
+
const readPkg = () => existsSync12(join14(folder, "package.json")) ? JSON.parse(readFileSync6(join14(folder, "package.json"), "utf8")) : null;
|
|
7545
8971
|
const beforePkg = readPkg();
|
|
7546
8972
|
const beforeId = beforePkg ? packageMeta(beforePkg).id : void 0;
|
|
7547
|
-
const output = await npm2(["install", "--no-audit", "--no-fund", "--ignore-scripts", spec], dir);
|
|
8973
|
+
const output = await npm2(["install", "--no-audit", "--no-fund", "--ignore-scripts", "--save-exact", spec], dir);
|
|
8974
|
+
if (o.expectIntegrity) {
|
|
8975
|
+
const got = installedIntegrity(dir, packageName(spec));
|
|
8976
|
+
if (got !== o.expectIntegrity) {
|
|
8977
|
+
if (beforePkg?.version) await npm2(["install", "--no-audit", "--no-fund", "--ignore-scripts", "--save-exact", `${packageName(spec)}@${beforePkg.version}`], dir);
|
|
8978
|
+
else await npm2(["uninstall", "--no-audit", "--no-fund", packageName(spec)], dir);
|
|
8979
|
+
throw new IntegrityError(`${spec}: what npm installed is not what the store's catalogue says (${got ? "another integrity" : "no integrity recorded"}); ${beforePkg?.version ? `${beforePkg.version} is back` : "removed again"}, nothing of it was loaded`);
|
|
8980
|
+
}
|
|
8981
|
+
}
|
|
7548
8982
|
const pkg = readPkg();
|
|
7549
8983
|
if (!pkg) return { ids: [], output, restart: true, problem: `${packageName(spec)} was installed but has no package.json` };
|
|
7550
8984
|
const id = packageMeta(pkg).id;
|
|
7551
8985
|
const prev = id ? r.plugin(id) : beforeId ? r.plugin(beforeId) : void 0;
|
|
7552
8986
|
const prevOrigin = prev ? r.originOf(prev.def.id) ?? prev.origin : void 0;
|
|
7553
|
-
let
|
|
8987
|
+
let ids2 = [];
|
|
7554
8988
|
let problem;
|
|
7555
8989
|
if (id && prev && r.originOf(id) === folder) {
|
|
7556
8990
|
problem = await r.reload(id) ?? void 0;
|
|
7557
|
-
if (!problem)
|
|
8991
|
+
if (!problem) ids2 = [id];
|
|
7558
8992
|
} else {
|
|
7559
8993
|
if (prev) r.remove(prev.def.id);
|
|
7560
8994
|
const before = r.problems.length;
|
|
7561
|
-
|
|
7562
|
-
if (!
|
|
8995
|
+
ids2 = await r.loadOne(folder);
|
|
8996
|
+
if (!ids2.length) problem = r.problems.slice(before).map((p) => p.message).join("; ") || "it did not load";
|
|
7563
8997
|
}
|
|
7564
8998
|
if (problem && prev) {
|
|
7565
8999
|
if (prevOrigin === folder && beforePkg?.version) {
|
|
7566
|
-
await npm2(["install", "--no-audit", "--no-fund", "--ignore-scripts", `${packageName(spec)}@${beforePkg.version}`], dir);
|
|
9000
|
+
await npm2(["install", "--no-audit", "--no-fund", "--ignore-scripts", "--save-exact", `${packageName(spec)}@${beforePkg.version}`], dir);
|
|
7567
9001
|
if (!r.plugin(prev.def.id)) await r.loadOne(folder);
|
|
7568
9002
|
else await r.reload(prev.def.id);
|
|
7569
9003
|
} else {
|
|
@@ -7573,10 +9007,10 @@ async function installPlugin(spec, o) {
|
|
|
7573
9007
|
o.runtime.pluginsChanged([prev.def.id]);
|
|
7574
9008
|
return { ids: [], output, restart: false, problem, rolledBack: true };
|
|
7575
9009
|
}
|
|
7576
|
-
if (
|
|
9010
|
+
if (ids2.length) o.runtime.pluginsChanged(ids2);
|
|
7577
9011
|
const now = id ? r.plugin(id) : void 0;
|
|
7578
9012
|
const added = prev && now ? addedPermissions(prev.def.permissions, now.def.permissions) : {};
|
|
7579
|
-
return { ids, output, restart: false, ...problem ? { problem } : {}, ...Object.keys(added).length ? { addedPermissions: added } : {} };
|
|
9013
|
+
return { ids: ids2, output, restart: false, ...problem ? { problem } : {}, ...Object.keys(added).length ? { addedPermissions: added } : {} };
|
|
7580
9014
|
}
|
|
7581
9015
|
async function removePlugin(id, o) {
|
|
7582
9016
|
const dir = resolve6(o.dir ?? paths.plugins);
|
|
@@ -7603,6 +9037,122 @@ async function reloadPlugin(id, o) {
|
|
|
7603
9037
|
return problem;
|
|
7604
9038
|
}
|
|
7605
9039
|
|
|
9040
|
+
// packages/server/src/store.ts
|
|
9041
|
+
import { existsSync as existsSync13, mkdirSync as mkdirSync10, readFileSync as readFileSync7, renameSync as renameSync4, writeFileSync as writeFileSync11 } from "node:fs";
|
|
9042
|
+
import { dirname as dirname6, join as join15 } from "node:path";
|
|
9043
|
+
var STORE_URL = "https://kioskolcd.dev/store/v1/";
|
|
9044
|
+
function shipped(...candidates) {
|
|
9045
|
+
for (const c of candidates) if (existsSync13(c)) return c;
|
|
9046
|
+
return null;
|
|
9047
|
+
}
|
|
9048
|
+
function snapshotIndex() {
|
|
9049
|
+
const file = shipped(join15(import.meta.dirname, "../assets/store-index.json"), join15(import.meta.dirname, "assets/store-index.json"));
|
|
9050
|
+
try {
|
|
9051
|
+
return file ? JSON.parse(readFileSync7(file, "utf8")) : null;
|
|
9052
|
+
} catch {
|
|
9053
|
+
return null;
|
|
9054
|
+
}
|
|
9055
|
+
}
|
|
9056
|
+
var schema;
|
|
9057
|
+
function indexSchema() {
|
|
9058
|
+
if (schema !== void 0) return schema;
|
|
9059
|
+
const file = shipped(join15(import.meta.dirname, "../../core/schema/store-index.json"), join15(import.meta.dirname, "assets/store-index.schema.json"));
|
|
9060
|
+
schema = file ? JSON.parse(readFileSync7(file, "utf8")) : null;
|
|
9061
|
+
return schema;
|
|
9062
|
+
}
|
|
9063
|
+
function indexProblem(x) {
|
|
9064
|
+
const i = x;
|
|
9065
|
+
if (!i || typeof i !== "object" || i.schema !== 1 || !Array.isArray(i.plugins)) return "not a Kiosko store index (schema 1)";
|
|
9066
|
+
const s = indexSchema();
|
|
9067
|
+
const issues = s ? validateJson(s, x) : [];
|
|
9068
|
+
return issues.length ? `${issues[0].path}: ${issues[0].message}${issues.length > 1 ? ` (and ${issues.length - 1} more)` : ""}` : null;
|
|
9069
|
+
}
|
|
9070
|
+
var StoreCatalog = class {
|
|
9071
|
+
state;
|
|
9072
|
+
etag;
|
|
9073
|
+
sheets = /* @__PURE__ */ new Map();
|
|
9074
|
+
url;
|
|
9075
|
+
o;
|
|
9076
|
+
constructor(o) {
|
|
9077
|
+
this.o = o;
|
|
9078
|
+
this.url = (o.url ?? process.env.KIOSKO_STORE_URL ?? STORE_URL).replace(/\/?$/, "/");
|
|
9079
|
+
this.state = { index: null, from: "none", fetchedAt: null, error: null };
|
|
9080
|
+
const cached = this.readCache();
|
|
9081
|
+
const snap = (o.snapshot ?? snapshotIndex)();
|
|
9082
|
+
if (cached && (!snap || cached.index.generatedAt >= snap.generatedAt)) {
|
|
9083
|
+
this.state = { index: cached.index, from: "cache", fetchedAt: cached.fetchedAt, error: null };
|
|
9084
|
+
this.etag = cached.etag;
|
|
9085
|
+
} else if (snap) this.state = { index: snap, from: "snapshot", fetchedAt: null, error: null };
|
|
9086
|
+
}
|
|
9087
|
+
get file() {
|
|
9088
|
+
return join15(this.o.cacheDir, "index.json");
|
|
9089
|
+
}
|
|
9090
|
+
readCache() {
|
|
9091
|
+
try {
|
|
9092
|
+
const c = JSON.parse(readFileSync7(this.file, "utf8"));
|
|
9093
|
+
return indexProblem(c.index) ? null : c;
|
|
9094
|
+
} catch {
|
|
9095
|
+
return null;
|
|
9096
|
+
}
|
|
9097
|
+
}
|
|
9098
|
+
current() {
|
|
9099
|
+
return this.state;
|
|
9100
|
+
}
|
|
9101
|
+
/** Asks for a newer catalogue (conditionally). Never throws: a failure keeps what there was and says why. */
|
|
9102
|
+
async refresh() {
|
|
9103
|
+
const now = this.o.now ?? Date.now;
|
|
9104
|
+
try {
|
|
9105
|
+
const res = await (this.o.fetch ?? fetch)(`${this.url}index.json`, {
|
|
9106
|
+
headers: { accept: "application/json", "user-agent": "Kiosko (+https://kioskolcd.dev)", ...this.etag && this.state.from !== "snapshot" ? { "if-none-match": this.etag } : {} },
|
|
9107
|
+
signal: AbortSignal.timeout(this.o.timeoutMs ?? 15e3)
|
|
9108
|
+
});
|
|
9109
|
+
if (res.status === 304) {
|
|
9110
|
+
this.state = { ...this.state, fetchedAt: now(), error: null };
|
|
9111
|
+
this.writeCache();
|
|
9112
|
+
return this.state;
|
|
9113
|
+
}
|
|
9114
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
9115
|
+
const index = await res.json();
|
|
9116
|
+
const problem = indexProblem(index);
|
|
9117
|
+
if (problem) throw new Error(`the catalogue doesn't pass its schema: ${problem}`);
|
|
9118
|
+
this.etag = res.headers.get("etag") ?? void 0;
|
|
9119
|
+
this.state = { index, from: "network", fetchedAt: now(), error: null };
|
|
9120
|
+
this.sheets.clear();
|
|
9121
|
+
this.writeCache();
|
|
9122
|
+
} catch (err) {
|
|
9123
|
+
this.state = { ...this.state, error: err instanceof Error ? err.name === "TimeoutError" ? "timed out" : err.message : String(err) };
|
|
9124
|
+
}
|
|
9125
|
+
return this.state;
|
|
9126
|
+
}
|
|
9127
|
+
writeCache() {
|
|
9128
|
+
if (!this.state.index) return;
|
|
9129
|
+
try {
|
|
9130
|
+
mkdirSync10(dirname6(this.file), { recursive: true });
|
|
9131
|
+
const tmp = `${this.file}.tmp`;
|
|
9132
|
+
writeFileSync11(tmp, JSON.stringify({ index: this.state.index, ...this.etag ? { etag: this.etag } : {}, fetchedAt: this.state.fetchedAt ?? 0 }));
|
|
9133
|
+
renameSync4(tmp, this.file);
|
|
9134
|
+
} catch {
|
|
9135
|
+
}
|
|
9136
|
+
}
|
|
9137
|
+
/** A plugin's full record (plugins/<id>.json), or what the index has when it can't be had. */
|
|
9138
|
+
async sheet(id) {
|
|
9139
|
+
const p = this.state.index?.plugins.find((x) => x.id === id && !x.hidden);
|
|
9140
|
+
if (!p) return null;
|
|
9141
|
+
const have = this.sheets.get(id);
|
|
9142
|
+
if (have && have.plugin.latest === p.latest) return have;
|
|
9143
|
+
try {
|
|
9144
|
+
const res = await (this.o.fetch ?? fetch)(`${this.url}plugins/${encodeURIComponent(id)}.json`, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(this.o.timeoutMs ?? 15e3) });
|
|
9145
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
9146
|
+
const sheet = await res.json();
|
|
9147
|
+
const out = { ...sheet, plugin: p };
|
|
9148
|
+
this.sheets.set(id, out);
|
|
9149
|
+
return out;
|
|
9150
|
+
} catch {
|
|
9151
|
+
return { schema: 1, generatedAt: this.state.index.generatedAt, plugin: p, riskyOptions: [], sources: [] };
|
|
9152
|
+
}
|
|
9153
|
+
}
|
|
9154
|
+
};
|
|
9155
|
+
|
|
7606
9156
|
// packages/server/src/homeassistant.ts
|
|
7607
9157
|
import { hostname } from "node:os";
|
|
7608
9158
|
|
|
@@ -7812,7 +9362,9 @@ var NAMES = {
|
|
|
7812
9362
|
page: { en: "Page", es: "P\xE1gina", de: "Seite", "zh-Hant": "\u9801\u9762", "zh-Hans": "\u9875\u9762" },
|
|
7813
9363
|
shown: { en: "Page shown", es: "P\xE1gina en pantalla", de: "Angezeigte Seite", "zh-Hant": "\u76EE\u524D\u9801\u9762", "zh-Hans": "\u5F53\u524D\u9875\u9762" },
|
|
7814
9364
|
display: { en: "Display", es: "Pantalla", de: "Anzeige", "zh-Hant": "\u87A2\u5E55", "zh-Hans": "\u5C4F\u5E55" },
|
|
7815
|
-
interlude: { en: "Play", es: "Reproducir", de: "Abspielen", "zh-Hant": "\u64AD\u653E", "zh-Hans": "\u64AD\u653E" }
|
|
9365
|
+
interlude: { en: "Play", es: "Reproducir", de: "Abspielen", "zh-Hant": "\u64AD\u653E", "zh-Hans": "\u64AD\u653E" },
|
|
9366
|
+
alert: { en: "Alert", es: "Alerta", de: "Alarm", "zh-Hant": "\u8B66\u5831", "zh-Hans": "\u8B66\u62A5" },
|
|
9367
|
+
ack: { en: "Acknowledge alerts", es: "Marcar alertas como vistas", de: "Alarme best\xE4tigen", "zh-Hant": "\u78BA\u8A8D\u8B66\u5831", "zh-Hans": "\u786E\u8BA4\u8B66\u62A5" }
|
|
7816
9368
|
};
|
|
7817
9369
|
var slug3 = (s) => s.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^a-z0-9_-]+/g, "_").replace(/^_+|_+$/g, "") || "x";
|
|
7818
9370
|
function pageOptions(screen, auto) {
|
|
@@ -7836,6 +9388,7 @@ var HomeAssistantBridge = class {
|
|
|
7836
9388
|
onFrame = () => this.publishStates();
|
|
7837
9389
|
onConfig = (cfg) => this.apply(cfg);
|
|
7838
9390
|
onScreen = () => this.publishStates();
|
|
9391
|
+
onAlerts = () => this.publishStates();
|
|
7839
9392
|
runtime;
|
|
7840
9393
|
version;
|
|
7841
9394
|
makeClient;
|
|
@@ -7846,6 +9399,7 @@ var HomeAssistantBridge = class {
|
|
|
7846
9399
|
runtime.on("frame", this.onFrame);
|
|
7847
9400
|
runtime.on("config", this.onConfig);
|
|
7848
9401
|
runtime.on("screen", this.onScreen);
|
|
9402
|
+
runtime.on("alerts", this.onAlerts);
|
|
7849
9403
|
this.apply(runtime.config);
|
|
7850
9404
|
}
|
|
7851
9405
|
status() {
|
|
@@ -7856,6 +9410,7 @@ var HomeAssistantBridge = class {
|
|
|
7856
9410
|
this.runtime.off("frame", this.onFrame);
|
|
7857
9411
|
this.runtime.off("config", this.onConfig);
|
|
7858
9412
|
this.runtime.off("screen", this.onScreen);
|
|
9413
|
+
this.runtime.off("alerts", this.onAlerts);
|
|
7859
9414
|
this.disconnect();
|
|
7860
9415
|
}
|
|
7861
9416
|
get base() {
|
|
@@ -7893,7 +9448,7 @@ var HomeAssistantBridge = class {
|
|
|
7893
9448
|
if (this.client !== c) return;
|
|
7894
9449
|
this.last.clear();
|
|
7895
9450
|
c.publish(`${base3}/status`, "online", true);
|
|
7896
|
-
c.subscribe([`${base3}/+/page/set`, `${base3}/+/display/set`, `${base3}/+/interlude/+/press`, `${this.link.discoveryPrefix}/status`]);
|
|
9451
|
+
c.subscribe([`${base3}/+/page/set`, `${base3}/+/display/set`, `${base3}/+/interlude/+/press`, `${base3}/alerts/ack/press`, `${this.link.discoveryPrefix}/status`]);
|
|
7897
9452
|
this.announce();
|
|
7898
9453
|
});
|
|
7899
9454
|
c.on("message", (topic, payload) => this.client === c && this.onMessage(topic, payload));
|
|
@@ -7921,6 +9476,25 @@ var HomeAssistantBridge = class {
|
|
|
7921
9476
|
c.publish(topic, JSON.stringify(body2), true);
|
|
7922
9477
|
};
|
|
7923
9478
|
const availability = { availability_topic: `${this.base}/status` };
|
|
9479
|
+
const hub = { identifiers: [`kiosko_${node}`], name: "Kiosko", manufacturer: "Kiosko", model: "Kiosko", sw_version: this.version };
|
|
9480
|
+
put("sensor", "alert", {
|
|
9481
|
+
name: this.loc(NAMES.alert),
|
|
9482
|
+
unique_id: `kiosko_${node}_alert`,
|
|
9483
|
+
icon: "mdi:alert-octagon-outline",
|
|
9484
|
+
state_topic: `${this.base}/alerts/top`,
|
|
9485
|
+
json_attributes_topic: `${this.base}/alerts/attributes`,
|
|
9486
|
+
device: hub,
|
|
9487
|
+
...availability
|
|
9488
|
+
});
|
|
9489
|
+
put("button", "alerts_ack", {
|
|
9490
|
+
name: this.loc(NAMES.ack),
|
|
9491
|
+
unique_id: `kiosko_${node}_alerts_ack`,
|
|
9492
|
+
icon: "mdi:check-all",
|
|
9493
|
+
command_topic: `${this.base}/alerts/ack/press`,
|
|
9494
|
+
payload_press: "PRESS",
|
|
9495
|
+
device: hub,
|
|
9496
|
+
...availability
|
|
9497
|
+
});
|
|
7924
9498
|
for (const screen of cfg.screens) {
|
|
7925
9499
|
const sid = slug3(screen.id);
|
|
7926
9500
|
const device = {
|
|
@@ -7930,7 +9504,7 @@ var HomeAssistantBridge = class {
|
|
|
7930
9504
|
model: `${screen.width}\xD7${screen.height}`,
|
|
7931
9505
|
sw_version: this.version
|
|
7932
9506
|
};
|
|
7933
|
-
const id = (
|
|
9507
|
+
const id = (what2) => `kiosko_${node}_${sid}_${what2}`;
|
|
7934
9508
|
const { options: options2 } = pageOptions(screen, this.loc(AUTO));
|
|
7935
9509
|
put("select", `${sid}_page`, {
|
|
7936
9510
|
name: this.loc(NAMES.page),
|
|
@@ -7985,6 +9559,17 @@ var HomeAssistantBridge = class {
|
|
|
7985
9559
|
const c = this.client;
|
|
7986
9560
|
if (!c?.connected || !this.link) return;
|
|
7987
9561
|
const status = this.runtime.status();
|
|
9562
|
+
const alerts = this.runtime.listAlerts().filter((a) => !a.snoozedUntil);
|
|
9563
|
+
const top = alerts[0];
|
|
9564
|
+
const alertStates = [
|
|
9565
|
+
[`${this.base}/alerts/top`, top ? top.title.slice(0, 250) : "\u2014"],
|
|
9566
|
+
[`${this.base}/alerts/attributes`, JSON.stringify(top ? { level: top.level, text: top.text, ...top.source ? { source: top.source } : {}, ...top.detail ? { detail: top.detail } : {}, id: top.id, count: alerts.length, since: new Date(top.since).toISOString() } : { level: "none", count: 0 })]
|
|
9567
|
+
];
|
|
9568
|
+
for (const [topic, value] of alertStates) {
|
|
9569
|
+
if (this.last.get(topic) === value) continue;
|
|
9570
|
+
this.last.set(topic, value);
|
|
9571
|
+
c.publish(topic, value, true);
|
|
9572
|
+
}
|
|
7988
9573
|
for (const screen of this.runtime.config.screens) {
|
|
7989
9574
|
const sid = slug3(screen.id);
|
|
7990
9575
|
const st = status.screens.find((x) => x.id === screen.id);
|
|
@@ -8007,6 +9592,10 @@ var HomeAssistantBridge = class {
|
|
|
8007
9592
|
if (payload === "online") this.announce();
|
|
8008
9593
|
return;
|
|
8009
9594
|
}
|
|
9595
|
+
if (topic === `${this.base}/alerts/ack/press`) {
|
|
9596
|
+
this.runtime.ackAllAlerts();
|
|
9597
|
+
return;
|
|
9598
|
+
}
|
|
8010
9599
|
const m = new RegExp(`^${this.base.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/([^/]+)/(page/set|display/set|interlude/([^/]+)/press)$`).exec(topic);
|
|
8011
9600
|
if (!m) return;
|
|
8012
9601
|
const screen = this.runtime.config.screens.find((s) => slug3(s.id) === m[1]);
|
|
@@ -8039,10 +9628,10 @@ var MIME = {
|
|
|
8039
9628
|
".ico": "image/x-icon"
|
|
8040
9629
|
};
|
|
8041
9630
|
function webRoot() {
|
|
8042
|
-
const bundled =
|
|
8043
|
-
if (
|
|
9631
|
+
const bundled = join16(import.meta.dirname, "web");
|
|
9632
|
+
if (existsSync14(join16(bundled, "index.html"))) return bundled;
|
|
8044
9633
|
try {
|
|
8045
|
-
return
|
|
9634
|
+
return join16(dirname7(require3.resolve("@kiosko/web/package.json")), "dist");
|
|
8046
9635
|
} catch {
|
|
8047
9636
|
return resolve7(import.meta.dirname, "../../web/dist");
|
|
8048
9637
|
}
|
|
@@ -8055,8 +9644,8 @@ async function body(req, limit = 5 * 1024 * 1024) {
|
|
|
8055
9644
|
if (size > limit) throw new Error("body too large");
|
|
8056
9645
|
chunks.push(c);
|
|
8057
9646
|
}
|
|
8058
|
-
const
|
|
8059
|
-
return
|
|
9647
|
+
const text3 = Buffer.concat(chunks).toString("utf8");
|
|
9648
|
+
return text3 ? JSON.parse(text3) : {};
|
|
8060
9649
|
}
|
|
8061
9650
|
function json(res, status, data) {
|
|
8062
9651
|
const s = JSON.stringify(data);
|
|
@@ -8084,16 +9673,36 @@ function startServer(o) {
|
|
|
8084
9673
|
const checking = o.checkUpdates ?? (!runtime.demoMode && process.env.KIOSKO_NO_UPDATE_CHECK !== "1");
|
|
8085
9674
|
const updateTimers = checking ? [setTimeout(() => void refreshUpdates().catch(() => void 0), 2e4), setInterval(() => void refreshUpdates().catch(() => void 0), 24 * 36e5)] : [];
|
|
8086
9675
|
for (const t2 of updateTimers) t2.unref?.();
|
|
9676
|
+
const store = o.store ?? new StoreCatalog({ cacheDir: join16(paths.home, "store") });
|
|
9677
|
+
const storeTimers = checking ? [setTimeout(() => void store.refresh(), 15e3), setInterval(() => void store.refresh(), 24 * 36e5)] : [];
|
|
9678
|
+
for (const t2 of storeTimers) t2.unref?.();
|
|
9679
|
+
const installFromStore = async (p, version) => {
|
|
9680
|
+
const index = store.current().index;
|
|
9681
|
+
const release = p.releases.find((r) => r.version === version);
|
|
9682
|
+
const results = [];
|
|
9683
|
+
for (const need of p.requires) {
|
|
9684
|
+
if (runtime.registry.plugin(need)) continue;
|
|
9685
|
+
const dep = index.plugins.find((x) => x.id === need && !x.hidden);
|
|
9686
|
+
const r = dep && installableRelease(dep, { sdk: SDK_VERSION, platform: process.platform });
|
|
9687
|
+
if (dep && r) results.push(await installPlugin(`${dep.package}@${r.version}`, { registry: runtime.registry, runtime, expectIntegrity: r.integrity }));
|
|
9688
|
+
}
|
|
9689
|
+
results.push(await installPlugin(`${p.package}@${release.version}`, { registry: runtime.registry, runtime, expectIntegrity: release.integrity }));
|
|
9690
|
+
return results;
|
|
9691
|
+
};
|
|
8087
9692
|
let rev = Date.now();
|
|
8088
9693
|
const send = (event, data) => {
|
|
8089
9694
|
const line = `event: ${event}
|
|
8090
9695
|
data: ${JSON.stringify(data)}
|
|
8091
9696
|
|
|
8092
9697
|
`;
|
|
8093
|
-
for (const c of clients) c.write(line);
|
|
9698
|
+
for (const c of clients) if (!c.writableEnded && !c.destroyed) c.write(line);
|
|
8094
9699
|
};
|
|
8095
|
-
|
|
8096
|
-
|
|
9700
|
+
const onFrame = (f) => send("frame", { screenId: f.screenId, pageId: f.pageId, at: f.at, interlude: f.interlude, alert: f.alert ?? null, sleeping: f.sleeping, tiles: f.tiles });
|
|
9701
|
+
const onAlerts = (alerts) => send("alerts", alerts);
|
|
9702
|
+
const onLog = (e) => send("log", e);
|
|
9703
|
+
runtime.on("frame", onFrame);
|
|
9704
|
+
runtime.on("alerts", onAlerts);
|
|
9705
|
+
runtime.on("log", onLog);
|
|
8097
9706
|
runtime.on("config", () => thumbs.clear());
|
|
8098
9707
|
const bridge = o.homeassistant ?? !runtime.demoMode ? new HomeAssistantBridge(runtime, o.version) : null;
|
|
8099
9708
|
const fullStatus = () => ({ ...runtime.status(), homeassistant: bridge?.status() ?? { enabled: false, state: "off", error: null } });
|
|
@@ -8113,6 +9722,7 @@ data: ${JSON.stringify(data)}
|
|
|
8113
9722
|
themes: THEMES,
|
|
8114
9723
|
presets: PANEL_PRESETS,
|
|
8115
9724
|
status: fullStatus(),
|
|
9725
|
+
alerts: runtime.listAlerts(),
|
|
8116
9726
|
paths: { config: o.configPath, plugins: paths.plugins, home: paths.home },
|
|
8117
9727
|
restartNeeded,
|
|
8118
9728
|
official: OFFICIAL_PLUGINS,
|
|
@@ -8146,7 +9756,7 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
8146
9756
|
|
|
8147
9757
|
`);
|
|
8148
9758
|
clients.add(res);
|
|
8149
|
-
const ping = setInterval(() => res.write(": ping\n\n"), 2e4);
|
|
9759
|
+
const ping = setInterval(() => !res.writableEnded && !res.destroyed && res.write(": ping\n\n"), 2e4);
|
|
8150
9760
|
req.on("close", () => {
|
|
8151
9761
|
clearInterval(ping);
|
|
8152
9762
|
clients.delete(res);
|
|
@@ -8157,7 +9767,7 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
8157
9767
|
if (mm && m === "GET") {
|
|
8158
9768
|
const f = runtime.lastFrame(decodeURIComponent(mm[1]));
|
|
8159
9769
|
if (!f) return json(res, 404, { error: "no frame yet", code: "noFrame" });
|
|
8160
|
-
const buf = f.image();
|
|
9770
|
+
const buf = await f.image();
|
|
8161
9771
|
res.writeHead(200, { "content-type": "image/jpeg", "cache-control": "no-store", "content-length": String(buf.length), "x-kiosko-at": String(f.at) });
|
|
8162
9772
|
return void res.end(buf);
|
|
8163
9773
|
}
|
|
@@ -8195,9 +9805,52 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
8195
9805
|
if (mm && m === "POST") {
|
|
8196
9806
|
const b = await body(req);
|
|
8197
9807
|
if (b.stop) runtime.stopInterlude(decodeURIComponent(mm[1]));
|
|
8198
|
-
else if (b.slotId) runtime.playInterlude(decodeURIComponent(mm[1]), b.slotId);
|
|
9808
|
+
else if (b.slotId) runtime.playInterlude(decodeURIComponent(mm[1]), b.slotId, !!b.play);
|
|
8199
9809
|
return json(res, 200, { ok: true });
|
|
8200
9810
|
}
|
|
9811
|
+
mm = /^\/api\/screens\/([^/]+)\/input$/.exec(p);
|
|
9812
|
+
if (mm && m === "POST") {
|
|
9813
|
+
const b = await body(req);
|
|
9814
|
+
const events = b.events ?? (b.key ? [{ key: b.key, pressed: !!b.pressed }] : []);
|
|
9815
|
+
let taken = false;
|
|
9816
|
+
for (const e of events.slice(0, 32)) taken = runtime.press(decodeURIComponent(mm[1]), e) || taken;
|
|
9817
|
+
return json(res, 200, { ok: true, playing: taken });
|
|
9818
|
+
}
|
|
9819
|
+
if (p === "/api/alerts" && m === "GET") return json(res, 200, { alerts: runtime.listAlerts() });
|
|
9820
|
+
if (p === "/api/alerts" && m === "POST") {
|
|
9821
|
+
try {
|
|
9822
|
+
return json(res, 200, { ok: true, alert: runtime.postAlert(await body(req, 64 * 1024)) });
|
|
9823
|
+
} catch (err) {
|
|
9824
|
+
if (err instanceof AlertError || err instanceof SyntaxError) return json(res, 400, { error: err.message, code: "badAlert" });
|
|
9825
|
+
throw err;
|
|
9826
|
+
}
|
|
9827
|
+
}
|
|
9828
|
+
mm = /^\/api\/alerts\/([^/]+)(?:\/(ack|snooze))?$/.exec(p);
|
|
9829
|
+
if (mm && (m === "POST" || m === "DELETE")) {
|
|
9830
|
+
const id = decodeURIComponent(mm[1]);
|
|
9831
|
+
const what2 = mm[2];
|
|
9832
|
+
if (m === "DELETE" && !what2) return runtime.removeAlert(id) ? json(res, 200, { ok: true }) : json(res, 404, { error: "no such alert from outside", code: "unknownAlert", params: { id } });
|
|
9833
|
+
if (m === "POST" && what2) {
|
|
9834
|
+
let r;
|
|
9835
|
+
if (what2 === "ack") r = runtime.ackAlert(id);
|
|
9836
|
+
else {
|
|
9837
|
+
const b = await body(req, 4096);
|
|
9838
|
+
const minutes2 = Number(b.minutes);
|
|
9839
|
+
r = runtime.snoozeAlert(id, Number.isFinite(minutes2) && minutes2 > 0 ? Math.min(1440, minutes2) * 6e4 : DEFAULT_SNOOZE_MS);
|
|
9840
|
+
}
|
|
9841
|
+
if (r === "unknown") return json(res, 404, { error: "no such alert", code: "unknownAlert", params: { id } });
|
|
9842
|
+
if (r === "notDismissible") return json(res, 409, { error: "this alert cannot be dismissed", code: "notDismissible", params: { id } });
|
|
9843
|
+
return json(res, 200, { ok: true, alerts: runtime.listAlerts() });
|
|
9844
|
+
}
|
|
9845
|
+
}
|
|
9846
|
+
mm = /^\/api\/screens\/([^/]+)\/test-alert$/.exec(p);
|
|
9847
|
+
if (mm && m === "POST") {
|
|
9848
|
+
const b = await body(req, 4096);
|
|
9849
|
+
const level = ALERT_LEVELS.includes(b.level) ? b.level : "critical";
|
|
9850
|
+
const a = runtime.testAlert(decodeURIComponent(mm[1]), level);
|
|
9851
|
+
if (!a) return json(res, 404, { error: "unknown screen", code: "unknownScreen" });
|
|
9852
|
+
return json(res, 200, { ok: true, alert: a });
|
|
9853
|
+
}
|
|
8201
9854
|
mm = /^\/api\/widgets\/([^/]+)\/refresh$/.exec(p);
|
|
8202
9855
|
if (mm && m === "POST") {
|
|
8203
9856
|
runtime.refreshWidget(decodeURIComponent(mm[1]));
|
|
@@ -8226,6 +9879,51 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
8226
9879
|
return json(res, /valid npm/.test(String(err)) ? 400 : 500, { error: err instanceof Error ? err.message : String(err) });
|
|
8227
9880
|
}
|
|
8228
9881
|
}
|
|
9882
|
+
if (p === "/api/store" && m === "GET") {
|
|
9883
|
+
const st = store.current();
|
|
9884
|
+
return json(res, 200, {
|
|
9885
|
+
index: st.index && { ...st.index, plugins: st.index.plugins.filter((x) => !x.hidden) },
|
|
9886
|
+
from: st.from,
|
|
9887
|
+
fetchedAt: st.fetchedAt,
|
|
9888
|
+
error: st.error,
|
|
9889
|
+
url: store.url,
|
|
9890
|
+
online: checking,
|
|
9891
|
+
sdk: SDK_VERSION,
|
|
9892
|
+
platform: process.platform,
|
|
9893
|
+
installed: Object.fromEntries(runtime.registry.list().map(({ def }) => [def.id, def.version]))
|
|
9894
|
+
});
|
|
9895
|
+
}
|
|
9896
|
+
if (p === "/api/store/refresh" && m === "POST") {
|
|
9897
|
+
const st = await store.refresh();
|
|
9898
|
+
return json(res, st.error && st.from !== "network" ? 502 : 200, { from: st.from, fetchedAt: st.fetchedAt, error: st.error });
|
|
9899
|
+
}
|
|
9900
|
+
mm = /^\/api\/store\/([a-z0-9-]+)$/.exec(p);
|
|
9901
|
+
if (mm && m === "GET") {
|
|
9902
|
+
const sheet = await store.sheet(mm[1]);
|
|
9903
|
+
return sheet ? json(res, 200, sheet) : json(res, 404, { error: `no "${mm[1]}" in the store`, code: "notInStore", params: { id: mm[1] } });
|
|
9904
|
+
}
|
|
9905
|
+
if (p === "/api/store/install" && m === "POST") {
|
|
9906
|
+
const b = await body(req, 4096);
|
|
9907
|
+
const id = String(b.id ?? "");
|
|
9908
|
+
const sp = store.current().index?.plugins.find((x) => x.id === id && !x.hidden);
|
|
9909
|
+
if (!sp) return json(res, 404, { error: `no "${id}" in the store`, code: "notInStore", params: { id } });
|
|
9910
|
+
const release = sp.releases.find((r) => r.version === b.version);
|
|
9911
|
+
if (!release) return json(res, 409, { error: `${sp.package} has no release ${String(b.version)} in the store`, code: "noRelease", params: { id, version: String(b.version) } });
|
|
9912
|
+
if (release.withdrawn) return json(res, 409, { error: `${sp.package}@${release.version} was withdrawn`, code: "withdrawn", params: { id, version: release.version } });
|
|
9913
|
+
const why = releaseProblem({ sdk: release.sdk, platforms: release.platforms ?? sp.platforms }, { sdk: SDK_VERSION, platform: process.platform });
|
|
9914
|
+
if (why) return json(res, 409, { error: why.code === "sdk" ? `written for the plugin API ${why.range}; this Kiosko has ${SDK_VERSION}` : `works on ${why.platforms.join(", ")}, not ${process.platform}`, code: "cantInstall", params: { id } });
|
|
9915
|
+
if (sp.tier === "found" && b.acceptRisk !== true) return json(res, 409, { error: `${sp.package} is unreviewed: confirm you accept the risk`, code: "acceptRisk", params: { id } });
|
|
9916
|
+
try {
|
|
9917
|
+
const results = await installFromStore(sp, release.version);
|
|
9918
|
+
if (results.some((r) => r.restart)) restartNeeded = true;
|
|
9919
|
+
rev++;
|
|
9920
|
+
send("config", { rev, by: null });
|
|
9921
|
+
const problem = results.map((r) => r.problem).filter(Boolean).join("; ") || null;
|
|
9922
|
+
return json(res, 200, { ok: !problem, ids: results.flatMap((r) => r.ids), problem, rolledBack: results.some((r) => r.rolledBack), addedPermissions: results.at(-1)?.addedPermissions ?? null, version: release.version, restartNeeded, state: state() });
|
|
9923
|
+
} catch (err) {
|
|
9924
|
+
return json(res, err instanceof IntegrityError ? 409 : 500, { error: err instanceof Error ? err.message : String(err), ...err instanceof IntegrityError ? { code: "integrity", params: { id } } : {} });
|
|
9925
|
+
}
|
|
9926
|
+
}
|
|
8229
9927
|
mm = /^\/api\/plugins\/([^/]+)$/.exec(p);
|
|
8230
9928
|
if (mm && m === "DELETE") {
|
|
8231
9929
|
const id = decodeURIComponent(mm[1]);
|
|
@@ -8299,16 +9997,16 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
8299
9997
|
}
|
|
8300
9998
|
function serveStatic(res, pathname) {
|
|
8301
9999
|
const rel = normPath(decodeURIComponent(pathname)).replace(/^([/\\])+/, "");
|
|
8302
|
-
let file =
|
|
10000
|
+
let file = join16(root, rel || "index.html");
|
|
8303
10001
|
if (!file.startsWith(root)) return void json(res, 400, { error: "bad path" });
|
|
8304
|
-
if (!
|
|
8305
|
-
if (!
|
|
10002
|
+
if (!existsSync14(file) || statSync3(file).isDirectory()) file = join16(root, "index.html");
|
|
10003
|
+
if (!existsSync14(file)) {
|
|
8306
10004
|
res.writeHead(500, { "content-type": "text/plain" });
|
|
8307
10005
|
return void res.end("The editor is not built. Run `npm run web:build`.");
|
|
8308
10006
|
}
|
|
8309
10007
|
const ext = extname(file);
|
|
8310
10008
|
res.writeHead(200, { "content-type": MIME[ext] ?? "application/octet-stream", "cache-control": ext === ".html" ? "no-cache" : "max-age=300" });
|
|
8311
|
-
res.end(
|
|
10009
|
+
res.end(readFileSync8(file));
|
|
8312
10010
|
}
|
|
8313
10011
|
const server = createServer((req, res) => {
|
|
8314
10012
|
const host = req.headers.host ?? "";
|
|
@@ -8336,7 +10034,12 @@ data: ${JSON.stringify({ version: o.version })}
|
|
|
8336
10034
|
clearInterval(statusTimer);
|
|
8337
10035
|
bridge?.stop();
|
|
8338
10036
|
for (const t2 of updateTimers) clearTimeout(t2);
|
|
10037
|
+
for (const t2 of storeTimers) clearTimeout(t2);
|
|
10038
|
+
runtime.off("frame", onFrame);
|
|
10039
|
+
runtime.off("alerts", onAlerts);
|
|
10040
|
+
runtime.off("log", onLog);
|
|
8339
10041
|
for (const c of clients) c.end();
|
|
10042
|
+
clients.clear();
|
|
8340
10043
|
server.close();
|
|
8341
10044
|
}
|
|
8342
10045
|
};
|
|
@@ -8379,7 +10082,7 @@ function starterConfig(registry2, o = {}) {
|
|
|
8379
10082
|
}
|
|
8380
10083
|
|
|
8381
10084
|
// packages/server/src/cli.ts
|
|
8382
|
-
var VERSION = "0.2.
|
|
10085
|
+
var VERSION = "0.2.7";
|
|
8383
10086
|
var USAGE2 = `Kiosko ${VERSION}: a widget mosaic for USB LCD panels
|
|
8384
10087
|
|
|
8385
10088
|
kiosko start [--port 7420] [--host 127.0.0.1] [--config file] [--open] [--demo]
|
|
@@ -8404,6 +10107,8 @@ var opt = (name) => {
|
|
|
8404
10107
|
const i = argv.indexOf(name);
|
|
8405
10108
|
return i >= 0 ? argv[i + 1] : void 0;
|
|
8406
10109
|
};
|
|
10110
|
+
var SCREEN_THREAD = ["./screen-thread.js", "./screen-thread.ts"].map((f) => new URL(f, import.meta.url)).find((u) => existsSync15(u));
|
|
10111
|
+
var THREADS = SCREEN_THREAD ? { threadEntry: SCREEN_THREAD } : {};
|
|
8407
10112
|
async function registry() {
|
|
8408
10113
|
installSdkResolver();
|
|
8409
10114
|
const r = new Registry();
|
|
@@ -8412,8 +10117,9 @@ async function registry() {
|
|
|
8412
10117
|
for (const o of OFFICIAL_PLUGINS) {
|
|
8413
10118
|
if (r.plugin(o.id)) continue;
|
|
8414
10119
|
try {
|
|
8415
|
-
const
|
|
8416
|
-
|
|
10120
|
+
const url2 = import.meta.resolve(o.npm);
|
|
10121
|
+
const mod = await import(url2);
|
|
10122
|
+
if (mod.default) r.add(mod.default, `npm:${o.npm}`, url2);
|
|
8417
10123
|
} catch {
|
|
8418
10124
|
}
|
|
8419
10125
|
}
|
|
@@ -8447,7 +10153,7 @@ async function main() {
|
|
|
8447
10153
|
const cfg = await config(reg, path);
|
|
8448
10154
|
const host = opt("--host") ?? cfg.server.host;
|
|
8449
10155
|
const port = Number(opt("--port") ?? cfg.server.port);
|
|
8450
|
-
const rt = new Runtime(reg, cfg, { demo: flag("--demo") });
|
|
10156
|
+
const rt = new Runtime(reg, cfg, { demo: flag("--demo"), ...THREADS });
|
|
8451
10157
|
if (flag("--demo")) console.log("demo mode: every widget shows sample data, nothing is read");
|
|
8452
10158
|
rt.start();
|
|
8453
10159
|
const srv = startServer({ runtime: rt, host, port, configPath: path, version: VERSION });
|
|
@@ -8479,7 +10185,7 @@ async function main() {
|
|
|
8479
10185
|
const screen = cfg.screens.find((s) => !want || s.id === want || s.name === want) ?? starterConfig(reg).screens[0];
|
|
8480
10186
|
const wantPage = opt("--page");
|
|
8481
10187
|
const page = screen.pages.find((p) => !wantPage || p.id === wantPage || p.name === wantPage) ?? screen.pages[0];
|
|
8482
|
-
const rt = new Runtime(reg, cfg);
|
|
10188
|
+
const rt = new Runtime(reg, cfg, THREADS);
|
|
8483
10189
|
if (flag("--live")) {
|
|
8484
10190
|
rt.apply(cfg);
|
|
8485
10191
|
const until = Date.now() + Number(opt("--wait") ?? 4e3);
|
|
@@ -8498,20 +10204,20 @@ async function main() {
|
|
|
8498
10204
|
}
|
|
8499
10205
|
case "import-aimonitor": {
|
|
8500
10206
|
const from = opt("--from") ?? `${process.env.HOME ?? ""}/.aimonitor/config.json`;
|
|
8501
|
-
if (!
|
|
10207
|
+
if (!existsSync15(from)) {
|
|
8502
10208
|
console.error(`not found: ${from}`);
|
|
8503
10209
|
process.exit(1);
|
|
8504
10210
|
}
|
|
8505
10211
|
const reg = await registry();
|
|
8506
|
-
const modePath =
|
|
8507
|
-
const modeOverride =
|
|
8508
|
-
const { config: imported, notes } = importAimonitor(JSON.parse(
|
|
10212
|
+
const modePath = join17(dirname8(from), "modo");
|
|
10213
|
+
const modeOverride = existsSync15(modePath) ? readFileSync9(modePath, "utf8") : null;
|
|
10214
|
+
const { config: imported, notes } = importAimonitor(JSON.parse(readFileSync9(from, "utf8")), reg, modeOverride, { withSecrets: flag("--with-secrets") });
|
|
8509
10215
|
if (modeOverride) notes.push(`mode from ${modePath}: ${modeOverride.trim()}`);
|
|
8510
10216
|
for (const n of notes) console.log(`- ${n}`);
|
|
8511
10217
|
if (flag("--write")) {
|
|
8512
|
-
if (
|
|
10218
|
+
if (existsSync15(path)) writeFileSync12(`${path}.bak`, readFileSync9(path));
|
|
8513
10219
|
saveConfig(imported, path);
|
|
8514
|
-
console.log(`written ${path}${
|
|
10220
|
+
console.log(`written ${path}${existsSync15(`${path}.bak`) ? ` (previous one in ${path}.bak)` : ""}`);
|
|
8515
10221
|
} else {
|
|
8516
10222
|
console.log(JSON.stringify(imported, null, 2));
|
|
8517
10223
|
console.log("\n(dry run: add --write to save it)");
|
|
@@ -8527,7 +10233,7 @@ async function main() {
|
|
|
8527
10233
|
const screen = cfg.screens[0];
|
|
8528
10234
|
screen.device = { driver: "usb", ...opt("--serial") ? { serial: opt("--serial") } : {} };
|
|
8529
10235
|
screen.rotate = Number(opt("--rotate") ?? 0);
|
|
8530
|
-
const rt = new Runtime(reg, cfg, { demo: true });
|
|
10236
|
+
const rt = new Runtime(reg, cfg, { demo: true, ...THREADS });
|
|
8531
10237
|
rt.start();
|
|
8532
10238
|
const seconds = Number(opt("--seconds") ?? 10);
|
|
8533
10239
|
let ok = false;
|
|
@@ -8581,7 +10287,7 @@ async function main() {
|
|
|
8581
10287
|
const reg = await registry();
|
|
8582
10288
|
const out = opt("--out") ?? "gallery";
|
|
8583
10289
|
const sample = opt("--pages");
|
|
8584
|
-
const n = buildGallery(reg, { out, locale: opt("--locale") ?? "en", languages: flag("--all-languages"), theme: opt("--theme") ?? "midnight", ...sample ? { pages: JSON.parse(
|
|
10290
|
+
const n = buildGallery(reg, { out, locale: opt("--locale") ?? "en", languages: flag("--all-languages"), theme: opt("--theme") ?? "midnight", ...sample ? { pages: JSON.parse(readFileSync9(sample, "utf8")) } : {} });
|
|
8585
10291
|
console.log(`${n} widgets \u2192 ${out}/index.html`);
|
|
8586
10292
|
return;
|
|
8587
10293
|
}
|