key-screen-framework 1.3.0 → 1.4.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/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
@@ -1170,6 +1170,12 @@ class MediaManager {
1170
1170
  if (!sourceRoot.isDirectory()) {
1171
1171
  throw new Error("Media source root must be a directory.");
1172
1172
  }
1173
+ if (options.overwrite) {
1174
+ if (isInsideDirectory(this.rootPath, sourceRootPath)) {
1175
+ throw new Error("Media source root must be outside of the media cleanup directory.");
1176
+ }
1177
+ await rm(this.rootPath, { recursive: true, force: true });
1178
+ }
1173
1179
  await this.ensureDirectories();
1174
1180
  await Promise.all(
1175
1181
  MEDIA_TYPES.map(async (type) => {
@@ -1461,8 +1467,16 @@ function resolveMainRuntimePaths(overrides, context) {
1461
1467
  defaultMediaRoot: overrides?.defaultMediaRoot ?? defaultMediaRoot
1462
1468
  };
1463
1469
  }
1470
+ async function getMediaInstallationId(executablePath) {
1471
+ const file = await stat(executablePath, { bigint: true });
1472
+ return ["v1", file.dev, file.ino, file.birthtimeNs, file.mtimeNs, file.size].join(":");
1473
+ }
1464
1474
  async function installMediaOnFirstLaunch(options) {
1465
- if (options.platform !== "darwin" || !options.isPackaged || options.isDev || options.completed) {
1475
+ if (options.platform !== "darwin" || !options.isPackaged || options.isDev) {
1476
+ return true;
1477
+ }
1478
+ const installationId = await options.getInstallationId();
1479
+ if (options.completedInstallationId === installationId) {
1466
1480
  return true;
1467
1481
  }
1468
1482
  const overwrite = await options.askOverwrite();
@@ -1470,7 +1484,7 @@ async function installMediaOnFirstLaunch(options) {
1470
1484
  return false;
1471
1485
  }
1472
1486
  await options.install(overwrite);
1473
- options.markCompleted();
1487
+ options.markCompleted(installationId);
1474
1488
  return true;
1475
1489
  }
1476
1490
  const requireMainDependency = createRequire(import.meta.url);
@@ -1956,13 +1970,14 @@ function startKeyScreenMain(options) {
1956
1970
  platform: process.platform,
1957
1971
  isPackaged: app.isPackaged,
1958
1972
  isDev,
1959
- completed: store.get("mediaInstallationCompleted", false),
1973
+ completedInstallationId: store.get("mediaInstallationId"),
1974
+ getInstallationId: () => getMediaInstallationId(app.getPath("exe")),
1960
1975
  askOverwrite: async () => {
1961
1976
  const result = await dialog.showMessageBox({
1962
1977
  type: "question",
1963
1978
  title: "리소스 설치 옵션",
1964
1979
  message: "최초 실행에 필요한 media 리소스를 설치합니다.",
1965
- detail: "기본값은 기존 파일 보존입니다. 덮어쓰기를 선택하면 같은 이름의 파일을 앱에 포함된 media 파일로 교체합니다. 사용자 추가 파일은 유지됩니다.",
1980
+ detail: "기본값은 기존 파일 보존입니다. 덮어쓰기를 선택하면 사용자 추가 파일을 포함한 기존 media 폴더의 모든 파일을 삭제한 뒤 앱에 포함된 리소스를 설치합니다.",
1966
1981
  checkboxLabel: "기존 리소스 덮어쓰기",
1967
1982
  checkboxChecked: false,
1968
1983
  buttons: ["리소스 설치", "종료"],
@@ -1972,7 +1987,7 @@ function startKeyScreenMain(options) {
1972
1987
  return result.response === 0 ? result.checkboxChecked : null;
1973
1988
  },
1974
1989
  install: (overwrite) => mediaManager.seedFrom(runtimePaths.defaultMediaRoot, { overwrite }),
1975
- markCompleted: () => store.set("mediaInstallationCompleted", true)
1990
+ markCompleted: (installationId) => store.set("mediaInstallationId", installationId)
1976
1991
  });
1977
1992
  if (!ready) {
1978
1993
  app.quit();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "key-screen-framework",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
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"
@@ -49,7 +49,7 @@
49
49
  "nsis": {
50
50
  "oneClick": false,
51
51
  "allowToChangeInstallationDirectory": true,
52
- "include": "build/installer.nsh"
52
+ "include": "node_modules/key-screen-framework/installer.nsh"
53
53
  },
54
54
  "win": {
55
55
  "icon": "build/favicon.ico",
@@ -1,9 +1,11 @@
1
+ export declare function getMediaInstallationId(executablePath: string): Promise<string>;
1
2
  export declare function installMediaOnFirstLaunch(options: {
2
3
  platform: string;
3
4
  isPackaged: boolean;
4
5
  isDev: boolean;
5
- completed: boolean;
6
+ completedInstallationId?: string;
7
+ getInstallationId: () => Promise<string>;
6
8
  askOverwrite: () => Promise<boolean | null>;
7
9
  install: (overwrite: boolean) => Promise<void>;
8
- markCompleted: () => void;
10
+ markCompleted: (installationId: string) => void;
9
11
  }): Promise<boolean>;
@@ -1,51 +0,0 @@
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