electron-incremental-update 2.0.0-beta.8 → 2.0.0-beta.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/dist/index.cjs +29 -43
- package/dist/index.d.cts +130 -9
- package/dist/index.d.ts +130 -9
- package/dist/index.js +28 -43
- package/dist/provider.cjs +16 -5
- package/dist/provider.d.cts +17 -1
- package/dist/provider.d.ts +17 -1
- package/dist/provider.js +16 -5
- package/dist/{types-CItP6bL-.d.cts → types-D7OK98ln.d.ts} +3 -28
- package/dist/{types-CItP6bL-.d.ts → types-mEfMjnlV.d.cts} +3 -28
- package/dist/utils.cjs +0 -8
- package/dist/utils.d.cts +2 -10
- package/dist/utils.d.ts +2 -10
- package/dist/utils.js +0 -9
- package/dist/version-DgfjJQUx.d.cts +27 -0
- package/dist/version-DgfjJQUx.d.ts +27 -0
- package/dist/vite.js +10 -16
- package/package.json +1 -1
- package/dist/core-DJdvtwvU.d.ts +0 -134
- package/dist/core-ZUlLHadf.d.cts +0 -134
package/dist/index.cjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var path = require('path');
|
|
4
3
|
var fs3 = require('fs');
|
|
5
|
-
var electron = require('electron');
|
|
6
4
|
var events = require('events');
|
|
5
|
+
var electron = require('electron');
|
|
6
|
+
var path = require('path');
|
|
7
7
|
|
|
8
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
9
|
|
|
10
|
-
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
11
10
|
var fs3__default = /*#__PURE__*/_interopDefault(fs3);
|
|
11
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
12
12
|
|
|
13
13
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
14
14
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
@@ -40,7 +40,7 @@ function restartApp() {
|
|
|
40
40
|
electron.app.quit();
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
// src/
|
|
43
|
+
// src/entry/types.ts
|
|
44
44
|
var ErrorInfo = {
|
|
45
45
|
download: "Download failed",
|
|
46
46
|
validate: "Validate failed",
|
|
@@ -55,7 +55,7 @@ var UpdaterError = class extends Error {
|
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
-
// src/updater
|
|
58
|
+
// src/entry/updater.ts
|
|
59
59
|
var Updater = class extends events.EventEmitter {
|
|
60
60
|
CERT = __EIU_SIGNATURE_CERT__;
|
|
61
61
|
info;
|
|
@@ -74,19 +74,14 @@ var Updater = class extends events.EventEmitter {
|
|
|
74
74
|
forceUpdate;
|
|
75
75
|
/**
|
|
76
76
|
* initialize incremental updater
|
|
77
|
-
* @param
|
|
78
|
-
* @param option UpdaterOption
|
|
77
|
+
* @param options UpdaterOption
|
|
79
78
|
*/
|
|
80
|
-
constructor(
|
|
79
|
+
constructor(options = {}) {
|
|
81
80
|
super();
|
|
82
|
-
this.provider = provider;
|
|
83
|
-
this.receiveBeta =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
if (option.logger) {
|
|
88
|
-
this.logger = option.logger;
|
|
89
|
-
}
|
|
81
|
+
this.provider = options.provider;
|
|
82
|
+
this.receiveBeta = options.receiveBeta;
|
|
83
|
+
this.CERT = options.SIGNATURE_CERT || __EIU_SIGNATURE_CERT__;
|
|
84
|
+
this.logger = options.logger;
|
|
90
85
|
if (isDev && !this.logger) {
|
|
91
86
|
this.logger = {
|
|
92
87
|
info: (...args) => console.log("[EIU-INFO ]", ...args),
|
|
@@ -96,6 +91,14 @@ var Updater = class extends events.EventEmitter {
|
|
|
96
91
|
};
|
|
97
92
|
this.logger.info("no logger set, enable dev-only logger");
|
|
98
93
|
}
|
|
94
|
+
if (!this.provider) {
|
|
95
|
+
this.logger?.debug("No update provider, please setup provider before checking update");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
checkProvider() {
|
|
99
|
+
if (!this.provider) {
|
|
100
|
+
throw new UpdaterError("param", "missing update provider");
|
|
101
|
+
}
|
|
99
102
|
}
|
|
100
103
|
async fetch(format, data) {
|
|
101
104
|
if (typeof data === "object") {
|
|
@@ -124,6 +127,7 @@ var Updater = class extends events.EventEmitter {
|
|
|
124
127
|
this.emit("error", err);
|
|
125
128
|
}
|
|
126
129
|
async checkUpdate(data) {
|
|
130
|
+
this.checkProvider();
|
|
127
131
|
const emitUnavailable = (msg) => {
|
|
128
132
|
this.logger?.info(msg);
|
|
129
133
|
this.emit("update-unavailable", msg);
|
|
@@ -159,6 +163,7 @@ var Updater = class extends events.EventEmitter {
|
|
|
159
163
|
return true;
|
|
160
164
|
}
|
|
161
165
|
async downloadUpdate(data, info) {
|
|
166
|
+
this.checkProvider();
|
|
162
167
|
const _sig = info?.signature ?? this.info?.signature;
|
|
163
168
|
const _version = info?.version ?? this.info?.version;
|
|
164
169
|
if (!_sig || !_version) {
|
|
@@ -196,23 +201,12 @@ var Updater = class extends events.EventEmitter {
|
|
|
196
201
|
this.logger?.info("quit and install");
|
|
197
202
|
restartApp();
|
|
198
203
|
}
|
|
199
|
-
/**
|
|
200
|
-
* setup provider URL handler
|
|
201
|
-
*
|
|
202
|
-
* @example
|
|
203
|
-
* updater.setURLHandler((url, isDownloadingAsar) => {
|
|
204
|
-
* if (isDownloadingAsar) {
|
|
205
|
-
* url.hostname = 'https://cdn.jsdelivr.net/gh'
|
|
206
|
-
* return url
|
|
207
|
-
* }
|
|
208
|
-
* })
|
|
209
|
-
*/
|
|
210
|
-
setURLHandler(handler) {
|
|
211
|
-
this.provider.urlHandler = handler;
|
|
212
|
-
}
|
|
213
204
|
};
|
|
214
|
-
|
|
215
|
-
|
|
205
|
+
async function autoUpdate(updater) {
|
|
206
|
+
if (await updater.checkUpdate() && await updater.downloadUpdate()) {
|
|
207
|
+
updater.quitAndInstall();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
216
210
|
function startupWithUpdater(fn) {
|
|
217
211
|
return fn;
|
|
218
212
|
}
|
|
@@ -222,7 +216,6 @@ var defaultOnInstall = (install, _, __, logger) => {
|
|
|
222
216
|
};
|
|
223
217
|
async function initApp(appOptions) {
|
|
224
218
|
const {
|
|
225
|
-
provider,
|
|
226
219
|
updater,
|
|
227
220
|
onInstall = defaultOnInstall,
|
|
228
221
|
beforeStart,
|
|
@@ -230,19 +223,11 @@ async function initApp(appOptions) {
|
|
|
230
223
|
} = appOptions;
|
|
231
224
|
let updaterInstance;
|
|
232
225
|
if (typeof updater === "object" || !updater) {
|
|
233
|
-
updaterInstance = new Updater(
|
|
226
|
+
updaterInstance = new Updater(updater);
|
|
234
227
|
} else {
|
|
235
228
|
updaterInstance = await updater();
|
|
236
229
|
}
|
|
237
|
-
|
|
238
|
-
if (isDev && !logger) {
|
|
239
|
-
logger = {
|
|
240
|
-
info: (...args) => console.log("[EIU-INFO ]", ...args),
|
|
241
|
-
debug: (...args) => console.log("[EIU-DEBUG]", ...args),
|
|
242
|
-
warn: (...args) => console.log("[EIU-WARN ]", ...args),
|
|
243
|
-
error: (...args) => console.error("[EIU-ERROR]", ...args)
|
|
244
|
-
};
|
|
245
|
-
}
|
|
230
|
+
const logger = updaterInstance.logger;
|
|
246
231
|
try {
|
|
247
232
|
const appNameAsarPath = getPathFromAppNameAsar();
|
|
248
233
|
const tempAsarPath = `${appNameAsarPath}.tmp`;
|
|
@@ -267,5 +252,6 @@ async function initApp(appOptions) {
|
|
|
267
252
|
exports.ErrorInfo = ErrorInfo;
|
|
268
253
|
exports.Updater = Updater;
|
|
269
254
|
exports.UpdaterError = UpdaterError;
|
|
255
|
+
exports.autoUpdate = autoUpdate;
|
|
270
256
|
exports.initApp = initApp;
|
|
271
257
|
exports.startupWithUpdater = startupWithUpdater;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,134 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { I as IProvider } from './types-
|
|
4
|
-
import 'node:events';
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { U as UpdateJSON, a as UpdateInfo } from './version-DgfjJQUx.cjs';
|
|
3
|
+
import { I as IProvider, D as DownloadingInfo } from './types-mEfMjnlV.cjs';
|
|
5
4
|
import '@subframe7536/type-utils';
|
|
6
5
|
|
|
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
|
+
* update provider
|
|
44
|
+
*/
|
|
45
|
+
provider?: IProvider;
|
|
46
|
+
/**
|
|
47
|
+
* public key of signature, which will be auto generated by plugin,
|
|
48
|
+
* generate by `selfsigned` if not set
|
|
49
|
+
*/
|
|
50
|
+
SIGNATURE_CERT?: string;
|
|
51
|
+
/**
|
|
52
|
+
* whether to receive beta update
|
|
53
|
+
*/
|
|
54
|
+
receiveBeta?: boolean;
|
|
55
|
+
logger?: Logger;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
declare class Updater extends EventEmitter<{
|
|
59
|
+
'checking': any;
|
|
60
|
+
'update-available': [data: UpdateInfo];
|
|
61
|
+
'update-unavailable': [reason: string];
|
|
62
|
+
'error': [error: UpdaterError];
|
|
63
|
+
'download-progress': [info: DownloadingInfo];
|
|
64
|
+
'update-downloaded': any;
|
|
65
|
+
}> {
|
|
66
|
+
private CERT;
|
|
67
|
+
private info?;
|
|
68
|
+
provider?: IProvider;
|
|
69
|
+
/**
|
|
70
|
+
* updater logger
|
|
71
|
+
*/
|
|
72
|
+
logger?: Logger;
|
|
73
|
+
/**
|
|
74
|
+
* whether to receive beta update
|
|
75
|
+
*/
|
|
76
|
+
receiveBeta?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* whether force update in DEV
|
|
79
|
+
*/
|
|
80
|
+
forceUpdate?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* initialize incremental updater
|
|
83
|
+
* @param options UpdaterOption
|
|
84
|
+
*/
|
|
85
|
+
constructor(options?: UpdaterOption);
|
|
86
|
+
private checkProvider;
|
|
87
|
+
/**
|
|
88
|
+
* this function is used to parse download data.
|
|
89
|
+
* - if format is `'json'`
|
|
90
|
+
* - if data is `UpdateJSON`, return it
|
|
91
|
+
* - if data is string or absent, download URL data and return it
|
|
92
|
+
* - if format is `'buffer'`
|
|
93
|
+
* - if data is `Buffer`, return it
|
|
94
|
+
* - if data is string or absent, download URL data and return it
|
|
95
|
+
* @param format 'json' or 'buffer'
|
|
96
|
+
* @param data download URL or update json or buffer
|
|
97
|
+
*/
|
|
98
|
+
private fetch;
|
|
99
|
+
/**
|
|
100
|
+
* handle error message and emit error event
|
|
101
|
+
*/
|
|
102
|
+
private err;
|
|
103
|
+
/**
|
|
104
|
+
* check update info using default options
|
|
105
|
+
*/
|
|
106
|
+
checkUpdate(): Promise<boolean>;
|
|
107
|
+
/**
|
|
108
|
+
* check update info using existing update json
|
|
109
|
+
* @param data existing update json
|
|
110
|
+
*/
|
|
111
|
+
checkUpdate(data: UpdateJSON): Promise<boolean>;
|
|
112
|
+
/**
|
|
113
|
+
* download update using default options
|
|
114
|
+
*/
|
|
115
|
+
downloadUpdate(): Promise<boolean>;
|
|
116
|
+
/**
|
|
117
|
+
* download update using existing `asar.gz` buffer and signature
|
|
118
|
+
* @param data existing `asar.gz` buffer
|
|
119
|
+
* @param info update info
|
|
120
|
+
*/
|
|
121
|
+
downloadUpdate(data: Uint8Array, info: Omit<UpdateInfo, 'minimumVersion'>): Promise<boolean>;
|
|
122
|
+
/**
|
|
123
|
+
* quit App and install
|
|
124
|
+
*/
|
|
125
|
+
quitAndInstall(): void;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* auto check update, download and install
|
|
129
|
+
*/
|
|
130
|
+
declare function autoUpdate(updater: Updater): Promise<void>;
|
|
131
|
+
|
|
7
132
|
type Promisable<T> = T | Promise<T>;
|
|
8
133
|
/**
|
|
9
134
|
* hooks on rename temp asar path to `${app.name}.asar`
|
|
@@ -15,10 +140,6 @@ type Promisable<T> = T | Promise<T>;
|
|
|
15
140
|
*/
|
|
16
141
|
type OnInstallFunction = (install: VoidFunction, tempAsarPath: string, appNameAsarPath: string, logger?: Logger) => Promisable<void>;
|
|
17
142
|
interface AppOption {
|
|
18
|
-
/**
|
|
19
|
-
* update provider
|
|
20
|
-
*/
|
|
21
|
-
provider: IProvider;
|
|
22
143
|
/**
|
|
23
144
|
* updater options
|
|
24
145
|
*/
|
|
@@ -75,4 +196,4 @@ declare function startupWithUpdater(fn: (updater: Updater) => Promisable<void>):
|
|
|
75
196
|
*/
|
|
76
197
|
declare function initApp(appOptions: AppOption): Promise<void>;
|
|
77
198
|
|
|
78
|
-
export { type AppOption, Logger, Updater, UpdaterOption, initApp, startupWithUpdater };
|
|
199
|
+
export { type AppOption, type CheckResult, type DownloadResult, ErrorInfo, type Logger, Updater, UpdaterError, type UpdaterOption, autoUpdate, initApp, startupWithUpdater };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,134 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { I as IProvider } from './types-
|
|
4
|
-
import 'node:events';
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { U as UpdateJSON, a as UpdateInfo } from './version-DgfjJQUx.js';
|
|
3
|
+
import { I as IProvider, D as DownloadingInfo } from './types-D7OK98ln.js';
|
|
5
4
|
import '@subframe7536/type-utils';
|
|
6
5
|
|
|
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
|
+
* update provider
|
|
44
|
+
*/
|
|
45
|
+
provider?: IProvider;
|
|
46
|
+
/**
|
|
47
|
+
* public key of signature, which will be auto generated by plugin,
|
|
48
|
+
* generate by `selfsigned` if not set
|
|
49
|
+
*/
|
|
50
|
+
SIGNATURE_CERT?: string;
|
|
51
|
+
/**
|
|
52
|
+
* whether to receive beta update
|
|
53
|
+
*/
|
|
54
|
+
receiveBeta?: boolean;
|
|
55
|
+
logger?: Logger;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
declare class Updater extends EventEmitter<{
|
|
59
|
+
'checking': any;
|
|
60
|
+
'update-available': [data: UpdateInfo];
|
|
61
|
+
'update-unavailable': [reason: string];
|
|
62
|
+
'error': [error: UpdaterError];
|
|
63
|
+
'download-progress': [info: DownloadingInfo];
|
|
64
|
+
'update-downloaded': any;
|
|
65
|
+
}> {
|
|
66
|
+
private CERT;
|
|
67
|
+
private info?;
|
|
68
|
+
provider?: IProvider;
|
|
69
|
+
/**
|
|
70
|
+
* updater logger
|
|
71
|
+
*/
|
|
72
|
+
logger?: Logger;
|
|
73
|
+
/**
|
|
74
|
+
* whether to receive beta update
|
|
75
|
+
*/
|
|
76
|
+
receiveBeta?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* whether force update in DEV
|
|
79
|
+
*/
|
|
80
|
+
forceUpdate?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* initialize incremental updater
|
|
83
|
+
* @param options UpdaterOption
|
|
84
|
+
*/
|
|
85
|
+
constructor(options?: UpdaterOption);
|
|
86
|
+
private checkProvider;
|
|
87
|
+
/**
|
|
88
|
+
* this function is used to parse download data.
|
|
89
|
+
* - if format is `'json'`
|
|
90
|
+
* - if data is `UpdateJSON`, return it
|
|
91
|
+
* - if data is string or absent, download URL data and return it
|
|
92
|
+
* - if format is `'buffer'`
|
|
93
|
+
* - if data is `Buffer`, return it
|
|
94
|
+
* - if data is string or absent, download URL data and return it
|
|
95
|
+
* @param format 'json' or 'buffer'
|
|
96
|
+
* @param data download URL or update json or buffer
|
|
97
|
+
*/
|
|
98
|
+
private fetch;
|
|
99
|
+
/**
|
|
100
|
+
* handle error message and emit error event
|
|
101
|
+
*/
|
|
102
|
+
private err;
|
|
103
|
+
/**
|
|
104
|
+
* check update info using default options
|
|
105
|
+
*/
|
|
106
|
+
checkUpdate(): Promise<boolean>;
|
|
107
|
+
/**
|
|
108
|
+
* check update info using existing update json
|
|
109
|
+
* @param data existing update json
|
|
110
|
+
*/
|
|
111
|
+
checkUpdate(data: UpdateJSON): Promise<boolean>;
|
|
112
|
+
/**
|
|
113
|
+
* download update using default options
|
|
114
|
+
*/
|
|
115
|
+
downloadUpdate(): Promise<boolean>;
|
|
116
|
+
/**
|
|
117
|
+
* download update using existing `asar.gz` buffer and signature
|
|
118
|
+
* @param data existing `asar.gz` buffer
|
|
119
|
+
* @param info update info
|
|
120
|
+
*/
|
|
121
|
+
downloadUpdate(data: Uint8Array, info: Omit<UpdateInfo, 'minimumVersion'>): Promise<boolean>;
|
|
122
|
+
/**
|
|
123
|
+
* quit App and install
|
|
124
|
+
*/
|
|
125
|
+
quitAndInstall(): void;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* auto check update, download and install
|
|
129
|
+
*/
|
|
130
|
+
declare function autoUpdate(updater: Updater): Promise<void>;
|
|
131
|
+
|
|
7
132
|
type Promisable<T> = T | Promise<T>;
|
|
8
133
|
/**
|
|
9
134
|
* hooks on rename temp asar path to `${app.name}.asar`
|
|
@@ -15,10 +140,6 @@ type Promisable<T> = T | Promise<T>;
|
|
|
15
140
|
*/
|
|
16
141
|
type OnInstallFunction = (install: VoidFunction, tempAsarPath: string, appNameAsarPath: string, logger?: Logger) => Promisable<void>;
|
|
17
142
|
interface AppOption {
|
|
18
|
-
/**
|
|
19
|
-
* update provider
|
|
20
|
-
*/
|
|
21
|
-
provider: IProvider;
|
|
22
143
|
/**
|
|
23
144
|
* updater options
|
|
24
145
|
*/
|
|
@@ -75,4 +196,4 @@ declare function startupWithUpdater(fn: (updater: Updater) => Promisable<void>):
|
|
|
75
196
|
*/
|
|
76
197
|
declare function initApp(appOptions: AppOption): Promise<void>;
|
|
77
198
|
|
|
78
|
-
export { type AppOption, Logger, Updater, UpdaterOption, initApp, startupWithUpdater };
|
|
199
|
+
export { type AppOption, type CheckResult, type DownloadResult, ErrorInfo, type Logger, Updater, UpdaterError, type UpdaterOption, autoUpdate, initApp, startupWithUpdater };
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { isDev, getEntryVersion, getAppVersion, getPathFromAppNameAsar, restartApp } from './chunk-4MH6ZXCY.js';
|
|
2
2
|
import { isUpdateJSON, __require } from './chunk-72ZAJ7AF.js';
|
|
3
|
-
import path from 'node:path';
|
|
4
3
|
import fs2 from 'node:fs';
|
|
5
|
-
import { app } from 'electron';
|
|
6
4
|
import { EventEmitter } from 'node:events';
|
|
5
|
+
import { app } from 'electron';
|
|
6
|
+
import path from 'node:path';
|
|
7
7
|
|
|
8
|
-
// src/
|
|
8
|
+
// src/entry/types.ts
|
|
9
9
|
var ErrorInfo = {
|
|
10
10
|
download: "Download failed",
|
|
11
11
|
validate: "Validate failed",
|
|
@@ -20,7 +20,7 @@ var UpdaterError = class extends Error {
|
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
// src/updater
|
|
23
|
+
// src/entry/updater.ts
|
|
24
24
|
var Updater = class extends EventEmitter {
|
|
25
25
|
CERT = __EIU_SIGNATURE_CERT__;
|
|
26
26
|
info;
|
|
@@ -39,19 +39,14 @@ var Updater = class extends EventEmitter {
|
|
|
39
39
|
forceUpdate;
|
|
40
40
|
/**
|
|
41
41
|
* initialize incremental updater
|
|
42
|
-
* @param
|
|
43
|
-
* @param option UpdaterOption
|
|
42
|
+
* @param options UpdaterOption
|
|
44
43
|
*/
|
|
45
|
-
constructor(
|
|
44
|
+
constructor(options = {}) {
|
|
46
45
|
super();
|
|
47
|
-
this.provider = provider;
|
|
48
|
-
this.receiveBeta =
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
if (option.logger) {
|
|
53
|
-
this.logger = option.logger;
|
|
54
|
-
}
|
|
46
|
+
this.provider = options.provider;
|
|
47
|
+
this.receiveBeta = options.receiveBeta;
|
|
48
|
+
this.CERT = options.SIGNATURE_CERT || __EIU_SIGNATURE_CERT__;
|
|
49
|
+
this.logger = options.logger;
|
|
55
50
|
if (isDev && !this.logger) {
|
|
56
51
|
this.logger = {
|
|
57
52
|
info: (...args) => console.log("[EIU-INFO ]", ...args),
|
|
@@ -61,6 +56,14 @@ var Updater = class extends EventEmitter {
|
|
|
61
56
|
};
|
|
62
57
|
this.logger.info("no logger set, enable dev-only logger");
|
|
63
58
|
}
|
|
59
|
+
if (!this.provider) {
|
|
60
|
+
this.logger?.debug("No update provider, please setup provider before checking update");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
checkProvider() {
|
|
64
|
+
if (!this.provider) {
|
|
65
|
+
throw new UpdaterError("param", "missing update provider");
|
|
66
|
+
}
|
|
64
67
|
}
|
|
65
68
|
async fetch(format, data) {
|
|
66
69
|
if (typeof data === "object") {
|
|
@@ -89,6 +92,7 @@ var Updater = class extends EventEmitter {
|
|
|
89
92
|
this.emit("error", err);
|
|
90
93
|
}
|
|
91
94
|
async checkUpdate(data) {
|
|
95
|
+
this.checkProvider();
|
|
92
96
|
const emitUnavailable = (msg) => {
|
|
93
97
|
this.logger?.info(msg);
|
|
94
98
|
this.emit("update-unavailable", msg);
|
|
@@ -124,6 +128,7 @@ var Updater = class extends EventEmitter {
|
|
|
124
128
|
return true;
|
|
125
129
|
}
|
|
126
130
|
async downloadUpdate(data, info) {
|
|
131
|
+
this.checkProvider();
|
|
127
132
|
const _sig = info?.signature ?? this.info?.signature;
|
|
128
133
|
const _version = info?.version ?? this.info?.version;
|
|
129
134
|
if (!_sig || !_version) {
|
|
@@ -161,23 +166,12 @@ var Updater = class extends EventEmitter {
|
|
|
161
166
|
this.logger?.info("quit and install");
|
|
162
167
|
restartApp();
|
|
163
168
|
}
|
|
164
|
-
/**
|
|
165
|
-
* setup provider URL handler
|
|
166
|
-
*
|
|
167
|
-
* @example
|
|
168
|
-
* updater.setURLHandler((url, isDownloadingAsar) => {
|
|
169
|
-
* if (isDownloadingAsar) {
|
|
170
|
-
* url.hostname = 'https://cdn.jsdelivr.net/gh'
|
|
171
|
-
* return url
|
|
172
|
-
* }
|
|
173
|
-
* })
|
|
174
|
-
*/
|
|
175
|
-
setURLHandler(handler) {
|
|
176
|
-
this.provider.urlHandler = handler;
|
|
177
|
-
}
|
|
178
169
|
};
|
|
179
|
-
|
|
180
|
-
|
|
170
|
+
async function autoUpdate(updater) {
|
|
171
|
+
if (await updater.checkUpdate() && await updater.downloadUpdate()) {
|
|
172
|
+
updater.quitAndInstall();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
181
175
|
function startupWithUpdater(fn) {
|
|
182
176
|
return fn;
|
|
183
177
|
}
|
|
@@ -187,7 +181,6 @@ var defaultOnInstall = (install, _, __, logger) => {
|
|
|
187
181
|
};
|
|
188
182
|
async function initApp(appOptions) {
|
|
189
183
|
const {
|
|
190
|
-
provider,
|
|
191
184
|
updater,
|
|
192
185
|
onInstall = defaultOnInstall,
|
|
193
186
|
beforeStart,
|
|
@@ -195,19 +188,11 @@ async function initApp(appOptions) {
|
|
|
195
188
|
} = appOptions;
|
|
196
189
|
let updaterInstance;
|
|
197
190
|
if (typeof updater === "object" || !updater) {
|
|
198
|
-
updaterInstance = new Updater(
|
|
191
|
+
updaterInstance = new Updater(updater);
|
|
199
192
|
} else {
|
|
200
193
|
updaterInstance = await updater();
|
|
201
194
|
}
|
|
202
|
-
|
|
203
|
-
if (isDev && !logger) {
|
|
204
|
-
logger = {
|
|
205
|
-
info: (...args) => console.log("[EIU-INFO ]", ...args),
|
|
206
|
-
debug: (...args) => console.log("[EIU-DEBUG]", ...args),
|
|
207
|
-
warn: (...args) => console.log("[EIU-WARN ]", ...args),
|
|
208
|
-
error: (...args) => console.error("[EIU-ERROR]", ...args)
|
|
209
|
-
};
|
|
210
|
-
}
|
|
195
|
+
const logger = updaterInstance.logger;
|
|
211
196
|
try {
|
|
212
197
|
const appNameAsarPath = getPathFromAppNameAsar();
|
|
213
198
|
const tempAsarPath = `${appNameAsarPath}.tmp`;
|
|
@@ -229,4 +214,4 @@ async function initApp(appOptions) {
|
|
|
229
214
|
}
|
|
230
215
|
}
|
|
231
216
|
|
|
232
|
-
export { ErrorInfo, Updater, UpdaterError, initApp, startupWithUpdater };
|
|
217
|
+
export { ErrorInfo, Updater, UpdaterError, autoUpdate, initApp, startupWithUpdater };
|
package/dist/provider.cjs
CHANGED
|
@@ -73,8 +73,7 @@ function getHeader(response, headerKey) {
|
|
|
73
73
|
async function downloadFn(url, headers, onResponse) {
|
|
74
74
|
await electron.app.whenReady();
|
|
75
75
|
return new Promise((resolve, reject) => {
|
|
76
|
-
const request = electron.net.request({ url, method: "GET", redirect: "follow" });
|
|
77
|
-
Object.keys(headers).forEach((key) => request.setHeader(key, headers[key]));
|
|
76
|
+
const request = electron.net.request({ url, method: "GET", redirect: "follow", headers });
|
|
78
77
|
request.on("response", (resp) => {
|
|
79
78
|
resp.on("aborted", () => reject(new Error("aborted")));
|
|
80
79
|
resp.on("error", () => reject(new Error("download error")));
|
|
@@ -159,8 +158,17 @@ async function defaultUnzipFile(buffer) {
|
|
|
159
158
|
// src/provider/base.ts
|
|
160
159
|
var BaseProvider = class {
|
|
161
160
|
name = "BaseProvider";
|
|
161
|
+
/**
|
|
162
|
+
* @inheritdoc
|
|
163
|
+
*/
|
|
162
164
|
isLowerVersion = defaultIsLowerVersion;
|
|
165
|
+
/**
|
|
166
|
+
* @inheritdoc
|
|
167
|
+
*/
|
|
163
168
|
verifySignaure = defaultVerifySignature;
|
|
169
|
+
/**
|
|
170
|
+
* @inheritdoc
|
|
171
|
+
*/
|
|
164
172
|
unzipFile = defaultUnzipFile;
|
|
165
173
|
};
|
|
166
174
|
|
|
@@ -179,6 +187,9 @@ var GitHubProvider = class extends BaseProvider {
|
|
|
179
187
|
constructor(options) {
|
|
180
188
|
super();
|
|
181
189
|
this.options = options;
|
|
190
|
+
if (!options.branch) {
|
|
191
|
+
this.options.branch = "HEAD";
|
|
192
|
+
}
|
|
182
193
|
}
|
|
183
194
|
get urlHandler() {
|
|
184
195
|
return this.options.urlHandler;
|
|
@@ -195,14 +206,14 @@ var GitHubProvider = class extends BaseProvider {
|
|
|
195
206
|
}
|
|
196
207
|
async downloadJSON(versionPath) {
|
|
197
208
|
return await defaultDownloadUpdateJSON(
|
|
198
|
-
await this.parseURL(false, `${this.options.branch
|
|
199
|
-
{
|
|
209
|
+
await this.parseURL(false, `${this.options.branch}/${versionPath}`),
|
|
210
|
+
{ Accept: "application/json", ...this.options.extraHeaders }
|
|
200
211
|
);
|
|
201
212
|
}
|
|
202
213
|
async downloadAsar(name, info, onDownloading) {
|
|
203
214
|
return await defaultDownloadAsar(
|
|
204
215
|
await this.parseURL(true, `releases/download/v${info.version}/${name}-${info.version}.asar.gz`),
|
|
205
|
-
{
|
|
216
|
+
{ Accept: "application/octet-stream", ...this.options.extraHeaders },
|
|
206
217
|
onDownloading
|
|
207
218
|
);
|
|
208
219
|
}
|
package/dist/provider.d.cts
CHANGED
|
@@ -1,13 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as defaultIsLowerVersion, U as UpdateJSON, a as UpdateInfo } from './version-DgfjJQUx.cjs';
|
|
2
|
+
import { I as IProvider, D as DownloadingInfo, U as URLHandler, O as OnDownloading } from './types-mEfMjnlV.cjs';
|
|
2
3
|
import { f as defaultVerifySignature, a as defaultUnzipFile } from './zip-DPF5IFkK.cjs';
|
|
3
4
|
import { Arrayable } from '@subframe7536/type-utils';
|
|
4
5
|
|
|
5
6
|
declare abstract class BaseProvider implements IProvider {
|
|
6
7
|
name: string;
|
|
8
|
+
/**
|
|
9
|
+
* @inheritdoc
|
|
10
|
+
*/
|
|
7
11
|
isLowerVersion: typeof defaultIsLowerVersion;
|
|
12
|
+
/**
|
|
13
|
+
* @inheritdoc
|
|
14
|
+
*/
|
|
8
15
|
verifySignaure: typeof defaultVerifySignature;
|
|
16
|
+
/**
|
|
17
|
+
* @inheritdoc
|
|
18
|
+
*/
|
|
9
19
|
unzipFile: typeof defaultUnzipFile;
|
|
20
|
+
/**
|
|
21
|
+
* @inheritdoc
|
|
22
|
+
*/
|
|
10
23
|
abstract downloadJSON(versionPath: string): Promise<UpdateJSON>;
|
|
24
|
+
/**
|
|
25
|
+
* @inheritdoc
|
|
26
|
+
*/
|
|
11
27
|
abstract downloadAsar(name: string, info: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
|
|
12
28
|
}
|
|
13
29
|
|