electron-incremental-update 1.3.0 → 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/README.md +7 -3
- package/dist/chunk-4MH6ZXCY.js +81 -0
- package/dist/chunk-72ZAJ7AF.js +70 -0
- package/dist/chunk-KZSYEXLO.js +55 -0
- package/dist/index.cjs +173 -386
- package/dist/index.d.cts +84 -213
- package/dist/index.d.ts +84 -213
- package/dist/index.js +142 -282
- package/dist/provider.cjs +232 -0
- package/dist/provider.d.cts +109 -0
- package/dist/provider.d.ts +109 -0
- package/dist/provider.js +139 -0
- package/dist/types-Bnc4jz6R.d.ts +78 -0
- package/dist/types-DEYw5VrL.d.cts +78 -0
- package/dist/utils.cjs +175 -208
- package/dist/utils.d.cts +47 -87
- package/dist/utils.d.ts +47 -87
- package/dist/utils.js +3 -38
- package/dist/version-C4tF_trh.d.cts +62 -0
- package/dist/version-C4tF_trh.d.ts +62 -0
- package/dist/vite.d.ts +93 -95
- package/dist/vite.js +342 -350
- package/dist/zip-rm9ED9nU.d.cts +33 -0
- package/dist/zip-rm9ED9nU.d.ts +33 -0
- package/package.json +28 -16
- package/provider.d.ts +1 -0
- package/provider.js +1 -0
- package/dist/chunk-7ET4GMTZ.js +0 -236
- package/dist/chunk-CXHA5TF7.js +0 -236
- package/dist/chunk-HWUYTDEF.js +0 -236
- package/dist/chunk-RQCTJY4L.js +0 -236
- package/dist/chunk-SBPTSLG7.js +0 -235
- package/dist/pure-GoN_3MEj.d.cts +0 -31
- package/dist/pure-GoN_3MEj.d.ts +0 -31
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
declare function hashBuffer(data: string | Buffer, length: number): Buffer;
|
|
2
|
+
declare function aesEncrypt(plainText: string, key: Buffer, iv: Buffer): string;
|
|
3
|
+
/**
|
|
4
|
+
* Default function to generate asar signature, returns generated signature
|
|
5
|
+
* @param buffer file buffer
|
|
6
|
+
* @param privateKey primary key
|
|
7
|
+
* @param cert certificate
|
|
8
|
+
* @param version target version
|
|
9
|
+
*/
|
|
10
|
+
declare function defaultSignature(buffer: Buffer, privateKey: string, cert: string, version: string): string;
|
|
11
|
+
declare function aesDecrypt(encryptedText: string, key: Buffer, iv: Buffer): string;
|
|
12
|
+
/**
|
|
13
|
+
* Default function to verify asar signature,
|
|
14
|
+
* if signature is valid, returns the version, otherwise returns `undefined`
|
|
15
|
+
* @param buffer file buffer
|
|
16
|
+
* @param version target version
|
|
17
|
+
* @param signature signature
|
|
18
|
+
* @param cert certificate
|
|
19
|
+
*/
|
|
20
|
+
declare function defaultVerifySignature(buffer: Buffer, version: string, signature: string, cert: string): boolean;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Default function to compress file using brotli
|
|
24
|
+
* @param buffer uncompressed file buffer
|
|
25
|
+
*/
|
|
26
|
+
declare function defaultZipFile(buffer: Buffer): Promise<Buffer>;
|
|
27
|
+
/**
|
|
28
|
+
* Default function to decompress file using brotli
|
|
29
|
+
* @param buffer compressed file buffer
|
|
30
|
+
*/
|
|
31
|
+
declare function defaultUnzipFile(buffer: Buffer): Promise<Buffer>;
|
|
32
|
+
|
|
33
|
+
export { defaultUnzipFile as a, aesEncrypt as b, defaultSignature as c, defaultZipFile as d, aesDecrypt as e, defaultVerifySignature as f, hashBuffer as h };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
declare function hashBuffer(data: string | Buffer, length: number): Buffer;
|
|
2
|
+
declare function aesEncrypt(plainText: string, key: Buffer, iv: Buffer): string;
|
|
3
|
+
/**
|
|
4
|
+
* Default function to generate asar signature, returns generated signature
|
|
5
|
+
* @param buffer file buffer
|
|
6
|
+
* @param privateKey primary key
|
|
7
|
+
* @param cert certificate
|
|
8
|
+
* @param version target version
|
|
9
|
+
*/
|
|
10
|
+
declare function defaultSignature(buffer: Buffer, privateKey: string, cert: string, version: string): string;
|
|
11
|
+
declare function aesDecrypt(encryptedText: string, key: Buffer, iv: Buffer): string;
|
|
12
|
+
/**
|
|
13
|
+
* Default function to verify asar signature,
|
|
14
|
+
* if signature is valid, returns the version, otherwise returns `undefined`
|
|
15
|
+
* @param buffer file buffer
|
|
16
|
+
* @param version target version
|
|
17
|
+
* @param signature signature
|
|
18
|
+
* @param cert certificate
|
|
19
|
+
*/
|
|
20
|
+
declare function defaultVerifySignature(buffer: Buffer, version: string, signature: string, cert: string): boolean;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Default function to compress file using brotli
|
|
24
|
+
* @param buffer uncompressed file buffer
|
|
25
|
+
*/
|
|
26
|
+
declare function defaultZipFile(buffer: Buffer): Promise<Buffer>;
|
|
27
|
+
/**
|
|
28
|
+
* Default function to decompress file using brotli
|
|
29
|
+
* @param buffer compressed file buffer
|
|
30
|
+
*/
|
|
31
|
+
declare function defaultUnzipFile(buffer: Buffer): Promise<Buffer>;
|
|
32
|
+
|
|
33
|
+
export { defaultUnzipFile as a, aesEncrypt as b, defaultSignature as c, defaultZipFile as d, aesDecrypt as e, defaultVerifySignature as f, hashBuffer as h };
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-incremental-update",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "2.0.0-beta.10",
|
|
5
|
+
"description": "Electron incremental update tools with vite plugin, support bytecode protection",
|
|
6
6
|
"author": "subframe7536",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"repository":
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/subframe7536/electron-incremental-update.git"
|
|
11
|
+
},
|
|
9
12
|
"keywords": [
|
|
10
13
|
"electron",
|
|
11
14
|
"incremental update",
|
|
@@ -23,12 +26,18 @@
|
|
|
23
26
|
"./utils": {
|
|
24
27
|
"import": "./dist/utils.js",
|
|
25
28
|
"require": "./dist/utils.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./provider": {
|
|
31
|
+
"import": "./dist/provider.js",
|
|
32
|
+
"require": "./dist/provider.cjs"
|
|
26
33
|
}
|
|
27
34
|
},
|
|
28
35
|
"main": "dist/index.cjs",
|
|
29
36
|
"module": "dist/index.js",
|
|
30
37
|
"files": [
|
|
31
38
|
"dist",
|
|
39
|
+
"provider.d.ts",
|
|
40
|
+
"provider.js",
|
|
32
41
|
"utils.d.ts",
|
|
33
42
|
"utils.js",
|
|
34
43
|
"vite.d.ts",
|
|
@@ -39,6 +48,7 @@
|
|
|
39
48
|
"build": "tsup && esno fix-module.cjs",
|
|
40
49
|
"release": "pnpm test && pnpm run build && bumpp --all && npm publish",
|
|
41
50
|
"test": "vitest --run",
|
|
51
|
+
"test:dev": "vitest",
|
|
42
52
|
"format": "eslint . --fix"
|
|
43
53
|
},
|
|
44
54
|
"publishConfig": {
|
|
@@ -46,30 +56,32 @@
|
|
|
46
56
|
"registry": "https://registry.npmjs.org/"
|
|
47
57
|
},
|
|
48
58
|
"peerDependencies": {
|
|
49
|
-
"@babel/core": "^7.24.7",
|
|
50
|
-
"@babel/plugin-transform-arrow-functions": "^7.24.7",
|
|
51
59
|
"@electron/asar": "*",
|
|
52
|
-
"esbuild": "*"
|
|
53
|
-
"magic-string": "*",
|
|
54
|
-
"vite-plugin-electron": "^0.15.6 || ^0.28"
|
|
60
|
+
"esbuild": "*"
|
|
55
61
|
},
|
|
56
62
|
"dependencies": {
|
|
63
|
+
"@babel/core": "^7.24.9",
|
|
64
|
+
"@babel/plugin-transform-arrow-functions": "^7.24.7",
|
|
65
|
+
"@babel/plugin-transform-template-literals": "^7.24.7",
|
|
57
66
|
"@subframe7536/type-utils": "^0.1.6",
|
|
67
|
+
"ci-info": "^4.0.0",
|
|
58
68
|
"local-pkg": "^0.5.0",
|
|
59
|
-
"
|
|
69
|
+
"magic-string": "^0.30.10",
|
|
70
|
+
"selfsigned": "^2.4.1",
|
|
71
|
+
"vite-plugin-electron": "^0.28.7"
|
|
60
72
|
},
|
|
61
73
|
"devDependencies": {
|
|
62
|
-
"@subframe7536/eslint-config": "^0.
|
|
74
|
+
"@subframe7536/eslint-config": "^0.7.3",
|
|
63
75
|
"@types/babel__core": "^7.20.5",
|
|
64
|
-
"@types/node": "^20.14.
|
|
76
|
+
"@types/node": "^20.14.11",
|
|
65
77
|
"bumpp": "^9.4.1",
|
|
66
78
|
"electron": "28.2.10",
|
|
67
|
-
"eslint": "^9.
|
|
79
|
+
"eslint": "^9.7.0",
|
|
68
80
|
"esno": "^4.7.0",
|
|
69
|
-
"tsup": "^8.1
|
|
70
|
-
"typescript": "^5.5.
|
|
71
|
-
"vite": "^5.3.
|
|
81
|
+
"tsup": "^8.2.1",
|
|
82
|
+
"typescript": "^5.5.3",
|
|
83
|
+
"vite": "^5.3.4",
|
|
72
84
|
"vite-plugin-electron": "^0.28.7",
|
|
73
|
-
"vitest": "^
|
|
85
|
+
"vitest": "^2.0.3"
|
|
74
86
|
}
|
|
75
87
|
}
|
package/provider.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/provider'
|
package/provider.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/provider.cjs')
|
package/dist/chunk-7ET4GMTZ.js
DELETED
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
// src/utils/electron.ts
|
|
9
|
-
import { existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
10
|
-
import { basename, dirname, join } from "node:path";
|
|
11
|
-
import { release } from "node:os";
|
|
12
|
-
import { app } from "electron";
|
|
13
|
-
var is = {
|
|
14
|
-
dev: !app.isPackaged,
|
|
15
|
-
win: process.platform === "win32",
|
|
16
|
-
mac: process.platform === "darwin",
|
|
17
|
-
linux: process.platform === "linux"
|
|
18
|
-
};
|
|
19
|
-
function getPathFromAppNameAsar(...path) {
|
|
20
|
-
return is.dev ? "DEV.asar" : join(dirname(app.getAppPath()), `${electron.app.name}.asar`, ...path);
|
|
21
|
-
}
|
|
22
|
-
function getVersions() {
|
|
23
|
-
const platform = is.win ? "Windows" : is.mac ? "MacOS" : process.platform.toUpperCase();
|
|
24
|
-
return {
|
|
25
|
-
appVersion: is.dev ? app.getVersion() : readFileSync(getPathFromAppNameAsar("version"), "utf-8"),
|
|
26
|
-
entryVersion: app.getVersion(),
|
|
27
|
-
electronVersion: process.versions.electron,
|
|
28
|
-
nodeVersion: process.versions.node,
|
|
29
|
-
systemVersion: `${platform} ${release()}`
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
function loadNativeModuleFromEntry(devEntryDirPath = "../../dist-entry", entryDirPath = join(app.getAppPath(), basename(devEntryDirPath))) {
|
|
33
|
-
const path = is.dev ? devEntryDirPath : entryDirPath;
|
|
34
|
-
return (moduleName) => {
|
|
35
|
-
try {
|
|
36
|
-
return __require(join(path, moduleName));
|
|
37
|
-
} catch (error) {
|
|
38
|
-
console.error("fail to load module", error);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function restartApp() {
|
|
43
|
-
app.relaunch();
|
|
44
|
-
app.quit();
|
|
45
|
-
}
|
|
46
|
-
function setAppUserModelId(id) {
|
|
47
|
-
app.setAppUserModelId(is.dev ? process.execPath : id ?? `org.${electron.app.name}`);
|
|
48
|
-
}
|
|
49
|
-
function disableHWAccForWin7() {
|
|
50
|
-
if (release().startsWith("6.1")) {
|
|
51
|
-
app.disableHardwareAcceleration();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function singleInstance(window) {
|
|
55
|
-
const result = app.requestSingleInstanceLock();
|
|
56
|
-
result ? app.on("second-instance", () => {
|
|
57
|
-
if (window) {
|
|
58
|
-
window.show();
|
|
59
|
-
if (window.isMinimized()) {
|
|
60
|
-
window.restore();
|
|
61
|
-
}
|
|
62
|
-
window.focus();
|
|
63
|
-
}
|
|
64
|
-
}) : app.quit();
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
function setPortableAppDataPath(dirName = "data") {
|
|
68
|
-
const portablePath = join(dirname(app.getPath("exe")), dirName);
|
|
69
|
-
if (!existsSync(portablePath)) {
|
|
70
|
-
mkdirSync(portablePath);
|
|
71
|
-
}
|
|
72
|
-
app.setPath("appData", portablePath);
|
|
73
|
-
}
|
|
74
|
-
function waitAppReady(timeout = 1e3) {
|
|
75
|
-
return app.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
|
|
76
|
-
const _ = setTimeout(() => {
|
|
77
|
-
reject(new Error("app is not ready"));
|
|
78
|
-
}, timeout);
|
|
79
|
-
app.whenReady().then(() => {
|
|
80
|
-
clearTimeout(_);
|
|
81
|
-
resolve();
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
function getPaths(entryDirName = "dist-entry") {
|
|
86
|
-
const root = join(__dirname, "..");
|
|
87
|
-
const mainDirPath = join(root, "main");
|
|
88
|
-
const preloadDirPath = join(root, "preload");
|
|
89
|
-
const rendererDirPath = join(root, "renderer");
|
|
90
|
-
const devServerURL = process.env.VITE_DEV_SERVER_URL;
|
|
91
|
-
const indexHTMLPath = join(rendererDirPath, "index.html");
|
|
92
|
-
const publicDirPath = devServerURL ? join(root, "../public") : rendererDirPath;
|
|
93
|
-
return {
|
|
94
|
-
/**
|
|
95
|
-
* @example
|
|
96
|
-
* ```ts
|
|
97
|
-
* devServerURL && win.loadURL(devServerURL)
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
devServerURL,
|
|
101
|
-
/**
|
|
102
|
-
* @example
|
|
103
|
-
* ```ts
|
|
104
|
-
* win.loadFile(indexHTMLPath)
|
|
105
|
-
* ```
|
|
106
|
-
*/
|
|
107
|
-
indexHTMLPath,
|
|
108
|
-
/**
|
|
109
|
-
* get path inside entry asar
|
|
110
|
-
* @param paths joined path
|
|
111
|
-
*/
|
|
112
|
-
getPathFromEntryAsar(...paths) {
|
|
113
|
-
return join(app.getAppPath(), entryDirName, ...paths);
|
|
114
|
-
},
|
|
115
|
-
/**
|
|
116
|
-
* get path inside `${electron.app.name}.asar/main`
|
|
117
|
-
* @param paths joined path
|
|
118
|
-
*/
|
|
119
|
-
getPathFromMain(...paths) {
|
|
120
|
-
return join(mainDirPath, ...paths);
|
|
121
|
-
},
|
|
122
|
-
/**
|
|
123
|
-
* get path inside `${electron.app.name}.asar/preload`
|
|
124
|
-
* @param paths joined path
|
|
125
|
-
*/
|
|
126
|
-
getPathFromPreload(...paths) {
|
|
127
|
-
return join(preloadDirPath, ...paths);
|
|
128
|
-
},
|
|
129
|
-
/**
|
|
130
|
-
* get path inside public dir
|
|
131
|
-
* @param paths joined path
|
|
132
|
-
*/
|
|
133
|
-
getPathFromPublic(...paths) {
|
|
134
|
-
return join(publicDirPath, ...paths);
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// src/utils/zip.ts
|
|
140
|
-
import { existsSync as existsSync2, readFileSync as readFileSync2, rmSync, writeFileSync } from "node:fs";
|
|
141
|
-
import { brotliCompress, brotliDecompress } from "node:zlib";
|
|
142
|
-
async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
|
|
143
|
-
if (!existsSync2(gzipPath)) {
|
|
144
|
-
throw new Error(`path to zipped file not exist: ${gzipPath}`);
|
|
145
|
-
}
|
|
146
|
-
const compressedBuffer = readFileSync2(gzipPath);
|
|
147
|
-
return new Promise((resolve, reject) => {
|
|
148
|
-
brotliDecompress(compressedBuffer, (err, buffer) => {
|
|
149
|
-
rmSync(gzipPath);
|
|
150
|
-
if (err) {
|
|
151
|
-
reject(err);
|
|
152
|
-
}
|
|
153
|
-
writeFileSync(targetFilePath, buffer);
|
|
154
|
-
resolve(null);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
|
|
159
|
-
if (!existsSync2(filePath)) {
|
|
160
|
-
throw new Error(`path to be zipped not exist: ${filePath}`);
|
|
161
|
-
}
|
|
162
|
-
const buffer = readFileSync2(filePath);
|
|
163
|
-
return new Promise((resolve, reject) => {
|
|
164
|
-
brotliCompress(buffer, (err, buffer2) => {
|
|
165
|
-
if (err) {
|
|
166
|
-
reject(err);
|
|
167
|
-
}
|
|
168
|
-
writeFileSync(targetFilePath, buffer2);
|
|
169
|
-
resolve(null);
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// src/utils/pure.ts
|
|
175
|
-
function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
|
|
176
|
-
if (!originRepoURL.startsWith("https://github.com/")) {
|
|
177
|
-
throw new Error("origin url must start with https://github.com/");
|
|
178
|
-
}
|
|
179
|
-
originRepoURL = originRepoURL.trim().replace(/\/?$/, "/").trim();
|
|
180
|
-
relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
|
|
181
|
-
cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
|
|
182
|
-
return originRepoURL.replace("github.com", cdnPrefix) + relativeFilePath;
|
|
183
|
-
}
|
|
184
|
-
function handleUnexpectedErrors(callback) {
|
|
185
|
-
process.on("uncaughtException", callback);
|
|
186
|
-
process.on("unhandledRejection", callback);
|
|
187
|
-
}
|
|
188
|
-
function parseVersion(version) {
|
|
189
|
-
const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i;
|
|
190
|
-
const match = semver.exec(version);
|
|
191
|
-
if (!match) {
|
|
192
|
-
throw new TypeError(`invalid version: ${version}`);
|
|
193
|
-
}
|
|
194
|
-
const [major, minor, patch] = match.slice(1, 4).map(Number);
|
|
195
|
-
const ret = {
|
|
196
|
-
major,
|
|
197
|
-
minor,
|
|
198
|
-
patch,
|
|
199
|
-
stage: "",
|
|
200
|
-
stageVersion: -1
|
|
201
|
-
};
|
|
202
|
-
if (match[4]) {
|
|
203
|
-
let [stage, _v] = match[4].split(".");
|
|
204
|
-
ret.stage = stage;
|
|
205
|
-
ret.stageVersion = Number(_v) || -1;
|
|
206
|
-
}
|
|
207
|
-
if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
|
|
208
|
-
throw new TypeError(`invalid version: ${version}`);
|
|
209
|
-
}
|
|
210
|
-
return ret;
|
|
211
|
-
}
|
|
212
|
-
function isUpdateJSON(json) {
|
|
213
|
-
const is2 = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
|
|
214
|
-
return is2(json) && is2(json?.beta);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
export {
|
|
218
|
-
__require,
|
|
219
|
-
is,
|
|
220
|
-
getPathFromAppNameAsar,
|
|
221
|
-
getVersions,
|
|
222
|
-
loadNativeModuleFromEntry,
|
|
223
|
-
restartApp,
|
|
224
|
-
setAppUserModelId,
|
|
225
|
-
disableHWAccForWin7,
|
|
226
|
-
singleInstance,
|
|
227
|
-
setPortableAppDataPath,
|
|
228
|
-
waitAppReady,
|
|
229
|
-
getPaths,
|
|
230
|
-
unzipFile,
|
|
231
|
-
zipFile,
|
|
232
|
-
parseGithubCdnURL,
|
|
233
|
-
handleUnexpectedErrors,
|
|
234
|
-
parseVersion,
|
|
235
|
-
isUpdateJSON
|
|
236
|
-
};
|
package/dist/chunk-CXHA5TF7.js
DELETED
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
// src/utils/electron.ts
|
|
9
|
-
import { existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
10
|
-
import { basename, dirname, join } from "node:path";
|
|
11
|
-
import { release } from "node:os";
|
|
12
|
-
import { app } from "electron";
|
|
13
|
-
var is = {
|
|
14
|
-
dev: !app.isPackaged,
|
|
15
|
-
win: process.platform === "win32",
|
|
16
|
-
mac: process.platform === "darwin",
|
|
17
|
-
linux: process.platform === "linux"
|
|
18
|
-
};
|
|
19
|
-
function getPathFromAppNameAsar(...path) {
|
|
20
|
-
return is.dev ? "DEV.asar" : join(dirname(app.getAppPath()), `${app.name}.asar`, ...path);
|
|
21
|
-
}
|
|
22
|
-
function getVersions() {
|
|
23
|
-
const platform = is.win ? "Windows" : is.mac ? "MacOS" : process.platform.toUpperCase();
|
|
24
|
-
return {
|
|
25
|
-
appVersion: is.dev ? app.getVersion() : readFileSync(getPathFromAppNameAsar("version"), "utf-8"),
|
|
26
|
-
entryVersion: app.getVersion(),
|
|
27
|
-
electronVersion: process.versions.electron,
|
|
28
|
-
nodeVersion: process.versions.node,
|
|
29
|
-
systemVersion: `${platform} ${release()}`
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
function loadNativeModuleFromEntry(devEntryDirPath = "../../dist-entry", entryDirPath = join(app.getAppPath(), basename(devEntryDirPath))) {
|
|
33
|
-
const path = is.dev ? devEntryDirPath : entryDirPath;
|
|
34
|
-
return (moduleName) => {
|
|
35
|
-
try {
|
|
36
|
-
return __require(join(path, moduleName));
|
|
37
|
-
} catch (error) {
|
|
38
|
-
console.error("fail to load module", error);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function restartApp() {
|
|
43
|
-
app.relaunch();
|
|
44
|
-
app.quit();
|
|
45
|
-
}
|
|
46
|
-
function setAppUserModelId(id) {
|
|
47
|
-
app.setAppUserModelId(is.dev ? process.execPath : id ?? `org.${app.name}`);
|
|
48
|
-
}
|
|
49
|
-
function disableHWAccForWin7() {
|
|
50
|
-
if (release().startsWith("6.1")) {
|
|
51
|
-
app.disableHardwareAcceleration();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function singleInstance(window) {
|
|
55
|
-
const result = app.requestSingleInstanceLock();
|
|
56
|
-
result ? app.on("second-instance", () => {
|
|
57
|
-
if (window) {
|
|
58
|
-
window.show();
|
|
59
|
-
if (window.isMinimized()) {
|
|
60
|
-
window.restore();
|
|
61
|
-
}
|
|
62
|
-
window.focus();
|
|
63
|
-
}
|
|
64
|
-
}) : app.quit();
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
function setPortableAppDataPath(dirName = "data") {
|
|
68
|
-
const portablePath = join(dirname(app.getPath("exe")), dirName);
|
|
69
|
-
if (!existsSync(portablePath)) {
|
|
70
|
-
mkdirSync(portablePath);
|
|
71
|
-
}
|
|
72
|
-
app.setPath("appData", portablePath);
|
|
73
|
-
}
|
|
74
|
-
function waitAppReady(timeout = 1e3) {
|
|
75
|
-
return app.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
|
|
76
|
-
const _ = setTimeout(() => {
|
|
77
|
-
reject(new Error("app is not ready"));
|
|
78
|
-
}, timeout);
|
|
79
|
-
app.whenReady().then(() => {
|
|
80
|
-
clearTimeout(_);
|
|
81
|
-
resolve();
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
function getPaths(entryDirName = "dist-entry") {
|
|
86
|
-
const root = join(__dirname, "..");
|
|
87
|
-
const mainDirPath = join(root, "main");
|
|
88
|
-
const preloadDirPath = join(root, "preload");
|
|
89
|
-
const rendererDirPath = join(root, "renderer");
|
|
90
|
-
const devServerURL = process.env.VITE_DEV_SERVER_URL;
|
|
91
|
-
const indexHTMLPath = join(rendererDirPath, "index.html");
|
|
92
|
-
const publicDirPath = devServerURL ? join(root, "../public") : rendererDirPath;
|
|
93
|
-
return {
|
|
94
|
-
/**
|
|
95
|
-
* @example
|
|
96
|
-
* ```ts
|
|
97
|
-
* devServerURL && win.loadURL(devServerURL)
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
devServerURL,
|
|
101
|
-
/**
|
|
102
|
-
* @example
|
|
103
|
-
* ```ts
|
|
104
|
-
* win.loadFile(indexHTMLPath)
|
|
105
|
-
* ```
|
|
106
|
-
*/
|
|
107
|
-
indexHTMLPath,
|
|
108
|
-
/**
|
|
109
|
-
* get path inside entry asar
|
|
110
|
-
* @param paths joined path
|
|
111
|
-
*/
|
|
112
|
-
getPathFromEntryAsar(...paths) {
|
|
113
|
-
return join(app.getAppPath(), entryDirName, ...paths);
|
|
114
|
-
},
|
|
115
|
-
/**
|
|
116
|
-
* get path inside `${app.name}.asar/main`
|
|
117
|
-
* @param paths joined path
|
|
118
|
-
*/
|
|
119
|
-
getPathFromMain(...paths) {
|
|
120
|
-
return join(mainDirPath, ...paths);
|
|
121
|
-
},
|
|
122
|
-
/**
|
|
123
|
-
* get path inside `${app.name}.asar/preload`
|
|
124
|
-
* @param paths joined path
|
|
125
|
-
*/
|
|
126
|
-
getPathFromPreload(...paths) {
|
|
127
|
-
return join(preloadDirPath, ...paths);
|
|
128
|
-
},
|
|
129
|
-
/**
|
|
130
|
-
* get path inside public dir
|
|
131
|
-
* @param paths joined path
|
|
132
|
-
*/
|
|
133
|
-
getPathFromPublic(...paths) {
|
|
134
|
-
return join(publicDirPath, ...paths);
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// src/utils/zip.ts
|
|
140
|
-
import { existsSync as existsSync2, readFileSync as readFileSync2, rmSync, writeFileSync } from "node:fs";
|
|
141
|
-
import { gunzip, gzip } from "node:zlib";
|
|
142
|
-
async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
|
|
143
|
-
if (!existsSync2(gzipPath)) {
|
|
144
|
-
throw new Error(`path to zipped file not exist: ${gzipPath}`);
|
|
145
|
-
}
|
|
146
|
-
const compressedBuffer = readFileSync2(gzipPath);
|
|
147
|
-
return new Promise((resolve, reject) => {
|
|
148
|
-
gunzip(compressedBuffer, (err, buffer) => {
|
|
149
|
-
rmSync(gzipPath);
|
|
150
|
-
if (err) {
|
|
151
|
-
reject(err);
|
|
152
|
-
}
|
|
153
|
-
writeFileSync(targetFilePath, buffer);
|
|
154
|
-
resolve(null);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
|
|
159
|
-
if (!existsSync2(filePath)) {
|
|
160
|
-
throw new Error(`path to be zipped not exist: ${filePath}`);
|
|
161
|
-
}
|
|
162
|
-
const buffer = readFileSync2(filePath);
|
|
163
|
-
return new Promise((resolve, reject) => {
|
|
164
|
-
gzip(buffer, (err, buffer2) => {
|
|
165
|
-
if (err) {
|
|
166
|
-
reject(err);
|
|
167
|
-
}
|
|
168
|
-
writeFileSync(targetFilePath, buffer2);
|
|
169
|
-
resolve(null);
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// src/utils/pure.ts
|
|
175
|
-
function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
|
|
176
|
-
if (!originRepoURL.startsWith("https://github.com/")) {
|
|
177
|
-
throw new Error("origin url must start with https://github.com/");
|
|
178
|
-
}
|
|
179
|
-
originRepoURL = originRepoURL.trim().replace(/\/?$/, "/").trim();
|
|
180
|
-
relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
|
|
181
|
-
cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
|
|
182
|
-
return originRepoURL.replace("github.com", cdnPrefix) + relativeFilePath;
|
|
183
|
-
}
|
|
184
|
-
function handleUnexpectedErrors(callback) {
|
|
185
|
-
process.on("uncaughtException", callback);
|
|
186
|
-
process.on("unhandledRejection", callback);
|
|
187
|
-
}
|
|
188
|
-
function parseVersion(version) {
|
|
189
|
-
const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i;
|
|
190
|
-
const match = semver.exec(version);
|
|
191
|
-
if (!match) {
|
|
192
|
-
throw new TypeError(`invalid version: ${version}`);
|
|
193
|
-
}
|
|
194
|
-
const [major, minor, patch] = match.slice(1, 4).map(Number);
|
|
195
|
-
const ret = {
|
|
196
|
-
major,
|
|
197
|
-
minor,
|
|
198
|
-
patch,
|
|
199
|
-
stage: "",
|
|
200
|
-
stageVersion: -1
|
|
201
|
-
};
|
|
202
|
-
if (match[4]) {
|
|
203
|
-
let [stage, _v] = match[4].split(".");
|
|
204
|
-
ret.stage = stage;
|
|
205
|
-
ret.stageVersion = Number(_v) || -1;
|
|
206
|
-
}
|
|
207
|
-
if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
|
|
208
|
-
throw new TypeError(`invalid version: ${version}`);
|
|
209
|
-
}
|
|
210
|
-
return ret;
|
|
211
|
-
}
|
|
212
|
-
function isUpdateJSON(json) {
|
|
213
|
-
const is2 = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
|
|
214
|
-
return is2(json) && is2(json?.beta);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
export {
|
|
218
|
-
__require,
|
|
219
|
-
is,
|
|
220
|
-
getPathFromAppNameAsar,
|
|
221
|
-
getVersions,
|
|
222
|
-
loadNativeModuleFromEntry,
|
|
223
|
-
restartApp,
|
|
224
|
-
setAppUserModelId,
|
|
225
|
-
disableHWAccForWin7,
|
|
226
|
-
singleInstance,
|
|
227
|
-
setPortableAppDataPath,
|
|
228
|
-
waitAppReady,
|
|
229
|
-
getPaths,
|
|
230
|
-
unzipFile,
|
|
231
|
-
zipFile,
|
|
232
|
-
parseGithubCdnURL,
|
|
233
|
-
handleUnexpectedErrors,
|
|
234
|
-
parseVersion,
|
|
235
|
-
isUpdateJSON
|
|
236
|
-
};
|