electron-incremental-update 1.3.0 → 2.0.0-beta.2
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 +7 -3
- package/dist/chunk-BG22XZAB.js +257 -0
- package/dist/decrypt-D9WdXYjH.d.cts +4 -0
- package/dist/decrypt-D9WdXYjH.d.ts +4 -0
- package/dist/index.cjs +164 -303
- package/dist/index.d.cts +81 -182
- package/dist/index.d.ts +81 -182
- package/dist/index.js +132 -237
- package/dist/provider.cjs +236 -0
- package/dist/provider.d.cts +37 -0
- package/dist/provider.d.ts +37 -0
- package/dist/provider.js +107 -0
- package/dist/types-COqp44eg.d.cts +69 -0
- package/dist/types-CPq1MrYZ.d.ts +69 -0
- package/dist/utils.cjs +159 -125
- package/dist/utils.d.cts +32 -77
- package/dist/utils.d.ts +32 -77
- package/dist/utils.js +35 -11
- package/dist/{pure-GoN_3MEj.d.cts → version-CffZWDhZ.d.cts} +8 -7
- package/dist/{pure-GoN_3MEj.d.ts → version-CffZWDhZ.d.ts} +8 -7
- package/dist/vite.js +101 -136
- package/package.json +13 -7
- package/provider.d.ts +1 -0
- package/provider.js +1 -0
- package/dist/chunk-7ET4GMTZ.js +0 -236
- package/dist/chunk-CXHA5TF7.js +0 -236
- package/dist/chunk-HWUYTDEF.js +0 -236
- package/dist/chunk-RQCTJY4L.js +0 -236
- package/dist/chunk-SBPTSLG7.js +0 -235
- package/dist/vite.d.ts +0 -372
package/dist/index.d.ts
CHANGED
|
@@ -1,135 +1,82 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EventEmitter } from 'node:stream';
|
|
2
|
+
import { U as UpdateJSON, a as UpdateInfo } from './version-CffZWDhZ.js';
|
|
3
|
+
import { D as DownloadingInfo, U as URLHandler, I as IProvider } from './types-CPq1MrYZ.js';
|
|
4
|
+
import '@subframe7536/type-utils';
|
|
2
5
|
|
|
3
6
|
declare const ErrorInfo: {
|
|
4
|
-
readonly
|
|
7
|
+
readonly download: "Download failed";
|
|
5
8
|
readonly validate: "Validate failed";
|
|
6
9
|
readonly param: "Missing params";
|
|
7
|
-
readonly version: "Unsatisfied version";
|
|
8
10
|
};
|
|
9
11
|
declare class UpdaterError extends Error {
|
|
10
|
-
|
|
12
|
+
code: keyof typeof ErrorInfo;
|
|
13
|
+
constructor(msg: keyof typeof ErrorInfo, info: string);
|
|
11
14
|
}
|
|
12
|
-
type CheckResult
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* downloaded size
|
|
25
|
-
*/
|
|
26
|
-
current: number;
|
|
15
|
+
type CheckResult<T extends UpdateJSON> = {
|
|
16
|
+
success: true;
|
|
17
|
+
data: Omit<T, 'beta'>;
|
|
18
|
+
} | {
|
|
19
|
+
success: false;
|
|
20
|
+
/**
|
|
21
|
+
* minimal version that can update
|
|
22
|
+
*/
|
|
23
|
+
data: string;
|
|
24
|
+
} | {
|
|
25
|
+
success: false;
|
|
26
|
+
data: UpdaterError;
|
|
27
27
|
};
|
|
28
|
-
type
|
|
28
|
+
type DownloadResult = {
|
|
29
|
+
success: true;
|
|
30
|
+
} | {
|
|
31
|
+
success: false;
|
|
32
|
+
data: UpdaterError;
|
|
33
|
+
};
|
|
34
|
+
interface Logger {
|
|
29
35
|
info: (msg: string) => void;
|
|
30
36
|
debug: (msg: string) => void;
|
|
31
37
|
warn: (msg: string) => void;
|
|
32
|
-
error: (msg: string, e?:
|
|
33
|
-
}
|
|
34
|
-
type UpdaterOverrideFunctions = {
|
|
35
|
-
/**
|
|
36
|
-
* custom version compare function
|
|
37
|
-
* @param version1 old version string
|
|
38
|
-
* @param version2 new version string
|
|
39
|
-
* @returns if version1 < version2
|
|
40
|
-
*/
|
|
41
|
-
isLowerVersion?: (version1: string, version2: string) => boolean | Promise<boolean>;
|
|
42
|
-
/**
|
|
43
|
-
* custom verify signature function
|
|
44
|
-
* @param buffer file buffer
|
|
45
|
-
* @param signature signature
|
|
46
|
-
* @param cert certificate
|
|
47
|
-
* @returns if signature is valid, returns the version or `true` , otherwise returns `false`
|
|
48
|
-
*/
|
|
49
|
-
verifySignaure?: (buffer: Buffer, signature: string, cert: string) => string | false | Promise<string | false>;
|
|
50
|
-
/**
|
|
51
|
-
* custom download JSON function
|
|
52
|
-
* @param url download url
|
|
53
|
-
* @param header download header
|
|
54
|
-
* @returns `UpdateJSON`
|
|
55
|
-
*/
|
|
56
|
-
downloadJSON?: (url: string, headers: Record<string, any>) => Promise<UpdateJSON>;
|
|
57
|
-
/**
|
|
58
|
-
* custom download buffer function
|
|
59
|
-
* @param url download url
|
|
60
|
-
* @param headers download header
|
|
61
|
-
* @param total precaculated file total size
|
|
62
|
-
* @param onDownloading on downloading callback
|
|
63
|
-
* @returns `Buffer`
|
|
64
|
-
*/
|
|
65
|
-
downloadBuffer?: (url: string, headers: Record<string, any>, total: number, onDownloading?: (progress: DownloadingInfo) => void) => Promise<Buffer>;
|
|
66
|
-
};
|
|
67
|
-
type UpdaterDownloadConfig = {
|
|
68
|
-
/**
|
|
69
|
-
* download user agent
|
|
70
|
-
* @default 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36'
|
|
71
|
-
*/
|
|
72
|
-
userAgent?: string;
|
|
73
|
-
/**
|
|
74
|
-
* extra download header, `accept` and `user-agent` is set by default
|
|
75
|
-
*/
|
|
76
|
-
extraHeader?: Record<string, string>;
|
|
77
|
-
};
|
|
38
|
+
error: (msg: string, e?: unknown) => void;
|
|
39
|
+
}
|
|
78
40
|
interface UpdaterOption {
|
|
79
41
|
/**
|
|
80
42
|
* public key of signature, which will be auto generated by plugin,
|
|
81
43
|
* generate by `selfsigned` if not set
|
|
82
44
|
*/
|
|
83
45
|
SIGNATURE_CERT?: string;
|
|
84
|
-
/**
|
|
85
|
-
* repository url, e.g. `https://github.com/electron/electron`
|
|
86
|
-
*
|
|
87
|
-
* you can use the `repository` in `package.json`
|
|
88
|
-
*
|
|
89
|
-
* if `updateJsonURL` or `releaseAsarURL` are absent,
|
|
90
|
-
* `repository` will be used to determine the url
|
|
91
|
-
*/
|
|
92
|
-
repository?: string;
|
|
93
|
-
/**
|
|
94
|
-
* URL of version info json
|
|
95
|
-
* @default `${repository.replace('github.com', 'raw.githubusercontent.com')}/master/version.json`
|
|
96
|
-
* @throws if `updateJsonURL` and `repository` are all not set
|
|
97
|
-
*/
|
|
98
|
-
updateJsonURL?: string;
|
|
99
|
-
/**
|
|
100
|
-
* URL of release asar.gz
|
|
101
|
-
* @default `${repository}/releases/download/v${version}/${app.name}-${version}.asar.gz`
|
|
102
|
-
* @throws if `releaseAsarURL` and `repository` are all not set
|
|
103
|
-
*/
|
|
104
|
-
releaseAsarURL?: string;
|
|
105
46
|
/**
|
|
106
47
|
* whether to receive beta update
|
|
107
48
|
*/
|
|
108
49
|
receiveBeta?: boolean;
|
|
109
|
-
|
|
110
|
-
downloadConfig?: UpdaterDownloadConfig;
|
|
50
|
+
logger?: Logger;
|
|
111
51
|
}
|
|
112
52
|
|
|
113
|
-
declare class Updater {
|
|
53
|
+
declare class Updater extends EventEmitter<{
|
|
54
|
+
'checking': any;
|
|
55
|
+
'update-available': [data: UpdateInfo];
|
|
56
|
+
'update-unavailable': [reason: string];
|
|
57
|
+
'error': [error: UpdaterError];
|
|
58
|
+
'download-progress': [info: DownloadingInfo];
|
|
59
|
+
'update-downloaded': any;
|
|
60
|
+
}> {
|
|
114
61
|
private CERT;
|
|
115
62
|
private info?;
|
|
116
|
-
private
|
|
63
|
+
private options;
|
|
117
64
|
private asarPath;
|
|
118
65
|
private gzipPath;
|
|
119
66
|
private tmpFilePath;
|
|
67
|
+
private provider;
|
|
120
68
|
/**
|
|
121
69
|
* updater logger
|
|
122
70
|
*/
|
|
123
71
|
logger?: Logger;
|
|
124
72
|
/**
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* @
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* }
|
|
73
|
+
* URL handler hook
|
|
74
|
+
*
|
|
75
|
+
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public CDNs}
|
|
76
|
+
* @param url source url
|
|
77
|
+
* @param isDownloadAsar whether is download asar
|
|
131
78
|
*/
|
|
132
|
-
|
|
79
|
+
handleURL?: URLHandler;
|
|
133
80
|
/**
|
|
134
81
|
* whether receive beta version
|
|
135
82
|
*/
|
|
@@ -137,10 +84,10 @@ declare class Updater {
|
|
|
137
84
|
set receiveBeta(receiveBeta: boolean);
|
|
138
85
|
/**
|
|
139
86
|
* initialize incremental updater
|
|
87
|
+
* @param provider update provider
|
|
140
88
|
* @param option UpdaterOption
|
|
141
89
|
*/
|
|
142
|
-
constructor(option?: UpdaterOption);
|
|
143
|
-
private needUpdate;
|
|
90
|
+
constructor(provider: IProvider, option?: UpdaterOption);
|
|
144
91
|
/**
|
|
145
92
|
* this function is used to parse download data.
|
|
146
93
|
* - if format is `'json'`
|
|
@@ -152,120 +99,72 @@ declare class Updater {
|
|
|
152
99
|
* @param format 'json' or 'buffer'
|
|
153
100
|
* @param data download URL or update json or buffer
|
|
154
101
|
*/
|
|
155
|
-
private
|
|
102
|
+
private fetch;
|
|
156
103
|
/**
|
|
157
|
-
*
|
|
158
|
-
* @returns
|
|
159
|
-
* - Available: `{size: number, version: string}`
|
|
160
|
-
* - Unavailable: `undefined`
|
|
161
|
-
* - Fail: `UpdaterError`
|
|
104
|
+
* handle error message and emit error event
|
|
162
105
|
*/
|
|
163
|
-
|
|
106
|
+
private err;
|
|
164
107
|
/**
|
|
165
|
-
* check update info using
|
|
166
|
-
* @param url custom download URL of `updatejson`
|
|
167
|
-
* @returns
|
|
168
|
-
* - Available:`{size: number, version: string}`
|
|
169
|
-
* - Unavailable: `undefined`
|
|
170
|
-
* - Fail: `UpdaterError`
|
|
108
|
+
* check update info using default options
|
|
171
109
|
*/
|
|
172
|
-
checkUpdate(
|
|
110
|
+
checkUpdate(): Promise<boolean>;
|
|
173
111
|
/**
|
|
174
112
|
* check update info using existing update json
|
|
175
113
|
* @param data existing update json
|
|
176
|
-
* @returns
|
|
177
|
-
* - Available:`{size: number, version: string}`
|
|
178
|
-
* - Unavailable: `undefined`
|
|
179
|
-
* - Fail: `UpdaterError`
|
|
180
114
|
*/
|
|
181
|
-
checkUpdate(data: UpdateJSON): Promise<
|
|
115
|
+
checkUpdate(data: UpdateJSON): Promise<boolean>;
|
|
182
116
|
/**
|
|
183
117
|
* download update using default options
|
|
184
|
-
* @returns
|
|
185
|
-
* - Success: `true`
|
|
186
|
-
* - Fail: `UpdaterError`
|
|
187
118
|
*/
|
|
188
|
-
download(): Promise<
|
|
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>;
|
|
119
|
+
download(): Promise<boolean>;
|
|
197
120
|
/**
|
|
198
121
|
* download update using existing `asar.gz` buffer and signature
|
|
199
122
|
* @param data existing `asar.gz` buffer
|
|
200
123
|
* @param sig signature
|
|
201
|
-
* @returns
|
|
202
|
-
* - Success: `true`
|
|
203
|
-
* - Fail: `UpdaterError`
|
|
204
124
|
*/
|
|
205
|
-
download(data:
|
|
125
|
+
download(data: Uint8Array, sig: string): Promise<boolean>;
|
|
206
126
|
/**
|
|
207
127
|
* quit App and install
|
|
208
128
|
*/
|
|
209
129
|
quitAndInstall(): void;
|
|
210
130
|
}
|
|
211
131
|
|
|
212
|
-
type
|
|
213
|
-
declare const downloadJSONDefault: Func['downloadJSON'];
|
|
214
|
-
declare const downloadBufferDefault: Func['downloadBuffer'];
|
|
215
|
-
|
|
216
|
-
declare const isLowerVersionDefault: Func['isLowerVersion'];
|
|
217
|
-
|
|
132
|
+
type Promisable<T> = T | Promise<T>;
|
|
218
133
|
/**
|
|
219
|
-
*
|
|
220
|
-
* @param
|
|
221
|
-
* @
|
|
134
|
+
* hooks on rename temp asar path to `${app.name}.asar`
|
|
135
|
+
* @param install `() => renameSync(tempAsarPath, appNameAsarPath)`
|
|
136
|
+
* @param tempAsarPath temp(updated) asar path
|
|
137
|
+
* @param appNameAsarPath `${app.name}.asar` path
|
|
138
|
+
* @param logger logger
|
|
139
|
+
* @default install(); logger.info(`update success!`)
|
|
222
140
|
*/
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
141
|
+
type OnInstallFunction = (install: VoidFunction, tempAsarPath: string, appNameAsarPath: string, logger: Logger) => Promisable<void>;
|
|
142
|
+
interface AppOption {
|
|
143
|
+
/**
|
|
144
|
+
* update provider
|
|
145
|
+
*/
|
|
146
|
+
provider: IProvider;
|
|
228
147
|
/**
|
|
229
148
|
* updater options
|
|
230
149
|
*/
|
|
231
150
|
updater?: (() => Promisable<Updater>) | UpdaterOption;
|
|
232
151
|
/**
|
|
233
|
-
*
|
|
234
|
-
* @default '../dist-electron'
|
|
152
|
+
* hooks on rename temp asar path to `${app.name}.asar`
|
|
235
153
|
*/
|
|
236
|
-
|
|
154
|
+
onInstall?: OnInstallFunction;
|
|
237
155
|
/**
|
|
238
|
-
*
|
|
239
|
-
* @
|
|
156
|
+
* hooks before app start up
|
|
157
|
+
* @param mainFilePath main file path of `${app.name}.asar`
|
|
158
|
+
* @param logger logger
|
|
240
159
|
*/
|
|
241
|
-
|
|
160
|
+
beforeStart?: (mainFilePath: string, logger: Logger) => Promisable<void>;
|
|
242
161
|
/**
|
|
243
|
-
*
|
|
162
|
+
* hooks on app start up error
|
|
163
|
+
* @param err installing or startup error
|
|
164
|
+
* @param logger logger
|
|
244
165
|
*/
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
* hooks on rename temp asar path to `${app.name}.asar`
|
|
248
|
-
* @param install `() => renameSync(tempAsarPath, appNameAsarPath)`
|
|
249
|
-
* @param tempAsarPath temp(updated) asar path
|
|
250
|
-
* @param appNameAsarPath `${app.name}.asar` path
|
|
251
|
-
* @param logger logger
|
|
252
|
-
* @default install(); logger?.info(`update success!`)
|
|
253
|
-
*/
|
|
254
|
-
onInstall?: OnInstallFunction;
|
|
255
|
-
/**
|
|
256
|
-
* hooks before start
|
|
257
|
-
* @param appNameAsarPath path of `${app.name}.asar`
|
|
258
|
-
* @param logger logger
|
|
259
|
-
*/
|
|
260
|
-
beforeStart?: (appNameAsarPath: string, logger?: Logger) => Promisable<void>;
|
|
261
|
-
/**
|
|
262
|
-
* hooks on start up error
|
|
263
|
-
* @param err installing or startup error
|
|
264
|
-
* @param logger logger
|
|
265
|
-
*/
|
|
266
|
-
onStartError?: (err: unknown, logger?: Logger) => void;
|
|
267
|
-
};
|
|
268
|
-
};
|
|
166
|
+
onStartError?: (err: unknown, logger: Logger) => void;
|
|
167
|
+
}
|
|
269
168
|
/**
|
|
270
169
|
* utils for startuping with updater
|
|
271
170
|
* @param fn startup function
|
|
@@ -299,6 +198,6 @@ declare function startupWithUpdater(fn: (updater: Updater) => Promisable<void>):
|
|
|
299
198
|
* })
|
|
300
199
|
* ```
|
|
301
200
|
*/
|
|
302
|
-
declare function initApp(appOptions
|
|
201
|
+
declare function initApp(appOptions: AppOption): Promise<void>;
|
|
303
202
|
|
|
304
|
-
export { type AppOption, type CheckResult, type DownloadResult,
|
|
203
|
+
export { type AppOption, type CheckResult, type DownloadResult, ErrorInfo, type Logger, Updater, UpdaterError, type UpdaterOption, initApp, startupWithUpdater };
|