electron-incremental-update 0.8.9 → 0.9.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/README.md CHANGED
@@ -175,7 +175,7 @@ However, you have the option to customize the download function when creating th
175
175
  ```ts
176
176
  // electron/main/index.ts
177
177
  import type { StartupWithUpdater, Updater } from 'electron-incremental-update'
178
- import { appInfo, getProductAsarPath } from 'electron-incremental-update/utils'
178
+ import { appInfo, getAppVersion, getElectronVersion, getProductAsarPath } from 'electron-incremental-update/utils'
179
179
  import { app } from 'electron'
180
180
  import { name } from '../../package.json'
181
181
 
@@ -183,8 +183,8 @@ const startup: StartupWithUpdater = (updater: Updater) => {
183
183
  await app.whenReady()
184
184
  console.log('\ncurrent:')
185
185
  console.log(`\tasar path: ${getProductAsarPath(name)}`)
186
- console.log(`\tapp: ${appInfo.appVersion(name)}`)
187
- console.log(`\telectron: ${appInfo.electronVersion}`)
186
+ console.log(`\tapp: ${getAppVersion(name)}`)
187
+ console.log(`\telectron: ${getElectronVersion()}`)
188
188
  updater.onDownloading = ({ percent }) => {
189
189
  console.log(percent)
190
190
  }
@@ -3,17 +3,16 @@ import {
3
3
  } from "./chunk-CMBFI77K.mjs";
4
4
 
5
5
  // src/utils/core.ts
6
- import { readFileSync } from "node:fs";
6
+ import { existsSync, mkdirSync, readFileSync } from "node:fs";
7
7
  import { dirname, join } from "node:path";
8
8
  import { release } from "node:os";
9
9
  import { app } from "electron";
10
10
  var DEFAULT_APP_NAME = "product";
11
- var appInfo = {
11
+ var is = {
12
12
  dev: !app.isPackaged,
13
13
  win: process.platform === "win32",
14
14
  mac: process.platform === "darwin",
15
- linux: process.platform === "linux",
16
- systemVersion: release()
15
+ linux: process.platform === "linux"
17
16
  };
18
17
  function getLocale() {
19
18
  return app.isReady() ? app.getLocale() : void 0;
@@ -45,33 +44,60 @@ function requireNative(packageName) {
45
44
  return new NoSuchNativeModuleError(packageName);
46
45
  }
47
46
  }
48
-
49
- // src/utils/utils.ts
50
- import { app as app2 } from "electron";
51
- function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
52
- if (!originRepoURL.startsWith("https://github.com/")) {
53
- throw new Error("origin url must start with https://github.com/");
47
+ function restartApp() {
48
+ app.relaunch();
49
+ app.quit();
50
+ }
51
+ function setAppUserModelId(id) {
52
+ is.win && app.setAppUserModelId(is.dev ? process.execPath : id);
53
+ }
54
+ function disableHWAccForWin7() {
55
+ if (release().startsWith("6.1")) {
56
+ app.disableHardwareAcceleration();
54
57
  }
55
- originRepoURL = originRepoURL.trim().replace(/\/?$/, "/").trim();
56
- relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
57
- cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
58
- return originRepoURL.replace("github.com", cdnPrefix) + relativeFilePath;
59
58
  }
60
- function restartApp() {
61
- app2.relaunch();
62
- app2.quit();
59
+ function singleInstance() {
60
+ if (!app.requestSingleInstanceLock()) {
61
+ app.quit();
62
+ process.exit(0);
63
+ }
64
+ }
65
+ function setPortableAppDataPath(dirName = "data", create) {
66
+ if (!is.win) {
67
+ return;
68
+ }
69
+ const portablePath = join(dirname(app.getPath("exe")), dirName);
70
+ let exists = existsSync(portablePath);
71
+ if (create && !exists) {
72
+ mkdirSync(portablePath);
73
+ exists = true;
74
+ }
75
+ if (exists) {
76
+ app.setPath("appData", portablePath);
77
+ }
63
78
  }
64
79
  function waitAppReady(timeout = 1e3) {
65
- return app2.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
80
+ return app.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
66
81
  const _ = setTimeout(() => {
67
82
  reject(new Error("app is not ready"));
68
83
  }, timeout);
69
- app2.whenReady().then(() => {
84
+ app.whenReady().then(() => {
70
85
  clearTimeout(_);
71
86
  resolve();
72
87
  });
73
88
  });
74
89
  }
90
+
91
+ // src/utils/utils.ts
92
+ function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
93
+ if (!originRepoURL.startsWith("https://github.com/")) {
94
+ throw new Error("origin url must start with https://github.com/");
95
+ }
96
+ originRepoURL = originRepoURL.trim().replace(/\/?$/, "/").trim();
97
+ relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
98
+ cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
99
+ return originRepoURL.replace("github.com", cdnPrefix) + relativeFilePath;
100
+ }
75
101
  function handleUnexpectedErrors(callback) {
76
102
  process.on("uncaughtException", callback);
77
103
  process.on("unhandledRejection", callback);
@@ -79,7 +105,7 @@ function handleUnexpectedErrors(callback) {
79
105
 
80
106
  export {
81
107
  DEFAULT_APP_NAME,
82
- appInfo,
108
+ is,
83
109
  getLocale,
84
110
  getProductAsarPath,
85
111
  getElectronVersion,
@@ -87,8 +113,12 @@ export {
87
113
  NoSuchNativeModuleError,
88
114
  isNoSuchNativeModuleError,
89
115
  requireNative,
90
- parseGithubCdnURL,
91
116
  restartApp,
117
+ setAppUserModelId,
118
+ disableHWAccForWin7,
119
+ singleInstance,
120
+ setPortableAppDataPath,
92
121
  waitAppReady,
122
+ parseGithubCdnURL,
93
123
  handleUnexpectedErrors
94
124
  };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { U as UpdateJSON } from './updateJson-7e45d9e1.js';
1
+ import { U as UpdateJSON } from './updateJson-synsK-Pt.mjs';
2
2
 
3
3
  declare class MinimumVersionError extends Error {
4
4
  currentVersion: string;
@@ -260,4 +260,4 @@ type SetUpdater = {
260
260
  */
261
261
  declare function initApp(appOptions?: AppOption): SetUpdater;
262
262
 
263
- export { AppOption, IncrementalUpdater, StartupWithUpdater, Updater, UpdaterOption, createUpdater, initApp };
263
+ export { type AppOption, IncrementalUpdater, type StartupWithUpdater, type Updater, type UpdaterOption, createUpdater, initApp };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { U as UpdateJSON } from './updateJson-7e45d9e1.js';
1
+ import { U as UpdateJSON } from './updateJson-synsK-Pt.js';
2
2
 
3
3
  declare class MinimumVersionError extends Error {
4
4
  currentVersion: string;
@@ -260,4 +260,4 @@ type SetUpdater = {
260
260
  */
261
261
  declare function initApp(appOptions?: AppOption): SetUpdater;
262
262
 
263
- export { AppOption, IncrementalUpdater, StartupWithUpdater, Updater, UpdaterOption, createUpdater, initApp };
263
+ export { type AppOption, IncrementalUpdater, type StartupWithUpdater, type Updater, type UpdaterOption, createUpdater, initApp };
package/dist/index.js CHANGED
@@ -27,7 +27,7 @@ __export(src_exports, {
27
27
  module.exports = __toCommonJS(src_exports);
28
28
  var import_node_path2 = require("path");
29
29
  var import_node_fs4 = require("fs");
30
- var import_electron4 = require("electron");
30
+ var import_electron3 = require("electron");
31
31
 
32
32
  // src/updater/index.ts
33
33
  var import_node_fs3 = require("fs");
@@ -39,12 +39,11 @@ var import_node_path = require("path");
39
39
  var import_node_os = require("os");
40
40
  var import_electron = require("electron");
41
41
  var DEFAULT_APP_NAME = "product";
42
- var appInfo = {
42
+ var is = {
43
43
  dev: !import_electron.app.isPackaged,
44
44
  win: process.platform === "win32",
45
45
  mac: process.platform === "darwin",
46
- linux: process.platform === "linux",
47
- systemVersion: (0, import_node_os.release)()
46
+ linux: process.platform === "linux"
48
47
  };
49
48
  function getProductAsarPath(name = DEFAULT_APP_NAME) {
50
49
  return !import_electron.app.isPackaged ? (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${name}.asar`) : "DEV.asar";
