electron-incremental-update 2.0.0-beta.2 → 2.0.0-beta.4

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.
@@ -1,7 +1,38 @@
1
1
  import { Promisable } from '@subframe7536/type-utils';
2
- import { U as UpdateJSON, a as UpdateInfo } from './version-CffZWDhZ.cjs';
3
2
 
4
- type URLHandler = (url: string, isDownloadAsar: boolean) => string;
3
+ /**
4
+ * handle all unhandled error
5
+ * @param callback callback function
6
+ */
7
+ declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
8
+ interface Version {
9
+ major: number;
10
+ minor: number;
11
+ patch: number;
12
+ stage: string;
13
+ stageVersion: number;
14
+ }
15
+ declare function parseVersion(version: string): Version;
16
+ declare function defaultIsLowerVersion(oldVer: string, newVer: string): boolean;
17
+ /**
18
+ * update info json
19
+ */
20
+ type UpdateInfo = {
21
+ signature: string;
22
+ minimumVersion: string;
23
+ version: string;
24
+ size: number;
25
+ };
26
+ /**
27
+ * {@link UpdateInfo} with beta
28
+ */
29
+ type UpdateJSON = UpdateInfo & {
30
+ beta: UpdateInfo;
31
+ };
32
+ declare function isUpdateJSON(json: any): json is UpdateJSON;
33
+ declare function defaultVersionJsonGenerator(existingJson: UpdateJSON, buffer: Buffer, signature: string, version: string, minimumVersion: string): UpdateJSON;
34
+
35
+ type URLHandler = (url: URL, isDownloadAsar: boolean) => Promisable<URL | string | undefined | null>;
5
36
  type OnDownloading = (progress: DownloadingInfo) => void;
