electron-incremental-update 2.4.2 → 3.0.0-beta.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 +72 -43
- package/dist/download-BN4uMS4_.d.mts +39 -0
- package/dist/download-DO7iuxEJ.d.cts +39 -0
- package/dist/electron-BFoZUBhU.cjs +320 -0
- package/dist/electron-CJIoO4ny.mjs +180 -0
- package/dist/index.cjs +259 -331
- package/dist/index.d.cts +179 -169
- package/dist/index.d.mts +204 -0
- package/dist/index.mjs +271 -0
- package/dist/provider.cjs +142 -356
- package/dist/provider.d.cts +116 -117
- package/dist/provider.d.mts +133 -0
- package/dist/provider.mjs +152 -0
- package/dist/types-BM9Jfu7q.d.cts +154 -0
- package/dist/types-DASqEPXE.d.mts +154 -0
- package/dist/utils.cjs +43 -381
- package/dist/utils.d.cts +117 -85
- package/dist/utils.d.mts +161 -0
- package/dist/utils.mjs +5 -0
- package/dist/version--eVB2A7n.mjs +72 -0
- package/dist/version-aPrLuz_-.cjs +129 -0
- package/dist/vite.d.mts +565 -0
- package/dist/vite.mjs +1222 -0
- package/dist/zip-BCC7FAQ_.cjs +264 -0
- package/dist/zip-Dwm7s1C9.mjs +185 -0
- package/package.json +65 -65
- package/dist/chunk-AAAM44NW.js +0 -70
- package/dist/chunk-IVHNGRZY.js +0 -122
- package/dist/chunk-PD4EV4MM.js +0 -147
- package/dist/index.d.ts +0 -194
- package/dist/index.js +0 -309
- package/dist/provider.d.ts +0 -134
- package/dist/provider.js +0 -178
- package/dist/types-CU7GyVez.d.cts +0 -151
- package/dist/types-CU7GyVez.d.ts +0 -151
- package/dist/utils.d.ts +0 -129
- package/dist/utils.js +0 -3
- package/dist/vite.d.ts +0 -533
- package/dist/vite.js +0 -945
- package/dist/zip-Blmn2vzE.d.cts +0 -71
- package/dist/zip-CnSv_Njj.d.ts +0 -71
- package/provider.d.ts +0 -1
- package/provider.js +0 -1
- package/utils.d.ts +0 -1
- package/utils.js +0 -1
- package/vite.d.ts +0 -1
- package/vite.js +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,350 +1,278 @@
|
|
|
1
|
-
|
|
1
|
+
const require_version = require('./version-aPrLuz_-.cjs');
|
|
2
|
+
const require_electron = require('./electron-BFoZUBhU.cjs');
|
|
3
|
+
let electron = require("electron");
|
|
4
|
+
let node_fs = require("node:fs");
|
|
5
|
+
node_fs = require_version.__toESM(node_fs);
|
|
6
|
+
let node_path = require("node:path");
|
|
7
|
+
node_path = require_version.__toESM(node_path);
|
|
8
|
+
let node_events = require("node:events");
|
|
2
9
|
|
|
3
|
-
|
|
4
|
-
var path2 = require('path');
|
|
5
|
-
var electron = require('electron');
|
|
6
|
-
var events = require('events');
|
|
7
|
-
|
|
8
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
|
|
10
|
-
var fs2__default = /*#__PURE__*/_interopDefault(fs2);
|
|
11
|
-
var path2__default = /*#__PURE__*/_interopDefault(path2);
|
|
12
|
-
var electron__default = /*#__PURE__*/_interopDefault(electron);
|
|
13
|
-
|
|
14
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
15
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
16
|
-
}) : x)(function(x) {
|
|
17
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
18
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
19
|
-
});
|
|
20
|
-
var isDev = __EIU_IS_DEV__;
|
|
21
|
-
process.platform === "win32";
|
|
22
|
-
process.platform === "darwin";
|
|
23
|
-
process.platform === "linux";
|
|
24
|
-
function getPathFromAppNameAsar(...paths) {
|
|
25
|
-
return isDev ? "DEV.asar" : path2__default.default.join(path2__default.default.dirname(electron__default.default.app.getAppPath()), `${electron__default.default.app.name}.asar`, ...paths);
|
|
26
|
-
}
|
|
27
|
-
function getAppVersion() {
|
|
28
|
-
return isDev ? getEntryVersion() : fs2__default.default.readFileSync(getPathFromAppNameAsar("version"), "utf-8");
|
|
29
|
-
}
|
|
30
|
-
function getEntryVersion() {
|
|
31
|
-
return electron__default.default.app.getVersion();
|
|
32
|
-
}
|
|
33
|
-
function restartApp() {
|
|
34
|
-
electron__default.default.app.relaunch();
|
|
35
|
-
electron__default.default.app.quit();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// src/utils/version.ts
|
|
39
|
-
var is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
|
|
40
|
-
function isUpdateJSON(json) {
|
|
41
|
-
return is(json) && is(json?.beta);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// src/entry/types.ts
|
|
10
|
+
//#region src/entry/types.ts
|
|
45
11
|
var UpdaterError = class extends Error {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
12
|
+
code;
|
|
13
|
+
constructor(code, info) {
|
|
14
|
+
super(`[${code}] ${info}`);
|
|
15
|
+
this.code = code;
|
|
16
|
+
}
|
|
51
17
|
};
|
|
52
18
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const _version = info?.version ?? this.info?.version;
|
|
237
|
-
if (!_sig || !_version) {
|
|
238
|
-
return emitError(
|
|
239
|
-
"ERR_PARAM",
|
|
240
|
-
"No update signature, please call `checkUpdate` first or manually setup params"
|
|
241
|
-
);
|
|
242
|
-
}
|
|
243
|
-
if (!data && !this.provider) {
|
|
244
|
-
return emitError(
|
|
245
|
-
"ERR_PARAM",
|
|
246
|
-
"No update asar buffer and provider"
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
const buffer = await this.fetch("buffer", data ? Buffer.from(data) : void 0);
|
|
250
|
-
if (!buffer) {
|
|
251
|
-
return emitError(
|
|
252
|
-
"ERR_PARAM",
|
|
253
|
-
"No update asar file buffer"
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
|
-
this.logger?.debug("Validation start");
|
|
257
|
-
if (!await this.provider.verifySignaure(buffer, _version, _sig, this.CERT)) {
|
|
258
|
-
return emitError(
|
|
259
|
-
"ERR_VALIDATE",
|
|
260
|
-
"Invalid update asar file"
|
|
261
|
-
);
|
|
262
|
-
}
|
|
263
|
-
this.logger?.debug("Validation end");
|
|
264
|
-
try {
|
|
265
|
-
this.tmpFilePath = `${getPathFromAppNameAsar()}.tmp`;
|
|
266
|
-
this.logger?.debug(`Install to ${this.tmpFilePath}`);
|
|
267
|
-
fs2__default.default.writeFileSync(this.tmpFilePath, await this.provider.unzipFile(buffer));
|
|
268
|
-
this.logger?.info(`Download success, version: ${_version}`);
|
|
269
|
-
this.info = void 0;
|
|
270
|
-
this.emit("update-downloaded");
|
|
271
|
-
this.processing = false;
|
|
272
|
-
this.logger?.debug("Download update end");
|
|
273
|
-
return true;
|
|
274
|
-
} catch (error) {
|
|
275
|
-
this.cleanup();
|
|
276
|
-
return emitError(
|
|
277
|
-
"ERR_DOWNLOAD",
|
|
278
|
-
`Failed to write update file: ${error instanceof Error ? error.message : error}`
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* quit App and install
|
|
284
|
-
*/
|
|
285
|
-
quitAndInstall() {
|
|
286
|
-
this.logger?.info("Quit and install");
|
|
287
|
-
restartApp();
|
|
288
|
-
}
|
|
289
|
-
cancel() {
|
|
290
|
-
if (this.controller.signal.aborted) {
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
this.controller.abort();
|
|
294
|
-
this.cleanup();
|
|
295
|
-
this.logger?.info("Cancel update");
|
|
296
|
-
this.emit("update-cancelled");
|
|
297
|
-
this.controller = new AbortController();
|
|
298
|
-
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/entry/updater.ts
|
|
21
|
+
var Updater = class extends node_events.EventEmitter {
|
|
22
|
+
CERT;
|
|
23
|
+
controller;
|
|
24
|
+
info;
|
|
25
|
+
tmpFilePath;
|
|
26
|
+
processing = false;
|
|
27
|
+
provider;
|
|
28
|
+
/**
|
|
29
|
+
* Updater logger
|
|
30
|
+
*/
|
|
31
|
+
logger;
|
|
32
|
+
/**
|
|
33
|
+
* Whether to receive beta update
|
|
34
|
+
*/
|
|
35
|
+
receiveBeta;
|
|
36
|
+
/**
|
|
37
|
+
* Whether force update in DEV
|
|
38
|
+
*/
|
|
39
|
+
forceUpdate;
|
|
40
|
+
/**
|
|
41
|
+
* Initialize incremental updater
|
|
42
|
+
* @param options UpdaterOption
|
|
43
|
+
*/
|
|
44
|
+
constructor(options = {}) {
|
|
45
|
+
super();
|
|
46
|
+
this.provider = options.provider;
|
|
47
|
+
this.receiveBeta = options.receiveBeta;
|
|
48
|
+
this.CERT = options.SIGNATURE_CERT || __EIU_SIGNATURE_CERT__;
|
|
49
|
+
this.logger = options.logger;
|
|
50
|
+
this.controller = new AbortController();
|
|
51
|
+
if (require_electron.isDev && !this.logger) {
|
|
52
|
+
this.logger = {
|
|
53
|
+
info: (...args) => console.log("[EIU-INFO ]", ...args),
|
|
54
|
+
debug: (...args) => console.log("[EIU-DEBUG]", ...args),
|
|
55
|
+
warn: (...args) => console.log("[EIU-WARN ]", ...args),
|
|
56
|
+
error: (...args) => console.error("[EIU-ERROR]", ...args)
|
|
57
|
+
};
|
|
58
|
+
this.logger.info("No logger set, enable dev-only logger");
|
|
59
|
+
}
|
|
60
|
+
if (!this.provider) this.logger?.debug("WARN: No update provider");
|
|
61
|
+
}
|
|
62
|
+
async fetch(format, data) {
|
|
63
|
+
if (typeof data === "object") if (format === "json" && require_version.isUpdateJSON(data) || format === "buffer" && Buffer.isBuffer(data)) return data;
|
|
64
|
+
else {
|
|
65
|
+
this.err("Invalid type", "ERR_PARAM", `Invalid type at format '${format}': ${JSON.stringify(data)}`);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
this.logger?.debug(`Download from \`${this.provider.name}\``);
|
|
69
|
+
try {
|
|
70
|
+
const result = format === "json" ? await this.provider.downloadJSON(electron.app.name, __EIU_VERSION_PATH__, this.controller.signal) : await this.provider.downloadAsar(this.info, this.controller.signal, (info) => this.emit("download-progress", info));
|
|
71
|
+
this.logger?.debug(`Download ${format} success${format === "buffer" ? `, file size: ${result.length}` : ""}`);
|
|
72
|
+
return result;
|
|
73
|
+
} catch (e) {
|
|
74
|
+
this.err(`Fetch ${format} failed`, "ERR_NETWORK", e instanceof Error ? e.message : e.toString());
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
cleanup() {
|
|
78
|
+
if (this.tmpFilePath && node_fs.default.existsSync(this.tmpFilePath)) try {
|
|
79
|
+
node_fs.default.unlinkSync(this.tmpFilePath);
|
|
80
|
+
this.tmpFilePath = void 0;
|
|
81
|
+
this.logger?.debug("Cleaned up temporary update file");
|
|
82
|
+
} catch (error) {
|
|
83
|
+
this.logger?.warn(`Failed to clean up temporary update file: ${error}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Handle error message and emit error event
|
|
88
|
+
*/
|
|
89
|
+
err(msg, code, errorInfo) {
|
|
90
|
+
const err = new UpdaterError(code, errorInfo);
|
|
91
|
+
this.logger?.error(`[${code}] ${msg}`, err);
|
|
92
|
+
this.cleanup();
|
|
93
|
+
this.emit("error", err);
|
|
94
|
+
}
|
|
95
|
+
async checkForUpdates(data) {
|
|
96
|
+
const emitUnavailable = (msg, code, info) => {
|
|
97
|
+
this.logger?.info(`[${code}] ${msg}`);
|
|
98
|
+
this.logger?.debug("Check update end");
|
|
99
|
+
this.processing = false;
|
|
100
|
+
this.emit("update-not-available", code, msg, info);
|
|
101
|
+
return false;
|
|
102
|
+
};
|
|
103
|
+
if (this.processing) {
|
|
104
|
+
this.logger?.info("Updater is already processing, skip check update");
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
this.processing = true;
|
|
108
|
+
this.logger?.debug("Check update start");
|
|
109
|
+
if (!data && !this.provider) {
|
|
110
|
+
const msg = "No update json or provider";
|
|
111
|
+
this.err("Check update failed", "ERR_PARAM", msg);
|
|
112
|
+
return emitUnavailable(msg, "UNAVAILABLE_ERROR");
|
|
113
|
+
}
|
|
114
|
+
const _data = await this.fetch("json", data);
|
|
115
|
+
if (!_data) return emitUnavailable("Failed to get update info", "UNAVAILABLE_ERROR");
|
|
116
|
+
const { signature, version, minimumVersion, url, ...rest } = this.receiveBeta ? _data.beta : _data;
|
|
117
|
+
const info = {
|
|
118
|
+
signature,
|
|
119
|
+
minimumVersion,
|
|
120
|
+
version,
|
|
121
|
+
url
|
|
122
|
+
};
|
|
123
|
+
const extraVersionInfo = {
|
|
124
|
+
signature,
|
|
125
|
+
minimumVersion,
|
|
126
|
+
version,
|
|
127
|
+
appVersion: require_electron.getAppVersion(),
|
|
128
|
+
entryVersion: require_electron.getEntryVersion(),
|
|
129
|
+
...rest
|
|
130
|
+
};
|
|
131
|
+
this.logger?.debug(`Checked update, version: ${version}, signature: ${signature}`);
|
|
132
|
+
if (require_electron.isDev && !this.forceUpdate && !data) return emitUnavailable("Skip check update in dev mode. To force update, set `updater.forceUpdate` to true or call checkUpdate with UpdateJSON", "UNAVAILABLE_DEV");
|
|
133
|
+
const isLowerVersion = this.provider.isLowerVersion;
|
|
134
|
+
try {
|
|
135
|
+
if (isLowerVersion(extraVersionInfo.entryVersion, minimumVersion)) return emitUnavailable(`Entry Version (${extraVersionInfo.entryVersion}) < MinimumVersion (${minimumVersion})`, "UNAVAILABLE_VERSION", extraVersionInfo);
|
|
136
|
+
this.logger?.info(`Current version is ${extraVersionInfo.appVersion}, new version is ${version}`);
|
|
137
|
+
if (!isLowerVersion(extraVersionInfo.appVersion, version)) return emitUnavailable(`Current version (${extraVersionInfo.appVersion}) > New version (${version})`, "UNAVAILABLE_VERSION", extraVersionInfo);
|
|
138
|
+
this.logger?.info(`Update available: ${version}`);
|
|
139
|
+
this.info = info;
|
|
140
|
+
this.processing = false;
|
|
141
|
+
this.logger?.debug("Check update end");
|
|
142
|
+
this.emit("update-available", extraVersionInfo);
|
|
143
|
+
return true;
|
|
144
|
+
} catch {
|
|
145
|
+
const msg = "Fail to parse version string";
|
|
146
|
+
this.err("Check update failed", "ERR_VALIDATE", msg);
|
|
147
|
+
return emitUnavailable(msg, "UNAVAILABLE_ERROR", extraVersionInfo);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async downloadUpdate(data, info) {
|
|
151
|
+
const emitError = (code, errorInfo) => {
|
|
152
|
+
this.err(`Download update failed`, code, errorInfo);
|
|
153
|
+
this.logger?.debug("Download update end");
|
|
154
|
+
this.processing = false;
|
|
155
|
+
return false;
|
|
156
|
+
};
|
|
157
|
+
if (this.processing) {
|
|
158
|
+
this.logger?.info("Updater is already processing, skip download update");
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
this.processing = true;
|
|
162
|
+
this.logger?.debug("Download update start");
|
|
163
|
+
const _sig = info?.signature ?? this.info?.signature;
|
|
164
|
+
const _version = info?.version ?? this.info?.version;
|
|
165
|
+
if (!_sig || !_version) return emitError("ERR_PARAM", "No update signature, please call `checkUpdate` first or manually setup params");
|
|
166
|
+
if (!data && !this.provider) return emitError("ERR_PARAM", "No update asar buffer and provider");
|
|
167
|
+
const buffer = await this.fetch("buffer", data ? Buffer.from(data) : void 0);
|
|
168
|
+
if (!buffer) return emitError("ERR_PARAM", "No update asar file buffer");
|
|
169
|
+
this.logger?.debug("Validation start");
|
|
170
|
+
if (!await this.provider.verifySignaure(buffer, _version, _sig, this.CERT)) return emitError("ERR_VALIDATE", "Invalid update asar file");
|
|
171
|
+
this.logger?.debug("Validation end");
|
|
172
|
+
try {
|
|
173
|
+
this.tmpFilePath = `${require_electron.getPathFromAppNameAsar()}.tmp`;
|
|
174
|
+
this.logger?.debug(`Install to ${this.tmpFilePath}`);
|
|
175
|
+
node_fs.default.writeFileSync(this.tmpFilePath, await this.provider.unzipFile(buffer));
|
|
176
|
+
this.logger?.info(`Download success, version: ${_version}`);
|
|
177
|
+
this.info = void 0;
|
|
178
|
+
this.emit("update-downloaded");
|
|
179
|
+
this.processing = false;
|
|
180
|
+
this.logger?.debug("Download update end");
|
|
181
|
+
return true;
|
|
182
|
+
} catch (error) {
|
|
183
|
+
this.cleanup();
|
|
184
|
+
return emitError("ERR_DOWNLOAD", `Failed to write update file: ${error instanceof Error ? error.message : error}`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* quit App and install
|
|
189
|
+
*/
|
|
190
|
+
quitAndInstall() {
|
|
191
|
+
this.logger?.info("Quit and install");
|
|
192
|
+
require_electron.restartApp();
|
|
193
|
+
}
|
|
194
|
+
cancel() {
|
|
195
|
+
if (this.controller.signal.aborted) return;
|
|
196
|
+
this.controller.abort();
|
|
197
|
+
this.cleanup();
|
|
198
|
+
this.logger?.info("Cancel update");
|
|
199
|
+
this.emit("update-cancelled");
|
|
200
|
+
this.controller = new AbortController();
|
|
201
|
+
}
|
|
299
202
|
};
|
|
203
|
+
/**
|
|
204
|
+
* Auto check update, download and install
|
|
205
|
+
*/
|
|
300
206
|
async function autoUpdate(updater) {
|
|
301
|
-
|
|
302
|
-
updater.quitAndInstall();
|
|
303
|
-
}
|
|
207
|
+
if (await updater.checkForUpdates() && await updater.downloadUpdate()) updater.quitAndInstall();
|
|
304
208
|
}
|
|
305
209
|
|
|
306
|
-
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/entry/core.ts
|
|
212
|
+
/**
|
|
213
|
+
* Utils to startup with updater
|
|
214
|
+
* @param fn startup function
|
|
215
|
+
* @example
|
|
216
|
+
* // in electron/main/index.ts
|
|
217
|
+
* export default startupWithUpdater((updater) => {
|
|
218
|
+
* updater.checkUpdate()
|
|
219
|
+
* })
|
|
220
|
+
*/
|
|
307
221
|
function startupWithUpdater(fn) {
|
|
308
|
-
|
|
222
|
+
console.log(typeof fn);
|
|
223
|
+
return fn;
|
|
224
|
+
}
|
|
225
|
+
function runWithDefaultExport(mod, args) {
|
|
226
|
+
return (mod.default || mod)(args);
|
|
309
227
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
228
|
+
const defaultOnInstall = (install, _, __, logger) => {
|
|
229
|
+
install();
|
|
230
|
+
logger?.info(`update success!`);
|
|
313
231
|
};
|
|
232
|
+
/**
|
|
233
|
+
* Initialize Electron with updater
|
|
234
|
+
* @example
|
|
235
|
+
* createElectronApp({
|
|
236
|
+
* updater: {
|
|
237
|
+
* provider: new GitHubProvider({
|
|
238
|
+
* username: 'yourname',
|
|
239
|
+
* repo: 'electron',
|
|
240
|
+
* }),
|
|
241
|
+
* },
|
|
242
|
+
* beforeStart(mainFilePath, logger) {
|
|
243
|
+
* logger?.debug(mainFilePath)
|
|
244
|
+
* },
|
|
245
|
+
* })
|
|
246
|
+
*/
|
|
314
247
|
async function createElectronApp(appOptions = {}) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
(await import(`file://${mainPath}`)).default(updaterInstance);
|
|
334
|
-
} else {
|
|
335
|
-
__require(mainPath)(updaterInstance);
|
|
336
|
-
}
|
|
337
|
-
} catch (error) {
|
|
338
|
-
logger?.error("startup error, exit", error);
|
|
339
|
-
onStartError?.(error, logger);
|
|
340
|
-
electron__default.default.app.quit();
|
|
341
|
-
}
|
|
248
|
+
const appNameAsarPath = require_electron.getPathFromAppNameAsar();
|
|
249
|
+
const { mainPath = require_electron.isDev ? node_path.default.join(electron.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "main", __EIU_MAIN_FILE__) : node_path.default.join(node_path.default.dirname(electron.app.getAppPath()), __EIU_ASAR_BASE_NAME__, "main", __EIU_MAIN_FILE__), updater, onInstall = defaultOnInstall, beforeStart, onStartError } = appOptions;
|
|
250
|
+
const updaterInstance = typeof updater === "object" || !updater ? new Updater(updater) : await updater();
|
|
251
|
+
const logger = updaterInstance.logger;
|
|
252
|
+
try {
|
|
253
|
+
const tempAsarPath = `${appNameAsarPath}.tmp`;
|
|
254
|
+
if (node_fs.default.existsSync(tempAsarPath)) {
|
|
255
|
+
logger?.info(`Installing new asar from ${tempAsarPath}`);
|
|
256
|
+
await onInstall(() => node_fs.default.renameSync(tempAsarPath, appNameAsarPath), tempAsarPath, appNameAsarPath, logger);
|
|
257
|
+
}
|
|
258
|
+
await beforeStart?.(mainPath, logger);
|
|
259
|
+
if (__EIU_IS_ESM__) runWithDefaultExport(await import(`file://${mainPath}`), updaterInstance);
|
|
260
|
+
else runWithDefaultExport(require(mainPath), updaterInstance);
|
|
261
|
+
} catch (error) {
|
|
262
|
+
logger?.error("startup error, exit", error);
|
|
263
|
+
onStartError?.(error, logger);
|
|
264
|
+
electron.app.quit();
|
|
265
|
+
}
|
|
342
266
|
}
|
|
343
|
-
|
|
267
|
+
/**
|
|
268
|
+
* @deprecated Use {@link createElectronApp} instead
|
|
269
|
+
*/
|
|
270
|
+
const initApp = createElectronApp;
|
|
344
271
|
|
|
272
|
+
//#endregion
|
|
345
273
|
exports.Updater = Updater;
|
|
346
274
|
exports.UpdaterError = UpdaterError;
|
|
347
275
|
exports.autoUpdate = autoUpdate;
|
|
348
276
|
exports.createElectronApp = createElectronApp;
|
|
349
277
|
exports.initApp = initApp;
|
|
350
|
-
exports.startupWithUpdater = startupWithUpdater;
|
|
278
|
+
exports.startupWithUpdater = startupWithUpdater;
|