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

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
@@ -20,21 +20,33 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/utils/index.ts
21
21
  var utils_exports = {};
22
22
  __export(utils_exports, {
23
+ decrypt: () => decrypt,
23
24
  disableHWAccForWin7: () => disableHWAccForWin7,
25
+ encrypt: () => encrypt,
26
+ getAppVersion: () => getAppVersion,
27
+ getEntryVersion: () => getEntryVersion,
24
28
  getPathFromAppNameAsar: () => getPathFromAppNameAsar,
25
- getPaths: () => getPaths,
26
- getVersions: () => getVersions,
29
+ getPathFromEntryAsar: () => getPathFromEntryAsar,
30
+ getPathFromPreload: () => getPathFromPreload,
31
+ getPathFromPublic: () => getPathFromPublic,
27
32
  handleUnexpectedErrors: () => handleUnexpectedErrors,
28
- is: () => is,
33
+ hashString: () => hashString,
34
+ isDev: () => isDev,
35
+ isLinux: () => isLinux,
36
+ isLowerVersionDefault: () => isLowerVersionDefault,
37
+ isMac: () => isMac,
29
38
  isUpdateJSON: () => isUpdateJSON,
30
- loadNativeModuleFromEntry: () => loadNativeModuleFromEntry,
31
- parseGithubCdnURL: () => parseGithubCdnURL,
39
+ isWin: () => isWin,
40
+ loadPage: () => loadPage,
32
41
  parseVersion: () => parseVersion,
42
+ requireNative: () => requireNative,
33
43
  restartApp: () => restartApp,
34
44
  setAppUserModelId: () => setAppUserModelId,
35
45
  setPortableAppDataPath: () => setPortableAppDataPath,
46
+ signature: () => signature,
36
47
  singleInstance: () => singleInstance,
37
48
  unzipFile: () => unzipFile,
49
+ verifySignatureDefault: () => verifySignatureDefault,
38
50
  waitAppReady: () => waitAppReady,
39
51
  zipFile: () => zipFile
40
52
  });
@@ -43,60 +55,52 @@ module.exports = __toCommonJS(utils_exports);
43
55
  // src/utils/electron.ts
44
56
  var import_node_fs = require("fs");
45
57
  var import_node_path = require("path");
46
- var import_node_os = require("os");
47
58
  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
- };
59
+ var isDev = __EIU_IS_DEV__;
60
+ var isWin = process.platform === "win32";
61
+ var isMac = process.platform === "darwin";
62
+ var isLinux = process.platform === "linux";
54
63
  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);
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);
56
65
  }
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
+ function getAppVersion() {
67
+ return isDev ? getEntryVersion() : (0, import_node_fs.readFileSync)(getPathFromAppNameAsar("version"), "utf-8");
66
68
  }
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
- };
69
+ function getEntryVersion() {
70
+ return import_electron.app.getVersion();
71
+ }
72
+ function requireNative(moduleName) {
73
+ return require((0, import_node_path.join)(import_electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, moduleName));
76
74
  }
77
75
  function restartApp() {
78
76
  import_electron.app.relaunch();
79
77
  import_electron.app.quit();
80
78
  }
81
79
  function setAppUserModelId(id) {
82
- import_electron.app.setAppUserModelId(is.dev ? process.execPath : id ?? `org.${import_electron.app.name}`);
80
+ if (isWin) {
81
+ import_electron.app.setAppUserModelId(id ?? `org.${import_electron.app.name}`);
82
+ }
83
83
  }
84
84
  function disableHWAccForWin7() {
85
- if ((0, import_node_os.release)().startsWith("6.1")) {
85
+ if (require("os").release().startsWith("6.1")) {
86
86
  import_electron.app.disableHardwareAcceleration();
87
87
  }
88
88
  }
89
89
  function singleInstance(window) {
90
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();
91
+ if (result) {
92
+ import_electron.app.on("second-instance", () => {
93
+ if (window) {
94
+ window.show();
95
+ if (window.isMinimized()) {
96
+ window.restore();
97
+ }
98
+ window.focus();
96
99
  }
97
- window.focus();
98
- }
99
- }) : import_electron.app.quit();
100
+ });
101
+ } else {
102
+ import_electron.app.quit();
103
+ }
100
104
  return result;
