key-screen-framework 1.2.2 → 1.3.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/installer.nsh ADDED
@@ -0,0 +1,90 @@
1
+ ; Public NSIS integration for key-screen-framework.
2
+ ; Define KEY_SCREEN_MANUAL_HOOKS before including to compose existing hooks.
3
+ !ifndef KEY_SCREEN_INSTALLER_INCLUDED
4
+ !define KEY_SCREEN_INSTALLER_INCLUDED
5
+
6
+ !ifndef BUILD_UNINSTALLER
7
+ !include nsDialogs.nsh
8
+ Var keyScreenMediaOverwriteCheckbox
9
+ Var keyScreenMediaOverwriteSelected
10
+
11
+ !macro KeyScreenMediaPage
12
+ Page custom KeyScreenMediaOptionsCreate KeyScreenMediaOptionsLeave
13
+
14
+ Function KeyScreenMediaOptionsCreate
15
+ !insertmacro MUI_HEADER_TEXT "리소스 설치 옵션" "기존 media 파일을 덮어쓸지 선택하세요."
16
+ nsDialogs::Create 1018
17
+ Pop $0
18
+ ${If} $0 == error
19
+ Abort
20
+ ${EndIf}
21
+
22
+ ${NSD_CreateLabel} 0 0 100% 36u "기본값은 기존 파일 보존입니다. 덮어쓰기를 선택하면 같은 이름의 파일을 인스톨러에 포함된 media 파일로 교체합니다."
23
+ Pop $0
24
+ ${NSD_CreateCheckbox} 0 44u 100% 20u "기존 리소스 덮어쓰기"
25
+ Pop $keyScreenMediaOverwriteCheckbox
26
+ ${If} $keyScreenMediaOverwriteSelected == ${BST_CHECKED}
27
+ ${NSD_SetState} $keyScreenMediaOverwriteCheckbox ${BST_CHECKED}
28
+ ${Else}
29
+ ${NSD_SetState} $keyScreenMediaOverwriteCheckbox ${BST_UNCHECKED}
30
+ ${EndIf}
31
+ nsDialogs::Show
32
+ FunctionEnd
33
+
34
+ Function KeyScreenMediaOptionsLeave
35
+ ${NSD_GetState} $keyScreenMediaOverwriteCheckbox $keyScreenMediaOverwriteSelected
36
+ FunctionEnd
37
+ !macroend
38
+ !endif
39
+
40
+ !macro KeyScreenInstallMedia
41
+ Push $0
42
+ !ifmacrodef KeyScreenBeforeMediaInstall
43
+ !insertmacro KeyScreenBeforeMediaInstall
44
+ !endif
45
+ DetailPrint "Installing default media..."
46
+ ClearErrors
47
+ ${If} $keyScreenMediaOverwriteSelected == ${BST_CHECKED}
48
+ ExecWait '"$INSTDIR\${APP_EXECUTABLE_FILENAME}" --install-media --overwrite-media' $0
49
+ ${Else}
50
+ ExecWait '"$INSTDIR\${APP_EXECUTABLE_FILENAME}" --install-media' $0
51
+ ${EndIf}
52
+ ${If} ${Errors}
53
+ DetailPrint "Unable to start media installation."
54
+ Abort "Media installation failed."
55
+ ${EndIf}
56
+ ${If} $0 != 0
57
+ DetailPrint "Media installation failed (exit code $0)."
58
+ Abort "Media installation failed."
59
+ ${EndIf}
60
+ !ifmacrodef KeyScreenAfterMediaInstall
61
+ !insertmacro KeyScreenAfterMediaInstall
62
+ !endif
63
+ Pop $0
64
+ !macroend
65
+
66
+ !ifndef KEY_SCREEN_MANUAL_HOOKS
67
+ !ifndef BUILD_UNINSTALLER
68
+ !ifmacrodef customPageAfterChangeDir
69
+ !error "customPageAfterChangeDir already exists. Define KEY_SCREEN_MANUAL_HOOKS and insert KeyScreenMediaPage in your hook."
70
+ !endif
71
+ !macro customPageAfterChangeDir
72
+ !ifmacrodef KeyScreenBeforeMediaPage
73
+ !insertmacro KeyScreenBeforeMediaPage
74
+ !endif
75
+ !insertmacro KeyScreenMediaPage
76
+ !ifmacrodef KeyScreenAfterMediaPage
77
+ !insertmacro KeyScreenAfterMediaPage
78
+ !endif
79
+ !macroend
80
+
81
+ !ifmacrodef customInstall
82
+ !error "customInstall already exists. Define KEY_SCREEN_MANUAL_HOOKS and insert KeyScreenInstallMedia in your hook."
83
+ !endif
84
+ !macro customInstall
85
+ !insertmacro KeyScreenInstallMedia
86
+ !macroend
87
+ !endif
88
+ !endif
89
+
90
+ !endif
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
- const mediaManager = new MediaManager(join(app.getPath("userData"), "media"));
1914
- await mediaManager.ensureDirectories();
1915
- await mediaManager.seedFrom(runtimePaths.defaultMediaRoot);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "key-screen-framework",
3
- "version": "1.2.2",
3
+ "version": "1.3.1",
4
4
  "description": "Screen framework for Keyescape desktop projects.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -44,6 +44,7 @@
44
44
  "import": "./shared/index.js"
45
45
  },
46
46
  "./package.json": "./package.json",
47
+ "./installer.nsh": "./installer.nsh",
47
48
  "./shared/types": {
48
49
  "types": "./types/shared/types.d.ts",
49
50
  "import": "./shared/types.js"
@@ -73,7 +74,8 @@
73
74
  "chunks",
74
75
  "types",
75
76
  "cli",
76
- "templates"
77
+ "templates",
78
+ "installer.nsh"
77
79
  ],
78
80
  "sideEffects": [
79
81
  "**/*.css"
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: "외부 리소스 파일이 없습니다. 폴더를 열고 `image`, `video`, `audio`, `font` 하위 폴더에 파일을 추가하세요." }) : /* @__PURE__ */ jsxs("div", { className: "overflow-hidden rounded-lg border border-border-soft", 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: "파일" }),
@@ -48,7 +48,8 @@
48
48
  ],
49
49
  "nsis": {
50
50
  "oneClick": false,
51
- "allowToChangeInstallationDirectory": true
51
+ "allowToChangeInstallationDirectory": true,
52
+ "include": "node_modules/key-screen-framework/installer.nsh"
52
53
  },
53
54
  "win": {
54
55
  "icon": "build/favicon.ico",
@@ -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): Promise<void>;
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;