electron-incremental-update 2.0.0-beta.3 → 2.0.0-beta.4
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/{chunk-5WFXC5GU.js → chunk-JSYIRKTR.js} +17 -7
- package/dist/core-CW7TMqi7.d.cts +134 -0
- package/dist/core-D6QlpOgp.d.ts +134 -0
- package/dist/index.cjs +6 -12
- package/dist/index.d.cts +5 -135
- package/dist/index.d.ts +5 -135
- package/dist/index.js +8 -14
- package/dist/provider.cjs +20 -24
- package/dist/provider.d.cts +11 -10
- package/dist/provider.d.ts +11 -10
- package/dist/provider.js +17 -20
- package/dist/{types-DxhNaNgR.d.ts → types-Bz1VD18z.d.cts} +35 -5
- package/dist/{types-Tequ_V2o.d.cts → types-Bz1VD18z.d.ts} +35 -5
- package/dist/utils.cjs +14 -6
- package/dist/utils.d.cts +10 -4
- package/dist/utils.d.ts +10 -4
- package/dist/utils.js +7 -14
- package/dist/vite.d.ts +397 -0
- package/dist/vite.js +44 -28
- package/dist/{unzip-JjYLjJkH.d.ts → zip-WRrEMkgp.d.cts} +3 -2
- package/dist/{unzip-JjYLjJkH.d.cts → zip-WRrEMkgp.d.ts} +3 -2
- package/package.json +2 -2
- package/dist/version-CemSHimT.d.cts +0 -33
- package/dist/version-CemSHimT.d.ts +0 -33
|
@@ -1,16 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { brotliDecompress } from 'node:zlib';
|
|
1
|
+
import { brotliCompress, brotliDecompress } from 'node:zlib';
|
|
3
2
|
import { createHash, createCipheriv, createSign, createPrivateKey, createDecipheriv, createVerify } from 'node:crypto';
|
|
4
3
|
|
|
5
|
-
// src/utils/
|
|
6
|
-
async function
|
|
4
|
+
// src/utils/zip.ts
|
|
5
|
+
async function defaultZipFile(buffer) {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
brotliCompress(buffer, (err, buffer2) => {
|
|
8
|
+
if (err) {
|
|
9
|
+
reject(err);
|
|
10
|
+
} else {
|
|
11
|
+
resolve(buffer2);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
async function defaultUnzipFile(buffer) {
|
|
7
17
|
return new Promise((resolve, reject) => {
|
|
8
18
|
brotliDecompress(buffer, (err, buffer2) => {
|
|
9
19
|
if (err) {
|
|
10
20
|
reject(err);
|
|
21
|
+
} else {
|
|
22
|
+
resolve(buffer2);
|
|
11
23
|
}
|
|
12
|
-
writeFileSync(targetFilePath, buffer2);
|
|
13
|
-
resolve();
|
|
14
24
|
});
|
|
15
25
|
});
|
|
16
26
|
}
|
|
@@ -40,4 +50,4 @@ function defaultVerify(buffer, signature, cert) {
|
|
|
40
50
|
}
|
|
41
51
|
}
|
|
42
52
|
|
|
43
|
-
export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerify, hashBuffer };
|
|
53
|
+
export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerify, defaultZipFile, hashBuffer };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { a as UpdateJSON, U as UpdateInfo, D as DownloadingInfo, I as IProvider, c as URLHandler } from './types-Bz1VD18z.cjs';
|
|
3
|
+
|
|
4
|
+
declare const ErrorInfo: {
|
|
5
|
+
readonly download: "Download failed";
|
|
6
|
+
readonly validate: "Validate failed";
|
|
7
|
+
readonly param: "Missing params";
|
|
8
|
+
readonly network: "Network error";
|
|
9
|
+
};
|
|
10
|
+
declare class UpdaterError extends Error {
|
|
11
|
+
code: keyof typeof ErrorInfo;
|
|
12
|
+
constructor(msg: keyof typeof ErrorInfo, info: string);
|
|
13
|
+
}
|
|
14
|
+
type CheckResult<T extends UpdateJSON> = {
|
|
15
|
+
success: true;
|
|
16
|
+
data: Omit<T, 'beta'>;
|
|
17
|
+
} | {
|
|
18
|
+
success: false;
|
|
19
|
+
/**
|
|
20
|
+
* minimal version that can update
|
|
21
|
+
*/
|
|
22
|
+
data: string;
|
|
23
|
+
} | {
|
|
24
|
+
success: false;
|
|
25
|
+
data: UpdaterError;
|
|
26
|
+
};
|
|
27
|
+
type DownloadResult = {
|
|
28
|
+
success: true;
|
|
29
|
+
} | {
|
|
30
|
+
success: false;
|
|
31
|
+
data: UpdaterError;
|
|
32
|
+
};
|
|
33
|
+
interface Logger {
|
|
34
|
+
info: (msg: string) => void;
|
|
35
|
+
debug: (msg: string) => void;
|
|
36
|
+
warn: (msg: string) => void;
|
|
37
|
+
error: (msg: string, e?: unknown) => void;
|
|
38
|
+
}
|
|
39
|
+
interface UpdaterOption {
|
|
40
|
+
/**
|
|
41
|
+
* public key of signature, which will be auto generated by plugin,
|
|
42
|
+
* generate by `selfsigned` if not set
|
|
43
|
+
*/
|
|
44
|
+
SIGNATURE_CERT?: string;
|
|
45
|
+
/**
|
|
46
|
+
* whether to receive beta update
|
|
47
|
+
*/
|
|
48
|
+
receiveBeta?: boolean;
|
|
49
|
+
logger?: Logger;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare class Updater extends EventEmitter<{
|
|
53
|
+
'checking': any;
|
|
54
|
+
'update-available': [data: UpdateInfo];
|
|
55
|
+
'update-unavailable': [reason: string];
|
|
56
|
+
'error': [error: UpdaterError];
|
|
57
|
+
'download-progress': [info: DownloadingInfo];
|
|
58
|
+
'update-downloaded': any;
|
|
59
|
+
}> {
|
|
60
|
+
private CERT;
|
|
61
|
+
private info?;
|
|
62
|
+
private provider;
|
|
63
|
+
/**
|
|
64
|
+
* updater logger
|
|
65
|
+
*/
|
|
66
|
+
logger?: Logger;
|
|
67
|
+
/**
|
|
68
|
+
* whether to receive beta update
|
|
69
|
+
*/
|
|
70
|
+
receiveBeta?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* whether force update in DEV
|
|
73
|
+
*/
|
|
74
|
+
forceUpdate?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* initialize incremental updater
|
|
77
|
+
* @param provider update provider
|
|
78
|
+
* @param option UpdaterOption
|
|
79
|
+
*/
|
|
80
|
+
constructor(provider: IProvider, option?: UpdaterOption);
|
|
81
|
+
/**
|
|
82
|
+
* this function is used to parse download data.
|
|
83
|
+
* - if format is `'json'`
|
|
84
|
+
* - if data is `UpdateJSON`, return it
|
|
85
|
+
* - if data is string or absent, download URL data and return it
|
|
86
|
+
* - if format is `'buffer'`
|
|
87
|
+
* - if data is `Buffer`, return it
|
|
88
|
+
* - if data is string or absent, download URL data and return it
|
|
89
|
+
* @param format 'json' or 'buffer'
|
|
90
|
+
* @param data download URL or update json or buffer
|
|
91
|
+
*/
|
|
92
|
+
private fetch;
|
|
93
|
+
/**
|
|
94
|
+
* handle error message and emit error event
|
|
95
|
+
*/
|
|
96
|
+
private err;
|
|
97
|
+
/**
|
|
98
|
+
* check update info using default options
|
|
99
|
+
*/
|
|
100
|
+
checkUpdate(): Promise<boolean>;
|
|
101
|
+
/**
|
|
102
|
+
* check update info using existing update json
|
|
103
|
+
* @param data existing update json
|
|
104
|
+
*/
|
|
105
|
+
checkUpdate(data: UpdateJSON): Promise<boolean>;
|
|
106
|
+
/**
|
|
107
|
+
* download update using default options
|
|
108
|
+
*/
|
|
109
|
+
downloadUpdate(): Promise<boolean>;
|
|
110
|
+
/**
|
|
111
|
+
* download update using existing `asar.gz` buffer and signature
|
|
112
|
+
* @param data existing `asar.gz` buffer
|
|
113
|
+
* @param sig signature
|
|
114
|
+
*/
|
|
115
|
+
downloadUpdate(data: Uint8Array | Buffer, sig: string): Promise<boolean>;
|
|
116
|
+
/**
|
|
117
|
+
* quit App and install
|
|
118
|
+
*/
|
|
119
|
+
quitAndInstall(): void;
|
|
120
|
+
/**
|
|
121
|
+
* setup provider URL handler
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* updater.setURLHandler((url, isDownloadingAsar) => {
|
|
125
|
+
* if (isDownloadingAsar) {
|
|
126
|
+
* url.hostname = 'https://cdn.jsdelivr.net/gh'
|
|
127
|
+
* return url
|
|
128
|
+
* }
|
|
129
|
+
* })
|
|
130
|
+
*/
|
|
131
|
+
setURLHandler(handler: URLHandler): void;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export { type CheckResult as C, type DownloadResult as D, ErrorInfo as E, type Logger as L, Updater as U, type UpdaterOption as a, UpdaterError as b };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { a as UpdateJSON, U as UpdateInfo, D as DownloadingInfo, I as IProvider, c as URLHandler } from './types-Bz1VD18z.js';
|
|
3
|
+
|
|
4
|
+
declare const ErrorInfo: {
|
|
5
|
+
readonly download: "Download failed";
|
|
6
|
+
readonly validate: "Validate failed";
|
|
7
|
+
readonly param: "Missing params";
|
|
8
|
+
readonly network: "Network error";
|
|
9
|
+
};
|
|
10
|
+
declare class UpdaterError extends Error {
|
|
11
|
+
code: keyof typeof ErrorInfo;
|
|
12
|
+
constructor(msg: keyof typeof ErrorInfo, info: string);
|
|
13
|
+
}
|
|
14
|
+
type CheckResult<T extends UpdateJSON> = {
|
|
15
|
+
success: true;
|
|
16
|
+
data: Omit<T, 'beta'>;
|
|
17
|
+
} | {
|
|
18
|
+
success: false;
|
|
19
|
+
/**
|
|
20
|
+
* minimal version that can update
|
|
21
|
+
*/
|
|
22
|
+
data: string;
|
|
23
|
+
} | {
|
|
24
|
+
success: false;
|
|
25
|
+
data: UpdaterError;
|
|
26
|
+
};
|
|
27
|
+
type DownloadResult = {
|
|
28
|
+
success: true;
|
|
29
|
+
} | {
|
|
30
|
+
success: false;
|
|
31
|
+
data: UpdaterError;
|
|
32
|
+
};
|
|
33
|
+
interface Logger {
|
|
34
|
+
info: (msg: string) => void;
|
|
35
|
+
debug: (msg: string) => void;
|
|
36
|
+
warn: (msg: string) => void;
|
|
37
|
+
error: (msg: string, e?: unknown) => void;
|
|
38
|
+
}
|
|
39
|
+
interface UpdaterOption {
|
|
40
|
+
/**
|
|
41
|
+
* public key of signature, which will be auto generated by plugin,
|
|
42
|
+
* generate by `selfsigned` if not set
|
|
43
|
+
*/
|
|
44
|
+
SIGNATURE_CERT?: string;
|
|
45
|
+
/**
|
|
46
|
+
* whether to receive beta update
|
|
47
|
+
*/
|
|
48
|
+
receiveBeta?: boolean;
|
|
49
|
+
logger?: Logger;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare class Updater extends EventEmitter<{
|
|
53
|
+
'checking': any;
|
|
54
|
+
'update-available': [data: UpdateInfo];
|
|
55
|
+
'update-unavailable': [reason: string];
|
|
56
|
+
'error': [error: UpdaterError];
|
|
57
|
+
'download-progress': [info: DownloadingInfo];
|
|
58
|
+
'update-downloaded': any;
|
|
59
|
+
}> {
|
|
60
|
+
private CERT;
|
|
61
|
+
private info?;
|
|
62
|
+
private provider;
|
|
63
|
+
/**
|
|
64
|
+
* updater logger
|
|
65
|
+
*/
|
|
66
|
+
logger?: Logger;
|
|
67
|
+
/**
|
|
68
|
+
* whether to receive beta update
|
|
69
|
+
*/
|
|
70
|
+
receiveBeta?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* whether force update in DEV
|
|
73
|
+
*/
|
|
74
|
+
forceUpdate?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* initialize incremental updater
|
|
77
|
+
* @param provider update provider
|
|
78
|
+
* @param option UpdaterOption
|
|
79
|
+
*/
|
|
80
|
+
constructor(provider: IProvider, option?: UpdaterOption);
|
|
81
|
+
/**
|
|
82
|
+
* this function is used to parse download data.
|
|
83
|
+
* - if format is `'json'`
|
|
84
|
+
* - if data is `UpdateJSON`, return it
|
|
85
|
+
* - if data is string or absent, download URL data and return it
|
|
86
|
+
* - if format is `'buffer'`
|
|
87
|
+
* - if data is `Buffer`, return it
|
|
88
|
+
* - if data is string or absent, download URL data and return it
|
|
89
|
+
* @param format 'json' or 'buffer'
|
|
90
|
+
* @param data download URL or update json or buffer
|
|
91
|
+
*/
|
|
92
|
+
private fetch;
|
|
93
|
+
/**
|
|
94
|
+
* handle error message and emit error event
|
|
95
|
+
*/
|
|
96
|
+
private err;
|
|
97
|
+
/**
|
|
98
|
+
* check update info using default options
|
|
99
|
+
*/
|
|
100
|
+
checkUpdate(): Promise<boolean>;
|
|
101
|
+
/**
|
|
102
|
+
* check update info using existing update json
|
|
103
|
+
* @param data existing update json
|
|
104
|
+
*/
|
|
105
|
+
checkUpdate(data: UpdateJSON): Promise<boolean>;
|
|
106
|
+
/**
|
|
107
|
+
* download update using default options
|
|
108
|
+
*/
|
|
109
|
+
downloadUpdate(): Promise<boolean>;
|
|
110
|
+
/**
|
|
111
|
+
* download update using existing `asar.gz` buffer and signature
|
|
112
|
+
* @param data existing `asar.gz` buffer
|
|
113
|
+
* @param sig signature
|
|
114
|
+
*/
|
|
115
|
+
downloadUpdate(data: Uint8Array | Buffer, sig: string): Promise<boolean>;
|
|
116
|
+
/**
|
|
117
|
+
* quit App and install
|
|
118
|
+
*/
|
|
119
|
+
quitAndInstall(): void;
|
|
120
|
+
/**
|
|
121
|
+
* setup provider URL handler
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* updater.setURLHandler((url, isDownloadingAsar) => {
|
|
125
|
+
* if (isDownloadingAsar) {
|
|
126
|
+
* url.hostname = 'https://cdn.jsdelivr.net/gh'
|
|
127
|
+
* return url
|
|
128
|
+
* }
|
|
129
|
+
* })
|
|
130
|
+
*/
|
|
131
|
+
setURLHandler(handler: URLHandler): void;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export { type CheckResult as C, type DownloadResult as D, ErrorInfo as E, type Logger as L, Updater as U, type UpdaterOption as a, UpdaterError as b };
|
package/dist/index.cjs
CHANGED
|
@@ -54,8 +54,6 @@ var UpdaterError = class extends Error {
|
|
|
54
54
|
var Updater = class extends events.EventEmitter {
|
|
55
55
|
CERT = __EIU_SIGNATURE_CERT__;
|
|
56
56
|
info;
|
|
57
|
-
asarPath;
|
|
58
|
-
tmpFilePath;
|
|
59
57
|
provider;
|
|
60
58
|
/**
|
|
61
59
|
* updater logger
|
|
@@ -93,14 +91,8 @@ var Updater = class extends events.EventEmitter {
|
|
|
93
91
|
};
|
|
94
92
|
this.logger.info("no logger set, enable dev-only logger");
|
|
95
93
|
}
|
|
96
|
-
this.asarPath = getPathFromAppNameAsar();
|
|
97
|
-
this.tmpFilePath = `${this.asarPath}.tmp`;
|
|
98
94
|
}
|
|
99
95
|
async fetch(format, data) {
|
|
100
|
-
if (fs.existsSync(this.tmpFilePath)) {
|
|
101
|
-
this.logger?.warn(`remove tmp file: ${this.tmpFilePath}`);
|
|
102
|
-
fs.rmSync(this.tmpFilePath);
|
|
103
|
-
}
|
|
104
96
|
if (typeof data === "object") {
|
|
105
97
|
if (format === "json" && isUpdateJSON(data) || format === "buffer" && Buffer.isBuffer(data)) {
|
|
106
98
|
return data;
|
|
@@ -162,7 +154,7 @@ var Updater = class extends events.EventEmitter {
|
|
|
162
154
|
this.emit("update-available", this.info);
|
|
163
155
|
return true;
|
|
164
156
|
}
|
|
165
|
-
async
|
|
157
|
+
async downloadUpdate(data, sig) {
|
|
166
158
|
const _sig = sig ?? this.info?.signature;
|
|
167
159
|
if (!_sig) {
|
|
168
160
|
this.err("download failed", "param", "no update signature, please call `checkUpdate` first");
|
|
@@ -181,8 +173,9 @@ var Updater = class extends events.EventEmitter {
|
|
|
181
173
|
}
|
|
182
174
|
this.logger?.debug("verify success");
|
|
183
175
|
try {
|
|
184
|
-
|
|
185
|
-
|
|
176
|
+
const tmpFilePath = getPathFromAppNameAsar() + ".tmp";
|
|
177
|
+
this.logger?.debug(`install to ${tmpFilePath}`);
|
|
178
|
+
fs.writeFileSync(tmpFilePath, await this.provider.unzipFile(buffer));
|
|
186
179
|
this.logger?.info(`download success, version: ${_ver}`);
|
|
187
180
|
this.info = void 0;
|
|
188
181
|
this.emit("update-downloaded");
|
|
@@ -205,7 +198,8 @@ var Updater = class extends events.EventEmitter {
|
|
|
205
198
|
* @example
|
|
206
199
|
* updater.setURLHandler((url, isDownloadingAsar) => {
|
|
207
200
|
* if (isDownloadingAsar) {
|
|
208
|
-
*
|
|
201
|
+
* url.hostname = 'https://cdn.jsdelivr.net/gh'
|
|
202
|
+
* return url
|
|
209
203
|
* }
|
|
210
204
|
* })
|
|
211
205
|
*/
|
package/dist/index.d.cts
CHANGED
|
@@ -1,139 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
1
|
+
import { U as Updater, a as UpdaterOption, L as Logger } from './core-CW7TMqi7.cjs';
|
|
2
|
+
export { C as CheckResult, D as DownloadResult, E as ErrorInfo, b as UpdaterError } from './core-CW7TMqi7.cjs';
|
|
3
|
+
import { I as IProvider } from './types-Bz1VD18z.cjs';
|
|
4
|
+
import 'node:events';
|
|
4
5
|
import '@subframe7536/type-utils';
|
|
5
6
|
|
|
6
|
-
declare const ErrorInfo: {
|
|
7
|
-
readonly download: "Download failed";
|
|
8
|
-
readonly validate: "Validate failed";
|
|
9
|
-
readonly param: "Missing params";
|
|
10
|
-
readonly network: "Network error";
|
|
11
|
-
};
|
|
12
|
-
declare class UpdaterError extends Error {
|
|
13
|
-
code: keyof typeof ErrorInfo;
|
|
14
|
-
constructor(msg: keyof typeof ErrorInfo, info: string);
|
|
15
|
-
}
|
|
16
|
-
type CheckResult<T extends UpdateJSON> = {
|
|
17
|
-
success: true;
|
|
18
|
-
data: Omit<T, 'beta'>;
|
|
19
|
-
} | {
|
|
20
|
-
success: false;
|
|
21
|
-
/**
|
|
22
|
-
* minimal version that can update
|
|
23
|
-
*/
|
|
24
|
-
data: string;
|
|
25
|
-
} | {
|
|
26
|
-
success: false;
|
|
27
|
-
data: UpdaterError;
|
|
28
|
-
};
|
|
29
|
-
type DownloadResult = {
|
|
30
|
-
success: true;
|
|
31
|
-
} | {
|
|
32
|
-
success: false;
|
|
33
|
-
data: UpdaterError;
|
|
34
|
-
};
|
|
35
|
-
interface Logger {
|
|
36
|
-
info: (msg: string) => void;
|
|
37
|
-
debug: (msg: string) => void;
|
|
38
|
-
warn: (msg: string) => void;
|
|
39
|
-
error: (msg: string, e?: unknown) => void;
|
|
40
|
-
}
|
|
41
|
-
interface UpdaterOption {
|
|
42
|
-
/**
|
|
43
|
-
* public key of signature, which will be auto generated by plugin,
|
|
44
|
-
* generate by `selfsigned` if not set
|
|
45
|
-
*/
|
|
46
|
-
SIGNATURE_CERT?: string;
|
|
47
|
-
/**
|
|
48
|
-
* whether to receive beta update
|
|
49
|
-
*/
|
|
50
|
-
receiveBeta?: boolean;
|
|
51
|
-
logger?: Logger;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
declare class Updater extends EventEmitter<{
|
|
55
|
-
'checking': any;
|
|
56
|
-
'update-available': [data: UpdateInfo];
|
|
57
|
-
'update-unavailable': [reason: string];
|
|
58
|
-
'error': [error: UpdaterError];
|
|
59
|
-
'download-progress': [info: DownloadingInfo];
|
|
60
|
-
'update-downloaded': any;
|
|
61
|
-
}> {
|
|
62
|
-
private CERT;
|
|
63
|
-
private info?;
|
|
64
|
-
private asarPath;
|
|
65
|
-
private tmpFilePath;
|
|
66
|
-
private provider;
|
|
67
|
-
/**
|
|
68
|
-
* updater logger
|
|
69
|
-
*/
|
|
70
|
-
logger?: Logger;
|
|
71
|
-
/**
|
|
72
|
-
* whether to receive beta update
|
|
73
|
-
*/
|
|
74
|
-
receiveBeta?: boolean;
|
|
75
|
-
/**
|
|
76
|
-
* whether force update in DEV
|
|
77
|
-
*/
|
|
78
|
-
forceUpdate?: boolean;
|
|
79
|
-
/**
|
|
80
|
-
* initialize incremental updater
|
|
81
|
-
* @param provider update provider
|
|
82
|
-
* @param option UpdaterOption
|
|
83
|
-
*/
|
|
84
|
-
constructor(provider: IProvider, option?: UpdaterOption);
|
|
85
|
-
/**
|
|
86
|
-
* this function is used to parse download data.
|
|
87
|
-
* - if format is `'json'`
|
|
88
|
-
* - if data is `UpdateJSON`, return it
|
|
89
|
-
* - if data is string or absent, download URL data and return it
|
|
90
|
-
* - if format is `'buffer'`
|
|
91
|
-
* - if data is `Buffer`, return it
|
|
92
|
-
* - if data is string or absent, download URL data and return it
|
|
93
|
-
* @param format 'json' or 'buffer'
|
|
94
|
-
* @param data download URL or update json or buffer
|
|
95
|
-
*/
|
|
96
|
-
private fetch;
|
|
97
|
-
/**
|
|
98
|
-
* handle error message and emit error event
|
|
99
|
-
*/
|
|
100
|
-
private err;
|
|
101
|
-
/**
|
|
102
|
-
* check update info using default options
|
|
103
|
-
*/
|
|
104
|
-
checkUpdate(): Promise<boolean>;
|
|
105
|
-
/**
|
|
106
|
-
* check update info using existing update json
|
|
107
|
-
* @param data existing update json
|
|
108
|
-
*/
|
|
109
|
-
checkUpdate(data: UpdateJSON): Promise<boolean>;
|
|
110
|
-
/**
|
|
111
|
-
* download update using default options
|
|
112
|
-
*/
|
|
113
|
-
download(): Promise<boolean>;
|
|
114
|
-
/**
|
|
115
|
-
* download update using existing `asar.gz` buffer and signature
|
|
116
|
-
* @param data existing `asar.gz` buffer
|
|
117
|
-
* @param sig signature
|
|
118
|
-
*/
|
|
119
|
-
download(data: Uint8Array | Buffer, sig: string): Promise<boolean>;
|
|
120
|
-
/**
|
|
121
|
-
* quit App and install
|
|
122
|
-
*/
|
|
123
|
-
quitAndInstall(): void;
|
|
124
|
-
/**
|
|
125
|
-
* setup provider URL handler
|
|
126
|
-
*
|
|
127
|
-
* @example
|
|
128
|
-
* updater.setURLHandler((url, isDownloadingAsar) => {
|
|
129
|
-
* if (isDownloadingAsar) {
|
|
130
|
-
* return url.replace('https://raw.githubusercontent.com', 'https://cdn.jsdelivr.net/gh')
|
|
131
|
-
* }
|
|
132
|
-
* })
|
|
133
|
-
*/
|
|
134
|
-
setURLHandler(handler: URLHandler): void;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
7
|
type Promisable<T> = T | Promise<T>;
|
|
138
8
|
/**
|
|
139
9
|
* hooks on rename temp asar path to `${app.name}.asar`
|
|
@@ -205,4 +75,4 @@ declare function startupWithUpdater(fn: (updater: Updater) => Promisable<void>):
|
|
|
205
75
|
*/
|
|
206
76
|
declare function initApp(appOptions: AppOption): Promise<void>;
|
|
207
77
|
|
|
208
|
-
export { type AppOption,
|
|
78
|
+
export { type AppOption, Logger, Updater, UpdaterOption, initApp, startupWithUpdater };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,139 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
1
|
+
import { U as Updater, a as UpdaterOption, L as Logger } from './core-D6QlpOgp.js';
|
|
2
|
+
export { C as CheckResult, D as DownloadResult, E as ErrorInfo, b as UpdaterError } from './core-D6QlpOgp.js';
|
|
3
|
+
import { I as IProvider } from './types-Bz1VD18z.js';
|
|
4
|
+
import 'node:events';
|
|
4
5
|
import '@subframe7536/type-utils';
|
|
5
6
|
|
|
6
|
-
declare const ErrorInfo: {
|
|
7
|
-
readonly download: "Download failed";
|
|
8
|
-
readonly validate: "Validate failed";
|
|
9
|
-
readonly param: "Missing params";
|
|
10
|
-
readonly network: "Network error";
|
|
11
|
-
};
|
|
12
|
-
declare class UpdaterError extends Error {
|
|
13
|
-
code: keyof typeof ErrorInfo;
|
|
14
|
-
constructor(msg: keyof typeof ErrorInfo, info: string);
|
|
15
|
-
}
|
|
16
|
-
type CheckResult<T extends UpdateJSON> = {
|
|
17
|
-
success: true;
|
|
18
|
-
data: Omit<T, 'beta'>;
|
|
19
|
-
} | {
|
|
20
|
-
success: false;
|
|
21
|
-
/**
|
|
22
|
-
* minimal version that can update
|
|
23
|
-
*/
|
|
24
|
-
data: string;
|
|
25
|
-
} | {
|
|
26
|
-
success: false;
|
|
27
|
-
data: UpdaterError;
|
|
28
|
-
};
|
|
29
|
-
type DownloadResult = {
|
|
30
|
-
success: true;
|
|
31
|
-
} | {
|
|
32
|
-
success: false;
|
|
33
|
-
data: UpdaterError;
|
|
34
|
-
};
|
|
35
|
-
interface Logger {
|
|
36
|
-
info: (msg: string) => void;
|
|
37
|
-
debug: (msg: string) => void;
|
|
38
|
-
warn: (msg: string) => void;
|
|
39
|
-
error: (msg: string, e?: unknown) => void;
|
|
40
|
-
}
|
|
41
|
-
interface UpdaterOption {
|
|
42
|
-
/**
|
|
43
|
-
* public key of signature, which will be auto generated by plugin,
|
|
44
|
-
* generate by `selfsigned` if not set
|
|
45
|
-
*/
|
|
46
|
-
SIGNATURE_CERT?: string;
|
|
47
|
-
/**
|
|
48
|
-
* whether to receive beta update
|
|
49
|
-
*/
|
|
50
|
-
receiveBeta?: boolean;
|
|
51
|
-
logger?: Logger;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
declare class Updater extends EventEmitter<{
|
|
55
|
-
'checking': any;
|
|
56
|
-
'update-available': [data: UpdateInfo];
|
|
57
|
-
'update-unavailable': [reason: string];
|
|
58
|
-
'error': [error: UpdaterError];
|
|
59
|
-
'download-progress': [info: DownloadingInfo];
|
|
60
|
-
'update-downloaded': any;
|
|
61
|
-
}> {
|
|
62
|
-
private CERT;
|
|
63
|
-
private info?;
|
|
64
|
-
private asarPath;
|
|
65
|
-
private tmpFilePath;
|
|
66
|
-
private provider;
|
|
67
|
-
/**
|
|
68
|
-
* updater logger
|
|
69
|
-
*/
|
|
70
|
-
logger?: Logger;
|
|
71
|
-
/**
|
|
72
|
-
* whether to receive beta update
|
|
73
|
-
*/
|
|
74
|
-
receiveBeta?: boolean;
|
|
75
|
-
/**
|
|
76
|
-
* whether force update in DEV
|
|
77
|
-
*/
|
|
78
|
-
forceUpdate?: boolean;
|
|
79
|
-
/**
|
|
80
|
-
* initialize incremental updater
|
|
81
|
-
* @param provider update provider
|
|
82
|
-
* @param option UpdaterOption
|
|
83
|
-
*/
|
|
84
|
-
constructor(provider: IProvider, option?: UpdaterOption);
|
|
85
|
-
/**
|
|
86
|
-
* this function is used to parse download data.
|
|
87
|
-
* - if format is `'json'`
|
|
88
|
-
* - if data is `UpdateJSON`, return it
|
|
89
|
-
* - if data is string or absent, download URL data and return it
|
|
90
|
-
* - if format is `'buffer'`
|
|
91
|
-
* - if data is `Buffer`, return it
|
|
92
|
-
* - if data is string or absent, download URL data and return it
|
|
93
|
-
* @param format 'json' or 'buffer'
|
|
94
|
-
* @param data download URL or update json or buffer
|
|
95
|
-
*/
|
|
96
|
-
private fetch;
|
|
97
|
-
/**
|
|
98
|
-
* handle error message and emit error event
|
|
99
|
-
*/
|
|
100
|
-
private err;
|
|
101
|
-
/**
|
|
102
|
-
* check update info using default options
|
|
103
|
-
*/
|
|
104
|
-
checkUpdate(): Promise<boolean>;
|
|
105
|
-
/**
|
|
106
|
-
* check update info using existing update json
|
|
107
|
-
* @param data existing update json
|
|
108
|
-
*/
|
|
109
|
-
checkUpdate(data: UpdateJSON): Promise<boolean>;
|
|
110
|
-
/**
|
|
111
|
-
* download update using default options
|
|
112
|
-
*/
|
|
113
|
-
download(): Promise<boolean>;
|
|
114
|
-
/**
|
|
115
|
-
* download update using existing `asar.gz` buffer and signature
|
|
116
|
-
* @param data existing `asar.gz` buffer
|
|
117
|
-
* @param sig signature
|
|
118
|
-
*/
|
|
119
|
-
download(data: Uint8Array | Buffer, sig: string): Promise<boolean>;
|
|
120
|
-
/**
|
|
121
|
-
* quit App and install
|
|
122
|
-
*/
|
|
123
|
-
quitAndInstall(): void;
|
|
124
|
-
/**
|
|
125
|
-
* setup provider URL handler
|
|
126
|
-
*
|
|
127
|
-
* @example
|
|
128
|
-
* updater.setURLHandler((url, isDownloadingAsar) => {
|
|
129
|
-
* if (isDownloadingAsar) {
|
|
130
|
-
* return url.replace('https://raw.githubusercontent.com', 'https://cdn.jsdelivr.net/gh')
|
|
131
|
-
* }
|
|
132
|
-
* })
|
|
133
|
-
*/
|
|
134
|
-
setURLHandler(handler: URLHandler): void;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
7
|
type Promisable<T> = T | Promise<T>;
|
|
138
8
|
/**
|
|
139
9
|
* hooks on rename temp asar path to `${app.name}.asar`
|
|
@@ -205,4 +75,4 @@ declare function startupWithUpdater(fn: (updater: Updater) => Promisable<void>):
|
|
|
205
75
|
*/
|
|
206
76
|
declare function initApp(appOptions: AppOption): Promise<void>;
|
|
207
77
|
|
|
208
|
-
export { type AppOption,
|
|
78
|
+
export { type AppOption, Logger, Updater, UpdaterOption, initApp, startupWithUpdater };
|