electron-incremental-update 0.7.0 → 0.7.1
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-XQ4Z2OVN.mjs → chunk-3YKEHZAU.mjs} +5 -15
- package/dist/chunk-CRBEZBU5.mjs +120 -0
- package/dist/index.d.mts +1 -35
- package/dist/index.d.ts +1 -35
- package/dist/index.js +34 -93
- package/dist/index.mjs +16 -100
- 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.js +18 -12
- package/dist/vite.mjs +5 -12
- package/package.json +8 -2
- package/utils.d.ts +1 -0
- package/utils.js +1 -0
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
|
*/
|
|
@@ -1,30 +1,21 @@
|
|
|
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
1
|
// src/crypto.ts
|
|
10
2
|
import { constants, createCipheriv, createDecipheriv, createHash, createSign, createVerify } from "node:crypto";
|
|
11
|
-
import { Buffer
|
|
12
|
-
var aesEncode = "base64url";
|
|
3
|
+
import { Buffer } from "node:buffer";
|
|
13
4
|
function encrypt(plainText, key2, iv) {
|
|
14
5
|
const cipher = createCipheriv("aes-256-cbc", key2, iv);
|
|
15
|
-
let encrypted = cipher.update(plainText, "utf8",
|
|
16
|
-
encrypted += cipher.final(
|
|
6
|
+
let encrypted = cipher.update(plainText, "utf8", "base64url");
|
|
7
|
+
encrypted += cipher.final("base64url");
|
|
17
8
|
return encrypted;
|
|
18
9
|
}
|
|
19
10
|
function decrypt(encryptedText, key2, iv) {
|
|
20
11
|
const decipher = createDecipheriv("aes-256-cbc", key2, iv);
|
|
21
|
-
let decrypted = decipher.update(encryptedText,
|
|
12
|
+
let decrypted = decipher.update(encryptedText, "base64url", "utf8");
|
|
22
13
|
decrypted += decipher.final("utf8");
|
|
23
14
|
return decrypted;
|
|
24
15
|
}
|
|
25
16
|
function key(data, length) {
|
|
26
17
|
const hash = createHash("SHA256").update(data).digest("binary");
|
|
27
|
-
return
|
|
18
|
+
return Buffer.from(hash).subarray(0, length);
|
|
28
19
|
}
|
|
29
20
|
var signature = (buffer, privateKey, cert, version) => {
|
|
30
21
|
const sig = createSign("RSA-SHA256").update(buffer).sign({
|
|
@@ -45,7 +36,6 @@ var verify = (buffer, signature2, cert) => {
|
|
|
45
36
|
};
|
|
46
37
|
|
|
47
38
|
export {
|
|
48
|
-
__require,
|
|
49
39
|
signature,
|
|
50
40
|
verify
|
|
51
41
|
};
|
|
@@ -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
|
+
};
|
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) {
|
|
@@ -247,26 +217,6 @@ function createUpdater({
|
|
|
247
217
|
function log(msg) {
|
|
248
218
|
debug && updater.emit("debug", msg);
|
|
249
219
|
}
|
|
250
|
-
async function extractFile() {
|
|
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
220
|
function needUpdate(version) {
|
|
271
221
|
if (!import_electron3.app.isPackaged) {
|
|
272
222
|
log("in dev mode, no need to update");
|
|
@@ -321,7 +271,7 @@ function createUpdater({
|
|
|
321
271
|
}
|
|
322
272
|
log(`download ${format} from ${data}`);
|
|
323
273
|
const ret = await info.fn(data, updater, headers);
|
|
324
|
-
log(`download ${format} success`);
|
|
274
|
+
log(`download ${format} success${format === "buffer" ? `, file size: ${ret.length}` : ""}`);
|
|
325
275
|
return ret;
|
|
326
276
|
} else {
|
|
327
277
|
throw new Error(`invalid type at format '${format}': ${data}`);
|
|
@@ -365,7 +315,7 @@ function createUpdater({
|
|
|
365
315
|
log(`write file: ${gzipPath}`);
|
|
366
316
|
await (0, import_promises.writeFile)(gzipPath, buffer);
|
|
367
317
|
log(`extract file: ${gzipPath}`);
|
|
368
|
-
await
|
|
318
|
+
await unzipFile(gzipPath, tmpFilePath);
|
|
369
319
|
const asarVersion = await (0, import_promises.readFile)((0, import_node_path2.resolve)(tmpFilePath, "version"), "utf8");
|
|
370
320
|
if (asarVersion !== version) {
|
|
371
321
|
(0, import_node_fs2.rmSync)(tmpFilePath);
|
|
@@ -408,14 +358,5 @@ function initApp(appOptions, updaterOptions) {
|
|
|
408
358
|
// Annotate the CommonJS export names for ESM import in node:
|
|
409
359
|
0 && (module.exports = {
|
|
410
360
|
createUpdater,
|
|
411
|
-
|
|
412
|
-
getGithubReleaseCdnGroup,
|
|
413
|
-
getProductAsarPath,
|
|
414
|
-
getProductVersion,
|
|
415
|
-
initApp,
|
|
416
|
-
isUpdateJSON,
|
|
417
|
-
parseGithubCdnURL,
|
|
418
|
-
requireNative,
|
|
419
|
-
restartApp,
|
|
420
|
-
waitAppReady
|
|
361
|
+
initApp
|
|
421
362
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
|
-
__require,
|
|
3
2
|
verify
|
|
4
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-3YKEHZAU.mjs";
|
|
4
|
+
import {
|
|
5
|
+
__require,
|
|
6
|
+
getEntryVersion,
|
|
7
|
+
getProductAsarPath,
|
|
8
|
+
unzipFile,
|
|
9
|
+
waitAppReady
|
|
10
|
+
} from "./chunk-CRBEZBU5.mjs";
|
|
5
11
|
|
|
6
12
|
// src/index.ts
|
|
7
13
|
import { resolve as resolve2 } from "node:path";
|
|
8
|
-
import { app as
|
|
14
|
+
import { app as app2 } from "electron";
|
|
9
15
|
|
|
10
16
|
// src/updater/index.ts
|
|
11
17
|
import { EventEmitter } from "node:events";
|
|
12
18
|
import { Buffer as Buffer2 } from "node:buffer";
|
|
13
|
-
import {
|
|
14
|
-
import { createReadStream, createWriteStream, existsSync, rmSync } from "node:fs";
|
|
19
|
+
import { existsSync, rmSync } from "node:fs";
|
|
15
20
|
import { readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
16
21
|
import { resolve } from "node:path";
|
|
17
|
-
import { app
|
|
22
|
+
import { app } from "electron";
|
|
18
23
|
|
|
19
24
|
// src/updater/defaultFunctions.ts
|
|
20
25
|
import { Buffer } from "node:buffer";
|
|
@@ -25,66 +30,6 @@ function isUpdateJSON(json) {
|
|
|
25
30
|
return "signature" in json && "version" in json && "size" in json;
|
|
26
31
|
}
|
|
27
32
|
|
|
28
|
-
// src/updater/utils.ts
|
|
29
|
-
import { readFileSync } from "node:fs";
|
|
30
|
-
import { dirname, join } from "node:path";
|
|
31
|
-
import { app } from "electron";
|
|
32
|
-
function getProductAsarPath(name) {
|
|
33
|
-
return app.isPackaged ? join(dirname(app.getAppPath()), `${name}.asar`) : "dev";
|
|
34
|
-
}
|
|
35
|
-
function getEntryVersion() {
|
|
36
|
-
return app.getVersion();
|
|
37
|
-
}
|
|
38
|
-
function getProductVersion(name) {
|
|
39
|
-
return app.isPackaged ? readFileSync(join(getProductAsarPath(name), "version"), "utf-8") : getEntryVersion();
|
|
40
|
-
}
|
|
41
|
-
function requireNative(packageName) {
|
|
42
|
-
const path = app.isPackaged ? join(app.getAppPath(), "node_modules", packageName) : packageName;
|
|
43
|
-
return __require(path);
|
|
44
|
-
}
|
|
45
|
-
function parseGithubCdnURL(repository, cdnPrefix, relativeFilePath) {
|
|
46
|
-
if (!repository.startsWith("https://github.com/")) {
|
|
47
|
-
throw new Error("url must start with https://github.com/");
|
|
48
|
-
}
|
|
49
|
-
repository = repository.trim().replace(/\/?$/, "/").trim();
|
|
50
|
-
relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
|
|
51
|
-
cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
|
|
52
|
-
return repository.replace("github.com", cdnPrefix) + relativeFilePath;
|
|
53
|
-
}
|
|
54
|
-
function getGithubReleaseCdnGroup() {
|
|
55
|
-
return [
|
|
56
|
-
{ cdnPrefix: "gh.gh2233.ml", maintainer: "@X.I.U/XIU2" },
|
|
57
|
-
{ cdnPrefix: "ghproxy.com", maintainer: "gh-proxy" },
|
|
58
|
-
{ cdnPrefix: "gh.ddlc.top", maintainer: "@mtr-static-official" },
|
|
59
|
-
{ cdnPrefix: "ghdl.feizhuqwq.cf", maintainer: "feizhuqwq.com" },
|
|
60
|
-
{ cdnPrefix: "slink.ltd", maintainer: "\u77E5\u4E86\u5C0F\u7AD9" },
|
|
61
|
-
{ cdnPrefix: "git.xfj0.cn", maintainer: "anonymous1" },
|
|
62
|
-
{ cdnPrefix: "gh.con.sh", maintainer: "anonymous2" },
|
|
63
|
-
{ cdnPrefix: "ghps.cc", maintainer: "anonymous3" },
|
|
64
|
-
{ cdnPrefix: "cors.isteed.cc/github.com", maintainer: "Lufs's" },
|
|
65
|
-
{ cdnPrefix: "hub.gitmirror.com", maintainer: "GitMirror" },
|
|
66
|
-
{ cdnPrefix: "js.xxooo.ml", maintainer: "\u996D\u592A\u786C" },
|
|
67
|
-
{ cdnPrefix: "download.njuu.cf", maintainer: "LibraryCloud-njuu" },
|
|
68
|
-
{ cdnPrefix: "download.yzuu.cf", maintainer: "LibraryCloud-yzuu" },
|
|
69
|
-
{ cdnPrefix: "download.nuaa.cf", maintainer: "LibraryCloud-nuaa" }
|
|
70
|
-
];
|
|
71
|
-
}
|
|
72
|
-
function restartApp() {
|
|
73
|
-
app.relaunch();
|
|
74
|
-
app.quit();
|
|
75
|
-
}
|
|
76
|
-
function waitAppReady(duration = 1e3) {
|
|
77
|
-
return new Promise((resolve3, reject) => {
|
|
78
|
-
const timeout = setTimeout(() => {
|
|
79
|
-
reject(new Error("app is not ready"));
|
|
80
|
-
}, duration);
|
|
81
|
-
app.whenReady().then(() => {
|
|
82
|
-
clearTimeout(timeout);
|
|
83
|
-
resolve3(null);
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
33
|
// src/updater/defaultFunctions.ts
|
|
89
34
|
async function downloadJSONDefault(url, updater, headers) {
|
|
90
35
|
await waitAppReady();
|
|
@@ -194,28 +139,8 @@ function createUpdater({
|
|
|
194
139
|
function log(msg) {
|
|
195
140
|
debug && updater.emit("debug", msg);
|
|
196
141
|
}
|
|
197
|
-
async function extractFile() {
|
|
198
|
-
if (!gzipPath.endsWith(".asar.gz") || !existsSync(gzipPath)) {
|
|
199
|
-
throw new Error(".asar.gz file not exist");
|
|
200
|
-
}
|
|
201
|
-
return new Promise((resolve3, reject) => {
|
|
202
|
-
const gunzip = createGunzip();
|
|
203
|
-
const input = createReadStream(gzipPath);
|
|
204
|
-
const output = createWriteStream(tmpFilePath);
|
|
205
|
-
log(`outputFilePath: ${tmpFilePath}`);
|
|
206
|
-
input.pipe(gunzip).pipe(output).on("finish", async () => {
|
|
207
|
-
await rm(gzipPath);
|
|
208
|
-
log(`${gzipPath} unzipped`);
|
|
209
|
-
resolve3(null);
|
|
210
|
-
}).on("error", async (err) => {
|
|
211
|
-
await rm(gzipPath);
|
|
212
|
-
output.destroy(err);
|
|
213
|
-
reject(err);
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
142
|
function needUpdate(version) {
|
|
218
|
-
if (!
|
|
143
|
+
if (!app.isPackaged) {
|
|
219
144
|
log("in dev mode, no need to update");
|
|
220
145
|
return false;
|
|
221
146
|
}
|
|
@@ -268,7 +193,7 @@ function createUpdater({
|
|
|
268
193
|
}
|
|
269
194
|
log(`download ${format} from ${data}`);
|
|
270
195
|
const ret = await info.fn(data, updater, headers);
|
|
271
|
-
log(`download ${format} success`);
|
|
196
|
+
log(`download ${format} success${format === "buffer" ? `, file size: ${ret.length}` : ""}`);
|
|
272
197
|
return ret;
|
|
273
198
|
} else {
|
|
274
199
|
throw new Error(`invalid type at format '${format}': ${data}`);
|
|
@@ -312,7 +237,7 @@ function createUpdater({
|
|
|
312
237
|
log(`write file: ${gzipPath}`);
|
|
313
238
|
await writeFile(gzipPath, buffer);
|
|
314
239
|
log(`extract file: ${gzipPath}`);
|
|
315
|
-
await
|
|
240
|
+
await unzipFile(gzipPath, tmpFilePath);
|
|
316
241
|
const asarVersion = await readFile(resolve(tmpFilePath, "version"), "utf8");
|
|
317
242
|
if (asarVersion !== version) {
|
|
318
243
|
rmSync(tmpFilePath);
|
|
@@ -338,7 +263,7 @@ function initApp(appOptions, updaterOptions) {
|
|
|
338
263
|
electronDistPath = "dist-electron",
|
|
339
264
|
mainPath = "main/index.js"
|
|
340
265
|
} = appOptions ?? {};
|
|
341
|
-
const mainDir =
|
|
266
|
+
const mainDir = app2.isPackaged ? `../${productName}.asar` : electronDistPath;
|
|
342
267
|
const entry = resolve2(__dirname, mainDir, mainPath);
|
|
343
268
|
if (updaterOptions) {
|
|
344
269
|
__require(entry)(
|
|
@@ -354,14 +279,5 @@ function initApp(appOptions, updaterOptions) {
|
|
|
354
279
|
}
|
|
355
280
|
export {
|
|
356
281
|
createUpdater,
|
|
357
|
-
|
|
358
|
-
getGithubReleaseCdnGroup,
|
|
359
|
-
getProductAsarPath,
|
|
360
|
-
getProductVersion,
|
|
361
|
-
initApp,
|
|
362
|
-
isUpdateJSON,
|
|
363
|
-
parseGithubCdnURL,
|
|
364
|
-
requireNative,
|
|
365
|
-
restartApp,
|
|
366
|
-
waitAppReady
|
|
282
|
+
initApp
|
|
367
283
|
};
|
package/dist/utils.d.mts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* get the application asar absolute path
|
|
3
|
+
* @param name The name of the application
|
|
4
|
+
*/
|
|
5
|
+
declare function getProductAsarPath(name: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* get the version of entry (app.asar)
|
|
8
|
+
*/
|
|
9
|
+
declare function getEntryVersion(): string;
|
|
10
|
+
/**
|
|
11
|
+
* get the version of application (name.asar)
|
|
12
|
+
* @param name - The name of the application
|
|
13
|
+
*/
|
|
14
|
+
declare function getProductVersion(name: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* require native package from app.asar
|
|
17
|
+
* @param packageName native package name
|
|
18
|
+
*/
|
|
19
|
+
declare function requireNative<T = any>(packageName: string): T;
|
|
20
|
+
/**
|
|
21
|
+
* get github version.json CDN URL for accelerating the speed of downloading version info
|
|
22
|
+
*/
|
|
23
|
+
declare function parseGithubCdnURL(repository: string, cdnPrefix: string, relativeFilePath: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* get group of github release CDN prefix for accelerating the speed of downloading release
|
|
26
|
+
*/
|
|
27
|
+
declare function getGithubReleaseCdnGroup(): {
|
|
28
|
+
cdnPrefix: string;
|
|
29
|
+
maintainer: string;
|
|
30
|
+
}[];
|
|
31
|
+
declare function restartApp(): void;
|
|
32
|
+
declare function waitAppReady(duration?: number): Promise<unknown>;
|
|
33
|
+
declare function unzipFile(gzipPath: string, targetFilePath: string): Promise<unknown>;
|
|
34
|
+
declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
|
|
35
|
+
declare function handleUnexpectedErrors(callback: (err: Error) => void): void;
|
|
36
|
+
|
|
37
|
+
export { getEntryVersion, getGithubReleaseCdnGroup, getProductAsarPath, getProductVersion, handleUnexpectedErrors, parseGithubCdnURL, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* get the application asar absolute path
|
|
3
|
+
* @param name The name of the application
|
|
4
|
+
*/
|
|
5
|
+
declare function getProductAsarPath(name: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* get the version of entry (app.asar)
|
|
8
|
+
*/
|
|
9
|
+
declare function getEntryVersion(): string;
|
|
10
|
+
/**
|
|
11
|
+
* get the version of application (name.asar)
|
|
12
|
+
* @param name - The name of the application
|
|
13
|
+
*/
|
|
14
|
+
declare function getProductVersion(name: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* require native package from app.asar
|
|
17
|
+
* @param packageName native package name
|
|
18
|
+
*/
|
|
19
|
+
declare function requireNative<T = any>(packageName: string): T;
|
|
20
|
+
/**
|
|
21
|
+
* get github version.json CDN URL for accelerating the speed of downloading version info
|
|
22
|
+
*/
|
|
23
|
+
declare function parseGithubCdnURL(repository: string, cdnPrefix: string, relativeFilePath: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* get group of github release CDN prefix for accelerating the speed of downloading release
|
|
26
|
+
*/
|
|
27
|
+
declare function getGithubReleaseCdnGroup(): {
|
|
28
|
+
cdnPrefix: string;
|
|
29
|
+
maintainer: string;
|
|
30
|
+
}[];
|
|
31
|
+
declare function restartApp(): void;
|
|
32
|
+
declare function waitAppReady(duration?: number): Promise<unknown>;
|
|
33
|
+
declare function unzipFile(gzipPath: string, targetFilePath: string): Promise<unknown>;
|
|
34
|
+
declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
|
|
35
|
+
declare function handleUnexpectedErrors(callback: (err: Error) => void): void;
|
|
36
|
+
|
|
37
|
+
export { getEntryVersion, getGithubReleaseCdnGroup, getProductAsarPath, getProductVersion, handleUnexpectedErrors, parseGithubCdnURL, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
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);
|
|
19
|
+
|
|
20
|
+
// src/utils.ts
|
|
21
|
+
var utils_exports = {};
|
|
22
|
+
__export(utils_exports, {
|
|
23
|
+
getEntryVersion: () => getEntryVersion,
|
|
24
|
+
getGithubReleaseCdnGroup: () => getGithubReleaseCdnGroup,
|
|
25
|
+
getProductAsarPath: () => getProductAsarPath,
|
|
26
|
+
getProductVersion: () => getProductVersion,
|
|
27
|
+
handleUnexpectedErrors: () => handleUnexpectedErrors,
|
|
28
|
+
parseGithubCdnURL: () => parseGithubCdnURL,
|
|
29
|
+
requireNative: () => requireNative,
|
|
30
|
+
restartApp: () => restartApp,
|
|
31
|
+
unzipFile: () => unzipFile,
|
|
32
|
+
waitAppReady: () => waitAppReady,
|
|
33
|
+
zipFile: () => zipFile
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(utils_exports);
|
|
36
|
+
var import_node_fs = require("fs");
|
|
37
|
+
var import_node_path = require("path");
|
|
38
|
+
var import_node_zlib = require("zlib");
|
|
39
|
+
var import_electron = require("electron");
|
|
40
|
+
function getProductAsarPath(name) {
|
|
41
|
+
return import_electron.app.isPackaged ? (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${name}.asar`) : "dev";
|
|
42
|
+
}
|
|
43
|
+
function getEntryVersion() {
|
|
44
|
+
return import_electron.app.getVersion();
|
|
45
|
+
}
|
|
46
|
+
function getProductVersion(name) {
|
|
47
|
+
return import_electron.app.isPackaged ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8") : getEntryVersion();
|
|
48
|
+
}
|
|
49
|
+
function requireNative(packageName) {
|
|
50
|
+
const path = import_electron.app.isPackaged ? (0, import_node_path.join)(import_electron.app.getAppPath(), "node_modules", packageName) : packageName;
|
|
51
|
+
return require(path);
|
|
52
|
+
}
|
|
53
|
+
function parseGithubCdnURL(repository, cdnPrefix, relativeFilePath) {
|
|
54
|
+
if (!repository.startsWith("https://github.com/")) {
|
|
55
|
+
throw new Error("url must start with https://github.com/");
|
|
56
|
+
}
|
|
57
|
+
repository = repository.trim().replace(/\/?$/, "/").trim();
|
|
58
|
+
relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
|
|
59
|
+
cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
|
|
60
|
+
return repository.replace("github.com", cdnPrefix) + relativeFilePath;
|
|
61
|
+
}
|
|
62
|
+
function getGithubReleaseCdnGroup() {
|
|
63
|
+
return [
|
|
64
|
+
{ cdnPrefix: "gh.gh2233.ml", maintainer: "@X.I.U/XIU2" },
|
|
65
|
+
{ cdnPrefix: "ghproxy.com", maintainer: "gh-proxy" },
|
|
66
|
+
{ cdnPrefix: "gh.ddlc.top", maintainer: "@mtr-static-official" },
|
|
67
|
+
{ cdnPrefix: "ghdl.feizhuqwq.cf", maintainer: "feizhuqwq.com" },
|
|
68
|
+
{ cdnPrefix: "slink.ltd", maintainer: "\u77E5\u4E86\u5C0F\u7AD9" },
|
|
69
|
+
{ cdnPrefix: "git.xfj0.cn", maintainer: "anonymous1" },
|
|
70
|
+
{ cdnPrefix: "gh.con.sh", maintainer: "anonymous2" },
|
|
71
|
+
{ cdnPrefix: "ghps.cc", maintainer: "anonymous3" },
|
|
72
|
+
{ cdnPrefix: "cors.isteed.cc/github.com", maintainer: "Lufs's" },
|
|
73
|
+
{ cdnPrefix: "hub.gitmirror.com", maintainer: "GitMirror" },
|
|
74
|
+
{ cdnPrefix: "js.xxooo.ml", maintainer: "\u996D\u592A\u786C" },
|
|
75
|
+
{ cdnPrefix: "download.njuu.cf", maintainer: "LibraryCloud-njuu" },
|
|
76
|
+
{ cdnPrefix: "download.yzuu.cf", maintainer: "LibraryCloud-yzuu" },
|
|
77
|
+
{ cdnPrefix: "download.nuaa.cf", maintainer: "LibraryCloud-nuaa" }
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
function restartApp() {
|
|
81
|
+
import_electron.app.relaunch();
|
|
82
|
+
import_electron.app.quit();
|
|
83
|
+
}
|
|
84
|
+
function waitAppReady(duration = 1e3) {
|
|
85
|
+
return new Promise((resolve, reject) => {
|
|
86
|
+
const timeout = setTimeout(() => {
|
|
87
|
+
reject(new Error("app is not ready"));
|
|
88
|
+
}, duration);
|
|
89
|
+
import_electron.app.whenReady().then(() => {
|
|
90
|
+
clearTimeout(timeout);
|
|
91
|
+
resolve(null);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
async function unzipFile(gzipPath, targetFilePath) {
|
|
96
|
+
if (!(0, import_node_fs.existsSync)(gzipPath)) {
|
|
97
|
+
throw new Error(`path to zipped file not exist: ${gzipPath}`);
|
|
98
|
+
}
|
|
99
|
+
return new Promise((resolve, reject) => {
|
|
100
|
+
const gunzip = (0, import_node_zlib.createGunzip)();
|
|
101
|
+
const input = (0, import_node_fs.createReadStream)(gzipPath);
|
|
102
|
+
const output = (0, import_node_fs.createWriteStream)(targetFilePath);
|
|
103
|
+
input.pipe(gunzip).pipe(output).on("finish", () => {
|
|
104
|
+
(0, import_node_fs.rmSync)(gzipPath);
|
|
105
|
+
resolve(null);
|
|
106
|
+
}).on("error", (err) => {
|
|
107
|
+
(0, import_node_fs.rmSync)(gzipPath);
|
|
108
|
+
output.destroy(err);
|
|
109
|
+
reject(err);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
|
|
114
|
+
if (!(0, import_node_fs.existsSync)(filePath)) {
|
|
115
|
+
throw new Error(`path to be zipped not exist: ${filePath}`);
|
|
116
|
+
}
|
|
117
|
+
return new Promise((resolve, reject) => {
|
|
118
|
+
const gzip = (0, import_node_zlib.createGzip)();
|
|
119
|
+
const input = (0, import_node_fs.createReadStream)(filePath);
|
|
120
|
+
const output = (0, import_node_fs.createWriteStream)(targetFilePath);
|
|
121
|
+
input.pipe(gzip).pipe(output).on("finish", () => resolve(null)).on("error", (err) => reject(err));
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function handleUnexpectedErrors(callback) {
|
|
125
|
+
const listener = (err) => {
|
|
126
|
+
const e = err instanceof Error ? err : new Error(typeof err === "string" ? err : JSON.stringify(err));
|
|
127
|
+
callback(e);
|
|
128
|
+
};
|
|
129
|
+
process.on("uncaughtException", listener);
|
|
130
|
+
process.on("unhandledRejection", listener);
|
|
131
|
+
}
|
|
132
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
133
|
+
0 && (module.exports = {
|
|
134
|
+
getEntryVersion,
|
|
135
|
+
getGithubReleaseCdnGroup,
|
|
136
|
+
getProductAsarPath,
|
|
137
|
+
getProductVersion,
|
|
138
|
+
handleUnexpectedErrors,
|
|
139
|
+
parseGithubCdnURL,
|
|
140
|
+
requireNative,
|
|
141
|
+
restartApp,
|
|
142
|
+
unzipFile,
|
|
143
|
+
waitAppReady,
|
|
144
|
+
zipFile
|
|
145
|
+
});
|
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getEntryVersion,
|
|
3
|
+
getGithubReleaseCdnGroup,
|
|
4
|
+
getProductAsarPath,
|
|
5
|
+
getProductVersion,
|
|
6
|
+
handleUnexpectedErrors,
|
|
7
|
+
parseGithubCdnURL,
|
|
8
|
+
requireNative,
|
|
9
|
+
restartApp,
|
|
10
|
+
unzipFile,
|
|
11
|
+
waitAppReady,
|
|
12
|
+
zipFile
|
|
13
|
+
} from "./chunk-CRBEZBU5.mjs";
|
|
14
|
+
export {
|
|
15
|
+
getEntryVersion,
|
|
16
|
+
getGithubReleaseCdnGroup,
|
|
17
|
+
getProductAsarPath,
|
|
18
|
+
getProductVersion,
|
|
19
|
+
handleUnexpectedErrors,
|
|
20
|
+
parseGithubCdnURL,
|
|
21
|
+
requireNative,
|
|
22
|
+
restartApp,
|
|
23
|
+
unzipFile,
|
|
24
|
+
waitAppReady,
|
|
25
|
+
zipFile
|
|
26
|
+
};
|
package/dist/vite.js
CHANGED
|
@@ -36,19 +36,16 @@ module.exports = __toCommonJS(vite_exports);
|
|
|
36
36
|
var import_vite = require("vite");
|
|
37
37
|
|
|
38
38
|
// src/build-plugins/build.ts
|
|
39
|
-
var import_node_fs = require("fs");
|
|
40
39
|
var import_promises = require("fs/promises");
|
|
41
|
-
var import_node_zlib = __toESM(require("zlib"));
|
|
42
40
|
var import_esbuild = require("esbuild");
|
|
43
41
|
|
|
44
42
|
// src/crypto.ts
|
|
45
43
|
var import_node_crypto = require("crypto");
|
|
46
44
|
var import_node_buffer = require("buffer");
|
|
47
|
-
var aesEncode = "base64url";
|
|
48
45
|
function encrypt(plainText, key2, iv) {
|
|
49
46
|
const cipher = (0, import_node_crypto.createCipheriv)("aes-256-cbc", key2, iv);
|
|
50
|
-
let encrypted = cipher.update(plainText, "utf8",
|
|
51
|
-
encrypted += cipher.final(
|
|
47
|
+
let encrypted = cipher.update(plainText, "utf8", "base64url");
|
|
48
|
+
encrypted += cipher.final("base64url");
|
|
52
49
|
return encrypted;
|
|
53
50
|
}
|
|
54
51
|
function key(data, length) {
|
|
@@ -64,15 +61,24 @@ var signature = (buffer, privateKey, cert, version) => {
|
|
|
64
61
|
return encrypt(`${sig}%${version}`, key(cert, 32), key(buffer, 16));
|
|
65
62
|
};
|
|
66
63
|
|
|
67
|
-
// src/
|
|
68
|
-
|
|
64
|
+
// src/utils.ts
|
|
65
|
+
var import_node_fs = require("fs");
|
|
66
|
+
var import_node_path = require("path");
|
|
67
|
+
var import_node_zlib = require("zlib");
|
|
68
|
+
var import_electron = require("electron");
|
|
69
|
+
async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
|
|
70
|
+
if (!(0, import_node_fs.existsSync)(filePath)) {
|
|
71
|
+
throw new Error(`path to be zipped not exist: ${filePath}`);
|
|
72
|
+
}
|
|
69
73
|
return new Promise((resolve, reject) => {
|
|
70
|
-
const gzip = import_node_zlib.
|
|
74
|
+
const gzip = (0, import_node_zlib.createGzip)();
|
|
71
75
|
const input = (0, import_node_fs.createReadStream)(filePath);
|
|
72
|
-
const output = (0, import_node_fs.createWriteStream)(
|
|
76
|
+
const output = (0, import_node_fs.createWriteStream)(targetFilePath);
|
|
73
77
|
input.pipe(gzip).pipe(output).on("finish", () => resolve(null)).on("error", (err) => reject(err));
|
|
74
78
|
});
|
|
75
79
|
}
|
|
80
|
+
|
|
81
|
+
// src/build-plugins/build.ts
|
|
76
82
|
async function pack(dir, target) {
|
|
77
83
|
let asar = null;
|
|
78
84
|
try {
|
|
@@ -99,7 +105,7 @@ async function buildAsar({
|
|
|
99
105
|
await (0, import_promises.rename)(rendererDistPath, `${electronDistPath}/renderer`);
|
|
100
106
|
await (0, import_promises.writeFile)(`${electronDistPath}/version`, version);
|
|
101
107
|
await pack(electronDistPath, asarOutputPath);
|
|
102
|
-
await
|
|
108
|
+
await zipFile(asarOutputPath);
|
|
103
109
|
}
|
|
104
110
|
async function buildVersion({
|
|
105
111
|
asarOutputPath,
|
|
@@ -134,7 +140,7 @@ async function buildEntry({
|
|
|
134
140
|
|
|
135
141
|
// src/build-plugins/key.ts
|
|
136
142
|
var import_node_fs2 = require("fs");
|
|
137
|
-
var
|
|
143
|
+
var import_node_path2 = require("path");
|
|
138
144
|
var import_node_os = require("os");
|
|
139
145
|
var import_node_crypto2 = require("crypto");
|
|
140
146
|
var import_jscert = require("@cyyynthia/jscert");
|
|
@@ -185,7 +191,7 @@ function getKeys({
|
|
|
185
191
|
expires,
|
|
186
192
|
generateKeyPair
|
|
187
193
|
}) {
|
|
188
|
-
const keysDir = (0,
|
|
194
|
+
const keysDir = (0, import_node_path2.dirname)(privateKeyPath);
|
|
189
195
|
!(0, import_node_fs2.existsSync)(keysDir) && (0, import_node_fs2.mkdirSync)(keysDir);
|
|
190
196
|
let privateKey, cert;
|
|
191
197
|
if (!(0, import_node_fs2.existsSync)(privateKeyPath) || !(0, import_node_fs2.existsSync)(certPath)) {
|
package/dist/vite.mjs
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
signature
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-3YKEHZAU.mjs";
|
|
4
|
+
import {
|
|
5
|
+
zipFile
|
|
6
|
+
} from "./chunk-CRBEZBU5.mjs";
|
|
4
7
|
|
|
5
8
|
// src/vite.ts
|
|
6
9
|
import { createLogger } from "vite";
|
|
7
10
|
|
|
8
11
|
// src/build-plugins/build.ts
|
|
9
|
-
import { createReadStream, createWriteStream } from "node:fs";
|
|
10
12
|
import { readFile, rename, writeFile } from "node:fs/promises";
|
|
11
|
-
import zlib from "node:zlib";
|
|
12
13
|
import { build } from "esbuild";
|
|
13
|
-
function gzipFile(filePath) {
|
|
14
|
-
return new Promise((resolve, reject) => {
|
|
15
|
-
const gzip = zlib.createGzip();
|
|
16
|
-
const input = createReadStream(filePath);
|
|
17
|
-
const output = createWriteStream(`${filePath}.gz`);
|
|
18
|
-
input.pipe(gzip).pipe(output).on("finish", () => resolve(null)).on("error", (err) => reject(err));
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
14
|
async function pack(dir, target) {
|
|
22
15
|
let asar = null;
|
|
23
16
|
try {
|
|
@@ -44,7 +37,7 @@ async function buildAsar({
|
|
|
44
37
|
await rename(rendererDistPath, `${electronDistPath}/renderer`);
|
|
45
38
|
await writeFile(`${electronDistPath}/version`, version);
|
|
46
39
|
await pack(electronDistPath, asarOutputPath);
|
|
47
|
-
await
|
|
40
|
+
await zipFile(asarOutputPath);
|
|
48
41
|
}
|
|
49
42
|
async function buildVersion({
|
|
50
43
|
asarOutputPath,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-incremental-update",
|
|
3
3
|
"author": "subframe7536",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.1",
|
|
5
5
|
"description": "electron incremental update tools, powered by vite",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsup && node fix-module.js",
|
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
"files": [
|
|
18
18
|
"dist",
|
|
19
19
|
"vite.js",
|
|
20
|
-
"vite.d.ts"
|
|
20
|
+
"vite.d.ts",
|
|
21
|
+
"utils.js",
|
|
22
|
+
"utils.d.ts"
|
|
21
23
|
],
|
|
22
24
|
"main": "dist/index.js",
|
|
23
25
|
"module": "dist/index.mjs",
|
|
@@ -29,6 +31,10 @@
|
|
|
29
31
|
"./vite": {
|
|
30
32
|
"import": "./dist/vite.mjs",
|
|
31
33
|
"require": "./dist/vite.js"
|
|
34
|
+
},
|
|
35
|
+
"./utils": {
|
|
36
|
+
"import": "./dist/utils.mjs",
|
|
37
|
+
"require": "./dist/utils.js"
|
|
32
38
|
}
|
|
33
39
|
},
|
|
34
40
|
"keywords": [
|
package/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/utils'
|
package/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/utils.js')
|