@@ -55,6 +54,17 @@ function getElectronVersion() {
55
54
  function getAppVersion(name = DEFAULT_APP_NAME) {
56
55
  return import_electron.app.isPackaged ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8") : getElectronVersion();
57
56
  }
57
+ function waitAppReady(timeout = 1e3) {
58
+ return import_electron.app.isReady() ? Promise.resolve() : new Promise((resolve2, reject) => {
59
+ const _ = setTimeout(() => {
60
+ reject(new Error("app is not ready"));
61
+ }, timeout);
62
+ import_electron.app.whenReady().then(() => {
63
+ clearTimeout(_);
64
+ resolve2();
65
+ });
66
+ });
67
+ }
58
68
 
59
69
  // src/utils/version.ts
60
70
  function parseVersion(version) {
@@ -102,20 +112,6 @@ async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
102
112
  });
103
113
  }
104
114
 
105
- // src/utils/utils.ts
106
- var import_electron2 = require("electron");
107
- function waitAppReady(timeout = 1e3) {
108
- return import_electron2.app.isReady() ? Promise.resolve() : new Promise((resolve2, reject) => {
109
- const _ = setTimeout(() => {
110
- reject(new Error("app is not ready"));
111
- }, timeout);
112
- import_electron2.app.whenReady().then(() => {
113
- clearTimeout(_);
114
- resolve2();
115
- });
116
- });
117
- }
118
-
119
115
  // src/crypto.ts
