key-screen-framework 1.1.0 → 1.2.1
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/chunks/screen-overrides-0d_pEdnM.js +110 -0
- package/chunks/{store-txJwmrlO.js → store-WzFy0ShX.js} +65 -3
- package/chunks/{useArduinoBuild-CVr4XAsL.js → useArduinoBuild-CFMmNokt.js} +1 -1
- package/cli/generate-screen.mjs +24 -7
- package/cli/screen-generation-renderers.mjs +10 -6
- package/cli/screen-module-utils.mjs +22 -5
- package/main/index.js +65 -24
- package/package.json +1 -1
- package/preload/index.js +5 -0
- package/renderer/components/VideoSceneScreen.js +59 -3
- package/renderer/hooks/index.js +1 -1
- package/renderer/index.js +1062 -752
- package/renderer/store.js +1 -1
- package/renderer/styles.css +17 -0
- package/shared/index.js +2 -0
- package/shared/types.js +4 -1
- package/templates/project/README.md +87 -17
- package/types/main/media-manager.d.ts +1 -0
- package/types/renderer/src/components/VideoSceneScreen.d.ts +9 -2
- package/types/renderer/src/screen-types.d.ts +1 -1
- package/types/renderer/src/store.d.ts +8 -1
- package/types/shared/display-settings.d.ts +3 -0
- package/types/shared/screen-overrides.d.ts +11 -0
- package/types/shared/types.d.ts +26 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { ADMIN_ZOOM_LEVELS } from "../shared/types.js";
|
|
2
|
+
function normalizeDisplayFit(value, fallback = "contain") {
|
|
3
|
+
return value === "fill" || value === "contain" ? value : fallback;
|
|
4
|
+
}
|
|
5
|
+
function normalizeAdminZoom(value) {
|
|
6
|
+
return ADMIN_ZOOM_LEVELS.includes(value) ? value : 100;
|
|
7
|
+
}
|
|
8
|
+
const VIDEO_EXTENSIONS = /* @__PURE__ */ new Set([".m4v", ".mov", ".mp4", ".ogg", ".ogv", ".webm"]);
|
|
9
|
+
function normalizeLoopCount(value) {
|
|
10
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 1) {
|
|
11
|
+
throw new Error("Screen loop count must be a finite number greater than or equal to 1.");
|
|
12
|
+
}
|
|
13
|
+
return Math.floor(value);
|
|
14
|
+
}
|
|
15
|
+
function normalizeVideoFileName(value) {
|
|
16
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
17
|
+
throw new Error("Screen video file name is required.");
|
|
18
|
+
}
|
|
19
|
+
const fileName = value.trim();
|
|
20
|
+
if (fileName.includes("/") || fileName.includes("\\")) {
|
|
21
|
+
throw new Error("Screen video must be a file name without path separators.");
|
|
22
|
+
}
|
|
23
|
+
const extensionIndex = fileName.lastIndexOf(".");
|
|
24
|
+
const extension = extensionIndex >= 0 ? fileName.slice(extensionIndex).toLowerCase() : "";
|
|
25
|
+
if (!VIDEO_EXTENSIONS.has(extension)) {
|
|
26
|
+
throw new Error(`Unsupported screen video extension: ${extension || "(none)"}`);
|
|
27
|
+
}
|
|
28
|
+
return fileName;
|
|
29
|
+
}
|
|
30
|
+
function mergeScreenOverrides(screens, overrides) {
|
|
31
|
+
return screens.map((screen) => ({ ...screen, ...overrides[screen.id] ?? {} }));
|
|
32
|
+
}
|
|
33
|
+
function normalizeScreenOverrides(overrides, baseScreens) {
|
|
34
|
+
if (!overrides || typeof overrides !== "object" || Array.isArray(overrides)) {
|
|
35
|
+
throw new Error("Screen overrides must be an object.");
|
|
36
|
+
}
|
|
37
|
+
const baseById = new Map(baseScreens.map((screen) => [screen.id, screen]));
|
|
38
|
+
const normalized = {};
|
|
39
|
+
for (const [id, input] of Object.entries(overrides)) {
|
|
40
|
+
const base = baseById.get(id);
|
|
41
|
+
if (!base || base.kind !== "scene") {
|
|
42
|
+
throw new Error(`Screen override target does not exist: ${id}`);
|
|
43
|
+
}
|
|
44
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) {
|
|
45
|
+
throw new Error(`Invalid screen override: ${id}`);
|
|
46
|
+
}
|
|
47
|
+
const entry = {};
|
|
48
|
+
if (input.title !== void 0) {
|
|
49
|
+
if (typeof input.title !== "string" || !input.title.trim()) {
|
|
50
|
+
throw new Error(`Screen title is required: ${id}`);
|
|
51
|
+
}
|
|
52
|
+
const title = input.title.trim();
|
|
53
|
+
if (title !== base.title) entry.title = title;
|
|
54
|
+
}
|
|
55
|
+
if (input.video !== void 0) {
|
|
56
|
+
const video = normalizeVideoFileName(input.video);
|
|
57
|
+
if (video !== base.video) entry.video = video;
|
|
58
|
+
}
|
|
59
|
+
if (input.loop !== void 0 && typeof input.loop !== "boolean") {
|
|
60
|
+
throw new Error(`Screen loop must be a boolean: ${id}`);
|
|
61
|
+
}
|
|
62
|
+
const loop = input.loop ?? base.loop ?? false;
|
|
63
|
+
if (input.loop !== void 0 && loop !== (base.loop ?? false)) entry.loop = loop;
|
|
64
|
+
if (!loop && input.loopCount !== void 0) {
|
|
65
|
+
const loopCount = normalizeLoopCount(input.loopCount);
|
|
66
|
+
if (loopCount !== (base.loopCount ?? 1)) entry.loopCount = loopCount;
|
|
67
|
+
}
|
|
68
|
+
if (Object.keys(entry).length > 0) normalized[id] = entry;
|
|
69
|
+
}
|
|
70
|
+
return normalized;
|
|
71
|
+
}
|
|
72
|
+
function normalizeStoredScreenOverrides(overrides, baseScreens) {
|
|
73
|
+
if (!overrides || typeof overrides !== "object" || Array.isArray(overrides)) return {};
|
|
74
|
+
const baseById = new Map(baseScreens.map((screen) => [screen.id, screen]));
|
|
75
|
+
const recovered = {};
|
|
76
|
+
for (const [id, value] of Object.entries(overrides)) {
|
|
77
|
+
const base = baseById.get(id);
|
|
78
|
+
if (!base || base.kind !== "scene" || !value || typeof value !== "object" || Array.isArray(value)) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const input = value;
|
|
82
|
+
const candidate = {};
|
|
83
|
+
if (typeof input.title === "string" && input.title.trim()) {
|
|
84
|
+
candidate.title = input.title;
|
|
85
|
+
}
|
|
86
|
+
if (input.video !== void 0) {
|
|
87
|
+
try {
|
|
88
|
+
candidate.video = normalizeVideoFileName(input.video);
|
|
89
|
+
} catch {
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (typeof input.loop === "boolean") candidate.loop = input.loop;
|
|
93
|
+
if (input.loopCount !== void 0) {
|
|
94
|
+
try {
|
|
95
|
+
candidate.loopCount = normalizeLoopCount(input.loopCount);
|
|
96
|
+
} catch {
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const normalized = normalizeScreenOverrides({ [id]: candidate }, baseScreens);
|
|
100
|
+
if (normalized[id]) recovered[id] = normalized[id];
|
|
101
|
+
}
|
|
102
|
+
return recovered;
|
|
103
|
+
}
|
|
104
|
+
export {
|
|
105
|
+
normalizeDisplayFit as a,
|
|
106
|
+
normalizeScreenOverrides as b,
|
|
107
|
+
normalizeStoredScreenOverrides as c,
|
|
108
|
+
mergeScreenOverrides as m,
|
|
109
|
+
normalizeAdminZoom as n
|
|
110
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { create } from "zustand";
|
|
2
2
|
import { validateArduinoBoardConfig, defaultArduinoBoardConfig } from "../shared/arduino-board.js";
|
|
3
3
|
import { buildDefaultGlobalShortcuts, normalizeShortcutAccelerator, mergeGlobalShortcuts } from "../shared/screen-shortcuts.js";
|
|
4
|
+
import { n as normalizeAdminZoom, a as normalizeDisplayFit, b as normalizeScreenOverrides, m as mergeScreenOverrides } from "./screen-overrides-0d_pEdnM.js";
|
|
4
5
|
const now = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
5
6
|
const FALLBACK_ADMIN_SCREEN = {
|
|
6
7
|
id: "admin",
|
|
@@ -17,6 +18,7 @@ function configureRendererPreview(screenDefinitions) {
|
|
|
17
18
|
fallbackScreenDefinitions = screenDefinitions.length > 0 ? screenDefinitions.map((screen) => ({ ...screen })) : [FALLBACK_ADMIN_SCREEN];
|
|
18
19
|
fallbackDefaultGlobalShortcuts = buildDefaultGlobalShortcuts(fallbackScreenDefinitions);
|
|
19
20
|
fallbackGlobalShortcuts = [];
|
|
21
|
+
fallbackScreenOverrides = {};
|
|
20
22
|
}
|
|
21
23
|
const fallbackDeviceState = () => ({
|
|
22
24
|
status: "disconnected",
|
|
@@ -42,12 +44,15 @@ const fallbackPerformanceSnapshot = () => ({
|
|
|
42
44
|
appMetrics: []
|
|
43
45
|
});
|
|
44
46
|
let fallbackGlobalShortcuts = [];
|
|
47
|
+
let fallbackScreenOverrides = {};
|
|
45
48
|
let fallbackArduinoBoardConfig = defaultArduinoBoardConfig();
|
|
46
49
|
const fallbackArduinoBuildStatus = {
|
|
47
50
|
phase: "idle",
|
|
48
51
|
updatedAt: now()
|
|
49
52
|
};
|
|
50
53
|
let fallbackWindowMode = "windowed";
|
|
54
|
+
let fallbackDisplayFit = "contain";
|
|
55
|
+
let fallbackAdminZoom = 100;
|
|
51
56
|
const fallbackApi = {
|
|
52
57
|
listPorts: async () => [],
|
|
53
58
|
listDeviceLogArchives: async () => [],
|
|
@@ -61,7 +66,7 @@ const fallbackApi = {
|
|
|
61
66
|
}),
|
|
62
67
|
getDeviceState: async () => fallbackDeviceState(),
|
|
63
68
|
getGameState: async () => fallbackGameState(),
|
|
64
|
-
getAvailableScreens: async () => fallbackScreenDefinitions
|
|
69
|
+
getAvailableScreens: async () => mergeScreenOverrides(fallbackScreenDefinitions, fallbackScreenOverrides),
|
|
65
70
|
getMediaLibrary: async () => ({
|
|
66
71
|
rootPath: "preview",
|
|
67
72
|
assets: []
|
|
@@ -86,6 +91,10 @@ const fallbackApi = {
|
|
|
86
91
|
).map((shortcut) => ({ ...shortcut }));
|
|
87
92
|
return mergeGlobalShortcuts(fallbackGlobalShortcuts, fallbackDefaultGlobalShortcuts);
|
|
88
93
|
},
|
|
94
|
+
updateScreenOverrides: async (overrides) => {
|
|
95
|
+
fallbackScreenOverrides = normalizeScreenOverrides(overrides, fallbackScreenDefinitions);
|
|
96
|
+
return mergeScreenOverrides(fallbackScreenDefinitions, fallbackScreenOverrides);
|
|
97
|
+
},
|
|
89
98
|
getArduinoBoardConfig: async () => fallbackArduinoBoardConfig,
|
|
90
99
|
updateArduinoBoardConfig: async (config) => {
|
|
91
100
|
fallbackArduinoBoardConfig = validateArduinoBoardConfig(config);
|
|
@@ -122,6 +131,16 @@ const fallbackApi = {
|
|
|
122
131
|
fallbackWindowMode = mode;
|
|
123
132
|
return fallbackWindowMode;
|
|
124
133
|
},
|
|
134
|
+
getDisplayFit: async () => fallbackDisplayFit,
|
|
135
|
+
setDisplayFit: async (mode) => {
|
|
136
|
+
fallbackDisplayFit = normalizeDisplayFit(mode);
|
|
137
|
+
return fallbackDisplayFit;
|
|
138
|
+
},
|
|
139
|
+
getAdminZoom: async () => fallbackAdminZoom,
|
|
140
|
+
setAdminZoom: async (level) => {
|
|
141
|
+
fallbackAdminZoom = normalizeAdminZoom(level);
|
|
142
|
+
return fallbackAdminZoom;
|
|
143
|
+
},
|
|
125
144
|
moveToScreen: async (target) => ({
|
|
126
145
|
mode: "running",
|
|
127
146
|
currentStepId: target,
|
|
@@ -165,6 +184,8 @@ const useAppStore = create((set) => ({
|
|
|
165
184
|
deviceSignalTargets: [],
|
|
166
185
|
windowMode: "windowed",
|
|
167
186
|
windowModeLocked: false,
|
|
187
|
+
displayFit: "contain",
|
|
188
|
+
adminZoom: 100,
|
|
168
189
|
loading: false,
|
|
169
190
|
setLoading: (loading) => set({ loading }),
|
|
170
191
|
setPorts: (ports) => set({ ports }),
|
|
@@ -176,6 +197,8 @@ const useAppStore = create((set) => ({
|
|
|
176
197
|
setDeviceSignalTargets: (deviceSignalTargets) => set({ deviceSignalTargets }),
|
|
177
198
|
setWindowMode: (windowMode) => set({ windowMode }),
|
|
178
199
|
setWindowModeLocked: (windowModeLocked) => set({ windowModeLocked }),
|
|
200
|
+
setDisplayFit: (displayFit) => set({ displayFit }),
|
|
201
|
+
setAdminZoom: (adminZoom) => set({ adminZoom }),
|
|
179
202
|
bootstrap: async () => {
|
|
180
203
|
set({ loading: true });
|
|
181
204
|
const gameApi = getGameApi();
|
|
@@ -188,7 +211,9 @@ const useAppStore = create((set) => ({
|
|
|
188
211
|
arduinoBoardConfig,
|
|
189
212
|
deviceSignalTargets,
|
|
190
213
|
windowMode,
|
|
191
|
-
windowModeLocked
|
|
214
|
+
windowModeLocked,
|
|
215
|
+
displayFit,
|
|
216
|
+
adminZoom
|
|
192
217
|
] = await Promise.all([
|
|
193
218
|
gameApi.listPorts(),
|
|
194
219
|
gameApi.getDeviceState(),
|
|
@@ -198,7 +223,9 @@ const useAppStore = create((set) => ({
|
|
|
198
223
|
gameApi.getArduinoBoardConfig(),
|
|
199
224
|
gameApi.getDeviceSignalTargets(),
|
|
200
225
|
gameApi.getWindowMode(),
|
|
201
|
-
gameApi.isWindowModeLocked()
|
|
226
|
+
gameApi.isWindowModeLocked(),
|
|
227
|
+
gameApi.getDisplayFit(),
|
|
228
|
+
gameApi.getAdminZoom()
|
|
202
229
|
]);
|
|
203
230
|
set({
|
|
204
231
|
ports,
|
|
@@ -208,6 +235,8 @@ const useAppStore = create((set) => ({
|
|
|
208
235
|
deviceSignalTargets,
|
|
209
236
|
windowMode,
|
|
210
237
|
windowModeLocked,
|
|
238
|
+
displayFit,
|
|
239
|
+
adminZoom,
|
|
211
240
|
deviceState,
|
|
212
241
|
gameState,
|
|
213
242
|
loading: false
|
|
@@ -241,6 +270,17 @@ const useAppStore = create((set) => ({
|
|
|
241
270
|
throw new Error("Failed to update global shortcuts.");
|
|
242
271
|
}
|
|
243
272
|
},
|
|
273
|
+
updateScreenOverrides: async (overrides) => {
|
|
274
|
+
set({ loading: true });
|
|
275
|
+
try {
|
|
276
|
+
const screens = await getGameApi().updateScreenOverrides(overrides);
|
|
277
|
+
set({ screens, loading: false });
|
|
278
|
+
} catch {
|
|
279
|
+
const screens = await getGameApi().getAvailableScreens();
|
|
280
|
+
set({ screens, loading: false });
|
|
281
|
+
throw new Error("Failed to update screen overrides.");
|
|
282
|
+
}
|
|
283
|
+
},
|
|
244
284
|
updateArduinoBoardConfig: async (config) => {
|
|
245
285
|
set({ loading: true });
|
|
246
286
|
try {
|
|
@@ -263,6 +303,28 @@ const useAppStore = create((set) => ({
|
|
|
263
303
|
throw new Error("Failed to update window mode.");
|
|
264
304
|
}
|
|
265
305
|
},
|
|
306
|
+
updateDisplayFit: async (mode) => {
|
|
307
|
+
set({ loading: true });
|
|
308
|
+
try {
|
|
309
|
+
const displayFit = await getGameApi().setDisplayFit(mode);
|
|
310
|
+
set({ displayFit, loading: false });
|
|
311
|
+
} catch {
|
|
312
|
+
const displayFit = await getGameApi().getDisplayFit();
|
|
313
|
+
set({ displayFit, loading: false });
|
|
314
|
+
throw new Error("Failed to update display fit.");
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
updateAdminZoom: async (level) => {
|
|
318
|
+
set({ loading: true });
|
|
319
|
+
try {
|
|
320
|
+
const adminZoom = await getGameApi().setAdminZoom(level);
|
|
321
|
+
set({ adminZoom, loading: false });
|
|
322
|
+
} catch {
|
|
323
|
+
const adminZoom = await getGameApi().getAdminZoom();
|
|
324
|
+
set({ adminZoom, loading: false });
|
|
325
|
+
throw new Error("Failed to update admin zoom.");
|
|
326
|
+
}
|
|
327
|
+
},
|
|
266
328
|
moveToScreen: async (target) => {
|
|
267
329
|
set({ loading: true });
|
|
268
330
|
try {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState, useCallback, useEffect } from "react";
|
|
2
|
-
import { u as useAppStore, g as getGameApi } from "./store-
|
|
2
|
+
import { u as useAppStore, g as getGameApi } from "./store-WzFy0ShX.js";
|
|
3
3
|
function normalizeAtodPart(value, label) {
|
|
4
4
|
const normalized = value.trim();
|
|
5
5
|
if (!normalized) {
|
package/cli/generate-screen.mjs
CHANGED
|
@@ -147,12 +147,15 @@ export async function generateScreen(args, { cwd = process.cwd(), interactive =
|
|
|
147
147
|
const descriptionLiteral = description ? JSON.stringify(description) : undefined
|
|
148
148
|
const videoSrcLiteral = videoSrc ? JSON.stringify(videoSrc) : undefined
|
|
149
149
|
const videoAssetImportPath = videoSrc ? toAssetImportPath(videoSrc) : undefined
|
|
150
|
+
const videoFileName = videoSrc?.startsWith('media://video/')
|
|
151
|
+
? videoSrc.slice('media://video/'.length)
|
|
152
|
+
: undefined
|
|
150
153
|
const componentSource =
|
|
151
154
|
template === 'video'
|
|
152
155
|
? `/* eslint-disable react-refresh/only-export-components */
|
|
153
156
|
import type { SceneScreenDefinition } from ${JSON.stringify(contract.importPaths.definitionsTypes)}
|
|
154
157
|
import VideoSceneScreen, { preloadVideoSource } from ${JSON.stringify(contract.importPaths.videoSceneScreen)}
|
|
155
|
-
import type { ScreenPreloadFunction } from ${JSON.stringify(contract.importPaths.registryScreenTypes)}
|
|
158
|
+
import type { ScreenComponentProps, ScreenPreloadFunction } from ${JSON.stringify(contract.importPaths.registryScreenTypes)}
|
|
156
159
|
${videoAssetImportPath ? `import videoSourceUrl from ${JSON.stringify(videoAssetImportPath)}\n` : ''}
|
|
157
160
|
|
|
158
161
|
const VIDEO_SRC = ${videoAssetImportPath ? 'videoSourceUrl' : videoSrcLiteral}
|
|
@@ -161,13 +164,22 @@ const VIDEO_SRC = ${videoAssetImportPath ? 'videoSourceUrl' : videoSrcLiteral}
|
|
|
161
164
|
export const screen: SceneScreenDefinition = {
|
|
162
165
|
id: ${idLiteral},
|
|
163
166
|
title: ${titleLiteral},
|
|
164
|
-
${descriptionLiteral ? ` description: ${descriptionLiteral},\n` : ''} kind: 'scene'
|
|
167
|
+
${descriptionLiteral ? ` description: ${descriptionLiteral},\n` : ''} kind: 'scene'${videoFileName ? `,\n video: ${JSON.stringify(videoFileName)}` : ''}
|
|
165
168
|
}
|
|
166
169
|
|
|
167
|
-
export const preload: ScreenPreloadFunction = () =>
|
|
170
|
+
export const preload: ScreenPreloadFunction = (activeScreen) =>
|
|
171
|
+
preloadVideoSource(activeScreen.video ? 'media://video/' + activeScreen.video : VIDEO_SRC)
|
|
168
172
|
|
|
169
|
-
function ${componentBaseName}() {
|
|
170
|
-
|
|
173
|
+
function ${componentBaseName}({ screen: activeScreen }: ScreenComponentProps) {
|
|
174
|
+
const activeVideoSource = activeScreen.video ? 'media://video/' + activeScreen.video : VIDEO_SRC
|
|
175
|
+
return (
|
|
176
|
+
<VideoSceneScreen
|
|
177
|
+
src={activeVideoSource}
|
|
178
|
+
loop={activeScreen.loop ?? false}
|
|
179
|
+
playCount={activeScreen.loopCount ?? 1}
|
|
180
|
+
objectFit="display-fit"
|
|
181
|
+
/>
|
|
182
|
+
)
|
|
171
183
|
}
|
|
172
184
|
|
|
173
185
|
export default ${componentBaseName}
|
|
@@ -223,7 +235,7 @@ export default ${componentBaseName}
|
|
|
223
235
|
template === 'video'
|
|
224
236
|
? `import { render, screen } from '@testing-library/react'
|
|
225
237
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
226
|
-
import ${componentBaseName} from './${componentBaseName}'
|
|
238
|
+
import ${componentBaseName}, { screen as screenDefinition } from './${componentBaseName}'
|
|
227
239
|
|
|
228
240
|
describe('${componentBaseName}', () => {
|
|
229
241
|
afterEach(() => {
|
|
@@ -234,7 +246,12 @@ describe('${componentBaseName}', () => {
|
|
|
234
246
|
vi.spyOn(HTMLMediaElement.prototype, 'play').mockResolvedValue(undefined)
|
|
235
247
|
vi.spyOn(HTMLMediaElement.prototype, 'load').mockImplementation(() => undefined)
|
|
236
248
|
|
|
237
|
-
render(
|
|
249
|
+
render(
|
|
250
|
+
<${componentBaseName}
|
|
251
|
+
gameState={{ mode: 'running', currentStepId: ${idLiteral}, updatedAt: new Date().toISOString() }}
|
|
252
|
+
screen={{ ...screenDefinition, componentKey: ${JSON.stringify(componentKey)} }}
|
|
253
|
+
/>
|
|
254
|
+
)
|
|
238
255
|
|
|
239
256
|
expect(screen.getByLabelText('video scene')).toHaveAttribute('src', ${videoSrcLiteral})
|
|
240
257
|
})
|
|
@@ -3,8 +3,11 @@ export function renderGeneratedDefinitions(modules, importPaths) {
|
|
|
3
3
|
.map(({ componentKey, screen }) => {
|
|
4
4
|
const descriptionLine = screen.description ? ` description: ${JSON.stringify(screen.description)},\n` : ''
|
|
5
5
|
const shortcutLine = screen.shortcut ? ` shortcut: ${JSON.stringify(screen.shortcut)},\n` : ''
|
|
6
|
+
const videoLine = screen.video ? ` video: ${JSON.stringify(screen.video)},\n` : ''
|
|
7
|
+
const loopLine = screen.loop === undefined ? '' : ` loop: ${screen.loop},\n`
|
|
8
|
+
const loopCountLine = screen.loopCount === undefined ? '' : ` loopCount: ${screen.loopCount},\n`
|
|
6
9
|
|
|
7
|
-
return ` {\n id: ${JSON.stringify(screen.id)},\n title: ${JSON.stringify(screen.title)},\n${descriptionLine} kind: 'scene',\n${shortcutLine} componentKey: ${JSON.stringify(componentKey)}\n }`
|
|
10
|
+
return ` {\n id: ${JSON.stringify(screen.id)},\n title: ${JSON.stringify(screen.title)},\n${descriptionLine} kind: 'scene',\n${shortcutLine}${videoLine}${loopLine}${loopCountLine} componentKey: ${JSON.stringify(componentKey)}\n }`
|
|
8
11
|
})
|
|
9
12
|
.join(',\n')
|
|
10
13
|
|
|
@@ -44,27 +47,28 @@ export const SCENE_SCREEN_COMPONENTS = Object.fromEntries(
|
|
|
44
47
|
|
|
45
48
|
const sceneScreenPreloadPromises = new Map<string, Promise<void>>()
|
|
46
49
|
|
|
47
|
-
export async function preloadSceneScreenComponent(componentKey: string): Promise<void> {
|
|
50
|
+
export async function preloadSceneScreenComponent(componentKey: string, screen: ScreenComponentProps['screen']): Promise<void> {
|
|
48
51
|
const module = SCENE_SCREEN_MODULES[componentKey]
|
|
49
52
|
if (!module?.preload) {
|
|
50
53
|
return
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
const
|
|
56
|
+
const preloadKey = JSON.stringify([componentKey, screen.video ?? '', screen.loop ?? false, screen.loopCount ?? 1])
|
|
57
|
+
const existingPreload = sceneScreenPreloadPromises.get(preloadKey)
|
|
54
58
|
if (existingPreload) {
|
|
55
59
|
await existingPreload
|
|
56
60
|
return
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
const preloadPromise = Promise.resolve()
|
|
60
|
-
.then(() => module.preload?.())
|
|
64
|
+
.then(() => module.preload?.(screen))
|
|
61
65
|
.then(() => undefined)
|
|
62
66
|
.catch((error: unknown) => {
|
|
63
|
-
sceneScreenPreloadPromises.delete(
|
|
67
|
+
sceneScreenPreloadPromises.delete(preloadKey)
|
|
64
68
|
throw error
|
|
65
69
|
})
|
|
66
70
|
|
|
67
|
-
sceneScreenPreloadPromises.set(
|
|
71
|
+
sceneScreenPreloadPromises.set(preloadKey, preloadPromise)
|
|
68
72
|
await preloadPromise
|
|
69
73
|
}
|
|
70
74
|
`
|
|
@@ -7,11 +7,15 @@ function hasModifier(node, kind) {
|
|
|
7
7
|
return Boolean(node.modifiers?.some((modifier) => modifier.kind === kind))
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
function
|
|
10
|
+
function getLiteralValue(node) {
|
|
11
11
|
if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
|
|
12
12
|
return node.text
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
if (node.kind === ts.SyntaxKind.TrueKeyword) return true
|
|
16
|
+
if (node.kind === ts.SyntaxKind.FalseKeyword) return false
|
|
17
|
+
if (ts.isNumericLiteral(node)) return Number(node.text)
|
|
18
|
+
|
|
15
19
|
return undefined
|
|
16
20
|
}
|
|
17
21
|
|
|
@@ -63,9 +67,9 @@ function parseScreenMetadata(sourceText, filePath) {
|
|
|
63
67
|
throw new Error(`Unsupported "screen" property in ${filePath}`)
|
|
64
68
|
}
|
|
65
69
|
|
|
66
|
-
const literalValue =
|
|
70
|
+
const literalValue = getLiteralValue(property.initializer)
|
|
67
71
|
if (literalValue === undefined) {
|
|
68
|
-
throw new Error(`"screen.${property.name.text}" must be a
|
|
72
|
+
throw new Error(`"screen.${property.name.text}" must be a literal in ${filePath}`)
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
values[property.name.text] = literalValue
|
|
@@ -83,7 +87,7 @@ function parseScreenMetadata(sourceText, filePath) {
|
|
|
83
87
|
throw new Error(`Screen module must export "screen": ${filePath}`)
|
|
84
88
|
}
|
|
85
89
|
|
|
86
|
-
const { id, title, description, kind, shortcut, componentKey, isInitial, ...unknown } = metadata
|
|
90
|
+
const { id, title, description, kind, shortcut, video, loop, loopCount, componentKey, isInitial, ...unknown } = metadata
|
|
87
91
|
if (componentKey || isInitial) {
|
|
88
92
|
throw new Error(`"screen" export cannot define componentKey or isInitial: ${filePath}`)
|
|
89
93
|
}
|
|
@@ -103,12 +107,25 @@ function parseScreenMetadata(sourceText, filePath) {
|
|
|
103
107
|
throw new Error(`"screen.kind" must be "scene": ${filePath}`)
|
|
104
108
|
}
|
|
105
109
|
|
|
110
|
+
if (video !== undefined && (typeof video !== 'string' || !video.trim())) {
|
|
111
|
+
throw new Error(`"screen.video" must be a non-empty string literal in ${filePath}`)
|
|
112
|
+
}
|
|
113
|
+
if (loop !== undefined && typeof loop !== 'boolean') {
|
|
114
|
+
throw new Error(`"screen.loop" must be a boolean literal in ${filePath}`)
|
|
115
|
+
}
|
|
116
|
+
if (loopCount !== undefined && (typeof loopCount !== 'number' || !Number.isFinite(loopCount) || loopCount < 1)) {
|
|
117
|
+
throw new Error(`"screen.loopCount" must be a number greater than or equal to 1 in ${filePath}`)
|
|
118
|
+
}
|
|
119
|
+
|
|
106
120
|
return {
|
|
107
121
|
id,
|
|
108
122
|
title,
|
|
109
123
|
description,
|
|
110
124
|
kind,
|
|
111
|
-
shortcut
|
|
125
|
+
shortcut,
|
|
126
|
+
video: video?.trim(),
|
|
127
|
+
loop,
|
|
128
|
+
loopCount: loopCount === undefined ? undefined : Math.floor(loopCount)
|
|
112
129
|
}
|
|
113
130
|
}
|
|
114
131
|
|
package/main/index.js
CHANGED
|
@@ -9,6 +9,7 @@ import Store from "electron-store";
|
|
|
9
9
|
import { validateArduinoBoardConfig, defaultArduinoBoardConfig } from "../shared/arduino-board.js";
|
|
10
10
|
import { createScreenCatalog } from "../shared/screen-catalog.js";
|
|
11
11
|
import { RESET_SCREEN_TARGET, buildDefaultGlobalShortcuts, mergeGlobalShortcuts, normalizeShortcutAccelerator } from "../shared/screen-shortcuts.js";
|
|
12
|
+
import { b as normalizeScreenOverrides, m as mergeScreenOverrides, a as normalizeDisplayFit, n as normalizeAdminZoom, c as normalizeStoredScreenOverrides } from "../chunks/screen-overrides-0d_pEdnM.js";
|
|
12
13
|
import { EventEmitter } from "node:events";
|
|
13
14
|
import { spawn } from "node:child_process";
|
|
14
15
|
import { acceleratorToArduinoKeyboardShortcut } from "../shared/arduino-keyboard-shortcut.js";
|
|
@@ -1077,11 +1078,34 @@ function isBlockedKioskShortcut(input, platform = process.platform) {
|
|
|
1077
1078
|
}
|
|
1078
1079
|
const MEDIA_TYPES = ["image", "video", "audio", "font"];
|
|
1079
1080
|
const MEDIA_EXTENSION_BY_TYPE = {
|
|
1080
|
-
image: /* @__PURE__ */ new Set([".apng", ".avif", ".gif", ".jpeg", ".jpg", ".png", ".webp"]),
|
|
1081
|
+
image: /* @__PURE__ */ new Set([".apng", ".avif", ".gif", ".jpeg", ".jpg", ".png", ".svg", ".webp"]),
|
|
1081
1082
|
video: /* @__PURE__ */ new Set([".m4v", ".mov", ".mp4", ".ogg", ".ogv", ".webm"]),
|
|
1082
1083
|
audio: /* @__PURE__ */ new Set([".aac", ".flac", ".m4a", ".mp3", ".oga", ".ogg", ".wav", ".weba"]),
|
|
1083
1084
|
font: /* @__PURE__ */ new Set([".otf", ".ttf", ".woff", ".woff2"])
|
|
1084
1085
|
};
|
|
1086
|
+
function getMediaContentType(fileName) {
|
|
1087
|
+
const extension = extname(fileName).toLowerCase();
|
|
1088
|
+
if (extension === ".mp4" || extension === ".m4v") return "video/mp4";
|
|
1089
|
+
if (extension === ".mov") return "video/quicktime";
|
|
1090
|
+
if (extension === ".webm") return "video/webm";
|
|
1091
|
+
if (extension === ".ogg" || extension === ".ogv") return "video/ogg";
|
|
1092
|
+
if (extension === ".mp3") return "audio/mpeg";
|
|
1093
|
+
if (extension === ".wav") return "audio/wav";
|
|
1094
|
+
if (extension === ".m4a") return "audio/mp4";
|
|
1095
|
+
if (extension === ".aac") return "audio/aac";
|
|
1096
|
+
if (extension === ".flac") return "audio/flac";
|
|
1097
|
+
if (extension === ".png") return "image/png";
|
|
1098
|
+
if (extension === ".jpg" || extension === ".jpeg") return "image/jpeg";
|
|
1099
|
+
if (extension === ".webp") return "image/webp";
|
|
1100
|
+
if (extension === ".gif") return "image/gif";
|
|
1101
|
+
if (extension === ".avif") return "image/avif";
|
|
1102
|
+
if (extension === ".svg") return "image/svg+xml";
|
|
1103
|
+
if (extension === ".woff2") return "font/woff2";
|
|
1104
|
+
if (extension === ".woff") return "font/woff";
|
|
1105
|
+
if (extension === ".ttf") return "font/ttf";
|
|
1106
|
+
if (extension === ".otf") return "font/otf";
|
|
1107
|
+
return "application/octet-stream";
|
|
1108
|
+
}
|
|
1085
1109
|
function assertMediaType(type) {
|
|
1086
1110
|
if (!MEDIA_TYPES.includes(type)) {
|
|
1087
1111
|
throw new Error(`Unsupported media type: ${type}`);
|
|
@@ -1501,12 +1525,39 @@ function startKeyScreenMain(options) {
|
|
|
1501
1525
|
function getGlobalShortcuts() {
|
|
1502
1526
|
return mergeGlobalShortcuts(store.get("globalShortcuts") ?? [], defaultGlobalShortcuts);
|
|
1503
1527
|
}
|
|
1528
|
+
function getScreenOverrides() {
|
|
1529
|
+
const stored = store.get("screenOverrides");
|
|
1530
|
+
const normalized = normalizeStoredScreenOverrides(stored, screenCatalog.screenDefinitions);
|
|
1531
|
+
if (stored !== void 0 && JSON.stringify(stored) !== JSON.stringify(normalized)) {
|
|
1532
|
+
store.set("screenOverrides", normalized);
|
|
1533
|
+
}
|
|
1534
|
+
return normalized;
|
|
1535
|
+
}
|
|
1536
|
+
function getAvailableScreens() {
|
|
1537
|
+
return mergeScreenOverrides(screenCatalog.screenDefinitions, getScreenOverrides());
|
|
1538
|
+
}
|
|
1504
1539
|
function getArduinoBoardConfig() {
|
|
1505
1540
|
return validateArduinoBoardConfig(store.get("arduinoBoardConfig") ?? defaultArduinoBoardConfig());
|
|
1506
1541
|
}
|
|
1507
1542
|
function getSavedWindowMode() {
|
|
1508
1543
|
return store.get("windowMode");
|
|
1509
1544
|
}
|
|
1545
|
+
function getDisplayFit() {
|
|
1546
|
+
return normalizeDisplayFit(store.get("displayFit"), options.defaultDisplayFit ?? "contain");
|
|
1547
|
+
}
|
|
1548
|
+
function setDisplayFit(value) {
|
|
1549
|
+
const displayFit = normalizeDisplayFit(value, options.defaultDisplayFit ?? "contain");
|
|
1550
|
+
store.set("displayFit", displayFit);
|
|
1551
|
+
return displayFit;
|
|
1552
|
+
}
|
|
1553
|
+
function getAdminZoom() {
|
|
1554
|
+
return normalizeAdminZoom(store.get("adminZoom"));
|
|
1555
|
+
}
|
|
1556
|
+
function setAdminZoom(value) {
|
|
1557
|
+
const adminZoom = normalizeAdminZoom(value);
|
|
1558
|
+
store.set("adminZoom", adminZoom);
|
|
1559
|
+
return adminZoom;
|
|
1560
|
+
}
|
|
1510
1561
|
function hasWindowModeEnvOverride() {
|
|
1511
1562
|
return getEnvWindowModeOverride(process.env) !== void 0;
|
|
1512
1563
|
}
|
|
@@ -1538,28 +1589,6 @@ function startKeyScreenMain(options) {
|
|
|
1538
1589
|
const name = decodeURIComponent(url.pathname.replace(/^\/+/, ""));
|
|
1539
1590
|
return { type, name };
|
|
1540
1591
|
}
|
|
1541
|
-
function getMediaContentType(fileName) {
|
|
1542
|
-
const extension = extname(fileName).toLowerCase();
|
|
1543
|
-
if (extension === ".mp4" || extension === ".m4v") return "video/mp4";
|
|
1544
|
-
if (extension === ".mov") return "video/quicktime";
|
|
1545
|
-
if (extension === ".webm") return "video/webm";
|
|
1546
|
-
if (extension === ".ogg" || extension === ".ogv") return "video/ogg";
|
|
1547
|
-
if (extension === ".mp3") return "audio/mpeg";
|
|
1548
|
-
if (extension === ".wav") return "audio/wav";
|
|
1549
|
-
if (extension === ".m4a") return "audio/mp4";
|
|
1550
|
-
if (extension === ".aac") return "audio/aac";
|
|
1551
|
-
if (extension === ".flac") return "audio/flac";
|
|
1552
|
-
if (extension === ".png") return "image/png";
|
|
1553
|
-
if (extension === ".jpg" || extension === ".jpeg") return "image/jpeg";
|
|
1554
|
-
if (extension === ".webp") return "image/webp";
|
|
1555
|
-
if (extension === ".gif") return "image/gif";
|
|
1556
|
-
if (extension === ".avif") return "image/avif";
|
|
1557
|
-
if (extension === ".woff2") return "font/woff2";
|
|
1558
|
-
if (extension === ".woff") return "font/woff";
|
|
1559
|
-
if (extension === ".ttf") return "font/ttf";
|
|
1560
|
-
if (extension === ".otf") return "font/otf";
|
|
1561
|
-
return "application/octet-stream";
|
|
1562
|
-
}
|
|
1563
1592
|
async function createMediaProtocolResponse(mediaManager, request) {
|
|
1564
1593
|
const ref = parseMediaProtocolUrl(request.url);
|
|
1565
1594
|
const filePath = mediaManager.resolveMediaPath(ref);
|
|
@@ -1901,7 +1930,7 @@ function startKeyScreenMain(options) {
|
|
|
1901
1930
|
ipcMain.handle("device:disconnect", async () => deviceController.disconnect());
|
|
1902
1931
|
ipcMain.handle("device:send", async (_event, command) => deviceController.send(command));
|
|
1903
1932
|
ipcMain.handle("game:getState", async () => gameSession.getState());
|
|
1904
|
-
ipcMain.handle("game:getAvailableScreens", async () =>
|
|
1933
|
+
ipcMain.handle("game:getAvailableScreens", async () => getAvailableScreens());
|
|
1905
1934
|
ipcMain.handle("media:getLibrary", async () => mediaManager.listLibrary());
|
|
1906
1935
|
ipcMain.handle("media:resolveUrl", async (_event, ref) => mediaManager.resolveMediaUrl(ref));
|
|
1907
1936
|
ipcMain.handle("media:openFolder", async () => {
|
|
@@ -1934,6 +1963,14 @@ function startKeyScreenMain(options) {
|
|
|
1934
1963
|
);
|
|
1935
1964
|
return getGlobalShortcuts();
|
|
1936
1965
|
});
|
|
1966
|
+
ipcMain.handle("game:updateScreenOverrides", async (_event, overrides) => {
|
|
1967
|
+
const normalized = normalizeScreenOverrides(overrides, screenCatalog.screenDefinitions);
|
|
1968
|
+
for (const override of Object.values(normalized)) {
|
|
1969
|
+
if (override.video) mediaManager.resolveMediaPath({ type: "video", name: override.video });
|
|
1970
|
+
}
|
|
1971
|
+
store.set("screenOverrides", normalized);
|
|
1972
|
+
return getAvailableScreens();
|
|
1973
|
+
});
|
|
1937
1974
|
ipcMain.handle("arduino:getBoardConfig", async () => getArduinoBoardConfig());
|
|
1938
1975
|
ipcMain.handle("arduino:updateBoardConfig", async (_event, config) => {
|
|
1939
1976
|
const normalizedConfig = validateArduinoBoardConfig(config);
|
|
@@ -1961,6 +1998,10 @@ function startKeyScreenMain(options) {
|
|
|
1961
1998
|
}
|
|
1962
1999
|
return setWindowMode(mode);
|
|
1963
2000
|
});
|
|
2001
|
+
ipcMain.handle("game:getDisplayFit", async () => getDisplayFit());
|
|
2002
|
+
ipcMain.handle("game:setDisplayFit", async (_event, mode) => setDisplayFit(mode));
|
|
2003
|
+
ipcMain.handle("game:getAdminZoom", async () => getAdminZoom());
|
|
2004
|
+
ipcMain.handle("game:setAdminZoom", async (_event, level) => setAdminZoom(level));
|
|
1964
2005
|
ipcMain.handle("game:moveToScreen", async (_event, target) => {
|
|
1965
2006
|
const response = await dtoaDispatcher.dispatch(target);
|
|
1966
2007
|
return response.ok ? gameSession.getState() : Promise.reject(new Error(response.message));
|
package/package.json
CHANGED
package/preload/index.js
CHANGED
|
@@ -17,6 +17,7 @@ function createKeyScreenBridgeApi(renderer = ipcRenderer) {
|
|
|
17
17
|
quitApp: () => renderer.send("app:quit"),
|
|
18
18
|
getGlobalShortcuts: () => renderer.invoke("game:getGlobalShortcuts"),
|
|
19
19
|
updateGlobalShortcuts: (shortcuts) => renderer.invoke("game:updateGlobalShortcuts", shortcuts),
|
|
20
|
+
updateScreenOverrides: (overrides) => renderer.invoke("game:updateScreenOverrides", overrides),
|
|
20
21
|
getArduinoBoardConfig: () => renderer.invoke("arduino:getBoardConfig"),
|
|
21
22
|
updateArduinoBoardConfig: (config) => renderer.invoke("arduino:updateBoardConfig", config),
|
|
22
23
|
previewArduinoSketch: () => renderer.invoke("arduino:previewSketch"),
|
|
@@ -28,6 +29,10 @@ function createKeyScreenBridgeApi(renderer = ipcRenderer) {
|
|
|
28
29
|
getWindowMode: () => renderer.invoke("game:getWindowMode"),
|
|
29
30
|
isWindowModeLocked: () => renderer.invoke("game:isWindowModeLocked"),
|
|
30
31
|
setWindowMode: (mode) => renderer.invoke("game:setWindowMode", mode),
|
|
32
|
+
getDisplayFit: () => renderer.invoke("game:getDisplayFit"),
|
|
33
|
+
setDisplayFit: (mode) => renderer.invoke("game:setDisplayFit", mode),
|
|
34
|
+
getAdminZoom: () => renderer.invoke("game:getAdminZoom"),
|
|
35
|
+
setAdminZoom: (level) => renderer.invoke("game:setAdminZoom", level),
|
|
31
36
|
moveToScreen: (target) => renderer.invoke("game:moveToScreen", target),
|
|
32
37
|
logPreload: (entry) => renderer.send("preload:log", entry),
|
|
33
38
|
logShortcutTransition: (entry) => renderer.send("shortcut:log", entry),
|