electron-incremental-update 0.6.0 → 0.6.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 +6 -5
- package/dist/index.cjs +98 -77
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +92 -62
- package/dist/vite.cjs +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.mjs +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -76,7 +76,11 @@ const updater = createUpdater({
|
|
|
76
76
|
initApp({ name }).setUpdater(updater)
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
###
|
|
79
|
+
### usage in main process
|
|
80
|
+
|
|
81
|
+
To utilize the electron `net` module for requesting update information, the `checkUpdate` and `downloadAndInstall` functions must be called after the app is ready by default.
|
|
82
|
+
|
|
83
|
+
However, you have the option to customize the download function when creating the updater.
|
|
80
84
|
|
|
81
85
|
```ts
|
|
82
86
|
// electron/main/index.ts
|
|
@@ -86,6 +90,7 @@ import { app } from 'electron'
|
|
|
86
90
|
import { name } from '../../package.json'
|
|
87
91
|
|
|
88
92
|
export default function (updater: Updater) {
|
|
93
|
+
await app.whenReady()
|
|
89
94
|
console.log('\ncurrent:')
|
|
90
95
|
console.log(`\tasar path: ${getProductAsarPath(name)}`)
|
|
91
96
|
console.log(`\tentry: ${getEntryVersion()}`)
|
|
@@ -111,10 +116,6 @@ export default function (updater: Updater) {
|
|
|
111
116
|
response === 0 && console.log(await updater.downloadAndInstall())
|
|
112
117
|
}
|
|
113
118
|
})
|
|
114
|
-
// app logics
|
|
115
|
-
app.whenReady().then(() => {
|
|
116
|
-
// ...
|
|
117
|
-
})
|
|
118
119
|
}
|
|
119
120
|
```
|
|
120
121
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
@@ -39,11 +29,12 @@ __export(src_exports, {
|
|
|
39
29
|
isUpdateJSON: () => isUpdateJSON,
|
|
40
30
|
parseGithubCdnURL: () => parseGithubCdnURL,
|
|
41
31
|
requireNative: () => requireNative,
|
|
42
|
-
restartApp: () => restartApp
|
|
32
|
+
restartApp: () => restartApp,
|
|
33
|
+
waitAppReady: () => waitAppReady
|
|
43
34
|
});
|
|
44
35
|
module.exports = __toCommonJS(src_exports);
|
|
45
36
|
var import_node_path3 = require("path");
|
|
46
|
-
var
|
|
37
|
+
var import_electron4 = require("electron");
|
|
47
38
|
|
|
48
39
|
// src/updater/index.ts
|
|
49
40
|
var import_node_events = require("events");
|
|
@@ -52,7 +43,7 @@ var import_node_zlib = require("zlib");
|
|
|
52
43
|
var import_node_fs2 = require("fs");
|
|
53
44
|
var import_promises = require("fs/promises");
|
|
54
45
|
var import_node_path2 = require("path");
|
|
55
|
-
var
|
|
46
|
+
var import_electron3 = require("electron");
|
|
56
47
|
|
|
57
48
|
// src/crypto.ts
|
|
58
49
|
var import_node_crypto = require("crypto");
|
|
@@ -80,20 +71,87 @@ function verify(buffer, signature, cert) {
|
|
|
80
71
|
|
|
81
72
|
// src/updater/defaultFunctions.ts
|
|
82
73
|
var import_node_buffer2 = require("buffer");
|
|
83
|
-
var
|
|
74
|
+
var import_electron2 = require("electron");
|
|
84
75
|
|
|
85
76
|
// src/updater/types.ts
|
|
86
77
|
function isUpdateJSON(json) {
|
|
87
78
|
return "signature" in json && "version" in json && "size" in json;
|
|
88
79
|
}
|
|
89
80
|
|
|
81
|
+
// src/updater/utils.ts
|
|
82
|
+
var import_node_fs = require("fs");
|
|
83
|
+
var import_node_path = require("path");
|
|
84
|
+
var import_electron = require("electron");
|
|
85
|
+
function getProductAsarPath(name) {
|
|
86
|
+
return import_electron.app.isPackaged ? (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${name}.asar`) : "dev";
|
|
87
|
+
}
|
|
88
|
+
function getEntryVersion() {
|
|
89
|
+
return import_electron.app.getVersion();
|
|
90
|
+
}
|
|
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
|
+
function waitAppReady(duration = 1e3) {
|
|
130
|
+
return new Promise((resolve3, reject) => {
|
|
131
|
+
const timeout = setTimeout(() => {
|
|
132
|
+
reject(new Error("app is not ready"));
|
|
133
|
+
}, duration);
|
|
134
|
+
import_electron.app.whenReady().then(() => {
|
|
135
|
+
clearTimeout(timeout);
|
|
136
|
+
resolve3(null);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
90
141
|
// src/updater/defaultFunctions.ts
|
|
91
|
-
function downloadJSONDefault(url, updater, headers) {
|
|
142
|
+
async function downloadJSONDefault(url, updater, headers) {
|
|
143
|
+
await waitAppReady();
|
|
92
144
|
return new Promise((resolve3, reject) => {
|
|
93
|
-
|
|
145
|
+
const request = import_electron2.net.request({
|
|
146
|
+
url,
|
|
147
|
+
method: "GET",
|
|
148
|
+
redirect: "follow"
|
|
149
|
+
});
|
|
150
|
+
Object.keys(headers).forEach((key2) => {
|
|
151
|
+
request.setHeader(key2, headers[key2]);
|
|
152
|
+
});
|
|
153
|
+
request.on("response", (res) => {
|
|
94
154
|
let data = "";
|
|
95
|
-
res.setEncoding("utf8");
|
|
96
|
-
res.headers = headers;
|
|
97
155
|
res.on("data", (chunk) => data += chunk);
|
|
98
156
|
res.on("end", () => {
|
|
99
157
|
try {
|
|
@@ -107,17 +165,27 @@ function downloadJSONDefault(url, updater, headers) {
|
|
|
107
165
|
reject(new Error("invalid json"));
|
|
108
166
|
}
|
|
109
167
|
});
|
|
110
|
-
})
|
|
168
|
+
});
|
|
169
|
+
request.on("error", (e) => {
|
|
111
170
|
reject(e);
|
|
112
171
|
});
|
|
172
|
+
request.end();
|
|
113
173
|
});
|
|
114
174
|
}
|
|
115
|
-
function downloadBufferDefault(url, updater, headers) {
|
|
175
|
+
async function downloadBufferDefault(url, updater, headers) {
|
|
176
|
+
await waitAppReady();
|
|
116
177
|
let progress = 0;
|
|
117
178
|
return new Promise((resolve3, reject) => {
|
|
118
|
-
|
|
179
|
+
const request = import_electron2.net.request({
|
|
180
|
+
url,
|
|
181
|
+
method: "GET",
|
|
182
|
+
redirect: "follow"
|
|
183
|
+
});
|
|
184
|
+
Object.keys(headers).forEach((key2) => {
|
|
185
|
+
request.setHeader(key2, headers[key2]);
|
|
186
|
+
});
|
|
187
|
+
request.on("response", (res) => {
|
|
119
188
|
let data = [];
|
|
120
|
-
res.headers = headers;
|
|
121
189
|
res.on("data", (chunk) => {
|
|
122
190
|
progress += chunk.length;
|
|
123
191
|
updater.emit("downloading", progress);
|
|
@@ -129,6 +197,7 @@ function downloadBufferDefault(url, updater, headers) {
|
|
|
129
197
|
}).on("error", (e) => {
|
|
130
198
|
reject(e);
|
|
131
199
|
});
|
|
200
|
+
request.end();
|
|
132
201
|
});
|
|
133
202
|
}
|
|
134
203
|
function compareVersionDefault(oldVersion, newVersion) {
|
|
@@ -154,55 +223,6 @@ function compareVersionDefault(oldVersion, newVersion) {
|
|
|
154
223
|
return false;
|
|
155
224
|
}
|
|
156
225
|
|
|
157
|
-
// src/updater/utils.ts
|
|
158
|
-
var import_node_fs = require("fs");
|
|
159
|
-
var import_node_path = require("path");
|
|
160
|
-
var import_electron = require("electron");
|
|
161
|
-
function getProductAsarPath(name) {
|
|
162
|
-
return import_electron.app.isPackaged ? (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${name}.asar`) : "dev";
|
|
163
|
-
}
|
|
164
|
-
function getEntryVersion() {
|
|
165
|
-
return import_electron.app.getVersion();
|
|
166
|
-
}
|
|
167
|
-
function getProductVersion(name) {
|
|
168
|
-
return import_electron.app.isPackaged ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8") : getEntryVersion();
|
|
169
|
-
}
|
|
170
|
-
function requireNative(packageName) {
|
|
171
|
-
const path = import_electron.app.isPackaged ? (0, import_node_path.join)(import_electron.app.getAppPath(), "node_modules", packageName) : packageName;
|
|
172
|
-
return require(path);
|
|
173
|
-
}
|
|
174
|
-
function parseGithubCdnURL(repository, cdnPrefix, relativeFilePath) {
|
|
175
|
-
if (!repository.startsWith("https://github.com/")) {
|
|
176
|
-
throw new Error("url must start with https://github.com/");
|
|
177
|
-
}
|
|
178
|
-
repository = repository.trim().replace(/\/?$/, "/").trim();
|
|
179
|
-
relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
|
|
180
|
-
cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
|
|
181
|
-
return repository.replace("github.com", cdnPrefix) + relativeFilePath;
|
|
182
|
-
}
|
|
183
|
-
function getGithubReleaseCdnGroup() {
|
|
184
|
-
return [
|
|
185
|
-
{ cdnPrefix: "gh.gh2233.ml", maintainer: "@X.I.U/XIU2" },
|
|
186
|
-
{ cdnPrefix: "ghproxy.com", maintainer: "gh-proxy" },
|
|
187
|
-
{ cdnPrefix: "gh.ddlc.top", maintainer: "@mtr-static-official" },
|
|
188
|
-
{ cdnPrefix: "ghdl.feizhuqwq.cf", maintainer: "feizhuqwq.com" },
|
|
189
|
-
{ cdnPrefix: "slink.ltd", maintainer: "\u77E5\u4E86\u5C0F\u7AD9" },
|
|
190
|
-
{ cdnPrefix: "git.xfj0.cn", maintainer: "anonymous1" },
|
|
191
|
-
{ cdnPrefix: "gh.con.sh", maintainer: "anonymous2" },
|
|
192
|
-
{ cdnPrefix: "ghps.cc", maintainer: "anonymous3" },
|
|
193
|
-
{ cdnPrefix: "cors.isteed.cc/github.com", maintainer: "Lufs's" },
|
|
194
|
-
{ cdnPrefix: "hub.gitmirror.com", maintainer: "GitMirror" },
|
|
195
|
-
{ cdnPrefix: "js.xxooo.ml", maintainer: "\u996D\u592A\u786C" },
|
|
196
|
-
{ cdnPrefix: "download.njuu.cf", maintainer: "LibraryCloud-njuu" },
|
|
197
|
-
{ cdnPrefix: "download.yzuu.cf", maintainer: "LibraryCloud-yzuu" },
|
|
198
|
-
{ cdnPrefix: "download.nuaa.cf", maintainer: "LibraryCloud-nuaa" }
|
|
199
|
-
];
|
|
200
|
-
}
|
|
201
|
-
function restartApp() {
|
|
202
|
-
import_electron.app.relaunch();
|
|
203
|
-
import_electron.app.quit();
|
|
204
|
-
}
|
|
205
|
-
|
|
206
226
|
// src/updater/index.ts
|
|
207
227
|
function createUpdater({
|
|
208
228
|
SIGNATURE_CERT,
|
|
@@ -244,7 +264,7 @@ function createUpdater({
|
|
|
244
264
|
});
|
|
245
265
|
}
|
|
246
266
|
function needUpdate(version) {
|
|
247
|
-
if (!
|
|
267
|
+
if (!import_electron3.app.isPackaged) {
|
|
248
268
|
log("in dev mode, no need to update");
|
|
249
269
|
return false;
|
|
250
270
|
}
|
|
@@ -306,8 +326,8 @@ function createUpdater({
|
|
|
306
326
|
updater.checkUpdate = async (data) => {
|
|
307
327
|
try {
|
|
308
328
|
const { signature: _sig, size, version } = await parseData("json", data);
|
|
309
|
-
log(`checked version: ${version}, size: ${size}`);
|
|
310
|
-
if (!
|
|
329
|
+
log(`checked version: ${version}, size: ${size}, signature: ${_sig}`);
|
|
330
|
+
if (!needUpdate(version)) {
|
|
311
331
|
log(`update unavailable: ${version}`);
|
|
312
332
|
return void 0;
|
|
313
333
|
} else {
|
|
@@ -333,7 +353,7 @@ function createUpdater({
|
|
|
333
353
|
throw new Error("verify failed, invalid signature");
|
|
334
354
|
}
|
|
335
355
|
log("verify success");
|
|
336
|
-
if (!
|
|
356
|
+
if (!needUpdate(version)) {
|
|
337
357
|
throw new Error(`update unavailable: ${version}`);
|
|
338
358
|
}
|
|
339
359
|
log(`write file: ${gzipPath}`);
|
|
@@ -365,7 +385,7 @@ function initApp(appOptions, updaterOptions) {
|
|
|
365
385
|
electronDistPath = "dist-electron",
|
|
366
386
|
mainPath = "main/index.js"
|
|
367
387
|
} = appOptions ?? {};
|
|
368
|
-
const mainDir =
|
|
388
|
+
const mainDir = import_electron4.app.isPackaged ? `../${productName}.asar` : electronDistPath;
|
|
369
389
|
const entry = (0, import_node_path3.resolve)(__dirname, mainDir, mainPath);
|
|
370
390
|
if (updaterOptions) {
|
|
371
391
|
require(entry)(
|
|
@@ -390,5 +410,6 @@ function initApp(appOptions, updaterOptions) {
|
|
|
390
410
|
isUpdateJSON,
|
|
391
411
|
parseGithubCdnURL,
|
|
392
412
|
requireNative,
|
|
393
|
-
restartApp
|
|
413
|
+
restartApp,
|
|
414
|
+
waitAppReady
|
|
394
415
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -158,6 +158,7 @@ declare function getGithubReleaseCdnGroup(): {
|
|
|
158
158
|
maintainer: string;
|
|
159
159
|
}[];
|
|
160
160
|
declare function restartApp(): void;
|
|
161
|
+
declare function waitAppReady(duration?: number): Promise<unknown>;
|
|
161
162
|
|
|
162
163
|
declare function createUpdater({ SIGNATURE_CERT, repository, productName, releaseAsarURL: _release, updateJsonURL: _update, debug, downloadConfig, compareVersion, }: UpdaterOption): Updater;
|
|
163
164
|
|
|
@@ -220,4 +221,4 @@ declare function initApp(appOptions: AppOption): {
|
|
|
220
221
|
*/
|
|
221
222
|
declare function initApp(appOptions: AppOption, updaterOptions: InitUpdaterOptions): undefined;
|
|
222
223
|
|
|
223
|
-
export { AppOption, CheckResultType, InitUpdaterOptions, InstallResult, UpdateJSON, Updater, UpdaterOption, createUpdater, getEntryVersion, getGithubReleaseCdnGroup, getProductAsarPath, getProductVersion, initApp, isUpdateJSON, parseGithubCdnURL, requireNative, restartApp };
|
|
224
|
+
export { AppOption, CheckResultType, InitUpdaterOptions, InstallResult, UpdateJSON, Updater, UpdaterOption, createUpdater, getEntryVersion, getGithubReleaseCdnGroup, getProductAsarPath, getProductVersion, initApp, isUpdateJSON, parseGithubCdnURL, requireNative, restartApp, waitAppReady };
|
package/dist/index.mjs
CHANGED
|
@@ -18,20 +18,87 @@ import { app as app2 } from "electron";
|
|
|
18
18
|
|
|
19
19
|
// src/updater/defaultFunctions.ts
|
|
20
20
|
import { Buffer } from "node:buffer";
|
|
21
|
-
import
|
|
21
|
+
import { net } from "electron";
|
|
22
22
|
|
|
23
23
|
// src/updater/types.ts
|
|
24
24
|
function isUpdateJSON(json) {
|
|
25
25
|
return "signature" in json && "version" in json && "size" in json;
|
|
26
26
|
}
|
|
27
27
|
|
|
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
|
+
|
|
28
88
|
// src/updater/defaultFunctions.ts
|
|
29
|
-
function downloadJSONDefault(url, updater, headers) {
|
|
89
|
+
async function downloadJSONDefault(url, updater, headers) {
|
|
90
|
+
await waitAppReady();
|
|
30
91
|
return new Promise((resolve3, reject) => {
|
|
31
|
-
|
|
92
|
+
const request = net.request({
|
|
93
|
+
url,
|
|
94
|
+
method: "GET",
|
|
95
|
+
redirect: "follow"
|
|
96
|
+
});
|
|
97
|
+
Object.keys(headers).forEach((key) => {
|
|
98
|
+
request.setHeader(key, headers[key]);
|
|
99
|
+
});
|
|
100
|
+
request.on("response", (res) => {
|
|
32
101
|
let data = "";
|
|
33
|
-
res.setEncoding("utf8");
|
|
34
|
-
res.headers = headers;
|
|
35
102
|
res.on("data", (chunk) => data += chunk);
|
|
36
103
|
res.on("end", () => {
|
|
37
104
|
try {
|
|
@@ -45,17 +112,27 @@ function downloadJSONDefault(url, updater, headers) {
|
|
|
45
112
|
reject(new Error("invalid json"));
|
|
46
113
|
}
|
|
47
114
|
});
|
|
48
|
-
})
|
|
115
|
+
});
|
|
116
|
+
request.on("error", (e) => {
|
|
49
117
|
reject(e);
|
|
50
118
|
});
|
|
119
|
+
request.end();
|
|
51
120
|
});
|
|
52
121
|
}
|
|
53
|
-
function downloadBufferDefault(url, updater, headers) {
|
|
122
|
+
async function downloadBufferDefault(url, updater, headers) {
|
|
123
|
+
await waitAppReady();
|
|
54
124
|
let progress = 0;
|
|
55
125
|
return new Promise((resolve3, reject) => {
|
|
56
|
-
|
|
126
|
+
const request = net.request({
|
|
127
|
+
url,
|
|
128
|
+
method: "GET",
|
|
129
|
+
redirect: "follow"
|
|
130
|
+
});
|
|
131
|
+
Object.keys(headers).forEach((key) => {
|
|
132
|
+
request.setHeader(key, headers[key]);
|
|
133
|
+
});
|
|
134
|
+
request.on("response", (res) => {
|
|
57
135
|
let data = [];
|
|
58
|
-
res.headers = headers;
|
|
59
136
|
res.on("data", (chunk) => {
|
|
60
137
|
progress += chunk.length;
|
|
61
138
|
updater.emit("downloading", progress);
|
|
@@ -67,6 +144,7 @@ function downloadBufferDefault(url, updater, headers) {
|
|
|
67
144
|
}).on("error", (e) => {
|
|
68
145
|
reject(e);
|
|
69
146
|
});
|
|
147
|
+
request.end();
|
|
70
148
|
});
|
|
71
149
|
}
|
|
72
150
|
function compareVersionDefault(oldVersion, newVersion) {
|
|
@@ -92,55 +170,6 @@ function compareVersionDefault(oldVersion, newVersion) {
|
|
|
92
170
|
return false;
|
|
93
171
|
}
|
|
94
172
|
|
|
95
|
-
// src/updater/utils.ts
|
|
96
|
-
import { readFileSync } from "node:fs";
|
|
97
|
-
import { dirname, join } from "node:path";
|
|
98
|
-
import { app } from "electron";
|
|
99
|
-
function getProductAsarPath(name) {
|
|
100
|
-
return app.isPackaged ? join(dirname(app.getAppPath()), `${name}.asar`) : "dev";
|
|
101
|
-
}
|
|
102
|
-
function getEntryVersion() {
|
|
103
|
-
return app.getVersion();
|
|
104
|
-
}
|
|
105
|
-
function getProductVersion(name) {
|
|
106
|
-
return app.isPackaged ? readFileSync(join(getProductAsarPath(name), "version"), "utf-8") : getEntryVersion();
|
|
107
|
-
}
|
|
108
|
-
function requireNative(packageName) {
|
|
109
|
-
const path = app.isPackaged ? join(app.getAppPath(), "node_modules", packageName) : packageName;
|
|
110
|
-
return __require(path);
|
|
111
|
-
}
|
|
112
|
-
function parseGithubCdnURL(repository, cdnPrefix, relativeFilePath) {
|
|
113
|
-
if (!repository.startsWith("https://github.com/")) {
|
|
114
|
-
throw new Error("url must start with https://github.com/");
|
|
115
|
-
}
|
|
116
|
-
repository = repository.trim().replace(/\/?$/, "/").trim();
|
|
117
|
-
relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
|
|
118
|
-
cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
|
|
119
|
-
return repository.replace("github.com", cdnPrefix) + relativeFilePath;
|
|
120
|
-
}
|
|
121
|
-
function getGithubReleaseCdnGroup() {
|
|
122
|
-
return [
|
|
123
|
-
{ cdnPrefix: "gh.gh2233.ml", maintainer: "@X.I.U/XIU2" },
|
|
124
|
-
{ cdnPrefix: "ghproxy.com", maintainer: "gh-proxy" },
|
|
125
|
-
{ cdnPrefix: "gh.ddlc.top", maintainer: "@mtr-static-official" },
|
|
126
|
-
{ cdnPrefix: "ghdl.feizhuqwq.cf", maintainer: "feizhuqwq.com" },
|
|
127
|
-
{ cdnPrefix: "slink.ltd", maintainer: "\u77E5\u4E86\u5C0F\u7AD9" },
|
|
128
|
-
{ cdnPrefix: "git.xfj0.cn", maintainer: "anonymous1" },
|
|
129
|
-
{ cdnPrefix: "gh.con.sh", maintainer: "anonymous2" },
|
|
130
|
-
{ cdnPrefix: "ghps.cc", maintainer: "anonymous3" },
|
|
131
|
-
{ cdnPrefix: "cors.isteed.cc/github.com", maintainer: "Lufs's" },
|
|
132
|
-
{ cdnPrefix: "hub.gitmirror.com", maintainer: "GitMirror" },
|
|
133
|
-
{ cdnPrefix: "js.xxooo.ml", maintainer: "\u996D\u592A\u786C" },
|
|
134
|
-
{ cdnPrefix: "download.njuu.cf", maintainer: "LibraryCloud-njuu" },
|
|
135
|
-
{ cdnPrefix: "download.yzuu.cf", maintainer: "LibraryCloud-yzuu" },
|
|
136
|
-
{ cdnPrefix: "download.nuaa.cf", maintainer: "LibraryCloud-nuaa" }
|
|
137
|
-
];
|
|
138
|
-
}
|
|
139
|
-
function restartApp() {
|
|
140
|
-
app.relaunch();
|
|
141
|
-
app.quit();
|
|
142
|
-
}
|
|
143
|
-
|
|
144
173
|
// src/updater/index.ts
|
|
145
174
|
function createUpdater({
|
|
146
175
|
SIGNATURE_CERT,
|
|
@@ -244,8 +273,8 @@ function createUpdater({
|
|
|
244
273
|
updater.checkUpdate = async (data) => {
|
|
245
274
|
try {
|
|
246
275
|
const { signature: _sig, size, version } = await parseData("json", data);
|
|
247
|
-
log(`checked version: ${version}, size: ${size}`);
|
|
248
|
-
if (!
|
|
276
|
+
log(`checked version: ${version}, size: ${size}, signature: ${_sig}`);
|
|
277
|
+
if (!needUpdate(version)) {
|
|
249
278
|
log(`update unavailable: ${version}`);
|
|
250
279
|
return void 0;
|
|
251
280
|
} else {
|
|
@@ -271,7 +300,7 @@ function createUpdater({
|
|
|
271
300
|
throw new Error("verify failed, invalid signature");
|
|
272
301
|
}
|
|
273
302
|
log("verify success");
|
|
274
|
-
if (!
|
|
303
|
+
if (!needUpdate(version)) {
|
|
275
304
|
throw new Error(`update unavailable: ${version}`);
|
|
276
305
|
}
|
|
277
306
|
log(`write file: ${gzipPath}`);
|
|
@@ -327,5 +356,6 @@ export {
|
|
|
327
356
|
isUpdateJSON,
|
|
328
357
|
parseGithubCdnURL,
|
|
329
358
|
requireNative,
|
|
330
|
-
restartApp
|
|
359
|
+
restartApp,
|
|
360
|
+
waitAppReady
|
|
331
361
|
};
|
package/dist/vite.cjs
CHANGED
|
@@ -217,7 +217,7 @@ function parseOptions(options) {
|
|
|
217
217
|
const {
|
|
218
218
|
entryPath = "electron/app.ts",
|
|
219
219
|
entryOutputPath = "app.js",
|
|
220
|
-
asarOutputPath = `release/${productName}.asar`,
|
|
220
|
+
asarOutputPath = `release/${productName}-${version}.asar`,
|
|
221
221
|
electronDistPath = "dist-electron",
|
|
222
222
|
rendererDistPath = "dist",
|
|
223
223
|
versionPath = "version.json"
|
package/dist/vite.d.ts
CHANGED
package/dist/vite.mjs
CHANGED
|
@@ -162,7 +162,7 @@ function parseOptions(options) {
|
|
|
162
162
|
const {
|
|
163
163
|
entryPath = "electron/app.ts",
|
|
164
164
|
entryOutputPath = "app.js",
|
|
165
|
-
asarOutputPath = `release/${productName}.asar`,
|
|
165
|
+
asarOutputPath = `release/${productName}-${version}.asar`,
|
|
166
166
|
electronDistPath = "dist-electron",
|
|
167
167
|
rendererDistPath = "dist",
|
|
168
168
|
versionPath = "version.json"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-incremental-update",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "electron incremental update tools, powered by vite",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsup",
|
|
@@ -64,4 +64,4 @@
|
|
|
64
64
|
"@cyyynthia/jscert": "^0.1.2",
|
|
65
65
|
"ci-info": "^3.8.0"
|
|
66
66
|
}
|
|
67
|
-
}
|
|
67
|
+
}
|