electron-incremental-update 0.7.8 → 0.7.9
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 +69 -43
- package/dist/index.d.ts +69 -43
- package/dist/index.js +181 -162
- package/dist/index.mjs +149 -139
- 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 +2 -2
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,68 @@ declare class VerifyFailedError extends Error {
|
|
|
11
11
|
cert: string;
|
|
12
12
|
constructor(signature: string, cert: string);
|
|
13
13
|
}
|
|
14
|
+
declare class IncrementalUpdater implements Updater {
|
|
15
|
+
private info?;
|
|
16
|
+
private option;
|
|
17
|
+
private asarPath;
|
|
18
|
+
private gzipPath;
|
|
19
|
+
private tmpFilePath;
|
|
20
|
+
logger?: Logger;
|
|
21
|
+
onDownloading?: (progress: DownloadingInfo) => void;
|
|
22
|
+
get productName(): string;
|
|
23
|
+
set productName(name: string);
|
|
24
|
+
get receiveBeta(): boolean;
|
|
25
|
+
set receiveBeta(receiveBeta: boolean);
|
|
26
|
+
constructor(option: UpdaterOption);
|
|
27
|
+
private needUpdate;
|
|
28
|
+
private parseData;
|
|
29
|
+
checkUpdate(data?: string | UpdateJSON): Promise<CheckResultType>;
|
|
30
|
+
download(data?: string | Buffer, sig?: string): Promise<DownloadResult>;
|
|
31
|
+
}
|
|
14
32
|
/**
|
|
15
|
-
*
|
|
33
|
+
* create updater instance
|
|
34
|
+
* @param option updater option
|
|
35
|
+
* @returns updater
|
|
16
36
|
*/
|
|
17
|
-
declare function createUpdater(
|
|
37
|
+
declare function createUpdater(option: UpdaterOption): IncrementalUpdater;
|
|
18
38
|
|
|
19
39
|
type CheckResultType = {
|
|
20
40
|
size: number;
|
|
21
41
|
version: string;
|
|
22
42
|
} | undefined | Error | MinimumVersionError | TypeError;
|
|
23
43
|
type DownloadResult = true | Error | VerifyFailedError | TypeError;
|
|
24
|
-
type
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
44
|
+
type DownloadingInfo = {
|
|
45
|
+
/**
|
|
46
|
+
* downloaded percent, 0% - 100%
|
|
47
|
+
*/
|
|
48
|
+
percent: string;
|
|
49
|
+
/**
|
|
50
|
+
* total size
|
|
51
|
+
*/
|
|
52
|
+
total: number;
|
|
53
|
+
/**
|
|
54
|
+
* downloaded size
|
|
55
|
+
*/
|
|
56
|
+
current: number;
|
|
57
|
+
};
|
|
58
|
+
type Logger = {
|
|
59
|
+
info: (msg: string) => void;
|
|
60
|
+
debug: (msg: string) => void;
|
|
61
|
+
warn: (msg: string) => void;
|
|
62
|
+
error: (msg: string, e?: Error) => void;
|
|
28
63
|
};
|
|
29
|
-
type Evt = Exclude<keyof UpdateEvents, number>;
|
|
30
64
|
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;
|
|
65
|
+
productName: string;
|
|
66
|
+
receiveBeta: boolean;
|
|
38
67
|
/**
|
|
39
68
|
* check update info
|
|
40
|
-
* @param data update json url
|
|
69
|
+
* @param data update json url or object
|
|
41
70
|
* @returns
|
|
42
71
|
* - `{size: number, version: string}`: available
|
|
43
72
|
* - `false`: unavailable
|
|
44
73
|
* - `Error`: fail ({@link MinimumVersionError} or other)
|
|
45
74
|
*/
|
|
46
|
-
checkUpdate(data?: string | UpdateJSON)
|
|
75
|
+
checkUpdate: (data?: string | UpdateJSON) => Promise<CheckResultType>;
|
|
47
76
|
/**
|
|
48
77
|
* download update
|
|
49
78
|
*
|
|
@@ -54,30 +83,30 @@ interface Updater {
|
|
|
54
83
|
* - `true`: success
|
|
55
84
|
* - `Error`: fail ({@link VerifyFailedError} or other)
|
|
56
85
|
*/
|
|
57
|
-
download(data?: string | Buffer, sig?: string)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
86
|
+
download: (data?: string | Buffer, sig?: string) => Promise<DownloadResult>;
|
|
87
|
+
/**
|
|
88
|
+
* log function
|
|
89
|
+
* @param data log info
|
|
90
|
+
*/
|
|
91
|
+
logger?: Logger;
|
|
92
|
+
onDownloading?: (progress: DownloadingInfo) => void;
|
|
61
93
|
}
|
|
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
94
|
type UpdaterOverrideFunctions = {
|
|
67
95
|
/**
|
|
68
|
-
* custom version compare function
|
|
69
|
-
* @param
|
|
70
|
-
* @param
|
|
71
|
-
* @returns whether
|
|
96
|
+
* custom version compare function
|
|
97
|
+
* @param version1 old version string
|
|
98
|
+
* @param version2 new version string
|
|
99
|
+
* @returns whether version1 < version2
|
|
72
100
|
*/
|
|
73
|
-
compareVersion?:
|
|
101
|
+
compareVersion?: (version1: string, version2: string) => boolean | Promise<boolean>;
|
|
74
102
|
/**
|
|
75
|
-
* custom verify signature function
|
|
103
|
+
* custom verify signature function
|
|
76
104
|
* @param buffer file buffer
|
|
77
105
|
* @param signature signature
|
|
78
106
|
* @param cert certificate
|
|
107
|
+
* @returns if signature is valid, returns the version or `true` , otherwise returns `false`
|
|
79
108
|
*/
|
|
80
|
-
verifySignaure?:
|
|
109
|
+
verifySignaure?: (buffer: Buffer, signature: string, cert: string) => string | boolean | Promise<string | boolean>;
|
|
81
110
|
/**
|
|
82
111
|
* custom download JSON function
|
|
83
112
|
* @param url download url
|
|
@@ -85,7 +114,7 @@ type UpdaterOverrideFunctions = {
|
|
|
85
114
|
* @param header download header
|
|
86
115
|
* @returns `UpdateJSON`
|
|
87
116
|
*/
|
|
88
|
-
downloadJSON?:
|
|
117
|
+
downloadJSON?: (url: string, headers: Record<string, any>) => Promise<UpdateJSON>;
|
|
89
118
|
/**
|
|
90
119
|
* custom download buffer function
|
|
91
120
|
* @param url download url
|
|
@@ -93,7 +122,7 @@ type UpdaterOverrideFunctions = {
|
|
|
93
122
|
* @param header download header
|
|
94
123
|
* @returns `Buffer`
|
|
95
124
|
*/
|
|
96
|
-
downloadBuffer?:
|
|
125
|
+
downloadBuffer?: (url: string, headers: Record<string, any>, total: number, onDownloading?: (progress: DownloadingInfo) => void) => Promise<Buffer>;
|
|
97
126
|
};
|
|
98
127
|
type UpdaterDownloadConfig = {
|
|
99
128
|
/**
|
|
@@ -148,10 +177,6 @@ interface UpdaterOption {
|
|
|
148
177
|
* @throws if `releaseAsarURL` and `repository` are all not set
|
|
149
178
|
*/
|
|
150
179
|
releaseAsarURL?: string;
|
|
151
|
-
/**
|
|
152
|
-
* whether to enable debug listener
|
|
153
|
-
*/
|
|
154
|
-
debug?: boolean;
|
|
155
180
|
/**
|
|
156
181
|
* whether to receive beta update
|
|
157
182
|
*/
|
|
@@ -196,19 +221,20 @@ type SetUpdater = {
|
|
|
196
221
|
*
|
|
197
222
|
* const SIGNATURE_CERT = '' // auto generate certificate when start app
|
|
198
223
|
*
|
|
199
|
-
* const { cdnPrefix } = getGithubReleaseCdnGroup()[0]
|
|
224
|
+
* const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
|
|
225
|
+
* const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
|
|
200
226
|
* initApp({ onStart: console.log })
|
|
201
227
|
* // can be updater option or function that return updater
|
|
202
228
|
* .setUpdater({
|
|
203
229
|
* SIGNATURE_CERT,
|
|
204
230
|
* productName: name,
|
|
205
231
|
* repository,
|
|
206
|
-
* updateJsonURL: parseGithubCdnURL(repository,
|
|
207
|
-
* releaseAsarURL: parseGithubCdnURL(repository,
|
|
208
|
-
*
|
|
232
|
+
* updateJsonURL: parseGithubCdnURL(repository, jsonPrefix, 'version.json'),
|
|
233
|
+
* releaseAsarURL: parseGithubCdnURL(repository, asarPrefix, `download/latest/${name}.asar.gz`),
|
|
234
|
+
* receiveBeta: true,
|
|
209
235
|
* })
|
|
210
236
|
* ```
|
|
211
237
|
*/
|
|
212
238
|
declare function initApp(appOptions?: AppOption): SetUpdater;
|
|
213
239
|
|
|
214
|
-
export { AppOption,
|
|
240
|
+
export { AppOption, 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,68 @@ declare class VerifyFailedError extends Error {
|
|
|
11
11
|
cert: string;
|
|
12
12
|
constructor(signature: string, cert: string);
|
|
13
13
|
}
|
|
14
|
+
declare class IncrementalUpdater implements Updater {
|
|
15
|
+
private info?;
|
|
16
|
+
private option;
|
|
17
|
+
private asarPath;
|
|
18
|
+
private gzipPath;
|
|
19
|
+
private tmpFilePath;
|
|
20
|
+
logger?: Logger;
|
|
21
|
+
onDownloading?: (progress: DownloadingInfo) => void;
|
|
22
|
+
get productName(): string;
|
|
23
|
+
set productName(name: string);
|
|
24
|
+
get receiveBeta(): boolean;
|
|
25
|
+
set receiveBeta(receiveBeta: boolean);
|
|
26
|
+
constructor(option: UpdaterOption);
|
|
27
|
+
private needUpdate;
|
|
28
|
+
private parseData;
|
|
29
|
+
checkUpdate(data?: string | UpdateJSON): Promise<CheckResultType>;
|
|
30
|
+
download(data?: string | Buffer, sig?: string): Promise<DownloadResult>;
|
|
31
|
+
}
|
|
14
32
|
/**
|
|
15
|
-
*
|
|
33
|
+
* create updater instance
|
|
34
|
+
* @param option updater option
|
|
35
|
+
* @returns updater
|
|
16
36
|
*/
|
|
17
|
-
declare function createUpdater(
|
|
37
|
+
declare function createUpdater(option: UpdaterOption): IncrementalUpdater;
|
|
18
38
|
|
|
19
39
|
type CheckResultType = {
|
|
20
40
|
size: number;
|
|
21
41
|
version: string;
|
|
22
42
|
} | undefined | Error | MinimumVersionError | TypeError;
|
|
23
43
|
type DownloadResult = true | Error | VerifyFailedError | TypeError;
|
|
24
|
-
type
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
44
|
+
type DownloadingInfo = {
|
|
45
|
+
/**
|
|
46
|
+
* downloaded percent, 0% - 100%
|
|
47
|
+
*/
|
|
48
|
+
percent: string;
|
|
49
|
+
/**
|
|
50
|
+
* total size
|
|
51
|
+
*/
|
|
52
|
+
total: number;
|
|
53
|
+
/**
|
|
54
|
+
* downloaded size
|
|
55
|
+
*/
|
|
56
|
+
current: number;
|
|
57
|
+
};
|
|
58
|
+
type Logger = {
|
|
59
|
+
info: (msg: string) => void;
|
|
60
|
+
debug: (msg: string) => void;
|
|
61
|
+
warn: (msg: string) => void;
|
|
62
|
+
error: (msg: string, e?: Error) => void;
|
|
28
63
|
};
|
|
29
|
-
type Evt = Exclude<keyof UpdateEvents, number>;
|
|
30
64
|
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;
|
|
65
|
+
productName: string;
|
|
66
|
+
receiveBeta: boolean;
|
|
38
67
|
/**
|
|
39
68
|
* check update info
|
|
40
|
-
* @param data update json url
|
|
69
|
+
* @param data update json url or object
|
|
41
70
|
* @returns
|
|
42
71
|
* - `{size: number, version: string}`: available
|
|
43
72
|
* - `false`: unavailable
|
|
44
73
|
* - `Error`: fail ({@link MinimumVersionError} or other)
|
|
45
74
|
*/
|
|
46
|
-
checkUpdate(data?: string | UpdateJSON)
|
|
75
|
+
checkUpdate: (data?: string | UpdateJSON) => Promise<CheckResultType>;
|
|
47
76
|
/**
|
|
48
77
|
* download update
|
|
49
78
|
*
|
|
@@ -54,30 +83,30 @@ interface Updater {
|
|
|
54
83
|
* - `true`: success
|
|
55
84
|
* - `Error`: fail ({@link VerifyFailedError} or other)
|
|
56
85
|
*/
|
|
57
|
-
download(data?: string | Buffer, sig?: string)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
86
|
+
download: (data?: string | Buffer, sig?: string) => Promise<DownloadResult>;
|
|
87
|
+
/**
|
|
88
|
+
* log function
|
|
89
|
+
* @param data log info
|
|
90
|
+
*/
|
|
91
|
+
logger?: Logger;
|
|
92
|
+
onDownloading?: (progress: DownloadingInfo) => void;
|
|
61
93
|
}
|
|
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
94
|
type UpdaterOverrideFunctions = {
|
|
67
95
|
/**
|
|
68
|
-
* custom version compare function
|
|
69
|
-
* @param
|
|
70
|
-
* @param
|
|
71
|
-
* @returns whether
|
|
96
|
+
* custom version compare function
|
|
97
|
+
* @param version1 old version string
|
|
98
|
+
* @param version2 new version string
|
|
99
|
+
* @returns whether version1 < version2
|
|
72
100
|
*/
|
|
73
|
-
compareVersion?:
|
|
101
|
+
compareVersion?: (version1: string, version2: string) => boolean | Promise<boolean>;
|
|
74
102
|
/**
|
|
75
|
-
* custom verify signature function
|
|
103
|
+
* custom verify signature function
|
|
76
104
|
* @param buffer file buffer
|
|
77
105
|
* @param signature signature
|
|
78
106
|
* @param cert certificate
|
|
107
|
+
* @returns if signature is valid, returns the version or `true` , otherwise returns `false`
|
|
79
108
|
*/
|
|
80
|
-
verifySignaure?:
|
|
109
|
+
verifySignaure?: (buffer: Buffer, signature: string, cert: string) => string | boolean | Promise<string | boolean>;
|
|
81
110
|
/**
|
|
82
111
|
* custom download JSON function
|
|
83
112
|
* @param url download url
|
|
@@ -85,7 +114,7 @@ type UpdaterOverrideFunctions = {
|
|
|
85
114
|
* @param header download header
|
|
86
115
|
* @returns `UpdateJSON`
|
|
87
116
|
*/
|
|
88
|
-
downloadJSON?:
|
|
117
|
+
downloadJSON?: (url: string, headers: Record<string, any>) => Promise<UpdateJSON>;
|
|
89
118
|
/**
|
|
90
119
|
* custom download buffer function
|
|
91
120
|
* @param url download url
|
|
@@ -93,7 +122,7 @@ type UpdaterOverrideFunctions = {
|
|
|
93
122
|
* @param header download header
|
|
94
123
|
* @returns `Buffer`
|
|
95
124
|
*/
|
|
96
|
-
downloadBuffer?:
|
|
125
|
+
downloadBuffer?: (url: string, headers: Record<string, any>, total: number, onDownloading?: (progress: DownloadingInfo) => void) => Promise<Buffer>;
|
|
97
126
|
};
|
|
98
127
|
type UpdaterDownloadConfig = {
|
|
99
128
|
/**
|
|
@@ -148,10 +177,6 @@ interface UpdaterOption {
|
|
|
148
177
|
* @throws if `releaseAsarURL` and `repository` are all not set
|
|
149
178
|
*/
|
|
150
179
|
releaseAsarURL?: string;
|
|
151
|
-
/**
|
|
152
|
-
* whether to enable debug listener
|
|
153
|
-
*/
|
|
154
|
-
debug?: boolean;
|
|
155
180
|
/**
|
|
156
181
|
* whether to receive beta update
|
|
157
182
|
*/
|
|
@@ -196,19 +221,20 @@ type SetUpdater = {
|
|
|
196
221
|
*
|
|
197
222
|
* const SIGNATURE_CERT = '' // auto generate certificate when start app
|
|
198
223
|
*
|
|
199
|
-
* const { cdnPrefix } = getGithubReleaseCdnGroup()[0]
|
|
224
|
+
* const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
|
|
225
|
+
* const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
|
|
200
226
|
* initApp({ onStart: console.log })
|
|
201
227
|
* // can be updater option or function that return updater
|
|
202
228
|
* .setUpdater({
|
|
203
229
|
* SIGNATURE_CERT,
|
|
204
230
|
* productName: name,
|
|
205
231
|
* repository,
|
|
206
|
-
* updateJsonURL: parseGithubCdnURL(repository,
|
|
207
|
-
* releaseAsarURL: parseGithubCdnURL(repository,
|
|
208
|
-
*
|
|
232
|
+
* updateJsonURL: parseGithubCdnURL(repository, jsonPrefix, 'version.json'),
|
|
233
|
+
* releaseAsarURL: parseGithubCdnURL(repository, asarPrefix, `download/latest/${name}.asar.gz`),
|
|
234
|
+
* receiveBeta: true,
|
|
209
235
|
* })
|
|
210
236
|
* ```
|
|
211
237
|
*/
|
|
212
238
|
declare function initApp(appOptions?: AppOption): SetUpdater;
|
|
213
239
|
|
|
214
|
-
export { AppOption,
|
|
240
|
+
export { AppOption, IncrementalUpdater, MinimumVersionError, StartupWithUpdater, Updater, UpdaterOption, VerifyFailedError, createUpdater, initApp };
|