electron-incremental-update 0.7.0 → 0.7.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/README.md +2 -2
- package/dist/chunk-CRBEZBU5.mjs +120 -0
- package/dist/chunk-Q2K52LOG.mjs +37 -0
- package/dist/index.d.mts +1 -35
- package/dist/index.d.ts +1 -35
- package/dist/index.js +58 -113
- package/dist/index.mjs +40 -120
- package/dist/utils.d.mts +37 -0
- package/dist/utils.d.ts +37 -0
- package/dist/utils.js +145 -0
- package/dist/utils.mjs +26 -0
- package/dist/vite.d.mts +5 -0
- package/dist/vite.d.ts +5 -0
- package/dist/vite.js +31 -24
- package/dist/vite.mjs +17 -19
- package/package.json +8 -3
- package/utils.d.ts +1 -0
- package/utils.js +1 -0
- package/dist/chunk-XQ4Z2OVN.mjs +0 -51
package/README.md
CHANGED
|
@@ -201,9 +201,9 @@ export default defineConfig(({ command }) => {
|
|
|
201
201
|
### electron-builder config
|
|
202
202
|
|
|
203
203
|
```js
|
|
204
|
-
const { name } = require('./package.json')
|
|
204
|
+
const { name, version } = require('./package.json')
|
|
205
205
|
|
|
206
|
-
const target = `${name}.asar`
|
|
206
|
+
const target = `${name}-${version}.asar`
|
|
207
207
|
/**
|
|
208
208
|
* @type {import('electron-builder').Configuration}
|
|
209
209
|
*/
|
|
@@ -0,0 +1,120 @@
|
|
|
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")
|
|
5
|
+
return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// src/utils.ts
|
|
10
|
+
import { createReadStream, createWriteStream, existsSync, readFileSync, rmSync } from "node:fs";
|
|
11
|
+
import { dirname, join } from "node:path";
|
|
12
|
+
import { createGunzip, createGzip } from "node:zlib";
|
|
13
|
+
import { app } from "electron";
|
|
14
|
+
function getProductAsarPath(name) {
|
|
15
|
+
return app.isPackaged ? join(dirname(app.getAppPath()), `${name}.asar`) : "dev";
|
|
16
|
+
}
|
|
17
|
+
function getEntryVersion() {
|
|
18
|
+
return app.getVersion();
|
|
19
|
+
}
|
|
20
|
+
function getProductVersion(name) {
|
|
21
|
+
return app.isPackaged ? readFileSync(join(getProductAsarPath(name), "version"), "utf-8") : getEntryVersion();
|
|
22
|
+
}
|
|
23
|
+
function requireNative(packageName) {
|
|
24
|
+
const path = app.isPackaged ? join(app.getAppPath(), "node_modules", packageName) : packageName;
|
|
25
|
+
return __require(path);
|
|
26
|
+
}
|
|
27
|
+
function parseGithubCdnURL(repository, cdnPrefix, relativeFilePath) {
|
|
28
|
+
if (!repository.startsWith("https://github.com/")) {
|
|
29
|
+
throw new Error("url must start with https://github.com/");
|
|
30
|
+
}
|
|
31
|
+
repository = repository.trim().replace(/\/?$/, "/").trim();
|
|
32
|
+
relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
|
|
33
|
+
cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
|
|
34
|
+
return repository.replace("github.com", cdnPrefix) + relativeFilePath;
|
|
35
|
+
}
|
|
36
|
+
function getGithubReleaseCdnGroup() {
|
|
37
|
+
return [
|
|
38
|
+
{ cdnPrefix: "gh.gh2233.ml", maintainer: "@X.I.U/XIU2" },
|
|
39
|
+
{ cdnPrefix: "ghproxy.com", maintainer: "gh-proxy" },
|
|
40
|
+
{ cdnPrefix: "gh.ddlc.top", maintainer: "@mtr-static-official" },
|
|
41
|
+
{ cdnPrefix: "ghdl.feizhuqwq.cf", maintainer: "feizhuqwq.com" },
|
|
42
|
+
{ cdnPrefix: "slink.ltd", maintainer: "\u77E5\u4E86\u5C0F\u7AD9" },
|
|
43
|
+
{ cdnPrefix: "git.xfj0.cn", maintainer: "anonymous1" },
|
|
44
|
+
{ cdnPrefix: "gh.con.sh", maintainer: "anonymous2" },
|
|
45
|
+
{ cdnPrefix: "ghps.cc", maintainer: "anonymous3" },
|
|
46
|
+
{ cdnPrefix: "cors.isteed.cc/github.com", maintainer: "Lufs's" },
|
|
47
|
+
{ cdnPrefix: "hub.gitmirror.com", maintainer: "GitMirror" },
|
|
48
|
+
{ cdnPrefix: "js.xxooo.ml", maintainer: "\u996D\u592A\u786C" },
|
|
49
|
+
{ cdnPrefix: "download.njuu.cf", maintainer: "LibraryCloud-njuu" },
|
|
50
|
+
{ cdnPrefix: "download.yzuu.cf", maintainer: "LibraryCloud-yzuu" },
|
|
51
|
+
{ cdnPrefix: "download.nuaa.cf", maintainer: "LibraryCloud-nuaa" }
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
function restartApp() {
|
|
55
|
+
app.relaunch();
|
|
56
|
+
app.quit();
|
|
57
|
+
}
|
|
58
|
+
function waitAppReady(duration = 1e3) {
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
const timeout = setTimeout(() => {
|
|
61
|
+
reject(new Error("app is not ready"));
|
|
62
|
+
}, duration);
|
|
63
|
+
app.whenReady().then(() => {
|
|
64
|
+
clearTimeout(timeout);
|
|
65
|
+
resolve(null);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async function unzipFile(gzipPath, targetFilePath) {
|
|
70
|
+
if (!existsSync(gzipPath)) {
|
|
71
|
+
throw new Error(`path to zipped file not exist: ${gzipPath}`);
|
|
72
|
+
}
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
const gunzip = createGunzip();
|
|
75
|
+
const input = createReadStream(gzipPath);
|
|
76
|
+
const output = createWriteStream(targetFilePath);
|
|
77
|
+
input.pipe(gunzip).pipe(output).on("finish", () => {
|
|
78
|
+
rmSync(gzipPath);
|
|
79
|
+
resolve(null);
|
|
80
|
+
}).on("error", (err) => {
|
|
81
|
+
rmSync(gzipPath);
|
|
82
|
+
output.destroy(err);
|
|
83
|
+
reject(err);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
|
|
88
|
+
if (!existsSync(filePath)) {
|
|
89
|
+
throw new Error(`path to be zipped not exist: ${filePath}`);
|
|
90
|
+
}
|
|
91
|
+
return new Promise((resolve, reject) => {
|
|
92
|
+
const gzip = createGzip();
|
|
93
|
+
const input = createReadStream(filePath);
|
|
94
|
+
const output = createWriteStream(targetFilePath);
|
|
95
|
+
input.pipe(gzip).pipe(output).on("finish", () => resolve(null)).on("error", (err) => reject(err));
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function handleUnexpectedErrors(callback) {
|
|
99
|
+
const listener = (err) => {
|
|
100
|
+
const e = err instanceof Error ? err : new Error(typeof err === "string" ? err : JSON.stringify(err));
|
|
101
|
+
callback(e);
|
|
102
|
+
};
|
|
103
|
+
process.on("uncaughtException", listener);
|
|
104
|
+
process.on("unhandledRejection", listener);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export {
|
|
108
|
+
__require,
|
|
109
|
+
getProductAsarPath,
|
|
110
|
+
getEntryVersion,
|
|
111
|
+
getProductVersion,
|
|
112
|
+
requireNative,
|
|
113
|
+
parseGithubCdnURL,
|
|
114
|
+
getGithubReleaseCdnGroup,
|
|
115
|
+
restartApp,
|
|
116
|
+
waitAppReady,
|
|
117
|
+
unzipFile,
|
|
118
|
+
zipFile,
|
|
119
|
+
handleUnexpectedErrors
|
|
120
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// src/crypto.ts
|
|
2
|
+
import { createCipheriv, createDecipheriv, createHash, createPrivateKey, createSign, createVerify } from "node:crypto";
|
|
3
|
+
import { Buffer } from "node:buffer";
|
|
4
|
+
function encrypt(plainText, key2, iv) {
|
|
5
|
+
const cipher = createCipheriv("aes-256-cbc", key2, iv);
|
|
6
|
+
let encrypted = cipher.update(plainText, "utf8", "base64url");
|
|
7
|
+
encrypted += cipher.final("base64url");
|
|
8
|
+
return encrypted;
|
|
9
|
+
}
|
|
10
|
+
function decrypt(encryptedText, key2, iv) {
|
|
11
|
+
const decipher = createDecipheriv("aes-256-cbc", key2, iv);
|
|
12
|
+
let decrypted = decipher.update(encryptedText, "base64url", "utf8");
|
|
13
|
+
decrypted += decipher.final("utf8");
|
|
14
|
+
return decrypted;
|
|
15
|
+
}
|
|
16
|
+
function key(data, length) {
|
|
17
|
+
const hash = createHash("SHA256").update(data).digest("binary");
|
|
18
|
+
return Buffer.from(hash).subarray(0, length);
|
|
19
|
+
}
|
|
20
|
+
var signature = (buffer, privateKey, cert, version) => {
|
|
21
|
+
const sig = createSign("RSA-SHA256").update(buffer).sign(createPrivateKey(privateKey), "base64");
|
|
22
|
+
return encrypt(`${sig}%${version}`, key(cert, 32), key(buffer, 16));
|
|
23
|
+
};
|
|
24
|
+
var verify = (buffer, signature2, cert) => {
|
|
25
|
+
try {
|
|
26
|
+
const [sig, version] = decrypt(signature2, key(cert, 32), key(buffer, 16)).split("%");
|
|
27
|
+
const result = createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
|
|
28
|
+
return result ? version : false;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
signature,
|
|
36
|
+
verify
|
|
37
|
+
};
|
package/dist/index.d.mts
CHANGED
|
@@ -11,7 +11,6 @@ type UpdateJSON = {
|
|
|
11
11
|
version: string;
|
|
12
12
|
size: number;
|
|
13
13
|
};
|
|
14
|
-
declare function isUpdateJSON(json: any): json is UpdateJSON;
|
|
15
14
|
type MaybeArray<T> = T extends undefined | null | never ? [] : T extends any[] ? T['length'] extends 1 ? [data: T[0]] : T : [data: T];
|
|
16
15
|
interface TypedUpdater<T extends Record<string | symbol, MaybeArray<any>>, Event extends Exclude<keyof T, number> = Exclude<keyof T, number>> {
|
|
17
16
|
removeAllListeners<E extends Event>(event?: E): this;
|
|
@@ -139,39 +138,6 @@ interface UpdaterOption {
|
|
|
139
138
|
};
|
|
140
139
|
}
|
|
141
140
|
|
|
142
|
-
/**
|
|
143
|
-
* get the application asar absolute path
|
|
144
|
-
* @param name The name of the application
|
|
145
|
-
*/
|
|
146
|
-
declare function getProductAsarPath(name: string): string;
|
|
147
|
-
/**
|
|
148
|
-
* get the version of entry (app.asar)
|
|
149
|
-
*/
|
|
150
|
-
declare function getEntryVersion(): string;
|
|
151
|
-
/**
|
|
152
|
-
* get the version of application (name.asar)
|
|
153
|
-
* @param name - The name of the application
|
|
154
|
-
*/
|
|
155
|
-
declare function getProductVersion(name: string): string;
|
|
156
|
-
/**
|
|
157
|
-
* require native package from app.asar
|
|
158
|
-
* @param packageName native package name
|
|
159
|
-
*/
|
|
160
|
-
declare function requireNative<T = any>(packageName: string): T;
|
|
161
|
-
/**
|
|
162
|
-
* get github version.json CDN URL for accelerating the speed of downloading version info
|
|
163
|
-
*/
|
|
164
|
-
declare function parseGithubCdnURL(repository: string, cdnPrefix: string, relativeFilePath: string): string;
|
|
165
|
-
/**
|
|
166
|
-
* get group of github release CDN prefix for accelerating the speed of downloading release
|
|
167
|
-
*/
|
|
168
|
-
declare function getGithubReleaseCdnGroup(): {
|
|
169
|
-
cdnPrefix: string;
|
|
170
|
-
maintainer: string;
|
|
171
|
-
}[];
|
|
172
|
-
declare function restartApp(): void;
|
|
173
|
-
declare function waitAppReady(duration?: number): Promise<unknown>;
|
|
174
|
-
|
|
175
141
|
declare function createUpdater({ SIGNATURE_CERT, repository, productName, releaseAsarURL: _release, updateJsonURL: _update, debug, downloadConfig: { extraHeader, userAgent }, overrideFunctions: { compareVersion, verifySignaure, downloadBuffer, downloadJSON, }, }: UpdaterOption): Updater;
|
|
176
142
|
|
|
177
143
|
type AppOption = {
|
|
@@ -234,4 +200,4 @@ declare function initApp(appOptions: AppOption): {
|
|
|
234
200
|
*/
|
|
235
201
|
declare function initApp(appOptions: AppOption, updaterOptions: InitUpdaterOptions): undefined;
|
|
236
202
|
|
|
237
|
-
export { AppOption,
|
|
203
|
+
export { AppOption, FunctionCompareVersion, FunctionVerifySignature, InitUpdaterOptions, StartupWithUpdater, UpdateJSON, Updater, UpdaterOption, createUpdater, initApp };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,6 @@ type UpdateJSON = {
|
|
|
11
11
|
version: string;
|
|
12
12
|
size: number;
|
|
13
13
|
};
|
|
14
|
-
declare function isUpdateJSON(json: any): json is UpdateJSON;
|
|
15
14
|
type MaybeArray<T> = T extends undefined | null | never ? [] : T extends any[] ? T['length'] extends 1 ? [data: T[0]] : T : [data: T];
|
|
16
15
|
interface TypedUpdater<T extends Record<string | symbol, MaybeArray<any>>, Event extends Exclude<keyof T, number> = Exclude<keyof T, number>> {
|
|
17
16
|
removeAllListeners<E extends Event>(event?: E): this;
|
|
@@ -139,39 +138,6 @@ interface UpdaterOption {
|
|
|
139
138
|
};
|
|
140
139
|
}
|
|
141
140
|
|
|
142
|
-
/**
|
|
143
|
-
* get the application asar absolute path
|
|
144
|
-
* @param name The name of the application
|
|
145
|
-
*/
|
|
146
|
-
declare function getProductAsarPath(name: string): string;
|
|
147
|
-
/**
|
|
148
|
-
* get the version of entry (app.asar)
|
|
149
|
-
*/
|
|
150
|
-
declare function getEntryVersion(): string;
|
|
151
|
-
/**
|
|
152
|
-
* get the version of application (name.asar)
|
|
153
|
-
* @param name - The name of the application
|
|
154
|
-
*/
|
|
155
|
-
declare function getProductVersion(name: string): string;
|
|
156
|
-
/**
|
|
157
|
-
* require native package from app.asar
|
|
158
|
-
* @param packageName native package name
|
|
159
|
-
*/
|
|
160
|
-
declare function requireNative<T = any>(packageName: string): T;
|
|
161
|
-
/**
|
|
162
|
-
* get github version.json CDN URL for accelerating the speed of downloading version info
|
|
163
|
-
*/
|
|
164
|
-
declare function parseGithubCdnURL(repository: string, cdnPrefix: string, relativeFilePath: string): string;
|
|
165
|
-
/**
|
|
166
|
-
* get group of github release CDN prefix for accelerating the speed of downloading release
|
|
167
|
-
*/
|
|
168
|
-
declare function getGithubReleaseCdnGroup(): {
|
|
169
|
-
cdnPrefix: string;
|
|
170
|
-
maintainer: string;
|
|
171
|
-
}[];
|
|
172
|
-
declare function restartApp(): void;
|
|
173
|
-
declare function waitAppReady(duration?: number): Promise<unknown>;
|
|
174
|
-
|
|
175
141
|
declare function createUpdater({ SIGNATURE_CERT, repository, productName, releaseAsarURL: _release, updateJsonURL: _update, debug, downloadConfig: { extraHeader, userAgent }, overrideFunctions: { compareVersion, verifySignaure, downloadBuffer, downloadJSON, }, }: UpdaterOption): Updater;
|
|
176
142
|
|
|
177
143
|
type AppOption = {
|
|
@@ -234,4 +200,4 @@ declare function initApp(appOptions: AppOption): {
|
|
|
234
200
|
*/
|
|
235
201
|
declare function initApp(appOptions: AppOption, updaterOptions: InitUpdaterOptions): undefined;
|
|
236
202
|
|
|
237
|
-
export { AppOption,
|
|
203
|
+
export { AppOption, FunctionCompareVersion, FunctionVerifySignature, InitUpdaterOptions, StartupWithUpdater, UpdateJSON, Updater, UpdaterOption, createUpdater, initApp };
|
package/dist/index.js
CHANGED
|
@@ -21,16 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
createUpdater: () => createUpdater,
|
|
24
|
-
|
|
25
|
-
getGithubReleaseCdnGroup: () => getGithubReleaseCdnGroup,
|
|
26
|
-
getProductAsarPath: () => getProductAsarPath,
|
|
27
|
-
getProductVersion: () => getProductVersion,
|
|
28
|
-
initApp: () => initApp,
|
|
29
|
-
isUpdateJSON: () => isUpdateJSON,
|
|
30
|
-
parseGithubCdnURL: () => parseGithubCdnURL,
|
|
31
|
-
requireNative: () => requireNative,
|
|
32
|
-
restartApp: () => restartApp,
|
|
33
|
-
waitAppReady: () => waitAppReady
|
|
24
|
+
initApp: () => initApp
|
|
34
25
|
});
|
|
35
26
|
module.exports = __toCommonJS(src_exports);
|
|
36
27
|
var import_node_path3 = require("path");
|
|
@@ -39,7 +30,6 @@ var import_electron4 = require("electron");
|
|
|
39
30
|
// src/updater/index.ts
|
|
40
31
|
var import_node_events = require("events");
|
|
41
32
|
var import_node_buffer3 = require("buffer");
|
|
42
|
-
var import_node_zlib = require("zlib");
|
|
43
33
|
var import_node_fs2 = require("fs");
|
|
44
34
|
var import_promises = require("fs/promises");
|
|
45
35
|
var import_node_path2 = require("path");
|
|
@@ -48,10 +38,9 @@ var import_electron3 = require("electron");
|
|
|
48
38
|
// src/crypto.ts
|
|
49
39
|
var import_node_crypto = require("crypto");
|
|
50
40
|
var import_node_buffer = require("buffer");
|
|
51
|
-
var aesEncode = "base64url";
|
|
52
41
|
function decrypt(encryptedText, key2, iv) {
|
|
53
42
|
const decipher = (0, import_node_crypto.createDecipheriv)("aes-256-cbc", key2, iv);
|
|
54
|
-
let decrypted = decipher.update(encryptedText,
|
|
43
|
+
let decrypted = decipher.update(encryptedText, "base64url", "utf8");
|
|
55
44
|
decrypted += decipher.final("utf8");
|
|
56
45
|
return decrypted;
|
|
57
46
|
}
|
|
@@ -69,18 +58,10 @@ var verify = (buffer, signature, cert) => {
|
|
|
69
58
|
}
|
|
70
59
|
};
|
|
71
60
|
|
|
72
|
-
// src/
|
|
73
|
-
var import_node_buffer2 = require("buffer");
|
|
74
|
-
var import_electron2 = require("electron");
|
|
75
|
-
|
|
76
|
-
// src/updater/types.ts
|
|
77
|
-
function isUpdateJSON(json) {
|
|
78
|
-
return "signature" in json && "version" in json && "size" in json;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// src/updater/utils.ts
|
|
61
|
+
// src/utils.ts
|
|
82
62
|
var import_node_fs = require("fs");
|
|
83
63
|
var import_node_path = require("path");
|
|
64
|
+
var import_node_zlib = require("zlib");
|
|
84
65
|
var import_electron = require("electron");
|
|
85
66
|
function getProductAsarPath(name) {
|
|
86
67
|
return import_electron.app.isPackaged ? (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${name}.asar`) : "dev";
|
|
@@ -88,44 +69,6 @@ function getProductAsarPath(name) {
|
|
|
88
69
|
function getEntryVersion() {
|
|
89
70
|
return import_electron.app.getVersion();
|
|
90
71
|
}
|
|
91
|
-
function getProductVersion(name) {
|
|
92
|
-
return import_electron.app.isPackaged ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8") : getEntryVersion();
|
|
93
|
-
}
|
|
94
|
-
function requireNative(packageName) {
|
|
95
|
-
const path = import_electron.app.isPackaged ? (0, import_node_path.join)(import_electron.app.getAppPath(), "node_modules", packageName) : packageName;
|
|
96
|
-
return require(path);
|
|
97
|
-
}
|
|
98
|
-
function parseGithubCdnURL(repository, cdnPrefix, relativeFilePath) {
|
|
99
|
-
if (!repository.startsWith("https://github.com/")) {
|
|
100
|
-
throw new Error("url must start with https://github.com/");
|
|
101
|
-
}
|
|
102
|
-
repository = repository.trim().replace(/\/?$/, "/").trim();
|
|
103
|
-
relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
|
|
104
|
-
cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
|
|
105
|
-
return repository.replace("github.com", cdnPrefix) + relativeFilePath;
|
|
106
|
-
}
|
|
107
|
-
function getGithubReleaseCdnGroup() {
|
|
108
|
-
return [
|
|
109
|
-
{ cdnPrefix: "gh.gh2233.ml", maintainer: "@X.I.U/XIU2" },
|
|
110
|
-
{ cdnPrefix: "ghproxy.com", maintainer: "gh-proxy" },
|
|
111
|
-
{ cdnPrefix: "gh.ddlc.top", maintainer: "@mtr-static-official" },
|
|
112
|
-
{ cdnPrefix: "ghdl.feizhuqwq.cf", maintainer: "feizhuqwq.com" },
|
|
113
|
-
{ cdnPrefix: "slink.ltd", maintainer: "\u77E5\u4E86\u5C0F\u7AD9" },
|
|
114
|
-
{ cdnPrefix: "git.xfj0.cn", maintainer: "anonymous1" },
|
|
115
|
-
{ cdnPrefix: "gh.con.sh", maintainer: "anonymous2" },
|
|
116
|
-
{ cdnPrefix: "ghps.cc", maintainer: "anonymous3" },
|
|
117
|
-
{ cdnPrefix: "cors.isteed.cc/github.com", maintainer: "Lufs's" },
|
|
118
|
-
{ cdnPrefix: "hub.gitmirror.com", maintainer: "GitMirror" },
|
|
119
|
-
{ cdnPrefix: "js.xxooo.ml", maintainer: "\u996D\u592A\u786C" },
|
|
120
|
-
{ cdnPrefix: "download.njuu.cf", maintainer: "LibraryCloud-njuu" },
|
|
121
|
-
{ cdnPrefix: "download.yzuu.cf", maintainer: "LibraryCloud-yzuu" },
|
|
122
|
-
{ cdnPrefix: "download.nuaa.cf", maintainer: "LibraryCloud-nuaa" }
|
|
123
|
-
];
|
|
124
|
-
}
|
|
125
|
-
function restartApp() {
|
|
126
|
-
import_electron.app.relaunch();
|
|
127
|
-
import_electron.app.quit();
|
|
128
|
-
}
|
|
129
72
|
function waitAppReady(duration = 1e3) {
|
|
130
73
|
return new Promise((resolve3, reject) => {
|
|
131
74
|
const timeout = setTimeout(() => {
|
|
@@ -137,6 +80,33 @@ function waitAppReady(duration = 1e3) {
|
|
|
137
80
|
});
|
|
138
81
|
});
|
|
139
82
|
}
|
|
83
|
+
async function unzipFile(gzipPath, targetFilePath) {
|
|
84
|
+
if (!(0, import_node_fs.existsSync)(gzipPath)) {
|
|
85
|
+
throw new Error(`path to zipped file not exist: ${gzipPath}`);
|
|
86
|
+
}
|
|
87
|
+
return new Promise((resolve3, reject) => {
|
|
88
|
+
const gunzip = (0, import_node_zlib.createGunzip)();
|
|
89
|
+
const input = (0, import_node_fs.createReadStream)(gzipPath);
|
|
90
|
+
const output = (0, import_node_fs.createWriteStream)(targetFilePath);
|
|
91
|
+
input.pipe(gunzip).pipe(output).on("finish", () => {
|
|
92
|
+
(0, import_node_fs.rmSync)(gzipPath);
|
|
93
|
+
resolve3(null);
|
|
94
|
+
}).on("error", (err) => {
|
|
95
|
+
(0, import_node_fs.rmSync)(gzipPath);
|
|
96
|
+
output.destroy(err);
|
|
97
|
+
reject(err);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/updater/defaultFunctions.ts
|
|
103
|
+
var import_node_buffer2 = require("buffer");
|
|
104
|
+
var import_electron2 = require("electron");
|
|
105
|
+
|
|
106
|
+
// src/updater/types.ts
|
|
107
|
+
function isUpdateJSON(json) {
|
|
108
|
+
return "signature" in json && "version" in json && "size" in json;
|
|
109
|
+
}
|
|
140
110
|
|
|
141
111
|
// src/updater/defaultFunctions.ts
|
|
142
112
|
async function downloadJSONDefault(url, updater, headers) {
|
|
@@ -240,44 +210,24 @@ function createUpdater({
|
|
|
240
210
|
} = {}
|
|
241
211
|
}) {
|
|
242
212
|
const updater = new import_node_events.EventEmitter();
|
|
243
|
-
let signature
|
|
213
|
+
let signature, version;
|
|
244
214
|
const asarPath = getProductAsarPath(productName);
|
|
245
215
|
const gzipPath = `${asarPath}.gz`;
|
|
246
216
|
const tmpFilePath = gzipPath.replace(".asar.gz", ".tmp.asar");
|
|
247
217
|
function log(msg) {
|
|
248
218
|
debug && updater.emit("debug", msg);
|
|
249
219
|
}
|
|
250
|
-
|
|
251
|
-
if (!gzipPath.endsWith(".asar.gz") || !(0, import_node_fs2.existsSync)(gzipPath)) {
|
|
252
|
-
throw new Error(".asar.gz file not exist");
|
|
253
|
-
}
|
|
254
|
-
return new Promise((resolve3, reject) => {
|
|
255
|
-
const gunzip = (0, import_node_zlib.createGunzip)();
|
|
256
|
-
const input = (0, import_node_fs2.createReadStream)(gzipPath);
|
|
257
|
-
const output = (0, import_node_fs2.createWriteStream)(tmpFilePath);
|
|
258
|
-
log(`outputFilePath: ${tmpFilePath}`);
|
|
259
|
-
input.pipe(gunzip).pipe(output).on("finish", async () => {
|
|
260
|
-
await (0, import_promises.rm)(gzipPath);
|
|
261
|
-
log(`${gzipPath} unzipped`);
|
|
262
|
-
resolve3(null);
|
|
263
|
-
}).on("error", async (err) => {
|
|
264
|
-
await (0, import_promises.rm)(gzipPath);
|
|
265
|
-
output.destroy(err);
|
|
266
|
-
reject(err);
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
function needUpdate(version) {
|
|
220
|
+
function needUpdate(version2) {
|
|
271
221
|
if (!import_electron3.app.isPackaged) {
|
|
272
222
|
log("in dev mode, no need to update");
|
|
273
223
|
return false;
|
|
274
224
|
}
|
|
275
225
|
const currentVersion = getEntryVersion();
|
|
276
|
-
log(`check update: current version is ${currentVersion}, new version is ${
|
|
226
|
+
log(`check update: current version is ${currentVersion}, new version is ${version2}`);
|
|
277
227
|
const _compare = compareVersion ?? compareVersionDefault;
|
|
278
|
-
return _compare(currentVersion,
|
|
228
|
+
return _compare(currentVersion, version2);
|
|
279
229
|
}
|
|
280
|
-
async function parseData(format, data) {
|
|
230
|
+
async function parseData(format, data, version2) {
|
|
281
231
|
if ((0, import_node_fs2.existsSync)(tmpFilePath)) {
|
|
282
232
|
log(`remove tmp file: ${tmpFilePath}`);
|
|
283
233
|
await (0, import_promises.rm)(tmpFilePath);
|
|
@@ -308,7 +258,7 @@ function createUpdater({
|
|
|
308
258
|
} : {
|
|
309
259
|
name: "releaseAsarURL",
|
|
310
260
|
url: _release,
|
|
311
|
-
repoFallback: `${repository}/releases/download/
|
|
261
|
+
repoFallback: `${repository}/releases/download/v${version2}/${productName}-${version2}.asar.gz`,
|
|
312
262
|
fn: downloadBuffer ?? downloadBufferDefault
|
|
313
263
|
};
|
|
314
264
|
data ??= info.url;
|
|
@@ -317,11 +267,14 @@ function createUpdater({
|
|
|
317
267
|
if (!repository) {
|
|
318
268
|
throw new Error(`${info.name} or repository are not set`);
|
|
319
269
|
}
|
|
270
|
+
if (format === "buffer" && !version2) {
|
|
271
|
+
throw new Error("version are not set");
|
|
272
|
+
}
|
|
320
273
|
data = info.repoFallback;
|
|
321
274
|
}
|
|
322
275
|
log(`download ${format} from ${data}`);
|
|
323
276
|
const ret = await info.fn(data, updater, headers);
|
|
324
|
-
log(`download ${format} success`);
|
|
277
|
+
log(`download ${format} success${format === "buffer" ? `, file size: ${ret.length}` : ""}`);
|
|
325
278
|
return ret;
|
|
326
279
|
} else {
|
|
327
280
|
throw new Error(`invalid type at format '${format}': ${data}`);
|
|
@@ -330,15 +283,16 @@ function createUpdater({
|
|
|
330
283
|
updater.setDebug = (isDebug) => debug = isDebug;
|
|
331
284
|
updater.checkUpdate = async (data) => {
|
|
332
285
|
try {
|
|
333
|
-
const { signature: _sig, size, version } = await parseData("json", data);
|
|
334
|
-
log(`checked version: ${
|
|
335
|
-
if (!needUpdate(
|
|
336
|
-
log(`update unavailable: ${
|
|
286
|
+
const { signature: _sig, size, version: _ver } = await parseData("json", data);
|
|
287
|
+
log(`checked version: ${_ver}, size: ${size}, signature: ${_sig}`);
|
|
288
|
+
if (!needUpdate(_ver)) {
|
|
289
|
+
log(`update unavailable: ${_ver}`);
|
|
337
290
|
return void 0;
|
|
338
291
|
} else {
|
|
339
|
-
log(`update available: ${
|
|
292
|
+
log(`update available: ${_ver}`);
|
|
340
293
|
signature = _sig;
|
|
341
|
-
|
|
294
|
+
version = _ver;
|
|
295
|
+
return { size, version: _ver };
|
|
342
296
|
}
|
|
343
297
|
} catch (error) {
|
|
344
298
|
log(error);
|
|
@@ -351,29 +305,29 @@ function createUpdater({
|
|
|
351
305
|
if (!_sig) {
|
|
352
306
|
throw new Error("signature are not set, please checkUpdate first or set the second parameter");
|
|
353
307
|
}
|
|
354
|
-
const buffer = await parseData("buffer", data);
|
|
308
|
+
const buffer = await parseData("buffer", data, version);
|
|
355
309
|
log("verify start");
|
|
356
310
|
const _verify = verifySignaure ?? verify;
|
|
357
|
-
const
|
|
358
|
-
if (!
|
|
311
|
+
const _ver = _verify(buffer, _sig, SIGNATURE_CERT);
|
|
312
|
+
if (!_ver) {
|
|
359
313
|
throw new Error("verify failed, invalid signature");
|
|
360
314
|
}
|
|
361
315
|
log("verify success");
|
|
362
|
-
if (!needUpdate(
|
|
363
|
-
throw new Error(`update unavailable: ${
|
|
316
|
+
if (!needUpdate(_ver)) {
|
|
317
|
+
throw new Error(`update unavailable: ${_ver}`);
|
|
364
318
|
}
|
|
365
319
|
log(`write file: ${gzipPath}`);
|
|
366
320
|
await (0, import_promises.writeFile)(gzipPath, buffer);
|
|
367
321
|
log(`extract file: ${gzipPath}`);
|
|
368
|
-
await
|
|
322
|
+
await unzipFile(gzipPath, tmpFilePath);
|
|
369
323
|
const asarVersion = await (0, import_promises.readFile)((0, import_node_path2.resolve)(tmpFilePath, "version"), "utf8");
|
|
370
|
-
if (asarVersion !==
|
|
324
|
+
if (asarVersion !== _ver) {
|
|
371
325
|
(0, import_node_fs2.rmSync)(tmpFilePath);
|
|
372
|
-
throw new Error(`update failed: asar version is ${asarVersion}, but it should be ${
|
|
326
|
+
throw new Error(`update failed: asar version is ${asarVersion}, but it should be ${_ver}`);
|
|
373
327
|
} else {
|
|
374
328
|
await (0, import_promises.rename)(tmpFilePath, asarPath);
|
|
375
329
|
}
|
|
376
|
-
log(`update success, version: ${
|
|
330
|
+
log(`update success, version: ${_ver}`);
|
|
377
331
|
signature = "";
|
|
378
332
|
return true;
|
|
379
333
|
} catch (error) {
|
|
@@ -408,14 +362,5 @@ function initApp(appOptions, updaterOptions) {
|
|
|
408
362
|
// Annotate the CommonJS export names for ESM import in node:
|
|
409
363
|
0 && (module.exports = {
|
|
410
364
|
createUpdater,
|
|
411
|
-
|
|
412
|
-
getGithubReleaseCdnGroup,
|
|
413
|
-
getProductAsarPath,
|
|
414
|
-
getProductVersion,
|
|
415
|
-
initApp,
|
|
416
|
-
isUpdateJSON,
|
|
417
|
-
parseGithubCdnURL,
|
|
418
|
-
requireNative,
|
|
419
|
-
restartApp,
|
|
420
|
-
waitAppReady
|
|
365
|
+
initApp
|
|
421
366
|
});
|