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

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,129 @@
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 electron__default = /*#__PURE__*/_interopDefault(electron);
14
+ var zlib__default = /*#__PURE__*/_interopDefault(zlib);
15
+ var crypto__default = /*#__PURE__*/_interopDefault(crypto);
16
+
17
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
18
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
19
+ }) : x)(function(x) {
20
+ if (typeof require !== "undefined") return require.apply(this, arguments);
21
+ throw Error('Dynamic require of "' + x + '" is not supported');
22
+ });
59
23
  var isDev = __EIU_IS_DEV__;
60
24
  var isWin = process.platform === "win32";
61
25
  var isMac = process.platform === "darwin";
62
26
  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);
27
+ function getPathFromAppNameAsar(...paths) {
28
+ return isDev ? "DEV.asar" : path__default.default.join(path__default.default.dirname(electron__default.default.app.getAppPath()), `${electron__default.default.app.name}.asar`, ...paths);
65
29
  }
66
30
  function getAppVersion() {
67
- return isDev ? getEntryVersion() : (0, import_node_fs.readFileSync)(getPathFromAppNameAsar("version"), "utf-8");
31
+ return isDev ? getEntryVersion() : fs__default.default.readFileSync(getPathFromAppNameAsar("version"), "utf-8");
68
32
  }
69
33
  function getEntryVersion() {
70
- return import_electron.app.getVersion();
34
+ return electron__default.default.app.getVersion();
71
35
  }
72
36
  function requireNative(moduleName) {
73
- return require((0, import_node_path.join)(import_electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, moduleName));
37
+ if (__EIU_IS_ESM__) {
38
+ throw new Error(`Cannot require "${path__default.default.join(__EIU_ENTRY_DIST_PATH__, moduleName)}", \`requireNative\` only support CommonJS`);
39
+ }
40
+ return __require(path__default.default.join(electron__default.default.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, moduleName));
74
41
  }
75
42
  function restartApp() {
76
- import_electron.app.relaunch();
77
- import_electron.app.quit();
43
+ electron__default.default.app.relaunch();
44
+ electron__default.default.app.quit();
78
45
  }
79
46
  function setAppUserModelId(id) {
80
- isWin && import_electron.app.setAppUserModelId(id ?? `org.${import_electron.app.name}`);
47
+ if (isWin) {
48
+ electron__default.default.app.setAppUserModelId(id ?? `org.${electron__default.default.app.name}`);
49
+ }
81
50
  }
82
51
  function disableHWAccForWin7() {
83
- if (require("os").release().startsWith("6.1")) {
84
- import_electron.app.disableHardwareAcceleration();
52
+ if (!__EIU_IS_ESM__ && __require("os").release().startsWith("6.1")) {
53
+ electron__default.default.app.disableHardwareAcceleration();
85
54
  }
86
55
  }
87
56
  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();
57
+ const result = electron__default.default.app.requestSingleInstanceLock();
58
+ if (result) {
59
+ electron__default.default.app.on("second-instance", () => {
60
+ if (window) {
61
+ window.show();
62
+ if (window.isMinimized()) {
63
+ window.restore();
64
+ }
65
+ window.focus();
94
66
  }
95
- window.focus();
96
- }
97
- }) : import_electron.app.quit();
67
+ });
68
+ } else {
69
+ electron__default.default.app.quit();
70
+ }
98
71
  return result;
99
72
  }
100
73
  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);
74
+ const portablePath = path__default.default.join(path__default.default.dirname(electron__default.default.app.getPath("exe")), dirName);
75
+ if (!fs__default.default.existsSync(portablePath)) {
76
+ fs__default.default.mkdirSync(portablePath);
104
77
  }
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
- });
78
+ electron__default.default.app.setPath("appData", portablePath);
117
79
  }
