key-screen-framework 1.2.2 → 1.3.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/main/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { createRequire } from "node:module";
|
|
|
4
4
|
import { join, dirname, extname, relative, sep, normalize } from "node:path";
|
|
5
5
|
import { Readable } from "node:stream";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
|
-
import { app, protocol, ipcMain, shell, BrowserWindow, screen } from "electron";
|
|
7
|
+
import { app, protocol, dialog, ipcMain, shell, BrowserWindow, screen } from "electron";
|
|
8
8
|
import Store from "electron-store";
|
|
9
9
|
import { validateArduinoBoardConfig, defaultArduinoBoardConfig } from "../shared/arduino-board.js";
|
|
10
10
|
import { createScreenCatalog } from "../shared/screen-catalog.js";
|
|
@@ -1165,12 +1165,19 @@ class MediaManager {
|
|
|
1165
1165
|
async ensureDirectories() {
|
|
1166
1166
|
await Promise.all(MEDIA_TYPES.map((type) => mkdir(join(this.rootPath, type), { recursive: true })));
|
|
1167
1167
|
}
|
|
1168
|
-
async seedFrom(sourceRootPath) {
|
|
1168
|
+
async seedFrom(sourceRootPath, options = {}) {
|
|
1169
|
+
const sourceRoot = await stat(sourceRootPath);
|
|
1170
|
+
if (!sourceRoot.isDirectory()) {
|
|
1171
|
+
throw new Error("Media source root must be a directory.");
|
|
1172
|
+
}
|
|
1169
1173
|
await this.ensureDirectories();
|
|
1170
1174
|
await Promise.all(
|
|
1171
1175
|
MEDIA_TYPES.map(async (type) => {
|
|
1172
1176
|
const sourceDirectory = join(sourceRootPath, type);
|
|
1173
|
-
const files = await readdir(sourceDirectory, { withFileTypes: true }).catch(() =>
|
|
1177
|
+
const files = await readdir(sourceDirectory, { withFileTypes: true }).catch((error) => {
|
|
1178
|
+
if (error.code === "ENOENT") return [];
|
|
1179
|
+
throw error;
|
|
1180
|
+
});
|
|
1174
1181
|
await Promise.all(
|
|
1175
1182
|
files.filter((file) => file.isFile()).filter((file) => MEDIA_EXTENSION_BY_TYPE[type].has(extname(file.name).toLowerCase())).map(async (file) => {
|
|
1176
1183
|
const sourcePath = join(sourceDirectory, file.name);
|
|
@@ -1182,7 +1189,7 @@ class MediaManager {
|
|
|
1182
1189
|
return;
|
|
1183
1190
|
}
|
|
1184
1191
|
const existingDestination = await stat(destinationPath).catch(() => null);
|
|
1185
|
-
if (existingDestination) {
|
|
1192
|
+
if (existingDestination && !options.overwrite) {
|
|
1186
1193
|
return;
|
|
1187
1194
|
}
|
|
1188
1195
|
await mkdir(dirname(destinationPath), { recursive: true });
|
|
@@ -1193,7 +1200,6 @@ class MediaManager {
|
|
|
1193
1200
|
);
|
|
1194
1201
|
}
|
|
1195
1202
|
async listLibrary() {
|
|
1196
|
-
await this.ensureDirectories();
|
|
1197
1203
|
const assets = (await Promise.all(MEDIA_TYPES.map((type) => this.listAssetsForType(type)))).flat();
|
|
1198
1204
|
return {
|
|
1199
1205
|
rootPath: this.rootPath,
|
|
@@ -1245,6 +1251,11 @@ class MediaManager {
|
|
|
1245
1251
|
return assets.filter((asset) => asset !== null);
|
|
1246
1252
|
}
|
|
1247
1253
|
}
|
|
1254
|
+
function createMediaManager(options) {
|
|
1255
|
+
return new MediaManager(
|
|
1256
|
+
options.isDev ? options.sourceRootPath : options.externalRootPath
|
|
1257
|
+
);
|
|
1258
|
+
}
|
|
1248
1259
|
function parseByteRange(rangeHeader, sizeBytes) {
|
|
1249
1260
|
if (!rangeHeader) {
|
|
1250
1261
|
return null;
|
|
@@ -1450,6 +1461,18 @@ function resolveMainRuntimePaths(overrides, context) {
|
|
|
1450
1461
|
defaultMediaRoot: overrides?.defaultMediaRoot ?? defaultMediaRoot
|
|
1451
1462
|
};
|
|
1452
1463
|
}
|
|
1464
|
+
async function installMediaOnFirstLaunch(options) {
|
|
1465
|
+
if (options.platform !== "darwin" || !options.isPackaged || options.isDev || options.completed) {
|
|
1466
|
+
return true;
|
|
1467
|
+
}
|
|
1468
|
+
const overwrite = await options.askOverwrite();
|
|
1469
|
+
if (overwrite === null) {
|
|
1470
|
+
return false;
|
|
1471
|
+
}
|
|
1472
|
+
await options.install(overwrite);
|
|
1473
|
+
options.markCompleted();
|
|
1474
|
+
return true;
|
|
1475
|
+
}
|
|
1453
1476
|
const requireMainDependency = createRequire(import.meta.url);
|
|
1454
1477
|
function startKeyScreenMain(options) {
|
|
1455
1478
|
const log = requireMainDependency("electron-log/main");
|
|
@@ -1910,9 +1933,57 @@ function startKeyScreenMain(options) {
|
|
|
1910
1933
|
}
|
|
1911
1934
|
}
|
|
1912
1935
|
app.whenReady().then(async () => {
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1936
|
+
if (app.isPackaged && process.argv.includes("--install-media")) {
|
|
1937
|
+
try {
|
|
1938
|
+
const installer = new MediaManager(join(app.getPath("userData"), "media"));
|
|
1939
|
+
await installer.seedFrom(runtimePaths.defaultMediaRoot, {
|
|
1940
|
+
overwrite: process.argv.includes("--overwrite-media")
|
|
1941
|
+
});
|
|
1942
|
+
app.exit(0);
|
|
1943
|
+
} catch (error) {
|
|
1944
|
+
log.error("[media] installation failed", error);
|
|
1945
|
+
app.exit(1);
|
|
1946
|
+
}
|
|
1947
|
+
return;
|
|
1948
|
+
}
|
|
1949
|
+
const mediaManager = createMediaManager({
|
|
1950
|
+
isDev,
|
|
1951
|
+
sourceRootPath: runtimePaths.defaultMediaRoot,
|
|
1952
|
+
externalRootPath: join(app.getPath("userData"), "media")
|
|
1953
|
+
});
|
|
1954
|
+
try {
|
|
1955
|
+
const ready = await installMediaOnFirstLaunch({
|
|
1956
|
+
platform: process.platform,
|
|
1957
|
+
isPackaged: app.isPackaged,
|
|
1958
|
+
isDev,
|
|
1959
|
+
completed: store.get("mediaInstallationCompleted", false),
|
|
1960
|
+
askOverwrite: async () => {
|
|
1961
|
+
const result = await dialog.showMessageBox({
|
|
1962
|
+
type: "question",
|
|
1963
|
+
title: "리소스 설치 옵션",
|
|
1964
|
+
message: "최초 실행에 필요한 media 리소스를 설치합니다.",
|
|
1965
|
+
detail: "기본값은 기존 파일 보존입니다. 덮어쓰기를 선택하면 같은 이름의 파일을 앱에 포함된 media 파일로 교체합니다. 사용자 추가 파일은 유지됩니다.",
|
|
1966
|
+
checkboxLabel: "기존 리소스 덮어쓰기",
|
|
1967
|
+
checkboxChecked: false,
|
|
1968
|
+
buttons: ["리소스 설치", "종료"],
|
|
1969
|
+
defaultId: 0,
|
|
1970
|
+
cancelId: 1
|
|
1971
|
+
});
|
|
1972
|
+
return result.response === 0 ? result.checkboxChecked : null;
|
|
1973
|
+
},
|
|
1974
|
+
install: (overwrite) => mediaManager.seedFrom(runtimePaths.defaultMediaRoot, { overwrite }),
|
|
1975
|
+
markCompleted: () => store.set("mediaInstallationCompleted", true)
|
|
1976
|
+
});
|
|
1977
|
+
if (!ready) {
|
|
1978
|
+
app.quit();
|
|
1979
|
+
return;
|
|
1980
|
+
}
|
|
1981
|
+
} catch (error) {
|
|
1982
|
+
log.error("[media] first launch installation failed", error);
|
|
1983
|
+
dialog.showErrorBox("리소스 설치 실패", "media 리소스를 설치하지 못했습니다. 다음 실행 시 다시 설치할 수 있습니다.");
|
|
1984
|
+
app.quit();
|
|
1985
|
+
return;
|
|
1986
|
+
}
|
|
1916
1987
|
protocol.handle("media", async (request) => {
|
|
1917
1988
|
try {
|
|
1918
1989
|
return await createMediaProtocolResponse(mediaManager, request);
|
|
@@ -1965,7 +2036,6 @@ function startKeyScreenMain(options) {
|
|
|
1965
2036
|
ipcMain.handle("media:getLibrary", async () => mediaManager.listLibrary());
|
|
1966
2037
|
ipcMain.handle("media:resolveUrl", async (_event, ref) => mediaManager.resolveMediaUrl(ref));
|
|
1967
2038
|
ipcMain.handle("media:openFolder", async () => {
|
|
1968
|
-
await mediaManager.ensureDirectories();
|
|
1969
2039
|
const path = mediaManager.getRootPath();
|
|
1970
2040
|
const message = await shell.openPath(path);
|
|
1971
2041
|
return {
|
package/package.json
CHANGED
package/renderer/index.js
CHANGED
|
@@ -1480,7 +1480,7 @@ function AdminScreen({ gameState }) {
|
|
|
1480
1480
|
try {
|
|
1481
1481
|
setMediaLibrary(await getGameApi().getMediaLibrary());
|
|
1482
1482
|
} catch {
|
|
1483
|
-
setMediaError("
|
|
1483
|
+
setMediaError("리소스 목록을 불러오지 못했습니다.");
|
|
1484
1484
|
} finally {
|
|
1485
1485
|
setMediaLoading(false);
|
|
1486
1486
|
}
|
|
@@ -1494,10 +1494,10 @@ function AdminScreen({ gameState }) {
|
|
|
1494
1494
|
try {
|
|
1495
1495
|
const result = await getGameApi().openMediaFolder();
|
|
1496
1496
|
if (!result.ok) {
|
|
1497
|
-
setMediaError(result.message ?? "
|
|
1497
|
+
setMediaError(result.message ?? "리소스 폴더를 열지 못했습니다.");
|
|
1498
1498
|
}
|
|
1499
1499
|
} catch {
|
|
1500
|
-
setMediaError("
|
|
1500
|
+
setMediaError("리소스 폴더를 열지 못했습니다.");
|
|
1501
1501
|
}
|
|
1502
1502
|
};
|
|
1503
1503
|
const selectArchive = async (dateKey) => {
|
|
@@ -1928,7 +1928,7 @@ function AdminScreen({ gameState }) {
|
|
|
1928
1928
|
children: [
|
|
1929
1929
|
/* @__PURE__ */ jsx("span", { className: "block text-[11px] uppercase tracking-[0.25em] text-text-dim", children: "리소스" }),
|
|
1930
1930
|
/* @__PURE__ */ jsx("span", { className: "mt-2 block text-sm font-semibold text-text", children: "관리" }),
|
|
1931
|
-
/* @__PURE__ */ jsx("span", { className: "mt-1 block text-xs text-text-subtle", children: mediaLibrary ? `${mediaLibrary.assets.length}개 파일` : "
|
|
1931
|
+
/* @__PURE__ */ jsx("span", { className: "mt-1 block text-xs text-text-subtle", children: mediaLibrary ? `${mediaLibrary.assets.length}개 파일` : "리소스 파일" })
|
|
1932
1932
|
]
|
|
1933
1933
|
}
|
|
1934
1934
|
),
|
|
@@ -2985,7 +2985,7 @@ function AdminScreen({ gameState }) {
|
|
|
2985
2985
|
/* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-4 border-b border-border-soft px-5 py-4", children: [
|
|
2986
2986
|
/* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
|
|
2987
2987
|
/* @__PURE__ */ jsx("p", { className: "text-xs uppercase tracking-[0.25em] text-text-subtle", children: "Media Library" }),
|
|
2988
|
-
/* @__PURE__ */ jsx("h3", { className: "mt-2 font-display text-xl text-text", children: "
|
|
2988
|
+
/* @__PURE__ */ jsx("h3", { className: "mt-2 font-display text-xl text-text", children: "리소스" }),
|
|
2989
2989
|
/* @__PURE__ */ jsx("p", { className: "mt-1 break-all text-sm text-text-muted", children: mediaLibrary?.rootPath ?? "리소스 폴더 확인 중" })
|
|
2990
2990
|
] }),
|
|
2991
2991
|
/* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-2", children: [
|
|
@@ -3033,7 +3033,7 @@ function AdminScreen({ gameState }) {
|
|
|
3033
3033
|
},
|
|
3034
3034
|
type
|
|
3035
3035
|
)) }),
|
|
3036
|
-
mediaLoading ? /* @__PURE__ */ jsx("div", { className: "flex h-52 items-center justify-center rounded-lg border border-dashed border-border-soft text-sm text-text-subtle", children: "불러오는 중..." }) : !mediaLibrary || mediaLibrary.assets.length === 0 ? /* @__PURE__ */ jsx("div", { className: "rounded-lg border border-dashed border-border-soft px-4 py-8 text-sm text-text-subtle", children: "
|
|
3036
|
+
mediaLoading ? /* @__PURE__ */ jsx("div", { className: "flex h-52 items-center justify-center rounded-lg border border-dashed border-border-soft text-sm text-text-subtle", children: "불러오는 중..." }) : !mediaLibrary || mediaLibrary.assets.length === 0 ? /* @__PURE__ */ jsx("div", { className: "rounded-lg border border-dashed border-border-soft px-4 py-8 text-sm text-text-subtle", children: "리소스 파일이 없습니다. 폴더를 열고 `image`, `video`, `audio`, `font` 하위 폴더에 파일을 추가하세요." }) : /* @__PURE__ */ jsxs("div", { className: "overflow-hidden rounded-lg border border-border-soft", children: [
|
|
3037
3037
|
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[120px_minmax(0,1fr)_120px_190px] gap-3 border-b border-border-soft bg-surface px-4 py-3 text-xs uppercase tracking-[0.2em] text-text-subtle", children: [
|
|
3038
3038
|
/* @__PURE__ */ jsx("span", { children: "종류" }),
|
|
3039
3039
|
/* @__PURE__ */ jsx("span", { children: "파일" }),
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
!ifndef BUILD_UNINSTALLER
|
|
2
|
+
!include nsDialogs.nsh
|
|
3
|
+
Var mediaOverwriteCheckbox
|
|
4
|
+
Var mediaOverwriteSelected
|
|
5
|
+
|
|
6
|
+
!macro customPageAfterChangeDir
|
|
7
|
+
Page custom MediaOptionsCreate MediaOptionsLeave
|
|
8
|
+
|
|
9
|
+
Function MediaOptionsCreate
|
|
10
|
+
!insertmacro MUI_HEADER_TEXT "리소스 설치 옵션" "기존 media 파일을 덮어쓸지 선택하세요."
|
|
11
|
+
nsDialogs::Create 1018
|
|
12
|
+
Pop $0
|
|
13
|
+
${If} $0 == error
|
|
14
|
+
Abort
|
|
15
|
+
${EndIf}
|
|
16
|
+
|
|
17
|
+
${NSD_CreateLabel} 0 0 100% 36u "기본값은 기존 파일 보존입니다. 덮어쓰기를 선택하면 같은 이름의 파일을 인스톨러에 포함된 media 파일로 교체합니다."
|
|
18
|
+
Pop $0
|
|
19
|
+
${NSD_CreateCheckbox} 0 44u 100% 20u "기존 리소스 덮어쓰기"
|
|
20
|
+
Pop $mediaOverwriteCheckbox
|
|
21
|
+
${If} $mediaOverwriteSelected == ${BST_CHECKED}
|
|
22
|
+
${NSD_SetState} $mediaOverwriteCheckbox ${BST_CHECKED}
|
|
23
|
+
${Else}
|
|
24
|
+
${NSD_SetState} $mediaOverwriteCheckbox ${BST_UNCHECKED}
|
|
25
|
+
${EndIf}
|
|
26
|
+
nsDialogs::Show
|
|
27
|
+
FunctionEnd
|
|
28
|
+
|
|
29
|
+
Function MediaOptionsLeave
|
|
30
|
+
${NSD_GetState} $mediaOverwriteCheckbox $mediaOverwriteSelected
|
|
31
|
+
FunctionEnd
|
|
32
|
+
!macroend
|
|
33
|
+
!endif
|
|
34
|
+
|
|
35
|
+
!macro customInstall
|
|
36
|
+
DetailPrint "Installing default media..."
|
|
37
|
+
ClearErrors
|
|
38
|
+
${If} $mediaOverwriteSelected == ${BST_CHECKED}
|
|
39
|
+
ExecWait '"$INSTDIR\${APP_EXECUTABLE_FILENAME}" --install-media --overwrite-media' $0
|
|
40
|
+
${Else}
|
|
41
|
+
ExecWait '"$INSTDIR\${APP_EXECUTABLE_FILENAME}" --install-media' $0
|
|
42
|
+
${EndIf}
|
|
43
|
+
${If} ${Errors}
|
|
44
|
+
DetailPrint "Unable to start media installation."
|
|
45
|
+
Abort "Media installation failed."
|
|
46
|
+
${EndIf}
|
|
47
|
+
${If} $0 != 0
|
|
48
|
+
DetailPrint "Media installation failed (exit code $0)."
|
|
49
|
+
Abort "Media installation failed."
|
|
50
|
+
${EndIf}
|
|
51
|
+
!macroend
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function installMediaOnFirstLaunch(options: {
|
|
2
|
+
platform: string;
|
|
3
|
+
isPackaged: boolean;
|
|
4
|
+
isDev: boolean;
|
|
5
|
+
completed: boolean;
|
|
6
|
+
askOverwrite: () => Promise<boolean | null>;
|
|
7
|
+
install: (overwrite: boolean) => Promise<void>;
|
|
8
|
+
markCompleted: () => void;
|
|
9
|
+
}): Promise<boolean>;
|
|
@@ -5,12 +5,19 @@ export declare class MediaManager {
|
|
|
5
5
|
constructor(rootPath: string);
|
|
6
6
|
getRootPath(): string;
|
|
7
7
|
ensureDirectories(): Promise<void>;
|
|
8
|
-
seedFrom(sourceRootPath: string
|
|
8
|
+
seedFrom(sourceRootPath: string, options?: {
|
|
9
|
+
overwrite?: boolean;
|
|
10
|
+
}): Promise<void>;
|
|
9
11
|
listLibrary(): Promise<MediaLibrary>;
|
|
10
12
|
resolveMediaPath(ref: MediaRef): string;
|
|
11
13
|
resolveMediaUrl(ref: MediaRef): string;
|
|
12
14
|
private listAssetsForType;
|
|
13
15
|
}
|
|
16
|
+
export declare function createMediaManager(options: {
|
|
17
|
+
isDev: boolean;
|
|
18
|
+
sourceRootPath: string;
|
|
19
|
+
externalRootPath: string;
|
|
20
|
+
}): MediaManager;
|
|
14
21
|
export interface ByteRange {
|
|
15
22
|
end: number;
|
|
16
23
|
start: number;
|