electron-incremental-update 0.8.9 → 0.9.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/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
  }
@@ -5,15 +5,13 @@ import {
5
5
  // src/utils/core.ts
6
6
  import { readFileSync } from "node:fs";
7
7
  import { dirname, join } from "node:path";
8
- import { release } from "node:os";
9
8
  import { app } from "electron";
10
9
  var DEFAULT_APP_NAME = "product";
11
- var appInfo = {
10
+ var is = {
12
11
  dev: !app.isPackaged,
13
12
  win: process.platform === "win32",
14
13
  mac: process.platform === "darwin",
15
- linux: process.platform === "linux",
16
- systemVersion: release()
14
+ linux: process.platform === "linux"
17
15
  };
18
16
  function getLocale() {
19
17
  return app.isReady() ? app.getLocale() : void 0;
@@ -47,6 +45,8 @@ function requireNative(packageName) {
47
45
  }
48
46
 
49
47
  // src/utils/utils.ts
48
+ import { dirname as dirname2, join as join2 } from "node:path";
49
+ import { existsSync, mkdirSync } from "node:fs";
50
50
  import { app as app2 } from "electron";
51
51
  function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
52
52
  if (!originRepoURL.startsWith("https://github.com/")) {
@@ -61,6 +61,23 @@ function restartApp() {
61
61
  app2.relaunch();
62
62
  app2.quit();
63
63
  }
64
+ function setAppUserModelId(id) {
65
+ is.win && app2.setAppUserModelId(is.dev ? process.execPath : id);
66
+ }
67
+ function setPortableAppDataPath(dirName = "data", create) {
68
+ if (!is.win) {
69
+ return;
70
+ }
71
+ const portablePath = join2(dirname2(app2.getPath("exe")), dirName);
72
+ let exists = existsSync(portablePath);
73
+ if (create && !exists) {
74
+ mkdirSync(portablePath);
75
+ exists = true;
76
+ }
77
+ if (exists) {
78
+ app2.setPath("appData", portablePath);
79
+ }
80
+ }
64
81
  function waitAppReady(timeout = 1e3) {
65
82
  return app2.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
66
83
  const _ = setTimeout(() => {
@@ -79,7 +96,7 @@ function handleUnexpectedErrors(callback) {
79
96
 
80
97
  export {
81
98
  DEFAULT_APP_NAME,
82
- appInfo,
99
+ is,
83
100
  getLocale,
84
101
  getProductAsarPath,
85
102
  getElectronVersion,
@@ -89,6 +106,8 @@ export {
89
106
  requireNative,
90
107
  parseGithubCdnURL,
91
108
  restartApp,
109
+ setAppUserModelId,
110
+ setPortableAppDataPath,
92
111
  waitAppReady,
93
112
  handleUnexpectedErrors
94
113
  };
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
@@ -25,26 +25,24 @@ __export(src_exports, {
25
25
  initApp: () => initApp
26
26
  });
27
27
  module.exports = __toCommonJS(src_exports);
28
- var import_node_path2 = require("path");
29
- var import_node_fs4 = require("fs");
28
+ var import_node_path3 = require("path");
29
+ var import_node_fs5 = require("fs");
30
30
  var import_electron4 = require("electron");
31
31
 
32
32
  // src/updater/index.ts
33
- var import_node_fs3 = require("fs");
33
+ var import_node_fs4 = require("fs");
34
34
  var import_promises = require("fs/promises");
35
35
 
36
36
  // src/utils/core.ts
37
37
  var import_node_fs = require("fs");
38
38
  var import_node_path = require("path");
39
- var import_node_os = require("os");
40
39
  var import_electron = require("electron");
41
40
  var DEFAULT_APP_NAME = "product";
42
- var appInfo = {
41
+ var is = {
43
42
  dev: !import_electron.app.isPackaged,
44
43
  win: process.platform === "win32",
45
44
  mac: process.platform === "darwin",
46
- linux: process.platform === "linux",
47
- systemVersion: (0, import_node_os.release)()
45
+ linux: process.platform === "linux"
48
46
  };
49
47
  function getProductAsarPath(name = DEFAULT_APP_NAME) {
50
48
  return !import_electron.app.isPackaged ? (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${name}.asar`) : "DEV.asar";
@@ -103,6 +101,8 @@ async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
103
101
  }
104
102
 
105
103
  // src/utils/utils.ts
104
+ var import_node_path2 = require("path");
105
+ var import_node_fs3 = require("fs");
106
106
  var import_electron2 = require("electron");
107
107
  function waitAppReady(timeout = 1e3) {
108
108
  return import_electron2.app.isReady() ? Promise.resolve() : new Promise((resolve2, reject) => {
@@ -140,8 +140,8 @@ var verify = (buffer, signature, cert) => {
140
140
 
141
141
  // src/updateJson.ts
142
142
  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);
143
+ const is2 = (j) => "signature" in j && "version" in j && "size" in j && "minimumVersion" in j;
144
+ return is2(json) && "beta" in json && is2(json.beta);
145
145
  }
146
146
 
147
147
  // src/updater/types.ts
@@ -295,11 +295,11 @@ var IncrementalUpdater = class {
295
295
  return await compare(productVersion, version);
296
296
  }
297
297
  async parseData(format, data) {
298
- if ((0, import_node_fs3.existsSync)(this.tmpFilePath)) {
298
+ if ((0, import_node_fs4.existsSync)(this.tmpFilePath)) {
299
299
  this.logger?.warn(`remove tmp file: ${this.tmpFilePath}`);
300
300
  await (0, import_promises.rm)(this.tmpFilePath);
301
301
  }
302
- if ((0, import_node_fs3.existsSync)(this.gzipPath)) {
302
+ if ((0, import_node_fs4.existsSync)(this.gzipPath)) {
303
303
  this.logger?.warn(`remove .gz file: ${this.gzipPath}`);
304
304
  await (0, import_promises.rm)(this.gzipPath);
305
305
  }
@@ -429,12 +429,12 @@ function initApp(appOptions) {
429
429
  try {
430
430
  const asarPath = getProductAsarPath(updater.productName);
431
431
  const updateAsarPath = `${asarPath}.tmp`;
432
- if ((0, import_node_fs4.existsSync)(updateAsarPath)) {
432
+ if ((0, import_node_fs5.existsSync)(updateAsarPath)) {
433
433
  await beforeDoUpdate?.(asarPath, updateAsarPath);
434
- (0, import_node_fs4.renameSync)(updateAsarPath, asarPath);
434
+ (0, import_node_fs5.renameSync)(updateAsarPath, asarPath);
435
435
  }
436
436
  const mainDir = import_electron4.app.isPackaged ? asarPath : electronDevDistPath;
437
- const entry = (0, import_node_path2.resolve)(__dirname, mainDir, mainPath);
437
+ const entry = (0, import_node_path3.resolve)(__dirname, mainDir, mainPath);
438
438
  await beforeStart?.(entry);
439
439
  require(entry)(updater);
440
440
  } catch (error) {
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-6UZHBPFT.mjs";
12
12
  import {
13
13
  __require,
14
14
  parseVersion,
@@ -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`),
@@ -64,6 +60,15 @@ declare function parseGithubCdnURL(originRepoURL: string, cdnPrefix: string, rel
64
60
  * Restarts the Electron app.
65
61
  */
66
62
  declare function restartApp(): void;
63
+ /**
64
+ * fix app use model id, only for Windows
65
+ * @param id app id
66
+ */
67
+ declare function setAppUserModelId(id: string): void;
68
+ /**
69
+ * set AppData dir for portable Windows app
70
+ */
71
+ declare function setPortableAppDataPath(dirName?: string, create?: boolean): void;
67
72
  /**
68
73
  * ensure app is ready.
69
74
  * @param timeout wait timeout, @default 1000
@@ -75,4 +80,4 @@ declare function waitAppReady(timeout?: number): Promise<void>;
75
80
  */
76
81
  declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
77
82
 
78
- export { DEFAULT_APP_NAME, NoSuchNativeModuleError, Version, appInfo, getAppVersion, getElectronVersion, getLocale, getProductAsarPath, handleUnexpectedErrors, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
83
+ export { DEFAULT_APP_NAME, NoSuchNativeModuleError, type Version, getAppVersion, getElectronVersion, getLocale, getProductAsarPath, handleUnexpectedErrors, is, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, 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`),
@@ -64,6 +60,15 @@ declare function parseGithubCdnURL(originRepoURL: string, cdnPrefix: string, rel
64
60
  * Restarts the Electron app.
65
61
  */
66
62
  declare function restartApp(): void;
63
+ /**
64
+ * fix app use model id, only for Windows
65
+ * @param id app id
66
+ */
67
+ declare function setAppUserModelId(id: string): void;
68
+ /**
69
+ * set AppData dir for portable Windows app
70
+ */
71
+ declare function setPortableAppDataPath(dirName?: string, create?: boolean): void;
67
72
  /**
68
73
  * ensure app is ready.
69
74
  * @param timeout wait timeout, @default 1000
@@ -75,4 +80,4 @@ declare function waitAppReady(timeout?: number): Promise<void>;
75
80
  */
76
81
  declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
77
82
 
78
- export { DEFAULT_APP_NAME, NoSuchNativeModuleError, Version, appInfo, getAppVersion, getElectronVersion, getLocale, getProductAsarPath, handleUnexpectedErrors, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
83
+ export { DEFAULT_APP_NAME, NoSuchNativeModuleError, type Version, getAppVersion, getElectronVersion, getLocale, getProductAsarPath, handleUnexpectedErrors, is, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, unzipFile, waitAppReady, zipFile };
package/dist/utils.js CHANGED
@@ -22,17 +22,19 @@ var utils_exports = {};
22
22
  __export(utils_exports, {
23
23
  DEFAULT_APP_NAME: () => DEFAULT_APP_NAME,
24
24
  NoSuchNativeModuleError: () => NoSuchNativeModuleError,
25
- appInfo: () => appInfo,
26
25
  getAppVersion: () => getAppVersion,
27
26
  getElectronVersion: () => getElectronVersion,
28
27
  getLocale: () => getLocale,
29
28
  getProductAsarPath: () => getProductAsarPath,
30
29
  handleUnexpectedErrors: () => handleUnexpectedErrors,
30
+ is: () => is,
31
31
  isNoSuchNativeModuleError: () => isNoSuchNativeModuleError,
32
32
  parseGithubCdnURL: () => parseGithubCdnURL,
33
33
  parseVersion: () => parseVersion,
34
34
  requireNative: () => requireNative,
35
35
  restartApp: () => restartApp,
36
+ setAppUserModelId: () => setAppUserModelId,
37
+ setPortableAppDataPath: () => setPortableAppDataPath,
36
38
  unzipFile: () => unzipFile,
37
39
  waitAppReady: () => waitAppReady,
38
40
  zipFile: () => zipFile
@@ -42,15 +44,13 @@ module.exports = __toCommonJS(utils_exports);
42
44
  // src/utils/core.ts
43
45
  var import_node_fs = require("fs");
44
46
  var import_node_path = require("path");
45
- var import_node_os = require("os");
46
47
  var import_electron = require("electron");
47
48
  var DEFAULT_APP_NAME = "product";
48
- var appInfo = {
49
+ var is = {
49
50
  dev: !import_electron.app.isPackaged,
50
51
  win: process.platform === "win32",
51
52
  mac: process.platform === "darwin",
52
- linux: process.platform === "linux",
53
- systemVersion: (0, import_node_os.release)()
53
+ linux: process.platform === "linux"
54
54
  };
55
55
  function getLocale() {
56
56
  return import_electron.app.isReady() ? import_electron.app.getLocale() : void 0;
@@ -145,6 +145,8 @@ async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
145
145
  }
146
146
 
147
147
  // src/utils/utils.ts
148
+ var import_node_path2 = require("path");
149
+ var import_node_fs3 = require("fs");
148
150
  var import_electron2 = require("electron");
149
151
  function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
150
152
  if (!originRepoURL.startsWith("https://github.com/")) {
@@ -159,6 +161,23 @@ function restartApp() {
159
161
  import_electron2.app.relaunch();
160
162
  import_electron2.app.quit();
161
163
  }
164
+ function setAppUserModelId(id) {
165
+ is.win && import_electron2.app.setAppUserModelId(is.dev ? process.execPath : id);
166
+ }
167
+ function setPortableAppDataPath(dirName = "data", create) {
168
+ if (!is.win) {
169
+ return;
170
+ }
171
+ const portablePath = (0, import_node_path2.join)((0, import_node_path2.dirname)(import_electron2.app.getPath("exe")), dirName);
172
+ let exists = (0, import_node_fs3.existsSync)(portablePath);
173
+ if (create && !exists) {
174
+ (0, import_node_fs3.mkdirSync)(portablePath);
175
+ exists = true;
176
+ }
177
+ if (exists) {
178
+ import_electron2.app.setPath("appData", portablePath);
179
+ }
180
+ }
162
181
  function waitAppReady(timeout = 1e3) {
163
182
  return import_electron2.app.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
164
183
  const _ = setTimeout(() => {
@@ -178,17 +197,19 @@ function handleUnexpectedErrors(callback) {
178
197
  0 && (module.exports = {
179
198
  DEFAULT_APP_NAME,
180
199
  NoSuchNativeModuleError,
181
- appInfo,
182
200
  getAppVersion,
183
201
  getElectronVersion,
184
202
  getLocale,
185
203
  getProductAsarPath,
186
204
  handleUnexpectedErrors,
205
+ is,
187
206
  isNoSuchNativeModuleError,
188
207
  parseGithubCdnURL,
189
208
  parseVersion,
190
209
  requireNative,
191
210
  restartApp,
211
+ setAppUserModelId,
212
+ setPortableAppDataPath,
192
213
  unzipFile,
193
214
  waitAppReady,
194
215
  zipFile
package/dist/utils.mjs CHANGED
@@ -1,18 +1,20 @@
1
1
  import {
2
2
  DEFAULT_APP_NAME,
3
3
  NoSuchNativeModuleError,
4
- appInfo,
5
4
  getAppVersion,
6
5
  getElectronVersion,
7
6
  getLocale,
8
7
  getProductAsarPath,
9
8
  handleUnexpectedErrors,
9
+ is,
10
10
  isNoSuchNativeModuleError,
11
11
  parseGithubCdnURL,
12
12
  requireNative,
13
13
  restartApp,
14
+ setAppUserModelId,
15
+ setPortableAppDataPath,
14
16
  waitAppReady
15
- } from "./chunk-6V5SXFGA.mjs";
17
+ } from "./chunk-6UZHBPFT.mjs";
16
18
  import {
17
19
  parseVersion,
18
20
  unzipFile,
@@ -21,17 +23,19 @@ import {
21
23
  export {
22
24
  DEFAULT_APP_NAME,
23
25
  NoSuchNativeModuleError,
24
- appInfo,
25
26
  getAppVersion,
26
27
  getElectronVersion,
27
28
  getLocale,
28
29
  getProductAsarPath,
29
30
  handleUnexpectedErrors,
31
+ is,
30
32
  isNoSuchNativeModuleError,
31
33
  parseGithubCdnURL,
32
34
  parseVersion,
33
35
  requireNative,
34
36
  restartApp,
37
+ setAppUserModelId,
38
+ setPortableAppDataPath,
35
39
  unzipFile,
36
40
  waitAppReady,
37
41
  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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electron-incremental-update",
3
- "version": "0.8.9",
3
+ "version": "0.9.0",
4
4
  "description": "electron incremental update tools, powered by vite",
5
5
  "author": "subframe7536",
6
6
  "license": "MIT",
@@ -46,17 +46,17 @@
46
46
  "dependencies": {
47
47
  "@electron/asar": "^3.2.8",
48
48
  "ci-info": "^4.0.0",
49
- "selfsigned": "^2.4.1",
50
- "vite": "^4.5.0"
49
+ "selfsigned": "^2.4.1"
51
50
  },
52
51
  "devDependencies": {
53
- "@subframe7536/eslint-config": "^0.4.1",
54
- "@types/node": "^20.9.0",
52
+ "@subframe7536/eslint-config": "^0.5.0",
53
+ "@types/node": "^20.9.4",
55
54
  "bumpp": "^9.2.0",
56
- "electron": "^27.0.4",
57
- "eslint": "^8.53.0",
58
- "tsup": "^7.2.0",
59
- "typescript": "^5.2.2",
55
+ "electron": "^27.1.0",
56
+ "eslint": "^8.54.0",
57
+ "tsup": "^8.0.1",
58
+ "typescript": "^5.3.2",
59
+ "vite": "^5.0.2",
60
60
  "vitest": "^0.34.6"
61
61
  }
62
62
  }