electron-incremental-update 0.7.9 → 0.8.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/dist/index.d.mts +27 -17
- package/dist/index.d.ts +27 -17
- package/dist/index.js +24 -8
- package/dist/index.mjs +23 -8
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -11,6 +11,9 @@ declare class VerifyFailedError extends Error {
|
|
|
11
11
|
cert: string;
|
|
12
12
|
constructor(signature: string, cert: string);
|
|
13
13
|
}
|
|
14
|
+
declare class DownloadError extends Error {
|
|
15
|
+
constructor(msg: string);
|
|
16
|
+
}
|
|
14
17
|
declare class IncrementalUpdater implements Updater {
|
|
15
18
|
private info?;
|
|
16
19
|
private option;
|
|
@@ -36,11 +39,13 @@ declare class IncrementalUpdater implements Updater {
|
|
|
36
39
|
*/
|
|
37
40
|
declare function createUpdater(option: UpdaterOption): IncrementalUpdater;
|
|
38
41
|
|
|
42
|
+
type CheckResultError = MinimumVersionError | DownloadError | TypeError | Error;
|
|
43
|
+
type DownloadResultError = DownloadError | VerifyFailedError | TypeError | Error;
|
|
39
44
|
type CheckResultType = {
|
|
40
45
|
size: number;
|
|
41
46
|
version: string;
|
|
42
|
-
} | undefined |
|
|
43
|
-
type DownloadResult = true |
|
|
47
|
+
} | undefined | CheckResultError;
|
|
48
|
+
type DownloadResult = true | DownloadResultError;
|
|
44
49
|
type DownloadingInfo = {
|
|
45
50
|
/**
|
|
46
51
|
* downloaded percent, 0% - 100%
|
|
@@ -69,8 +74,8 @@ interface Updater {
|
|
|
69
74
|
* @param data update json url or object
|
|
70
75
|
* @returns
|
|
71
76
|
* - `{size: number, version: string}`: available
|
|
72
|
-
* - `
|
|
73
|
-
* - `
|
|
77
|
+
* - `undefined`: unavailable
|
|
78
|
+
* - `CheckResultError`: fail
|
|
74
79
|
*/
|
|
75
80
|
checkUpdate: (data?: string | UpdateJSON) => Promise<CheckResultType>;
|
|
76
81
|
/**
|
|
@@ -81,7 +86,7 @@ interface Updater {
|
|
|
81
86
|
* @param sig signature
|
|
82
87
|
* @returns
|
|
83
88
|
* - `true`: success
|
|
84
|
-
* - `
|
|
89
|
+
* - `DownloadResultError`: fail
|
|
85
90
|
*/
|
|
86
91
|
download: (data?: string | Buffer, sig?: string) => Promise<DownloadResult>;
|
|
87
92
|
/**
|
|
@@ -106,7 +111,7 @@ type UpdaterOverrideFunctions = {
|
|
|
106
111
|
* @param cert certificate
|
|
107
112
|
* @returns if signature is valid, returns the version or `true` , otherwise returns `false`
|
|
108
113
|
*/
|
|
109
|
-
verifySignaure?: (buffer: Buffer, signature: string, cert: string) => string |
|
|
114
|
+
verifySignaure?: (buffer: Buffer, signature: string, cert: string) => string | false | Promise<string | false>;
|
|
110
115
|
/**
|
|
111
116
|
* custom download JSON function
|
|
112
117
|
* @param url download url
|
|
@@ -196,14 +201,20 @@ type AppOption = {
|
|
|
196
201
|
* @default 'main/index.js'
|
|
197
202
|
*/
|
|
198
203
|
mainPath?: string;
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
204
|
+
hooks?: {
|
|
205
|
+
/**
|
|
206
|
+
* hooks before replace the old asar is replaced by the new asar
|
|
207
|
+
*/
|
|
208
|
+
beforeDoUpdate?: (updateTempAsarPath: string) => void | Promise<void>;
|
|
209
|
+
/**
|
|
210
|
+
* hooks on start up
|
|
211
|
+
*/
|
|
212
|
+
onStart?: (productAsarPath: string) => void;
|
|
213
|
+
/**
|
|
214
|
+
* hooks on start up error
|
|
215
|
+
*/
|
|
216
|
+
onStartError?: (err: unknown) => void;
|
|
217
|
+
};
|
|
207
218
|
};
|
|
208
219
|
type StartupWithUpdater = (updater: Updater) => void;
|
|
209
220
|
type SetUpdater = {
|
|
@@ -213,14 +224,13 @@ type SetUpdater = {
|
|
|
213
224
|
setUpdater: (updater: (() => Updater | Promise<Updater>) | UpdaterOption) => void;
|
|
214
225
|
};
|
|
215
226
|
/**
|
|
216
|
-
*
|
|
227
|
+
* initialize app
|
|
217
228
|
* @example
|
|
218
229
|
* ```ts
|
|
219
230
|
* import { getGithubReleaseCdnGroup, initApp, parseGithubCdnURL } from 'electron-incremental-update'
|
|
220
231
|
* import { name, repository } from '../package.json'
|
|
221
232
|
*
|
|
222
233
|
* const SIGNATURE_CERT = '' // auto generate certificate when start app
|
|
223
|
-
*
|
|
224
234
|
* const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
|
|
225
235
|
* const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
|
|
226
236
|
* initApp({ onStart: console.log })
|
|
@@ -237,4 +247,4 @@ type SetUpdater = {
|
|
|
237
247
|
*/
|
|
238
248
|
declare function initApp(appOptions?: AppOption): SetUpdater;
|
|
239
249
|
|
|
240
|
-
export { AppOption, IncrementalUpdater, MinimumVersionError, StartupWithUpdater, Updater, UpdaterOption, VerifyFailedError, createUpdater, initApp };
|
|
250
|
+
export { AppOption, DownloadError, IncrementalUpdater, MinimumVersionError, StartupWithUpdater, Updater, UpdaterOption, VerifyFailedError, createUpdater, initApp };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ declare class VerifyFailedError extends Error {
|
|
|
11
11
|
cert: string;
|
|
12
12
|
constructor(signature: string, cert: string);
|
|
13
13
|
}
|
|
14
|
+
declare class DownloadError extends Error {
|
|
15
|
+
constructor(msg: string);
|
|
16
|
+
}
|
|
14
17
|
declare class IncrementalUpdater implements Updater {
|
|
15
18
|
private info?;
|
|
16
19
|
private option;
|
|
@@ -36,11 +39,13 @@ declare class IncrementalUpdater implements Updater {
|
|
|
36
39
|
*/
|
|
37
40
|
declare function createUpdater(option: UpdaterOption): IncrementalUpdater;
|
|
38
41
|
|
|
42
|
+
type CheckResultError = MinimumVersionError | DownloadError | TypeError | Error;
|
|
43
|
+
type DownloadResultError = DownloadError | VerifyFailedError | TypeError | Error;
|
|
39
44
|
type CheckResultType = {
|
|
40
45
|
size: number;
|
|
41
46
|
version: string;
|
|
42
|
-
} | undefined |
|
|
43
|
-
type DownloadResult = true |
|
|
47
|
+
} | undefined | CheckResultError;
|
|
48
|
+
type DownloadResult = true | DownloadResultError;
|
|
44
49
|
type DownloadingInfo = {
|
|
45
50
|
/**
|
|
46
51
|
* downloaded percent, 0% - 100%
|
|
@@ -69,8 +74,8 @@ interface Updater {
|
|
|
69
74
|
* @param data update json url or object
|
|
70
75
|
* @returns
|
|
71
76
|
* - `{size: number, version: string}`: available
|
|
72
|
-
* - `
|
|
73
|
-
* - `
|
|
77
|
+
* - `undefined`: unavailable
|
|
78
|
+
* - `CheckResultError`: fail
|
|
74
79
|
*/
|
|
75
80
|
checkUpdate: (data?: string | UpdateJSON) => Promise<CheckResultType>;
|
|
76
81
|
/**
|
|
@@ -81,7 +86,7 @@ interface Updater {
|
|
|
81
86
|
* @param sig signature
|
|
82
87
|
* @returns
|
|
83
88
|
* - `true`: success
|
|
84
|
-
* - `
|
|
89
|
+
* - `DownloadResultError`: fail
|
|
85
90
|
*/
|
|
86
91
|
download: (data?: string | Buffer, sig?: string) => Promise<DownloadResult>;
|
|
87
92
|
/**
|
|
@@ -106,7 +111,7 @@ type UpdaterOverrideFunctions = {
|
|
|
106
111
|
* @param cert certificate
|
|
107
112
|
* @returns if signature is valid, returns the version or `true` , otherwise returns `false`
|
|
108
113
|
*/
|
|
109
|
-
verifySignaure?: (buffer: Buffer, signature: string, cert: string) => string |
|
|
114
|
+
verifySignaure?: (buffer: Buffer, signature: string, cert: string) => string | false | Promise<string | false>;
|
|
110
115
|
/**
|
|
111
116
|
* custom download JSON function
|
|
112
117
|
* @param url download url
|
|
@@ -196,14 +201,20 @@ type AppOption = {
|
|
|
196
201
|
* @default 'main/index.js'
|
|
197
202
|
*/
|
|
198
203
|
mainPath?: string;
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
204
|
+
hooks?: {
|
|
205
|
+
/**
|
|
206
|
+
* hooks before replace the old asar is replaced by the new asar
|
|
207
|
+
*/
|
|
208
|
+
beforeDoUpdate?: (updateTempAsarPath: string) => void | Promise<void>;
|
|
209
|
+
/**
|
|
210
|
+
* hooks on start up
|
|
211
|
+
*/
|
|
212
|
+
onStart?: (productAsarPath: string) => void;
|
|
213
|
+
/**
|
|
214
|
+
* hooks on start up error
|
|
215
|
+
*/
|
|
216
|
+
onStartError?: (err: unknown) => void;
|
|
217
|
+
};
|
|
207
218
|
};
|
|
208
219
|
type StartupWithUpdater = (updater: Updater) => void;
|
|
209
220
|
type SetUpdater = {
|
|
@@ -213,14 +224,13 @@ type SetUpdater = {
|
|
|
213
224
|
setUpdater: (updater: (() => Updater | Promise<Updater>) | UpdaterOption) => void;
|
|
214
225
|
};
|
|
215
226
|
/**
|
|
216
|
-
*
|
|
227
|
+
* initialize app
|
|
217
228
|
* @example
|
|
218
229
|
* ```ts
|
|
219
230
|
* import { getGithubReleaseCdnGroup, initApp, parseGithubCdnURL } from 'electron-incremental-update'
|
|
220
231
|
* import { name, repository } from '../package.json'
|
|
221
232
|
*
|
|
222
233
|
* const SIGNATURE_CERT = '' // auto generate certificate when start app
|
|
223
|
-
*
|
|
224
234
|
* const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
|
|
225
235
|
* const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
|
|
226
236
|
* initApp({ onStart: console.log })
|
|
@@ -237,4 +247,4 @@ type SetUpdater = {
|
|
|
237
247
|
*/
|
|
238
248
|
declare function initApp(appOptions?: AppOption): SetUpdater;
|
|
239
249
|
|
|
240
|
-
export { AppOption, IncrementalUpdater, MinimumVersionError, StartupWithUpdater, Updater, UpdaterOption, VerifyFailedError, createUpdater, initApp };
|
|
250
|
+
export { AppOption, DownloadError, IncrementalUpdater, MinimumVersionError, StartupWithUpdater, Updater, UpdaterOption, VerifyFailedError, createUpdater, initApp };
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
|
+
DownloadError: () => DownloadError,
|
|
23
24
|
IncrementalUpdater: () => IncrementalUpdater,
|
|
24
25
|
MinimumVersionError: () => MinimumVersionError,
|
|
25
26
|
VerifyFailedError: () => VerifyFailedError,
|
|
@@ -239,6 +240,11 @@ var VerifyFailedError = class extends Error {
|
|
|
239
240
|
this.cert = cert;
|
|
240
241
|
}
|
|
241
242
|
};
|
|
243
|
+
var DownloadError = class extends Error {
|
|
244
|
+
constructor(msg) {
|
|
245
|
+
super(`download update error, ${msg}`);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
242
248
|
var IncrementalUpdater = class {
|
|
243
249
|
info;
|
|
244
250
|
option;
|
|
@@ -323,9 +329,13 @@ var IncrementalUpdater = class {
|
|
|
323
329
|
data = config.repoFallback;
|
|
324
330
|
}
|
|
325
331
|
this.logger?.info(`download ${format} from ${data}`);
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
332
|
+
try {
|
|
333
|
+
const ret = format === "json" ? await config.fn(data, headers) : await config.fn(data, headers, this.info.size, this.onDownloading);
|
|
334
|
+
this.logger?.info(`download ${format} success${format === "buffer" ? `, file size: ${ret.length}` : ""}`);
|
|
335
|
+
return ret;
|
|
336
|
+
} catch (e) {
|
|
337
|
+
throw new DownloadError(e.toString());
|
|
338
|
+
}
|
|
329
339
|
}
|
|
330
340
|
async checkUpdate(data) {
|
|
331
341
|
try {
|
|
@@ -373,7 +383,7 @@ var IncrementalUpdater = class {
|
|
|
373
383
|
await (0, import_promises.writeFile)(this.gzipPath, buffer);
|
|
374
384
|
this.logger?.info(`extract to ${this.tmpFilePath}`);
|
|
375
385
|
await unzipFile(this.gzipPath, this.tmpFilePath);
|
|
376
|
-
this.logger?.info(`download success
|
|
386
|
+
this.logger?.info(`download success, version: ${_ver}`);
|
|
377
387
|
this.info = void 0;
|
|
378
388
|
return true;
|
|
379
389
|
} catch (error) {
|
|
@@ -391,17 +401,22 @@ function initApp(appOptions) {
|
|
|
391
401
|
const {
|
|
392
402
|
electronDevDistPath = "dist-electron",
|
|
393
403
|
mainPath = "main/index.js",
|
|
404
|
+
hooks
|
|
405
|
+
} = appOptions || {};
|
|
406
|
+
const {
|
|
407
|
+
beforeDoUpdate,
|
|
394
408
|
onStart,
|
|
395
409
|
onStartError
|
|
396
|
-
} =
|
|
410
|
+
} = hooks || {};
|
|
397
411
|
function handleError(msg) {
|
|
398
412
|
onStartError?.(new Error(msg));
|
|
399
413
|
import_electron3.app.quit();
|
|
400
414
|
}
|
|
401
|
-
function startup(updater) {
|
|
415
|
+
async function startup(updater) {
|
|
402
416
|
try {
|
|
403
417
|
const asarPath = getProductAsarPath(updater.productName);
|
|
404
418
|
if ((0, import_node_fs3.existsSync)(`${asarPath}.tmp`)) {
|
|
419
|
+
await beforeDoUpdate?.(asarPath);
|
|
405
420
|
(0, import_node_fs3.renameSync)(`${asarPath}.tmp`, asarPath);
|
|
406
421
|
}
|
|
407
422
|
const mainDir = import_electron3.app.isPackaged ? asarPath : electronDevDistPath;
|
|
@@ -419,9 +434,9 @@ function initApp(appOptions) {
|
|
|
419
434
|
async setUpdater(updater) {
|
|
420
435
|
clearTimeout(timer);
|
|
421
436
|
if (typeof updater === "object") {
|
|
422
|
-
startup(createUpdater(updater));
|
|
437
|
+
await startup(createUpdater(updater));
|
|
423
438
|
} else if (typeof updater === "function") {
|
|
424
|
-
startup(await updater());
|
|
439
|
+
await startup(await updater());
|
|
425
440
|
} else {
|
|
426
441
|
handleError("invalid updater option or updater is not a function");
|
|
427
442
|
}
|
|
@@ -430,6 +445,7 @@ function initApp(appOptions) {
|
|
|
430
445
|
}
|
|
431
446
|
// Annotate the CommonJS export names for ESM import in node:
|
|
432
447
|
0 && (module.exports = {
|
|
448
|
+
DownloadError,
|
|
433
449
|
IncrementalUpdater,
|
|
434
450
|
MinimumVersionError,
|
|
435
451
|
VerifyFailedError,
|
package/dist/index.mjs
CHANGED
|
@@ -134,6 +134,11 @@ var VerifyFailedError = class extends Error {
|
|
|
134
134
|
this.cert = cert;
|
|
135
135
|
}
|
|
136
136
|
};
|
|
137
|
+
var DownloadError = class extends Error {
|
|
138
|
+
constructor(msg) {
|
|
139
|
+
super(`download update error, ${msg}`);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
137
142
|
var IncrementalUpdater = class {
|
|
138
143
|
info;
|
|
139
144
|
option;
|
|
@@ -218,9 +223,13 @@ var IncrementalUpdater = class {
|
|
|
218
223
|
data = config.repoFallback;
|
|
219
224
|
}
|
|
220
225
|
this.logger?.info(`download ${format} from ${data}`);
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
226
|
+
try {
|
|
227
|
+
const ret = format === "json" ? await config.fn(data, headers) : await config.fn(data, headers, this.info.size, this.onDownloading);
|
|
228
|
+
this.logger?.info(`download ${format} success${format === "buffer" ? `, file size: ${ret.length}` : ""}`);
|
|
229
|
+
return ret;
|
|
230
|
+
} catch (e) {
|
|
231
|
+
throw new DownloadError(e.toString());
|
|
232
|
+
}
|
|
224
233
|
}
|
|
225
234
|
async checkUpdate(data) {
|
|
226
235
|
try {
|
|
@@ -268,7 +277,7 @@ var IncrementalUpdater = class {
|
|
|
268
277
|
await writeFile(this.gzipPath, buffer);
|
|
269
278
|
this.logger?.info(`extract to ${this.tmpFilePath}`);
|
|
270
279
|
await unzipFile(this.gzipPath, this.tmpFilePath);
|
|
271
|
-
this.logger?.info(`download success
|
|
280
|
+
this.logger?.info(`download success, version: ${_ver}`);
|
|
272
281
|
this.info = void 0;
|
|
273
282
|
return true;
|
|
274
283
|
} catch (error) {
|
|
@@ -286,17 +295,22 @@ function initApp(appOptions) {
|
|
|
286
295
|
const {
|
|
287
296
|
electronDevDistPath = "dist-electron",
|
|
288
297
|
mainPath = "main/index.js",
|
|
298
|
+
hooks
|
|
299
|
+
} = appOptions || {};
|
|
300
|
+
const {
|
|
301
|
+
beforeDoUpdate,
|
|
289
302
|
onStart,
|
|
290
303
|
onStartError
|
|
291
|
-
} =
|
|
304
|
+
} = hooks || {};
|
|
292
305
|
function handleError(msg) {
|
|
293
306
|
onStartError?.(new Error(msg));
|
|
294
307
|
app.quit();
|
|
295
308
|
}
|
|
296
|
-
function startup(updater) {
|
|
309
|
+
async function startup(updater) {
|
|
297
310
|
try {
|
|
298
311
|
const asarPath = getProductAsarPath(updater.productName);
|
|
299
312
|
if (existsSync2(`${asarPath}.tmp`)) {
|
|
313
|
+
await beforeDoUpdate?.(asarPath);
|
|
300
314
|
renameSync(`${asarPath}.tmp`, asarPath);
|
|
301
315
|
}
|
|
302
316
|
const mainDir = app.isPackaged ? asarPath : electronDevDistPath;
|
|
@@ -314,9 +328,9 @@ function initApp(appOptions) {
|
|
|
314
328
|
async setUpdater(updater) {
|
|
315
329
|
clearTimeout(timer);
|
|
316
330
|
if (typeof updater === "object") {
|
|
317
|
-
startup(createUpdater(updater));
|
|
331
|
+
await startup(createUpdater(updater));
|
|
318
332
|
} else if (typeof updater === "function") {
|
|
319
|
-
startup(await updater());
|
|
333
|
+
await startup(await updater());
|
|
320
334
|
} else {
|
|
321
335
|
handleError("invalid updater option or updater is not a function");
|
|
322
336
|
}
|
|
@@ -324,6 +338,7 @@ function initApp(appOptions) {
|
|
|
324
338
|
};
|
|
325
339
|
}
|
|
326
340
|
export {
|
|
341
|
+
DownloadError,
|
|
327
342
|
IncrementalUpdater,
|
|
328
343
|
MinimumVersionError,
|
|
329
344
|
VerifyFailedError,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-incremental-update",
|
|
3
3
|
"author": "subframe7536",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.0",
|
|
5
5
|
"description": "electron incremental update tools, powered by vite",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsup && node fix-module.js",
|
|
@@ -58,4 +58,4 @@
|
|
|
58
58
|
"ci-info": "^3.8.0",
|
|
59
59
|
"selfsigned": "^2.1.1"
|
|
60
60
|
}
|
|
61
|
-
}
|
|
61
|
+
}
|