electron-incremental-update 1.0.3 → 1.1.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/dist/index.js CHANGED
@@ -1,149 +1,46 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key2 of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key2) && key2 !== except)
14
- __defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ import {
2
+ __require,
3
+ getPathFromAppNameAsar,
4
+ getVersions,
5
+ is,
6
+ isUpdateJSON,
7
+ parseVersion,
8
+ restartApp,
9
+ unzipFile,
10
+ waitAppReady
11
+ } from "./chunk-CXHA5TF7.js";
19
12
 
20
13
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- DownloadError: () => DownloadError,
24
- MinimumVersionError: () => MinimumVersionError,
25
- Updater: () => Updater,
26
- VerifyFailedError: () => VerifyFailedError,
27
- createUpdater: () => createUpdater,
28
- initApp: () => initApp,
29
- startupWithUpdater: () => startupWithUpdater
30
- });
31
- module.exports = __toCommonJS(src_exports);
32
- var import_node_path2 = require("path");
33
- var import_node_fs4 = require("fs");
34
- var import_electron4 = require("electron");
14
+ import { resolve } from "node:path";
15
+ import { existsSync as existsSync2, renameSync } from "node:fs";
16
+ import { app as app2 } from "electron";
35
17
 
36
18
  // src/updater/core.ts
37
- var import_node_fs3 = require("fs");
38
- var import_promises = require("fs/promises");
39
- var import_electron3 = require("electron");
40
-
41
- // src/utils/electron.ts
42
- var import_node_fs = require("fs");
43
- var import_node_path = require("path");
44
- var import_node_os = require("os");
45
- var import_electron = require("electron");
46
- var is = {
47
- dev: !import_electron.app.isPackaged,
48
- win: process.platform === "win32",
49
- mac: process.platform === "darwin",
50
- linux: process.platform === "linux"
51
- };
52
- function getPathFromAppNameAsar(...path) {
53
- return is.dev ? "DEV.asar" : (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${import_electron.app.name}.asar`, ...path);
54
- }
55
- function getVersions() {
56
- const platform = is.win ? "Windows" : is.mac ? "MacOS" : process.platform.toUpperCase();
57
- return {
58
- appVersion: is.dev ? import_electron.app.getVersion() : (0, import_node_fs.readFileSync)(getPathFromAppNameAsar("version"), "utf-8"),
59
- entryVersion: import_electron.app.getVersion(),
60
- electronVersion: process.versions.electron,
61
- nodeVersion: process.versions.node,
62
- systemVersion: `${platform} ${(0, import_node_os.release)()}`
63
- };
64
- }
65
- function restartApp() {
66
- import_electron.app.relaunch();
67
- import_electron.app.quit();
68
- }
69
- function waitAppReady(timeout = 1e3) {
70
- return import_electron.app.isReady() ? Promise.resolve() : new Promise((resolve2, reject) => {
71
- const _ = setTimeout(() => {
72
- reject(new Error("app is not ready"));
73
- }, timeout);
74
- import_electron.app.whenReady().then(() => {
75
- clearTimeout(_);
76
- resolve2();
77
- });
78
- });
79
- }
19
+ import { existsSync } from "node:fs";
20
+ import { rm, writeFile } from "node:fs/promises";
21
+ import { app } from "electron";
80
22
 
81
- // src/utils/zip.ts
82
- var import_node_fs2 = require("fs");
83
- var import_node_zlib = require("zlib");
84
- async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
85
- if (!(0, import_node_fs2.existsSync)(gzipPath)) {
86
- throw new Error(`path to zipped file not exist: ${gzipPath}`);
87
- }
88
- const compressedBuffer = (0, import_node_fs2.readFileSync)(gzipPath);
89
- return new Promise((resolve2, reject) => {
90
- (0, import_node_zlib.gunzip)(compressedBuffer, (err, buffer) => {
91
- (0, import_node_fs2.rmSync)(gzipPath);
92
- if (err) {
93
- reject(err);
94
- }
95
- (0, import_node_fs2.writeFileSync)(targetFilePath, buffer);
96
- resolve2(null);
97
- });
98
- });
99
- }
23
+ // src/crypto/dec.ts
24
+ import { createDecipheriv, createVerify } from "node:crypto";
100
25
 
101
- // src/utils/noDep.ts
102
- function parseVersion(version) {
103
- const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
104
- const match = semver.exec(version);
105
- if (!match) {
106
- throw new TypeError(`invalid version: ${version}`);
107
- }
108
- const [major, minor, patch] = match.slice(1, 4).map(Number);
109
- const ret = {
110
- major,
111
- minor,
112
- patch,
113
- stage: "",
114
- stageVersion: -1
115
- };
116
- if (match[4]) {
117
- let [stage, _v] = match[4].split(".");
118
- ret.stage = stage;
119
- ret.stageVersion = Number(_v) || -1;
120
- }
121
- if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
122
- throw new TypeError(`invalid version: ${version}`);
123
- }
124
- return ret;
125
- }
126
- function isUpdateJSON(json) {
127
- const is2 = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
128
- return is2(json) && is2(json?.beta);
26
+ // src/crypto/utils.ts
27
+ import { createHash } from "node:crypto";
28
+ function hashString(data, length) {
29
+ const hash = createHash("SHA256").update(data).digest("binary");
30
+ return Buffer.from(hash).subarray(0, length);
129
31
  }
130
32
 
131
- // src/crypto.ts
132
- var import_node_crypto = require("crypto");
133
- function decrypt(encryptedText, key2, iv) {
134
- const decipher = (0, import_node_crypto.createDecipheriv)("aes-256-cbc", key2, iv);
33
+ // src/crypto/dec.ts
34
+ function decrypt(encryptedText, key, iv) {
35
+ const decipher = createDecipheriv("aes-256-cbc", key, iv);
135
36
  let decrypted = decipher.update(encryptedText, "base64url", "utf8");
136
37
  decrypted += decipher.final("utf8");
137
38
  return decrypted;
138
39
  }
139
- function key(data, length) {
140
- const hash = (0, import_node_crypto.createHash)("SHA256").update(data).digest("binary");
141
- return Buffer.from(hash).subarray(0, length);
142
- }
143
40
  var verify = (buffer, signature, cert) => {
144
41
  try {
145
- const [sig, version] = decrypt(signature, key(cert, 32), key(buffer, 16)).split("%");
146
- const result = (0, import_node_crypto.createVerify)("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
42
+ const [sig, version] = decrypt(signature, hashString(cert, 32), hashString(buffer, 16)).split("%");
43
+ const result = createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
147
44
  return result ? version : false;
148
45
  } catch (error) {
149
46
  return false;
@@ -176,17 +73,17 @@ var DownloadError = class extends Error {
176
73
  };
177
74
 
178
75
  // src/updater/defaultFunctions/download.ts
179
- var import_electron2 = require("electron");
76
+ import { net } from "electron";
180
77
  var downloadJSONDefault = async (url, headers) => {
181
78
  await waitAppReady();
182
79
  return new Promise((resolve2, reject) => {
183
- const request = import_electron2.net.request({
80
+ const request = net.request({
184
81
  url,
185
82
  method: "GET",
186
83
  redirect: "follow"
187
84
  });
188
- Object.keys(headers).forEach((key2) => {
189
- request.setHeader(key2, headers[key2]);
85
+ Object.keys(headers).forEach((key) => {
86
+ request.setHeader(key, headers[key]);
190
87
  });
191
88
  request.on("response", (res) => {
192
89
  let data = "";
@@ -214,13 +111,13 @@ var downloadBufferDefault = async (url, headers, total, onDownloading) => {
214
111
  await waitAppReady();
215
112
  let current = 0;
216
113
  return new Promise((resolve2, reject) => {
217
- const request = import_electron2.net.request({
114
+ const request = net.request({
218
115
  url,
219
116
  method: "GET",
220
117
  redirect: "follow"
221
118
  });
222
- Object.keys(headers).forEach((key2) => {
223
- request.setHeader(key2, headers[key2]);
119
+ Object.keys(headers).forEach((key) => {
120
+ request.setHeader(key, headers[key]);
224
121
  });
225
122
  request.on("response", (res) => {
226
123
  let data = [];
@@ -255,11 +152,11 @@ var compareVersionDefault = (version1, version2) => {
255
152
  }
256
153
  return str1 < str2;
257
154
  }
258
- for (let key2 of Object.keys(oldV)) {
259
- if (key2 === "stage" && compareStrings(oldV[key2], newV[key2])) {
155
+ for (let key of Object.keys(oldV)) {
156
+ if (key === "stage" && compareStrings(oldV[key], newV[key])) {
260
157
  return true;
261
- } else if (oldV[key2] !== newV[key2]) {
262
- return oldV[key2] < newV[key2];
158
+ } else if (oldV[key] !== newV[key]) {
159
+ return oldV[key] < newV[key];
263
160
  }
264
161
  }
265
162
  return false;
@@ -314,13 +211,13 @@ var Updater = class {
314
211
  return await compare(appVersion, version);
315
212
  }
316
213
  async parseData(format, data) {
317
- if ((0, import_node_fs3.existsSync)(this.tmpFilePath)) {
214
+ if (existsSync(this.tmpFilePath)) {
318
215
  this.logger?.warn(`remove tmp file: ${this.tmpFilePath}`);
319
- await (0, import_promises.rm)(this.tmpFilePath);
216
+ await rm(this.tmpFilePath);
320
217
  }
321
- if ((0, import_node_fs3.existsSync)(this.gzipPath)) {
218
+ if (existsSync(this.gzipPath)) {
322
219
  this.logger?.warn(`remove .gz file: ${this.gzipPath}`);
323
- await (0, import_promises.rm)(this.gzipPath);
220
+ await rm(this.gzipPath);
324
221
  }
325
222
  if (!["string", "object", "undefined"].includes(typeof data)) {
326
223
  throw new TypeError(`invalid type at format '${format}': ${data}`);
@@ -346,7 +243,7 @@ var Updater = class {
346
243
  } : {
347
244
  name: "releaseAsarURL",
348
245
  url: this.option.releaseAsarURL,
349
- repoFallback: `${this.option.repository}/releases/download/v${this.info?.version}/${import_electron3.app.name}-${this.info?.version}.asar.gz`,
246
+ repoFallback: `${this.option.repository}/releases/download/v${this.info?.version}/${app.name}-${this.info?.version}.asar.gz`,
350
247
  fn: this.option.overrideFunctions?.downloadBuffer ?? downloadBufferDefault
351
248
  };
352
249
  data ??= config.url;
@@ -432,7 +329,7 @@ var Updater = class {
432
329
  }
433
330
  this.logger?.info("verify success");
434
331
  this.logger?.info(`write to ${this.gzipPath}`);
435
- await (0, import_promises.writeFile)(this.gzipPath, buffer);
332
+ await writeFile(this.gzipPath, buffer);
436
333
  this.logger?.info(`extract to ${this.tmpFilePath}`);
437
334
  await unzipFile(this.gzipPath, this.tmpFilePath);
438
335
  this.logger?.info(`download success, version: ${_ver}`);
@@ -479,21 +376,21 @@ function initApp(appOptions) {
479
376
  function handleError(err, logger) {
480
377
  console.error(err);
481
378
  onStartError?.(err, logger);
482
- import_electron4.app.quit();
379
+ app2.quit();
483
380
  }
484
381
  async function startup(updater) {
485
382
  const logger = updater.logger;
486
383
  try {
487
384
  const appNameAsarPath = getPathFromAppNameAsar();
488
385
  const tempAsarPath = `${appNameAsarPath}.tmp`;
489
- if ((0, import_node_fs4.existsSync)(tempAsarPath)) {
386
+ if (existsSync2(tempAsarPath)) {
490
387
  logger?.info(`installing new asar: ${tempAsarPath}`);
491
- await onInstall(() => (0, import_node_fs4.renameSync)(tempAsarPath, appNameAsarPath), tempAsarPath, appNameAsarPath, logger);
388
+ await onInstall(() => renameSync(tempAsarPath, appNameAsarPath), tempAsarPath, appNameAsarPath, logger);
492
389
  }
493
390
  const mainDir = is.dev ? electronDevDistPath : appNameAsarPath;
494
- const entry = (0, import_node_path2.resolve)(__dirname, mainDir, mainPath);
391
+ const entry = resolve(__dirname, mainDir, mainPath);
495
392
  await beforeStart?.(entry, logger);
496
- require(entry)(updater);
393
+ __require(entry)(updater);
497
394
  } catch (error) {
498
395
  handleError(error, logger);
499
396
  }
@@ -514,8 +411,7 @@ function initApp(appOptions) {
514
411
  }
515
412
  };
516
413
  }
517
- // Annotate the CommonJS export names for ESM import in node:
518
- 0 && (module.exports = {
414
+ export {
519
415
  DownloadError,
520
416
  MinimumVersionError,
521
417
  Updater,
@@ -523,4 +419,4 @@ function initApp(appOptions) {
523
419
  createUpdater,
524
420
  initApp,
525
421
  startupWithUpdater
526
- });
422
+ };
package/dist/utils.cjs ADDED
@@ -0,0 +1,270 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/utils/index.ts
21
+ var utils_exports = {};
22
+ __export(utils_exports, {
23
+ disableHWAccForWin7: () => disableHWAccForWin7,
24
+ getPathFromAppNameAsar: () => getPathFromAppNameAsar,
25
+ getPaths: () => getPaths,
26
+ getVersions: () => getVersions,
27
+ handleUnexpectedErrors: () => handleUnexpectedErrors,
28
+ is: () => is,
29
+ isUpdateJSON: () => isUpdateJSON,
30
+ loadNativeModuleFromEntry: () => loadNativeModuleFromEntry,
31
+ parseGithubCdnURL: () => parseGithubCdnURL,
32
+ parseVersion: () => parseVersion,
33
+ restartApp: () => restartApp,
34
+ setAppUserModelId: () => setAppUserModelId,
35
+ setPortableAppDataPath: () => setPortableAppDataPath,
36
+ singleInstance: () => singleInstance,
37
+ unzipFile: () => unzipFile,
38
+ waitAppReady: () => waitAppReady,
39
+ zipFile: () => zipFile
40
+ });
41
+ module.exports = __toCommonJS(utils_exports);
42
+
43
+ // src/utils/electron.ts
44
+ var import_node_fs = require("fs");
45
+ var import_node_path = require("path");
46
+ var import_node_os = require("os");
47
+ var import_electron = require("electron");
48
+ var is = {
49
+ dev: !import_electron.app.isPackaged,
50
+ win: process.platform === "win32",
51
+ mac: process.platform === "darwin",
52
+ linux: process.platform === "linux"
53
+ };
54
+ function getPathFromAppNameAsar(...path) {
55
+ return is.dev ? "DEV.asar" : (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${import_electron.app.name}.asar`, ...path);
56
+ }
57
+ function getVersions() {
58
+ const platform = is.win ? "Windows" : is.mac ? "MacOS" : process.platform.toUpperCase();
59
+ return {
60
+ appVersion: is.dev ? import_electron.app.getVersion() : (0, import_node_fs.readFileSync)(getPathFromAppNameAsar("version"), "utf-8"),
61
+ entryVersion: import_electron.app.getVersion(),
62
+ electronVersion: process.versions.electron,
63
+ nodeVersion: process.versions.node,
64
+ systemVersion: `${platform} ${(0, import_node_os.release)()}`
65
+ };
66
+ }
67
+ function loadNativeModuleFromEntry(devEntryDirPath = "../../dist-entry", entryDirPath = (0, import_node_path.join)(import_electron.app.getAppPath(), (0, import_node_path.basename)(devEntryDirPath))) {
68
+ const path = is.dev ? devEntryDirPath : entryDirPath;
69
+ return (moduleName) => {
70
+ try {
71
+ return require((0, import_node_path.join)(path, moduleName));
72
+ } catch (error) {
73
+ console.error("fail to load module", error);
74
+ }
75
+ };
76
+ }
77
+ function restartApp() {
78
+ import_electron.app.relaunch();
79
+ import_electron.app.quit();
80
+ }
81
+ function setAppUserModelId(id) {
82
+ import_electron.app.setAppUserModelId(is.dev ? process.execPath : id ?? `org.${import_electron.app.name}`);
83
+ }
84
+ function disableHWAccForWin7() {
85
+ if ((0, import_node_os.release)().startsWith("6.1")) {
86
+ import_electron.app.disableHardwareAcceleration();
87
+ }
88
+ }
89
+ function singleInstance(window) {
90
+ const result = import_electron.app.requestSingleInstanceLock();
91
+ result ? import_electron.app.on("second-instance", () => {
92
+ if (window) {
93
+ window.show();
94
+ if (window.isMinimized()) {
95
+ window.restore();
96
+ }
97
+ window.focus();
98
+ }
99
+ }) : import_electron.app.quit();
100
+ return result;
101
+ }
102
+ function setPortableAppDataPath(dirName = "data") {
103
+ const portablePath = (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getPath("exe")), dirName);
104
+ if (!(0, import_node_fs.existsSync)(portablePath)) {
105
+ (0, import_node_fs.mkdirSync)(portablePath);
106
+ }
107
+ import_electron.app.setPath("appData", portablePath);
108
+ }
109
+ function waitAppReady(timeout = 1e3) {
110
+ return import_electron.app.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
111
+ const _ = setTimeout(() => {
112
+ reject(new Error("app is not ready"));
113
+ }, timeout);
114
+ import_electron.app.whenReady().then(() => {
115
+ clearTimeout(_);
116
+ resolve();
117
+ });
118
+ });
119
+ }
120
+ function getPaths(entryDirName = "dist-entry") {
121
+ const root = (0, import_node_path.join)(__dirname, "..");
122
+ const mainDirPath = (0, import_node_path.join)(root, "main");
123
+ const preloadDirPath = (0, import_node_path.join)(root, "preload");
124
+ const rendererDirPath = (0, import_node_path.join)(root, "renderer");
125
+ const devServerURL = process.env.VITE_DEV_SERVER_URL;
126
+ const indexHTMLPath = (0, import_node_path.join)(rendererDirPath, "index.html");
127
+ const publicDirPath = devServerURL ? (0, import_node_path.join)(root, "../public") : rendererDirPath;
128
+ return {
129
+ /**
130
+ * @example
131
+ * ```ts
132
+ * devServerURL && win.loadURL(devServerURL)
133
+ * ```
134
+ */
135
+ devServerURL,
136
+ /**
137
+ * @example
138
+ * ```ts
139
+ * win.loadFile(indexHTMLPath)
140
+ * ```
141
+ */
142
+ indexHTMLPath,
143
+ /**
144
+ * get path inside entry asar
145
+ * @param paths joined path
146
+ */
147
+ getPathFromEntryAsar(...paths) {
148
+ return (0, import_node_path.join)(import_electron.app.getAppPath(), entryDirName, ...paths);
149
+ },
150
+ /**
151
+ * get path inside `${app.name}.asar/main`
152
+ * @param paths joined path
153
+ */
154
+ getPathFromMain(...paths) {
155
+ return (0, import_node_path.join)(mainDirPath, ...paths);
156
+ },
157
+ /**
158
+ * get path inside `${app.name}.asar/preload`
159
+ * @param paths joined path
160
+ */
161
+ getPathFromPreload(...paths) {
162
+ return (0, import_node_path.join)(preloadDirPath, ...paths);
163
+ },
164
+ /**
165
+ * get path inside public dir
166
+ * @param paths joined path
167
+ */
168
+ getPathFromPublic(...paths) {
169
+ return (0, import_node_path.join)(publicDirPath, ...paths);
170
+ }
171
+ };
172
+ }
173
+
174
+ // src/utils/zip.ts
175
+ var import_node_fs2 = require("fs");
176
+ var import_node_zlib = require("zlib");
177
+ async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
178
+ if (!(0, import_node_fs2.existsSync)(gzipPath)) {
179
+ throw new Error(`path to zipped file not exist: ${gzipPath}`);
180
+ }
181
+ const compressedBuffer = (0, import_node_fs2.readFileSync)(gzipPath);
182
+ return new Promise((resolve, reject) => {
183
+ (0, import_node_zlib.gunzip)(compressedBuffer, (err, buffer) => {
184
+ (0, import_node_fs2.rmSync)(gzipPath);
185
+ if (err) {
186
+ reject(err);
187
+ }
188
+ (0, import_node_fs2.writeFileSync)(targetFilePath, buffer);
189
+ resolve(null);
190
+ });
191
+ });
192
+ }
193
+ async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
194
+ if (!(0, import_node_fs2.existsSync)(filePath)) {
195
+ throw new Error(`path to be zipped not exist: ${filePath}`);
196
+ }
197
+ const buffer = (0, import_node_fs2.readFileSync)(filePath);
198
+ return new Promise((resolve, reject) => {
199
+ (0, import_node_zlib.gzip)(buffer, (err, buffer2) => {
200
+ if (err) {
201
+ reject(err);
202
+ }
203
+ (0, import_node_fs2.writeFileSync)(targetFilePath, buffer2);
204
+ resolve(null);
205
+ });
206
+ });
207
+ }
208
+
209
+ // src/utils/pure.ts
210
+ function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
211
+ if (!originRepoURL.startsWith("https://github.com/")) {
212
+ throw new Error("origin url must start with https://github.com/");
213
+ }
214
+ originRepoURL = originRepoURL.trim().replace(/\/?$/, "/").trim();
215
+ relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
216
+ cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
217
+ return originRepoURL.replace("github.com", cdnPrefix) + relativeFilePath;
218
+ }
219
+ function handleUnexpectedErrors(callback) {
220
+ process.on("uncaughtException", callback);
221
+ process.on("unhandledRejection", callback);
222
+ }
223
+ function parseVersion(version) {
224
+ const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i;
225
+ const match = semver.exec(version);
226
+ if (!match) {
227
+ throw new TypeError(`invalid version: ${version}`);
228
+ }
229
+ const [major, minor, patch] = match.slice(1, 4).map(Number);
230
+ const ret = {
231
+ major,
232
+ minor,
233
+ patch,
234
+ stage: "",
235
+ stageVersion: -1
236
+ };
237
+ if (match[4]) {
238
+ let [stage, _v] = match[4].split(".");
239
+ ret.stage = stage;
240
+ ret.stageVersion = Number(_v) || -1;
241
+ }
242
+ if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
243
+ throw new TypeError(`invalid version: ${version}`);
244
+ }
245
+ return ret;
246
+ }
247
+ function isUpdateJSON(json) {
248
+ const is2 = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
249
+ return is2(json) && is2(json?.beta);
250
+ }
251
+ // Annotate the CommonJS export names for ESM import in node:
252
+ 0 && (module.exports = {
253
+ disableHWAccForWin7,
254
+ getPathFromAppNameAsar,
255
+ getPaths,
256
+ getVersions,
257
+ handleUnexpectedErrors,
258
+ is,
259
+ isUpdateJSON,
260
+ loadNativeModuleFromEntry,
261
+ parseGithubCdnURL,
262
+ parseVersion,
263
+ restartApp,
264
+ setAppUserModelId,
265
+ setPortableAppDataPath,
266
+ singleInstance,
267
+ unzipFile,
268
+ waitAppReady,
269
+ zipFile
270
+ });
@@ -1,21 +1,19 @@
1
1
  import { BrowserWindow } from 'electron';
