electron-incremental-update 0.5.1 → 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 +13 -12
- package/dist/{chunk-OBERMV66.mjs → chunk-VADH6AZA.mjs} +12 -21
- package/dist/index.cjs +220 -173
- package/dist/index.d.ts +27 -15
- package/dist/index.mjs +204 -150
- package/dist/vite.cjs +72 -49
- package/dist/vite.d.ts +25 -3
- package/dist/vite.mjs +64 -33
- package/package.json +2 -1
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)
|
|
@@ -11,64 +9,61 @@ var __export = (target, all) => {
|
|
|
11
9
|
};
|
|
12
10
|
var __copyProps = (to, from, except, desc) => {
|
|
13
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let
|
|
15
|
-
if (!__hasOwnProp.call(to,
|
|
16
|
-
__defProp(to,
|
|
12
|
+
for (let key2 of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key2) && key2 !== except)
|
|
14
|
+
__defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
|
|
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
|
|
31
21
|
var src_exports = {};
|
|
32
22
|
__export(src_exports, {
|
|
33
23
|
createUpdater: () => createUpdater,
|
|
34
|
-
getAppAsarPath: () => getAppAsarPath,
|
|
35
|
-
getAppVersion: () => getAppVersion,
|
|
36
24
|
getEntryVersion: () => getEntryVersion,
|
|
37
25
|
getGithubReleaseCdnGroup: () => getGithubReleaseCdnGroup,
|
|
26
|
+
getProductAsarPath: () => getProductAsarPath,
|
|
27
|
+
getProductVersion: () => getProductVersion,
|
|
38
28
|
initApp: () => initApp,
|
|
29
|
+
isUpdateJSON: () => isUpdateJSON,
|
|
39
30
|
parseGithubCdnURL: () => parseGithubCdnURL,
|
|
40
31
|
requireNative: () => requireNative,
|
|
41
|
-
restartApp: () => restartApp
|
|
32
|
+
restartApp: () => restartApp,
|
|
33
|
+
waitAppReady: () => waitAppReady
|
|
42
34
|
});
|
|
43
35
|
module.exports = __toCommonJS(src_exports);
|
|
44
|
-
var
|
|
45
|
-
var
|
|
36
|
+
var import_node_path3 = require("path");
|
|
37
|
+
var import_electron4 = require("electron");
|
|
46
38
|
|
|
47
39
|
// src/updater/index.ts
|
|
48
40
|
var import_node_events = require("events");
|
|
41
|
+
var import_node_buffer3 = require("buffer");
|
|
49
42
|
var import_node_zlib = require("zlib");
|
|
50
43
|
var import_node_fs2 = require("fs");
|
|
51
44
|
var import_promises = require("fs/promises");
|
|
52
|
-
var
|
|
45
|
+
var import_node_path2 = require("path");
|
|
46
|
+
var import_electron3 = require("electron");
|
|
53
47
|
|
|
54
48
|
// src/crypto.ts
|
|
55
49
|
var import_node_crypto = require("crypto");
|
|
56
50
|
var import_node_buffer = require("buffer");
|
|
57
51
|
var aesEncode = "base64url";
|
|
58
|
-
function decrypt(encryptedText,
|
|
59
|
-
const decipher = (0, import_node_crypto.createDecipheriv)("aes-256-cbc",
|
|
52
|
+
function decrypt(encryptedText, key2, iv) {
|
|
53
|
+
const decipher = (0, import_node_crypto.createDecipheriv)("aes-256-cbc", key2, iv);
|
|
60
54
|
let decrypted = decipher.update(encryptedText, aesEncode, "utf8");
|
|
61
55
|
decrypted += decipher.final("utf8");
|
|
62
56
|
return decrypted;
|
|
63
57
|
}
|
|
64
|
-
function
|
|
58
|
+
function key(data, length) {
|
|
65
59
|
const hash = (0, import_node_crypto.createHash)("SHA256").update(data).digest("binary");
|
|
66
60
|
return import_node_buffer.Buffer.from(hash).subarray(0, length);
|
|
67
61
|
}
|
|
68
|
-
function verify(buffer, signature,
|
|
62
|
+
function verify(buffer, signature, cert) {
|
|
69
63
|
try {
|
|
70
|
-
const sig = decrypt(signature,
|
|
71
|
-
|
|
64
|
+
const [sig, version] = decrypt(signature, key(cert, 32), key(buffer, 16)).split("%");
|
|
65
|
+
const result = (0, import_node_crypto.createVerify)("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
|
|
66
|
+
return result ? version : false;
|
|
72
67
|
} catch (error) {
|
|
73
68
|
return false;
|
|
74
69
|
}
|
|
@@ -76,19 +71,93 @@ function verify(buffer, signature, publicKey) {
|
|
|
76
71
|
|
|
77
72
|
// src/updater/defaultFunctions.ts
|
|
78
73
|
var import_node_buffer2 = require("buffer");
|
|
79
|
-
var
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
|
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
|
+
|
|
141
|
+
// src/updater/defaultFunctions.ts
|
|
142
|
+
async function downloadJSONDefault(url, updater, headers) {
|
|
143
|
+
await waitAppReady();
|
|
144
|
+
return new Promise((resolve3, reject) => {
|
|
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) => {
|
|
83
154
|
let data = "";
|
|
84
|
-
res.setEncoding("utf8");
|
|
85
|
-
res.headers = headers;
|
|
86
155
|
res.on("data", (chunk) => data += chunk);
|
|
87
156
|
res.on("end", () => {
|
|
88
157
|
try {
|
|
89
158
|
const json = JSON.parse(data);
|
|
90
|
-
if (
|
|
91
|
-
|
|
159
|
+
if (isUpdateJSON(json)) {
|
|
160
|
+
resolve3(json);
|
|
92
161
|
} else {
|
|
93
162
|
throw Error;
|
|
94
163
|
}
|
|
@@ -96,28 +165,39 @@ function downloadJSONDefault(url, updater, headers) {
|
|
|
96
165
|
reject(new Error("invalid json"));
|
|
97
166
|
}
|
|
98
167
|
});
|
|
99
|
-
})
|
|
168
|
+
});
|
|
169
|
+
request.on("error", (e) => {
|
|
100
170
|
reject(e);
|
|
101
171
|
});
|
|
172
|
+
request.end();
|
|
102
173
|
});
|
|
103
174
|
}
|
|
104
|
-
function downloadBufferDefault(url, updater, headers) {
|
|
175
|
+
async function downloadBufferDefault(url, updater, headers) {
|
|
176
|
+
await waitAppReady();
|
|
105
177
|
let progress = 0;
|
|
106
|
-
return new Promise((
|
|
107
|
-
|
|
178
|
+
return new Promise((resolve3, reject) => {
|
|
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) => {
|
|
108
188
|
let data = [];
|
|
109
|
-
res.headers = headers;
|
|
110
189
|
res.on("data", (chunk) => {
|
|
111
190
|
progress += chunk.length;
|
|
112
191
|
updater.emit("downloading", progress);
|
|
113
192
|
data.push(chunk);
|
|
114
193
|
});
|
|
115
194
|
res.on("end", () => {
|
|
116
|
-
|
|
195
|
+
resolve3(import_node_buffer2.Buffer.concat(data));
|
|
117
196
|
});
|
|
118
197
|
}).on("error", (e) => {
|
|
119
198
|
reject(e);
|
|
120
199
|
});
|
|
200
|
+
request.end();
|
|
121
201
|
});
|
|
122
202
|
}
|
|
123
203
|
function compareVersionDefault(oldVersion, newVersion) {
|
|
@@ -143,58 +223,9 @@ function compareVersionDefault(oldVersion, newVersion) {
|
|
|
143
223
|
return false;
|
|
144
224
|
}
|
|
145
225
|
|
|
146
|
-
// src/updater/utils.ts
|
|
147
|
-
var import_node_fs = require("fs");
|
|
148
|
-
var import_node_path = require("path");
|
|
149
|
-
var import_electron = require("electron");
|
|
150
|
-
function getAppAsarPath(name) {
|
|
151
|
-
return import_electron.app.isPackaged ? (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${name}.asar`) : "dev";
|
|
152
|
-
}
|
|
153
|
-
function getEntryVersion() {
|
|
154
|
-
return import_electron.app.getVersion();
|
|
155
|
-
}
|
|
156
|
-
function getAppVersion(name) {
|
|
157
|
-
return import_electron.app.isPackaged ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getAppAsarPath(name), "version"), "utf-8") : getEntryVersion();
|
|
158
|
-
}
|
|
159
|
-
function requireNative(packageName) {
|
|
160
|
-
const path = import_electron.app.isPackaged ? (0, import_node_path.join)(import_electron.app.getAppPath(), "node_modules", packageName) : packageName;
|
|
161
|
-
return require(path);
|
|
162
|
-
}
|
|
163
|
-
function parseGithubCdnURL(repository, cdnPrefix, relativeFilePath) {
|
|
164
|
-
if (!repository.startsWith("https://github.com/")) {
|
|
165
|
-
throw new Error("url must start with https://github.com/");
|
|
166
|
-
}
|
|
167
|
-
repository = repository.trim().replace(/\/?$/, "/").trim();
|
|
168
|
-
relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
|
|
169
|
-
cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
|
|
170
|
-
return repository.replace("github.com", cdnPrefix) + relativeFilePath;
|
|
171
|
-
}
|
|
172
|
-
function getGithubReleaseCdnGroup() {
|
|
173
|
-
return [
|
|
174
|
-
{ cdnPrefix: "gh.gh2233.ml", maintainer: "@X.I.U/XIU2" },
|
|
175
|
-
{ cdnPrefix: "ghproxy.com", maintainer: "gh-proxy" },
|
|
176
|
-
{ cdnPrefix: "gh.ddlc.top", maintainer: "@mtr-static-official" },
|
|
177
|
-
{ cdnPrefix: "ghdl.feizhuqwq.cf", maintainer: "feizhuqwq.com" },
|
|
178
|
-
{ cdnPrefix: "slink.ltd", maintainer: "\u77E5\u4E86\u5C0F\u7AD9" },
|
|
179
|
-
{ cdnPrefix: "git.xfj0.cn", maintainer: "anonymous1" },
|
|
180
|
-
{ cdnPrefix: "gh.con.sh", maintainer: "anonymous2" },
|
|
181
|
-
{ cdnPrefix: "ghps.cc", maintainer: "anonymous3" },
|
|
182
|
-
{ cdnPrefix: "cors.isteed.cc/github.com", maintainer: "Lufs's" },
|
|
183
|
-
{ cdnPrefix: "hub.gitmirror.com", maintainer: "GitMirror" },
|
|
184
|
-
{ cdnPrefix: "js.xxooo.ml", maintainer: "\u996D\u592A\u786C" },
|
|
185
|
-
{ cdnPrefix: "download.njuu.cf", maintainer: "LibraryCloud-njuu" },
|
|
186
|
-
{ cdnPrefix: "download.yzuu.cf", maintainer: "LibraryCloud-yzuu" },
|
|
187
|
-
{ cdnPrefix: "download.nuaa.cf", maintainer: "LibraryCloud-nuaa" }
|
|
188
|
-
];
|
|
189
|
-
}
|
|
190
|
-
function restartApp() {
|
|
191
|
-
import_electron.app.relaunch();
|
|
192
|
-
import_electron.app.quit();
|
|
193
|
-
}
|
|
194
|
-
|
|
195
226
|
// src/updater/index.ts
|
|
196
227
|
function createUpdater({
|
|
197
|
-
|
|
228
|
+
SIGNATURE_CERT,
|
|
198
229
|
repository,
|
|
199
230
|
productName,
|
|
200
231
|
releaseAsarURL: _release,
|
|
@@ -205,94 +236,103 @@ function createUpdater({
|
|
|
205
236
|
}) {
|
|
206
237
|
const updater = new import_node_events.EventEmitter();
|
|
207
238
|
let signature = "";
|
|
208
|
-
|
|
209
|
-
const gzipPath =
|
|
210
|
-
const
|
|
239
|
+
const asarPath = getProductAsarPath(productName);
|
|
240
|
+
const gzipPath = `${asarPath}.gz`;
|
|
241
|
+
const tmpFilePath = gzipPath.replace(".asar.gz", ".tmp.asar");
|
|
211
242
|
const { downloadBuffer, downloadJSON, extraHeader, userAgent } = downloadConfig || {};
|
|
212
243
|
function log(msg) {
|
|
213
244
|
debug && updater.emit("debug", msg);
|
|
214
245
|
}
|
|
215
|
-
async function
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
Accept: `application/${format === "json" ? "json" : "octet-stream"}`,
|
|
219
|
-
UserAgent: ua,
|
|
220
|
-
...extraHeader
|
|
221
|
-
};
|
|
222
|
-
log(`download headers: ${JSON.stringify(headers, null, 2)}`);
|
|
223
|
-
const downloadFn = format === "json" ? downloadJSON ?? downloadJSONDefault : downloadBuffer ?? downloadBufferDefault;
|
|
224
|
-
log(`download ${format} from ${url}`);
|
|
225
|
-
const ret = await downloadFn(url, updater, headers);
|
|
226
|
-
log(`download ${format} success`);
|
|
227
|
-
return ret;
|
|
228
|
-
}
|
|
229
|
-
async function extractFile(gzipFilePath) {
|
|
230
|
-
if (!gzipFilePath.endsWith(".asar.gz") || !(0, import_node_fs2.existsSync)(gzipFilePath)) {
|
|
231
|
-
log("update .asar.gz file not exist");
|
|
232
|
-
return;
|
|
246
|
+
async function extractFile() {
|
|
247
|
+
if (!gzipPath.endsWith(".asar.gz") || !(0, import_node_fs2.existsSync)(gzipPath)) {
|
|
248
|
+
throw new Error(".asar.gz file not exist");
|
|
233
249
|
}
|
|
234
|
-
|
|
235
|
-
return new Promise((resolve2, reject) => {
|
|
250
|
+
return new Promise((resolve3, reject) => {
|
|
236
251
|
const gunzip = (0, import_node_zlib.createGunzip)();
|
|
237
|
-
const input = (0, import_node_fs2.createReadStream)(
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
log(`outputFilePath: ${outputFilePath}`);
|
|
252
|
+
const input = (0, import_node_fs2.createReadStream)(gzipPath);
|
|
253
|
+
const output = (0, import_node_fs2.createWriteStream)(tmpFilePath);
|
|
254
|
+
log(`outputFilePath: ${tmpFilePath}`);
|
|
241
255
|
input.pipe(gunzip).pipe(output).on("finish", async () => {
|
|
242
|
-
await (0, import_promises.rm)(
|
|
243
|
-
log(`${
|
|
244
|
-
|
|
256
|
+
await (0, import_promises.rm)(gzipPath);
|
|
257
|
+
log(`${gzipPath} unzipped`);
|
|
258
|
+
resolve3(null);
|
|
245
259
|
}).on("error", async (err) => {
|
|
246
|
-
await (0, import_promises.rm)(
|
|
260
|
+
await (0, import_promises.rm)(gzipPath);
|
|
247
261
|
output.destroy(err);
|
|
248
262
|
reject(err);
|
|
249
263
|
});
|
|
250
264
|
});
|
|
251
265
|
}
|
|
252
|
-
function needUpdate(
|
|
253
|
-
if (!
|
|
266
|
+
function needUpdate(version) {
|
|
267
|
+
if (!import_electron3.app.isPackaged) {
|
|
254
268
|
log("in dev mode, no need to update");
|
|
255
269
|
return false;
|
|
256
270
|
}
|
|
257
271
|
const currentVersion = getEntryVersion();
|
|
258
|
-
log(`check update:
|
|
259
|
-
current version is ${currentVersion},
|
|
260
|
-
new version is ${version2}`);
|
|
272
|
+
log(`check update: current version is ${currentVersion}, new version is ${version}`);
|
|
261
273
|
const _compare = compareVersion ?? compareVersionDefault;
|
|
262
|
-
return _compare(currentVersion,
|
|
274
|
+
return _compare(currentVersion, version);
|
|
263
275
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
276
|
+
async function parseData(format, data) {
|
|
277
|
+
if ((0, import_node_fs2.existsSync)(tmpFilePath)) {
|
|
278
|
+
log(`remove tmp file: ${tmpFilePath}`);
|
|
279
|
+
await (0, import_promises.rm)(tmpFilePath);
|
|
280
|
+
}
|
|
281
|
+
if ((0, import_node_fs2.existsSync)(gzipPath)) {
|
|
282
|
+
log(`remove .gz file: ${gzipPath}`);
|
|
283
|
+
await (0, import_promises.rm)(gzipPath);
|
|
284
|
+
}
|
|
285
|
+
if (typeof data === "object") {
|
|
286
|
+
if (format === "json" && isUpdateJSON(data) || format === "buffer" && import_node_buffer3.Buffer.isBuffer(data)) {
|
|
287
|
+
return data;
|
|
288
|
+
} else {
|
|
289
|
+
throw new Error(`invalid type at format '${format}': ${data}`);
|
|
290
|
+
}
|
|
291
|
+
} else if (["string", "undefined"].includes(typeof data)) {
|
|
292
|
+
const ua = userAgent || "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36";
|
|
293
|
+
const headers = {
|
|
294
|
+
Accept: `application/${format === "json" ? "json" : "octet-stream"}`,
|
|
295
|
+
UserAgent: ua,
|
|
296
|
+
...extraHeader
|
|
297
|
+
};
|
|
298
|
+
log(`download headers: ${JSON.stringify(headers, null, 2)}`);
|
|
299
|
+
const info = format === "json" ? {
|
|
300
|
+
name: "updateJsonURL",
|
|
301
|
+
url: _update,
|
|
302
|
+
repoFallback: `${repository.replace("github.com", "raw.githubusercontent.com")}/master/version.json`,
|
|
303
|
+
fn: downloadJSON ?? downloadJSONDefault
|
|
304
|
+
} : {
|
|
305
|
+
name: "releaseAsarURL",
|
|
306
|
+
url: _release,
|
|
307
|
+
repoFallback: `${repository}/releases/download/latest/${productName}.asar.gz`,
|
|
308
|
+
fn: downloadBuffer ?? downloadBufferDefault
|
|
309
|
+
};
|
|
310
|
+
data ??= info.url;
|
|
311
|
+
if (!data) {
|
|
312
|
+
log(`no ${info.name}, fallback to use repository`);
|
|
269
313
|
if (!repository) {
|
|
270
|
-
throw new Error(
|
|
314
|
+
throw new Error(`${info.name} or repository are not set`);
|
|
271
315
|
}
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
if ((0, import_node_fs2.existsSync)(tmpFile)) {
|
|
275
|
-
log(`remove tmp file: ${tmpFile}`);
|
|
276
|
-
await (0, import_promises.rm)(tmpFile);
|
|
277
|
-
}
|
|
278
|
-
if ((0, import_node_fs2.existsSync)(gzipPath)) {
|
|
279
|
-
log(`remove .gz file: ${gzipPath}`);
|
|
280
|
-
await (0, import_promises.rm)(gzipPath);
|
|
316
|
+
data = info.repoFallback;
|
|
281
317
|
}
|
|
282
|
-
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
318
|
+
log(`download ${format} from ${data}`);
|
|
319
|
+
const ret = await info.fn(data, updater, headers);
|
|
320
|
+
log(`download ${format} success`);
|
|
321
|
+
return ret;
|
|
322
|
+
} else {
|
|
323
|
+
throw new Error(`invalid type at format '${format}': ${data}`);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
updater.checkUpdate = async (data) => {
|
|
327
|
+
try {
|
|
328
|
+
const { signature: _sig, size, version } = await parseData("json", data);
|
|
329
|
+
log(`checked version: ${version}, size: ${size}, signature: ${_sig}`);
|
|
330
|
+
if (!needUpdate(version)) {
|
|
331
|
+
log(`update unavailable: ${version}`);
|
|
291
332
|
return void 0;
|
|
292
333
|
} else {
|
|
293
|
-
log(`update available: ${
|
|
334
|
+
log(`update available: ${version}`);
|
|
294
335
|
signature = _sig;
|
|
295
|
-
version = _v;
|
|
296
336
|
return { size, version };
|
|
297
337
|
}
|
|
298
338
|
} catch (error) {
|
|
@@ -300,30 +340,35 @@ function createUpdater({
|
|
|
300
340
|
return error;
|
|
301
341
|
}
|
|
302
342
|
};
|
|
303
|
-
updater.
|
|
343
|
+
updater.downloadAndInstall = async (data, sig) => {
|
|
304
344
|
try {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
log("no releaseAsarURL, fallback to use repository");
|
|
309
|
-
if (!repository) {
|
|
310
|
-
throw new Error("releaseAsarURL or repository are not set");
|
|
311
|
-
}
|
|
312
|
-
_url = `${repository}/releases/download/latest/${productName}.asar.gz`;
|
|
313
|
-
}
|
|
314
|
-
src = await download(_url, "buffer");
|
|
345
|
+
const _sig = sig ?? signature;
|
|
346
|
+
if (!_sig) {
|
|
347
|
+
throw new Error("signature are not set, please checkUpdate first or set the second parameter");
|
|
315
348
|
}
|
|
349
|
+
const buffer = await parseData("buffer", data);
|
|
316
350
|
log("verify start");
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
throw new Error("invalid signature");
|
|
351
|
+
const version = verify(buffer, _sig, SIGNATURE_CERT);
|
|
352
|
+
if (!version) {
|
|
353
|
+
throw new Error("verify failed, invalid signature");
|
|
320
354
|
}
|
|
321
355
|
log("verify success");
|
|
356
|
+
if (!needUpdate(version)) {
|
|
357
|
+
throw new Error(`update unavailable: ${version}`);
|
|
358
|
+
}
|
|
322
359
|
log(`write file: ${gzipPath}`);
|
|
323
|
-
await (0, import_promises.writeFile)(gzipPath,
|
|
360
|
+
await (0, import_promises.writeFile)(gzipPath, buffer);
|
|
324
361
|
log(`extract file: ${gzipPath}`);
|
|
325
|
-
await extractFile(
|
|
362
|
+
await extractFile();
|
|
363
|
+
const asarVersion = await (0, import_promises.readFile)((0, import_node_path2.resolve)(tmpFilePath, "version"), "utf8");
|
|
364
|
+
if (asarVersion !== version) {
|
|
365
|
+
(0, import_node_fs2.rmSync)(tmpFilePath);
|
|
366
|
+
throw new Error(`update failed: asar version is ${asarVersion}, but it should be ${version}`);
|
|
367
|
+
} else {
|
|
368
|
+
await (0, import_promises.rename)(tmpFilePath, asarPath);
|
|
369
|
+
}
|
|
326
370
|
log(`update success, version: ${version}`);
|
|
371
|
+
signature = "";
|
|
327
372
|
return true;
|
|
328
373
|
} catch (error) {
|
|
329
374
|
log(error);
|
|
@@ -340,8 +385,8 @@ function initApp(appOptions, updaterOptions) {
|
|
|
340
385
|
electronDistPath = "dist-electron",
|
|
341
386
|
mainPath = "main/index.js"
|
|
342
387
|
} = appOptions ?? {};
|
|
343
|
-
const mainDir =
|
|
344
|
-
const entry = (0,
|
|
388
|
+
const mainDir = import_electron4.app.isPackaged ? `../${productName}.asar` : electronDistPath;
|
|
389
|
+
const entry = (0, import_node_path3.resolve)(__dirname, mainDir, mainPath);
|
|
345
390
|
if (updaterOptions) {
|
|
346
391
|
require(entry)(
|
|
347
392
|
createUpdater({ ...updaterOptions, productName })
|
|
@@ -357,12 +402,14 @@ function initApp(appOptions, updaterOptions) {
|
|
|
357
402
|
// Annotate the CommonJS export names for ESM import in node:
|
|
358
403
|
0 && (module.exports = {
|
|
359
404
|
createUpdater,
|
|
360
|
-
getAppAsarPath,
|
|
361
|
-
getAppVersion,
|
|
362
405
|
getEntryVersion,
|
|
363
406
|
getGithubReleaseCdnGroup,
|
|
407
|
+
getProductAsarPath,
|
|
408
|
+
getProductVersion,
|
|
364
409
|
initApp,
|
|
410
|
+
isUpdateJSON,
|
|
365
411
|
parseGithubCdnURL,
|
|
366
412
|
requireNative,
|
|
367
|
-
restartApp
|
|
413
|
+
restartApp,
|
|
414
|
+
waitAppReady
|
|
368
415
|
});
|