electron-incremental-update 2.0.0-beta.1 → 2.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 +3 -3
- package/dist/{chunk-RSLOPAIZ.js → chunk-BG22XZAB.js} +23 -13
- package/dist/{decrypt-BNBcodiO.d.cts → decrypt-D9WdXYjH.d.cts} +1 -1
- package/dist/{decrypt-BNBcodiO.d.ts → decrypt-D9WdXYjH.d.ts} +1 -1
- package/dist/index.cjs +88 -74
- package/dist/index.d.cts +22 -30
- package/dist/index.d.ts +22 -30
- package/dist/index.js +88 -74
- package/dist/provider.cjs +15 -6
- package/dist/provider.d.cts +3 -3
- package/dist/provider.d.ts +3 -3
- package/dist/provider.js +15 -6
- package/dist/{types-DxPmQmaq.d.cts → types-COqp44eg.d.cts} +13 -5
- package/dist/{types-seJf3Wbc.d.ts → types-CPq1MrYZ.d.ts} +13 -5
- package/dist/utils.cjs +23 -13
- package/dist/utils.d.cts +3 -3
- package/dist/utils.d.ts +3 -3
- package/dist/utils.js +1 -1
- package/dist/vite.js +31 -19
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -181,7 +181,7 @@ initApp({
|
|
|
181
181
|
in `electron/main/index.ts`
|
|
182
182
|
|
|
183
183
|
```ts
|
|
184
|
-
import {
|
|
184
|
+
import { UpdaterError, startupWithUpdater } from 'electron-incremental-update'
|
|
185
185
|
import { getPathFromAppNameAsar, getVersions } from 'electron-incremental-update/utils'
|
|
186
186
|
import { app } from 'electron'
|
|
187
187
|
|
|
@@ -199,7 +199,7 @@ export default startupWithUpdater((updater) => {
|
|
|
199
199
|
}
|
|
200
200
|
updater.logger = console
|
|
201
201
|
updater.receiveBeta = true
|
|
202
|
-
|
|
202
|
+
|
|
203
203
|
updater.checkUpdate().then(async (result) => {
|
|
204
204
|
if (result === undefined) {
|
|
205
205
|
console.log('Update Unavailable')
|
|
@@ -276,7 +276,7 @@ import Database from 'better-sqlite3'
|
|
|
276
276
|
|
|
277
277
|
const db = new Database(':memory:', { nativeBinding: './better_sqlite3.node' })
|
|
278
278
|
|
|
279
|
-
export function test() {
|
|
279
|
+
export function test(): void {
|
|
280
280
|
db.exec(
|
|
281
281
|
'DROP TABLE IF EXISTS employees; '
|
|
282
282
|
+ 'CREATE TABLE IF NOT EXISTS employees (name TEXT, salary INTEGER)',
|
|
@@ -30,7 +30,9 @@ function restartApp() {
|
|
|
30
30
|
app.quit();
|
|
31
31
|
}
|
|
32
32
|
function setAppUserModelId(id) {
|
|
33
|
-
|
|
33
|
+
if (isWin) {
|
|
34
|
+
app.setAppUserModelId(id ?? `org.${app.name}`);
|
|
35
|
+
}
|
|
34
36
|
}
|
|
35
37
|
function disableHWAccForWin7() {
|
|
36
38
|
if (__require("node:os").release().startsWith("6.1")) {
|
|
@@ -39,15 +41,19 @@ function disableHWAccForWin7() {
|
|
|
39
41
|
}
|
|
40
42
|
function singleInstance(window) {
|
|
41
43
|
const result = app.requestSingleInstanceLock();
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
window
|
|
45
|
-
|
|
46
|
-
window.
|
|
44
|
+
if (result) {
|
|
45
|
+
app.on("second-instance", () => {
|
|
46
|
+
if (window) {
|
|
47
|
+
window.show();
|
|
48
|
+
if (window.isMinimized()) {
|
|
49
|
+
window.restore();
|
|
50
|
+
}
|
|
51
|
+
window.focus();
|
|
47
52
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
});
|
|
54
|
+
} else {
|
|
55
|
+
app.quit();
|
|
56
|
+
}
|
|
51
57
|
return result;
|
|
52
58
|
}
|
|
53
59
|
function setPortableAppDataPath(dirName = "data") {
|
|
@@ -69,7 +75,11 @@ function waitAppReady(timeout = 1e3) {
|
|
|
69
75
|
});
|
|
70
76
|
}
|
|
71
77
|
function loadPage(win, htmlFilePath = "index.html") {
|
|
72
|
-
|
|
78
|
+
if (isDev) {
|
|
79
|
+
win.loadURL(process.env.VITE_DEV_SERVER_URL + htmlFilePath);
|
|
80
|
+
} else {
|
|
81
|
+
win.loadFile(getPathFromAppNameAsar("renderer", htmlFilePath));
|
|
82
|
+
}
|
|
73
83
|
}
|
|
74
84
|
function getPathFromPreload(...paths) {
|
|
75
85
|
return isDev ? join(app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
|
|
@@ -95,7 +105,7 @@ async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
|
|
|
95
105
|
reject(err);
|
|
96
106
|
}
|
|
97
107
|
writeFileSync(targetFilePath, buffer2);
|
|
98
|
-
resolve(
|
|
108
|
+
resolve();
|
|
99
109
|
});
|
|
100
110
|
});
|
|
101
111
|
}
|
|
@@ -115,7 +125,7 @@ async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
|
|
|
115
125
|
reject(err);
|
|
116
126
|
}
|
|
117
127
|
writeFileSync2(targetFilePath, buffer);
|
|
118
|
-
resolve(
|
|
128
|
+
resolve();
|
|
119
129
|
});
|
|
120
130
|
});
|
|
121
131
|
}
|
|
@@ -195,7 +205,7 @@ function verifySignatureDefault(buffer, signature2, cert) {
|
|
|
195
205
|
const [sig, version] = decrypt(signature2, hashString(cert, 32), hashString(buffer, 16)).split("%");
|
|
196
206
|
const result = createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
|
|
197
207
|
return result ? version : void 0;
|
|
198
|
-
} catch
|
|
208
|
+
} catch {
|
|
199
209
|
return void 0;
|
|
200
210
|
}
|
|
201
211
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
declare function decrypt(encryptedText: string, key: Buffer, iv: Buffer): string;
|
|
2
|
-
declare function verifySignatureDefault(buffer: Buffer, signature: string, cert: string): string | undefined
|
|
2
|
+
declare function verifySignatureDefault(buffer: Buffer, signature: string, cert: string): string | undefined;
|
|
3
3
|
|
|
4
4
|
export { decrypt as d, verifySignatureDefault as v };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
declare function decrypt(encryptedText: string, key: Buffer, iv: Buffer): string;
|
|
2
|
-
declare function verifySignatureDefault(buffer: Buffer, signature: string, cert: string): string | undefined
|
|
2
|
+
declare function verifySignatureDefault(buffer: Buffer, signature: string, cert: string): string | undefined;
|
|
3
3
|
|
|
4
4
|
export { decrypt as d, verifySignatureDefault as v };
|
package/dist/index.cjs
CHANGED
|
@@ -33,6 +33,7 @@ var import_electron4 = require("electron");
|
|
|
33
33
|
|
|
34
34
|
// src/updater/core.ts
|
|
35
35
|
var import_node_fs3 = require("fs");
|
|
36
|
+
var import_node_stream = require("stream");
|
|
36
37
|
var import_electron2 = require("electron");
|
|
37
38
|
|
|
38
39
|
// src/utils/version.ts
|
|
@@ -78,7 +79,7 @@ async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
|
|
|
78
79
|
reject(err);
|
|
79
80
|
}
|
|
80
81
|
(0, import_node_fs2.writeFileSync)(targetFilePath, buffer);
|
|
81
|
-
resolve(
|
|
82
|
+
resolve();
|
|
82
83
|
});
|
|
83
84
|
});
|
|
84
85
|
}
|
|
@@ -87,17 +88,18 @@ async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
|
|
|
87
88
|
var ErrorInfo = {
|
|
88
89
|
download: "Download failed",
|
|
89
90
|
validate: "Validate failed",
|
|
90
|
-
param: "Missing params"
|
|
91
|
-
version: "Unsatisfied version"
|
|
91
|
+
param: "Missing params"
|
|
92
92
|
};
|
|
93
93
|
var UpdaterError = class extends Error {
|
|
94
|
+
code;
|
|
94
95
|
constructor(msg, info) {
|
|
95
|
-
super(msg + ": " + info);
|
|
96
|
+
super(ErrorInfo[msg] + ": " + info);
|
|
97
|
+
this.code = msg;
|
|
96
98
|
}
|
|
97
99
|
};
|
|
98
100
|
|
|
99
101
|
// src/updater/core.ts
|
|
100
|
-
var Updater = class {
|
|
102
|
+
var Updater = class extends import_node_stream.EventEmitter {
|
|
101
103
|
CERT = __EIU_SIGNATURE_CERT__;
|
|
102
104
|
info;
|
|
103
105
|
options;
|
|
@@ -109,19 +111,10 @@ var Updater = class {
|
|
|
109
111
|
* updater logger
|
|
110
112
|
*/
|
|
111
113
|
logger;
|
|
112
|
-
/**
|
|
113
|
-
* downloading progress hook
|
|
114
|
-
* @param progress download progress
|
|
115
|
-
* @example
|
|
116
|
-
* updater.onDownloading = ({ percent, total, current }) => {
|
|
117
|
-
* console.log(`download progress: ${percent}, total: ${total}, current: ${current}`)
|
|
118
|
-
* }
|
|
119
|
-
*/
|
|
120
|
-
onDownloading;
|
|
121
114
|
/**
|
|
122
115
|
* URL handler hook
|
|
123
116
|
*
|
|
124
|
-
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public
|
|
117
|
+
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public CDNs}
|
|
125
118
|
* @param url source url
|
|
126
119
|
* @param isDownloadAsar whether is download asar
|
|
127
120
|
*/
|
|
@@ -141,6 +134,7 @@ var Updater = class {
|
|
|
141
134
|
* @param option UpdaterOption
|
|
142
135
|
*/
|
|
143
136
|
constructor(provider, option = {}) {
|
|
137
|
+
super();
|
|
144
138
|
this.provider = provider;
|
|
145
139
|
this.options = option;
|
|
146
140
|
if (option.SIGNATURE_CERT) {
|
|
@@ -149,25 +143,20 @@ var Updater = class {
|
|
|
149
143
|
if (option.logger) {
|
|
150
144
|
this.logger = option.logger;
|
|
151
145
|
}
|
|
146
|
+
if (isDev && !this.logger) {
|
|
147
|
+
this.logger = {
|
|
148
|
+
info: (...args) => console.log("[EIU-INFO ]", ...args),
|
|
149
|
+
debug: (...args) => console.log("[EIU-DEBUG]", ...args),
|
|
150
|
+
warn: (...args) => console.log("[EIU-WARN ]", ...args),
|
|
151
|
+
error: (...args) => console.error("[EIU-ERROR]", ...args)
|
|
152
|
+
};
|
|
153
|
+
this.logger.info("no logger set, enable dev-only logger");
|
|
154
|
+
}
|
|
152
155
|
this.asarPath = getPathFromAppNameAsar();
|
|
153
156
|
this.gzipPath = `${this.asarPath}.gz`;
|
|
154
157
|
this.tmpFilePath = `${this.asarPath}.tmp`;
|
|
155
158
|
}
|
|
156
|
-
async
|
|
157
|
-
if (isDev) {
|
|
158
|
-
this.logger?.warn(`in dev mode, skip check update`);
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
const isLowerVersion = this.provider.isLowerVersion;
|
|
162
|
-
const entryVersion = getEntryVersion();
|
|
163
|
-
const appVersion = getAppVersion();
|
|
164
|
-
if (await isLowerVersion(entryVersion, minVersion)) {
|
|
165
|
-
throw new UpdaterError(ErrorInfo.version, `entry version (${entryVersion}) < minimumVersion (${minVersion})`);
|
|
166
|
-
}
|
|
167
|
-
this.logger?.info(`check update: current version is ${appVersion}, new version is ${version}`);
|
|
168
|
-
return await isLowerVersion(appVersion, version);
|
|
169
|
-
}
|
|
170
|
-
async parseData(format, data) {
|
|
159
|
+
async fetch(format, data) {
|
|
171
160
|
if ((0, import_node_fs3.existsSync)(this.tmpFilePath)) {
|
|
172
161
|
this.logger?.warn(`remove tmp file: ${this.tmpFilePath}`);
|
|
173
162
|
(0, import_node_fs3.rmSync)(this.tmpFilePath);
|
|
@@ -180,71 +169,96 @@ var Updater = class {
|
|
|
180
169
|
if (format === "json" && isUpdateJSON(data) || format === "buffer" && Buffer.isBuffer(data)) {
|
|
181
170
|
return data;
|
|
182
171
|
} else {
|
|
183
|
-
|
|
172
|
+
this.err("invalid type", "param", `invalid type at format '${format}': ${JSON.stringify(data)}`);
|
|
173
|
+
return;
|
|
184
174
|
}
|
|
185
175
|
}
|
|
186
176
|
this.logger?.debug(`download from ${this.provider.name}`);
|
|
187
177
|
try {
|
|
188
|
-
const result = format === "json" ? await this.provider.downloadJSON(data ?? __EIU_VERSION_PATH__) : await this.provider.
|
|
178
|
+
const result = format === "json" ? await this.provider.downloadJSON(data ?? __EIU_VERSION_PATH__) : await this.provider.downloadAsar(import_electron2.app.name, this.info, (data2) => this.emit("download-progress", data2));
|
|
189
179
|
this.logger?.debug(`download ${format} success${format === "buffer" ? `, file size: ${result.length}` : ""}`);
|
|
190
180
|
return result;
|
|
191
181
|
} catch (e) {
|
|
192
|
-
this.
|
|
193
|
-
throw new UpdaterError(ErrorInfo.download, `download ${format} failed: ${e}`);
|
|
182
|
+
this.err(`download ${format} failed`, "download", `download ${format} failed: ${e}`);
|
|
194
183
|
}
|
|
195
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* handle error message and emit error event
|
|
187
|
+
*/
|
|
188
|
+
err(msg, code, errorInfo) {
|
|
189
|
+
const err = new UpdaterError(code, errorInfo);
|
|
190
|
+
this.logger?.error(msg, err);
|
|
191
|
+
this.emit("error", err);
|
|
192
|
+
}
|
|
196
193
|
async checkUpdate(data) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
this.logger?.debug(`checked update, version: ${version}, size: ${size}, signature: ${signature}`);
|
|
206
|
-
if (!await this.needUpdate(version, minimumVersion)) {
|
|
207
|
-
this.logger?.info(`update unavailable: ${version} is the latest version`);
|
|
208
|
-
return { success: false, data: version };
|
|
209
|
-
} else {
|
|
210
|
-
this.logger?.info(`update available: ${version}`);
|
|
211
|
-
this.info = { signature, minimumVersion, version, size };
|
|
212
|
-
return { success: true, data: this.info };
|
|
213
|
-
}
|
|
214
|
-
} catch (error) {
|
|
215
|
-
this.logger?.error("check update failed", error);
|
|
216
|
-
return {
|
|
217
|
-
success: false,
|
|
218
|
-
data: error instanceof UpdaterError ? error : new UpdaterError(ErrorInfo.download, error.toString())
|
|
219
|
-
};
|
|
194
|
+
const emitUnavailable = (msg) => {
|
|
195
|
+
this.logger?.info(msg);
|
|
196
|
+
this.emit("update-unavailable", msg);
|
|
197
|
+
};
|
|
198
|
+
const _data = await this.fetch("json", data);
|
|
199
|
+
if (!_data) {
|
|
200
|
+
emitUnavailable("failed to get update info");
|
|
201
|
+
return false;
|
|
220
202
|
}
|
|
203
|
+
let { signature, size, version, minimumVersion, beta } = _data;
|
|
204
|
+
if (this.receiveBeta) {
|
|
205
|
+
version = beta.version;
|
|
206
|
+
signature = beta.signature;
|
|
207
|
+
minimumVersion = beta.minimumVersion;
|
|
208
|
+
size = beta.size;
|
|
209
|
+
}
|
|
210
|
+
this.logger?.debug(`checked update, version: ${version}, size: ${size}, signature: ${signature}`);
|
|
211
|
+
if (isDev) {
|
|
212
|
+
emitUnavailable("in dev mode, skip check update");
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
const isLowerVersion = this.provider.isLowerVersion;
|
|
216
|
+
const entryVersion = getEntryVersion();
|
|
217
|
+
const appVersion = getAppVersion();
|
|
218
|
+
if (isLowerVersion(entryVersion, minimumVersion)) {
|
|
219
|
+
emitUnavailable(`entry version (${entryVersion}) < minimumVersion (${minimumVersion})`);
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
this.logger?.info(`check update: current version is ${appVersion}, new version is ${version}`);
|
|
223
|
+
if (!isLowerVersion(appVersion, version)) {
|
|
224
|
+
emitUnavailable(`current version (${appVersion}) < new version (${version})`);
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
this.logger?.info(`update available: ${version}`);
|
|
228
|
+
this.info = { signature, minimumVersion, version, size };
|
|
229
|
+
this.emit("update-available", this.info);
|
|
230
|
+
return true;
|
|
221
231
|
}
|
|
222
232
|
async download(data, sig) {
|
|
233
|
+
if (!this.info) {
|
|
234
|
+
this.err("download failed", "param", "no update info, call `checkUpdate` first");
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
const _sig = sig ?? this.info.signature;
|
|
238
|
+
const buffer = await this.fetch("buffer", data ? Buffer.from(data) : void 0);
|
|
239
|
+
if (!buffer) {
|
|
240
|
+
this.err("download failed", "param", "no update asar file buffer");
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
this.logger?.debug("verify start");
|
|
244
|
+
const _ver = await this.provider.verifySignaure(buffer, _sig, this.CERT);
|
|
245
|
+
if (!_ver) {
|
|
246
|
+
this.err("verify failed", "validate", "invalid signature / certificate pair");
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
this.logger?.debug("verify success");
|
|
223
250
|
try {
|
|
224
|
-
if (!this.info) {
|
|
225
|
-
throw new UpdaterError(ErrorInfo.param, "no update info");
|
|
226
|
-
}
|
|
227
|
-
const _sig = sig ?? this.info.signature;
|
|
228
|
-
const buffer = await this.parseData("buffer", data);
|
|
229
|
-
this.logger?.debug("verify start");
|
|
230
|
-
const _ver = await this.provider.verifySignaure(buffer, _sig, this.CERT);
|
|
231
|
-
if (!_ver) {
|
|
232
|
-
throw new UpdaterError(ErrorInfo.validate, "invalid signature or certificate");
|
|
233
|
-
}
|
|
234
|
-
this.logger?.debug("verify success");
|
|
235
251
|
this.logger?.debug(`write to ${this.gzipPath}`);
|
|
236
252
|
(0, import_node_fs3.writeFileSync)(this.gzipPath, buffer);
|
|
237
253
|
this.logger?.debug(`extract to ${this.tmpFilePath}`);
|
|
238
254
|
await unzipFile(this.gzipPath, this.tmpFilePath);
|
|
239
255
|
this.logger?.info(`download success, version: ${_ver}`);
|
|
240
256
|
this.info = void 0;
|
|
241
|
-
|
|
257
|
+
this.emit("update-downloaded");
|
|
258
|
+
return true;
|
|
242
259
|
} catch (error) {
|
|
243
|
-
this.
|
|
244
|
-
return
|
|
245
|
-
success: false,
|
|
246
|
-
data: error instanceof UpdaterError ? error : new UpdaterError(ErrorInfo.download, error.toString())
|
|
247
|
-
};
|
|
260
|
+
this.err("unwrap asar failed", "download", `fail to unwrap asar file, ${error}`);
|
|
261
|
+
return false;
|
|
248
262
|
}
|
|
249
263
|
}
|
|
250
264
|
/**
|
package/dist/index.d.cts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { EventEmitter } from 'node:stream';
|
|
2
|
+
import { U as UpdateJSON, a as UpdateInfo } from './version-CffZWDhZ.cjs';
|
|
3
|
+
import { D as DownloadingInfo, U as URLHandler, I as IProvider } from './types-COqp44eg.cjs';
|
|
3
4
|
import '@subframe7536/type-utils';
|
|
4
5
|
|
|
5
6
|
declare const ErrorInfo: {
|
|
6
7
|
readonly download: "Download failed";
|
|
7
8
|
readonly validate: "Validate failed";
|
|
8
9
|
readonly param: "Missing params";
|
|
9
|
-
readonly version: "Unsatisfied version";
|
|
10
10
|
};
|
|
11
11
|
declare class UpdaterError extends Error {
|
|
12
|
-
|
|
12
|
+
code: keyof typeof ErrorInfo;
|
|
13
|
+
constructor(msg: keyof typeof ErrorInfo, info: string);
|
|
13
14
|
}
|
|
14
15
|
type CheckResult<T extends UpdateJSON> = {
|
|
15
16
|
success: true;
|
|
@@ -49,7 +50,14 @@ interface UpdaterOption {
|
|
|
49
50
|
logger?: Logger;
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
declare class Updater {
|
|
53
|
+
declare class Updater extends EventEmitter<{
|
|
54
|
+
'checking': any;
|
|
55
|
+
'update-available': [data: UpdateInfo];
|
|
56
|
+
'update-unavailable': [reason: string];
|
|
57
|
+
'error': [error: UpdaterError];
|
|
58
|
+
'download-progress': [info: DownloadingInfo];
|
|
59
|
+
'update-downloaded': any;
|
|
60
|
+
}> {
|
|
53
61
|
private CERT;
|
|
54
62
|
private info?;
|
|
55
63
|
private options;
|
|
@@ -61,19 +69,10 @@ declare class Updater {
|
|
|
61
69
|
* updater logger
|
|
62
70
|
*/
|
|
63
71
|
logger?: Logger;
|
|
64
|
-
/**
|
|
65
|
-
* downloading progress hook
|
|
66
|
-
* @param progress download progress
|
|
67
|
-
* @example
|
|
68
|
-
* updater.onDownloading = ({ percent, total, current }) => {
|
|
69
|
-
* console.log(`download progress: ${percent}, total: ${total}, current: ${current}`)
|
|
70
|
-
* }
|
|
71
|
-
*/
|
|
72
|
-
onDownloading?: OnDownloading;
|
|
73
72
|
/**
|
|
74
73
|
* URL handler hook
|
|
75
74
|
*
|
|
76
|
-
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public
|
|
75
|
+
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public CDNs}
|
|
77
76
|
* @param url source url
|
|
78
77
|
* @param isDownloadAsar whether is download asar
|
|
79
78
|
*/
|
|
@@ -89,7 +88,6 @@ declare class Updater {
|
|
|
89
88
|
* @param option UpdaterOption
|
|
90
89
|
*/
|
|
91
90
|
constructor(provider: IProvider, option?: UpdaterOption);
|
|
92
|
-
private needUpdate;
|
|
93
91
|
/**
|
|
94
92
|
* this function is used to parse download data.
|
|
95
93
|
* - if format is `'json'`
|
|
@@ -101,36 +99,30 @@ declare class Updater {
|
|
|
101
99
|
* @param format 'json' or 'buffer'
|
|
102
100
|
* @param data download URL or update json or buffer
|
|
103
101
|
*/
|
|
104
|
-
private
|
|
102
|
+
private fetch;
|
|
105
103
|
/**
|
|
106
|
-
*
|
|
104
|
+
* handle error message and emit error event
|
|
107
105
|
*/
|
|
108
|
-
|
|
106
|
+
private err;
|
|
109
107
|
/**
|
|
110
|
-
* check update info using
|
|
111
|
-
* @param url custom download URL of `updatejson`
|
|
108
|
+
* check update info using default options
|
|
112
109
|
*/
|
|
113
|
-
checkUpdate
|
|
110
|
+
checkUpdate(): Promise<boolean>;
|
|
114
111
|
/**
|
|
115
112
|
* check update info using existing update json
|
|
116
113
|
* @param data existing update json
|
|
117
114
|
*/
|
|
118
|
-
checkUpdate
|
|
115
|
+
checkUpdate(data: UpdateJSON): Promise<boolean>;
|
|
119
116
|
/**
|
|
120
117
|
* download update using default options
|
|
121
118
|
*/
|
|
122
|
-
download(): Promise<
|
|
123
|
-
/**
|
|
124
|
-
* download update using custom url
|
|
125
|
-
* @param url custom download URL
|
|
126
|
-
*/
|
|
127
|
-
download(url: string): Promise<DownloadResult>;
|
|
119
|
+
download(): Promise<boolean>;
|
|
128
120
|
/**
|
|
129
121
|
* download update using existing `asar.gz` buffer and signature
|
|
130
122
|
* @param data existing `asar.gz` buffer
|
|
131
123
|
* @param sig signature
|
|
132
124
|
*/
|
|
133
|
-
download(data:
|
|
125
|
+
download(data: Uint8Array, sig: string): Promise<boolean>;
|
|
134
126
|
/**
|
|
135
127
|
* quit App and install
|
|
136
128
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { EventEmitter } from 'node:stream';
|
|
2
|
+
import { U as UpdateJSON, a as UpdateInfo } from './version-CffZWDhZ.js';
|
|
3
|
+
import { D as DownloadingInfo, U as URLHandler, I as IProvider } from './types-CPq1MrYZ.js';
|
|
3
4
|
import '@subframe7536/type-utils';
|
|
4
5
|
|
|
5
6
|
declare const ErrorInfo: {
|
|
6
7
|
readonly download: "Download failed";
|
|
7
8
|
readonly validate: "Validate failed";
|
|
8
9
|
readonly param: "Missing params";
|
|
9
|
-
readonly version: "Unsatisfied version";
|
|
10
10
|
};
|
|
11
11
|
declare class UpdaterError extends Error {
|
|
12
|
-
|
|
12
|
+
code: keyof typeof ErrorInfo;
|
|
13
|
+
constructor(msg: keyof typeof ErrorInfo, info: string);
|
|
13
14
|
}
|
|
14
15
|
type CheckResult<T extends UpdateJSON> = {
|
|
15
16
|
success: true;
|
|
@@ -49,7 +50,14 @@ interface UpdaterOption {
|
|
|
49
50
|
logger?: Logger;
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
declare class Updater {
|
|
53
|
+
declare class Updater extends EventEmitter<{
|
|
54
|
+
'checking': any;
|
|
55
|
+
'update-available': [data: UpdateInfo];
|
|
56
|
+
'update-unavailable': [reason: string];
|
|
57
|
+
'error': [error: UpdaterError];
|
|
58
|
+
'download-progress': [info: DownloadingInfo];
|
|
59
|
+
'update-downloaded': any;
|
|
60
|
+
}> {
|
|
53
61
|
private CERT;
|
|
54
62
|
private info?;
|
|
55
63
|
private options;
|
|
@@ -61,19 +69,10 @@ declare class Updater {
|
|
|
61
69
|
* updater logger
|
|
62
70
|
*/
|
|
63
71
|
logger?: Logger;
|
|
64
|
-
/**
|
|
65
|
-
* downloading progress hook
|
|
66
|
-
* @param progress download progress
|
|
67
|
-
* @example
|
|
68
|
-
* updater.onDownloading = ({ percent, total, current }) => {
|
|
69
|
-
* console.log(`download progress: ${percent}, total: ${total}, current: ${current}`)
|
|
70
|
-
* }
|
|
71
|
-
*/
|
|
72
|
-
onDownloading?: OnDownloading;
|
|
73
72
|
/**
|
|
74
73
|
* URL handler hook
|
|
75
74
|
*
|
|
76
|
-
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public
|
|
75
|
+
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public CDNs}
|
|
77
76
|
* @param url source url
|
|
78
77
|
* @param isDownloadAsar whether is download asar
|
|
79
78
|
*/
|
|
@@ -89,7 +88,6 @@ declare class Updater {
|
|
|
89
88
|
* @param option UpdaterOption
|
|
90
89
|
*/
|
|
91
90
|
constructor(provider: IProvider, option?: UpdaterOption);
|
|
92
|
-
private needUpdate;
|
|
93
91
|
/**
|
|
94
92
|
* this function is used to parse download data.
|
|
95
93
|
* - if format is `'json'`
|
|
@@ -101,36 +99,30 @@ declare class Updater {
|
|
|
101
99
|
* @param format 'json' or 'buffer'
|
|
102
100
|
* @param data download URL or update json or buffer
|
|
103
101
|
*/
|
|
104
|
-
private
|
|
102
|
+
private fetch;
|
|
105
103
|
/**
|
|
106
|
-
*
|
|
104
|
+
* handle error message and emit error event
|
|
107
105
|
*/
|
|
108
|
-
|
|
106
|
+
private err;
|
|
109
107
|
/**
|
|
110
|
-
* check update info using
|
|
111
|
-
* @param url custom download URL of `updatejson`
|
|
108
|
+
* check update info using default options
|
|
112
109
|
*/
|
|
113
|
-
checkUpdate
|
|
110
|
+
checkUpdate(): Promise<boolean>;
|
|
114
111
|
/**
|
|
115
112
|
* check update info using existing update json
|
|
116
113
|
* @param data existing update json
|
|
117
114
|
*/
|
|
118
|
-
checkUpdate
|
|
115
|
+
checkUpdate(data: UpdateJSON): Promise<boolean>;
|
|
119
116
|
/**
|
|
120
117
|
* download update using default options
|
|
121
118
|
*/
|
|
122
|
-
download(): Promise<
|
|
123
|
-
/**
|
|
124
|
-
* download update using custom url
|
|
125
|
-
* @param url custom download URL
|
|
126
|
-
*/
|
|
127
|
-
download(url: string): Promise<DownloadResult>;
|
|
119
|
+
download(): Promise<boolean>;
|
|
128
120
|
/**
|
|
129
121
|
* download update using existing `asar.gz` buffer and signature
|
|
130
122
|
* @param data existing `asar.gz` buffer
|
|
131
123
|
* @param sig signature
|
|
132
124
|
*/
|
|
133
|
-
download(data:
|
|
125
|
+
download(data: Uint8Array, sig: string): Promise<boolean>;
|
|
134
126
|
/**
|
|
135
127
|
* quit App and install
|
|
136
128
|
*/
|