electron-incremental-update 2.0.0-beta.1 → 2.0.0-beta.10

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