electron-incremental-update 2.0.0-beta.10 → 2.0.0-beta.11
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-IABBXJFB.js +87 -0
- package/dist/{chunk-72ZAJ7AF.js → chunk-RCRKUKFX.js} +1 -1
- package/dist/index.cjs +68 -48
- package/dist/index.d.cts +33 -25
- package/dist/index.d.ts +33 -25
- package/dist/index.js +65 -47
- package/dist/provider.cjs +58 -44
- package/dist/provider.d.cts +13 -13
- package/dist/provider.d.ts +13 -13
- package/dist/provider.js +58 -45
- package/dist/{types-Bnc4jz6R.d.ts → types-C8JhnJjU.d.ts} +6 -4
- package/dist/{types-DEYw5VrL.d.cts → types-CGSkHX4Y.d.cts} +6 -4
- package/dist/utils.cjs +25 -17
- package/dist/utils.d.cts +10 -3
- package/dist/utils.d.ts +10 -3
- package/dist/utils.js +2 -2
- package/dist/{version-C4tF_trh.d.cts → version-BYVQ367i.d.cts} +5 -5
- package/dist/{version-C4tF_trh.d.ts → version-BYVQ367i.d.ts} +5 -5
- package/dist/vite.d.ts +3 -1
- package/dist/vite.js +31 -18
- package/package.json +5 -5
- package/dist/chunk-4MH6ZXCY.js +0 -81
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isDev, getEntryVersion, getAppVersion, getPathFromAppNameAsar, restartApp } from './chunk-
|
|
2
|
-
import { isUpdateJSON, __require } from './chunk-
|
|
1
|
+
import { isDev, getEntryVersion, getAppVersion, getPathFromAppNameAsar, restartApp } from './chunk-IABBXJFB.js';
|
|
2
|
+
import { isUpdateJSON, __require } from './chunk-RCRKUKFX.js';
|
|
3
3
|
import fs2 from 'node:fs';
|
|
4
4
|
import { EventEmitter } from 'node:events';
|
|
5
5
|
import { app } from 'electron';
|
|
@@ -22,7 +22,8 @@ var UpdaterError = class extends Error {
|
|
|
22
22
|
|
|
23
23
|
// src/entry/updater.ts
|
|
24
24
|
var Updater = class extends EventEmitter {
|
|
25
|
-
CERT
|
|
25
|
+
CERT;
|
|
26
|
+
controller;
|
|
26
27
|
info;
|
|
27
28
|
provider;
|
|
28
29
|
/**
|
|
@@ -47,6 +48,7 @@ var Updater = class extends EventEmitter {
|
|
|
47
48
|
this.receiveBeta = options.receiveBeta;
|
|
48
49
|
this.CERT = options.SIGNATURE_CERT || __EIU_SIGNATURE_CERT__;
|
|
49
50
|
this.logger = options.logger;
|
|
51
|
+
this.controller = new AbortController();
|
|
50
52
|
if (isDev && !this.logger) {
|
|
51
53
|
this.logger = {
|
|
52
54
|
info: (...args) => console.log("[EIU-INFO ]", ...args),
|
|
@@ -54,15 +56,10 @@ var Updater = class extends EventEmitter {
|
|
|
54
56
|
warn: (...args) => console.log("[EIU-WARN ]", ...args),
|
|
55
57
|
error: (...args) => console.error("[EIU-ERROR]", ...args)
|
|
56
58
|
};
|
|
57
|
-
this.logger.info("
|
|
59
|
+
this.logger.info("No logger set, enable dev-only logger");
|
|
58
60
|
}
|
|
59
61
|
if (!this.provider) {
|
|
60
|
-
this.logger?.debug("No update provider
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
checkProvider() {
|
|
64
|
-
if (!this.provider) {
|
|
65
|
-
throw new UpdaterError("param", "missing update provider");
|
|
62
|
+
this.logger?.debug("WARN: No update provider");
|
|
66
63
|
}
|
|
67
64
|
}
|
|
68
65
|
async fetch(format, data) {
|
|
@@ -70,17 +67,17 @@ var Updater = class extends EventEmitter {
|
|
|
70
67
|
if (format === "json" && isUpdateJSON(data) || format === "buffer" && Buffer.isBuffer(data)) {
|
|
71
68
|
return data;
|
|
72
69
|
} else {
|
|
73
|
-
this.err("
|
|
70
|
+
this.err("Invalid type", "param", `Invalid type at format '${format}': ${JSON.stringify(data)}`);
|
|
74
71
|
return;
|
|
75
72
|
}
|
|
76
73
|
}
|
|
77
|
-
this.logger?.debug(`
|
|
74
|
+
this.logger?.debug(`Download from \`${this.provider.name}\``);
|
|
78
75
|
try {
|
|
79
|
-
const result = format === "json" ? await this.provider.downloadJSON(
|
|
80
|
-
this.logger?.debug(`
|
|
76
|
+
const result = format === "json" ? await this.provider.downloadJSON(__EIU_VERSION_PATH__, this.controller.signal) : await this.provider.downloadAsar(app.name, this.info, this.controller.signal, (info) => this.emit("download-progress", info));
|
|
77
|
+
this.logger?.debug(`Download ${format} success${format === "buffer" ? `, file size: ${result.length}` : ""}`);
|
|
81
78
|
return result;
|
|
82
79
|
} catch (e) {
|
|
83
|
-
this.err(`
|
|
80
|
+
this.err(`Fetch ${format} failed`, "network", `Download ${format} failed: ${e}`);
|
|
84
81
|
}
|
|
85
82
|
}
|
|
86
83
|
/**
|
|
@@ -91,16 +88,20 @@ var Updater = class extends EventEmitter {
|
|
|
91
88
|
this.logger?.error(msg, err);
|
|
92
89
|
this.emit("error", err);
|
|
93
90
|
}
|
|
94
|
-
async
|
|
95
|
-
this.checkProvider();
|
|
91
|
+
async checkForUpdates(data) {
|
|
96
92
|
const emitUnavailable = (msg) => {
|
|
97
93
|
this.logger?.info(msg);
|
|
98
|
-
this.emit("update-
|
|
94
|
+
this.emit("update-not-available", msg);
|
|
99
95
|
return false;
|
|
100
96
|
};
|
|
97
|
+
if (!data && !this.provider) {
|
|
98
|
+
const errorInfo = "No update json or provider";
|
|
99
|
+
this.err("Check update failed", "param", errorInfo);
|
|
100
|
+
return emitUnavailable(errorInfo);
|
|
101
|
+
}
|
|
101
102
|
const _data = await this.fetch("json", data);
|
|
102
103
|
if (!_data) {
|
|
103
|
-
return emitUnavailable("
|
|
104
|
+
return emitUnavailable("Failed to get update info");
|
|
104
105
|
}
|
|
105
106
|
let { signature, version, minimumVersion, beta } = _data;
|
|
106
107
|
if (this.receiveBeta) {
|
|
@@ -108,59 +109,62 @@ var Updater = class extends EventEmitter {
|
|
|
108
109
|
signature = beta.signature;
|
|
109
110
|
minimumVersion = beta.minimumVersion;
|
|
110
111
|
}
|
|
111
|
-
this.logger?.debug(`
|
|
112
|
+
this.logger?.debug(`Checked update, version: ${version}, signature: ${signature}`);
|
|
112
113
|
if (isDev && !this.forceUpdate && !data) {
|
|
113
|
-
return emitUnavailable("
|
|
114
|
+
return emitUnavailable("Skip check update in dev mode. To force update, set `updater.forceUpdate` to true or call checkUpdate with UpdateJSON");
|
|
114
115
|
}
|
|
115
116
|
const isLowerVersion = this.provider.isLowerVersion;
|
|
116
117
|
const entryVersion = getEntryVersion();
|
|
117
118
|
const appVersion = getAppVersion();
|
|
118
119
|
try {
|
|
119
120
|
if (isLowerVersion(entryVersion, minimumVersion)) {
|
|
120
|
-
return emitUnavailable(`
|
|
121
|
+
return emitUnavailable(`Entry Version (${entryVersion}) < MinimumVersion (${minimumVersion})`);
|
|
121
122
|
}
|
|
122
|
-
this.logger?.info(`
|
|
123
|
+
this.logger?.info(`Check update: current version is ${appVersion}, new version is ${version}`);
|
|
123
124
|
if (!isLowerVersion(appVersion, version)) {
|
|
124
|
-
return emitUnavailable(`
|
|
125
|
+
return emitUnavailable(`Current version (${appVersion}) < New version (${version})`);
|
|
125
126
|
}
|
|
126
|
-
this.logger?.info(`
|
|
127
|
+
this.logger?.info(`Update available: ${version}`);
|
|
127
128
|
this.info = { signature, minimumVersion, version };
|
|
128
129
|
this.emit("update-available", this.info);
|
|
129
130
|
return true;
|
|
130
131
|
} catch {
|
|
131
|
-
this.err("Fail to parse version", "validate", "
|
|
132
|
+
this.err("Fail to parse version", "validate", "Fail to parse version string");
|
|
132
133
|
return false;
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
136
|
async downloadUpdate(data, info) {
|
|
136
|
-
this.checkProvider();
|
|
137
137
|
const _sig = info?.signature ?? this.info?.signature;
|
|
138
138
|
const _version = info?.version ?? this.info?.version;
|
|
139
139
|
if (!_sig || !_version) {
|
|
140
|
-
this.err("
|
|
140
|
+
this.err("Download failed", "param", "No update signature, please call `checkUpdate` first or manually setup params");
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
if (!data && !this.provider) {
|
|
144
|
+
this.err("Download failed", "param", "No update asar buffer and provider");
|
|
141
145
|
return false;
|
|
142
146
|
}
|
|
143
147
|
const buffer = await this.fetch("buffer", data ? Buffer.from(data) : void 0);
|
|
144
148
|
if (!buffer) {
|
|
145
|
-
this.err("
|
|
149
|
+
this.err("Download failed", "param", "No update asar file buffer");
|
|
146
150
|
return false;
|
|
147
151
|
}
|
|
148
152
|
this.logger?.debug("verify start");
|
|
149
153
|
if (!await this.provider.verifySignaure(buffer, _version, _sig, this.CERT)) {
|
|
150
|
-
this.err("
|
|
154
|
+
this.err("Download failed", "validate", "Invalid update asar file");
|
|
151
155
|
return false;
|
|
152
156
|
}
|
|
153
|
-
this.logger?.debug("
|
|
157
|
+
this.logger?.debug("Verify success");
|
|
154
158
|
try {
|
|
155
159
|
const tmpFilePath = getPathFromAppNameAsar() + ".tmp";
|
|
156
|
-
this.logger?.debug(`
|
|
160
|
+
this.logger?.debug(`Install to ${tmpFilePath}`);
|
|
157
161
|
fs2.writeFileSync(tmpFilePath, await this.provider.unzipFile(buffer));
|
|
158
|
-
this.logger?.info(`
|
|
162
|
+
this.logger?.info(`Download success, version: ${_version}`);
|
|
159
163
|
this.info = void 0;
|
|
160
164
|
this.emit("update-downloaded");
|
|
161
165
|
return true;
|
|
162
166
|
} catch (error) {
|
|
163
|
-
this.err("
|
|
167
|
+
this.err("Download failed", "download", `Fail to unwrap asar file, ${error}`);
|
|
164
168
|
return false;
|
|
165
169
|
}
|
|
166
170
|
}
|
|
@@ -168,12 +172,21 @@ var Updater = class extends EventEmitter {
|
|
|
168
172
|
* quit App and install
|
|
169
173
|
*/
|
|
170
174
|
quitAndInstall() {
|
|
171
|
-
this.logger?.info("
|
|
175
|
+
this.logger?.info("Quit and install");
|
|
172
176
|
restartApp();
|
|
173
177
|
}
|
|
178
|
+
cancel() {
|
|
179
|
+
if (this.controller.signal.aborted) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
this.controller.abort();
|
|
183
|
+
this.logger?.info("Cancel update");
|
|
184
|
+
this.emit("update-cancelled");
|
|
185
|
+
this.controller = new AbortController();
|
|
186
|
+
}
|
|
174
187
|
};
|
|
175
188
|
async function autoUpdate(updater) {
|
|
176
|
-
if (await updater.
|
|
189
|
+
if (await updater.checkForUpdates() && await updater.downloadUpdate()) {
|
|
177
190
|
updater.quitAndInstall();
|
|
178
191
|
}
|
|
179
192
|
}
|
|
@@ -184,8 +197,14 @@ var defaultOnInstall = (install, _, __, logger) => {
|
|
|
184
197
|
install();
|
|
185
198
|
logger?.info(`update success!`);
|
|
186
199
|
};
|
|
187
|
-
async function
|
|
200
|
+
async function createElectronApp(appOptions = {}) {
|
|
201
|
+
const appNameAsarPath = getPathFromAppNameAsar();
|
|
188
202
|
const {
|
|
203
|
+
mainPath = path.join(
|
|
204
|
+
isDev ? path.join(app.getAppPath(), __EIU_MAIN_DEV_DIR__) : appNameAsarPath,
|
|
205
|
+
"main",
|
|
206
|
+
__EIU_MAIN_FILE__
|
|
207
|
+
),
|
|
189
208
|
updater,
|
|
190
209
|
onInstall = defaultOnInstall,
|
|
191
210
|
beforeStart,
|
|
@@ -199,24 +218,23 @@ async function initApp(appOptions = {}) {
|
|
|
199
218
|
}
|
|
200
219
|
const logger = updaterInstance.logger;
|
|
201
220
|
try {
|
|
202
|
-
const appNameAsarPath = getPathFromAppNameAsar();
|
|
203
221
|
const tempAsarPath = `${appNameAsarPath}.tmp`;
|
|
204
222
|
if (fs2.existsSync(tempAsarPath)) {
|
|
205
|
-
logger?.info(`
|
|
223
|
+
logger?.info(`Installing new asar from ${tempAsarPath}`);
|
|
206
224
|
await onInstall(() => fs2.renameSync(tempAsarPath, appNameAsarPath), tempAsarPath, appNameAsarPath, logger);
|
|
207
225
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
"
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
__require(mainFilePath)(updaterInstance);
|
|
226
|
+
await beforeStart?.(mainPath, logger);
|
|
227
|
+
if (__EIU_IS_ESM__) {
|
|
228
|
+
(await import("file://" + mainPath)).default(updaterInstance);
|
|
229
|
+
} else {
|
|
230
|
+
__require(mainPath)(updaterInstance);
|
|
231
|
+
}
|
|
215
232
|
} catch (error) {
|
|
216
233
|
logger?.error("startup error", error);
|
|
217
234
|
onStartError?.(error, logger);
|
|
218
235
|
app.quit();
|
|
219
236
|
}
|
|
220
237
|
}
|
|
238
|
+
var initApp = createElectronApp;
|
|
221
239
|
|
|
222
|
-
export { ErrorInfo, Updater, UpdaterError, autoUpdate, initApp, startupWithUpdater };
|
|
240
|
+
export { ErrorInfo, Updater, UpdaterError, autoUpdate, createElectronApp, initApp, startupWithUpdater };
|
package/dist/provider.cjs
CHANGED
|
@@ -7,6 +7,7 @@ var zlib = require('zlib');
|
|
|
7
7
|
|
|
8
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
9
|
|
|
10
|
+
var electron__default = /*#__PURE__*/_interopDefault(electron);
|
|
10
11
|
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
11
12
|
var zlib__default = /*#__PURE__*/_interopDefault(zlib);
|
|
12
13
|
|
|
@@ -32,7 +33,7 @@ function parseVersion(version) {
|
|
|
32
33
|
ret.stageVersion = Number(_v) || -1;
|
|
33
34
|
}
|
|
34
35
|
if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
|
|
35
|
-
throw new TypeError(`
|
|
36
|
+
throw new TypeError(`Invalid version: ${version}`);
|
|
36
37
|
}
|
|
37
38
|
return ret;
|
|
38
39
|
}
|
|
@@ -70,10 +71,11 @@ function getHeader(headers, key) {
|
|
|
70
71
|
return value;
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
|
-
async function downloadFn(url, headers, onResponse) {
|
|
74
|
-
await
|
|
74
|
+
async function downloadFn(url, headers, signal, onResponse) {
|
|
75
|
+
await electron__default.default.app.whenReady();
|
|
75
76
|
return new Promise((resolve, reject) => {
|
|
76
|
-
const request =
|
|
77
|
+
const request = electron__default.default.net.request({ url, method: "GET", redirect: "follow", headers, cache: "no-cache" });
|
|
78
|
+
signal.addEventListener("abort", () => request.abort(), { once: true });
|
|
77
79
|
request.on("response", (resp) => {
|
|
78
80
|
resp.on("aborted", () => reject(new Error("aborted")));
|
|
79
81
|
resp.on("error", () => reject(new Error("download error")));
|
|
@@ -83,46 +85,56 @@ async function downloadFn(url, headers, onResponse) {
|
|
|
83
85
|
request.end();
|
|
84
86
|
});
|
|
85
87
|
}
|
|
86
|
-
async function defaultDownloadUpdateJSON(url, headers) {
|
|
87
|
-
return await downloadFn(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
88
|
+
async function defaultDownloadUpdateJSON(url, headers, signal) {
|
|
89
|
+
return await downloadFn(
|
|
90
|
+
url,
|
|
91
|
+
headers,
|
|
92
|
+
signal,
|
|
93
|
+
(resp, resolve, reject) => {
|
|
94
|
+
let data = "";
|
|
95
|
+
resp.on("data", (chunk) => data += chunk);
|
|
96
|
+
resp.on("end", () => {
|
|
97
|
+
try {
|
|
98
|
+
const json = JSON.parse(data);
|
|
99
|
+
if (isUpdateJSON(json)) {
|
|
100
|
+
resolve(json);
|
|
101
|
+
} else {
|
|
102
|
+
throw Error;
|
|
103
|
+
}
|
|
104
|
+
} catch {
|
|
105
|
+
reject(new Error("invalid update json " + data));
|
|
97
106
|
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
});
|
|
102
|
-
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
);
|
|
103
110
|
}
|
|
104
|
-
async function defaultDownloadAsar(url, headers, onDownloading) {
|
|
111
|
+
async function defaultDownloadAsar(url, headers, signal, onDownloading) {
|
|
105
112
|
let transferred = 0;
|
|
106
113
|
let time = Date.now();
|
|
107
|
-
return await downloadFn(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
114
|
+
return await downloadFn(
|
|
115
|
+
url,
|
|
116
|
+
headers,
|
|
117
|
+
signal,
|
|
118
|
+
(resp, resolve) => {
|
|
119
|
+
const total = +getHeader(resp.headers, "content-length") || -1;
|
|
120
|
+
let data = [];
|
|
121
|
+
resp.on("data", (chunk) => {
|
|
122
|
+
const delta = chunk.length;
|
|
123
|
+
transferred += delta;
|
|
124
|
+
const current = Date.now();
|
|
125
|
+
onDownloading?.({
|
|
126
|
+
percent: total ? +(transferred / total).toFixed(2) * 100 : -1,
|
|
127
|
+
total,
|
|
128
|
+
transferred,
|
|
129
|
+
delta,
|
|
130
|
+
bps: delta / ((current - time) * 1e3)
|
|
131
|
+
});
|
|
132
|
+
time = current;
|
|
133
|
+
data.push(chunk);
|
|
120
134
|
});
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
resp.on("end", () => resolve(Buffer.concat(data)));
|
|
125
|
-
});
|
|
135
|
+
resp.on("end", () => resolve(Buffer.concat(data)));
|
|
136
|
+
}
|
|
137
|
+
);
|
|
126
138
|
}
|
|
127
139
|
function hashBuffer(data, length) {
|
|
128
140
|
const hash = crypto__default.default.createHash("SHA256").update(data).digest("binary");
|
|
@@ -181,7 +193,7 @@ var GitHubProvider = class extends BaseProvider {
|
|
|
181
193
|
* - download update json from `https://raw.githubusercontent.com/{user}/{repo}/HEAD/{versionPath}`
|
|
182
194
|
* - download update asar from `https://github.com/{user}/{repo}/releases/download/v{version}/{name}-{version}.asar.gz`
|
|
183
195
|
*
|
|
184
|
-
* you can setup `urlHandler` in {@link GitHubProviderOptions}
|
|
196
|
+
* you can setup `urlHandler` in {@link GitHubProviderOptions} to modify url before request
|
|
185
197
|
* @param options provider options
|
|
186
198
|
*/
|
|
187
199
|
constructor(options) {
|
|
@@ -199,7 +211,7 @@ var GitHubProvider = class extends BaseProvider {
|
|
|
199
211
|
}
|
|
200
212
|
async parseURL(isDownloadAsar, extraPath) {
|
|
201
213
|
const url$1 = new url.URL(
|
|
202
|
-
`/${this.options.
|
|
214
|
+
`/${this.options.user}/${this.options.repo}/${extraPath}`,
|
|
203
215
|
"https://" + (isDownloadAsar ? "github.com" : "raw.githubusercontent.com")
|
|
204
216
|
);
|
|
205
217
|
return (await this.urlHandler?.(url$1, isDownloadAsar) || url$1).toString();
|
|
@@ -207,19 +219,21 @@ var GitHubProvider = class extends BaseProvider {
|
|
|
207
219
|
/**
|
|
208
220
|
* @inheritdoc
|
|
209
221
|
*/
|
|
210
|
-
async downloadJSON(versionPath) {
|
|
222
|
+
async downloadJSON(versionPath, signal) {
|
|
211
223
|
return await defaultDownloadUpdateJSON(
|
|
212
224
|
await this.parseURL(false, `${this.options.branch}/${versionPath}`),
|
|
213
|
-
{ Accept: "application/json", ...this.options.extraHeaders }
|
|
225
|
+
{ Accept: "application/json", ...this.options.extraHeaders },
|
|
226
|
+
signal
|
|
214
227
|
);
|
|
215
228
|
}
|
|
216
229
|
/**
|
|
217
230
|
* @inheritdoc
|
|
218
231
|
*/
|
|
219
|
-
async downloadAsar(name, info, onDownloading) {
|
|
232
|
+
async downloadAsar(name, info, signal, onDownloading) {
|
|
220
233
|
return await defaultDownloadAsar(
|
|
221
234
|
await this.parseURL(true, `releases/download/v${info.version}/${name}-${info.version}.asar.gz`),
|
|
222
235
|
{ Accept: "application/octet-stream", ...this.options.extraHeaders },
|
|
236
|
+
signal,
|
|
223
237
|
onDownloading
|
|
224
238
|
);
|
|
225
239
|
}
|
package/dist/provider.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { d as defaultIsLowerVersion, a as UpdateJSON, U as UpdateInfo } from './version-
|
|
2
|
-
import { I as IProvider, D as DownloadingInfo, U as URLHandler, O as OnDownloading } from './types-
|
|
1
|
+
import { d as defaultIsLowerVersion, a as UpdateJSON, U as UpdateInfo } from './version-BYVQ367i.cjs';
|
|
2
|
+
import { I as IProvider, D as DownloadingInfo, U as URLHandler, O as OnDownloading } from './types-CGSkHX4Y.cjs';
|
|
3
3
|
import { f as defaultVerifySignature, a as defaultUnzipFile } from './zip-rm9ED9nU.cjs';
|
|
4
4
|
import { Arrayable } from '@subframe7536/type-utils';
|
|
5
5
|
|
|
@@ -20,18 +20,18 @@ declare abstract class BaseProvider implements IProvider {
|
|
|
20
20
|
/**
|
|
21
21
|
* @inheritdoc
|
|
22
22
|
*/
|
|
23
|
-
abstract downloadJSON(versionPath: string): Promise<UpdateJSON>;
|
|
23
|
+
abstract downloadJSON(versionPath: string, signal: AbortSignal): Promise<UpdateJSON>;
|
|
24
24
|
/**
|
|
25
25
|
* @inheritdoc
|
|
26
26
|
*/
|
|
27
|
-
abstract downloadAsar(name: string, info: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
|
|
27
|
+
abstract downloadAsar(name: string, info: UpdateInfo, signal: AbortSignal, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
interface GitHubProviderOptions {
|
|
31
31
|
/**
|
|
32
32
|
* Github user name
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
user: string;
|
|
35
35
|
/**
|
|
36
36
|
* Github repo name
|
|
37
37
|
*/
|
|
@@ -46,9 +46,7 @@ interface GitHubProviderOptions {
|
|
|
46
46
|
*/
|
|
47
47
|
extraHeaders?: Record<string, string>;
|
|
48
48
|
/**
|
|
49
|
-
* Custom url handler
|
|
50
|
-
*
|
|
51
|
-
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L40 public CDN links}
|
|
49
|
+
* Custom url handler ({@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L40 some public CDN links})
|
|
52
50
|
* @example
|
|
53
51
|
* (url, isDownloadAsar) => {
|
|
54
52
|
* if (isDownloadAsar) {
|
|
@@ -68,7 +66,7 @@ declare class GitHubProvider extends BaseProvider {
|
|
|
68
66
|
* - download update json from `https://raw.githubusercontent.com/{user}/{repo}/HEAD/{versionPath}`
|
|
69
67
|
* - download update asar from `https://github.com/{user}/{repo}/releases/download/v{version}/{name}-{version}.asar.gz`
|
|
70
68
|
*
|
|
71
|
-
* you can setup `urlHandler` in {@link GitHubProviderOptions}
|
|
69
|
+
* you can setup `urlHandler` in {@link GitHubProviderOptions} to modify url before request
|
|
72
70
|
* @param options provider options
|
|
73
71
|
*/
|
|
74
72
|
constructor(options: GitHubProviderOptions);
|
|
@@ -78,11 +76,11 @@ declare class GitHubProvider extends BaseProvider {
|
|
|
78
76
|
/**
|
|
79
77
|
* @inheritdoc
|
|
80
78
|
*/
|
|
81
|
-
downloadJSON(versionPath: string): Promise<UpdateJSON>;
|
|
79
|
+
downloadJSON(versionPath: string, signal: AbortSignal): Promise<UpdateJSON>;
|
|
82
80
|
/**
|
|
83
81
|
* @inheritdoc
|
|
84
82
|
*/
|
|
85
|
-
downloadAsar(name: string, info: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
|
|
83
|
+
downloadAsar(name: string, info: UpdateInfo, signal: AbortSignal, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
|
|
86
84
|
}
|
|
87
85
|
|
|
88
86
|
/**
|
|
@@ -95,15 +93,17 @@ declare function getHeader(headers: Record<string, Arrayable<string>>, key: any)
|
|
|
95
93
|
* Default function to download json and parse to UpdateJson
|
|
96
94
|
* @param url target url
|
|
97
95
|
* @param headers extra headers
|
|
96
|
+
* @param signal abort signal
|
|
98
97
|
*/
|
|
99
|
-
declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any
|
|
98
|
+
declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any>, signal: AbortSignal): Promise<UpdateJSON>;
|
|
100
99
|
/**
|
|
101
100
|
* Default function to download asar buffer,
|
|
102
101
|
* get total size from `Content-Length` header
|
|
103
102
|
* @param url target url
|
|
104
103
|
* @param headers extra headers
|
|
104
|
+
* @param signal abort signal
|
|
105
105
|
* @param onDownloading on downloading callback
|
|
106
106
|
*/
|
|
107
|
-
declare function defaultDownloadAsar(url: string, headers: Record<string, any>, onDownloading?: OnDownloading): Promise<Buffer>;
|
|
107
|
+
declare function defaultDownloadAsar(url: string, headers: Record<string, any>, signal: AbortSignal, onDownloading?: OnDownloading): Promise<Buffer>;
|
|
108
108
|
|
|
109
109
|
export { BaseProvider, DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, defaultDownloadAsar, defaultDownloadUpdateJSON, getHeader };
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { d as defaultIsLowerVersion, a as UpdateJSON, U as UpdateInfo } from './version-
|
|
2
|
-
import { I as IProvider, D as DownloadingInfo, U as URLHandler, O as OnDownloading } from './types-
|
|
1
|
+
import { d as defaultIsLowerVersion, a as UpdateJSON, U as UpdateInfo } from './version-BYVQ367i.js';
|
|
2
|
+
import { I as IProvider, D as DownloadingInfo, U as URLHandler, O as OnDownloading } from './types-C8JhnJjU.js';
|
|
3
3
|
import { f as defaultVerifySignature, a as defaultUnzipFile } from './zip-rm9ED9nU.js';
|
|
4
4
|
import { Arrayable } from '@subframe7536/type-utils';
|
|
5
5
|
|
|
@@ -20,18 +20,18 @@ declare abstract class BaseProvider implements IProvider {
|
|
|
20
20
|
/**
|
|
21
21
|
* @inheritdoc
|
|
22
22
|
*/
|
|
23
|
-
abstract downloadJSON(versionPath: string): Promise<UpdateJSON>;
|
|
23
|
+
abstract downloadJSON(versionPath: string, signal: AbortSignal): Promise<UpdateJSON>;
|
|
24
24
|
/**
|
|
25
25
|
* @inheritdoc
|
|
26
26
|
*/
|
|
27
|
-
abstract downloadAsar(name: string, info: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
|
|
27
|
+
abstract downloadAsar(name: string, info: UpdateInfo, signal: AbortSignal, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
interface GitHubProviderOptions {
|
|
31
31
|
/**
|
|
32
32
|
* Github user name
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
user: string;
|
|
35
35
|
/**
|
|
36
36
|
* Github repo name
|
|
37
37
|
*/
|
|
@@ -46,9 +46,7 @@ interface GitHubProviderOptions {
|
|
|
46
46
|
*/
|
|
47
47
|
extraHeaders?: Record<string, string>;
|
|
48
48
|
/**
|
|
49
|
-
* Custom url handler
|
|
50
|
-
*
|
|
51
|
-
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L40 public CDN links}
|
|
49
|
+
* Custom url handler ({@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L40 some public CDN links})
|
|
52
50
|
* @example
|
|
53
51
|
* (url, isDownloadAsar) => {
|
|
54
52
|
* if (isDownloadAsar) {
|
|
@@ -68,7 +66,7 @@ declare class GitHubProvider extends BaseProvider {
|
|
|
68
66
|
* - download update json from `https://raw.githubusercontent.com/{user}/{repo}/HEAD/{versionPath}`
|
|
69
67
|
* - download update asar from `https://github.com/{user}/{repo}/releases/download/v{version}/{name}-{version}.asar.gz`
|
|
70
68
|
*
|
|
71
|
-
* you can setup `urlHandler` in {@link GitHubProviderOptions}
|
|
69
|
+
* you can setup `urlHandler` in {@link GitHubProviderOptions} to modify url before request
|
|
72
70
|
* @param options provider options
|
|
73
71
|
*/
|
|
74
72
|
constructor(options: GitHubProviderOptions);
|
|
@@ -78,11 +76,11 @@ declare class GitHubProvider extends BaseProvider {
|
|
|
78
76
|
/**
|
|
79
77
|
* @inheritdoc
|
|
80
78
|
*/
|
|
81
|
-
downloadJSON(versionPath: string): Promise<UpdateJSON>;
|
|
79
|
+
downloadJSON(versionPath: string, signal: AbortSignal): Promise<UpdateJSON>;
|
|
82
80
|
/**
|
|
83
81
|
* @inheritdoc
|
|
84
82
|
*/
|
|
85
|
-
downloadAsar(name: string, info: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
|
|
83
|
+
downloadAsar(name: string, info: UpdateInfo, signal: AbortSignal, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
|
|
86
84
|
}
|
|
87
85
|
|
|
88
86
|
/**
|
|
@@ -95,15 +93,17 @@ declare function getHeader(headers: Record<string, Arrayable<string>>, key: any)
|
|
|
95
93
|
* Default function to download json and parse to UpdateJson
|
|
96
94
|
* @param url target url
|
|
97
95
|
* @param headers extra headers
|
|
96
|
+
* @param signal abort signal
|
|
98
97
|
*/
|
|
99
|
-
declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any
|
|
98
|
+
declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any>, signal: AbortSignal): Promise<UpdateJSON>;
|
|
100
99
|
/**
|
|
101
100
|
* Default function to download asar buffer,
|
|
102
101
|
* get total size from `Content-Length` header
|
|
103
102
|
* @param url target url
|
|
104
103
|
* @param headers extra headers
|
|
104
|
+
* @param signal abort signal
|
|
105
105
|
* @param onDownloading on downloading callback
|
|
106
106
|
*/
|
|
107
|
-
declare function defaultDownloadAsar(url: string, headers: Record<string, any>, onDownloading?: OnDownloading): Promise<Buffer>;
|
|
107
|
+
declare function defaultDownloadAsar(url: string, headers: Record<string, any>, signal: AbortSignal, onDownloading?: OnDownloading): Promise<Buffer>;
|
|
108
108
|
|
|
109
109
|
export { BaseProvider, DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, defaultDownloadAsar, defaultDownloadUpdateJSON, getHeader };
|