key-screen-framework 1.0.0 → 1.2.0
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/key-screen-framework.mjs +50 -0
- package/cli/screen-generation-renderers.mjs +10 -6
- package/cli/screen-module-utils.mjs +22 -5
- package/main/index.js +42 -2
- package/package.json +2 -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/templates/project/package.json +1 -1
- 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
|
})
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from 'node:child_process'
|
|
3
|
+
import { readFileSync } from 'node:fs'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
|
+
|
|
6
|
+
const commands = {
|
|
7
|
+
'new-project': ['key-screen-new-project', 'new-project.mjs'],
|
|
8
|
+
migrate: ['key-screen-migrate', 'migrate-project.mjs'],
|
|
9
|
+
doctor: ['key-screen-doctor', 'doctor-project.mjs'],
|
|
10
|
+
generate: ['key-screen-generate', 'generate-screen.mjs'],
|
|
11
|
+
remove: ['key-screen-remove', 'remove-screen.mjs'],
|
|
12
|
+
sync: ['key-screen-sync', 'sync-screens.mjs'],
|
|
13
|
+
'setup-arduino': ['key-screen-setup-arduino', 'setup-arduino-cli.mjs'],
|
|
14
|
+
'check-arduino-bundle': ['key-screen-check-arduino-bundle', 'check-arduino-bundle.mjs']
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const [command, ...args] = process.argv.slice(2)
|
|
18
|
+
|
|
19
|
+
if (!command || command === '--help' || command === '-h') {
|
|
20
|
+
console.log('Usage: npx key-screen-framework <command> [options]\n')
|
|
21
|
+
console.log('Commands:')
|
|
22
|
+
for (const name of Object.keys(commands)) {
|
|
23
|
+
console.log(` ${name}`)
|
|
24
|
+
}
|
|
25
|
+
console.log('\nExample: npx key-screen-framework new-project')
|
|
26
|
+
} else if (command === '--version' || command === '-v') {
|
|
27
|
+
const manifest = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'))
|
|
28
|
+
console.log(manifest.version)
|
|
29
|
+
} else {
|
|
30
|
+
const entry = Object.hasOwn(commands, command)
|
|
31
|
+
? commands[command]
|
|
32
|
+
: Object.values(commands).find(([alias]) => alias === command)
|
|
33
|
+
if (!entry) {
|
|
34
|
+
console.error(`Unknown command: ${command}. Run key-screen-framework --help for available commands.`)
|
|
35
|
+
process.exitCode = 1
|
|
36
|
+
} else {
|
|
37
|
+
// Keep the caller's working directory and terminal for interactive prompts.
|
|
38
|
+
const result = spawnSync(process.execPath, [fileURLToPath(new URL(entry[1], import.meta.url)), ...args], {
|
|
39
|
+
stdio: 'inherit'
|
|
40
|
+
})
|
|
41
|
+
if (result.error) {
|
|
42
|
+
console.error(result.error.message)
|
|
43
|
+
process.exitCode = 1
|
|
44
|
+
} else if (result.signal) {
|
|
45
|
+
process.kill(process.pid, result.signal)
|
|
46
|
+
} else {
|
|
47
|
+
process.exitCode = result.status ?? 1
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -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,7 +1078,7 @@ 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"])
|
|
@@ -1501,12 +1502,39 @@ function startKeyScreenMain(options) {
|
|
|
1501
1502
|
function getGlobalShortcuts() {
|
|
1502
1503
|
return mergeGlobalShortcuts(store.get("globalShortcuts") ?? [], defaultGlobalShortcuts);
|
|
1503
1504
|
}
|
|
1505
|
+
function getScreenOverrides() {
|
|
1506
|
+
const stored = store.get("screenOverrides");
|
|
1507
|
+
const normalized = normalizeStoredScreenOverrides(stored, screenCatalog.screenDefinitions);
|
|
1508
|
+
if (stored !== void 0 && JSON.stringify(stored) !== JSON.stringify(normalized)) {
|
|
1509
|
+
store.set("screenOverrides", normalized);
|
|
1510
|
+
}
|
|
1511
|
+
return normalized;
|
|
1512
|
+
}
|
|
1513
|
+
function getAvailableScreens() {
|
|
1514
|
+
return mergeScreenOverrides(screenCatalog.screenDefinitions, getScreenOverrides());
|
|
1515
|
+
}
|
|
1504
1516
|
function getArduinoBoardConfig() {
|
|
1505
1517
|
return validateArduinoBoardConfig(store.get("arduinoBoardConfig") ?? defaultArduinoBoardConfig());
|
|
1506
1518
|
}
|
|
1507
1519
|
function getSavedWindowMode() {
|
|
1508
1520
|
return store.get("windowMode");
|
|
1509
1521
|
}
|
|
1522
|
+
function getDisplayFit() {
|
|
1523
|
+
return normalizeDisplayFit(store.get("displayFit"), options.defaultDisplayFit ?? "contain");
|
|
1524
|
+
}
|
|
1525
|
+
function setDisplayFit(value) {
|
|
1526
|
+
const displayFit = normalizeDisplayFit(value, options.defaultDisplayFit ?? "contain");
|
|
1527
|
+
store.set("displayFit", displayFit);
|
|
1528
|
+
return displayFit;
|
|
1529
|
+
}
|
|
1530
|
+
function getAdminZoom() {
|
|
1531
|
+
return normalizeAdminZoom(store.get("adminZoom"));
|
|
1532
|
+
}
|
|
1533
|
+
function setAdminZoom(value) {
|
|
1534
|
+
const adminZoom = normalizeAdminZoom(value);
|
|
1535
|
+
store.set("adminZoom", adminZoom);
|
|
1536
|
+
return adminZoom;
|
|
1537
|
+
}
|
|
1510
1538
|
function hasWindowModeEnvOverride() {
|
|
1511
1539
|
return getEnvWindowModeOverride(process.env) !== void 0;
|
|
1512
1540
|
}
|
|
@@ -1901,7 +1929,7 @@ function startKeyScreenMain(options) {
|
|
|
1901
1929
|
ipcMain.handle("device:disconnect", async () => deviceController.disconnect());
|
|
1902
1930
|
ipcMain.handle("device:send", async (_event, command) => deviceController.send(command));
|
|
1903
1931
|
ipcMain.handle("game:getState", async () => gameSession.getState());
|
|
1904
|
-
ipcMain.handle("game:getAvailableScreens", async () =>
|
|
1932
|
+
ipcMain.handle("game:getAvailableScreens", async () => getAvailableScreens());
|
|
1905
1933
|
ipcMain.handle("media:getLibrary", async () => mediaManager.listLibrary());
|
|
1906
1934
|
ipcMain.handle("media:resolveUrl", async (_event, ref) => mediaManager.resolveMediaUrl(ref));
|
|
1907
1935
|
ipcMain.handle("media:openFolder", async () => {
|
|
@@ -1934,6 +1962,14 @@ function startKeyScreenMain(options) {
|
|
|
1934
1962
|
);
|
|
1935
1963
|
return getGlobalShortcuts();
|
|
1936
1964
|
});
|
|
1965
|
+
ipcMain.handle("game:updateScreenOverrides", async (_event, overrides) => {
|
|
1966
|
+
const normalized = normalizeScreenOverrides(overrides, screenCatalog.screenDefinitions);
|
|
1967
|
+
for (const override of Object.values(normalized)) {
|
|
1968
|
+
if (override.video) mediaManager.resolveMediaPath({ type: "video", name: override.video });
|
|
1969
|
+
}
|
|
1970
|
+
store.set("screenOverrides", normalized);
|
|
1971
|
+
return getAvailableScreens();
|
|
1972
|
+
});
|
|
1937
1973
|
ipcMain.handle("arduino:getBoardConfig", async () => getArduinoBoardConfig());
|
|
1938
1974
|
ipcMain.handle("arduino:updateBoardConfig", async (_event, config) => {
|
|
1939
1975
|
const normalizedConfig = validateArduinoBoardConfig(config);
|
|
@@ -1961,6 +1997,10 @@ function startKeyScreenMain(options) {
|
|
|
1961
1997
|
}
|
|
1962
1998
|
return setWindowMode(mode);
|
|
1963
1999
|
});
|
|
2000
|
+
ipcMain.handle("game:getDisplayFit", async () => getDisplayFit());
|
|
2001
|
+
ipcMain.handle("game:setDisplayFit", async (_event, mode) => setDisplayFit(mode));
|
|
2002
|
+
ipcMain.handle("game:getAdminZoom", async () => getAdminZoom());
|
|
2003
|
+
ipcMain.handle("game:setAdminZoom", async (_event, level) => setAdminZoom(level));
|
|
1964
2004
|
ipcMain.handle("game:moveToScreen", async (_event, target) => {
|
|
1965
2005
|
const response = await dtoaDispatcher.dispatch(target);
|
|
1966
2006
|
return response.ok ? gameSession.getState() : Promise.reject(new Error(response.message));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "key-screen-framework",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Screen framework for Keyescape desktop projects.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
"**/*.css"
|
|
80
80
|
],
|
|
81
81
|
"bin": {
|
|
82
|
+
"key-screen-framework": "./cli/key-screen-framework.mjs",
|
|
82
83
|
"key-screen-new-project": "./cli/new-project.mjs",
|
|
83
84
|
"key-screen-migrate": "./cli/migrate-project.mjs",
|
|
84
85
|
"key-screen-doctor": "./cli/doctor-project.mjs",
|
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),
|