120
116
  var import_node_crypto = require("crypto");
121
117
  function decrypt(encryptedText, key2, iv) {
@@ -140,8 +136,8 @@ var verify = (buffer, signature, cert) => {
140
136
 
141
137
  // src/updateJson.ts
142
138
  function isUpdateJSON(json) {
143
- const is = (j) => "signature" in j && "version" in j && "size" in j && "minimumVersion" in j;
144
- return is(json) && "beta" in json && is(json.beta);
139
+ const is2 = (j) => "signature" in j && "version" in j && "size" in j && "minimumVersion" in j;
140
+ return is2(json) && "beta" in json && is2(json.beta);
145
141
  }
146
142
 
147
143
  // src/updater/types.ts
@@ -169,12 +165,12 @@ var DownloadError = class extends Error {
169
165
  }
170
166
  };
171
167
 
172
- // src/updater/defaultFunctions.ts
173
- var import_electron3 = require("electron");
168
+ // src/updater/defaultFunctions/download.ts
169
+ var import_electron2 = require("electron");
174
170
  var downloadJSONDefault = async (url, headers) => {
175
171
  await waitAppReady();
176
172
  return new Promise((resolve2, reject) => {
177
- const request = import_electron3.net.request({
173
+ const request = import_electron2.net.request({
178
174
  url,
179
175
  method: "GET",
180
176
  redirect: "follow"
@@ -208,7 +204,7 @@ var downloadBufferDefault = async (url, headers, total, onDownloading) => {
208
204
  await waitAppReady();
209
205
  let current = 0;
210
206
  return new Promise((resolve2, reject) => {
211
- const request = import_electron3.net.request({
207
+ const request = import_electron2.net.request({
212
208
  url,
213
209
  method: "GET",
214
210
  redirect: "follow"
@@ -236,6 +232,8 @@ var downloadBufferDefault = async (url, headers, total, onDownloading) => {
236
232
  request.end();
237
233
  });
238
234
  };
235
+
236
+ // src/updater/defaultFunctions/compareVersion.ts
239
237
  var compareVersionDefault = (version1, version2) => {
240
238
  const oldV = parseVersion(version1);
241
239
  const newV = parseVersion(version2);
@@ -423,7 +421,7 @@ function initApp(appOptions) {
423
421
  } = hooks || {};
424
422
  function handleError(msg) {
425
423
  onStartError?.(new Error(msg));
426
- import_electron4.app.quit();
424
+ import_electron3.app.quit();
427
425
  }
428
426
  async function startup(updater) {
429
427
  try {
@@ -433,7 +431,7 @@ function initApp(appOptions) {
433
431
  await beforeDoUpdate?.(asarPath, updateAsarPath);
434
432
  (0, import_node_fs4.renameSync)(updateAsarPath, asarPath);
435
433
  }
436
- const mainDir = import_electron4.app.isPackaged ? asarPath : electronDevDistPath;
434
+ const mainDir = import_electron3.app.isPackaged ? asarPath : electronDevDistPath;
437
435
  const entry = (0, import_node_path2.resolve)(__dirname, mainDir, mainPath);
438
436
  await beforeStart?.(entry);
439
437
  require(entry)(updater);
package/dist/index.mjs CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  getElectronVersion,
9
9
  getProductAsarPath,
10
10
  waitAppReady
11
- } from "./chunk-6V5SXFGA.mjs";
11
+ } from "./chunk-SPZL37O5.mjs";
12
12
  import {
13
13
  __require,
14
14
  parseVersion,
@@ -49,7 +49,7 @@ var DownloadError = class extends Error {
49
49
  }
50
50
  };
51
51
 
52
- // src/updater/defaultFunctions.ts
52
+ // src/updater/defaultFunctions/download.ts
53
53
  import { net } from "electron";
54
54
  var downloadJSONDefault = async (url, headers) => {
55
55
  await waitAppReady();
@@ -116,6 +116,8 @@ var downloadBufferDefault = async (url, headers, total, onDownloading) => {
116
116
  request.end();
117
117
  });
118
118
  };
119
+
120
+ // src/updater/defaultFunctions/compareVersion.ts
119
121
  var compareVersionDefault = (version1, version2) => {
120
122
  const oldV = parseVersion(version1);
121
123
  const newV = parseVersion(version2);
@@ -8,4 +8,4 @@ type UpdateJSON = UpdateInfo & {
8
8
  beta: UpdateInfo;
9
9
  };
10
10
 
11
- export { UpdateJSON as U };
11
+ export type { UpdateJSON as U };
@@ -0,0 +1,11 @@
1
+ type UpdateInfo = {
2
+ signature: string;
3
+ minimumVersion: string;
4
+ version: string;
5
+ size: number;
6
+ };
7
+ type UpdateJSON = UpdateInfo & {
8
+ beta: UpdateInfo;
9
+ };
10
+
11
+ export type { UpdateJSON as U };
package/dist/utils.d.mts CHANGED
@@ -1,18 +1,14 @@
1
1
  declare const DEFAULT_APP_NAME = "product";
2
- type Info = {
2
+ type Is = {
3
3
  dev: boolean;
4
4
  win: boolean;
5
5
  mac: boolean;
6
6
  linux: boolean;
7
- /**
8
- * `os.release()`
9
- */
10
- systemVersion: string;
11
7
  };
12
8
  /**
13
9
  * get app info
14
10
  */
15
- declare const appInfo: Info;
11
+ declare const is: Is;
16
12
  declare function getLocale(): string | undefined;
17
13
  /**
18
14
  * get the application asar absolute path (not `app.asar`),
@@ -41,6 +37,32 @@ declare function isNoSuchNativeModuleError(e: unknown): e is NoSuchNativeModuleE
41
37
  * @param packageName native package name
42
38
  */
43
39
  declare function requireNative<T = any>(packageName: string): T | NoSuchNativeModuleError;
40
+ /**
41
+ * Restarts the Electron app.
42
+ */
43
+ declare function restartApp(): void;
44
+ /**
45
+ * fix app use model id, only for Windows
46
+ * @param id app id
47
+ */
48
+ declare function setAppUserModelId(id: string): void;
49
+ /**
50
+ * disable hardware acceleration for Windows 7
51
+ */
52
+ declare function disableHWAccForWin7(): void;
53
+ /**
54
+ * keep single electron instance
55
+ */
56
+ declare function singleInstance(): void;
57
+ /**
58
+ * set AppData dir for portable Windows app
59
+ */
60
+ declare function setPortableAppDataPath(dirName?: string, create?: boolean): void;
61
+ /**
62
+ * ensure app is ready.
63
+ * @param timeout wait timeout, @default 1000
64
+ */
65
+ declare function waitAppReady(timeout?: number): Promise<void>;
44
66
 
45
67
  interface Version {
46
68
  major: number;
@@ -60,19 +82,10 @@ declare function zipFile(filePath: string, targetFilePath?: string): Promise<unk
60
82
  * {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 some public CDN links}
61
83
  */
62
84
  declare function parseGithubCdnURL(originRepoURL: string, cdnPrefix: string, relativeFilePath: string): string;
63
- /**
64
- * Restarts the Electron app.
65
- */
66
- declare function restartApp(): void;
67
- /**
68
- * ensure app is ready.
69
- * @param timeout wait timeout, @default 1000
70
- */
71
- declare function waitAppReady(timeout?: number): Promise<void>;
72
85
  /**
73
86
  * handle all unhandled error
74
87
  * @param callback callback function
75
88
  */
76
89
  declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
77
90
 
78
- export { DEFAULT_APP_NAME, NoSuchNativeModuleError, Version, appInfo, getAppVersion, getElectronVersion, getLocale, getProductAsarPath, handleUnexpectedErrors, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
91
+ export { DEFAULT_APP_NAME, NoSuchNativeModuleError, type Version, disableHWAccForWin7, getAppVersion, getElectronVersion, getLocale, getProductAsarPath, handleUnexpectedErrors, is, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance, unzipFile, waitAppReady, zipFile };
package/dist/utils.d.ts CHANGED
@@ -1,18 +1,14 @@
1
1
  declare const DEFAULT_APP_NAME = "product";
2
- type Info = {
2
+ type Is = {
3
3
  dev: boolean;
4
4
  win: boolean;
5
5
  mac: boolean;
6
6
  linux: boolean;
7
- /**
8
- * `os.release()`
9
- */
10
- systemVersion: string;
11
7
  };
12
8
  /**
13
9
  * get app info
14
10
  */
15
- declare const appInfo: Info;
11
+ declare const is: Is;
16
12
  declare function getLocale(): string | undefined;
17
13
  /**
18
14
  * get the application asar absolute path (not `app.asar`),
@@ -41,6 +37,32 @@ declare function isNoSuchNativeModuleError(e: unknown): e is NoSuchNativeModuleE
41
37
  * @param packageName native package name
42
38
  */
43
39
  declare function requireNative<T = any>(packageName: string): T | NoSuchNativeModuleError;
40
+ /**
41
+ * Restarts the Electron app.
42
+ */
43
+ declare function restartApp(): void;
44
+ /**
45
+ * fix app use model id, only for Windows
46
+ * @param id app id
47
+ */
48
+ declare function setAppUserModelId(id: string): void;
49
+ /**
50
+ * disable hardware acceleration for Windows 7
51
+ */
52
+ declare function disableHWAccForWin7(): void;
53
+ /**
54
+ * keep single electron instance
55
+ */
56
+ declare function singleInstance(): void;
57
+ /**
58
+ * set AppData dir for portable Windows app
59
+ */
60
+ declare function setPortableAppDataPath(dirName?: string, create?: boolean): void;
61
+ /**
62
+ * ensure app is ready.
63
+ * @param timeout wait timeout, @default 1000
64
+ */
65
+ declare function waitAppReady(timeout?: number): Promise<void>;
44
66
 
45
67
  interface Version {
46
68
  major: number;
@@ -60,19 +82,10 @@ declare function zipFile(filePath: string, targetFilePath?: string): Promise<unk
60
82
  * {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 some public CDN links}
61
83
  */
62
84
  declare function parseGithubCdnURL(originRepoURL: string, cdnPrefix: string, relativeFilePath: string): string;
63
- /**
64
- * Restarts the Electron app.
65
- */
66
- declare function restartApp(): void;
67
- /**
68
- * ensure app is ready.
69
- * @param timeout wait timeout, @default 1000
70
- */
71
- declare function waitAppReady(timeout?: number): Promise<void>;
72
85
  /**
73
86
  * handle all unhandled error
74
87
  * @param callback callback function
75
88
  */
76
89
  declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
77
90
 
78
- export { DEFAULT_APP_NAME, NoSuchNativeModuleError, Version, appInfo, getAppVersion, getElectronVersion, getLocale, getProductAsarPath, handleUnexpectedErrors, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
91
+ export { DEFAULT_APP_NAME, NoSuchNativeModuleError, type Version, disableHWAccForWin7, getAppVersion, getElectronVersion, getLocale, getProductAsarPath, handleUnexpectedErrors, is, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance, unzipFile, waitAppReady, zipFile };
package/dist/utils.js CHANGED
@@ -22,17 +22,21 @@ var utils_exports = {};
22
22
  __export(utils_exports, {
23
23
  DEFAULT_APP_NAME: () => DEFAULT_APP_NAME,
24
24
  NoSuchNativeModuleError: () => NoSuchNativeModuleError,
25
- appInfo: () => appInfo,
25
+ disableHWAccForWin7: () => disableHWAccForWin7,
26
26
  getAppVersion: () => getAppVersion,
27
27
  getElectronVersion: () => getElectronVersion,
28
28
  getLocale: () => getLocale,
29
29
  getProductAsarPath: () => getProductAsarPath,
30
30
  handleUnexpectedErrors: () => handleUnexpectedErrors,
31
+ is: () => is,
31
32
  isNoSuchNativeModuleError: () => isNoSuchNativeModuleError,
32
33
  parseGithubCdnURL: () => parseGithubCdnURL,
33
34
  parseVersion: () => parseVersion,
34
35
  requireNative: () => requireNative,
35
36
  restartApp: () => restartApp,
37
+ setAppUserModelId: () => setAppUserModelId,
38
+ setPortableAppDataPath: () => setPortableAppDataPath,
39
+ singleInstance: () => singleInstance,
36
40
  unzipFile: () => unzipFile,
37
41
  waitAppReady: () => waitAppReady,
38
42
  zipFile: () => zipFile
@@ -45,12 +49,11 @@ var import_node_path = require("path");
45
49
  var import_node_os = require("os");
46
50
  var import_electron = require("electron");
47
51
  var DEFAULT_APP_NAME = "product";
48
- var appInfo = {
52
+ var is = {
49
53
  dev: !import_electron.app.isPackaged,
50
54
  win: process.platform === "win32",
51
55
  mac: process.platform === "darwin",
52
- linux: process.platform === "linux",
53
- systemVersion: (0, import_node_os.release)()
56
+ linux: process.platform === "linux"
54
57
  };
55
58
  function getLocale() {
56
59
  return import_electron.app.isReady() ? import_electron.app.getLocale() : void 0;
@@ -82,6 +85,49 @@ function requireNative(packageName) {
82
85
  return new NoSuchNativeModuleError(packageName);
83
86
  }
84
87
  }
88
+ function restartApp() {
89
+ import_electron.app.relaunch();
90
+ import_electron.app.quit();
91
+ }
92
+ function setAppUserModelId(id) {
93
+ is.win && import_electron.app.setAppUserModelId(is.dev ? process.execPath : id);
94
+ }
95
+ function disableHWAccForWin7() {
96
+ if ((0, import_node_os.release)().startsWith("6.1")) {
97
+ import_electron.app.disableHardwareAcceleration();
98
+ }
99
+ }
100
+ function singleInstance() {
101
+ if (!import_electron.app.requestSingleInstanceLock()) {
102
+ import_electron.app.quit();
103
+ process.exit(0);
104
+ }
105
+ }
106
+ function setPortableAppDataPath(dirName = "data", create) {
107
+ if (!is.win) {
108
+ return;
109
+ }
110
+ const portablePath = (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getPath("exe")), dirName);
111
+ let exists = (0, import_node_fs.existsSync)(portablePath);
112
+ if (create && !exists) {
113
+ (0, import_node_fs.mkdirSync)(portablePath);
114
+ exists = true;
115
+ }
116
+ if (exists) {
117
+ import_electron.app.setPath("appData", portablePath);
118
+ }
119
+ }
120
+ function waitAppReady(timeout = 1e3) {
121
+ return import_electron.app.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
122
+ const _ = setTimeout(() => {
123
+ reject(new Error("app is not ready"));
124
+ }, timeout);
125
+ import_electron.app.whenReady().then(() => {
126
+ clearTimeout(_);
127
+ resolve();
128
+ });
129
+ });
130
+ }
85
131
 
86
132
  // src/utils/version.ts
87
133
  function parseVersion(version) {
@@ -145,7 +191,6 @@ async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
145
191
  }
146
192
 
147
193
  // src/utils/utils.ts
148
- var import_electron2 = require("electron");
149
194
  function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
150
195
  if (!originRepoURL.startsWith("https://github.com/")) {
151
196
  throw new Error("origin url must start with https://github.com/");
@@ -155,21 +200,6 @@ function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
155
200
  cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
156
201
  return originRepoURL.replace("github.com", cdnPrefix) + relativeFilePath;
157
202
  }
158
- function restartApp() {
159
- import_electron2.app.relaunch();
160
- import_electron2.app.quit();
161
- }
162
- function waitAppReady(timeout = 1e3) {
163
- return import_electron2.app.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
164
- const _ = setTimeout(() => {
165
- reject(new Error("app is not ready"));
166
- }, timeout);
167
- import_electron2.app.whenReady().then(() => {
168
- clearTimeout(_);
169
- resolve();
170
- });
171
- });
172
- }
173
203
  function handleUnexpectedErrors(callback) {
174
204
  process.on("uncaughtException", callback);
175
205
  process.on("unhandledRejection", callback);
@@ -178,17 +208,21 @@ function handleUnexpectedErrors(callback) {
178
208
  0 && (module.exports = {
179
209
  DEFAULT_APP_NAME,
180
210
  NoSuchNativeModuleError,
181
- appInfo,
211
+ disableHWAccForWin7,
182
212
  getAppVersion,
183
213
  getElectronVersion,
184
214
  getLocale,
185
215
  getProductAsarPath,
186
216
  handleUnexpectedErrors,
217
+ is,
187
218
  isNoSuchNativeModuleError,
188
219
  parseGithubCdnURL,
189
220
  parseVersion,
190
221
  requireNative,
191
222
  restartApp,
223
+ setAppUserModelId,
224
+ setPortableAppDataPath,
225
+ singleInstance,
192
226
  unzipFile,
193
227
  waitAppReady,
194
228
  zipFile
package/dist/utils.mjs CHANGED
@@ -1,18 +1,22 @@
1
1
  import {
2
2
  DEFAULT_APP_NAME,
3
3
  NoSuchNativeModuleError,
4
- appInfo,
4
+ disableHWAccForWin7,
5
5
  getAppVersion,
6
6
  getElectronVersion,
7
7
  getLocale,
8
8
  getProductAsarPath,
9
9
  handleUnexpectedErrors,
10
+ is,
10
11
  isNoSuchNativeModuleError,
11
12
  parseGithubCdnURL,
12
13
  requireNative,
13
14
  restartApp,
15
+ setAppUserModelId,
16
+ setPortableAppDataPath,
17
+ singleInstance,
14
18
  waitAppReady
15
- } from "./chunk-6V5SXFGA.mjs";
19
+ } from "./chunk-SPZL37O5.mjs";
16
20
  import {
17
21
  parseVersion,
18
22
  unzipFile,
@@ -21,17 +25,21 @@ import {
21
25
  export {
22
26
  DEFAULT_APP_NAME,
23
27
  NoSuchNativeModuleError,
24
- appInfo,
28
+ disableHWAccForWin7,
25
29
  getAppVersion,
26
30
  getElectronVersion,
27
31
  getLocale,
28
32
  getProductAsarPath,
29
33
  handleUnexpectedErrors,
34
+ is,
30
35
  isNoSuchNativeModuleError,
31
36
  parseGithubCdnURL,
32
37
  parseVersion,
33
38
  requireNative,
34
39
  restartApp,
40
+ setAppUserModelId,
41
+ setPortableAppDataPath,
42
+ singleInstance,
35
43
  unzipFile,
36
44
  waitAppReady,
37
45
  zipFile
package/dist/vite.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from 'vite';
2
- import { U as UpdateJSON } from './updateJson-7e45d9e1.js';
2
+ import { U as UpdateJSON } from './updateJson-synsK-Pt.mjs';
3
3
 
4
4
  type DistinguishedName = {
5
5
  countryName?: string;
@@ -146,4 +146,4 @@ type Options = {
146
146
 
147
147
  declare function ElectronUpdater(options: Options): Plugin;
148
148
 
149
- export { ElectronUpdater, Options };
149
+ export { ElectronUpdater, type Options };
package/dist/vite.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from 'vite';
2
- import { U as UpdateJSON } from './updateJson-7e45d9e1.js';
2
+ import { U as UpdateJSON } from './updateJson-synsK-Pt.js';
3
3
 
4
4
  type DistinguishedName = {
5
5
  countryName?: string;
@@ -146,4 +146,4 @@ type Options = {
146
146
 
147
147
  declare function ElectronUpdater(options: Options): Plugin;
148
148
 
149
- export { ElectronUpdater, Options };
149
+ export { ElectronUpdater, type Options };
package/dist/vite.js CHANGED
@@ -195,9 +195,13 @@ var import_node_path = require("path");
195
195
  var import_selfsigned = require("selfsigned");
196
196
  function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
197
197
  const privateKeyDir = (0, import_node_path.dirname)(privateKeyPath);
198
- (0, import_node_fs3.existsSync)(privateKeyDir) || (0, import_node_fs3.mkdirSync)(privateKeyDir, { recursive: true });
198
+ if (!(0, import_node_fs3.existsSync)(privateKeyDir)) {
199
+ (0, import_node_fs3.mkdirSync)(privateKeyDir, { recursive: true });
200
+ }
199
201
  const certDir = (0, import_node_path.dirname)(certPath);
200
- (0, import_node_fs3.existsSync)(certDir) || (0, import_node_fs3.mkdirSync)(certDir, { recursive: true });
202
+ if (!(0, import_node_fs3.existsSync)(certDir)) {
203
+ (0, import_node_fs3.mkdirSync)(certDir, { recursive: true });
204
+ }
201
205
  const { cert, private: privateKey } = (0, import_selfsigned.generate)(subject, {
202
206
  keySize: keyLength,
203
207
  algorithm: "sha256",
@@ -211,7 +215,7 @@ function writeCertToMain(entryPath, cert) {
211
215
  const initRegex = /(?<=const SIGNATURE_CERT\s*=\s*)['"]{2}/m;
212
216
  const existRegex = /(?<=const SIGNATURE_CERT\s*=\s*)(['"]-----BEGIN CERTIFICATE-----[\s\S]*-----END CERTIFICATE-----\\n['"])/m;
213
217
  const eol = file.includes("\r") ? "\r\n" : "\n";
214
- const replacement = cert.split("\n").filter(Boolean).map((s) => `'${s}\\n'`).join(`${eol}+ `);
218
+ const replacement = cert.split("\n").filter(Boolean).map((s) => `'${s}\\n'`).join(`${eol} + `);
215
219
  let replaced = file;
216
220
  if (initRegex.test(file)) {
217
221
  replaced = file.replace(initRegex, replacement);
package/dist/vite.mjs CHANGED
@@ -100,9 +100,13 @@ import { dirname } from "node:path";
100
100
  import { generate } from "selfsigned";
101
101
  function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
102
102
  const privateKeyDir = dirname(privateKeyPath);
103
- existsSync2(privateKeyDir) || mkdirSync(privateKeyDir, { recursive: true });
103
+ if (!existsSync2(privateKeyDir)) {
104
+ mkdirSync(privateKeyDir, { recursive: true });
105
+ }
104
106
  const certDir = dirname(certPath);
105
- existsSync2(certDir) || mkdirSync(certDir, { recursive: true });
107
+ if (!existsSync2(certDir)) {
108
+ mkdirSync(certDir, { recursive: true });
109
+ }
106
110
  const { cert, private: privateKey } = generate(subject, {
107
111
  keySize: keyLength,
108
112
  algorithm: "sha256",
@@ -116,7 +120,7 @@ function writeCertToMain(entryPath, cert) {
116
120
  const initRegex = /(?<=const SIGNATURE_CERT\s*=\s*)['"]{2}/m;
117
121
  const existRegex = /(?<=const SIGNATURE_CERT\s*=\s*)(['"]-----BEGIN CERTIFICATE-----[\s\S]*-----END CERTIFICATE-----\\n['"])/m;
118
122
  const eol = file.includes("\r") ? "\r\n" : "\n";
119
- const replacement = cert.split("\n").filter(Boolean).map((s) => `'${s}\\n'`).join(`${eol}+ `);
123
+ const replacement = cert.split("\n").filter(Boolean).map((s) => `'${s}\\n'`).join(`${eol} + `);
120
124
  let replaced = file;
121
125
  if (initRegex.test(file)) {
122
126
  replaced = file.replace(initRegex, replacement);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electron-incremental-update",
3
- "version": "0.8.9",
3
+ "version": "0.9.1",
4
4
  "description": "electron incremental update tools, powered by vite",
5
5
  "author": "subframe7536",
6
6
  "license": "MIT",
@@ -34,6 +34,7 @@
34
34
  "vite.js"
35
35
  ],
36
36
  "scripts": {
37
+ "dev": "tsup --watch",
37
38
  "build": "tsup && node fix-module.js",
38
39
  "release": "pnpm test && pnpm run build && bumpp --all && npm publish",
39
40
  "test": "vitest --run",
@@ -43,20 +44,23 @@
43
44
  "access": "public",
44
45
  "registry": "https://registry.npmjs.org/"
45
46
  },
47
+ "peerDependencies": {
48
+ "esbuild": "*"
49
+ },
46
50
  "dependencies": {
47
51
  "@electron/asar": "^3.2.8",
48
52
  "ci-info": "^4.0.0",
49
- "selfsigned": "^2.4.1",
50
- "vite": "^4.5.0"
53
+ "selfsigned": "^2.4.1"
51
54
  },
52
55
  "devDependencies": {
53
- "@subframe7536/eslint-config": "^0.4.1",
54
- "@types/node": "^20.9.0",
56
+ "@subframe7536/eslint-config": "^0.5.2",
57
+ "@types/node": "^20.10.1",
55
58
  "bumpp": "^9.2.0",
56
- "electron": "^27.0.4",
57
- "eslint": "^8.53.0",
58
- "tsup": "^7.2.0",
59
- "typescript": "^5.2.2",
59
+ "electron": "^27.1.2",
60
+ "eslint": "^8.54.0",
61
+ "tsup": "^8.0.1",
62
+ "typescript": "^5.3.2",
63
+ "vite": "^5.0.4",
60
64
  "vitest": "^0.34.6"
61
65
  }
62
66
  }