2
- export { U as UpdateInfo, a as UpdateJSON, V as Version, h as handleUnexpectedErrors, i as isUpdateJSON, p as parseGithubCdnURL, b as parseVersion } from './noDep-TvZoKVF8.mjs';
2
+ export { U as UpdateInfo, a as UpdateJSON, V as Version, h as handleUnexpectedErrors, i as isUpdateJSON, p as parseGithubCdnURL, b as parseVersion } from './pure-GoN_3MEj.cjs';
3
3
 
4
- type Is = {
5
- dev: boolean;
6
- win: boolean;
7
- mac: boolean;
8
- linux: boolean;
9
- };
10
4
  /**
11
- * get app info
5
+ * app info
12
6
  */
13
- declare const is: Is;
7
+ declare const is: {
8
+ readonly dev: boolean;
9
+ readonly win: boolean;
10
+ readonly mac: boolean;
11
+ readonly linux: boolean;
12
+ };
14
13
  /**
15
- * get the absolute path of `${app.name}.asar` (not `app.asar`)
14
+ * get the absolute path of `${electron.app.name}.asar` (not `app.asar`)
16
15
  *
17
16
  * if is in dev, return `'DEV.asar'`
18
- * @todo change a better function name or merge into {@link getPaths}
19
17
  */
20
18
  declare function getPathFromAppNameAsar(...path: string[]): string;
