electron-incremental-update 0.7.8 → 0.7.10
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 +9 -10
- package/dist/chunk-2JVXVTC5.mjs +9 -0
- package/dist/{chunk-SWXNCK6H.mjs → chunk-4TION32M.mjs} +19 -12
- package/dist/{chunk-2XHZMWRR.mjs → chunk-Q2K52LOG.mjs} +1 -8
- package/dist/chunk-ZFXKCRJC.mjs +11 -0
- package/dist/index.d.mts +79 -48
- package/dist/index.d.ts +79 -48
- package/dist/index.js +191 -161
- package/dist/index.mjs +158 -138
- package/dist/{updateJson-7e45d9e1.d.ts → updateJson.d.mts} +2 -1
- package/dist/updateJson.d.ts +12 -0
- package/dist/updateJson.js +33 -0
- package/dist/updateJson.mjs +7 -0
- package/dist/utils.d.mts +17 -7
- package/dist/utils.d.ts +17 -7
- package/dist/utils.js +16 -4
- package/dist/utils.mjs +2 -1
- package/dist/vite.d.mts +22 -19
- package/dist/vite.d.ts +22 -19
- package/dist/vite.js +14 -2
- package/dist/vite.mjs +6 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,16 +60,17 @@ import { name, repository } from '../package.json'
|
|
|
60
60
|
|
|
61
61
|
const SIGNATURE_CERT = '' // auto generate certificate when start app
|
|
62
62
|
|
|
63
|
-
const { cdnPrefix } = getGithubReleaseCdnGroup()[0]
|
|
63
|
+
const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
|
|
64
|
+
const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
|
|
64
65
|
initApp({ onStart: console.log })
|
|
65
66
|
// can be updater option or function that return updater
|
|
66
67
|
.setUpdater({
|
|
67
68
|
SIGNATURE_CERT,
|
|
68
69
|
productName: name,
|
|
69
70
|
repository,
|
|
70
|
-
updateJsonURL: parseGithubCdnURL(repository,
|
|
71
|
-
releaseAsarURL: parseGithubCdnURL(repository,
|
|
72
|
-
|
|
71
|
+
updateJsonURL: parseGithubCdnURL(repository, jsonPrefix, 'version.json'),
|
|
72
|
+
releaseAsarURL: parseGithubCdnURL(repository, asarPrefix, `download/latest/${name}.asar.gz`),
|
|
73
|
+
receiveBeta: true
|
|
73
74
|
})
|
|
74
75
|
```
|
|
75
76
|
|
|
@@ -94,18 +95,16 @@ const startup: StartupWithUpdater = (updater: Updater) => {
|
|
|
94
95
|
console.log(`\tasar path: ${getProductAsarPath(name)}`)
|
|
95
96
|
console.log(`\tentry: ${getEntryVersion()}`)
|
|
96
97
|
console.log(`\tapp: ${getProductVersion(name)}`)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
updater.on('debug', data => console.log('[updater]:', data))
|
|
98
|
+
updater.onDownloading = ({ percent }) => {
|
|
99
|
+
console.log(percent)
|
|
100
|
+
}
|
|
101
|
+
updater.logger = console
|
|
102
102
|
updater.checkUpdate().then(async (result) => {
|
|
103
103
|
if (result === undefined) {
|
|
104
104
|
console.log('Update Unavailable')
|
|
105
105
|
} else if (result instanceof Error) {
|
|
106
106
|
console.error(result)
|
|
107
107
|
} else {
|
|
108
|
-
size = result.size
|
|
109
108
|
console.log('new version: ', result.version)
|
|
110
109
|
const { response } = await dialog.showMessageBox({
|
|
111
110
|
type: 'info',
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
if (typeof require !== "undefined")
|
|
5
|
-
return require.apply(this, arguments);
|
|
6
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
-
});
|
|
1
|
+
import {
|
|
2
|
+
__require
|
|
3
|
+
} from "./chunk-ZFXKCRJC.mjs";
|
|
8
4
|
|
|
9
5
|
// src/utils.ts
|
|
10
6
|
import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
@@ -82,11 +78,11 @@ function waitAppReady(duration = 1e3) {
|
|
|
82
78
|
}, duration);
|
|
83
79
|
app.whenReady().then(() => {
|
|
84
80
|
clearTimeout(timeout);
|
|
85
|
-
resolve(
|
|
81
|
+
resolve();
|
|
86
82
|
});
|
|
87
83
|
});
|
|
88
84
|
}
|
|
89
|
-
async function unzipFile(gzipPath, targetFilePath) {
|
|
85
|
+
async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
|
|
90
86
|
if (!existsSync(gzipPath)) {
|
|
91
87
|
throw new Error(`path to zipped file not exist: ${gzipPath}`);
|
|
92
88
|
}
|
|
@@ -132,14 +128,25 @@ function parseVersion(version) {
|
|
|
132
128
|
throw new TypeError(`invalid version: ${version}`);
|
|
133
129
|
}
|
|
134
130
|
const [major, minor, patch] = match.slice(1, 4).map(Number);
|
|
135
|
-
|
|
131
|
+
const ret = {
|
|
132
|
+
major,
|
|
133
|
+
minor,
|
|
134
|
+
patch,
|
|
135
|
+
stage: "",
|
|
136
|
+
stageVersion: -1
|
|
137
|
+
};
|
|
138
|
+
if (match[4]) {
|
|
139
|
+
let [stage, _v] = match[4].split(".");
|
|
140
|
+
ret.stage = stage;
|
|
141
|
+
ret.stageVersion = Number(_v) || -1;
|
|
142
|
+
}
|
|
143
|
+
if (isNaN(major) || isNaN(minor) || isNaN(patch) || isNaN(ret.stageVersion)) {
|
|
136
144
|
throw new TypeError(`invalid version: ${version}`);
|
|
137
145
|
}
|
|
138
|
-
return
|
|
146
|
+
return ret;
|
|
139
147
|
}
|
|
140
148
|
|
|
141
149
|
export {
|
|
142
|
-
__require,
|
|
143
150
|
getProductAsarPath,
|
|
144
151
|
getEntryVersion,
|
|
145
152
|
getProductVersion,
|
|
@@ -31,14 +31,7 @@ var verify = (buffer, signature2, cert) => {
|
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
// src/updateJson.ts
|
|
35
|
-
function isUpdateJSON(json) {
|
|
36
|
-
const is = (j) => "signature" in j && "version" in j && "size" in j && "minimumVersion" in j;
|
|
37
|
-
return is(json) && "beta" in json && is(json.beta);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
34
|
export {
|
|
41
35
|
signature,
|
|
42
|
-
verify
|
|
43
|
-
isUpdateJSON
|
|
36
|
+
verify
|
|
44
37
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined")
|
|
5
|
+
return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
__require
|
|
11
|
+
};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
|
-
import {
|
|
2
|
+
import { UpdateJSON } from './updateJson.mjs';
|
|
3
3
|
|
|
4
4
|
declare class MinimumVersionError extends Error {
|
|
5
5
|
currentVersion: string;
|
|
@@ -11,39 +11,73 @@ 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();
|
|
16
|
+
}
|
|
17
|
+
declare class IncrementalUpdater implements Updater {
|
|
18
|
+
private info?;
|
|
19
|
+
private option;
|
|
20
|
+
private asarPath;
|
|
21
|
+
private gzipPath;
|
|
22
|
+
private tmpFilePath;
|
|
23
|
+
logger?: Logger;
|
|
24
|
+
onDownloading?: (progress: DownloadingInfo) => void;
|
|
25
|
+
get productName(): string;
|
|
26
|
+
set productName(name: string);
|
|
27
|
+
get receiveBeta(): boolean;
|
|
28
|
+
set receiveBeta(receiveBeta: boolean);
|
|
29
|
+
constructor(option: UpdaterOption);
|
|
30
|
+
private needUpdate;
|
|
31
|
+
private parseData;
|
|
32
|
+
checkUpdate(data?: string | UpdateJSON): Promise<CheckResultType>;
|
|
33
|
+
download(data?: string | Buffer, sig?: string): Promise<DownloadResult>;
|
|
34
|
+
}
|
|
14
35
|
/**
|
|
15
|
-
*
|
|
36
|
+
* create updater instance
|
|
37
|
+
* @param option updater option
|
|
38
|
+
* @returns updater
|
|
16
39
|
*/
|
|
17
|
-
declare function createUpdater(
|
|
40
|
+
declare function createUpdater(option: UpdaterOption): IncrementalUpdater;
|
|
18
41
|
|
|
42
|
+
type CheckResultError = MinimumVersionError | DownloadError | TypeError | Error;
|
|
43
|
+
type DownloadResultError = DownloadError | VerifyFailedError | TypeError | Error;
|
|
19
44
|
type CheckResultType = {
|
|
20
45
|
size: number;
|
|
21
46
|
version: string;
|
|
22
|
-
} | undefined |
|
|
23
|
-
type DownloadResult = true |
|
|
24
|
-
type
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
47
|
+
} | undefined | CheckResultError;
|
|
48
|
+
type DownloadResult = true | DownloadResultError;
|
|
49
|
+
type DownloadingInfo = {
|
|
50
|
+
/**
|
|
51
|
+
* downloaded percent, 0% - 100%
|
|
52
|
+
*/
|
|
53
|
+
percent: string;
|
|
54
|
+
/**
|
|
55
|
+
* total size
|
|
56
|
+
*/
|
|
57
|
+
total: number;
|
|
58
|
+
/**
|
|
59
|
+
* downloaded size
|
|
60
|
+
*/
|
|
61
|
+
current: number;
|
|
62
|
+
};
|
|
63
|
+
type Logger = {
|
|
64
|
+
info: (msg: string) => void;
|
|
65
|
+
debug: (msg: string) => void;
|
|
66
|
+
warn: (msg: string) => void;
|
|
67
|
+
error: (msg: string, e?: Error) => void;
|
|
28
68
|
};
|
|
29
|
-
type Evt = Exclude<keyof UpdateEvents, number>;
|
|
30
69
|
interface Updater {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
eventNames(): Evt[];
|
|
34
|
-
on<E extends Evt>(eventName: E, listener: (...data: UpdateEvents[E]) => void): this;
|
|
35
|
-
once<E extends Evt>(eventName: E, listener: (...data: UpdateEvents[E]) => void): this;
|
|
36
|
-
emit<E extends Evt>(eventName: E, ...args: UpdateEvents[E]): boolean;
|
|
37
|
-
off<E extends Evt>(eventName: E, listener: (...args: UpdateEvents[E]) => void): this;
|
|
70
|
+
productName: string;
|
|
71
|
+
receiveBeta: boolean;
|
|
38
72
|
/**
|
|
39
73
|
* check update info
|
|
40
|
-
* @param data update json url
|
|
74
|
+
* @param data update json url or object
|
|
41
75
|
* @returns
|
|
42
76
|
* - `{size: number, version: string}`: available
|
|
43
|
-
* - `
|
|
44
|
-
* - `
|
|
77
|
+
* - `undefined`: unavailable
|
|
78
|
+
* - `CheckResultError`: fail
|
|
45
79
|
*/
|
|
46
|
-
checkUpdate(data?: string | UpdateJSON)
|
|
80
|
+
checkUpdate: (data?: string | UpdateJSON) => Promise<CheckResultType>;
|
|
47
81
|
/**
|
|
48
82
|
* download update
|
|
49
83
|
*
|
|
@@ -52,32 +86,32 @@ interface Updater {
|
|
|
52
86
|
* @param sig signature
|
|
53
87
|
* @returns
|
|
54
88
|
* - `true`: success
|
|
55
|
-
* - `
|
|
89
|
+
* - `DownloadResultError`: fail
|
|
56
90
|
*/
|
|
57
|
-
download(data?: string | Buffer, sig?: string)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
91
|
+
download: (data?: string | Buffer, sig?: string) => Promise<DownloadResult>;
|
|
92
|
+
/**
|
|
93
|
+
* log function
|
|
94
|
+
* @param data log info
|
|
95
|
+
*/
|
|
96
|
+
logger?: Logger;
|
|
97
|
+
onDownloading?: (progress: DownloadingInfo) => void;
|
|
61
98
|
}
|
|
62
|
-
type FunctionVerifySignature = (buffer: Buffer, signature: string, cert: string) => string | false | Promise<string | false>;
|
|
63
|
-
type FunctionCompareVersion = (oldVersion: string, newVersion: string) => boolean | Promise<boolean>;
|
|
64
|
-
type FunctionDownloadBuffer = (url: string, updater: Updater, headers: Record<string, any>) => Promise<Buffer>;
|
|
65
|
-
type FunctionDownloadJSON = (url: string, updater: Updater, headers: Record<string, any>) => Promise<UpdateJSON>;
|
|
66
99
|
type UpdaterOverrideFunctions = {
|
|
67
100
|
/**
|
|
68
|
-
* custom version compare function
|
|
69
|
-
* @param
|
|
70
|
-
* @param
|
|
71
|
-
* @returns whether
|
|
101
|
+
* custom version compare function
|
|
102
|
+
* @param version1 old version string
|
|
103
|
+
* @param version2 new version string
|
|
104
|
+
* @returns whether version1 < version2
|
|
72
105
|
*/
|
|
73
|
-
compareVersion?:
|
|
106
|
+
compareVersion?: (version1: string, version2: string) => boolean | Promise<boolean>;
|
|
74
107
|
/**
|
|
75
|
-
* custom verify signature function
|
|
108
|
+
* custom verify signature function
|
|
76
109
|
* @param buffer file buffer
|
|
77
110
|
* @param signature signature
|
|
78
111
|
* @param cert certificate
|
|
112
|
+
* @returns if signature is valid, returns the version or `true` , otherwise returns `false`
|
|
79
113
|
*/
|
|
80
|
-
verifySignaure?:
|
|
114
|
+
verifySignaure?: (buffer: Buffer, signature: string, cert: string) => string | boolean | Promise<string | boolean>;
|
|
81
115
|
/**
|
|
82
116
|
* custom download JSON function
|
|
83
117
|
* @param url download url
|
|
@@ -85,7 +119,7 @@ type UpdaterOverrideFunctions = {
|
|
|
85
119
|
* @param header download header
|
|
86
120
|
* @returns `UpdateJSON`
|
|
87
121
|
*/
|
|
88
|
-
downloadJSON?:
|
|
122
|
+
downloadJSON?: (url: string, headers: Record<string, any>) => Promise<UpdateJSON>;
|
|
89
123
|
/**
|
|
90
124
|
* custom download buffer function
|
|
91
125
|
* @param url download url
|
|
@@ -93,7 +127,7 @@ type UpdaterOverrideFunctions = {
|
|
|
93
127
|
* @param header download header
|
|
94
128
|
* @returns `Buffer`
|
|
95
129
|
*/
|
|
96
|
-
downloadBuffer?:
|
|
130
|
+
downloadBuffer?: (url: string, headers: Record<string, any>, total: number, onDownloading?: (progress: DownloadingInfo) => void) => Promise<Buffer>;
|
|
97
131
|
};
|
|
98
132
|
type UpdaterDownloadConfig = {
|
|
99
133
|
/**
|
|
@@ -148,10 +182,6 @@ interface UpdaterOption {
|
|
|
148
182
|
* @throws if `releaseAsarURL` and `repository` are all not set
|
|
149
183
|
*/
|
|
150
184
|
releaseAsarURL?: string;
|
|
151
|
-
/**
|
|
152
|
-
* whether to enable debug listener
|
|
153
|
-
*/
|
|
154
|
-
debug?: boolean;
|
|
155
185
|
/**
|
|
156
186
|
* whether to receive beta update
|
|
157
187
|
*/
|
|
@@ -196,19 +226,20 @@ type SetUpdater = {
|
|
|
196
226
|
*
|
|
197
227
|
* const SIGNATURE_CERT = '' // auto generate certificate when start app
|
|
198
228
|
*
|
|
199
|
-
* const { cdnPrefix } = getGithubReleaseCdnGroup()[0]
|
|
229
|
+
* const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
|
|
230
|
+
* const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
|
|
200
231
|
* initApp({ onStart: console.log })
|
|
201
232
|
* // can be updater option or function that return updater
|
|
202
233
|
* .setUpdater({
|
|
203
234
|
* SIGNATURE_CERT,
|
|
204
235
|
* productName: name,
|
|
205
236
|
* repository,
|
|
206
|
-
* updateJsonURL: parseGithubCdnURL(repository,
|
|
207
|
-
* releaseAsarURL: parseGithubCdnURL(repository,
|
|
208
|
-
*
|
|
237
|
+
* updateJsonURL: parseGithubCdnURL(repository, jsonPrefix, 'version.json'),
|
|
238
|
+
* releaseAsarURL: parseGithubCdnURL(repository, asarPrefix, `download/latest/${name}.asar.gz`),
|
|
239
|
+
* receiveBeta: true,
|
|
209
240
|
* })
|
|
210
241
|
* ```
|
|
211
242
|
*/
|
|
212
243
|
declare function initApp(appOptions?: AppOption): SetUpdater;
|
|
213
244
|
|
|
214
|
-
export { AppOption,
|
|
245
|
+
export { AppOption, DownloadError, IncrementalUpdater, MinimumVersionError, StartupWithUpdater, Updater, UpdaterOption, VerifyFailedError, createUpdater, initApp };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
|
-
import {
|
|
2
|
+
import { UpdateJSON } from './updateJson.js';
|
|
3
3
|
|
|
4
4
|
declare class MinimumVersionError extends Error {
|
|
5
5
|
currentVersion: string;
|
|
@@ -11,39 +11,73 @@ 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();
|
|
16
|
+
}
|
|
17
|
+
declare class IncrementalUpdater implements Updater {
|
|
18
|
+
private info?;
|
|
19
|
+
private option;
|
|
20
|
+
private asarPath;
|
|
21
|
+
private gzipPath;
|
|
22
|
+
private tmpFilePath;
|
|
23
|
+
logger?: Logger;
|
|
24
|
+
onDownloading?: (progress: DownloadingInfo) => void;
|
|
25
|
+
get productName(): string;
|
|
26
|
+
set productName(name: string);
|
|
27
|
+
get receiveBeta(): boolean;
|
|
28
|
+
set receiveBeta(receiveBeta: boolean);
|
|
29
|
+
constructor(option: UpdaterOption);
|
|
30
|
+
private needUpdate;
|
|
31
|
+
private parseData;
|
|
32
|
+
checkUpdate(data?: string | UpdateJSON): Promise<CheckResultType>;
|
|
33
|
+
download(data?: string | Buffer, sig?: string): Promise<DownloadResult>;
|
|
34
|
+
}
|
|
14
35
|
/**
|
|
15
|
-
*
|
|
36
|
+
* create updater instance
|
|
37
|
+
* @param option updater option
|
|
38
|
+
* @returns updater
|
|
16
39
|
*/
|
|
17
|
-
declare function createUpdater(
|
|
40
|
+
declare function createUpdater(option: UpdaterOption): IncrementalUpdater;
|
|
18
41
|
|
|
42
|
+
type CheckResultError = MinimumVersionError | DownloadError | TypeError | Error;
|
|
43
|
+
type DownloadResultError = DownloadError | VerifyFailedError | TypeError | Error;
|
|
19
44
|
type CheckResultType = {
|
|
20
45
|
size: number;
|
|
21
46
|
version: string;
|
|
22
|
-
} | undefined |
|
|
23
|
-
type DownloadResult = true |
|
|
24
|
-
type
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
47
|
+
} | undefined | CheckResultError;
|
|
48
|
+
type DownloadResult = true | DownloadResultError;
|
|
49
|
+
type DownloadingInfo = {
|
|
50
|
+
/**
|
|
51
|
+
* downloaded percent, 0% - 100%
|
|
52
|
+
*/
|
|
53
|
+
percent: string;
|
|
54
|
+
/**
|
|
55
|
+
* total size
|
|
56
|
+
*/
|
|
57
|
+
total: number;
|
|
58
|
+
/**
|
|
59
|
+
* downloaded size
|
|
60
|
+
*/
|
|
61
|
+
current: number;
|
|
62
|
+
};
|
|
63
|
+
type Logger = {
|
|
64
|
+
info: (msg: string) => void;
|
|
65
|
+
debug: (msg: string) => void;
|
|
66
|
+
warn: (msg: string) => void;
|
|
67
|
+
error: (msg: string, e?: Error) => void;
|
|
28
68
|
};
|
|
29
|
-
type Evt = Exclude<keyof UpdateEvents, number>;
|
|
30
69
|
interface Updater {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
eventNames(): Evt[];
|
|
34
|
-
on<E extends Evt>(eventName: E, listener: (...data: UpdateEvents[E]) => void): this;
|
|
35
|
-
once<E extends Evt>(eventName: E, listener: (...data: UpdateEvents[E]) => void): this;
|
|
36
|
-
emit<E extends Evt>(eventName: E, ...args: UpdateEvents[E]): boolean;
|
|
37
|
-
off<E extends Evt>(eventName: E, listener: (...args: UpdateEvents[E]) => void): this;
|
|
70
|
+
productName: string;
|
|
71
|
+
receiveBeta: boolean;
|
|
38
72
|
/**
|
|
39
73
|
* check update info
|
|
40
|
-
* @param data update json url
|
|
74
|
+
* @param data update json url or object
|
|
41
75
|
* @returns
|
|
42
76
|
* - `{size: number, version: string}`: available
|
|
43
|
-
* - `
|
|
44
|
-
* - `
|
|
77
|
+
* - `undefined`: unavailable
|
|
78
|
+
* - `CheckResultError`: fail
|
|
45
79
|
*/
|
|
46
|
-
checkUpdate(data?: string | UpdateJSON)
|
|
80
|
+
checkUpdate: (data?: string | UpdateJSON) => Promise<CheckResultType>;
|
|
47
81
|
/**
|
|
48
82
|
* download update
|
|
49
83
|
*
|
|
@@ -52,32 +86,32 @@ interface Updater {
|
|
|
52
86
|
* @param sig signature
|
|
53
87
|
* @returns
|
|
54
88
|
* - `true`: success
|
|
55
|
-
* - `
|
|
89
|
+
* - `DownloadResultError`: fail
|
|
56
90
|
*/
|
|
57
|
-
download(data?: string | Buffer, sig?: string)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
91
|
+
download: (data?: string | Buffer, sig?: string) => Promise<DownloadResult>;
|
|
92
|
+
/**
|
|
93
|
+
* log function
|
|
94
|
+
* @param data log info
|
|
95
|
+
*/
|
|
96
|
+
logger?: Logger;
|
|
97
|
+
onDownloading?: (progress: DownloadingInfo) => void;
|
|
61
98
|
}
|
|
62
|
-
type FunctionVerifySignature = (buffer: Buffer, signature: string, cert: string) => string | false | Promise<string | false>;
|
|
63
|
-
type FunctionCompareVersion = (oldVersion: string, newVersion: string) => boolean | Promise<boolean>;
|
|
64
|
-
type FunctionDownloadBuffer = (url: string, updater: Updater, headers: Record<string, any>) => Promise<Buffer>;
|
|
65
|
-
type FunctionDownloadJSON = (url: string, updater: Updater, headers: Record<string, any>) => Promise<UpdateJSON>;
|
|
66
99
|
type UpdaterOverrideFunctions = {
|
|
67
100
|
/**
|
|
68
|
-
* custom version compare function
|
|
69
|
-
* @param
|
|
70
|
-
* @param
|
|
71
|
-
* @returns whether
|
|
101
|
+
* custom version compare function
|
|
102
|
+
* @param version1 old version string
|
|
103
|
+
* @param version2 new version string
|
|
104
|
+
* @returns whether version1 < version2
|
|
72
105
|
*/
|
|
73
|
-
compareVersion?:
|
|
106
|
+
compareVersion?: (version1: string, version2: string) => boolean | Promise<boolean>;
|
|
74
107
|
/**
|
|
75
|
-
* custom verify signature function
|
|
108
|
+
* custom verify signature function
|
|
76
109
|
* @param buffer file buffer
|
|
77
110
|
* @param signature signature
|
|
78
111
|
* @param cert certificate
|
|
112
|
+
* @returns if signature is valid, returns the version or `true` , otherwise returns `false`
|
|
79
113
|
*/
|
|
80
|
-
verifySignaure?:
|
|
114
|
+
verifySignaure?: (buffer: Buffer, signature: string, cert: string) => string | boolean | Promise<string | boolean>;
|
|
81
115
|
/**
|
|
82
116
|
* custom download JSON function
|
|
83
117
|
* @param url download url
|
|
@@ -85,7 +119,7 @@ type UpdaterOverrideFunctions = {
|
|
|
85
119
|
* @param header download header
|
|
86
120
|
* @returns `UpdateJSON`
|
|
87
121
|
*/
|
|
88
|
-
downloadJSON?:
|
|
122
|
+
downloadJSON?: (url: string, headers: Record<string, any>) => Promise<UpdateJSON>;
|
|
89
123
|
/**
|
|
90
124
|
* custom download buffer function
|
|
91
125
|
* @param url download url
|
|
@@ -93,7 +127,7 @@ type UpdaterOverrideFunctions = {
|
|
|
93
127
|
* @param header download header
|
|
94
128
|
* @returns `Buffer`
|
|
95
129
|
*/
|
|
96
|
-
downloadBuffer?:
|
|
130
|
+
downloadBuffer?: (url: string, headers: Record<string, any>, total: number, onDownloading?: (progress: DownloadingInfo) => void) => Promise<Buffer>;
|
|
97
131
|
};
|
|
98
132
|
type UpdaterDownloadConfig = {
|
|
99
133
|
/**
|
|
@@ -148,10 +182,6 @@ interface UpdaterOption {
|
|
|
148
182
|
* @throws if `releaseAsarURL` and `repository` are all not set
|
|
149
183
|
*/
|
|
150
184
|
releaseAsarURL?: string;
|
|
151
|
-
/**
|
|
152
|
-
* whether to enable debug listener
|
|
153
|
-
*/
|
|
154
|
-
debug?: boolean;
|
|
155
185
|
/**
|
|
156
186
|
* whether to receive beta update
|
|
157
187
|
*/
|
|
@@ -196,19 +226,20 @@ type SetUpdater = {
|
|
|
196
226
|
*
|
|
197
227
|
* const SIGNATURE_CERT = '' // auto generate certificate when start app
|
|
198
228
|
*
|
|
199
|
-
* const { cdnPrefix } = getGithubReleaseCdnGroup()[0]
|
|
229
|
+
* const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
|
|
230
|
+
* const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
|
|
200
231
|
* initApp({ onStart: console.log })
|
|
201
232
|
* // can be updater option or function that return updater
|
|
202
233
|
* .setUpdater({
|
|
203
234
|
* SIGNATURE_CERT,
|
|
204
235
|
* productName: name,
|
|
205
236
|
* repository,
|
|
206
|
-
* updateJsonURL: parseGithubCdnURL(repository,
|
|
207
|
-
* releaseAsarURL: parseGithubCdnURL(repository,
|
|
208
|
-
*
|
|
237
|
+
* updateJsonURL: parseGithubCdnURL(repository, jsonPrefix, 'version.json'),
|
|
238
|
+
* releaseAsarURL: parseGithubCdnURL(repository, asarPrefix, `download/latest/${name}.asar.gz`),
|
|
239
|
+
* receiveBeta: true,
|
|
209
240
|
* })
|
|
210
241
|
* ```
|
|
211
242
|
*/
|
|
212
243
|
declare function initApp(appOptions?: AppOption): SetUpdater;
|
|
213
244
|
|
|
214
|
-
export { AppOption,
|
|
245
|
+
export { AppOption, DownloadError, IncrementalUpdater, MinimumVersionError, StartupWithUpdater, Updater, UpdaterOption, VerifyFailedError, createUpdater, initApp };
|