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/dist/index.mjs
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
|
-
__require,
|
|
3
2
|
verify
|
|
4
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-Q2K52LOG.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();
|
|
@@ -187,44 +132,24 @@ function createUpdater({
|
|
|
187
132
|
} = {}
|
|
188
133
|
}) {
|
|
189
134
|
const updater = new EventEmitter();
|
|
190
|
-
let signature
|
|
135
|
+
let signature, version;
|
|
191
136
|
const asarPath = getProductAsarPath(productName);
|
|
192
137
|
const gzipPath = `${asarPath}.gz`;
|
|
193
138
|
const tmpFilePath = gzipPath.replace(".asar.gz", ".tmp.asar");
|
|
194
139
|
function log(msg) {
|
|
195
140
|
debug && updater.emit("debug", msg);
|
|
196
141
|
}
|
|
197
|
-
|
|
198
|
-
if (!
|
|
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
|
-
function needUpdate(version) {
|
|
218
|
-
if (!app2.isPackaged) {
|
|
142
|
+
function needUpdate(version2) {
|
|
143
|
+
if (!app.isPackaged) {
|
|
219
144
|
log("in dev mode, no need to update");
|
|
220
145
|
return false;
|
|
221
146
|
}
|
|
222
147
|
const currentVersion = getEntryVersion();
|
|
223
|
-
log(`check update: current version is ${currentVersion}, new version is ${
|
|
148
|
+
log(`check update: current version is ${currentVersion}, new version is ${version2}`);
|
|
224
149
|
const _compare = compareVersion ?? compareVersionDefault;
|
|
225
|
-
return _compare(currentVersion,
|
|
150
|
+
return _compare(currentVersion, version2);
|
|
226
151
|
}
|
|
227
|
-
async function parseData(format, data) {
|
|
152
|
+
async function parseData(format, data, version2) {
|
|
228
153
|
if (existsSync(tmpFilePath)) {
|
|
229
154
|
log(`remove tmp file: ${tmpFilePath}`);
|
|
230
155
|
await rm(tmpFilePath);
|
|
@@ -255,7 +180,7 @@ function createUpdater({
|
|
|
255
180
|
} : {
|
|
256
181
|
name: "releaseAsarURL",
|
|
257
182
|
url: _release,
|
|
258
|
-
repoFallback: `${repository}/releases/download/
|
|
183
|
+
repoFallback: `${repository}/releases/download/v${version2}/${productName}-${version2}.asar.gz`,
|
|
259
184
|
fn: downloadBuffer ?? downloadBufferDefault
|
|
260
185
|
};
|
|
261
186
|
data ??= info.url;
|
|
@@ -264,11 +189,14 @@ function createUpdater({
|
|
|
264
189
|
if (!repository) {
|
|
265
190
|
throw new Error(`${info.name} or repository are not set`);
|
|
266
191
|
}
|
|
192
|
+
if (format === "buffer" && !version2) {
|
|
193
|
+
throw new Error("version are not set");
|
|
194
|
+
}
|
|
267
195
|
data = info.repoFallback;
|
|
268
196
|
}
|
|
269
197
|
log(`download ${format} from ${data}`);
|
|
270
198
|
const ret = await info.fn(data, updater, headers);
|
|
271
|
-
log(`download ${format} success`);
|
|
199
|
+
log(`download ${format} success${format === "buffer" ? `, file size: ${ret.length}` : ""}`);
|
|
272
200
|
return ret;
|
|
273
201
|
} else {
|
|
274
202
|
throw new Error(`invalid type at format '${format}': ${data}`);
|
|
@@ -277,15 +205,16 @@ function createUpdater({
|
|
|
277
205
|
updater.setDebug = (isDebug) => debug = isDebug;
|
|
278
206
|
updater.checkUpdate = async (data) => {
|
|
279
207
|
try {
|
|
280
|
-
const { signature: _sig, size, version } = await parseData("json", data);
|
|
281
|
-
log(`checked version: ${
|
|
282
|
-
if (!needUpdate(
|
|
283
|
-
log(`update unavailable: ${
|
|
208
|
+
const { signature: _sig, size, version: _ver } = await parseData("json", data);
|
|
209
|
+
log(`checked version: ${_ver}, size: ${size}, signature: ${_sig}`);
|
|
210
|
+
if (!needUpdate(_ver)) {
|
|
211
|
+
log(`update unavailable: ${_ver}`);
|
|
284
212
|
return void 0;
|
|
285
213
|
} else {
|
|
286
|
-
log(`update available: ${
|
|
214
|
+
log(`update available: ${_ver}`);
|
|
287
215
|
signature = _sig;
|
|
288
|
-
|
|
216
|
+
version = _ver;
|
|
217
|
+
return { size, version: _ver };
|
|
289
218
|
}
|
|
290
219
|
} catch (error) {
|
|
291
220
|
log(error);
|
|
@@ -298,29 +227,29 @@ function createUpdater({
|
|
|
298
227
|
if (!_sig) {
|
|
299
228
|
throw new Error("signature are not set, please checkUpdate first or set the second parameter");
|
|
300
229
|
}
|
|
301
|
-
const buffer = await parseData("buffer", data);
|
|
230
|
+
const buffer = await parseData("buffer", data, version);
|
|
302
231
|
log("verify start");
|
|
303
232
|
const _verify = verifySignaure ?? verify;
|
|
304
|
-
const
|
|
305
|
-
if (!
|
|
233
|
+
const _ver = _verify(buffer, _sig, SIGNATURE_CERT);
|
|
234
|
+
if (!_ver) {
|
|
306
235
|
throw new Error("verify failed, invalid signature");
|
|
307
236
|
}
|
|
308
237
|
log("verify success");
|
|
309
|
-
if (!needUpdate(
|
|
310
|
-
throw new Error(`update unavailable: ${
|
|
238
|
+
if (!needUpdate(_ver)) {
|
|
239
|
+
throw new Error(`update unavailable: ${_ver}`);
|
|
311
240
|
}
|
|
312
241
|
log(`write file: ${gzipPath}`);
|
|
313
242
|
await writeFile(gzipPath, buffer);
|
|
314
243
|
log(`extract file: ${gzipPath}`);
|
|
315
|
-
await
|
|
244
|
+
await unzipFile(gzipPath, tmpFilePath);
|
|
316
245
|
const asarVersion = await readFile(resolve(tmpFilePath, "version"), "utf8");
|
|
317
|
-
if (asarVersion !==
|
|
246
|
+
if (asarVersion !== _ver) {
|
|
318
247
|
rmSync(tmpFilePath);
|
|
319
|
-
throw new Error(`update failed: asar version is ${asarVersion}, but it should be ${
|
|
248
|
+
throw new Error(`update failed: asar version is ${asarVersion}, but it should be ${_ver}`);
|
|
320
249
|
} else {
|
|
321
250
|
await rename(tmpFilePath, asarPath);
|
|
322
251
|
}
|
|
323
|
-
log(`update success, version: ${
|
|
252
|
+
log(`update success, version: ${_ver}`);
|
|
324
253
|
signature = "";
|
|
325
254
|
return true;
|
|
326
255
|
} catch (error) {
|
|
@@ -338,7 +267,7 @@ function initApp(appOptions, updaterOptions) {
|
|
|
338
267
|
electronDistPath = "dist-electron",
|
|
339
268
|
mainPath = "main/index.js"
|
|
340
269
|
} = appOptions ?? {};
|
|
341
|
-
const mainDir =
|
|
270
|
+
const mainDir = app2.isPackaged ? `../${productName}.asar` : electronDistPath;
|
|
342
271
|
const entry = resolve2(__dirname, mainDir, mainPath);
|
|
343
272
|
if (updaterOptions) {
|
|
344
273
|
__require(entry)(
|
|
@@ -354,14 +283,5 @@ function initApp(appOptions, updaterOptions) {
|
|
|
354
283
|
}
|
|
355
284
|
export {
|
|
356
285
|
createUpdater,
|
|
357
|
-
|
|
358
|
-
getGithubReleaseCdnGroup,
|
|
359
|
-
getProductAsarPath,
|
|
360
|
-
getProductVersion,
|
|
361
|
-
initApp,
|
|
362
|
-
isUpdateJSON,
|
|
363
|
-
parseGithubCdnURL,
|
|
364
|
-
requireNative,
|
|
365
|
-
restartApp,
|
|
366
|
-
waitAppReady
|
|
286
|
+
initApp
|
|
367
287
|
};
|
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.d.mts
CHANGED
|
@@ -47,6 +47,11 @@ type Options = {
|
|
|
47
47
|
* @default `release/${productName}.asar`
|
|
48
48
|
*/
|
|
49
49
|
asarOutputPath?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Path to gzipped asar file
|
|
52
|
+
* @default `release/${productName}-${version}.asar.gz`
|
|
53
|
+
*/
|
|
54
|
+
gzipPath?: string;
|
|
50
55
|
/**
|
|
51
56
|
* Path to electron build output
|
|
52
57
|
* @default `dist-electron`
|
package/dist/vite.d.ts
CHANGED
|
@@ -47,6 +47,11 @@ type Options = {
|
|
|
47
47
|
* @default `release/${productName}.asar`
|
|
48
48
|
*/
|
|
49
49
|
asarOutputPath?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Path to gzipped asar file
|
|
52
|
+
* @default `release/${productName}-${version}.asar.gz`
|
|
53
|
+
*/
|
|
54
|
+
gzipPath?: string;
|
|
50
55
|
/**
|
|
51
56
|
* Path to electron build output
|
|
52
57
|
* @default `dist-electron`
|