101
105
  }
102
106
  function setPortableAppDataPath(dirName = "data") {
@@ -117,79 +121,26 @@ function waitAppReady(timeout = 1e3) {
117
121
  });
118
122
  });
119
123
  }
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 `${electron.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 `${electron.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
- };
124
+ function loadPage(win, htmlFilePath = "index.html") {
125
+ if (isDev) {
126
+ win.loadURL(process.env.VITE_DEV_SERVER_URL + htmlFilePath);
127
+ } else {
128
+ win.loadFile(getPathFromAppNameAsar("renderer", htmlFilePath));
129
+ }
130
+ }
131
+ function getPathFromPreload(...paths) {
132
+ return isDev ? (0, import_node_path.join)(import_electron.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
133
+ }
134
+ function getPathFromPublic(...paths) {
135
+ return isDev ? (0, import_node_path.join)(import_electron.app.getAppPath(), "public", ...paths) : getPathFromAppNameAsar("renderer", ...paths);
136
+ }
137
+ function getPathFromEntryAsar(...paths) {
138
+ return (0, import_node_path.join)(import_electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
172
139
  }
173
140
 
174
141
  // src/utils/zip.ts
175
142
  var import_node_fs2 = require("fs");
176
143
  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.brotliDecompress)(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
144
  async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
194
145
  if (!(0, import_node_fs2.existsSync)(filePath)) {
195
146
  throw new Error(`path to be zipped not exist: ${filePath}`);
@@ -201,21 +152,32 @@ async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
201
152
  reject(err);
202
153
  }
203
154
  (0, import_node_fs2.writeFileSync)(targetFilePath, buffer2);
204
- resolve(null);
155
+ resolve();
205
156
  });
206
157
  });
207
158
  }
