electron-incremental-update 2.0.0-beta.7 → 2.0.0-beta.9
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/dist/{chunk-DFNDKSE6.js → chunk-4MH6ZXCY.js} +12 -12
- package/dist/{chunk-N77WQ5WB.js → chunk-KZSYEXLO.js} +9 -9
- package/dist/index.cjs +43 -52
- package/dist/index.d.cts +130 -9
- package/dist/index.d.ts +130 -9
- package/dist/index.js +36 -51
- package/dist/provider.cjs +25 -9
- package/dist/provider.d.cts +17 -1
- package/dist/provider.d.ts +17 -1
- package/dist/provider.js +17 -6
- package/dist/{types-CItP6bL-.d.ts → types-D7OK98ln.d.ts} +3 -28
- package/dist/{types-CItP6bL-.d.cts → types-mEfMjnlV.d.cts} +3 -28
- package/dist/utils.cjs +24 -25
- package/dist/utils.d.cts +3 -11
- package/dist/utils.d.ts +3 -11
- package/dist/utils.js +2 -11
- package/dist/version-DgfjJQUx.d.cts +27 -0
- package/dist/version-DgfjJQUx.d.ts +27 -0
- package/dist/vite.d.ts +7 -4
- package/dist/vite.js +164 -125
- package/package.json +8 -6
- package/dist/core-DJdvtwvU.d.ts +0 -134
- package/dist/core-ZUlLHadf.d.cts +0 -134
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { __require } from './chunk-72ZAJ7AF.js';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
4
|
import { app } from 'electron';
|
|
5
5
|
|
|
6
6
|
var isDev = __EIU_IS_DEV__;
|
|
7
7
|
var isWin = process.platform === "win32";
|
|
8
8
|
var isMac = process.platform === "darwin";
|
|
9
9
|
var isLinux = process.platform === "linux";
|
|
10
|
-
function getPathFromAppNameAsar(...
|
|
11
|
-
return isDev ? "DEV.asar" : join(dirname(app.getAppPath()), `${app.name}.asar`, ...
|
|
10
|
+
function getPathFromAppNameAsar(...paths) {
|
|
11
|
+
return isDev ? "DEV.asar" : path.join(path.dirname(app.getAppPath()), `${app.name}.asar`, ...paths);
|
|
12
12
|
}
|
|
13
13
|
function getAppVersion() {
|
|
14
|
-
return isDev ? getEntryVersion() : readFileSync(getPathFromAppNameAsar("version"), "utf-8");
|
|
14
|
+
return isDev ? getEntryVersion() : fs.readFileSync(getPathFromAppNameAsar("version"), "utf-8");
|
|
15
15
|
}
|
|
16
16
|
function getEntryVersion() {
|
|
17
17
|
return app.getVersion();
|
|
18
18
|
}
|
|
19
19
|
function requireNative(moduleName) {
|
|
20
|
-
return __require(join(app.getAppPath(), __EIU_ENTRY_DIST_PATH__, moduleName));
|
|
20
|
+
return __require(path.join(app.getAppPath(), __EIU_ENTRY_DIST_PATH__, moduleName));
|
|
21
21
|
}
|
|
22
22
|
function restartApp() {
|
|
23
23
|
app.relaunch();
|
|
@@ -51,9 +51,9 @@ function singleInstance(window) {
|
|
|
51
51
|
return result;
|
|
52
52
|
}
|
|
53
53
|
function setPortableAppDataPath(dirName = "data") {
|
|
54
|
-
const portablePath = join(dirname(app.getPath("exe")), dirName);
|
|
55
|
-
if (!existsSync(portablePath)) {
|
|
56
|
-
mkdirSync(portablePath);
|
|
54
|
+
const portablePath = path.join(path.dirname(app.getPath("exe")), dirName);
|
|
55
|
+
if (!fs.existsSync(portablePath)) {
|
|
56
|
+
fs.mkdirSync(portablePath);
|
|
57
57
|
}
|
|
58
58
|
app.setPath("appData", portablePath);
|
|
59
59
|
}
|
|
@@ -65,13 +65,13 @@ function loadPage(win, htmlFilePath = "index.html") {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
function getPathFromPreload(...paths) {
|
|
68
|
-
return isDev ? join(app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
|
|
68
|
+
return isDev ? path.join(app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
|
|
69
69
|
}
|
|
70
70
|
function getPathFromPublic(...paths) {
|
|
71
|
-
return isDev ? join(app.getAppPath(), "public", ...paths) : getPathFromAppNameAsar("renderer", ...paths);
|
|
71
|
+
return isDev ? path.join(app.getAppPath(), "public", ...paths) : getPathFromAppNameAsar("renderer", ...paths);
|
|
72
72
|
}
|
|
73
73
|
function getPathFromEntryAsar(...paths) {
|
|
74
|
-
return join(app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
|
|
74
|
+
return path.join(app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
|
|
75
75
|
}
|
|
76
76
|
function handleUnexpectedErrors(callback) {
|
|
77
77
|
process.on("uncaughtException", callback);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import zlib from 'node:zlib';
|
|
2
|
+
import crypto from 'node:crypto';
|
|
3
3
|
|
|
4
4
|
// src/utils/zip.ts
|
|
5
5
|
async function defaultZipFile(buffer) {
|
|
6
6
|
return new Promise((resolve, reject) => {
|
|
7
|
-
brotliCompress(buffer, (err, buffer2) => {
|
|
7
|
+
zlib.brotliCompress(buffer, (err, buffer2) => {
|
|
8
8
|
if (err) {
|
|
9
9
|
reject(err);
|
|
10
10
|
} else {
|
|
@@ -15,7 +15,7 @@ async function defaultZipFile(buffer) {
|
|
|
15
15
|
}
|
|
16
16
|
async function defaultUnzipFile(buffer) {
|
|
17
17
|
return new Promise((resolve, reject) => {
|
|
18
|
-
brotliDecompress(buffer, (err, buffer2) => {
|
|
18
|
+
zlib.brotliDecompress(buffer, (err, buffer2) => {
|
|
19
19
|
if (err) {
|
|
20
20
|
reject(err);
|
|
21
21
|
} else {
|
|
@@ -25,19 +25,19 @@ async function defaultUnzipFile(buffer) {
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
function hashBuffer(data, length) {
|
|
28
|
-
const hash = createHash("SHA256").update(data).digest("binary");
|
|
28
|
+
const hash = crypto.createHash("SHA256").update(data).digest("binary");
|
|
29
29
|
return Buffer.from(hash).subarray(0, length);
|
|
30
30
|
}
|
|
31
31
|
function aesEncrypt(plainText, key, iv) {
|
|
32
|
-
const cipher = createCipheriv("aes-256-cbc", key, iv);
|
|
32
|
+
const cipher = crypto.createCipheriv("aes-256-cbc", key, iv);
|
|
33
33
|
return cipher.update(plainText, "utf8", "base64url") + cipher.final("base64url");
|
|
34
34
|
}
|
|
35
35
|
function defaultSignature(buffer, privateKey, cert, version) {
|
|
36
|
-
const sig = createSign("RSA-SHA256").update(buffer).sign(createPrivateKey(privateKey), "base64");
|
|
36
|
+
const sig = crypto.createSign("RSA-SHA256").update(buffer).sign(crypto.createPrivateKey(privateKey), "base64");
|
|
37
37
|
return aesEncrypt(`${sig}%${version}`, hashBuffer(cert, 32), hashBuffer(buffer, 16));
|
|
38
38
|
}
|
|
39
39
|
function aesDecrypt(encryptedText, key, iv) {
|
|
40
|
-
const decipher = createDecipheriv("aes-256-cbc", key, iv);
|
|
40
|
+
const decipher = crypto.createDecipheriv("aes-256-cbc", key, iv);
|
|
41
41
|
return decipher.update(encryptedText, "base64url", "utf8") + decipher.final("utf8");
|
|
42
42
|
}
|
|
43
43
|
function defaultVerifySignature(buffer, version, signature, cert) {
|
|
@@ -46,7 +46,7 @@ function defaultVerifySignature(buffer, version, signature, cert) {
|
|
|
46
46
|
if (ver !== version) {
|
|
47
47
|
return false;
|
|
48
48
|
}
|
|
49
|
-
return createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
|
|
49
|
+
return crypto.createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
|
|
50
50
|
} catch {
|
|
51
51
|
return false;
|
|
52
52
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var fs = require('fs');
|
|
5
|
-
var electron = require('electron');
|
|
3
|
+
var fs3 = require('fs');
|
|
6
4
|
var events = require('events');
|
|
5
|
+
var electron = require('electron');
|
|
6
|
+
var path = require('path');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var fs3__default = /*#__PURE__*/_interopDefault(fs3);
|
|
11
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
7
12
|
|
|
8
13
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
9
14
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
@@ -21,11 +26,11 @@ var isDev = __EIU_IS_DEV__;
|
|
|
21
26
|
process.platform === "win32";
|
|
22
27
|
process.platform === "darwin";
|
|
23
28
|
process.platform === "linux";
|
|
24
|
-
function getPathFromAppNameAsar(...
|
|
25
|
-
return isDev ? "DEV.asar" :
|
|
29
|
+
function getPathFromAppNameAsar(...paths) {
|
|
30
|
+
return isDev ? "DEV.asar" : path__default.default.join(path__default.default.dirname(electron.app.getAppPath()), `${electron.app.name}.asar`, ...paths);
|
|
26
31
|
}
|
|
27
32
|
function getAppVersion() {
|
|
28
|
-
return isDev ? getEntryVersion() :
|
|
33
|
+
return isDev ? getEntryVersion() : fs3__default.default.readFileSync(getPathFromAppNameAsar("version"), "utf-8");
|
|
29
34
|
}
|
|
30
35
|
function getEntryVersion() {
|
|
31
36
|
return electron.app.getVersion();
|
|
@@ -35,7 +40,7 @@ function restartApp() {
|
|
|
35
40
|
electron.app.quit();
|
|
36
41
|
}
|
|
37
42
|
|
|
38
|
-
// src/
|
|
43
|
+
// src/entry/types.ts
|
|
39
44
|
var ErrorInfo = {
|
|
40
45
|
download: "Download failed",
|
|
41
46
|
validate: "Validate failed",
|
|
@@ -50,7 +55,7 @@ var UpdaterError = class extends Error {
|
|
|
50
55
|
}
|
|
51
56
|
};
|
|
52
57
|
|
|
53
|
-
// src/updater
|
|
58
|
+
// src/entry/updater.ts
|
|
54
59
|
var Updater = class extends events.EventEmitter {
|
|
55
60
|
CERT = __EIU_SIGNATURE_CERT__;
|
|
56
61
|
info;
|
|
@@ -69,19 +74,14 @@ var Updater = class extends events.EventEmitter {
|
|
|
69
74
|
forceUpdate;
|
|
70
75
|
/**
|
|
71
76
|
* initialize incremental updater
|
|
72
|
-
* @param
|
|
73
|
-
* @param option UpdaterOption
|
|
77
|
+
* @param options UpdaterOption
|
|
74
78
|
*/
|
|
75
|
-
constructor(
|
|
79
|
+
constructor(options = {}) {
|
|
76
80
|
super();
|
|
77
|
-
this.provider = provider;
|
|
78
|
-
this.receiveBeta =
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
if (option.logger) {
|
|
83
|
-
this.logger = option.logger;
|
|
84
|
-
}
|
|
81
|
+
this.provider = options.provider;
|
|
82
|
+
this.receiveBeta = options.receiveBeta;
|
|
83
|
+
this.CERT = options.SIGNATURE_CERT || __EIU_SIGNATURE_CERT__;
|
|
84
|
+
this.logger = options.logger;
|
|
85
85
|
if (isDev && !this.logger) {
|
|
86
86
|
this.logger = {
|
|
87
87
|
info: (...args) => console.log("[EIU-INFO ]", ...args),
|
|
@@ -91,6 +91,14 @@ var Updater = class extends events.EventEmitter {
|
|
|
91
91
|
};
|
|
92
92
|
this.logger.info("no logger set, enable dev-only logger");
|
|
93
93
|
}
|
|
94
|
+
if (!this.provider) {
|
|
95
|
+
this.logger?.debug("No update provider, please setup provider before checking update");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
checkProvider() {
|
|
99
|
+
if (!this.provider) {
|
|
100
|
+
throw new UpdaterError("param", "missing update provider");
|
|
101
|
+
}
|
|
94
102
|
}
|
|
95
103
|
async fetch(format, data) {
|
|
96
104
|
if (typeof data === "object") {
|
|
@@ -119,6 +127,7 @@ var Updater = class extends events.EventEmitter {
|
|
|
119
127
|
this.emit("error", err);
|
|
120
128
|
}
|
|
121
129
|
async checkUpdate(data) {
|
|
130
|
+
this.checkProvider();
|
|
122
131
|
const emitUnavailable = (msg) => {
|
|
123
132
|
this.logger?.info(msg);
|
|
124
133
|
this.emit("update-unavailable", msg);
|
|
@@ -154,6 +163,7 @@ var Updater = class extends events.EventEmitter {
|
|
|
154
163
|
return true;
|
|
155
164
|
}
|
|
156
165
|
async downloadUpdate(data, info) {
|
|
166
|
+
this.checkProvider();
|
|
157
167
|
const _sig = info?.signature ?? this.info?.signature;
|
|
158
168
|
const _version = info?.version ?? this.info?.version;
|
|
159
169
|
if (!_sig || !_version) {
|
|
@@ -167,14 +177,14 @@ var Updater = class extends events.EventEmitter {
|
|
|
167
177
|
}
|
|
168
178
|
this.logger?.debug("verify start");
|
|
169
179
|
if (!await this.provider.verifySignaure(buffer, _version, _sig, this.CERT)) {
|
|
170
|
-
this.err("download failed", "validate", "invalid
|
|
180
|
+
this.err("download failed", "validate", "invalid update asar file");
|
|
171
181
|
return false;
|
|
172
182
|
}
|
|
173
183
|
this.logger?.debug("verify success");
|
|
174
184
|
try {
|
|
175
185
|
const tmpFilePath = getPathFromAppNameAsar() + ".tmp";
|
|
176
186
|
this.logger?.debug(`install to ${tmpFilePath}`);
|
|
177
|
-
|
|
187
|
+
fs3__default.default.writeFileSync(tmpFilePath, await this.provider.unzipFile(buffer));
|
|
178
188
|
this.logger?.info(`download success, version: ${_version}`);
|
|
179
189
|
this.info = void 0;
|
|
180
190
|
this.emit("update-downloaded");
|
|
@@ -191,23 +201,12 @@ var Updater = class extends events.EventEmitter {
|
|
|
191
201
|
this.logger?.info("quit and install");
|
|
192
202
|
restartApp();
|
|
193
203
|
}
|
|
194
|
-
/**
|
|
195
|
-
* setup provider URL handler
|
|
196
|
-
*
|
|
197
|
-
* @example
|
|
198
|
-
* updater.setURLHandler((url, isDownloadingAsar) => {
|
|
199
|
-
* if (isDownloadingAsar) {
|
|
200
|
-
* url.hostname = 'https://cdn.jsdelivr.net/gh'
|
|
201
|
-
* return url
|
|
202
|
-
* }
|
|
203
|
-
* })
|
|
204
|
-
*/
|
|
205
|
-
setURLHandler(handler) {
|
|
206
|
-
this.provider.urlHandler = handler;
|
|
207
|
-
}
|
|
208
204
|
};
|
|
209
|
-
|
|
210
|
-
|
|
205
|
+
async function autoUpdate(updater) {
|
|
206
|
+
if (await updater.checkUpdate() && await updater.downloadUpdate()) {
|
|
207
|
+
updater.quitAndInstall();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
211
210
|
function startupWithUpdater(fn) {
|
|
212
211
|
return fn;
|
|
213
212
|
}
|
|
@@ -217,7 +216,6 @@ var defaultOnInstall = (install, _, __, logger) => {
|
|
|
217
216
|
};
|
|
218
217
|
async function initApp(appOptions) {
|
|
219
218
|
const {
|
|
220
|
-
provider,
|
|
221
219
|
updater,
|
|
222
220
|
onInstall = defaultOnInstall,
|
|
223
221
|
beforeStart,
|
|
@@ -225,28 +223,20 @@ async function initApp(appOptions) {
|
|
|
225
223
|
} = appOptions;
|
|
226
224
|
let updaterInstance;
|
|
227
225
|
if (typeof updater === "object" || !updater) {
|
|
228
|
-
updaterInstance = new Updater(
|
|
226
|
+
updaterInstance = new Updater(updater);
|
|
229
227
|
} else {
|
|
230
228
|
updaterInstance = await updater();
|
|
231
229
|
}
|
|
232
|
-
|
|
233
|
-
if (isDev && !logger) {
|
|
234
|
-
logger = {
|
|
235
|
-
info: (...args) => console.log("[EIU-INFO ]", ...args),
|
|
236
|
-
debug: (...args) => console.log("[EIU-DEBUG]", ...args),
|
|
237
|
-
warn: (...args) => console.log("[EIU-WARN ]", ...args),
|
|
238
|
-
error: (...args) => console.error("[EIU-ERROR]", ...args)
|
|
239
|
-
};
|
|
240
|
-
}
|
|
230
|
+
const logger = updaterInstance.logger;
|
|
241
231
|
try {
|
|
242
232
|
const appNameAsarPath = getPathFromAppNameAsar();
|
|
243
233
|
const tempAsarPath = `${appNameAsarPath}.tmp`;
|
|
244
|
-
if (
|
|
234
|
+
if (fs3__default.default.existsSync(tempAsarPath)) {
|
|
245
235
|
logger?.info(`installing new asar: ${tempAsarPath}`);
|
|
246
|
-
await onInstall(() =>
|
|
236
|
+
await onInstall(() => fs3__default.default.renameSync(tempAsarPath, appNameAsarPath), tempAsarPath, appNameAsarPath, logger);
|
|
247
237
|
}
|
|
248
|
-
const mainFilePath =
|
|
249
|
-
isDev ?
|
|
238
|
+
const mainFilePath = path__default.default.join(
|
|
239
|
+
isDev ? path__default.default.join(electron.app.getAppPath(), __EIU_MAIN_DEV_DIR__) : appNameAsarPath,
|
|
250
240
|
"main",
|
|
251
241
|
__EIU_MAIN_FILE__
|
|
252
242
|
);
|
|
@@ -262,5 +252,6 @@ async function initApp(appOptions) {
|
|
|
262
252
|
exports.ErrorInfo = ErrorInfo;
|
|
263
253
|
exports.Updater = Updater;
|
|
264
254
|
exports.UpdaterError = UpdaterError;
|
|
255
|
+
exports.autoUpdate = autoUpdate;
|
|
265
256
|
exports.initApp = initApp;
|
|
266
257
|
exports.startupWithUpdater = startupWithUpdater;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,134 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { I as IProvider } from './types-
|
|
4
|
-
import 'node:events';
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { U as UpdateJSON, a as UpdateInfo } from './version-DgfjJQUx.cjs';
|
|
3
|
+
import { I as IProvider, D as DownloadingInfo } from './types-mEfMjnlV.cjs';
|
|
5
4
|
import '@subframe7536/type-utils';
|
|
6
5
|
|
|
6
|
+
declare const ErrorInfo: {
|
|
7
|
+
readonly download: "Download failed";
|
|
8
|
+
readonly validate: "Validate failed";
|
|
9
|
+
readonly param: "Missing params";
|
|
10
|
+
readonly network: "Network error";
|
|
11
|
+
};
|
|
12
|
+
declare class UpdaterError extends Error {
|
|
13
|
+
code: keyof typeof ErrorInfo;
|
|
14
|
+
constructor(msg: keyof typeof ErrorInfo, info: string);
|
|
15
|
+
}
|
|
16
|
+
type CheckResult<T extends UpdateJSON> = {
|
|
17
|
+
success: true;
|
|
18
|
+
data: Omit<T, 'beta'>;
|
|
19
|
+
} | {
|
|
20
|
+
success: false;
|
|
21
|
+
/**
|
|
22
|
+
* minimal version that can update
|
|
23
|
+
*/
|
|
24
|
+
data: string;
|
|
25
|
+
} | {
|
|
26
|
+
success: false;
|
|
27
|
+
data: UpdaterError;
|
|
28
|
+
};
|
|
29
|
+
type DownloadResult = {
|
|
30
|
+
success: true;
|
|
31
|
+
} | {
|
|
32
|
+
success: false;
|
|
33
|
+
data: UpdaterError;
|
|
34
|
+
};
|
|
35
|
+
interface Logger {
|
|
36
|
+
info: (msg: string) => void;
|
|
37
|
+
debug: (msg: string) => void;
|
|
38
|
+
warn: (msg: string) => void;
|
|
39
|
+
error: (msg: string, e?: unknown) => void;
|
|
40
|
+
}
|
|
41
|
+
interface UpdaterOption {
|
|
42
|
+
/**
|
|
43
|
+
* update provider
|
|
44
|
+
*/
|
|
45
|
+
provider?: IProvider;
|
|
46
|
+
/**
|
|
47
|
+
* public key of signature, which will be auto generated by plugin,
|
|
48
|
+
* generate by `selfsigned` if not set
|
|
49
|
+
*/
|
|
50
|
+
SIGNATURE_CERT?: string;
|
|
51
|
+
/**
|
|
52
|
+
* whether to receive beta update
|
|
53
|
+
*/
|
|
54
|
+
receiveBeta?: boolean;
|
|
55
|
+
logger?: Logger;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
declare class Updater extends EventEmitter<{
|
|
59
|
+
'checking': any;
|
|
60
|
+
'update-available': [data: UpdateInfo];
|
|
61
|
+
'update-unavailable': [reason: string];
|
|
62
|
+
'error': [error: UpdaterError];
|
|
63
|
+
'download-progress': [info: DownloadingInfo];
|
|
64
|
+
'update-downloaded': any;
|
|
65
|
+
}> {
|
|
66
|
+
private CERT;
|
|
67
|
+
private info?;
|
|
68
|
+
provider?: IProvider;
|
|
69
|
+
/**
|
|
70
|
+
* updater logger
|
|
71
|
+
*/
|
|
72
|
+
logger?: Logger;
|
|
73
|
+
/**
|
|
74
|
+
* whether to receive beta update
|
|
75
|
+
*/
|
|
76
|
+
receiveBeta?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* whether force update in DEV
|
|
79
|
+
*/
|
|
80
|
+
forceUpdate?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* initialize incremental updater
|
|
83
|
+
* @param options UpdaterOption
|
|
84
|
+
*/
|
|
85
|
+
constructor(options?: UpdaterOption);
|
|
86
|
+
private checkProvider;
|
|
87
|
+
/**
|
|
88
|
+
* this function is used to parse download data.
|
|
89
|
+
* - if format is `'json'`
|
|
90
|
+
* - if data is `UpdateJSON`, return it
|
|
91
|
+
* - if data is string or absent, download URL data and return it
|
|
92
|
+
* - if format is `'buffer'`
|
|
93
|
+
* - if data is `Buffer`, return it
|
|
94
|
+
* - if data is string or absent, download URL data and return it
|
|
95
|
+
* @param format 'json' or 'buffer'
|
|
96
|
+
* @param data download URL or update json or buffer
|
|
97
|
+
*/
|
|
98
|
+
private fetch;
|
|
99
|
+
/**
|
|
100
|
+
* handle error message and emit error event
|
|
101
|
+
*/
|
|
102
|
+
private err;
|
|
103
|
+
/**
|
|
104
|
+
* check update info using default options
|
|
105
|
+
*/
|
|
106
|
+
checkUpdate(): Promise<boolean>;
|
|
107
|
+
/**
|
|
108
|
+
* check update info using existing update json
|
|
109
|
+
* @param data existing update json
|
|
110
|
+
*/
|
|
111
|
+
checkUpdate(data: UpdateJSON): Promise<boolean>;
|
|
112
|
+
/**
|
|
113
|
+
* download update using default options
|
|
114
|
+
*/
|
|
115
|
+
downloadUpdate(): Promise<boolean>;
|
|
116
|
+
/**
|
|
117
|
+
* download update using existing `asar.gz` buffer and signature
|
|
118
|
+
* @param data existing `asar.gz` buffer
|
|
119
|
+
* @param info update info
|
|
120
|
+
*/
|
|
121
|
+
downloadUpdate(data: Uint8Array, info: Omit<UpdateInfo, 'minimumVersion'>): Promise<boolean>;
|
|
122
|
+
/**
|
|
123
|
+
* quit App and install
|
|
124
|
+
*/
|
|
125
|
+
quitAndInstall(): void;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* auto check update, download and install
|
|
129
|
+
*/
|
|
130
|
+
declare function autoUpdate(updater: Updater): Promise<void>;
|
|
131
|
+
|
|
7
132
|
type Promisable<T> = T | Promise<T>;
|
|
8
133
|
/**
|
|
9
134
|
* hooks on rename temp asar path to `${app.name}.asar`
|
|
@@ -15,10 +140,6 @@ type Promisable<T> = T | Promise<T>;
|
|
|
15
140
|
*/
|
|
16
141
|
type OnInstallFunction = (install: VoidFunction, tempAsarPath: string, appNameAsarPath: string, logger?: Logger) => Promisable<void>;
|
|
17
142
|
interface AppOption {
|
|
18
|
-
/**
|
|
19
|
-
* update provider
|
|
20
|
-
*/
|
|
21
|
-
provider: IProvider;
|
|
22
143
|
/**
|
|
23
144
|
* updater options
|
|
24
145
|
*/
|
|
@@ -75,4 +196,4 @@ declare function startupWithUpdater(fn: (updater: Updater) => Promisable<void>):
|
|
|
75
196
|
*/
|
|
76
197
|
declare function initApp(appOptions: AppOption): Promise<void>;
|
|
77
198
|
|
|
78
|
-
export { type AppOption, Logger, Updater, UpdaterOption, initApp, startupWithUpdater };
|
|
199
|
+
export { type AppOption, type CheckResult, type DownloadResult, ErrorInfo, type Logger, Updater, UpdaterError, type UpdaterOption, autoUpdate, initApp, startupWithUpdater };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,134 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { I as IProvider } from './types-
|
|
4
|
-
import 'node:events';
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { U as UpdateJSON, a as UpdateInfo } from './version-DgfjJQUx.js';
|
|
3
|
+
import { I as IProvider, D as DownloadingInfo } from './types-D7OK98ln.js';
|
|
5
4
|
import '@subframe7536/type-utils';
|
|
6
5
|
|
|
6
|
+
declare const ErrorInfo: {
|
|
7
|
+
readonly download: "Download failed";
|
|
8
|
+
readonly validate: "Validate failed";
|
|
9
|
+
readonly param: "Missing params";
|
|
10
|
+
readonly network: "Network error";
|
|
11
|
+
};
|
|
12
|
+
declare class UpdaterError extends Error {
|
|
13
|
+
code: keyof typeof ErrorInfo;
|
|
14
|
+
constructor(msg: keyof typeof ErrorInfo, info: string);
|
|
15
|
+
}
|
|
16
|
+
type CheckResult<T extends UpdateJSON> = {
|
|
17
|
+
success: true;
|
|
18
|
+
data: Omit<T, 'beta'>;
|
|
19
|
+
} | {
|
|
20
|
+
success: false;
|
|
21
|
+
/**
|
|
22
|
+
* minimal version that can update
|
|
23
|
+
*/
|
|
24
|
+
data: string;
|
|
25
|
+
} | {
|
|
26
|
+
success: false;
|
|
27
|
+
data: UpdaterError;
|
|
28
|
+
};
|
|
29
|
+
type DownloadResult = {
|
|
30
|
+
success: true;
|
|
31
|
+
} | {
|
|
32
|
+
success: false;
|
|
33
|
+
data: UpdaterError;
|
|
34
|
+
};
|
|
35
|
+
interface Logger {
|
|
36
|
+
info: (msg: string) => void;
|
|
37
|
+
debug: (msg: string) => void;
|
|
38
|
+
warn: (msg: string) => void;
|
|
39
|
+
error: (msg: string, e?: unknown) => void;
|
|
40
|
+
}
|
|
41
|
+
interface UpdaterOption {
|
|
42
|
+
/**
|
|
43
|
+
* update provider
|
|
44
|
+
*/
|
|
45
|
+
provider?: IProvider;
|
|
46
|
+
/**
|
|
47
|
+
* public key of signature, which will be auto generated by plugin,
|
|
48
|
+
* generate by `selfsigned` if not set
|
|
49
|
+
*/
|
|
50
|
+
SIGNATURE_CERT?: string;
|
|
51
|
+
/**
|
|
52
|
+
* whether to receive beta update
|
|
53
|
+
*/
|
|
54
|
+
receiveBeta?: boolean;
|
|
55
|
+
logger?: Logger;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
declare class Updater extends EventEmitter<{
|
|
59
|
+
'checking': any;
|
|
60
|
+
'update-available': [data: UpdateInfo];
|
|
61
|
+
'update-unavailable': [reason: string];
|
|
62
|
+
'error': [error: UpdaterError];
|
|
63
|
+
'download-progress': [info: DownloadingInfo];
|
|
64
|
+
'update-downloaded': any;
|
|
65
|
+
}> {
|
|
66
|
+
private CERT;
|
|
67
|
+
private info?;
|
|
68
|
+
provider?: IProvider;
|
|
69
|
+
/**
|
|
70
|
+
* updater logger
|
|
71
|
+
*/
|
|
72
|
+
logger?: Logger;
|
|
73
|
+
/**
|
|
74
|
+
* whether to receive beta update
|
|
75
|
+
*/
|
|
76
|
+
receiveBeta?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* whether force update in DEV
|
|
79
|
+
*/
|
|
80
|
+
forceUpdate?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* initialize incremental updater
|
|
83
|
+
* @param options UpdaterOption
|
|
84
|
+
*/
|
|
85
|
+
constructor(options?: UpdaterOption);
|
|
86
|
+
private checkProvider;
|
|
87
|
+
/**
|
|
88
|
+
* this function is used to parse download data.
|
|
89
|
+
* - if format is `'json'`
|
|
90
|
+
* - if data is `UpdateJSON`, return it
|
|
91
|
+
* - if data is string or absent, download URL data and return it
|
|
92
|
+
* - if format is `'buffer'`
|
|
93
|
+
* - if data is `Buffer`, return it
|
|
94
|
+
* - if data is string or absent, download URL data and return it
|
|
95
|
+
* @param format 'json' or 'buffer'
|
|
96
|
+
* @param data download URL or update json or buffer
|
|
97
|
+
*/
|
|
98
|
+
private fetch;
|
|
99
|
+
/**
|
|
100
|
+
* handle error message and emit error event
|
|
101
|
+
*/
|
|
102
|
+
private err;
|
|
103
|
+
/**
|
|
104
|
+
* check update info using default options
|
|
105
|
+
*/
|
|
106
|
+
checkUpdate(): Promise<boolean>;
|
|
107
|
+
/**
|
|
108
|
+
* check update info using existing update json
|
|
109
|
+
* @param data existing update json
|
|
110
|
+
*/
|
|
111
|
+
checkUpdate(data: UpdateJSON): Promise<boolean>;
|
|
112
|
+
/**
|
|
113
|
+
* download update using default options
|
|
114
|
+
*/
|
|
115
|
+
downloadUpdate(): Promise<boolean>;
|
|
116
|
+
/**
|
|
117
|
+
* download update using existing `asar.gz` buffer and signature
|
|
118
|
+
* @param data existing `asar.gz` buffer
|
|
119
|
+
* @param info update info
|
|
120
|
+
*/
|
|
121
|
+
downloadUpdate(data: Uint8Array, info: Omit<UpdateInfo, 'minimumVersion'>): Promise<boolean>;
|
|
122
|
+
/**
|
|
123
|
+
* quit App and install
|
|
124
|
+
*/
|
|
125
|
+
quitAndInstall(): void;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* auto check update, download and install
|
|
129
|
+
*/
|
|
130
|
+
declare function autoUpdate(updater: Updater): Promise<void>;
|
|
131
|
+
|
|
7
132
|
type Promisable<T> = T | Promise<T>;
|
|
8
133
|
/**
|
|
9
134
|
* hooks on rename temp asar path to `${app.name}.asar`
|
|
@@ -15,10 +140,6 @@ type Promisable<T> = T | Promise<T>;
|
|
|
15
140
|
*/
|
|
16
141
|
type OnInstallFunction = (install: VoidFunction, tempAsarPath: string, appNameAsarPath: string, logger?: Logger) => Promisable<void>;
|
|
17
142
|
interface AppOption {
|
|
18
|
-
/**
|
|
19
|
-
* update provider
|
|
20
|
-
*/
|
|
21
|
-
provider: IProvider;
|
|
22
143
|
/**
|
|
23
144
|
* updater options
|
|
24
145
|
*/
|
|
@@ -75,4 +196,4 @@ declare function startupWithUpdater(fn: (updater: Updater) => Promisable<void>):
|
|
|
75
196
|
*/
|
|
76
197
|
declare function initApp(appOptions: AppOption): Promise<void>;
|
|
77
198
|
|
|
78
|
-
export { type AppOption, Logger, Updater, UpdaterOption, initApp, startupWithUpdater };
|
|
199
|
+
export { type AppOption, type CheckResult, type DownloadResult, ErrorInfo, type Logger, Updater, UpdaterError, type UpdaterOption, autoUpdate, initApp, startupWithUpdater };
|