electron-incremental-update 0.8.6 → 0.8.7

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
@@ -51,25 +51,25 @@ src
51
51
 
52
52
  ```ts
53
53
  // electron/app.ts
54
- import { getGithubReleaseCdnGroup, initApp, parseGithubCdnURL } from 'electron-incremental-update'
54
+ import { initApp, parseGithubCdnURL } from 'electron-incremental-update'
55
55
  import { name, repository } from '../package.json'
56
56
 
57
57
  const SIGNATURE_CERT = '' // auto generate certificate when start app
58
58
 
59
- const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
60
- const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
61
59
  initApp({ onStart: console.log })
62
60
  // can be updater option or function that return updater
63
61
  .setUpdater({
64
62
  SIGNATURE_CERT,
65
63
  productName: name,
66
64
  repository,
67
- updateJsonURL: parseGithubCdnURL(repository, jsonPrefix, 'version.json'),
68
- releaseAsarURL: parseGithubCdnURL(repository, asarPrefix, `download/latest/${name}.asar.gz`),
65
+ updateJsonURL: parseGithubCdnURL(repository, '...', 'version.json'),
66
+ releaseAsarURL: parseGithubCdnURL(repository, '...', `download/latest/${name}.asar.gz`),
69
67
  receiveBeta: true
70
68
  })
71
69
  ```
72
70
 
71
+ - [some cdn resources](https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34):
72
+
73
73
  ### setup vite.config.ts
74
74
 
75
75
  make sure the plugin is set in the **last** build task
@@ -174,7 +174,7 @@ However, you have the option to customize the download function when creating th
174
174
  ```ts
175
175
  // electron/main/index.ts
176
176
  import type { StartupWithUpdater, Updater } from 'electron-incremental-update'
177
- import { getAppVersion, getElectronVersion, getProductAsarPath } from 'electron-incremental-update/utils'
177
+ import { appInfo, getProductAsarPath } from 'electron-incremental-update/utils'
178
178
  import { app } from 'electron'
179
179
  import { name } from '../../package.json'
180
180
 
@@ -182,8 +182,8 @@ const startup: StartupWithUpdater = (updater: Updater) => {
182
182
  await app.whenReady()
183
183
  console.log('\ncurrent:')
184
184
  console.log(`\tasar path: ${getProductAsarPath(name)}`)
185
- console.log(`\tapp: ${getAppVersion(name)}`)
186
- console.log(`\telectron: ${getElectronVersion()}`)
185
+ console.log(`\tapp: ${appInfo.appVersion(name)}`)
186
+ console.log(`\telectron: ${appInfo.electronVersion}`)
187
187
  updater.onDownloading = ({ percent }) => {
188
188
  console.log(percent)
189
189
  }
@@ -0,0 +1,99 @@
1
+ import {
2
+ __require
3
+ } from "./chunk-CMBFI77K.mjs";
4
+
5
+ // src/utils/core.ts
6
+ import { readFileSync } from "node:fs";
7
+ import { dirname, join } from "node:path";
8
+ import { release } from "node:os";
9
+ import { app } from "electron";
10
+ var DEFAULT_APP_NAME = "product";
11
+ var appInfo = {
12
+ dev: !app.isPackaged,
13
+ win: process.platform === "win32",
14
+ mac: process.platform === "darwin",
15
+ linux: process.platform === "linux",
16
+ electronVersion: getElectronVersion(),
17
+ appVersion: getAppVersion,
18
+ systemVersion: release()
19
+ };
20
+ function getLocale() {
21
+ return app.isReady() ? app.getLocale() : void 0;
22
+ }
23
+ function getProductAsarPath(name = DEFAULT_APP_NAME) {
24
+ return !app.isPackaged ? "DEV.asar" : join(dirname(app.getAppPath()), `${name}.asar`);
25
+ }
26
+ function getElectronVersion() {
27
+ return app.getVersion();
28
+ }
29
+ function getAppVersion(name = DEFAULT_APP_NAME) {
30
+ return app.isPackaged ? readFileSync(join(getProductAsarPath(name), "version"), "utf-8") : getElectronVersion();
31
+ }
32
+ var NoSuchNativeModuleError = class extends Error {
33
+ moduleName;
34
+ constructor(moduleName) {
35
+ super(`no such native module: ${moduleName}`);
36
+ this.moduleName = moduleName;
37
+ }
38
+ };
39
+ function isNoSuchNativeModuleError(e) {
40
+ return e instanceof NoSuchNativeModuleError;
41
+ }
42
+ function requireNative(packageName) {
43
+ const path = app.isPackaged ? join(app.getAppPath(), "node_modules", packageName) : packageName;
44
+ try {
45
+ return __require(path);
46
+ } catch (error) {
47
+ return new NoSuchNativeModuleError(packageName);
48
+ }
49
+ }
50
+
51
+ // src/utils/utils.ts
52
+ import { app as app2 } from "electron";
53
+ function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
54
+ if (!originRepoURL.startsWith("https://github.com/")) {
55
+ throw new Error("origin url must start with https://github.com/");
56
+ }
57
+ originRepoURL = originRepoURL.trim().replace(/\/?$/, "/").trim();
58
+ relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
59
+ cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
60
+ return originRepoURL.replace("github.com", cdnPrefix) + relativeFilePath;
61
+ }
62
+ function restartApp() {
63
+ app2.relaunch();
64
+ app2.quit();
65
+ }
66
+ function waitAppReady(duration = 1e3) {
67
+ if (app2.isReady()) {
68
+ return Promise.resolve();
69
+ }
70
+ return new Promise((resolve, reject) => {
71
+ const timeout = setTimeout(() => {
72
+ reject(new Error("app is not ready"));
73
+ }, duration);
74
+ app2.whenReady().then(() => {
75
+ clearTimeout(timeout);
76
+ resolve();
77
+ });
78
+ });
79
+ }
80
+ function handleUnexpectedErrors(callback) {
81
+ process.on("uncaughtException", callback);
82
+ process.on("unhandledRejection", callback);
83
+ }
84
+
85
+ export {
86
+ DEFAULT_APP_NAME,
87
+ appInfo,
88
+ getLocale,
89
+ getProductAsarPath,
90
+ getElectronVersion,
91
+ getAppVersion,
92
+ NoSuchNativeModuleError,
93
+ isNoSuchNativeModuleError,
94
+ requireNative,
95
+ parseGithubCdnURL,
96
+ restartApp,
97
+ waitAppReady,
98
+ handleUnexpectedErrors
99
+ };
package/dist/index.d.mts CHANGED
@@ -141,11 +141,11 @@ interface UpdaterOption {
141
141
  */
142
142
  SIGNATURE_CERT: string;
143
143
  /**
144
- * name of your application
144
+ * name of your application, you can use the `name` in `package.json`
145
145
  *
146
- * you can use the `name` in `package.json`
146
+ * @default DEFAULT_APP_NAME
147
147
  */
148
- productName: string;
148
+ productName?: string;
149
149
  /**
150
150
  * repository url, e.g. `https://github.com/electron/electron`