208
159
 
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/");
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}`);
213
166
  }
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;
167
+ const compressedBuffer = (0, import_node_fs3.readFileSync)(gzipPath);
168
+ return new Promise((resolve, reject) => {
169
+ (0, import_node_zlib2.brotliDecompress)(compressedBuffer, (err, buffer) => {
170
+ (0, import_node_fs3.rmSync)(gzipPath);
171
+ if (err) {
172
+ reject(err);
173
+ }
174
+ (0, import_node_fs3.writeFileSync)(targetFilePath, buffer);
175
+ resolve();
176
+ });
177
+ });
218
178
  }
179
+
180
+ // src/utils/version.ts
219
181
  function handleUnexpectedErrors(callback) {
220
182
  process.on("uncaughtException", callback);
221
183
  process.on("unhandledRejection", callback);
@@ -243,27 +205,99 @@ function parseVersion(version) {
243
205
  }
244
206
  return ret;
245
207
  }
208
+ function isLowerVersionDefault(oldVer, newVer) {
209
+ const oldV = parseVersion(oldVer);
210
+ const newV = parseVersion(newVer);
211
+ function compareStrings(str1, str2) {
212
+ if (str1 === "") {
213
+ return str2 !== "";
214
+ } else if (str2 === "") {
215
+ return true;
216
+ }
217
+ return str1 < str2;
218
+ }
219
+ for (let key of Object.keys(oldV)) {
220
+ if (key === "stage" && compareStrings(oldV[key], newV[key])) {
221
+ return true;
222
+ } else if (oldV[key] !== newV[key]) {
223
+ return oldV[key] < newV[key];
224
+ }
225
+ }
226
+ return false;
227
+ }
246
228
  function isUpdateJSON(json) {
247
- const is2 = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
248
- return is2(json) && is2(json?.beta);
229
+ const is = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
230
+ return is(json) && is(json?.beta);
231
+ }
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");
240
+ return Buffer.from(hash).subarray(0, length);
241
+ }
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;
249
+ }
250
+ function verifySignatureDefault(buffer, signature2, cert) {
251
+ 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");
254
+ return result ? version : void 0;
255
+ } catch {
256
+ return void 0;
257
+ }
258
+ }
259
+
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));
249
271
  }
250
272
  // Annotate the CommonJS export names for ESM import in node:
251
273
  0 && (module.exports = {
274
+ decrypt,
252
275
  disableHWAccForWin7,
276
+ encrypt,
277
+ getAppVersion,
278
+ getEntryVersion,
253
279
  getPathFromAppNameAsar,
254
- getPaths,
255
- getVersions,
280
+ getPathFromEntryAsar,
281
+ getPathFromPreload,
282
+ getPathFromPublic,
256
283
  handleUnexpectedErrors,
257
- is,
284
+ hashString,
285
+ isDev,
286
+ isLinux,
287
+ isLowerVersionDefault,
288
+ isMac,
258
289
  isUpdateJSON,
259
- loadNativeModuleFromEntry,
260
- parseGithubCdnURL,
290
+ isWin,
291
+ loadPage,
261
292
  parseVersion,
293
+ requireNative,
262
294
  restartApp,
263
295
  setAppUserModelId,
264
296
  setPortableAppDataPath,
297
+ signature,
265
298
  singleInstance,
266
299
  unzipFile,
300
+ verifySignatureDefault,
267
301
  waitAppReady,
268
302
  zipFile
269
303
  });
package/dist/utils.d.cts CHANGED
@@ -1,60 +1,40 @@
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 './pure-GoN_3MEj.cjs';
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';
3
4
 
4
5
  /**
5
- * app info
6
+ * compile time dev check
6
7
  */
7
- declare const is: {
8
- readonly dev: boolean;
9
- readonly win: boolean;
10
- readonly mac: boolean;
11
- readonly linux: boolean;
12
- };
8
+ declare const isDev: boolean;
9
+ declare const isWin: boolean;
10
+ declare const isMac: boolean;
11
+ declare const isLinux: boolean;
13
12
  /**
14
13
  * get the absolute path of `${electron.app.name}.asar` (not `app.asar`)
15
14
  *
16
- * if is in dev, return `'DEV.asar'`
15
+ * if is in dev, **always** return `'DEV.asar'`
17
16
  */
18
17
  declare function getPathFromAppNameAsar(...path: string[]): string;
19
18
  /**
20
- * get versions of App, Entry, Electron, Node and System
21
- *
22
- * App version is read from `version` file in `${electron.app.name}.asar`
23
- *
24
- * Entry version is read from `package.json`
25
- *
26
- * SystemVersion: `${platform} ${os.release()}`
19
+ * get app version, if is in dev, return `getEntryVersion()`
27
20
  */
28
- declare function getVersions(): {
29
- appVersion: string;
30
- entryVersion: string;
31
- electronVersion: string;
32
- nodeVersion: string;
33
- systemVersion: string;
34
- };
21
+ declare function getAppVersion(): string;
35
22
  /**
36
- * load native module from entry
37
- * @param moduleName file name in entry
23
+ * get entry version
38
24
  */
39
- type RequireNative = <T = any>(moduleName: string) => T;
25
+ declare function getEntryVersion(): string;
40
26
  /**
41
- * load module from entry, **only for main and preload**
42
- * @remark use `require`, only support **CommonJS**
43
- * @param devEntryDirPath entry directory path when dev, default `../../dist-entry`
44
- * @param entryDirPath entry directory path when not dev, default `join(app.getAppPath(), basename(devEntryDirPath))`
45
- * @example
46
- * const requireNative = loadNativeModuleFromEntry()
47
- * const db = requireNative<typeof import('../native/db')>('db')
48
- * db.test()
27
+ * use `require` to load native module from entry
28
+ * @param moduleName file name in entry
49
29
  */
50
- declare function loadNativeModuleFromEntry(devEntryDirPath?: string, entryDirPath?: string): RequireNative;
30
+ declare function requireNative<T = any>(moduleName: string): T;
51
31
  /**
52
32
  * Restarts the Electron app.
53
33
  */
54
34
  declare function restartApp(): void;
55
35
  /**
56
36
  * fix app use model id, only for Windows
57
- * @param id app id @default `org.${electron.app.name}`
37
+ * @param id app id, default is `org.${electron.app.name}`
58
38
  */
59
39
  declare function setAppUserModelId(id?: string): void;
60
40
  /**
@@ -80,47 +60,22 @@ declare function setPortableAppDataPath(dirName?: string): void;
80
60
  */
81
61
  declare function waitAppReady(timeout?: number): Promise<void>;
82
62
  /**
83
- * get paths, **only for main and preload**
84
- * @param entryDirName entry dir name, default to `dist-entry`
63
+ * load `process.env.VITE_DEV_SERVER_URL` when dev, else load html file
64
+ * @param win window
65
+ * @param htmlFilePath html file path, default is `index.html`
85
66
  */
86
- declare function getPaths(entryDirName?: string): {
87
- /**
88
- * @example
89
- * ```ts
90
- * devServerURL && win.loadURL(devServerURL)
91
- * ```
92
- */
93
- devServerURL: string | undefined;
94
- /**
95
- * @example
96
- * ```ts
97
- * win.loadFile(indexHTMLPath)
98
- * ```
99
- */
100
- indexHTMLPath: string;
101
- /**
102
- * get path inside entry asar
103
- * @param paths joined path
104
- */
105
- getPathFromEntryAsar(...paths: string[]): string;
106
- /**
107
- * get path inside `${electron.app.name}.asar/main`
108
- * @param paths joined path
109
- */
110
- getPathFromMain(...paths: string[]): string;
111
- /**
112
- * get path inside `${electron.app.name}.asar/preload`
113
- * @param paths joined path
114
- */
115
- getPathFromPreload(...paths: string[]): string;
116
- /**
117
- * get path inside public dir
118
- * @param paths joined path
119
- */
120
- getPathFromPublic(...paths: string[]): string;
121
- };
67
+ declare function loadPage(win: BrowserWindow, htmlFilePath?: string): void;
68
+ declare function getPathFromPreload(...paths: string[]): string;
69
+ declare function getPathFromPublic(...paths: string[]): string;
70
+ declare function getPathFromEntryAsar(...paths: string[]): string;
71
+
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;
122
78
 
123
- declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<unknown>;
124
- declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
79
+ declare function hashString(data: string | Buffer, length: number): Buffer;
125
80
 
126
- export { disableHWAccForWin7, getPathFromAppNameAsar, getPaths, getVersions, is, loadNativeModuleFromEntry, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance, unzipFile, waitAppReady, zipFile };
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 };
package/dist/utils.d.ts CHANGED
@@ -1,60 +1,40 @@
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 './pure-GoN_3MEj.js';
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';
3
4
 
4
5
  /**
5
- * app info
6
+ * compile time dev check
6
7
  */
7
- declare const is: {
8
- readonly dev: boolean;
9
- readonly win: boolean;
10
- readonly mac: boolean;
11
- readonly linux: boolean;
12
- };
8
+ declare const isDev: boolean;
9
+ declare const isWin: boolean;
10
+ declare const isMac: boolean;
11
+ declare const isLinux: boolean;
13
12
  /**
14
13
  * get the absolute path of `${electron.app.name}.asar` (not `app.asar`)
15
14
  *
16
- * if is in dev, return `'DEV.asar'`
15
+ * if is in dev, **always** return `'DEV.asar'`
17
16
  */
18
17
  declare function getPathFromAppNameAsar(...path: string[]): string;
19
18
  /**
20
- * get versions of App, Entry, Electron, Node and System
21
- *
22
- * App version is read from `version` file in `${electron.app.name}.asar`
23
- *
24
- * Entry version is read from `package.json`
25
- *
26
- * SystemVersion: `${platform} ${os.release()}`
19
+ * get app version, if is in dev, return `getEntryVersion()`
27
20
  */
28
- declare function getVersions(): {
29
- appVersion: string;
30
- entryVersion: string;
31
- electronVersion: string;
32
- nodeVersion: string;
33
- systemVersion: string;
34
- };
21
+ declare function getAppVersion(): string;
35
22
  /**
36
- * load native module from entry
37
- * @param moduleName file name in entry
23
+ * get entry version
38
24
  */
39
- type RequireNative = <T = any>(moduleName: string) => T;
25
+ declare function getEntryVersion(): string;
40
26
  /**
41
- * load module from entry, **only for main and preload**
42
- * @remark use `require`, only support **CommonJS**
43
- * @param devEntryDirPath entry directory path when dev, default `../../dist-entry`
44
- * @param entryDirPath entry directory path when not dev, default `join(app.getAppPath(), basename(devEntryDirPath))`
45
- * @example
46
- * const requireNative = loadNativeModuleFromEntry()
47
- * const db = requireNative<typeof import('../native/db')>('db')
48
- * db.test()
27
+ * use `require` to load native module from entry
28
+ * @param moduleName file name in entry
49
29
  */
50
- declare function loadNativeModuleFromEntry(devEntryDirPath?: string, entryDirPath?: string): RequireNative;
30
+ declare function requireNative<T = any>(moduleName: string): T;
51
31
  /**
52
32
  * Restarts the Electron app.
53
33
  */
54
34
  declare function restartApp(): void;
55
35
  /**
56
36
  * fix app use model id, only for Windows
57
- * @param id app id @default `org.${electron.app.name}`
37
+ * @param id app id, default is `org.${electron.app.name}`
58
38
  */
59
39
  declare function setAppUserModelId(id?: string): void;
60
40
  /**
@@ -80,47 +60,22 @@ declare function setPortableAppDataPath(dirName?: string): void;
80
60
  */
81
61
  declare function waitAppReady(timeout?: number): Promise<void>;
82
62
  /**
83
- * get paths, **only for main and preload**
84
- * @param entryDirName entry dir name, default to `dist-entry`
63
+ * load `process.env.VITE_DEV_SERVER_URL` when dev, else load html file
64
+ * @param win window
65
+ * @param htmlFilePath html file path, default is `index.html`
85
66
  */
86
- declare function getPaths(entryDirName?: string): {
87
- /**
88
- * @example
89
- * ```ts
90
- * devServerURL && win.loadURL(devServerURL)
91
- * ```
92
- */
93
- devServerURL: string | undefined;
94
- /**
95
- * @example
96
- * ```ts
97
- * win.loadFile(indexHTMLPath)
98
- * ```
99
- */
100
- indexHTMLPath: string;
101
- /**
102
- * get path inside entry asar
103
- * @param paths joined path
104
- */
105
- getPathFromEntryAsar(...paths: string[]): string;
106
- /**
107
- * get path inside `${electron.app.name}.asar/main`
108
- * @param paths joined path
109
- */
110
- getPathFromMain(...paths: string[]): string;
111
- /**
112
- * get path inside `${electron.app.name}.asar/preload`
113
- * @param paths joined path
114
- */
115
- getPathFromPreload(...paths: string[]): string;
116
- /**
117
- * get path inside public dir
118
- * @param paths joined path
119
- */
120
- getPathFromPublic(...paths: string[]): string;
121
- };
67
+ declare function loadPage(win: BrowserWindow, htmlFilePath?: string): void;
68
+ declare function getPathFromPreload(...paths: string[]): string;
69
+ declare function getPathFromPublic(...paths: string[]): string;
70
+ declare function getPathFromEntryAsar(...paths: string[]): string;
71
+
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;
122
78
 
123
- declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<unknown>;
124
- declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
79
+ declare function hashString(data: string | Buffer, length: number): Buffer;
125
80
 
126
- export { disableHWAccForWin7, getPathFromAppNameAsar, getPaths, getVersions, is, loadNativeModuleFromEntry, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance, unzipFile, waitAppReady, zipFile };
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 };