electron-incremental-update 2.0.0-beta.10 → 2.0.0-beta.11
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-IABBXJFB.js +87 -0
- package/dist/{chunk-72ZAJ7AF.js → chunk-RCRKUKFX.js} +1 -1
- package/dist/index.cjs +68 -48
- package/dist/index.d.cts +33 -25
- package/dist/index.d.ts +33 -25
- package/dist/index.js +65 -47
- package/dist/provider.cjs +58 -44
- package/dist/provider.d.cts +13 -13
- package/dist/provider.d.ts +13 -13
- package/dist/provider.js +58 -45
- package/dist/{types-Bnc4jz6R.d.ts → types-C8JhnJjU.d.ts} +6 -4
- package/dist/{types-DEYw5VrL.d.cts → types-CGSkHX4Y.d.cts} +6 -4
- package/dist/utils.cjs +25 -17
- package/dist/utils.d.cts +10 -3
- package/dist/utils.d.ts +10 -3
- package/dist/utils.js +2 -2
- package/dist/{version-C4tF_trh.d.cts → version-BYVQ367i.d.cts} +5 -5
- package/dist/{version-C4tF_trh.d.ts → version-BYVQ367i.d.ts} +5 -5
- package/dist/vite.d.ts +3 -1
- package/dist/vite.js +31 -18
- package/package.json +5 -5
- package/dist/chunk-4MH6ZXCY.js +0 -81
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { __require } from './chunk-RCRKUKFX.js';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import electron from 'electron';
|
|
5
|
+
|
|
6
|
+
var isDev = __EIU_IS_DEV__;
|
|
7
|
+
var isWin = process.platform === "win32";
|
|
8
|
+
var isMac = process.platform === "darwin";
|
|
9
|
+
var isLinux = process.platform === "linux";
|
|
10
|
+
function getPathFromAppNameAsar(...paths) {
|
|
11
|
+
return isDev ? "DEV.asar" : path.join(path.dirname(electron.app.getAppPath()), `${electron.app.name}.asar`, ...paths);
|
|
12
|
+
}
|
|
13
|
+
function getAppVersion() {
|
|
14
|
+
return isDev ? getEntryVersion() : fs.readFileSync(getPathFromAppNameAsar("version"), "utf-8");
|
|
15
|
+
}
|
|
16
|
+
function getEntryVersion() {
|
|
17
|
+
return electron.app.getVersion();
|
|
18
|
+
}
|
|
19
|
+
function requireNative(moduleName) {
|
|
20
|
+
if (__EIU_IS_ESM__) {
|
|
21
|
+
throw new Error(`Cannot require "${path.join(__EIU_ENTRY_DIST_PATH__, moduleName)}", \`requireNative\` only support CommonJS`);
|
|
22
|
+
}
|
|
23
|
+
return __require(path.join(electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, moduleName));
|
|
24
|
+
}
|
|
25
|
+
function restartApp() {
|
|
26
|
+
electron.app.relaunch();
|
|
27
|
+
electron.app.quit();
|
|
28
|
+
}
|
|
29
|
+
function setAppUserModelId(id) {
|
|
30
|
+
if (isWin) {
|
|
31
|
+
electron.app.setAppUserModelId(id ?? `org.${electron.app.name}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function disableHWAccForWin7() {
|
|
35
|
+
if (!__EIU_IS_ESM__ && __require("node:os").release().startsWith("6.1")) {
|
|
36
|
+
electron.app.disableHardwareAcceleration();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function singleInstance(window) {
|
|
40
|
+
const result = electron.app.requestSingleInstanceLock();
|
|
41
|
+
if (result) {
|
|
42
|
+
electron.app.on("second-instance", () => {
|
|
43
|
+
if (window) {
|
|
44
|
+
window.show();
|
|
45
|
+
if (window.isMinimized()) {
|
|
46
|
+
window.restore();
|
|
47
|
+
}
|
|
48
|
+
window.focus();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
} else {
|
|
52
|
+
electron.app.quit();
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
function setPortableAppDataPath(dirName = "data") {
|
|
57
|
+
const portablePath = path.join(path.dirname(electron.app.getPath("exe")), dirName);
|
|
58
|
+
if (!fs.existsSync(portablePath)) {
|
|
59
|
+
fs.mkdirSync(portablePath);
|
|
60
|
+
}
|
|
61
|
+
electron.app.setPath("appData", portablePath);
|
|
62
|
+
}
|
|
63
|
+
function loadPage(win, htmlFilePath = "index.html") {
|
|
64
|
+
if (isDev) {
|
|
65
|
+
win.loadURL(process.env.VITE_DEV_SERVER_URL + htmlFilePath);
|
|
66
|
+
} else {
|
|
67
|
+
win.loadFile(getPathFromAppNameAsar("renderer", htmlFilePath));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function getPathFromMain(...paths) {
|
|
71
|
+
return isDev ? path.join(electron.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "main", ...paths) : getPathFromAppNameAsar("main", ...paths);
|
|
72
|
+
}
|
|
73
|
+
function getPathFromPreload(...paths) {
|
|
74
|
+
return isDev ? path.join(electron.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
|
|
75
|
+
}
|
|
76
|
+
function getPathFromPublic(...paths) {
|
|
77
|
+
return isDev ? path.join(electron.app.getAppPath(), "public", ...paths) : getPathFromAppNameAsar("renderer", ...paths);
|
|
78
|
+
}
|
|
79
|
+
function getPathFromEntryAsar(...paths) {
|
|
80
|
+
return path.join(electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
|
|
81
|
+
}
|
|
82
|
+
function handleUnexpectedErrors(callback) {
|
|
83
|
+
process.on("uncaughtException", callback);
|
|
84
|
+
process.on("unhandledRejection", callback);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
|
|
@@ -25,7 +25,7 @@ function parseVersion(version) {
|
|
|
25
25
|
ret.stageVersion = Number(_v) || -1;
|
|
26
26
|
}
|
|
27
27
|
if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
|
|
28
|
-
throw new TypeError(`
|
|
28
|
+
throw new TypeError(`Invalid version: ${version}`);
|
|
29
29
|
}
|
|
30
30
|
return ret;
|
|
31
31
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -8,6 +8,7 @@ var path = require('path');
|
|
|
8
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
9
|
|
|
10
10
|
var fs3__default = /*#__PURE__*/_interopDefault(fs3);
|
|
11
|
+
var electron__default = /*#__PURE__*/_interopDefault(electron);
|
|
11
12
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
12
13
|
|
|
13
14
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
@@ -27,17 +28,17 @@ process.platform === "win32";
|
|
|
27
28
|
process.platform === "darwin";
|
|
28
29
|
process.platform === "linux";
|
|
29
30
|
function getPathFromAppNameAsar(...paths) {
|
|
30
|
-
return isDev ? "DEV.asar" : path__default.default.join(path__default.default.dirname(
|
|
31
|
+
return isDev ? "DEV.asar" : path__default.default.join(path__default.default.dirname(electron__default.default.app.getAppPath()), `${electron__default.default.app.name}.asar`, ...paths);
|
|
31
32
|
}
|
|
32
33
|
function getAppVersion() {
|
|
33
34
|
return isDev ? getEntryVersion() : fs3__default.default.readFileSync(getPathFromAppNameAsar("version"), "utf-8");
|
|
34
35
|
}
|
|
35
36
|
function getEntryVersion() {
|
|
36
|
-
return
|
|
37
|
+
return electron__default.default.app.getVersion();
|
|
37
38
|
}
|
|
38
39
|
function restartApp() {
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
electron__default.default.app.relaunch();
|
|
41
|
+
electron__default.default.app.quit();
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
// src/entry/types.ts
|
|
@@ -57,7 +58,8 @@ var UpdaterError = class extends Error {
|
|
|
57
58
|
|
|
58
59
|
// src/entry/updater.ts
|
|
59
60
|
var Updater = class extends events.EventEmitter {
|
|
60
|
-
CERT
|
|
61
|
+
CERT;
|
|
62
|
+
controller;
|
|
61
63
|
info;
|
|
62
64
|
provider;
|
|
63
65
|
/**
|
|
@@ -82,6 +84,7 @@ var Updater = class extends events.EventEmitter {
|
|
|
82
84
|
this.receiveBeta = options.receiveBeta;
|
|
83
85
|
this.CERT = options.SIGNATURE_CERT || __EIU_SIGNATURE_CERT__;
|
|
84
86
|
this.logger = options.logger;
|
|
87
|
+
this.controller = new AbortController();
|
|
85
88
|
if (isDev && !this.logger) {
|
|
86
89
|
this.logger = {
|
|
87
90
|
info: (...args) => console.log("[EIU-INFO ]", ...args),
|
|
@@ -89,15 +92,10 @@ var Updater = class extends events.EventEmitter {
|
|
|
89
92
|
warn: (...args) => console.log("[EIU-WARN ]", ...args),
|
|
90
93
|
error: (...args) => console.error("[EIU-ERROR]", ...args)
|
|
91
94
|
};
|
|
92
|
-
this.logger.info("
|
|
95
|
+
this.logger.info("No logger set, enable dev-only logger");
|
|
93
96
|
}
|
|
94
97
|
if (!this.provider) {
|
|
95
|
-
this.logger?.debug("No update provider
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
checkProvider() {
|
|
99
|
-
if (!this.provider) {
|
|
100
|
-
throw new UpdaterError("param", "missing update provider");
|
|
98
|
+
this.logger?.debug("WARN: No update provider");
|
|
101
99
|
}
|
|
102
100
|
}
|
|
103
101
|
async fetch(format, data) {
|
|
@@ -105,17 +103,17 @@ var Updater = class extends events.EventEmitter {
|
|
|
105
103
|
if (format === "json" && isUpdateJSON(data) || format === "buffer" && Buffer.isBuffer(data)) {
|
|
106
104
|
return data;
|
|
107
105
|
} else {
|
|
108
|
-
this.err("
|
|
106
|
+
this.err("Invalid type", "param", `Invalid type at format '${format}': ${JSON.stringify(data)}`);
|
|
109
107
|
return;
|
|
110
108
|
}
|
|
111
109
|
}
|
|
112
|
-
this.logger?.debug(`
|
|
110
|
+
this.logger?.debug(`Download from \`${this.provider.name}\``);
|
|
113
111
|
try {
|
|
114
|
-
const result = format === "json" ? await this.provider.downloadJSON(
|
|
115
|
-
this.logger?.debug(`
|
|
112
|
+
const result = format === "json" ? await this.provider.downloadJSON(__EIU_VERSION_PATH__, this.controller.signal) : await this.provider.downloadAsar(electron.app.name, this.info, this.controller.signal, (info) => this.emit("download-progress", info));
|
|
113
|
+
this.logger?.debug(`Download ${format} success${format === "buffer" ? `, file size: ${result.length}` : ""}`);
|
|
116
114
|
return result;
|
|
117
115
|
} catch (e) {
|
|
118
|
-
this.err(`
|
|
116
|
+
this.err(`Fetch ${format} failed`, "network", `Download ${format} failed: ${e}`);
|
|
119
117
|
}
|
|
120
118
|
}
|
|
121
119
|
/**
|
|
@@ -126,16 +124,20 @@ var Updater = class extends events.EventEmitter {
|
|
|
126
124
|
this.logger?.error(msg, err);
|
|
127
125
|
this.emit("error", err);
|
|
128
126
|
}
|
|
129
|
-
async
|
|
130
|
-
this.checkProvider();
|
|
127
|
+
async checkForUpdates(data) {
|
|
131
128
|
const emitUnavailable = (msg) => {
|
|
132
129
|
this.logger?.info(msg);
|
|
133
|
-
this.emit("update-
|
|
130
|
+
this.emit("update-not-available", msg);
|
|
134
131
|
return false;
|
|
135
132
|
};
|
|
133
|
+
if (!data && !this.provider) {
|
|
134
|
+
const errorInfo = "No update json or provider";
|
|
135
|
+
this.err("Check update failed", "param", errorInfo);
|
|
136
|
+
return emitUnavailable(errorInfo);
|
|
137
|
+
}
|
|
136
138
|
const _data = await this.fetch("json", data);
|
|
137
139
|
if (!_data) {
|
|
138
|
-
return emitUnavailable("
|
|
140
|
+
return emitUnavailable("Failed to get update info");
|
|
139
141
|
}
|
|
140
142
|
let { signature, version, minimumVersion, beta } = _data;
|
|
141
143
|
if (this.receiveBeta) {
|
|
@@ -143,59 +145,62 @@ var Updater = class extends events.EventEmitter {
|
|
|
143
145
|
signature = beta.signature;
|
|
144
146
|
minimumVersion = beta.minimumVersion;
|
|
145
147
|
}
|
|
146
|
-
this.logger?.debug(`
|
|
148
|
+
this.logger?.debug(`Checked update, version: ${version}, signature: ${signature}`);
|
|
147
149
|
if (isDev && !this.forceUpdate && !data) {
|
|
148
|
-
return emitUnavailable("
|
|
150
|
+
return emitUnavailable("Skip check update in dev mode. To force update, set `updater.forceUpdate` to true or call checkUpdate with UpdateJSON");
|
|
149
151
|
}
|
|
150
152
|
const isLowerVersion = this.provider.isLowerVersion;
|
|
151
153
|
const entryVersion = getEntryVersion();
|
|
152
154
|
const appVersion = getAppVersion();
|
|
153
155
|
try {
|
|
154
156
|
if (isLowerVersion(entryVersion, minimumVersion)) {
|
|
155
|
-
return emitUnavailable(`
|
|
157
|
+
return emitUnavailable(`Entry Version (${entryVersion}) < MinimumVersion (${minimumVersion})`);
|
|
156
158
|
}
|
|
157
|
-
this.logger?.info(`
|
|
159
|
+
this.logger?.info(`Check update: current version is ${appVersion}, new version is ${version}`);
|
|
158
160
|
if (!isLowerVersion(appVersion, version)) {
|
|
159
|
-
return emitUnavailable(`
|
|
161
|
+
return emitUnavailable(`Current version (${appVersion}) < New version (${version})`);
|
|
160
162
|
}
|
|
161
|
-
this.logger?.info(`
|
|
163
|
+
this.logger?.info(`Update available: ${version}`);
|
|
162
164
|
this.info = { signature, minimumVersion, version };
|
|
163
165
|
this.emit("update-available", this.info);
|
|
164
166
|
return true;
|
|
165
167
|
} catch {
|
|
166
|
-
this.err("Fail to parse version", "validate", "
|
|
168
|
+
this.err("Fail to parse version", "validate", "Fail to parse version string");
|
|
167
169
|
return false;
|
|
168
170
|
}
|
|
169
171
|
}
|
|
170
172
|
async downloadUpdate(data, info) {
|
|
171
|
-
this.checkProvider();
|
|
172
173
|
const _sig = info?.signature ?? this.info?.signature;
|
|
173
174
|
const _version = info?.version ?? this.info?.version;
|
|
174
175
|
if (!_sig || !_version) {
|
|
175
|
-
this.err("
|
|
176
|
+
this.err("Download failed", "param", "No update signature, please call `checkUpdate` first or manually setup params");
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
if (!data && !this.provider) {
|
|
180
|
+
this.err("Download failed", "param", "No update asar buffer and provider");
|
|
176
181
|
return false;
|
|
177
182
|
}
|
|
178
183
|
const buffer = await this.fetch("buffer", data ? Buffer.from(data) : void 0);
|
|
179
184
|
if (!buffer) {
|
|
180
|
-
this.err("
|
|
185
|
+
this.err("Download failed", "param", "No update asar file buffer");
|
|
181
186
|
return false;
|
|
182
187
|
}
|
|
183
188
|
this.logger?.debug("verify start");
|
|
184
189
|
if (!await this.provider.verifySignaure(buffer, _version, _sig, this.CERT)) {
|
|
185
|
-
this.err("
|
|
190
|
+
this.err("Download failed", "validate", "Invalid update asar file");
|
|
186
191
|
return false;
|
|
187
192
|
}
|
|
188
|
-
this.logger?.debug("
|
|
193
|
+
this.logger?.debug("Verify success");
|
|
189
194
|
try {
|
|
190
195
|
const tmpFilePath = getPathFromAppNameAsar() + ".tmp";
|
|
191
|
-
this.logger?.debug(`
|
|
196
|
+
this.logger?.debug(`Install to ${tmpFilePath}`);
|
|
192
197
|
fs3__default.default.writeFileSync(tmpFilePath, await this.provider.unzipFile(buffer));
|
|
193
|
-
this.logger?.info(`
|
|
198
|
+
this.logger?.info(`Download success, version: ${_version}`);
|
|
194
199
|
this.info = void 0;
|
|
195
200
|
this.emit("update-downloaded");
|
|
196
201
|
return true;
|
|
197
202
|
} catch (error) {
|
|
198
|
-
this.err("
|
|
203
|
+
this.err("Download failed", "download", `Fail to unwrap asar file, ${error}`);
|
|
199
204
|
return false;
|
|
200
205
|
}
|
|
201
206
|
}
|
|
@@ -203,12 +208,21 @@ var Updater = class extends events.EventEmitter {
|
|
|
203
208
|
* quit App and install
|
|
204
209
|
*/
|
|
205
210
|
quitAndInstall() {
|
|
206
|
-
this.logger?.info("
|
|
211
|
+
this.logger?.info("Quit and install");
|
|
207
212
|
restartApp();
|
|
208
213
|
}
|
|
214
|
+
cancel() {
|
|
215
|
+
if (this.controller.signal.aborted) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
this.controller.abort();
|
|
219
|
+
this.logger?.info("Cancel update");
|
|
220
|
+
this.emit("update-cancelled");
|
|
221
|
+
this.controller = new AbortController();
|
|
222
|
+
}
|
|
209
223
|
};
|
|
210
224
|
async function autoUpdate(updater) {
|
|
211
|
-
if (await updater.
|
|
225
|
+
if (await updater.checkForUpdates() && await updater.downloadUpdate()) {
|
|
212
226
|
updater.quitAndInstall();
|
|
213
227
|
}
|
|
214
228
|
}
|
|
@@ -219,8 +233,14 @@ var defaultOnInstall = (install, _, __, logger) => {
|
|
|
219
233
|
install();
|
|
220
234
|
logger?.info(`update success!`);
|
|
221
235
|
};
|
|
222
|
-
async function
|
|
236
|
+
async function createElectronApp(appOptions = {}) {
|
|
237
|
+
const appNameAsarPath = getPathFromAppNameAsar();
|
|
223
238
|
const {
|
|
239
|
+
mainPath = path__default.default.join(
|
|
240
|
+
isDev ? path__default.default.join(electron.app.getAppPath(), __EIU_MAIN_DEV_DIR__) : appNameAsarPath,
|
|
241
|
+
"main",
|
|
242
|
+
__EIU_MAIN_FILE__
|
|
243
|
+
),
|
|
224
244
|
updater,
|
|
225
245
|
onInstall = defaultOnInstall,
|
|
226
246
|
beforeStart,
|
|
@@ -234,29 +254,29 @@ async function initApp(appOptions = {}) {
|
|
|
234
254
|
}
|
|
235
255
|
const logger = updaterInstance.logger;
|
|
236
256
|
try {
|
|
237
|
-
const appNameAsarPath = getPathFromAppNameAsar();
|
|
238
257
|
const tempAsarPath = `${appNameAsarPath}.tmp`;
|
|
239
258
|
if (fs3__default.default.existsSync(tempAsarPath)) {
|
|
240
|
-
logger?.info(`
|
|
259
|
+
logger?.info(`Installing new asar from ${tempAsarPath}`);
|
|
241
260
|
await onInstall(() => fs3__default.default.renameSync(tempAsarPath, appNameAsarPath), tempAsarPath, appNameAsarPath, logger);
|
|
242
261
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
"
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
__require(mainFilePath)(updaterInstance);
|
|
262
|
+
await beforeStart?.(mainPath, logger);
|
|
263
|
+
if (__EIU_IS_ESM__) {
|
|
264
|
+
(await import("file://" + mainPath)).default(updaterInstance);
|
|
265
|
+
} else {
|
|
266
|
+
__require(mainPath)(updaterInstance);
|
|
267
|
+
}
|
|
250
268
|
} catch (error) {
|
|
251
269
|
logger?.error("startup error", error);
|
|
252
270
|
onStartError?.(error, logger);
|
|
253
271
|
electron.app.quit();
|
|
254
272
|
}
|
|
255
273
|
}
|
|
274
|
+
var initApp = createElectronApp;
|
|
256
275
|
|
|
257
276
|
exports.ErrorInfo = ErrorInfo;
|
|
258
277
|
exports.Updater = Updater;
|
|
259
278
|
exports.UpdaterError = UpdaterError;
|
|
260
279
|
exports.autoUpdate = autoUpdate;
|
|
280
|
+
exports.createElectronApp = createElectronApp;
|
|
261
281
|
exports.initApp = initApp;
|
|
262
282
|
exports.startupWithUpdater = startupWithUpdater;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
|
-
import { U as UpdateInfo, a as UpdateJSON } from './version-
|
|
3
|
-
import { I as IProvider, D as DownloadingInfo } from './types-
|
|
4
|
-
import '@subframe7536/type-utils';
|
|
2
|
+
import { U as UpdateInfo, a as UpdateJSON } from './version-BYVQ367i.cjs';
|
|
3
|
+
import { I as IProvider, D as DownloadingInfo } from './types-CGSkHX4Y.cjs';
|
|
4
|
+
import { Promisable } from '@subframe7536/type-utils';
|
|
5
5
|
|
|
6
6
|
declare const ErrorInfo: {
|
|
7
7
|
readonly download: "Download Failed";
|
|
@@ -21,7 +21,9 @@ interface Logger {
|
|
|
21
21
|
}
|
|
22
22
|
interface UpdaterOption {
|
|
23
23
|
/**
|
|
24
|
-
* Update provider
|
|
24
|
+
* Update provider
|
|
25
|
+
*
|
|
26
|
+
* If you will not setup `UpdateJSON` or `Buffer` in params when checking update or download, this option is **required**
|
|
25
27
|
*/
|
|
26
28
|
provider?: IProvider;
|
|
27
29
|
/**
|
|
@@ -42,12 +44,14 @@ interface UpdaterOption {
|
|
|
42
44
|
declare class Updater extends EventEmitter<{
|
|
43
45
|
'checking': any;
|
|
44
46
|
'update-available': [data: UpdateInfo];
|
|
45
|
-
'update-
|
|
47
|
+
'update-not-available': [reason: string];
|
|
46
48
|
'error': [error: UpdaterError];
|
|
47
49
|
'download-progress': [info: DownloadingInfo];
|
|
48
50
|
'update-downloaded': any;
|
|
51
|
+
'update-cancelled': any;
|
|
49
52
|
}> {
|
|
50
53
|
private CERT;
|
|
54
|
+
private controller;
|
|
51
55
|
private info?;
|
|
52
56
|
provider?: IProvider;
|
|
53
57
|
/**
|
|
@@ -67,17 +71,11 @@ declare class Updater extends EventEmitter<{
|
|
|
67
71
|
* @param options UpdaterOption
|
|
68
72
|
*/
|
|
69
73
|
constructor(options?: UpdaterOption);
|
|
70
|
-
private checkProvider;
|
|
71
74
|
/**
|
|
72
75
|
* This function is used to parse download data.
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* - if format is `'buffer'`
|
|
77
|
-
* - if data is `Buffer`, return it
|
|
78
|
-
* - if data is string or absent, download URL data and return it
|
|
79
|
-
* @param format 'json' or 'buffer'
|
|
80
|
-
* @param data download URL or update json or buffer
|
|
76
|
+
*
|
|
77
|
+
* if data is absent, download URL from provider and return it,
|
|
78
|
+
* else if data is `UpdateJSON`, return it
|
|
81
79
|
*/
|
|
82
80
|
private fetch;
|
|
83
81
|
/**
|
|
@@ -87,12 +85,12 @@ declare class Updater extends EventEmitter<{
|
|
|
87
85
|
/**
|
|
88
86
|
* Check update info using default options
|
|
89
87
|
*/
|
|
90
|
-
|
|
88
|
+
checkForUpdates(): Promise<boolean>;
|
|
91
89
|
/**
|
|
92
90
|
* Check update info using existing update json
|
|
93
91
|
* @param data existing update json
|
|
94
92
|
*/
|
|
95
|
-
|
|
93
|
+
checkForUpdates(data: UpdateJSON): Promise<boolean>;
|
|
96
94
|
/**
|
|
97
95
|
* Download update using default options
|
|
98
96
|
*/
|
|
@@ -107,13 +105,13 @@ declare class Updater extends EventEmitter<{
|
|
|
107
105
|
* quit App and install
|
|
108
106
|
*/
|
|
109
107
|
quitAndInstall(): void;
|
|
108
|
+
cancel(): void;
|
|
110
109
|
}
|
|
111
110
|
/**
|
|
112
111
|
* Auto check update, download and install
|
|
113
112
|
*/
|
|
114
113
|
declare function autoUpdate(updater: Updater): Promise<void>;
|
|
115
114
|
|
|
116
|
-
type Promisable<T> = T | Promise<T>;
|
|
117
115
|
/**
|
|
118
116
|
* Hooks on rename temp asar path to `${app.name}.asar`
|
|
119
117
|
* @param install `() => renameSync(tempAsarPath, appNameAsarPath)`
|
|
@@ -124,6 +122,12 @@ type Promisable<T> = T | Promise<T>;
|
|
|
124
122
|
*/
|
|
125
123
|
type OnInstallFunction = (install: VoidFunction, tempAsarPath: string, appNameAsarPath: string, logger?: Logger) => Promisable<void>;
|
|
126
124
|
interface AppOption {
|
|
125
|
+
/**
|
|
126
|
+
* Path to index file that make {@link startupWithUpdater} as default export
|
|
127
|
+
*
|
|
128
|
+
* Generate from plugin configuration by default
|
|
129
|
+
*/
|
|
130
|
+
mainPath?: string;
|
|
127
131
|
/**
|
|
128
132
|
* Updater options
|
|
129
133
|
*/
|
|
@@ -133,13 +137,13 @@ interface AppOption {
|
|
|
133
137
|
*/
|
|
134
138
|
onInstall?: OnInstallFunction;
|
|
135
139
|
/**
|
|
136
|
-
* Hooks before app
|
|
140
|
+
* Hooks before app startup
|
|
137
141
|
* @param mainFilePath main file path of `${app.name}.asar`
|
|
138
142
|
* @param logger logger
|
|
139
143
|
*/
|
|
140
144
|
beforeStart?: (mainFilePath: string, logger?: Logger) => Promisable<void>;
|
|
141
145
|
/**
|
|
142
|
-
* Hooks on app
|
|
146
|
+
* Hooks on app startup error
|
|
143
147
|
* @param err installing or startup error
|
|
144
148
|
* @param logger logger
|
|
145
149
|
*/
|
|
@@ -156,13 +160,13 @@ interface AppOption {
|
|
|
156
160
|
*/
|
|
157
161
|
declare function startupWithUpdater(fn: (updater: Updater) => Promisable<void>): (updater: Updater) => Promisable<void>;
|
|
158
162
|
/**
|
|
159
|
-
*
|
|
163
|
+
* Initialize Electron with updater
|
|
160
164
|
* @example
|
|
161
|
-
*
|
|
165
|
+
* createElectronApp({
|
|
162
166
|
* updater: {
|
|
163
167
|
* provider: new GitHubProvider({
|
|
164
|
-
* username: '
|
|
165
|
-
* repo: '
|
|
168
|
+
* username: 'yourname',
|
|
169
|
+
* repo: 'electron',
|
|
166
170
|
* }),
|
|
167
171
|
* },
|
|
168
172
|
* beforeStart(mainFilePath, logger) {
|
|
@@ -170,6 +174,10 @@ declare function startupWithUpdater(fn: (updater: Updater) => Promisable<void>):
|
|
|
170
174
|
* },
|
|
171
175
|
* })
|
|
172
176
|
*/
|
|
173
|
-
declare function
|
|
177
|
+
declare function createElectronApp(appOptions?: AppOption): Promise<void>;
|
|
178
|
+
/**
|
|
179
|
+
* @alias {@link createElectronApp}
|
|
180
|
+
*/
|
|
181
|
+
declare const initApp: typeof createElectronApp;
|
|
174
182
|
|
|
175
|
-
export { type AppOption, ErrorInfo, type Logger, Updater, UpdaterError, type UpdaterOption, autoUpdate, initApp, startupWithUpdater };
|
|
183
|
+
export { type AppOption, ErrorInfo, type Logger, Updater, UpdaterError, type UpdaterOption, autoUpdate, createElectronApp, initApp, startupWithUpdater };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
|
-
import { U as UpdateInfo, a as UpdateJSON } from './version-
|
|
3
|
-
import { I as IProvider, D as DownloadingInfo } from './types-
|
|
4
|
-
import '@subframe7536/type-utils';
|
|
2
|
+
import { U as UpdateInfo, a as UpdateJSON } from './version-BYVQ367i.js';
|
|
3
|
+
import { I as IProvider, D as DownloadingInfo } from './types-C8JhnJjU.js';
|
|
4
|
+
import { Promisable } from '@subframe7536/type-utils';
|
|
5
5
|
|
|
6
6
|
declare const ErrorInfo: {
|
|
7
7
|
readonly download: "Download Failed";
|
|
@@ -21,7 +21,9 @@ interface Logger {
|
|
|
21
21
|
}
|
|
22
22
|
interface UpdaterOption {
|
|
23
23
|
/**
|
|
24
|
-
* Update provider
|
|
24
|
+
* Update provider
|
|
25
|
+
*
|
|
26
|
+
* If you will not setup `UpdateJSON` or `Buffer` in params when checking update or download, this option is **required**
|
|
25
27
|
*/
|
|
26
28
|
provider?: IProvider;
|
|
27
29
|
/**
|
|
@@ -42,12 +44,14 @@ interface UpdaterOption {
|
|
|
42
44
|
declare class Updater extends EventEmitter<{
|
|
43
45
|
'checking': any;
|
|
44
46
|
'update-available': [data: UpdateInfo];
|
|
45
|
-
'update-
|
|
47
|
+
'update-not-available': [reason: string];
|
|
46
48
|
'error': [error: UpdaterError];
|
|
47
49
|
'download-progress': [info: DownloadingInfo];
|
|
48
50
|
'update-downloaded': any;
|
|
51
|
+
'update-cancelled': any;
|
|
49
52
|
}> {
|
|
50
53
|
private CERT;
|
|
54
|
+
private controller;
|
|
51
55
|
private info?;
|
|
52
56
|
provider?: IProvider;
|
|
53
57
|
/**
|
|
@@ -67,17 +71,11 @@ declare class Updater extends EventEmitter<{
|
|
|
67
71
|
* @param options UpdaterOption
|
|
68
72
|
*/
|
|
69
73
|
constructor(options?: UpdaterOption);
|
|
70
|
-
private checkProvider;
|
|
71
74
|
/**
|
|
72
75
|
* This function is used to parse download data.
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* - if format is `'buffer'`
|
|
77
|
-
* - if data is `Buffer`, return it
|
|
78
|
-
* - if data is string or absent, download URL data and return it
|
|
79
|
-
* @param format 'json' or 'buffer'
|
|
80
|
-
* @param data download URL or update json or buffer
|
|
76
|
+
*
|
|
77
|
+
* if data is absent, download URL from provider and return it,
|
|
78
|
+
* else if data is `UpdateJSON`, return it
|
|
81
79
|
*/
|
|
82
80
|
private fetch;
|
|
83
81
|
/**
|
|
@@ -87,12 +85,12 @@ declare class Updater extends EventEmitter<{
|
|
|
87
85
|
/**
|
|
88
86
|
* Check update info using default options
|
|
89
87
|
*/
|
|
90
|
-
|
|
88
|
+
checkForUpdates(): Promise<boolean>;
|
|
91
89
|
/**
|
|
92
90
|
* Check update info using existing update json
|
|
93
91
|
* @param data existing update json
|
|
94
92
|
*/
|
|
95
|
-
|
|
93
|
+
checkForUpdates(data: UpdateJSON): Promise<boolean>;
|
|
96
94
|
/**
|
|
97
95
|
* Download update using default options
|
|
98
96
|
*/
|
|
@@ -107,13 +105,13 @@ declare class Updater extends EventEmitter<{
|
|
|
107
105
|
* quit App and install
|
|
108
106
|
*/
|
|
109
107
|
quitAndInstall(): void;
|
|
108
|
+
cancel(): void;
|
|
110
109
|
}
|
|
111
110
|
/**
|
|
112
111
|
* Auto check update, download and install
|
|
113
112
|
*/
|
|
114
113
|
declare function autoUpdate(updater: Updater): Promise<void>;
|
|
115
114
|
|
|
116
|
-
type Promisable<T> = T | Promise<T>;
|
|
117
115
|
/**
|
|
118
116
|
* Hooks on rename temp asar path to `${app.name}.asar`
|
|
119
117
|
* @param install `() => renameSync(tempAsarPath, appNameAsarPath)`
|
|
@@ -124,6 +122,12 @@ type Promisable<T> = T | Promise<T>;
|
|
|
124
122
|
*/
|
|
125
123
|
type OnInstallFunction = (install: VoidFunction, tempAsarPath: string, appNameAsarPath: string, logger?: Logger) => Promisable<void>;
|
|
126
124
|
interface AppOption {
|
|
125
|
+
/**
|
|
126
|
+
* Path to index file that make {@link startupWithUpdater} as default export
|
|
127
|
+
*
|
|
128
|
+
* Generate from plugin configuration by default
|
|
129
|
+
*/
|
|
130
|
+
mainPath?: string;
|
|
127
131
|
/**
|
|
128
132
|
* Updater options
|
|
129
133
|
*/
|
|
@@ -133,13 +137,13 @@ interface AppOption {
|
|
|
133
137
|
*/
|
|
134
138
|
onInstall?: OnInstallFunction;
|
|
135
139
|
/**
|
|
136
|
-
* Hooks before app
|
|
140
|
+
* Hooks before app startup
|
|
137
141
|
* @param mainFilePath main file path of `${app.name}.asar`
|
|
138
142
|
* @param logger logger
|
|
139
143
|
*/
|
|
140
144
|
beforeStart?: (mainFilePath: string, logger?: Logger) => Promisable<void>;
|
|
141
145
|
/**
|
|
142
|
-
* Hooks on app
|
|
146
|
+
* Hooks on app startup error
|
|
143
147
|
* @param err installing or startup error
|
|
144
148
|
* @param logger logger
|
|
145
149
|
*/
|
|
@@ -156,13 +160,13 @@ interface AppOption {
|
|
|
156
160
|
*/
|
|
157
161
|
declare function startupWithUpdater(fn: (updater: Updater) => Promisable<void>): (updater: Updater) => Promisable<void>;
|
|
158
162
|
/**
|
|
159
|
-
*
|
|
163
|
+
* Initialize Electron with updater
|
|
160
164
|
* @example
|
|
161
|
-
*
|
|
165
|
+
* createElectronApp({
|
|
162
166
|
* updater: {
|
|
163
167
|
* provider: new GitHubProvider({
|
|
164
|
-
* username: '
|
|
165
|
-
* repo: '
|
|
168
|
+
* username: 'yourname',
|
|
169
|
+
* repo: 'electron',
|
|
166
170
|
* }),
|
|
167
171
|
* },
|
|
168
172
|
* beforeStart(mainFilePath, logger) {
|
|
@@ -170,6 +174,10 @@ declare function startupWithUpdater(fn: (updater: Updater) => Promisable<void>):
|
|
|
170
174
|
* },
|
|
171
175
|
* })
|
|
172
176
|
*/
|
|
173
|
-
declare function
|
|
177
|
+
declare function createElectronApp(appOptions?: AppOption): Promise<void>;
|
|
178
|
+
/**
|
|
179
|
+
* @alias {@link createElectronApp}
|
|
180
|
+
*/
|
|
181
|
+
declare const initApp: typeof createElectronApp;
|
|
174
182
|
|
|
175
|
-
export { type AppOption, ErrorInfo, type Logger, Updater, UpdaterError, type UpdaterOption, autoUpdate, initApp, startupWithUpdater };
|
|
183
|
+
export { type AppOption, ErrorInfo, type Logger, Updater, UpdaterError, type UpdaterOption, autoUpdate, createElectronApp, initApp, startupWithUpdater };
|