6
37
  interface DownloadingInfo {
7
38
  /**
@@ -56,6 +87,11 @@ interface IProvider {
56
87
  * @returns if version1 < version2
57
88
  */
58
89
  isLowerVersion: (oldVer: string, newVer: string) => boolean;
90
+ /**
91
+ * unzip file buffer
92
+ * @param buffer source buffer
93
+ */
94
+ unzipFile: (buffer: Buffer) => Promise<Buffer>;
59
95
  /**
60
96
  * verify asar signature
61
97
  * @param buffer file buffer
@@ -66,4 +102,4 @@ interface IProvider {
66
102
  verifySignaure: (buffer: Buffer, signature: string, cert: string) => Promisable<string | undefined>;
67
103
  }
68
104
 
69
- export type { DownloadingInfo as D, IProvider as I, OnDownloading as O, URLHandler as U };
105
+ export { type DownloadingInfo as D, type IProvider as I, type OnDownloading as O, type UpdateInfo as U, type Version as V, type UpdateJSON as a, defaultVersionJsonGenerator as b, type URLHandler as c, defaultIsLowerVersion as d, handleUnexpectedErrors as h, isUpdateJSON as i, parseVersion as p };
package/dist/utils.cjs CHANGED
@@ -1,95 +1,51 @@
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);
1
+ 'use strict';
19
2
 
20
- // src/utils/index.ts
21
- var utils_exports = {};
22
- __export(utils_exports, {
23
- decrypt: () => decrypt,
24
- disableHWAccForWin7: () => disableHWAccForWin7,
25
- encrypt: () => encrypt,
26
- getAppVersion: () => getAppVersion,
27
- getEntryVersion: () => getEntryVersion,
28
- getPathFromAppNameAsar: () => getPathFromAppNameAsar,
29
- getPathFromEntryAsar: () => getPathFromEntryAsar,
30
- getPathFromPreload: () => getPathFromPreload,
31
- getPathFromPublic: () => getPathFromPublic,
32
- handleUnexpectedErrors: () => handleUnexpectedErrors,
33
- hashString: () => hashString,
34
- isDev: () => isDev,
35
- isLinux: () => isLinux,
36
- isLowerVersionDefault: () => isLowerVersionDefault,
37
- isMac: () => isMac,
38
- isUpdateJSON: () => isUpdateJSON,
39
- isWin: () => isWin,
40
- loadPage: () => loadPage,
41
- parseVersion: () => parseVersion,
42
- requireNative: () => requireNative,
43
- restartApp: () => restartApp,
44
- setAppUserModelId: () => setAppUserModelId,
45
- setPortableAppDataPath: () => setPortableAppDataPath,
46
- signature: () => signature,
47
- singleInstance: () => singleInstance,
48
- unzipFile: () => unzipFile,
49
- verifySignatureDefault: () => verifySignatureDefault,
50
- waitAppReady: () => waitAppReady,
51
- zipFile: () => zipFile
52
- });
53
- module.exports = __toCommonJS(utils_exports);
3
+ var fs = require('fs');
4
+ var path = require('path');
5
+ var electron = require('electron');
6
+ var zlib = require('zlib');
7
+ var crypto = require('crypto');
54
8
 
55
- // src/utils/electron.ts
56
- var import_node_fs = require("fs");
57
- var import_node_path = require("path");
58
- var import_electron = require("electron");
9
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
10
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
11
+ }) : x)(function(x) {
12
+ if (typeof require !== "undefined") return require.apply(this, arguments);
13
+ throw Error('Dynamic require of "' + x + '" is not supported');
14
+ });
59
15
  var isDev = __EIU_IS_DEV__;
60
16
  var isWin = process.platform === "win32";
61
17
  var isMac = process.platform === "darwin";
62
18
  var isLinux = process.platform === "linux";
63
- function getPathFromAppNameAsar(...path) {
64
- return isDev ? "DEV.asar" : (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${import_electron.app.name}.asar`, ...path);
19
+ function getPathFromAppNameAsar(...path$1) {
20
+ return isDev ? "DEV.asar" : path.join(path.dirname(electron.app.getAppPath()), `${electron.app.name}.asar`, ...path$1);
65
21
  }
66
22
  function getAppVersion() {
67
- return isDev ? getEntryVersion() : (0, import_node_fs.readFileSync)(getPathFromAppNameAsar("version"), "utf-8");
23
+ return isDev ? getEntryVersion() : fs.readFileSync(getPathFromAppNameAsar("version"), "utf-8");
68
24
  }
69
25
  function getEntryVersion() {
70
- return import_electron.app.getVersion();
26
+ return electron.app.getVersion();
71
27
  }
72
28
  function requireNative(moduleName) {
73
- return require((0, import_node_path.join)(import_electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, moduleName));
29
+ return __require(path.join(electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, moduleName));
74
30
  }
75
31
  function restartApp() {
76
- import_electron.app.relaunch();
77
- import_electron.app.quit();
32
+ electron.app.relaunch();
33
+ electron.app.quit();
78
34
  }
79
35
  function setAppUserModelId(id) {
80
36
  if (isWin) {
81
- import_electron.app.setAppUserModelId(id ?? `org.${import_electron.app.name}`);
37
+ electron.app.setAppUserModelId(id ?? `org.${electron.app.name}`);
82
38
  }
83
39
  }
84
40
  function disableHWAccForWin7() {
85
- if (require("os").release().startsWith("6.1")) {
86
- import_electron.app.disableHardwareAcceleration();
41
+ if (__require("os").release().startsWith("6.1")) {
42
+ electron.app.disableHardwareAcceleration();
87
43
  }
88
44
  }
89
45
  function singleInstance(window) {
90
- const result = import_electron.app.requestSingleInstanceLock();
46
+ const result = electron.app.requestSingleInstanceLock();
91
47
  if (result) {
92
- import_electron.app.on("second-instance", () => {
48
+ electron.app.on("second-instance", () => {
93
49
  if (window) {
94
50
  window.show();
95
51
  if (window.isMinimized()) {
@@ -99,27 +55,16 @@ function singleInstance(window) {
99
55
  }
100
56
  });
101
57
  } else {
102
- import_electron.app.quit();
58
+ electron.app.quit();
103
59
  }
104
60
  return result;
105
61
  }
106
62
  function setPortableAppDataPath(dirName = "data") {
107
- const portablePath = (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getPath("exe")), dirName);
108
- if (!(0, import_node_fs.existsSync)(portablePath)) {
109
- (0, import_node_fs.mkdirSync)(portablePath);
63
+ const portablePath = path.join(path.dirname(electron.app.getPath("exe")), dirName);
64
+ if (!fs.existsSync(portablePath)) {
65
+ fs.mkdirSync(portablePath);
110
66
  }
111
- import_electron.app.setPath("appData", portablePath);
112
- }
113
- function waitAppReady(timeout = 1e3) {
114
- return import_electron.app.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
115
- const _ = setTimeout(() => {
116
- reject(new Error("app is not ready"));
117
- }, timeout);
118
- import_electron.app.whenReady().then(() => {
119
- clearTimeout(_);
120
- resolve();
121
- });
122
- });
67
+ electron.app.setPath("appData", portablePath);
123
68
  }
124
69
  function loadPage(win, htmlFilePath = "index.html") {
125
70
  if (isDev) {
@@ -129,50 +74,33 @@ function loadPage(win, htmlFilePath = "index.html") {
129
74
  }
130
75
  }
131
76
  function getPathFromPreload(...paths) {
132
- return isDev ? (0, import_node_path.join)(import_electron.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
77
+ return isDev ? path.join(electron.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
133
78
  }
134
79
  function getPathFromPublic(...paths) {
135
- return isDev ? (0, import_node_path.join)(import_electron.app.getAppPath(), "public", ...paths) : getPathFromAppNameAsar("renderer", ...paths);
80
+ return isDev ? path.join(electron.app.getAppPath(), "public", ...paths) : getPathFromAppNameAsar("renderer", ...paths);
136
81
  }
137
82
  function getPathFromEntryAsar(...paths) {
138
- return (0, import_node_path.join)(import_electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
83
+ return path.join(electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
139
84
  }
140
-
141
- // src/utils/zip.ts
142
- var import_node_fs2 = require("fs");
143
- var import_node_zlib = require("zlib");
144
- async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
145
- if (!(0, import_node_fs2.existsSync)(filePath)) {
146
- throw new Error(`path to be zipped not exist: ${filePath}`);
147
- }
148
- const buffer = (0, import_node_fs2.readFileSync)(filePath);
85
+ async function defaultZipFile(buffer) {
149
86
  return new Promise((resolve, reject) => {
150
- (0, import_node_zlib.brotliCompress)(buffer, (err, buffer2) => {
87
+ zlib.brotliCompress(buffer, (err, buffer2) => {
151
88
  if (err) {
152
89
  reject(err);
90
+ } else {
91
+ resolve(buffer2);
153
92
  }
154
- (0, import_node_fs2.writeFileSync)(targetFilePath, buffer2);
155
- resolve();
156
93
  });
157
94
  });
158
95
  }
159
-
160
- // src/utils/unzip.ts
161
- var import_node_fs3 = require("fs");
162
- var import_node_zlib2 = require("zlib");
163
- async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
164
- if (!(0, import_node_fs3.existsSync)(gzipPath)) {
165
- throw new Error(`path to zipped file not exist: ${gzipPath}`);
166
- }
167
- const compressedBuffer = (0, import_node_fs3.readFileSync)(gzipPath);
96
+ async function defaultUnzipFile(buffer) {
168
97
  return new Promise((resolve, reject) => {
169
- (0, import_node_zlib2.brotliDecompress)(compressedBuffer, (err, buffer) => {
170
- (0, import_node_fs3.rmSync)(gzipPath);
98
+ zlib.brotliDecompress(buffer, (err, buffer2) => {
171
99
  if (err) {
172
100
  reject(err);
101
+ } else {
102
+ resolve(buffer2);
173
103
  }
174
- (0, import_node_fs3.writeFileSync)(targetFilePath, buffer);
175
- resolve();
176
104
  });
177
105
  });
178
106
  }
@@ -205,7 +133,7 @@ function parseVersion(version) {
205
133
  }
206
134
  return ret;
207
135
  }
208
- function isLowerVersionDefault(oldVer, newVer) {
136
+ function defaultIsLowerVersion(oldVer, newVer) {
209
137
  const oldV = parseVersion(oldVer);
210
138
  const newV = parseVersion(newVer);
211
139
  function compareStrings(str1, str2) {
@@ -229,75 +157,81 @@ function isUpdateJSON(json) {
229
157
  const is = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
230
158
  return is(json) && is(json?.beta);
231
159
  }
232
-
233
- // src/utils/crypto/decrypt.ts
234
- var import_node_crypto2 = require("crypto");
235
-
236
- // src/utils/crypto/utils.ts
237
- var import_node_crypto = require("crypto");
238
- function hashString(data, length) {
239
- const hash = (0, import_node_crypto.createHash)("SHA256").update(data).digest("binary");
160
+ function defaultVersionJsonGenerator(existingJson, buffer, signature, version, minimumVersion) {
161
+ existingJson.beta = {
162
+ version,
163
+ minimumVersion,
164
+ signature,
165
+ size: buffer.length
166
+ };
167
+ if (!parseVersion(version).stage) {
168
+ existingJson.version = version;
169
+ existingJson.minimumVersion = minimumVersion;
170
+ existingJson.signature = signature;
171
+ existingJson.size = buffer.length;
172
+ }
173
+ return existingJson;
174
+ }
175
+ function hashBuffer(data, length) {
176
+ const hash = crypto.createHash("SHA256").update(data).digest("binary");
240
177
  return Buffer.from(hash).subarray(0, length);
241
178
  }
242
-
243
- // src/utils/crypto/decrypt.ts
244
- function decrypt(encryptedText, key, iv) {
245
- const decipher = (0, import_node_crypto2.createDecipheriv)("aes-256-cbc", key, iv);
246
- let decrypted = decipher.update(encryptedText, "base64url", "utf8");
247
- decrypted += decipher.final("utf8");
248
- return decrypted;
179
+ function aesEncrypt(plainText, key, iv) {
180
+ const cipher = crypto.createCipheriv("aes-256-cbc", key, iv);
181
+ return cipher.update(plainText, "utf8", "base64url") + cipher.final("base64url");
182
+ }
183
+ function defaultSignature(buffer, privateKey, cert, version) {
184
+ const sig = crypto.createSign("RSA-SHA256").update(buffer).sign(crypto.createPrivateKey(privateKey), "base64");
185
+ return aesEncrypt(`${sig}%${version}`, hashBuffer(cert, 32), hashBuffer(buffer, 16));
249
186
  }
250
- function verifySignatureDefault(buffer, signature2, cert) {
187
+ function aesDecrypt(encryptedText, key, iv) {
188
+ const decipher = crypto.createDecipheriv("aes-256-cbc", key, iv);
189
+ return decipher.update(encryptedText, "base64url", "utf8") + decipher.final("utf8");
190
+ }
191
+ function defaultVerify(buffer, signature, cert) {
251
192
  try {
252
- const [sig, version] = decrypt(signature2, hashString(cert, 32), hashString(buffer, 16)).split("%");
253
- const result = (0, import_node_crypto2.createVerify)("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
193
+ const [sig, version] = aesDecrypt(signature, hashBuffer(cert, 32), hashBuffer(buffer, 16)).split("%");
194
+ const result = crypto.createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
254
195
  return result ? version : void 0;
255
196
  } catch {
256
197
  return void 0;
257
198
  }
258
199
  }
259
200
 
260
- // src/utils/crypto/encrypt.ts
261
- var import_node_crypto3 = require("crypto");
262
- function encrypt(plainText, key, iv) {
263
- const cipher = (0, import_node_crypto3.createCipheriv)("aes-256-cbc", key, iv);
264
- let encrypted = cipher.update(plainText, "utf8", "base64url");
265
- encrypted += cipher.final("base64url");
266
- return encrypted;
267
- }
268
- function signature(buffer, privateKey, cert, version) {
269
- const sig = (0, import_node_crypto3.createSign)("RSA-SHA256").update(buffer).sign((0, import_node_crypto3.createPrivateKey)(privateKey), "base64");
270
- return encrypt(`${sig}%${version}`, hashString(cert, 32), hashString(buffer, 16));
201
+ // src/utils/updater.ts
202
+ async function autoUpdate(updater) {
203
+ if (await updater.checkUpdate() && await updater.downloadUpdate()) {
204
+ updater.quitAndInstall();
205
+ }
271
206
  }
272
- // Annotate the CommonJS export names for ESM import in node:
273
- 0 && (module.exports = {
274
- decrypt,
275
- disableHWAccForWin7,
276
- encrypt,
277
- getAppVersion,
278
- getEntryVersion,
279
- getPathFromAppNameAsar,
280
- getPathFromEntryAsar,
281
- getPathFromPreload,
282
- getPathFromPublic,
283
- handleUnexpectedErrors,
284
- hashString,
285
- isDev,
286
- isLinux,
287
- isLowerVersionDefault,
288
- isMac,
289
- isUpdateJSON,
290
- isWin,
291
- loadPage,
292
- parseVersion,
293
- requireNative,
294
- restartApp,
295
- setAppUserModelId,
296
- setPortableAppDataPath,
297
- signature,
298
- singleInstance,
299
- unzipFile,
300
- verifySignatureDefault,
301
- waitAppReady,
302
- zipFile
303
- });
207
+
208
+ exports.aesDecrypt = aesDecrypt;
209
+ exports.aesEncrypt = aesEncrypt;
210
+ exports.autoUpdate = autoUpdate;
211
+ exports.defaultIsLowerVersion = defaultIsLowerVersion;
212
+ exports.defaultSignature = defaultSignature;
213
+ exports.defaultUnzipFile = defaultUnzipFile;
214
+ exports.defaultVerify = defaultVerify;
215
+ exports.defaultVersionJsonGenerator = defaultVersionJsonGenerator;
216
+ exports.defaultZipFile = defaultZipFile;
217
+ exports.disableHWAccForWin7 = disableHWAccForWin7;
218
+ exports.getAppVersion = getAppVersion;
219
+ exports.getEntryVersion = getEntryVersion;
220
+ exports.getPathFromAppNameAsar = getPathFromAppNameAsar;
221
+ exports.getPathFromEntryAsar = getPathFromEntryAsar;
222
+ exports.getPathFromPreload = getPathFromPreload;
223
+ exports.getPathFromPublic = getPathFromPublic;
224
+ exports.handleUnexpectedErrors = handleUnexpectedErrors;
225
+ exports.hashBuffer = hashBuffer;
226
+ exports.isDev = isDev;
227
+ exports.isLinux = isLinux;
228
+ exports.isMac = isMac;
229
+ exports.isUpdateJSON = isUpdateJSON;
230
+ exports.isWin = isWin;
231
+ exports.loadPage = loadPage;
232
+ exports.parseVersion = parseVersion;
233
+ exports.requireNative = requireNative;
234
+ exports.restartApp = restartApp;
235
+ exports.setAppUserModelId = setAppUserModelId;
236
+ exports.setPortableAppDataPath = setPortableAppDataPath;
237
+ exports.singleInstance = singleInstance;
package/dist/utils.d.cts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { BrowserWindow } from 'electron';
2
- export { a as UpdateInfo, U as UpdateJSON, V as Version, h as handleUnexpectedErrors, i as isLowerVersionDefault, b as isUpdateJSON, p as parseVersion } from './version-CffZWDhZ.cjs';
3
- export { d as decrypt, v as verifySignatureDefault } from './decrypt-D9WdXYjH.cjs';
2
+ export { e as aesDecrypt, b as aesEncrypt, c as defaultSignature, a as defaultUnzipFile, f as defaultVerify, d as defaultZipFile, h as hashBuffer } from './zip-WRrEMkgp.cjs';
3
+ export { U as UpdateInfo, a as UpdateJSON, V as Version, d as defaultIsLowerVersion, b as defaultVersionJsonGenerator, h as handleUnexpectedErrors, i as isUpdateJSON, p as parseVersion } from './types-Bz1VD18z.cjs';
4
+ import { U as Updater } from './core-CW7TMqi7.cjs';
5
+ import '@subframe7536/type-utils';
6
+ import 'node:events';
4
7
 
5
8
  /**
6
9
  * compile time dev check
@@ -54,11 +57,6 @@ declare function singleInstance(window?: BrowserWindow): boolean;
54
57
  * @param dirName dir name, default to `data`
55
58
  */
56
59
  declare function setPortableAppDataPath(dirName?: string): void;
57
- /**
58
- * ensure app is ready.
59
- * @param timeout wait timeout, @default 1000
60
- */
61
- declare function waitAppReady(timeout?: number): Promise<void>;
62
60
  /**
63
61
  * load `process.env.VITE_DEV_SERVER_URL` when dev, else load html file
64
62
  * @param win window
@@ -69,13 +67,9 @@ declare function getPathFromPreload(...paths: string[]): string;
69
67
  declare function getPathFromPublic(...paths: string[]): string;
70
68
  declare function getPathFromEntryAsar(...paths: string[]): string;
71
69
 
72
- declare function zipFile(filePath: string, targetFilePath?: string): Promise<void>;
73
-
74
- declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<void>;
75
-
76
- declare function encrypt(plainText: string, key: Buffer, iv: Buffer): string;
77
- declare function signature(buffer: Buffer, privateKey: string, cert: string, version: string): string;
78
-
79
- declare function hashString(data: string | Buffer, length: number): Buffer;
70
+ /**
71
+ * auto check update, download and install
72
+ */
73
+ declare function autoUpdate(updater: Updater): Promise<void>;
80
74
 
81
- export { disableHWAccForWin7, encrypt, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, hashString, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, signature, singleInstance, unzipFile, waitAppReady, zipFile };
75
+ export { autoUpdate, disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { BrowserWindow } from 'electron';
2
- export { a as UpdateInfo, U as UpdateJSON, V as Version, h as handleUnexpectedErrors, i as isLowerVersionDefault, b as isUpdateJSON, p as parseVersion } from './version-CffZWDhZ.js';
3
- export { d as decrypt, v as verifySignatureDefault } from './decrypt-D9WdXYjH.js';
2
+ export { e as aesDecrypt, b as aesEncrypt, c as defaultSignature, a as defaultUnzipFile, f as defaultVerify, d as defaultZipFile, h as hashBuffer } from './zip-WRrEMkgp.js';
3
+ export { U as UpdateInfo, a as UpdateJSON, V as Version, d as defaultIsLowerVersion, b as defaultVersionJsonGenerator, h as handleUnexpectedErrors, i as isUpdateJSON, p as parseVersion } from './types-Bz1VD18z.js';
4
+ import { U as Updater } from './core-D6QlpOgp.js';
5
+ import '@subframe7536/type-utils';
6
+ import 'node:events';
4
7
 
5
8
  /**
6
9
  * compile time dev check
@@ -54,11 +57,6 @@ declare function singleInstance(window?: BrowserWindow): boolean;
54
57
  * @param dirName dir name, default to `data`
55
58
  */
56
59
  declare function setPortableAppDataPath(dirName?: string): void;
57
- /**
58
- * ensure app is ready.
59
- * @param timeout wait timeout, @default 1000
60
- */
61
- declare function waitAppReady(timeout?: number): Promise<void>;
62
60
  /**
63
61
  * load `process.env.VITE_DEV_SERVER_URL` when dev, else load html file
64
62
  * @param win window
@@ -69,13 +67,9 @@ declare function getPathFromPreload(...paths: string[]): string;
69
67
  declare function getPathFromPublic(...paths: string[]): string;
70
68
  declare function getPathFromEntryAsar(...paths: string[]): string;
71
69
 
72
- declare function zipFile(filePath: string, targetFilePath?: string): Promise<void>;
73
-
74
- declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<void>;
75
-
76
- declare function encrypt(plainText: string, key: Buffer, iv: Buffer): string;
77
- declare function signature(buffer: Buffer, privateKey: string, cert: string, version: string): string;
78
-
79
- declare function hashString(data: string | Buffer, length: number): Buffer;
70
+ /**
71
+ * auto check update, download and install
72
+ */
73
+ declare function autoUpdate(updater: Updater): Promise<void>;
80
74
 
81
- export { disableHWAccForWin7, encrypt, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, hashString, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, signature, singleInstance, unzipFile, waitAppReady, zipFile };
75
+ export { autoUpdate, disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
package/dist/utils.js CHANGED
@@ -1,62 +1,12 @@
1
- import {
2
- decrypt,
3
- disableHWAccForWin7,
4
- encrypt,
5
- getAppVersion,
6
- getEntryVersion,
7
- getPathFromAppNameAsar,
8
- getPathFromEntryAsar,
9
- getPathFromPreload,
10
- getPathFromPublic,
11
- handleUnexpectedErrors,
12
- hashString,
13
- isDev,
14
- isLinux,
15
- isLowerVersionDefault,
16
- isMac,
17
- isUpdateJSON,
18
- isWin,
19
- loadPage,
20
- parseVersion,
21
- requireNative,
22
- restartApp,
23
- setAppUserModelId,
24
- setPortableAppDataPath,
25
- signature,
26
- singleInstance,
27
- unzipFile,
28
- verifySignatureDefault,
29
- waitAppReady,
30
- zipFile
31
- } from "./chunk-BG22XZAB.js";
32
- export {
33
- decrypt,
34
- disableHWAccForWin7,
35
- encrypt,
36
- getAppVersion,
37
- getEntryVersion,
38
- getPathFromAppNameAsar,
39
- getPathFromEntryAsar,
40
- getPathFromPreload,
41
- getPathFromPublic,
42
- handleUnexpectedErrors,
43
- hashString,
44
- isDev,
45
- isLinux,
46
- isLowerVersionDefault,
47
- isMac,
48
- isUpdateJSON,
49
- isWin,
50
- loadPage,
51
- parseVersion,
52
- requireNative,
53
- restartApp,
54
- setAppUserModelId,
55
- setPortableAppDataPath,
56
- signature,
57
- singleInstance,
58
- unzipFile,
59
- verifySignatureDefault,
60
- waitAppReady,
61
- zipFile
62
- };
1
+ export { disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance } from './chunk-PNYRQYFC.js';
2
+ export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerify, defaultZipFile, hashBuffer } from './chunk-JSYIRKTR.js';
3
+ export { defaultIsLowerVersion, defaultVersionJsonGenerator, handleUnexpectedErrors, isUpdateJSON, parseVersion } from './chunk-BVFQWBLK.js';
4
+
5
+ // src/utils/updater.ts
6
+ async function autoUpdate(updater) {
7
+ if (await updater.checkUpdate() && await updater.downloadUpdate()) {
8
+ updater.quitAndInstall();
9
+ }
10
+ }
11
+
12
+ export { autoUpdate };