electron-incremental-update 1.1.0 → 1.3.0
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 +162 -25
- package/dist/chunk-7ET4GMTZ.js +236 -0
- package/dist/chunk-HWUYTDEF.js +236 -0
- package/dist/chunk-RQCTJY4L.js +236 -0
- package/dist/chunk-SBPTSLG7.js +235 -0
- package/dist/index.cjs +109 -168
- package/dist/index.d.cts +78 -59
- package/dist/index.d.ts +78 -59
- package/dist/index.js +104 -164
- package/dist/utils.cjs +5 -6
- package/dist/utils.d.cts +4 -4
- package/dist/utils.d.ts +4 -4
- package/dist/utils.js +1 -1
- package/dist/vite.d.ts +32 -6
- package/dist/vite.js +441 -80
- package/package.json +7 -2
package/dist/index.cjs
CHANGED
|
@@ -20,12 +20,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
|
-
|
|
24
|
-
MinimumVersionError: () => MinimumVersionError,
|
|
23
|
+
ErrorInfo: () => ErrorInfo,
|
|
25
24
|
Updater: () => Updater,
|
|
26
|
-
|
|
25
|
+
UpdaterError: () => UpdaterError,
|
|
27
26
|
createUpdater: () => createUpdater,
|
|
27
|
+
downloadBufferDefault: () => downloadBufferDefault,
|
|
28
|
+
downloadJSONDefault: () => downloadJSONDefault,
|
|
28
29
|
initApp: () => initApp,
|
|
30
|
+
isLowerVersionDefault: () => isLowerVersionDefault,
|
|
29
31
|
startupWithUpdater: () => startupWithUpdater
|
|
30
32
|
});
|
|
31
33
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -35,7 +37,6 @@ var import_electron4 = require("electron");
|
|
|
35
37
|
|
|
36
38
|
// src/updater/core.ts
|
|
37
39
|
var import_node_fs3 = require("fs");
|
|
38
|
-
var import_promises = require("fs/promises");
|
|
39
40
|
var import_electron3 = require("electron");
|
|
40
41
|
|
|
41
42
|
// src/utils/electron.ts
|
|
@@ -87,7 +88,7 @@ async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
|
|
|
87
88
|
}
|
|
88
89
|
const compressedBuffer = (0, import_node_fs2.readFileSync)(gzipPath);
|
|
89
90
|
return new Promise((resolve2, reject) => {
|
|
90
|
-
(0, import_node_zlib.
|
|
91
|
+
(0, import_node_zlib.brotliDecompress)(compressedBuffer, (err, buffer) => {
|
|
91
92
|
(0, import_node_fs2.rmSync)(gzipPath);
|
|
92
93
|
if (err) {
|
|
93
94
|
reject(err);
|
|
@@ -100,8 +101,7 @@ async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
|
|
|
100
101
|
|
|
101
102
|
// src/utils/pure.ts
|
|
102
103
|
function parseVersion(version) {
|
|
103
|
-
const
|
|
104
|
-
const match = semver.exec(version);
|
|
104
|
+
const match = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i.exec(version);
|
|
105
105
|
if (!match) {
|
|
106
106
|
throw new TypeError(`invalid version: ${version}`);
|
|
107
107
|
}
|
|
@@ -159,100 +159,67 @@ var verify = (buffer, signature, cert) => {
|
|
|
159
159
|
var import_node_crypto3 = require("crypto");
|
|
160
160
|
|
|
161
161
|
// src/updater/types.ts
|
|
162
|
-
var
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
this.currentVersion = version;
|
|
168
|
-
this.minVersion = minimumVersion;
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
var VerifyFailedError = class extends Error {
|
|
172
|
-
signature;
|
|
173
|
-
cert;
|
|
174
|
-
constructor(signature, cert) {
|
|
175
|
-
super("verify failed, invalid signature or certificate");
|
|
176
|
-
this.signature = signature;
|
|
177
|
-
this.cert = cert;
|
|
178
|
-
}
|
|
162
|
+
var ErrorInfo = {
|
|
163
|
+
downlaod: "Download failed",
|
|
164
|
+
validate: "Validate failed",
|
|
165
|
+
param: "Missing params",
|
|
166
|
+
version: "Unsatisfied version"
|
|
179
167
|
};
|
|
180
|
-
var
|
|
181
|
-
constructor(msg) {
|
|
182
|
-
super(
|
|
168
|
+
var UpdaterError = class extends Error {
|
|
169
|
+
constructor(msg, info) {
|
|
170
|
+
super(msg + ": " + info);
|
|
183
171
|
}
|
|
184
172
|
};
|
|
185
173
|
|
|
186
174
|
// src/updater/defaultFunctions/download.ts
|
|
187
175
|
var import_electron2 = require("electron");
|
|
188
|
-
|
|
176
|
+
async function downlaodFn(url, headers, onResponse) {
|
|
189
177
|
await waitAppReady();
|
|
190
178
|
return new Promise((resolve2, reject) => {
|
|
191
|
-
const request = import_electron2.net.request({
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
} catch (e) {
|
|
211
|
-
reject(new Error("invalid json"));
|
|
179
|
+
const request = import_electron2.net.request({ url, method: "GET", redirect: "follow" });
|
|
180
|
+
Object.keys(headers).forEach((key) => request.setHeader(key, headers[key]));
|
|
181
|
+
request.on("response", (res) => onResponse(res, resolve2, reject));
|
|
182
|
+
request.on("error", reject);
|
|
183
|
+
request.end();
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
var downloadJSONDefault = async (url, headers) => {
|
|
187
|
+
return await downlaodFn(url, headers, (resp, resolve2, reject) => {
|
|
188
|
+
let data = "";
|
|
189
|
+
resp.on("data", (chunk) => data += chunk);
|
|
190
|
+
resp.on("end", () => {
|
|
191
|
+
try {
|
|
192
|
+
const json = JSON.parse(data);
|
|
193
|
+
if (isUpdateJSON(json)) {
|
|
194
|
+
resolve2(json);
|
|
195
|
+
} else {
|
|
196
|
+
throw Error;
|
|
212
197
|
}
|
|
213
|
-
})
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
reject(e);
|
|
198
|
+
} catch (ignore) {
|
|
199
|
+
reject(new Error("invalid update json"));
|
|
200
|
+
}
|
|
217
201
|
});
|
|
218
|
-
|
|
202
|
+
resp.on("aborted", () => reject(new Error("aborted")));
|
|
203
|
+
resp.on("error", () => reject(new Error("download error")));
|
|
219
204
|
});
|
|
220
205
|
};
|
|
221
206
|
var downloadBufferDefault = async (url, headers, total, onDownloading) => {
|
|
222
|
-
await waitAppReady();
|
|
223
207
|
let current = 0;
|
|
224
|
-
return
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
208
|
+
return await downlaodFn(url, headers, (resp, resolve2, reject) => {
|
|
209
|
+
let data = [];
|
|
210
|
+
resp.on("data", (chunk) => {
|
|
211
|
+
current += chunk.length;
|
|
212
|
+
onDownloading?.({ percent: `${+(current / total).toFixed(2) * 100}%`, total, current });
|
|
213
|
+
data.push(chunk);
|
|
229
214
|
});
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
request.on("response", (res) => {
|
|
234
|
-
let data = [];
|
|
235
|
-
res.on("data", (chunk) => {
|
|
236
|
-
current += chunk.length;
|
|
237
|
-
onDownloading?.({
|
|
238
|
-
percent: `${+(current / total).toFixed(2) * 100}%`,
|
|
239
|
-
total,
|
|
240
|
-
current
|
|
241
|
-
});
|
|
242
|
-
data.push(chunk);
|
|
243
|
-
});
|
|
244
|
-
res.on("end", () => {
|
|
245
|
-
resolve2(Buffer.concat(data));
|
|
246
|
-
});
|
|
247
|
-
}).on("error", (e) => {
|
|
248
|
-
reject(e);
|
|
249
|
-
});
|
|
250
|
-
request.end();
|
|
215
|
+
resp.on("end", () => resolve2(Buffer.concat(data)));
|
|
216
|
+
resp.on("aborted", () => reject(new Error("aborted")));
|
|
217
|
+
resp.on("error", () => reject(new Error("download error")));
|
|
251
218
|
});
|
|
252
219
|
};
|
|
253
220
|
|
|
254
221
|
// src/updater/defaultFunctions/compareVersion.ts
|
|
255
|
-
var
|
|
222
|
+
var isLowerVersionDefault = (version1, version2) => {
|
|
256
223
|
const oldV = parseVersion(version1);
|
|
257
224
|
const newV = parseVersion(version2);
|
|
258
225
|
function compareStrings(str1, str2) {
|
|
@@ -275,6 +242,7 @@ var compareVersionDefault = (version1, version2) => {
|
|
|
275
242
|
|
|
276
243
|
// src/updater/core.ts
|
|
277
244
|
var Updater = class {
|
|
245
|
+
CERT = __SIGNATURE_CERT__;
|
|
278
246
|
info;
|
|
279
247
|
option;
|
|
280
248
|
asarPath;
|
|
@@ -306,38 +274,39 @@ var Updater = class {
|
|
|
306
274
|
* initialize incremental updater
|
|
307
275
|
* @param option UpdaterOption
|
|
308
276
|
*/
|
|
309
|
-
constructor(option) {
|
|
277
|
+
constructor(option = {}) {
|
|
310
278
|
this.option = option;
|
|
279
|
+
if (option.SIGNATURE_CERT) {
|
|
280
|
+
this.CERT = option.SIGNATURE_CERT;
|
|
281
|
+
}
|
|
311
282
|
this.asarPath = getPathFromAppNameAsar();
|
|
312
283
|
this.gzipPath = `${this.asarPath}.gz`;
|
|
313
284
|
this.tmpFilePath = `${this.asarPath}.tmp`;
|
|
314
285
|
}
|
|
315
286
|
async needUpdate(version, minVersion) {
|
|
316
|
-
const
|
|
287
|
+
const isLowerVersion = this.option.overrideFunctions?.isLowerVersion ?? isLowerVersionDefault;
|
|
317
288
|
const { appVersion, entryVersion } = getVersions();
|
|
318
|
-
if (await
|
|
319
|
-
throw new
|
|
289
|
+
if (await isLowerVersion(entryVersion, minVersion)) {
|
|
290
|
+
throw new UpdaterError(ErrorInfo.version, `entry version (${entryVersion}) < minimumVersion (${minVersion})`);
|
|
320
291
|
}
|
|
321
292
|
this.logger?.info(`check update: current version is ${appVersion}, new version is ${version}`);
|
|
322
|
-
return await
|
|
293
|
+
return await isLowerVersion(appVersion, version);
|
|
323
294
|
}
|
|
324
295
|
async parseData(format, data) {
|
|
325
296
|
if ((0, import_node_fs3.existsSync)(this.tmpFilePath)) {
|
|
326
297
|
this.logger?.warn(`remove tmp file: ${this.tmpFilePath}`);
|
|
327
|
-
|
|
298
|
+
(0, import_node_fs3.rmSync)(this.tmpFilePath);
|
|
328
299
|
}
|
|
329
300
|
if ((0, import_node_fs3.existsSync)(this.gzipPath)) {
|
|
330
301
|
this.logger?.warn(`remove .gz file: ${this.gzipPath}`);
|
|
331
|
-
|
|
332
|
-
}
|
|
333
|
-
if (!["string", "object", "undefined"].includes(typeof data)) {
|
|
334
|
-
throw new TypeError(`invalid type at format '${format}': ${data}`);
|
|
335
|
-
}
|
|
336
|
-
if (typeof data === "object" && (format === "json" && isUpdateJSON(data) || format === "buffer" && Buffer.isBuffer(data))) {
|
|
337
|
-
return data;
|
|
302
|
+
(0, import_node_fs3.rmSync)(this.gzipPath);
|
|
338
303
|
}
|
|
339
304
|
if (typeof data === "object") {
|
|
340
|
-
|
|
305
|
+
if (format === "json" && isUpdateJSON(data) || format === "buffer" && Buffer.isBuffer(data)) {
|
|
306
|
+
return data;
|
|
307
|
+
} else {
|
|
308
|
+
throw new UpdaterError(ErrorInfo.param, `invalid type at format '${format}': ${JSON.stringify(data)}`);
|
|
309
|
+
}
|
|
341
310
|
}
|
|
342
311
|
const ua = this.option.downloadConfig?.userAgent || "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36";
|
|
343
312
|
const headers = {
|
|
@@ -345,11 +314,11 @@ var Updater = class {
|
|
|
345
314
|
UserAgent: ua,
|
|
346
315
|
...this.option.downloadConfig?.extraHeader
|
|
347
316
|
};
|
|
348
|
-
this.logger?.
|
|
317
|
+
this.logger?.debug(`download headers: ${JSON.stringify(headers)}`);
|
|
349
318
|
const config = format === "json" ? {
|
|
350
319
|
name: "updateJsonURL",
|
|
351
320
|
url: this.option.updateJsonURL,
|
|
352
|
-
repoFallback: `${this.option.repository
|
|
321
|
+
repoFallback: `${this.option.repository?.replace("github.com", "raw.githubusercontent.com")}/master/version.json`,
|
|
353
322
|
fn: this.option.overrideFunctions?.downloadJSON ?? downloadJSONDefault
|
|
354
323
|
} : {
|
|
355
324
|
name: "releaseAsarURL",
|
|
@@ -361,32 +330,22 @@ var Updater = class {
|
|
|
361
330
|
if (!data) {
|
|
362
331
|
this.logger?.debug(`no ${config.name}, fallback to use repository`);
|
|
363
332
|
if (!this.option.repository) {
|
|
364
|
-
throw new
|
|
333
|
+
throw new UpdaterError(ErrorInfo.param, `${config.name} or repository is not set`);
|
|
365
334
|
}
|
|
366
335
|
if (format === "buffer" && !this.info?.version) {
|
|
367
|
-
throw new
|
|
336
|
+
throw new UpdaterError(ErrorInfo.param, "version is not set");
|
|
368
337
|
}
|
|
369
338
|
data = config.repoFallback;
|
|
370
339
|
}
|
|
371
|
-
this.logger?.
|
|
340
|
+
this.logger?.debug(`download ${format} from ${data}`);
|
|
372
341
|
try {
|
|
373
342
|
const ret = format === "json" ? await config.fn(data, headers) : await config.fn(data, headers, this.info.size, this.onDownloading);
|
|
374
|
-
this.logger?.
|
|
343
|
+
this.logger?.debug(`download ${format} success${format === "buffer" ? `, file size: ${ret.length}` : ""}`);
|
|
375
344
|
return ret;
|
|
376
345
|
} catch (e) {
|
|
377
|
-
throw new
|
|
346
|
+
throw new UpdaterError(ErrorInfo.downlaod, e.toString());
|
|
378
347
|
}
|
|
379
348
|
}
|
|
380
|
-
/**
|
|
381
|
-
* check update info
|
|
382
|
-
*
|
|
383
|
-
* if you want to update **offline**, you can set `data` and `sig` add update info
|
|
384
|
-
* @param data custom download URL of `updatejson` or existing update json
|
|
385
|
-
* @returns
|
|
386
|
-
* - Available:`{size: number, version: string}`
|
|
387
|
-
* - Unavailable: `undefined`
|
|
388
|
-
* - Fail: `CheckResultError`
|
|
389
|
-
*/
|
|
390
349
|
async checkUpdate(data) {
|
|
391
350
|
try {
|
|
392
351
|
let { signature, size, version, minimumVersion, beta } = await this.parseData("json", data);
|
|
@@ -396,7 +355,7 @@ var Updater = class {
|
|
|
396
355
|
minimumVersion = beta.minimumVersion;
|
|
397
356
|
size = beta.size;
|
|
398
357
|
}
|
|
399
|
-
this.logger?.
|
|
358
|
+
this.logger?.debug(`checked version: ${version}, size: ${size}, signature: ${signature}`);
|
|
400
359
|
if (!await this.needUpdate(version, minimumVersion)) {
|
|
401
360
|
this.logger?.info(`update unavailable: ${version} is the latest version`);
|
|
402
361
|
return void 0;
|
|
@@ -415,33 +374,23 @@ var Updater = class {
|
|
|
415
374
|
return error;
|
|
416
375
|
}
|
|
417
376
|
}
|
|
418
|
-
/**
|
|
419
|
-
* download update
|
|
420
|
-
*
|
|
421
|
-
* if you want to update **offline**, you can set both `data` and `sig` to verify and install
|
|
422
|
-
* @param data custom download URL of `asar.gz` or existing `asar.gz` buffer
|
|
423
|
-
* @param sig signature
|
|
424
|
-
* @returns
|
|
425
|
-
* - `true`: success
|
|
426
|
-
* - `DownloadResultError`: fail
|
|
427
|
-
*/
|
|
428
377
|
async download(data, sig) {
|
|
429
378
|
try {
|
|
430
379
|
const _sig = sig ?? this.info?.signature;
|
|
431
380
|
if (!_sig) {
|
|
432
|
-
throw new
|
|
381
|
+
throw new UpdaterError(ErrorInfo.param, "signature is empty");
|
|
433
382
|
}
|
|
434
383
|
const buffer = await this.parseData("buffer", data);
|
|
435
|
-
this.logger?.
|
|
384
|
+
this.logger?.debug("verify start");
|
|
436
385
|
const _verify = this.option.overrideFunctions?.verifySignaure ?? verify;
|
|
437
|
-
const _ver = await _verify(buffer, _sig, this.
|
|
386
|
+
const _ver = await _verify(buffer, _sig, this.CERT);
|
|
438
387
|
if (!_ver) {
|
|
439
|
-
throw new
|
|
388
|
+
throw new UpdaterError(ErrorInfo.validate, "invalid signature or certificate");
|
|
440
389
|
}
|
|
441
|
-
this.logger?.
|
|
442
|
-
this.logger?.
|
|
443
|
-
|
|
444
|
-
this.logger?.
|
|
390
|
+
this.logger?.debug("verify success");
|
|
391
|
+
this.logger?.debug(`write to ${this.gzipPath}`);
|
|
392
|
+
(0, import_node_fs3.writeFileSync)(this.gzipPath, buffer);
|
|
393
|
+
this.logger?.debug(`extract to ${this.tmpFilePath}`);
|
|
445
394
|
await unzipFile(this.gzipPath, this.tmpFilePath);
|
|
446
395
|
this.logger?.info(`download success, version: ${_ver}`);
|
|
447
396
|
this.info = void 0;
|
|
@@ -473,8 +422,9 @@ var defaultOnInstall = (install, _, __, logger) => {
|
|
|
473
422
|
install();
|
|
474
423
|
logger?.info(`update success!`);
|
|
475
424
|
};
|
|
476
|
-
function initApp(appOptions) {
|
|
425
|
+
async function initApp(appOptions = {}) {
|
|
477
426
|
const {
|
|
427
|
+
updater,
|
|
478
428
|
electronDevDistPath = "../dist-electron",
|
|
479
429
|
mainPath = "main/index.js",
|
|
480
430
|
hooks
|
|
@@ -484,51 +434,42 @@ function initApp(appOptions) {
|
|
|
484
434
|
beforeStart,
|
|
485
435
|
onStartError
|
|
486
436
|
} = hooks || {};
|
|
487
|
-
function handleError(err,
|
|
437
|
+
function handleError(err, logger2) {
|
|
488
438
|
console.error(err);
|
|
489
|
-
onStartError?.(err,
|
|
439
|
+
onStartError?.(err, logger2);
|
|
490
440
|
import_electron4.app.quit();
|
|
491
441
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
if ((0, import_node_fs4.existsSync)(tempAsarPath)) {
|
|
498
|
-
logger?.info(`installing new asar: ${tempAsarPath}`);
|
|
499
|
-
await onInstall(() => (0, import_node_fs4.renameSync)(tempAsarPath, appNameAsarPath), tempAsarPath, appNameAsarPath, logger);
|
|
500
|
-
}
|
|
501
|
-
const mainDir = is.dev ? electronDevDistPath : appNameAsarPath;
|
|
502
|
-
const entry = (0, import_node_path2.resolve)(__dirname, mainDir, mainPath);
|
|
503
|
-
await beforeStart?.(entry, logger);
|
|
504
|
-
require(entry)(updater);
|
|
505
|
-
} catch (error) {
|
|
506
|
-
handleError(error, logger);
|
|
507
|
-
}
|
|
442
|
+
let updaterInstance;
|
|
443
|
+
if (typeof updater === "object" || !updater) {
|
|
444
|
+
updaterInstance = createUpdater(updater);
|
|
445
|
+
} else {
|
|
446
|
+
updaterInstance = await updater();
|
|
508
447
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
await startup(createUpdater(updater));
|
|
517
|
-
} else if (typeof updater === "function") {
|
|
518
|
-
await startup(await updater());
|
|
519
|
-
} else {
|
|
520
|
-
handleError("invalid updater option or updater is not a function");
|
|
521
|
-
}
|
|
448
|
+
const logger = updaterInstance.logger;
|
|
449
|
+
try {
|
|
450
|
+
const appNameAsarPath = getPathFromAppNameAsar();
|
|
451
|
+
const tempAsarPath = `${appNameAsarPath}.tmp`;
|
|
452
|
+
if ((0, import_node_fs4.existsSync)(tempAsarPath)) {
|
|
453
|
+
logger?.info(`installing new asar: ${tempAsarPath}`);
|
|
454
|
+
await onInstall(() => (0, import_node_fs4.renameSync)(tempAsarPath, appNameAsarPath), tempAsarPath, appNameAsarPath, logger);
|
|
522
455
|
}
|
|
523
|
-
|
|
456
|
+
const mainDir = is.dev ? electronDevDistPath : appNameAsarPath;
|
|
457
|
+
const entry = (0, import_node_path2.resolve)(__dirname, mainDir, mainPath);
|
|
458
|
+
await beforeStart?.(entry, logger);
|
|
459
|
+
require(entry)(updaterInstance);
|
|
460
|
+
} catch (error) {
|
|
461
|
+
handleError(error, logger);
|
|
462
|
+
}
|
|
524
463
|
}
|
|
525
464
|
// Annotate the CommonJS export names for ESM import in node:
|
|
526
465
|
0 && (module.exports = {
|
|
527
|
-
|
|
528
|
-
MinimumVersionError,
|
|
466
|
+
ErrorInfo,
|
|
529
467
|
Updater,
|
|
530
|
-
|
|
468
|
+
UpdaterError,
|
|
531
469
|
createUpdater,
|
|
470
|
+
downloadBufferDefault,
|
|
471
|
+
downloadJSONDefault,
|
|
532
472
|
initApp,
|
|
473
|
+
isLowerVersionDefault,
|
|
533
474
|
startupWithUpdater
|
|
534
475
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
import { U as UpdateInfo, a as UpdateJSON } from './pure-GoN_3MEj.cjs';
|
|
2
2
|
|
|
3
|
-
declare
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
constructor(signature: string, cert: string);
|
|
12
|
-
}
|
|
13
|
-
declare class DownloadError extends Error {
|
|
14
|
-
constructor(msg: string);
|
|
3
|
+
declare const ErrorInfo: {
|
|
4
|
+
readonly downlaod: "Download failed";
|
|
5
|
+
readonly validate: "Validate failed";
|
|
6
|
+
readonly param: "Missing params";
|
|
7
|
+
readonly version: "Unsatisfied version";
|
|
8
|
+
};
|
|
9
|
+
declare class UpdaterError extends Error {
|
|
10
|
+
constructor(msg: typeof ErrorInfo[keyof typeof ErrorInfo], info: string);
|
|
15
11
|
}
|
|
16
|
-
type CheckResult = UpdateInfo | undefined |
|
|
17
|
-
type
|
|
18
|
-
type DownloadResult = true | DownloadResultError;
|
|
19
|
-
type DownloadResultError = DownloadError | VerifyFailedError | TypeError | Error;
|
|
12
|
+
type CheckResult = UpdateInfo | undefined | UpdaterError;
|
|
13
|
+
type DownloadResult = true | UpdaterError;
|
|
20
14
|
type DownloadingInfo = {
|
|
21
15
|
/**
|
|
22
16
|
* downloaded percent, 0% - 100%
|
|
@@ -42,9 +36,9 @@ type UpdaterOverrideFunctions = {
|
|
|
42
36
|
* custom version compare function
|
|
43
37
|
* @param version1 old version string
|
|
44
38
|
* @param version2 new version string
|
|
45
|
-
* @returns
|
|
39
|
+
* @returns if version1 < version2
|
|
46
40
|
*/
|
|
47
|
-
|
|
41
|
+
isLowerVersion?: (version1: string, version2: string) => boolean | Promise<boolean>;
|
|
48
42
|
/**
|
|
49
43
|
* custom verify signature function
|
|
50
44
|
* @param buffer file buffer
|
|
@@ -83,19 +77,10 @@ type UpdaterDownloadConfig = {
|
|
|
83
77
|
};
|
|
84
78
|
interface UpdaterOption {
|
|
85
79
|
/**
|
|
86
|
-
* public key of signature, which will be auto generated by plugin
|
|
87
|
-
*
|
|
88
|
-
* ```ts
|
|
89
|
-
* // just empty here, auto filled by plugin
|
|
90
|
-
* const SIGNATURE_CERT = ''
|
|
91
|
-
*
|
|
92
|
-
* const updater = createUpdater({
|
|
93
|
-
* SIGNATURE_CERT,
|
|
94
|
-
* ...
|
|
95
|
-
* })
|
|
96
|
-
* ```
|
|
80
|
+
* public key of signature, which will be auto generated by plugin,
|
|
81
|
+
* generate by `selfsigned` if not set
|
|
97
82
|
*/
|
|
98
|
-
SIGNATURE_CERT
|
|
83
|
+
SIGNATURE_CERT?: string;
|
|
99
84
|
/**
|
|
100
85
|
* repository url, e.g. `https://github.com/electron/electron`
|
|
101
86
|
*
|
|
@@ -126,6 +111,7 @@ interface UpdaterOption {
|
|
|
126
111
|
}
|
|
127
112
|
|
|
128
113
|
declare class Updater {
|
|
114
|
+
private CERT;
|
|
129
115
|
private info?;
|
|
130
116
|
private option;
|
|
131
117
|
private asarPath;
|
|
@@ -153,7 +139,7 @@ declare class Updater {
|
|
|
153
139
|
* initialize incremental updater
|
|
154
140
|
* @param option UpdaterOption
|
|
155
141
|
*/
|
|
156
|
-
constructor(option
|
|
142
|
+
constructor(option?: UpdaterOption);
|
|
157
143
|
private needUpdate;
|
|
158
144
|
/**
|
|
159
145
|
* this function is used to parse download data.
|
|
@@ -168,43 +154,81 @@ declare class Updater {
|
|
|
168
154
|
*/
|
|
169
155
|
private parseData;
|
|
170
156
|
/**
|
|
171
|
-
* check update info
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
157
|
+
* check update info using default options
|
|
158
|
+
* @returns
|
|
159
|
+
* - Available: `{size: number, version: string}`
|
|
160
|
+
* - Unavailable: `undefined`
|
|
161
|
+
* - Fail: `UpdaterError`
|
|
162
|
+
*/
|
|
163
|
+
checkUpdate(): Promise<CheckResult>;
|
|
164
|
+
/**
|
|
165
|
+
* check update info using custom url
|
|
166
|
+
* @param url custom download URL of `updatejson`
|
|
175
167
|
* @returns
|
|
176
168
|
* - Available:`{size: number, version: string}`
|
|
177
169
|
* - Unavailable: `undefined`
|
|
178
|
-
* - Fail: `
|
|
170
|
+
* - Fail: `UpdaterError`
|
|
179
171
|
*/
|
|
180
|
-
checkUpdate(
|
|
172
|
+
checkUpdate(url: string): Promise<CheckResult>;
|
|
181
173
|
/**
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
174
|
+
* check update info using existing update json
|
|
175
|
+
* @param data existing update json
|
|
176
|
+
* @returns
|
|
177
|
+
* - Available:`{size: number, version: string}`
|
|
178
|
+
* - Unavailable: `undefined`
|
|
179
|
+
* - Fail: `UpdaterError`
|
|
180
|
+
*/
|
|
181
|
+
checkUpdate(data: UpdateJSON): Promise<CheckResult>;
|
|
182
|
+
/**
|
|
183
|
+
* download update using default options
|
|
184
|
+
* @returns
|
|
185
|
+
* - Success: `true`
|
|
186
|
+
* - Fail: `UpdaterError`
|
|
187
|
+
*/
|
|
188
|
+
download(): Promise<DownloadResult>;
|
|
189
|
+
/**
|
|
190
|
+
* download update using custom url
|
|
191
|
+
* @param url custom download URL
|
|
192
|
+
* @returns
|
|
193
|
+
* - Success: `true`
|
|
194
|
+
* - Fail: `UpdaterError`
|
|
195
|
+
*/
|
|
196
|
+
download(url: string): Promise<DownloadResult>;
|
|
197
|
+
/**
|
|
198
|
+
* download update using existing `asar.gz` buffer and signature
|
|
199
|
+
* @param data existing `asar.gz` buffer
|
|
186
200
|
* @param sig signature
|
|
187
201
|
* @returns
|
|
188
|
-
* - `true
|
|
189
|
-
* - `
|
|
202
|
+
* - Success: `true`
|
|
203
|
+
* - Fail: `UpdaterError`
|
|
190
204
|
*/
|
|
191
|
-
download(data
|
|
205
|
+
download(data: Buffer, sig: string): Promise<DownloadResult>;
|
|
192
206
|
/**
|
|
193
207
|
* quit App and install
|
|
194
208
|
*/
|
|
195
209
|
quitAndInstall(): void;
|
|
196
210
|
}
|
|
197
211
|
|
|
212
|
+
type Func = Required<UpdaterOverrideFunctions>;
|
|
213
|
+
declare const downloadJSONDefault: Func['downloadJSON'];
|
|
214
|
+
declare const downloadBufferDefault: Func['downloadBuffer'];
|
|
215
|
+
|
|
216
|
+
declare const isLowerVersionDefault: Func['isLowerVersion'];
|
|
217
|
+
|
|
198
218
|
/**
|
|
199
219
|
* create updater instance
|
|
200
220
|
* @param option updater option
|
|
201
221
|
* @returns updater
|
|
202
222
|
*/
|
|
203
|
-
declare function createUpdater(option
|
|
223
|
+
declare function createUpdater(option?: UpdaterOption): Updater;
|
|
204
224
|
|
|
205
225
|
type Promisable<T> = T | Promise<T>;
|
|
206
226
|
type OnInstallFunction = (install: VoidFunction, tempAsarPath: string, appNameAsarPath: string, logger?: Logger) => Promisable<void>;
|
|
207
227
|
type AppOption = {
|
|
228
|
+
/**
|
|
229
|
+
* updater options
|
|
230
|
+
*/
|
|
231
|
+
updater?: (() => Promisable<Updater>) | UpdaterOption;
|
|
208
232
|
/**
|
|
209
233
|
* path of electron output dist when in development
|
|
210
234
|
* @default '../dist-electron'
|
|
@@ -252,13 +276,6 @@ type AppOption = {
|
|
|
252
276
|
* })
|
|
253
277
|
*/
|
|
254
278
|
declare function startupWithUpdater(fn: (updater: Updater) => Promisable<void>): (updater: Updater) => Promisable<void>;
|
|
255
|
-
type StartupWithUpdater = {
|
|
256
|
-
/**
|
|
257
|
-
* starup app
|
|
258
|
-
* @param updater updater option or create function
|
|
259
|
-
*/
|
|
260
|
-
startupWithUpdater: (updater: (() => Promisable<Updater>) | UpdaterOption) => void;
|
|
261
|
-
};
|
|
262
279
|
/**
|
|
263
280
|
* initialize app
|
|
264
281
|
* @example
|
|
@@ -266,20 +283,22 @@ type StartupWithUpdater = {
|
|
|
266
283
|
* import { getGithubReleaseCdnGroup, initApp, parseGithubCdnURL } from 'electron-incremental-update'
|
|
267
284
|
* import { repository } from '../package.json'
|
|
268
285
|
*
|
|
269
|
-
* const SIGNATURE_CERT = '' // auto generate certificate when start app
|
|
270
286
|
* const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
|
|
271
287
|
* const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
|
|
272
|
-
*
|
|
288
|
+
*
|
|
289
|
+
* initApp({
|
|
273
290
|
* // can be updater option or function that return updater
|
|
274
|
-
*
|
|
275
|
-
* SIGNATURE_CERT,
|
|
291
|
+
* updater: {
|
|
292
|
+
* SIGNATURE_CERT: 'custom certificate',
|
|
276
293
|
* repository,
|
|
277
294
|
* updateJsonURL: parseGithubCdnURL(repository, jsonPrefix, 'version.json'),
|
|
278
295
|
* releaseAsarURL: parseGithubCdnURL(repository, asarPrefix, `download/latest/${app.name}.asar.gz`),
|
|
279
296
|
* receiveBeta: true,
|
|
280
|
-
* }
|
|
297
|
+
* },
|
|
298
|
+
* onStart: console.log
|
|
299
|
+
* })
|
|
281
300
|
* ```
|
|
282
301
|
*/
|
|
283
|
-
declare function initApp(appOptions?: AppOption):
|
|
302
|
+
declare function initApp(appOptions?: AppOption): Promise<void>;
|
|
284
303
|
|
|
285
|
-
export { type AppOption, type CheckResult, type
|
|
304
|
+
export { type AppOption, type CheckResult, type DownloadResult, type DownloadingInfo, ErrorInfo, type Func, type Logger, Updater, type UpdaterDownloadConfig, UpdaterError, type UpdaterOption, type UpdaterOverrideFunctions, createUpdater, downloadBufferDefault, downloadJSONDefault, initApp, isLowerVersionDefault, startupWithUpdater };
|