electron-incremental-update 0.9.1 → 1.0.1
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 +172 -112
- package/dist/{chunk-CMBFI77K.mjs → chunk-GB6VLKJZ.mjs} +48 -28
- package/dist/{chunk-5BZLJPHJ.mjs → chunk-GXZSAUBR.mjs} +1 -8
- package/dist/chunk-OUZLSVQC.mjs +148 -0
- package/dist/index.d.mts +102 -80
- package/dist/index.d.ts +102 -80
- package/dist/index.js +134 -71
- package/dist/index.mjs +97 -43
- package/dist/noDep-TvZoKVF8.d.mts +31 -0
- package/dist/noDep-TvZoKVF8.d.ts +31 -0
- package/dist/utils.d.mts +85 -48
- package/dist/utils.d.ts +85 -48
- package/dist/utils.js +127 -86
- package/dist/utils.mjs +14 -20
- package/dist/vite.d.mts +218 -41
- package/dist/vite.d.ts +218 -41
- package/dist/vite.js +245 -122
- package/dist/vite.mjs +222 -98
- package/package.json +18 -11
- package/dist/chunk-SPZL37O5.mjs +0 -124
- package/dist/updateJson-synsK-Pt.d.mts +0 -11
- package/dist/updateJson-synsK-Pt.d.ts +0 -11
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { U as UpdateJSON } from './
|
|
1
|
+
import { U as UpdateInfo, a as UpdateJSON } from './noDep-TvZoKVF8.mjs';
|
|
2
2
|
|
|
3
3
|
declare class MinimumVersionError extends Error {
|
|
4
4
|
currentVersion: string;
|
|
@@ -13,18 +13,15 @@ declare class VerifyFailedError extends Error {
|
|
|
13
13
|
declare class DownloadError extends Error {
|
|
14
14
|
constructor(msg: string);
|
|
15
15
|
}
|
|
16
|
+
type CheckResult = UpdateInfo | undefined | CheckResultError;
|
|
16
17
|
type CheckResultError = MinimumVersionError | DownloadError | TypeError | Error;
|
|
17
|
-
type DownloadResultError = DownloadError | VerifyFailedError | TypeError | Error;
|
|
18
|
-
type CheckResultType = {
|
|
19
|
-
size: number;
|
|
20
|
-
version: string;
|
|
21
|
-
} | undefined | CheckResultError;
|
|
22
18
|
type DownloadResult = true | DownloadResultError;
|
|
19
|
+
type DownloadResultError = DownloadError | VerifyFailedError | TypeError | Error;
|
|
23
20
|
type DownloadingInfo = {
|
|
24
21
|
/**
|
|
25
22
|
* downloaded percent, 0% - 100%
|
|
26
23
|
*/
|
|
27
|
-
percent:
|
|
24
|
+
percent: `${number}%`;
|
|
28
25
|
/**
|
|
29
26
|
* total size
|
|
30
27
|
*/
|
|
@@ -40,47 +37,6 @@ type Logger = {
|
|
|
40
37
|
warn: (msg: string) => void;
|
|
41
38
|
error: (msg: string, e?: Error) => void;
|
|
42
39
|
};
|
|
43
|
-
interface Updater {
|
|
44
|
-
/**
|
|
45
|
-
* the name of the product, also the basename of the asar
|
|
46
|
-
*/
|
|
47
|
-
productName: string;
|
|
48
|
-
/**
|
|
49
|
-
* whether receive beta version
|
|
50
|
-
*/
|
|
51
|
-
receiveBeta: boolean;
|
|
52
|
-
/**
|
|
53
|
-
* check update info
|
|
54
|
-
* @param data update json url or object
|
|
55
|
-
* @returns
|
|
56
|
-
* - `{size: number, version: string}`: available
|
|
57
|
-
* - `undefined`: unavailable
|
|
58
|
-
* - `CheckResultError`: fail
|
|
59
|
-
*/
|
|
60
|
-
checkUpdate: (data?: string | UpdateJSON) => Promise<CheckResultType>;
|
|
61
|
-
/**
|
|
62
|
-
* download update
|
|
63
|
-
*
|
|
64
|
-
* if you want to update **offline**, you can set both `src` and `sig` to verify and install
|
|
65
|
-
* @param data asar download url or buffer
|
|
66
|
-
* @param sig signature
|
|
67
|
-
* @returns
|
|
68
|
-
* - `true`: success
|
|
69
|
-
* - `DownloadResultError`: fail
|
|
70
|
-
*/
|
|
71
|
-
download: (data?: string | Buffer, sig?: string) => Promise<DownloadResult>;
|
|
72
|
-
/**
|
|
73
|
-
* log function
|
|
74
|
-
* @param data log info
|
|
75
|
-
*/
|
|
76
|
-
logger?: Logger;
|
|
77
|
-
/**
|
|
78
|
-
* download progress function
|
|
79
|
-
* @param progress download progress info
|
|
80
|
-
* @returns void
|
|
81
|
-
*/
|
|
82
|
-
onDownloading?: (progress: DownloadingInfo) => void;
|
|
83
|
-
}
|
|
84
40
|
type UpdaterOverrideFunctions = {
|
|
85
41
|
/**
|
|
86
42
|
* custom version compare function
|
|
@@ -130,7 +86,7 @@ interface UpdaterOption {
|
|
|
130
86
|
* public key of signature, which will be auto generated by plugin
|
|
131
87
|
* @example
|
|
132
88
|
* ```ts
|
|
133
|
-
* // auto filled by plugin
|
|
89
|
+
* // just empty here, auto filled by plugin
|
|
134
90
|
* const SIGNATURE_CERT = ''
|
|
135
91
|
*
|
|
136
92
|
* const updater = createUpdater({
|
|
@@ -140,12 +96,6 @@ interface UpdaterOption {
|
|
|
140
96
|
* ```
|
|
141
97
|
*/
|
|
142
98
|
SIGNATURE_CERT: string;
|
|
143
|
-
/**
|
|
144
|
-
* name of your application, you can use the `name` in `package.json`
|
|
145
|
-
*
|
|
146
|
-
* @default DEFAULT_APP_NAME
|
|
147
|
-
*/
|
|
148
|
-
productName?: string;
|
|
149
99
|
/**
|
|
150
100
|
* repository url, e.g. `https://github.com/electron/electron`
|
|
151
101
|
*
|
|
@@ -163,7 +113,7 @@ interface UpdaterOption {
|
|
|
163
113
|
updateJsonURL?: string;
|
|
164
114
|
/**
|
|
165
115
|
* URL of release asar.gz
|
|
166
|
-
* @default `${repository}/releases/download/v${version}/${
|
|
116
|
+
* @default `${repository}/releases/download/v${version}/${app.name}-${version}.asar.gz`
|
|
167
117
|
* @throws if `releaseAsarURL` and `repository` are all not set
|
|
168
118
|
*/
|
|
169
119
|
releaseAsarURL?: string;
|
|
@@ -175,35 +125,89 @@ interface UpdaterOption {
|
|
|
175
125
|
downloadConfig?: UpdaterDownloadConfig;
|
|
176
126
|
}
|
|
177
127
|
|
|
178
|
-
declare class
|
|
128
|
+
declare class Updater {
|
|
179
129
|
private info?;
|
|
180
130
|
private option;
|
|
181
131
|
private asarPath;
|
|
182
132
|
private gzipPath;
|
|
183
133
|
private tmpFilePath;
|
|
134
|
+
/**
|
|
135
|
+
* updater logger
|
|
136
|
+
*/
|
|
184
137
|
logger?: Logger;
|
|
138
|
+
/**
|
|
139
|
+
* downloading progress hook
|
|
140
|
+
* @param progress download progress
|
|
141
|
+
* @example
|
|
142
|
+
* updater.onDownloading = ({ percent, total, current }) => {
|
|
143
|
+
* console.log(`download progress: ${percent}, total: ${total}, current: ${current}`)
|
|
144
|
+
* }
|
|
145
|
+
*/
|
|
185
146
|
onDownloading?: (progress: DownloadingInfo) => void;
|
|
186
|
-
|
|
147
|
+
/**
|
|
148
|
+
* whether receive beta version
|
|
149
|
+
*/
|
|
187
150
|
get receiveBeta(): boolean;
|
|
188
151
|
set receiveBeta(receiveBeta: boolean);
|
|
152
|
+
/**
|
|
153
|
+
* initialize incremental updater
|
|
154
|
+
* @param option UpdaterOption
|
|
155
|
+
*/
|
|
189
156
|
constructor(option: UpdaterOption);
|
|
190
157
|
private needUpdate;
|
|
158
|
+
/**
|
|
159
|
+
* this function is used to parse download data.
|
|
160
|
+
* - if format is `'json'`
|
|
161
|
+
* - if data is `UpdateJSON`, return it
|
|
162
|
+
* - if data is string or absent, download URL data and return it
|
|
163
|
+
* - if format is `'buffer'`
|
|
164
|
+
* - if data is `Buffer`, return it
|
|
165
|
+
* - if data is string or absent, download URL data and return it
|
|
166
|
+
* @param format 'json' or 'buffer'
|
|
167
|
+
* @param data download URL or update json or buffer
|
|
168
|
+
*/
|
|
191
169
|
private parseData;
|
|
192
|
-
|
|
193
|
-
|
|
170
|
+
/**
|
|
171
|
+
* check update info
|
|
172
|
+
*
|
|
173
|
+
* if you want to update **offline**, you can set `data` and `sig` add update info
|
|
174
|
+
* @param data custom download URL of `updatejson` or existing update json
|
|
175
|
+
* @returns
|
|
176
|
+
* - Available:`{size: number, version: string}`
|
|
177
|
+
* - Unavailable: `undefined`
|
|
178
|
+
* - Fail: `CheckResultError`
|
|
179
|
+
*/
|
|
180
|
+
checkUpdate(data?: string | UpdateJSON): Promise<CheckResult>;
|
|
181
|
+
/**
|
|
182
|
+
* download update
|
|
183
|
+
*
|
|
184
|
+
* if you want to update **offline**, you can set both `data` and `sig` to verify and install
|
|
185
|
+
* @param data custom download URL of `asar.gz` or existing `asar.gz` buffer
|
|
186
|
+
* @param sig signature
|
|
187
|
+
* @returns
|
|
188
|
+
* - `true`: success
|
|
189
|
+
* - `DownloadResultError`: fail
|
|
190
|
+
*/
|
|
191
|
+
download(data?: Buffer, sig?: string): Promise<DownloadResult>;
|
|
192
|
+
/**
|
|
193
|
+
* quit App and install
|
|
194
|
+
*/
|
|
195
|
+
quitAndInstall(): void;
|
|
194
196
|
}
|
|
197
|
+
|
|
195
198
|
/**
|
|
196
199
|
* create updater instance
|
|
197
200
|
* @param option updater option
|
|
198
201
|
* @returns updater
|
|
199
202
|
*/
|
|
200
|
-
declare function createUpdater(option: UpdaterOption):
|
|
203
|
+
declare function createUpdater(option: UpdaterOption): Updater;
|
|
201
204
|
|
|
202
205
|
type Promisable<T> = T | Promise<T>;
|
|
206
|
+
type OnInstallFunction = (install: VoidFunction, tempAsarPath: string, appNameAsarPath: string, logger?: Logger) => Promisable<void>;
|
|
203
207
|
type AppOption = {
|
|
204
208
|
/**
|
|
205
209
|
* path of electron output dist when in development
|
|
206
|
-
* @default 'dist-electron'
|
|
210
|
+
* @default '../dist-electron'
|
|
207
211
|
*/
|
|
208
212
|
electronDevDistPath?: string;
|
|
209
213
|
/**
|
|
@@ -211,53 +215,71 @@ type AppOption = {
|
|
|
211
215
|
* @default 'main/index.js'
|
|
212
216
|
*/
|
|
213
217
|
mainPath?: string;
|
|
218
|
+
/**
|
|
219
|
+
* update hooks
|
|
220
|
+
*/
|
|
214
221
|
hooks?: {
|
|
215
222
|
/**
|
|
216
|
-
* hooks
|
|
217
|
-
*
|
|
218
|
-
* @param
|
|
219
|
-
* @param
|
|
223
|
+
* hooks on rename temp asar path to `${app.name}.asar`
|
|
224
|
+
* @param install `() => renameSync(tempAsarPath, appNameAsarPath)`
|
|
225
|
+
* @param tempAsarPath temp(updated) asar path
|
|
226
|
+
* @param appNameAsarPath `${app.name}.asar` path
|
|
227
|
+
* @param logger logger
|
|
228
|
+
* @default install(); logger?.info(`update success!`)
|
|
220
229
|
*/
|
|
221
|
-
|
|
230
|
+
onInstall?: OnInstallFunction;
|
|
222
231
|
/**
|
|
223
|
-
* hooks before start
|
|
232
|
+
* hooks before start
|
|
233
|
+
* @param appNameAsarPath path of `${app.name}.asar`
|
|
234
|
+
* @param logger logger
|
|
224
235
|
*/
|
|
225
|
-
beforeStart?: (
|
|
236
|
+
beforeStart?: (appNameAsarPath: string, logger?: Logger) => Promisable<void>;
|
|
226
237
|
/**
|
|
227
238
|
* hooks on start up error
|
|
239
|
+
* @param err installing or startup error
|
|
240
|
+
* @param logger logger
|
|
228
241
|
*/
|
|
229
|
-
onStartError?: (err: unknown) => void;
|
|
242
|
+
onStartError?: (err: unknown, logger?: Logger) => void;
|
|
230
243
|
};
|
|
231
244
|
};
|
|
232
|
-
|
|
233
|
-
|
|
245
|
+
/**
|
|
246
|
+
* utils for startuping with updater
|
|
247
|
+
* @param fn startup function
|
|
248
|
+
* @example
|
|
249
|
+
* // in electron/main/index.ts
|
|
250
|
+
* export default startupWithUpdater((updater) => {
|
|
251
|
+
* updater.checkUpdate()
|
|
252
|
+
* })
|
|
253
|
+
*/
|
|
254
|
+
declare function startupWithUpdater(fn: (updater: Updater) => Promisable<void>): (updater: Updater) => Promisable<void>;
|
|
255
|
+
type StartupWithUpdater = {
|
|
234
256
|
/**
|
|
235
|
-
*
|
|
257
|
+
* starup app
|
|
258
|
+
* @param updater updater option or create function
|
|
236
259
|
*/
|
|
237
|
-
|
|
260
|
+
startupWithUpdater: (updater: (() => Promisable<Updater>) | UpdaterOption) => void;
|
|
238
261
|
};
|
|
239
262
|
/**
|
|
240
263
|
* initialize app
|
|
241
264
|
* @example
|
|
242
265
|
* ```ts
|
|
243
266
|
* import { getGithubReleaseCdnGroup, initApp, parseGithubCdnURL } from 'electron-incremental-update'
|
|
244
|
-
* import {
|
|
267
|
+
* import { repository } from '../package.json'
|
|
245
268
|
*
|
|
246
269
|
* const SIGNATURE_CERT = '' // auto generate certificate when start app
|
|
247
270
|
* const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
|
|
248
271
|
* const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
|
|
249
272
|
* initApp({ onStart: console.log })
|
|
250
273
|
* // can be updater option or function that return updater
|
|
251
|
-
* .
|
|
274
|
+
* .startupWithUpdater({
|
|
252
275
|
* SIGNATURE_CERT,
|
|
253
|
-
* productName: name,
|
|
254
276
|
* repository,
|
|
255
277
|
* updateJsonURL: parseGithubCdnURL(repository, jsonPrefix, 'version.json'),
|
|
256
|
-
* releaseAsarURL: parseGithubCdnURL(repository, asarPrefix, `download/latest/${name}.asar.gz`),
|
|
278
|
+
* releaseAsarURL: parseGithubCdnURL(repository, asarPrefix, `download/latest/${app.name}.asar.gz`),
|
|
257
279
|
* receiveBeta: true,
|
|
258
280
|
* })
|
|
259
281
|
* ```
|
|
260
282
|
*/
|
|
261
|
-
declare function initApp(appOptions?: AppOption):
|
|
283
|
+
declare function initApp(appOptions?: AppOption): StartupWithUpdater;
|
|
262
284
|
|
|
263
|
-
export { type AppOption,
|
|
285
|
+
export { type AppOption, type CheckResult, type CheckResultError, DownloadError, type DownloadResult, type DownloadResultError, type DownloadingInfo, type Logger, MinimumVersionError, Updater, type UpdaterDownloadConfig, type UpdaterOption, type UpdaterOverrideFunctions, VerifyFailedError, createUpdater, initApp, startupWithUpdater };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { U as UpdateJSON } from './
|
|
1
|
+
import { U as UpdateInfo, a as UpdateJSON } from './noDep-TvZoKVF8.js';
|
|
2
2
|
|
|
3
3
|
declare class MinimumVersionError extends Error {
|
|
4
4
|
currentVersion: string;
|
|
@@ -13,18 +13,15 @@ declare class VerifyFailedError extends Error {
|
|
|
13
13
|
declare class DownloadError extends Error {
|
|
14
14
|
constructor(msg: string);
|
|
15
15
|
}
|
|
16
|
+
type CheckResult = UpdateInfo | undefined | CheckResultError;
|
|
16
17
|
type CheckResultError = MinimumVersionError | DownloadError | TypeError | Error;
|
|
17
|
-
type DownloadResultError = DownloadError | VerifyFailedError | TypeError | Error;
|
|
18
|
-
type CheckResultType = {
|
|
19
|
-
size: number;
|
|
20
|
-
version: string;
|
|
21
|
-
} | undefined | CheckResultError;
|
|
22
18
|
type DownloadResult = true | DownloadResultError;
|
|
19
|
+
type DownloadResultError = DownloadError | VerifyFailedError | TypeError | Error;
|
|
23
20
|
type DownloadingInfo = {
|
|
24
21
|
/**
|
|
25
22
|
* downloaded percent, 0% - 100%
|
|
26
23
|
*/
|
|
27
|
-
percent:
|
|
24
|
+
percent: `${number}%`;
|
|
28
25
|
/**
|
|
29
26
|
* total size
|
|
30
27
|
*/
|
|
@@ -40,47 +37,6 @@ type Logger = {
|
|
|
40
37
|
warn: (msg: string) => void;
|
|
41
38
|
error: (msg: string, e?: Error) => void;
|
|
42
39
|
};
|
|
43
|
-
interface Updater {
|
|
44
|
-
/**
|
|
45
|
-
* the name of the product, also the basename of the asar
|
|
46
|
-
*/
|
|
47
|
-
productName: string;
|
|
48
|
-
/**
|
|
49
|
-
* whether receive beta version
|
|
50
|
-
*/
|
|
51
|
-
receiveBeta: boolean;
|
|
52
|
-
/**
|
|
53
|
-
* check update info
|
|
54
|
-
* @param data update json url or object
|
|
55
|
-
* @returns
|
|
56
|
-
* - `{size: number, version: string}`: available
|
|
57
|
-
* - `undefined`: unavailable
|
|
58
|
-
* - `CheckResultError`: fail
|
|
59
|
-
*/
|
|
60
|
-
checkUpdate: (data?: string | UpdateJSON) => Promise<CheckResultType>;
|
|
61
|
-
/**
|
|
62
|
-
* download update
|
|
63
|
-
*
|
|
64
|
-
* if you want to update **offline**, you can set both `src` and `sig` to verify and install
|
|
65
|
-
* @param data asar download url or buffer
|
|
66
|
-
* @param sig signature
|
|
67
|
-
* @returns
|
|
68
|
-
* - `true`: success
|
|
69
|
-
* - `DownloadResultError`: fail
|
|
70
|
-
*/
|
|
71
|
-
download: (data?: string | Buffer, sig?: string) => Promise<DownloadResult>;
|
|
72
|
-
/**
|
|
73
|
-
* log function
|
|
74
|
-
* @param data log info
|
|
75
|
-
*/
|
|
76
|
-
logger?: Logger;
|
|
77
|
-
/**
|
|
78
|
-
* download progress function
|
|
79
|
-
* @param progress download progress info
|
|
80
|
-
* @returns void
|
|
81
|
-
*/
|
|
82
|
-
onDownloading?: (progress: DownloadingInfo) => void;
|
|
83
|
-
}
|
|
84
40
|
type UpdaterOverrideFunctions = {
|
|
85
41
|
/**
|
|
86
42
|
* custom version compare function
|
|
@@ -130,7 +86,7 @@ interface UpdaterOption {
|
|
|
130
86
|
* public key of signature, which will be auto generated by plugin
|
|
131
87
|
* @example
|
|
132
88
|
* ```ts
|
|
133
|
-
* // auto filled by plugin
|
|
89
|
+
* // just empty here, auto filled by plugin
|
|
134
90
|
* const SIGNATURE_CERT = ''
|
|
135
91
|
*
|
|
136
92
|
* const updater = createUpdater({
|
|
@@ -140,12 +96,6 @@ interface UpdaterOption {
|
|
|
140
96
|
* ```
|
|
141
97
|
*/
|
|
142
98
|
SIGNATURE_CERT: string;
|
|
143
|
-
/**
|
|
144
|
-
* name of your application, you can use the `name` in `package.json`
|
|
145
|
-
*
|
|
146
|
-
* @default DEFAULT_APP_NAME
|
|
147
|
-
*/
|
|
148
|
-
productName?: string;
|
|
149
99
|
/**
|
|
150
100
|
* repository url, e.g. `https://github.com/electron/electron`
|
|
151
101
|
*
|
|
@@ -163,7 +113,7 @@ interface UpdaterOption {
|
|
|
163
113
|
updateJsonURL?: string;
|
|
164
114
|
/**
|
|
165
115
|
* URL of release asar.gz
|
|
166
|
-
* @default `${repository}/releases/download/v${version}/${
|
|
116
|
+
* @default `${repository}/releases/download/v${version}/${app.name}-${version}.asar.gz`
|
|
167
117
|
* @throws if `releaseAsarURL` and `repository` are all not set
|
|
168
118
|
*/
|
|
169
119
|
releaseAsarURL?: string;
|
|
@@ -175,35 +125,89 @@ interface UpdaterOption {
|
|
|
175
125
|
downloadConfig?: UpdaterDownloadConfig;
|
|
176
126
|
}
|
|
177
127
|
|
|
178
|
-
declare class
|
|
128
|
+
declare class Updater {
|
|
179
129
|
private info?;
|
|
180
130
|
private option;
|
|
181
131
|
private asarPath;
|
|
182
132
|
private gzipPath;
|
|
183
133
|
private tmpFilePath;
|
|
134
|
+
/**
|
|
135
|
+
* updater logger
|
|
136
|
+
*/
|
|
184
137
|
logger?: Logger;
|
|
138
|
+
/**
|
|
139
|
+
* downloading progress hook
|
|
140
|
+
* @param progress download progress
|
|
141
|
+
* @example
|
|
142
|
+
* updater.onDownloading = ({ percent, total, current }) => {
|
|
143
|
+
* console.log(`download progress: ${percent}, total: ${total}, current: ${current}`)
|
|
144
|
+
* }
|
|
145
|
+
*/
|
|
185
146
|
onDownloading?: (progress: DownloadingInfo) => void;
|
|
186
|
-
|
|
147
|
+
/**
|
|
148
|
+
* whether receive beta version
|
|
149
|
+
*/
|
|
187
150
|
get receiveBeta(): boolean;
|
|
188
151
|
set receiveBeta(receiveBeta: boolean);
|
|
152
|
+
/**
|
|
153
|
+
* initialize incremental updater
|
|
154
|
+
* @param option UpdaterOption
|
|
155
|
+
*/
|
|
189
156
|
constructor(option: UpdaterOption);
|
|
190
157
|
private needUpdate;
|
|
158
|
+
/**
|
|
159
|
+
* this function is used to parse download data.
|
|
160
|
+
* - if format is `'json'`
|
|
161
|
+
* - if data is `UpdateJSON`, return it
|
|
162
|
+
* - if data is string or absent, download URL data and return it
|
|
163
|
+
* - if format is `'buffer'`
|
|
164
|
+
* - if data is `Buffer`, return it
|
|
165
|
+
* - if data is string or absent, download URL data and return it
|
|
166
|
+
* @param format 'json' or 'buffer'
|
|
167
|
+
* @param data download URL or update json or buffer
|
|
168
|
+
*/
|
|
191
169
|
private parseData;
|
|
192
|
-
|
|
193
|
-
|
|
170
|
+
/**
|
|
171
|
+
* check update info
|
|
172
|
+
*
|
|
173
|
+
* if you want to update **offline**, you can set `data` and `sig` add update info
|
|
174
|
+
* @param data custom download URL of `updatejson` or existing update json
|
|
175
|
+
* @returns
|
|
176
|
+
* - Available:`{size: number, version: string}`
|
|
177
|
+
* - Unavailable: `undefined`
|
|
178
|
+
* - Fail: `CheckResultError`
|
|
179
|
+
*/
|
|
180
|
+
checkUpdate(data?: string | UpdateJSON): Promise<CheckResult>;
|
|
181
|
+
/**
|
|
182
|
+
* download update
|
|
183
|
+
*
|
|
184
|
+
* if you want to update **offline**, you can set both `data` and `sig` to verify and install
|
|
185
|
+
* @param data custom download URL of `asar.gz` or existing `asar.gz` buffer
|
|
186
|
+
* @param sig signature
|
|
187
|
+
* @returns
|
|
188
|
+
* - `true`: success
|
|
189
|
+
* - `DownloadResultError`: fail
|
|
190
|
+
*/
|
|
191
|
+
download(data?: Buffer, sig?: string): Promise<DownloadResult>;
|
|
192
|
+
/**
|
|
193
|
+
* quit App and install
|
|
194
|
+
*/
|
|
195
|
+
quitAndInstall(): void;
|
|
194
196
|
}
|
|
197
|
+
|
|
195
198
|
/**
|
|
196
199
|
* create updater instance
|
|
197
200
|
* @param option updater option
|
|
198
201
|
* @returns updater
|
|
199
202
|
*/
|
|
200
|
-
declare function createUpdater(option: UpdaterOption):
|
|
203
|
+
declare function createUpdater(option: UpdaterOption): Updater;
|
|
201
204
|
|
|
202
205
|
type Promisable<T> = T | Promise<T>;
|
|
206
|
+
type OnInstallFunction = (install: VoidFunction, tempAsarPath: string, appNameAsarPath: string, logger?: Logger) => Promisable<void>;
|
|
203
207
|
type AppOption = {
|
|
204
208
|
/**
|
|
205
209
|
* path of electron output dist when in development
|
|
206
|
-
* @default 'dist-electron'
|
|
210
|
+
* @default '../dist-electron'
|
|
207
211
|
*/
|
|
208
212
|
electronDevDistPath?: string;
|
|
209
213
|
/**
|
|
@@ -211,53 +215,71 @@ type AppOption = {
|
|
|
211
215
|
* @default 'main/index.js'
|
|
212
216
|
*/
|
|
213
217
|
mainPath?: string;
|
|
218
|
+
/**
|
|
219
|
+
* update hooks
|
|
220
|
+
*/
|
|
214
221
|
hooks?: {
|
|
215
222
|
/**
|
|
216
|
-
* hooks
|
|
217
|
-
*
|
|
218
|
-
* @param
|
|
219
|
-
* @param
|
|
223
|
+
* hooks on rename temp asar path to `${app.name}.asar`
|
|
224
|
+
* @param install `() => renameSync(tempAsarPath, appNameAsarPath)`
|
|
225
|
+
* @param tempAsarPath temp(updated) asar path
|
|
226
|
+
* @param appNameAsarPath `${app.name}.asar` path
|
|
227
|
+
* @param logger logger
|
|
228
|
+
* @default install(); logger?.info(`update success!`)
|
|
220
229
|
*/
|
|
221
|
-
|
|
230
|
+
onInstall?: OnInstallFunction;
|
|
222
231
|
/**
|
|
223
|
-
* hooks before start
|
|
232
|
+
* hooks before start
|
|
233
|
+
* @param appNameAsarPath path of `${app.name}.asar`
|
|
234
|
+
* @param logger logger
|
|
224
235
|
*/
|
|
225
|
-
beforeStart?: (
|
|
236
|
+
beforeStart?: (appNameAsarPath: string, logger?: Logger) => Promisable<void>;
|
|
226
237
|
/**
|
|
227
238
|
* hooks on start up error
|
|
239
|
+
* @param err installing or startup error
|
|
240
|
+
* @param logger logger
|
|
228
241
|
*/
|
|
229
|
-
onStartError?: (err: unknown) => void;
|
|
242
|
+
onStartError?: (err: unknown, logger?: Logger) => void;
|
|
230
243
|
};
|
|
231
244
|
};
|
|
232
|
-
|
|
233
|
-
|
|
245
|
+
/**
|
|
246
|
+
* utils for startuping with updater
|
|
247
|
+
* @param fn startup function
|
|
248
|
+
* @example
|
|
249
|
+
* // in electron/main/index.ts
|
|
250
|
+
* export default startupWithUpdater((updater) => {
|
|
251
|
+
* updater.checkUpdate()
|
|
252
|
+
* })
|
|
253
|
+
*/
|
|
254
|
+
declare function startupWithUpdater(fn: (updater: Updater) => Promisable<void>): (updater: Updater) => Promisable<void>;
|
|
255
|
+
type StartupWithUpdater = {
|
|
234
256
|
/**
|
|
235
|
-
*
|
|
257
|
+
* starup app
|
|
258
|
+
* @param updater updater option or create function
|
|
236
259
|
*/
|
|
237
|
-
|
|
260
|
+
startupWithUpdater: (updater: (() => Promisable<Updater>) | UpdaterOption) => void;
|
|
238
261
|
};
|
|
239
262
|
/**
|
|
240
263
|
* initialize app
|
|
241
264
|
* @example
|
|
242
265
|
* ```ts
|
|
243
266
|
* import { getGithubReleaseCdnGroup, initApp, parseGithubCdnURL } from 'electron-incremental-update'
|
|
244
|
-
* import {
|
|
267
|
+
* import { repository } from '../package.json'
|
|
245
268
|
*
|
|
246
269
|
* const SIGNATURE_CERT = '' // auto generate certificate when start app
|
|
247
270
|
* const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
|
|
248
271
|
* const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
|
|
249
272
|
* initApp({ onStart: console.log })
|
|
250
273
|
* // can be updater option or function that return updater
|
|
251
|
-
* .
|
|
274
|
+
* .startupWithUpdater({
|
|
252
275
|
* SIGNATURE_CERT,
|
|
253
|
-
* productName: name,
|
|
254
276
|
* repository,
|
|
255
277
|
* updateJsonURL: parseGithubCdnURL(repository, jsonPrefix, 'version.json'),
|
|
256
|
-
* releaseAsarURL: parseGithubCdnURL(repository, asarPrefix, `download/latest/${name}.asar.gz`),
|
|
278
|
+
* releaseAsarURL: parseGithubCdnURL(repository, asarPrefix, `download/latest/${app.name}.asar.gz`),
|
|
257
279
|
* receiveBeta: true,
|
|
258
280
|
* })
|
|
259
281
|
* ```
|
|
260
282
|
*/
|
|
261
|
-
declare function initApp(appOptions?: AppOption):
|
|
283
|
+
declare function initApp(appOptions?: AppOption): StartupWithUpdater;
|
|
262
284
|
|
|
263
|
-
export { type AppOption,
|
|
285
|
+
export { type AppOption, type CheckResult, type CheckResultError, DownloadError, type DownloadResult, type DownloadResultError, type DownloadingInfo, type Logger, MinimumVersionError, Updater, type UpdaterDownloadConfig, type UpdaterOption, type UpdaterOverrideFunctions, VerifyFailedError, createUpdater, initApp, startupWithUpdater };
|