151
151
  *
@@ -184,7 +184,6 @@ declare class IncrementalUpdater implements Updater {
184
184
  logger?: Logger;
185
185
  onDownloading?: (progress: DownloadingInfo) => void;
186
186
  get productName(): string;
187
- set productName(name: string);
188
187
  get receiveBeta(): boolean;
189
188
  set receiveBeta(receiveBeta: boolean);
190
189
  constructor(option: UpdaterOption);
package/dist/index.d.ts CHANGED
@@ -141,11 +141,11 @@ interface UpdaterOption {
141
141
  */
142
142
  SIGNATURE_CERT: string;
143
143
  /**
144
- * name of your application
144
+ * name of your application, you can use the `name` in `package.json`
145
145
  *
146
- * you can use the `name` in `package.json`
146
+ * @default DEFAULT_APP_NAME
147
147
  */
148
- productName: string;
148
+ productName?: string;
149
149
  /**
150
150
  * repository url, e.g. `https://github.com/electron/electron`
151
151
  *
@@ -184,7 +184,6 @@ declare class IncrementalUpdater implements Updater {
184
184
  logger?: Logger;
185
185
  onDownloading?: (progress: DownloadingInfo) => void;
186
186
  get productName(): string;
187
- set productName(name: string);
188
187
  get receiveBeta(): boolean;
189
188
  set receiveBeta(receiveBeta: boolean);
190
189
  constructor(option: UpdaterOption);
package/dist/index.js CHANGED
@@ -37,7 +37,7 @@ __export(src_exports, {
37
37
  module.exports = __toCommonJS(src_exports);
38
38
  var import_node_path2 = require("path");
39
39
  var import_node_fs4 = require("fs");
40
- var import_electron3 = __toESM(require("electron"));
40
+ var import_electron4 = __toESM(require("electron"));
41
41
 
42
42
  // src/updater/index.ts
43
43
  var import_node_fs3 = require("fs");
@@ -48,26 +48,25 @@ var import_node_fs = require("fs");
48
48
  var import_node_path = require("path");
49
49
  var import_node_os = require("os");
50
50
  var import_electron = require("electron");
51
- function getProductAsarPath(name) {
51
+ var DEFAULT_APP_NAME = "product";
52
+ var appInfo = {
53
+ dev: !import_electron.app.isPackaged,
54
+ win: process.platform === "win32",
55
+ mac: process.platform === "darwin",
56
+ linux: process.platform === "linux",
57
+ electronVersion: getElectronVersion(),
58
+ appVersion: getAppVersion,
59
+ systemVersion: (0, import_node_os.release)()
60
+ };
61
+ function getProductAsarPath(name = DEFAULT_APP_NAME) {
52
62
  return !import_electron.app.isPackaged ? "DEV.asar" : (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${name}.asar`);
53
63
  }
54
64
  function getElectronVersion() {
55
65
  return import_electron.app.getVersion();
56
66
  }
57
- function getAppVersion(name) {
67
+ function getAppVersion(name = DEFAULT_APP_NAME) {
58
68
  return import_electron.app.isPackaged ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8") : getElectronVersion();
59
69
  }
60
- function waitAppReady(duration = 1e3) {
61
- return new Promise((resolve2, reject) => {
62
- const timeout = setTimeout(() => {
63
- reject(new Error("app is not ready"));
64
- }, duration);
65
- import_electron.app.whenReady().then(() => {
66
- clearTimeout(timeout);
67
- resolve2();
68
- });
69
- });
70
- }
71
70
 
72
71
  // src/utils/version.ts
73
72
  function parseVersion(version) {
@@ -115,6 +114,23 @@ async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
115
114
  });
116
115
  }
117
116
 
117
+ // src/utils/utils.ts
118
+ var import_electron2 = require("electron");
119
+ function waitAppReady(duration = 1e3) {
120
+ if (import_electron2.app.isReady()) {
121
+ return Promise.resolve();
122
+ }
123
+ return new Promise((resolve2, reject) => {
124
+ const timeout = setTimeout(() => {
125
+ reject(new Error("app is not ready"));
126
+ }, duration);
127
+ import_electron2.app.whenReady().then(() => {
128
+ clearTimeout(timeout);
129
+ resolve2();
130
+ });
131
+ });
132
+ }
133
+
118
134
  // src/crypto.ts
119
135
  var import_node_crypto = require("crypto");
120
136
  function decrypt(encryptedText, key2, iv) {
@@ -169,11 +185,11 @@ var DownloadError = class extends Error {
169
185
  };
170
186
 
171
187
  // src/updater/defaultFunctions.ts
172
- var import_electron2 = require("electron");
188
+ var import_electron3 = require("electron");
173
189
  var downloadJSONDefault = async (url, headers) => {
174
190
  await waitAppReady();
175
191
  return new Promise((resolve2, reject) => {
176
- const request = import_electron2.net.request({
192
+ const request = import_electron3.net.request({
177
193
  url,
178
194
  method: "GET",
179
195
  redirect: "follow"
@@ -207,7 +223,7 @@ var downloadBufferDefault = async (url, headers, total, onDownloading) => {
207
223
  await waitAppReady();
208
224
  let current = 0;
209
225
  return new Promise((resolve2, reject) => {
210
- const request = import_electron2.net.request({
226
+ const request = import_electron3.net.request({
211
227
  url,
212
228
  method: "GET",
213
229
  redirect: "follow"
@@ -268,9 +284,6 @@ var IncrementalUpdater = class {
268
284
  get productName() {
269
285
  return this.option.productName;
270
286
  }
271
- set productName(name) {
272
- this.option.productName = name;
273
- }
274
287
  get receiveBeta() {
275
288
  return !!this.option.receiveBeta;
276
289
  }
@@ -279,6 +292,9 @@ var IncrementalUpdater = class {
279
292
  }
280
293
  constructor(option) {
281
294
  this.option = option;
295
+ if (!option.productName) {
296
+ this.option.productName = DEFAULT_APP_NAME;
297
+ }
282
298
  this.asarPath = getProductAsarPath(this.productName);
283
299
  this.gzipPath = `${this.asarPath}.gz`;
284
300
  this.tmpFilePath = `${this.asarPath}.tmp`;
@@ -422,7 +438,7 @@ function initApp(appOptions) {
422
438
  } = hooks || {};
423
439
  function handleError(msg) {
424
440
  onStartError?.(new Error(msg));
425
- import_electron3.default.app.quit();
441
+ import_electron4.default.app.quit();
426
442
  }
427
443
  async function startup(updater) {
428
444
  try {
@@ -432,7 +448,7 @@ function initApp(appOptions) {
432
448
  await beforeDoUpdate?.(asarPath, updateAsarPath);
433
449
  (0, import_node_fs4.renameSync)(updateAsarPath, asarPath);
434
450
  }
435
- const mainDir = import_electron3.default.app.isPackaged ? asarPath : electronDevDistPath;
451
+ const mainDir = import_electron4.default.app.isPackaged ? asarPath : electronDevDistPath;
436
452
  const entry = (0, import_node_path2.resolve)(__dirname, mainDir, mainPath);
437
453
  await beforeStart?.(entry);
438
454
  require(entry)(updater);
package/dist/index.mjs CHANGED
@@ -3,11 +3,12 @@ import {
3
3
  verify
4
4
  } from "./chunk-5BZLJPHJ.mjs";
5
5
  import {
6
+ DEFAULT_APP_NAME,
6
7
  getAppVersion,
7
8
  getElectronVersion,
8
9
  getProductAsarPath,
9
10
  waitAppReady
10
- } from "./chunk-MFFH2NRM.mjs";
11
+ } from "./chunk-OGAOUYV3.mjs";
11
12
  import {
12
13
  __require,
13
14
  parseVersion,
@@ -148,9 +149,6 @@ var IncrementalUpdater = class {
148
149
  get productName() {
149
150
  return this.option.productName;
150
151
  }
151
- set productName(name) {
152
- this.option.productName = name;
153
- }
154
152
  get receiveBeta() {
155
153
  return !!this.option.receiveBeta;
156
154
  }
@@ -159,6 +157,9 @@ var IncrementalUpdater = class {
159
157
  }
160
158
  constructor(option) {
161
159
  this.option = option;
160
+ if (!option.productName) {
161
+ this.option.productName = DEFAULT_APP_NAME;
162
+ }
162
163
  this.asarPath = getProductAsarPath(this.productName);
163
164
  this.gzipPath = `${this.asarPath}.gz`;
164
165
  this.tmpFilePath = `${this.asarPath}.tmp`;
package/dist/utils.d.mts CHANGED
@@ -1,28 +1,27 @@
1
+ declare const DEFAULT_APP_NAME = "product";
1
2
  type Info = {
2
3
  dev: boolean;
3
4
  win: boolean;
4
5
  mac: boolean;
5
6
  linux: boolean;
6
7
  electronVersion: string;
8
+ appVersion: (name?: string) => string;
7
9
  /**
8
10
  * `os.release()`
9
11
  */
10
- system: string;
11
- /**
12
- * system locale, `undefined` when `!app.isReady()`
13
- */
14
- locale: string | undefined;
12
+ systemVersion: string;
15
13
  };
16
14
  /**
17
15
  * get app info
18
16
  */
19
- declare function getAppInfo(): Info;
17
+ declare const appInfo: Info;
18
+ declare function getLocale(): string | undefined;
20
19
  /**
21
20
  * get the application asar absolute path (not `app.asar`),
22
21
  * if is in dev, return `'DEV.asar'`
23
22
  * @param name The name of the application
24
23
  */
25
- declare function getProductAsarPath(name: string): string;
24
+ declare function getProductAsarPath(name?: string): string;
26
25
  /**
27
26
  * get the version of Electron runtime
28
27
  */
@@ -33,7 +32,7 @@ declare function getElectronVersion(): string;
33
32
  * if is dev, return {@link getElectronVersion}
34
33
  * @param name - The name of the application
35
34
  */
36
- declare function getAppVersion(name: string): string;
35
+ declare function getAppVersion(name?: string): string;
37
36
  declare class NoSuchNativeModuleError extends Error {
38
37
  moduleName: string;
39
38
  constructor(moduleName: string);
@@ -44,33 +43,6 @@ declare function isNoSuchNativeModuleError(e: unknown): e is NoSuchNativeModuleE
44
43
  * @param packageName native package name
45
44
  */
46
45
  declare function requireNative<T = any>(packageName: string): T | NoSuchNativeModuleError;
47
- /**
48
- * parse Github CDN URL for accelerating the speed of downloading
49
- */
50
- declare function parseGithubCdnURL(repository: string, cdnPrefix: string, relativeFilePath: string): string;
51
- /**
52
- * get group of Github file CDN prefix for accelerating the speed of downloading project files
53
- */
54
- declare function getGithubFileCdnGroup(): {
55
- cdnPrefix: string;
56
- source: string;
57
- }[];
58
- /**
59
- * get group of github release CDN prefix for accelerating the speed of downloading release
60
- */
61
- declare function getGithubReleaseCdnGroup(): {
62
- cdnPrefix: string;
63
- source: string;
64
- }[];
65
- /**
66
- * Restarts the Electron app.
67
- */
68
- declare function restartApp(): void;
69
- /**
70
- * ensure app is ready.
71
- */
72
- declare function waitAppReady(duration?: number): Promise<void>;
73
- declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
74
46
 
75
47
  interface Version {
76
48
  major: number;
@@ -84,4 +56,20 @@ declare function parseVersion(version: string): Version;
84
56
  declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<unknown>;
85
57
  declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
86
58
 
87
- export { NoSuchNativeModuleError, Version, getAppInfo, getAppVersion, getElectronVersion, getGithubFileCdnGroup, getGithubReleaseCdnGroup, getProductAsarPath, handleUnexpectedErrors, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
59
+ /**
60
+ * parse Github CDN URL for accelerating the speed of downloading
61
+ *
62
+ * {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 some public CDN links}
63
+ */
64
+ declare function parseGithubCdnURL(originRepoURL: string, cdnPrefix: string, relativeFilePath: string): string;
65
+ /**
66
+ * Restarts the Electron app.
67
+ */
68
+ declare function restartApp(): void;
69
+ /**
70
+ * ensure app is ready.
71
+ */
72
+ declare function waitAppReady(duration?: number): Promise<void>;
73
+ declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
74
+
75
+ export { DEFAULT_APP_NAME, NoSuchNativeModuleError, Version, appInfo, getAppVersion, getElectronVersion, getLocale, getProductAsarPath, handleUnexpectedErrors, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
package/dist/utils.d.ts CHANGED
@@ -1,28 +1,27 @@
1
+ declare const DEFAULT_APP_NAME = "product";
1
2
  type Info = {
2
3
  dev: boolean;
3
4
  win: boolean;
4
5
  mac: boolean;
5
6
  linux: boolean;
6
7
  electronVersion: string;
8
+ appVersion: (name?: string) => string;
7
9
  /**
8
10
  * `os.release()`
9
11
  */
10
- system: string;
11
- /**
12
- * system locale, `undefined` when `!app.isReady()`
13
- */
14
- locale: string | undefined;
12
+ systemVersion: string;
15
13
  };
16
14
  /**
17
15
  * get app info
18
16
  */
19
- declare function getAppInfo(): Info;
17
+ declare const appInfo: Info;
18
+ declare function getLocale(): string | undefined;
20
19
  /**
21
20
  * get the application asar absolute path (not `app.asar`),
22
21
  * if is in dev, return `'DEV.asar'`
23
22
  * @param name The name of the application
24
23
  */
25
- declare function getProductAsarPath(name: string): string;
24
+ declare function getProductAsarPath(name?: string): string;
26
25
  /**
27
26
  * get the version of Electron runtime
28
27
  */
@@ -33,7 +32,7 @@ declare function getElectronVersion(): string;
33
32
  * if is dev, return {@link getElectronVersion}
34
33
  * @param name - The name of the application
35
34
  */
36
- declare function getAppVersion(name: string): string;
35
+ declare function getAppVersion(name?: string): string;
37
36
  declare class NoSuchNativeModuleError extends Error {
38
37
  moduleName: string;
39
38
  constructor(moduleName: string);
@@ -44,33 +43,6 @@ declare function isNoSuchNativeModuleError(e: unknown): e is NoSuchNativeModuleE
44
43
  * @param packageName native package name
45
44
  */
46
45
  declare function requireNative<T = any>(packageName: string): T | NoSuchNativeModuleError;
47
- /**
48
- * parse Github CDN URL for accelerating the speed of downloading
49
- */
50
- declare function parseGithubCdnURL(repository: string, cdnPrefix: string, relativeFilePath: string): string;
51
- /**
52
- * get group of Github file CDN prefix for accelerating the speed of downloading project files
53
- */
54
- declare function getGithubFileCdnGroup(): {
55
- cdnPrefix: string;
56
- source: string;
57
- }[];
58
- /**
59
- * get group of github release CDN prefix for accelerating the speed of downloading release
60
- */
61
- declare function getGithubReleaseCdnGroup(): {
62
- cdnPrefix: string;
63
- source: string;
64
- }[];
65
- /**
66
- * Restarts the Electron app.
67
- */
68
- declare function restartApp(): void;
69
- /**
70
- * ensure app is ready.
71
- */
72
- declare function waitAppReady(duration?: number): Promise<void>;
73
- declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
74
46
 
75
47
  interface Version {
76
48
  major: number;
@@ -84,4 +56,20 @@ declare function parseVersion(version: string): Version;
84
56
  declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<unknown>;
85
57
  declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
86
58
 
87
- export { NoSuchNativeModuleError, Version, getAppInfo, getAppVersion, getElectronVersion, getGithubFileCdnGroup, getGithubReleaseCdnGroup, getProductAsarPath, handleUnexpectedErrors, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
59
+ /**
60
+ * parse Github CDN URL for accelerating the speed of downloading
61
+ *
62
+ * {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 some public CDN links}
63
+ */
64
+ declare function parseGithubCdnURL(originRepoURL: string, cdnPrefix: string, relativeFilePath: string): string;
65
+ /**
66
+ * Restarts the Electron app.
67
+ */
68
+ declare function restartApp(): void;
69
+ /**
70
+ * ensure app is ready.
71
+ */
72
+ declare function waitAppReady(duration?: number): Promise<void>;
73
+ declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
74
+
75
+ export { DEFAULT_APP_NAME, NoSuchNativeModuleError, Version, appInfo, getAppVersion, getElectronVersion, getLocale, getProductAsarPath, handleUnexpectedErrors, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
package/dist/utils.js CHANGED
@@ -20,12 +20,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/utils/index.ts
21
21
  var utils_exports = {};
22
22
  __export(utils_exports, {
23
+ DEFAULT_APP_NAME: () => DEFAULT_APP_NAME,
23
24
  NoSuchNativeModuleError: () => NoSuchNativeModuleError,
24
- getAppInfo: () => getAppInfo,
25
+ appInfo: () => appInfo,
25
26
  getAppVersion: () => getAppVersion,
26
27
  getElectronVersion: () => getElectronVersion,
27
- getGithubFileCdnGroup: () => getGithubFileCdnGroup,
28
- getGithubReleaseCdnGroup: () => getGithubReleaseCdnGroup,
28
+ getLocale: () => getLocale,
29
29
  getProductAsarPath: () => getProductAsarPath,
30
30
  handleUnexpectedErrors: () => handleUnexpectedErrors,
31
31
  isNoSuchNativeModuleError: () => isNoSuchNativeModuleError,
@@ -44,24 +44,26 @@ var import_node_fs = require("fs");
44
44
  var import_node_path = require("path");
45
45
  var import_node_os = require("os");
46
46
  var import_electron = require("electron");
47
- function getAppInfo() {
48
- return {
49
- dev: !import_electron.app.isPackaged,
50
- win: process.platform === "win32",
51
- mac: process.platform === "darwin",
52
- linux: process.platform === "linux",
53
- electronVersion: getElectronVersion(),
54
- system: (0, import_node_os.release)(),
55
- locale: import_electron.app.isReady() ? import_electron.app.getLocale() : void 0
56
- };
47
+ var DEFAULT_APP_NAME = "product";
48
+ var appInfo = {
49
+ dev: !import_electron.app.isPackaged,
50
+ win: process.platform === "win32",
51
+ mac: process.platform === "darwin",
52
+ linux: process.platform === "linux",
53
+ electronVersion: getElectronVersion(),
54
+ appVersion: getAppVersion,
55
+ systemVersion: (0, import_node_os.release)()
56
+ };
57
+ function getLocale() {
58
+ return import_electron.app.isReady() ? import_electron.app.getLocale() : void 0;
57
59
  }
58
- function getProductAsarPath(name) {
60
+ function getProductAsarPath(name = DEFAULT_APP_NAME) {
59
61
  return !import_electron.app.isPackaged ? "DEV.asar" : (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${name}.asar`);
60
62
  }
61
63
  function getElectronVersion() {
62
64
  return import_electron.app.getVersion();
63
65
  }
64
- function getAppVersion(name) {
66
+ function getAppVersion(name = DEFAULT_APP_NAME) {
65
67
  return import_electron.app.isPackaged ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8") : getElectronVersion();
66
68
  }
67
69
  var NoSuchNativeModuleError = class extends Error {
@@ -82,61 +84,6 @@ function requireNative(packageName) {
82
84
  return new NoSuchNativeModuleError(packageName);
83
85
  }
84
86
  }
85
- function parseGithubCdnURL(repository, cdnPrefix, relativeFilePath) {
86
- if (!repository.startsWith("https://github.com/")) {
87
- throw new Error("url must start with https://github.com/");
88
- }
89
- repository = repository.trim().replace(/\/?$/, "/").trim();
90
- relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
91
- cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
92
- return repository.replace("github.com", cdnPrefix) + relativeFilePath;
93
- }
94
- function getGithubFileCdnGroup() {
95
- return [
96
- { cdnPrefix: "cdn.jsdelivr.net/gh", source: "jsdelivr" },
97
- { cdnPrefix: "fastly.jsdelivr.net/gh", source: "jsdelivr-fastly" },
98
- { cdnPrefix: "cdn.statically.io/gh", source: "statically" },
99
- { cdnPrefix: "rawcdn.githack.com/gh", source: "githack" },
100
- { cdnPrefix: "raw.githack.com/gh", source: "githack-dev" }
101
- ];
102
- }
103
- function getGithubReleaseCdnGroup() {
104
- return [
105
- { cdnPrefix: "gh.gh2233.ml", source: "@X.I.U/XIU2" },
106
- { cdnPrefix: "ghproxy.com", source: "gh-proxy" },
107
- { cdnPrefix: "gh.ddlc.top", source: "@mtr-static-official" },
108
- { cdnPrefix: "ghdl.feizhuqwq.cf", source: "feizhuqwq.com" },
109
- { cdnPrefix: "slink.ltd", source: "\u77E5\u4E86\u5C0F\u7AD9" },
110
- { cdnPrefix: "git.xfj0.cn", source: "anonymous1" },
111
- { cdnPrefix: "gh.con.sh", source: "anonymous2" },
112
- { cdnPrefix: "ghps.cc", source: "anonymous3" },
113
- { cdnPrefix: "cors.isteed.cc/github.com", source: "Lufs's" },
114
- { cdnPrefix: "hub.gitmirror.com", source: "GitMirror" },
115
- { cdnPrefix: "js.xxooo.ml", source: "\u996D\u592A\u786C" },
116
- { cdnPrefix: "download.njuu.cf", source: "LibraryCloud-njuu" },
117
- { cdnPrefix: "download.yzuu.cf", source: "LibraryCloud-yzuu" },
118
- { cdnPrefix: "download.nuaa.cf", source: "LibraryCloud-nuaa" }
119
- ];
120
- }
121
- function restartApp() {
122
- import_electron.app.relaunch();
123
- import_electron.app.quit();
124
- }
125
- function waitAppReady(duration = 1e3) {
126
- return new Promise((resolve, reject) => {
127
- const timeout = setTimeout(() => {
128
- reject(new Error("app is not ready"));
129
- }, duration);
130
- import_electron.app.whenReady().then(() => {
131
- clearTimeout(timeout);
132
- resolve();
133
- });
134
- });
135
- }
136
- function handleUnexpectedErrors(callback) {
137
- process.on("uncaughtException", callback);
138
- process.on("unhandledRejection", callback);
139
- }
140
87
 
141
88
  // src/utils/version.ts
142
89
  function parseVersion(version) {
@@ -198,14 +145,48 @@ async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
198
145
  });
199
146
  });
200
147
  }
148
+
149
+ // src/utils/utils.ts
150
+ var import_electron2 = require("electron");
151
+ function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
152
+ if (!originRepoURL.startsWith("https://github.com/")) {
153
+ throw new Error("origin url must start with https://github.com/");
154
+ }
155
+ originRepoURL = originRepoURL.trim().replace(/\/?$/, "/").trim();
156
+ relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
157
+ cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
158
+ return originRepoURL.replace("github.com", cdnPrefix) + relativeFilePath;
159
+ }
160
+ function restartApp() {
161
+ import_electron2.app.relaunch();
162
+ import_electron2.app.quit();
163
+ }
164
+ function waitAppReady(duration = 1e3) {
165
+ if (import_electron2.app.isReady()) {
166
+ return Promise.resolve();
167
+ }
168
+ return new Promise((resolve, reject) => {
169
+ const timeout = setTimeout(() => {
170
+ reject(new Error("app is not ready"));
171
+ }, duration);
172
+ import_electron2.app.whenReady().then(() => {
173
+ clearTimeout(timeout);
174
+ resolve();
175
+ });
176
+ });
177
+ }
178
+ function handleUnexpectedErrors(callback) {
179
+ process.on("uncaughtException", callback);
180
+ process.on("unhandledRejection", callback);
181
+ }
201
182
  // Annotate the CommonJS export names for ESM import in node:
202
183
  0 && (module.exports = {
184
+ DEFAULT_APP_NAME,
203
185
  NoSuchNativeModuleError,
204
- getAppInfo,
186
+ appInfo,
205
187
  getAppVersion,
206
188
  getElectronVersion,
207
- getGithubFileCdnGroup,
208
- getGithubReleaseCdnGroup,
189
+ getLocale,
209
190
  getProductAsarPath,
210
191
  handleUnexpectedErrors,
211
192
  isNoSuchNativeModuleError,
package/dist/utils.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
+ DEFAULT_APP_NAME,
2
3
  NoSuchNativeModuleError,
3
- getAppInfo,
4
+ appInfo,
4
5
  getAppVersion,
5
6
  getElectronVersion,
6
- getGithubFileCdnGroup,
7
- getGithubReleaseCdnGroup,
7
+ getLocale,
8
8
  getProductAsarPath,
9
9
  handleUnexpectedErrors,
10
10
  isNoSuchNativeModuleError,
@@ -12,19 +12,19 @@ import {
12
12
  requireNative,
13
13
  restartApp,
14
14
  waitAppReady
15
- } from "./chunk-MFFH2NRM.mjs";
15
+ } from "./chunk-OGAOUYV3.mjs";
16
16
  import {
17
17
  parseVersion,
18
18
  unzipFile,
19
19
  zipFile
20
20
  } from "./chunk-CMBFI77K.mjs";
21
21
  export {
22
+ DEFAULT_APP_NAME,
22
23
  NoSuchNativeModuleError,
23
- getAppInfo,
24
+ appInfo,
24
25
  getAppVersion,
25
26
  getElectronVersion,
26
- getGithubFileCdnGroup,
27
- getGithubReleaseCdnGroup,
27
+ getLocale,
28
28
  getProductAsarPath,
29
29
  handleUnexpectedErrors,
30
30
  isNoSuchNativeModuleError,
package/dist/vite.js CHANGED
@@ -235,7 +235,6 @@ function writeCertToMain(entryPath, cert) {
235
235
  !isMatched && lines.push(r);
236
236
  replaced = lines.join(eol);
237
237
  }
238
- console.log(JSON.stringify(replaced));
239
238
  (0, import_node_fs3.writeFileSync)(entryPath, replaced);
240
239
  }
241
240
  function parseKeys({
package/dist/vite.mjs CHANGED
@@ -140,7 +140,6 @@ function writeCertToMain(entryPath, cert) {
140
140
  !isMatched && lines.push(r);
141
141
  replaced = lines.join(eol);
142
142
  }
143
- console.log(JSON.stringify(replaced));
144
143
  writeFileSync(entryPath, replaced);
145
144
  }
146
145
  function parseKeys({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "electron-incremental-update",
3
3
  "author": "subframe7536",
4
- "version": "0.8.6",
4
+ "version": "0.8.7",
5
5
  "description": "electron incremental update tools, powered by vite",
6
6
  "scripts": {
7
7
  "build": "tsup && node fix-module.js",
@@ -1,118 +0,0 @@
1
- import {
2
- __require
3
- } from "./chunk-CMBFI77K.mjs";
4
-
5
- // src/utils/core.ts
6
- import { readFileSync } from "node:fs";
7
- import { dirname, join } from "node:path";
8
- import { release } from "node:os";
9
- import { app } from "electron";
10
- function getAppInfo() {
11
- return {
12
- dev: !app.isPackaged,
13
- win: process.platform === "win32",
14
- mac: process.platform === "darwin",
15
- linux: process.platform === "linux",
16
- electronVersion: getElectronVersion(),
17
- system: release(),
18
- locale: app.isReady() ? app.getLocale() : void 0
19
- };
20
- }
21
- function getProductAsarPath(name) {
22
- return !app.isPackaged ? "DEV.asar" : join(dirname(app.getAppPath()), `${name}.asar`);
23
- }
24
- function getElectronVersion() {
25
- return app.getVersion();
26
- }
27
- function getAppVersion(name) {
28
- return app.isPackaged ? readFileSync(join(getProductAsarPath(name), "version"), "utf-8") : getElectronVersion();
29
- }
30
- var NoSuchNativeModuleError = class extends Error {
31
- moduleName;
32
- constructor(moduleName) {
33
- super(`no such native module: ${moduleName}`);
34
- this.moduleName = moduleName;
35
- }
36
- };
37
- function isNoSuchNativeModuleError(e) {
38
- return e instanceof NoSuchNativeModuleError;
39
- }
40
- function requireNative(packageName) {
41
- const path = app.isPackaged ? join(app.getAppPath(), "node_modules", packageName) : packageName;
42
- try {
43
- return __require(path);
44
- } catch (error) {
45
- return new NoSuchNativeModuleError(packageName);
46
- }
47
- }
48
- function parseGithubCdnURL(repository, cdnPrefix, relativeFilePath) {
49
- if (!repository.startsWith("https://github.com/")) {
50
- throw new Error("url must start with https://github.com/");
51
- }
52
- repository = repository.trim().replace(/\/?$/, "/").trim();
53
- relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
54
- cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
55
- return repository.replace("github.com", cdnPrefix) + relativeFilePath;
56
- }
57
- function getGithubFileCdnGroup() {
58
- return [
59
- { cdnPrefix: "cdn.jsdelivr.net/gh", source: "jsdelivr" },
60
- { cdnPrefix: "fastly.jsdelivr.net/gh", source: "jsdelivr-fastly" },
61
- { cdnPrefix: "cdn.statically.io/gh", source: "statically" },
62
- { cdnPrefix: "rawcdn.githack.com/gh", source: "githack" },
63
- { cdnPrefix: "raw.githack.com/gh", source: "githack-dev" }
64
- ];
65
- }
66
- function getGithubReleaseCdnGroup() {
67
- return [
68
- { cdnPrefix: "gh.gh2233.ml", source: "@X.I.U/XIU2" },
69
- { cdnPrefix: "ghproxy.com", source: "gh-proxy" },
70
- { cdnPrefix: "gh.ddlc.top", source: "@mtr-static-official" },
71
- { cdnPrefix: "ghdl.feizhuqwq.cf", source: "feizhuqwq.com" },
72
- { cdnPrefix: "slink.ltd", source: "\u77E5\u4E86\u5C0F\u7AD9" },
73
- { cdnPrefix: "git.xfj0.cn", source: "anonymous1" },
74
- { cdnPrefix: "gh.con.sh", source: "anonymous2" },
75
- { cdnPrefix: "ghps.cc", source: "anonymous3" },
76
- { cdnPrefix: "cors.isteed.cc/github.com", source: "Lufs's" },
77
- { cdnPrefix: "hub.gitmirror.com", source: "GitMirror" },
78
- { cdnPrefix: "js.xxooo.ml", source: "\u996D\u592A\u786C" },
79
- { cdnPrefix: "download.njuu.cf", source: "LibraryCloud-njuu" },
80
- { cdnPrefix: "download.yzuu.cf", source: "LibraryCloud-yzuu" },
81
- { cdnPrefix: "download.nuaa.cf", source: "LibraryCloud-nuaa" }
82
- ];
83
- }
84
- function restartApp() {
85
- app.relaunch();
86
- app.quit();
87
- }
88
- function waitAppReady(duration = 1e3) {
89
- return new Promise((resolve, reject) => {
90
- const timeout = setTimeout(() => {
91
- reject(new Error("app is not ready"));
92
- }, duration);
93
- app.whenReady().then(() => {
94
- clearTimeout(timeout);
95
- resolve();
96
- });
97
- });
98
- }
99
- function handleUnexpectedErrors(callback) {
100
- process.on("uncaughtException", callback);
101
- process.on("unhandledRejection", callback);
102
- }
103
-
104
- export {
105
- getAppInfo,
106
- getProductAsarPath,
107
- getElectronVersion,
108
- getAppVersion,
109
- NoSuchNativeModuleError,
110
- isNoSuchNativeModuleError,
111
- requireNative,
112
- parseGithubCdnURL,
113
- getGithubFileCdnGroup,
114
- getGithubReleaseCdnGroup,
115
- restartApp,
116
- waitAppReady,
117
- handleUnexpectedErrors
118
- };