21
19
  /**
package/dist/utils.d.ts CHANGED
@@ -1,21 +1,19 @@
1
1
  import { BrowserWindow } from 'electron';
2
- export { U as UpdateInfo, a as UpdateJSON, V as Version, h as handleUnexpectedErrors, i as isUpdateJSON, p as parseGithubCdnURL, b as parseVersion } from './noDep-TvZoKVF8.js';
2
+ export { U as UpdateInfo, a as UpdateJSON, V as Version, h as handleUnexpectedErrors, i as isUpdateJSON, p as parseGithubCdnURL, b as parseVersion } from './pure-GoN_3MEj.js';
3
3
 
4
- type Is = {
5
- dev: boolean;
6
- win: boolean;
7
- mac: boolean;
8
- linux: boolean;
9
- };
10
4
  /**
11
- * get app info
5
+ * app info
12
6
  */
13
- declare const is: Is;
7
+ declare const is: {
8
+ readonly dev: boolean;
9
+ readonly win: boolean;
10
+ readonly mac: boolean;
11
+ readonly linux: boolean;
12
+ };
14
13
  /**
15
- * get the absolute path of `${app.name}.asar` (not `app.asar`)
14
+ * get the absolute path of `${electron.app.name}.asar` (not `app.asar`)
16
15
  *
17
16
  * if is in dev, return `'DEV.asar'`
18
- * @todo change a better function name or merge into {@link getPaths}
19
17
  */
20
18
  declare function getPathFromAppNameAsar(...path: string[]): string;
21
19
  /**