118
80
  function loadPage(win, htmlFilePath = "index.html") {
119
- isDev ? win.loadURL(process.env.VITE_DEV_SERVER_URL + htmlFilePath) : win.loadFile(getPathFromAppNameAsar("renderer", htmlFilePath));
81
+ if (isDev) {
82
+ win.loadURL(process.env.VITE_DEV_SERVER_URL + htmlFilePath);
83
+ } else {
84
+ win.loadFile(getPathFromAppNameAsar("renderer", htmlFilePath));
85
+ }
86
+ }
87
+ function getPathFromMain(...paths) {
88
+ return isDev ? path__default.default.join(electron__default.default.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "main", ...paths) : getPathFromAppNameAsar("main", ...paths);
120
89
  }
121
90
  function getPathFromPreload(...paths) {
122
- return isDev ? (0, import_node_path.join)(import_electron.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
91
+ return isDev ? path__default.default.join(electron__default.default.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
123
92
  }
124
93
  function getPathFromPublic(...paths) {
125
- return isDev ? (0, import_node_path.join)(import_electron.app.getAppPath(), "public", ...paths) : getPathFromAppNameAsar("renderer", ...paths);
94
+ return isDev ? path__default.default.join(electron__default.default.app.getAppPath(), "public", ...paths) : getPathFromAppNameAsar("renderer", ...paths);
126
95
  }
127
96
  function getPathFromEntryAsar(...paths) {
128
- return (0, import_node_path.join)(import_electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
97
+ return path__default.default.join(electron__default.default.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
129
98
  }
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);
99
+ function handleUnexpectedErrors(callback) {
100
+ process.on("uncaughtException", callback);
101
+ process.on("unhandledRejection", callback);
102
+ }
103
+ async function defaultZipFile(buffer) {
139
104
  return new Promise((resolve, reject) => {
140
- (0, import_node_zlib.brotliCompress)(buffer, (err, buffer2) => {
105
+ zlib__default.default.brotliCompress(buffer, (err, buffer2) => {
141
106
  if (err) {
142
107
  reject(err);
108
+ } else {
109
+ resolve(buffer2);
143
110
  }
144
- (0, import_node_fs2.writeFileSync)(targetFilePath, buffer2);
145
- resolve(null);
146
111
  });
147
112
  });
148
113
  }
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);
114
+ async function defaultUnzipFile(buffer) {
158
115
  return new Promise((resolve, reject) => {
159
- (0, import_node_zlib2.brotliDecompress)(compressedBuffer, (err, buffer) => {
160
- (0, import_node_fs3.rmSync)(gzipPath);
116
+ zlib__default.default.brotliDecompress(buffer, (err, buffer2) => {
161
117
  if (err) {
162
118
  reject(err);
119
+ } else {
120
+ resolve(buffer2);
163
121
  }
164
- (0, import_node_fs3.writeFileSync)(targetFilePath, buffer);
165
- resolve(null);
166
122
  });
167
123
  });
168
124
  }
169
125
 
170
126
  // src/utils/version.ts
171
- function handleUnexpectedErrors(callback) {
172
- process.on("uncaughtException", callback);
173
- process.on("unhandledRejection", callback);
174
- }
175
127
  function parseVersion(version) {
176
128
  const match = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i.exec(version);
177
129
  if (!match) {
@@ -191,11 +143,11 @@ function parseVersion(version) {
191
143
  ret.stageVersion = Number(_v) || -1;
192
144
  }
193
145
  if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
194
- throw new TypeError(`invalid version: ${version}`);
146
+ throw new TypeError(`Invalid version: ${version}`);
195
147
  }
196
148
  return ret;
197
149
  }
198
- function isLowerVersionDefault(oldVer, newVer) {
150
+ function defaultIsLowerVersion(oldVer, newVer) {
199
151
  const oldV = parseVersion(oldVer);
200
152
  const newV = parseVersion(newVer);
201
153
  function compareStrings(str1, str2) {
@@ -216,78 +168,77 @@ function isLowerVersionDefault(oldVer, newVer) {
216
168
  return false;
217
169
  }
218
170
  function isUpdateJSON(json) {
219
- const is = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
171
+ const is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
220
172
  return is(json) && is(json?.beta);
221
173
  }
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");
174
+ function defaultVersionJsonGenerator(existingJson, signature, version, minimumVersion) {
175
+ existingJson.beta = {
176
+ version,
177
+ minimumVersion,
178
+ signature
179
+ };
180
+ if (!parseVersion(version).stage) {
181
+ existingJson.version = version;
182
+ existingJson.minimumVersion = minimumVersion;
183
+ existingJson.signature = signature;
184
+ }
185
+ return existingJson;
186
+ }
187
+ function hashBuffer(data, length) {
188
+ const hash = crypto__default.default.createHash("SHA256").update(data).digest("binary");
230
189
  return Buffer.from(hash).subarray(0, length);
231
190
  }
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;
191
+ function aesEncrypt(plainText, key, iv) {
192
+ const cipher = crypto__default.default.createCipheriv("aes-256-cbc", key, iv);
193
+ return cipher.update(plainText, "utf8", "base64url") + cipher.final("base64url");
194
+ }
195
+ function defaultSignature(buffer, privateKey, cert, version) {
196
+ const sig = crypto__default.default.createSign("RSA-SHA256").update(buffer).sign(crypto__default.default.createPrivateKey(privateKey), "base64");
197
+ return aesEncrypt(`${sig}%${version}`, hashBuffer(cert, 32), hashBuffer(buffer, 16));
239
198
  }
240
- function verifySignatureDefault(buffer, signature2, cert) {
199
+ function aesDecrypt(encryptedText, key, iv) {
200
+ const decipher = crypto__default.default.createDecipheriv("aes-256-cbc", key, iv);
201
+ return decipher.update(encryptedText, "base64url", "utf8") + decipher.final("utf8");
202
+ }
203
+ function defaultVerifySignature(buffer, version, signature, cert) {
241
204
  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;
205
+ const [sig, ver] = aesDecrypt(signature, hashBuffer(cert, 32), hashBuffer(buffer, 16)).split("%");
206
+ if (ver !== version) {
207
+ return false;
208
+ }
209
+ return crypto__default.default.createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
210
+ } catch {
211
+ return false;
247
212
  }
248
213
  }
249
214
 
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
- });
215
+ exports.aesDecrypt = aesDecrypt;
216
+ exports.aesEncrypt = aesEncrypt;
217
+ exports.defaultIsLowerVersion = defaultIsLowerVersion;
218
+ exports.defaultSignature = defaultSignature;
219
+ exports.defaultUnzipFile = defaultUnzipFile;
220
+ exports.defaultVerifySignature = defaultVerifySignature;
221
+ exports.defaultVersionJsonGenerator = defaultVersionJsonGenerator;
222
+ exports.defaultZipFile = defaultZipFile;
223
+ exports.disableHWAccForWin7 = disableHWAccForWin7;
224
+ exports.getAppVersion = getAppVersion;
225
+ exports.getEntryVersion = getEntryVersion;
226
+ exports.getPathFromAppNameAsar = getPathFromAppNameAsar;
227
+ exports.getPathFromEntryAsar = getPathFromEntryAsar;
228
+ exports.getPathFromMain = getPathFromMain;
229
+ exports.getPathFromPreload = getPathFromPreload;
230
+ exports.getPathFromPublic = getPathFromPublic;
231
+ exports.handleUnexpectedErrors = handleUnexpectedErrors;
232
+ exports.hashBuffer = hashBuffer;
233
+ exports.isDev = isDev;
234
+ exports.isLinux = isLinux;
235
+ exports.isMac = isMac;
236
+ exports.isUpdateJSON = isUpdateJSON;
237
+ exports.isWin = isWin;
238
+ exports.loadPage = loadPage;
239
+ exports.parseVersion = parseVersion;
240
+ exports.requireNative = requireNative;
241
+ exports.restartApp = restartApp;
242
+ exports.setAppUserModelId = setAppUserModelId;
243
+ exports.setPortableAppDataPath = setPortableAppDataPath;
244
+ 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-BYVQ367i.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 joined 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,59 @@ 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
44
+ *
45
+ * Only support CommonJS
42
46
  */
43
47
  declare function disableHWAccForWin7(): void;
44
48
  /**
45
- * keep single electron instance and auto restore window on `second-instance` event
49
+ * Keep single electron instance and auto restore window on `second-instance` event
46
50
  * @param window brwoser window to show
47
51
  * @returns `false` if the app is running
48
52
  */
49
53
  declare function singleInstance(window?: BrowserWindow): boolean;
50
54
  /**
51
- * set `AppData` dir to the dir of .exe file
55
+ * Set `AppData` dir to the dir of .exe file
52
56
  *
53
- * useful for portable Windows app
57
+ * Useful for portable Windows app
54
58
  * @param dirName dir name, default to `data`
55
59
  */
56
60
  declare function setPortableAppDataPath(dirName?: string): void;
57
61
  /**
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
62
+ * Load `process.env.VITE_DEV_SERVER_URL` when dev, else load html file
64
63
  * @param win window
65
64
  * @param htmlFilePath html file path, default is `index.html`
66
65
  */
67
66
  declare function loadPage(win: BrowserWindow, htmlFilePath?: string): void;
67
+ /**
68
+ * Get joined path from preload dir
69
+ * @param paths rest paths
70
+ */
71
+ declare function getPathFromMain(...paths: string[]): string;
72
+ /**
73
+ * Get joined path from preload dir
74
+ * @param paths rest paths
75
+ */
68
76
  declare function getPathFromPreload(...paths: string[]): string;
77
+ /**
78
+ * Get joined path from publich dir
79
+ * @param paths rest paths
80
+ */
69
81
  declare function getPathFromPublic(...paths: string[]): string;
82
+ /**
83
+ * Get joined path from entry asar
84
+ * @param paths rest paths
85
+ */
70
86
  declare function getPathFromEntryAsar(...paths: string[]): string;
87
+ /**
88
+ * Handle all unhandled error
89
+ * @param callback callback function
90
+ */
91
+ declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
71
92
 
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 };
93
+ export { disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, 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-BYVQ367i.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 joined 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,59 @@ 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
44
+ *
45
+ * Only support CommonJS
42
46
  */
43
47
  declare function disableHWAccForWin7(): void;
44
48
  /**
45
- * keep single electron instance and auto restore window on `second-instance` event
49
+ * Keep single electron instance and auto restore window on `second-instance` event
46
50
  * @param window brwoser window to show
47
51
  * @returns `false` if the app is running
48
52
  */
49
53
  declare function singleInstance(window?: BrowserWindow): boolean;
50
54
  /**
51
- * set `AppData` dir to the dir of .exe file
55
+ * Set `AppData` dir to the dir of .exe file
52
56
  *
53
- * useful for portable Windows app
57
+ * Useful for portable Windows app
54
58
  * @param dirName dir name, default to `data`
55
59
  */
56
60
  declare function setPortableAppDataPath(dirName?: string): void;
57
61
  /**
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
62
+ * Load `process.env.VITE_DEV_SERVER_URL` when dev, else load html file
64
63
  * @param win window
65
64
  * @param htmlFilePath html file path, default is `index.html`
66
65
  */
67
66
  declare function loadPage(win: BrowserWindow, htmlFilePath?: string): void;
67
+ /**
68
+ * Get joined path from preload dir
69
+ * @param paths rest paths
70
+ */
71
+ declare function getPathFromMain(...paths: string[]): string;
72
+ /**
73
+ * Get joined path from preload dir
74
+ * @param paths rest paths
75
+ */
68
76
  declare function getPathFromPreload(...paths: string[]): string;
77
+ /**
78
+ * Get joined path from publich dir
79
+ * @param paths rest paths
80
+ */
69
81
  declare function getPathFromPublic(...paths: string[]): string;
82
+ /**
83
+ * Get joined path from entry asar
84
+ * @param paths rest paths
85
+ */
70
86
  declare function getPathFromEntryAsar(...paths: string[]): string;
87
+ /**
88
+ * Handle all unhandled error
89
+ * @param callback callback function
90
+ */
91
+ declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
71
92
 
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 };
93
+ export { disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };