electron-incremental-update 2.2.1 → 2.2.3
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 +62 -7
- package/dist/{bytecode-7V24FFYI.js → bytecode-R2B4KTMV.js} +3 -3
- package/dist/chunk-D7NXTCQW.js +135 -0
- package/dist/{chunk-JI27JWJN.js → chunk-YZGE4RFY.js} +12 -1
- package/dist/{esm-UJAQJA65.js → esm-4S4XCVEW.js} +1 -1
- package/dist/index.cjs +17 -17
- package/dist/index.d.cts +15 -7
- package/dist/index.d.ts +15 -7
- package/dist/index.js +13 -9
- package/dist/provider.cjs +48 -51
- package/dist/provider.d.cts +14 -43
- package/dist/provider.d.ts +14 -43
- package/dist/provider.js +4 -98
- package/dist/{types-nE_pIMPo.d.ts → types-C5M2xRjF.d.cts} +77 -5
- package/dist/{types-C6lSLZWB.d.cts → types-C5M2xRjF.d.ts} +77 -5
- package/dist/utils.cjs +216 -106
- package/dist/utils.d.cts +6 -3
- package/dist/utils.d.ts +6 -3
- package/dist/utils.js +2 -2
- package/dist/vite.d.ts +50 -28
- package/dist/vite.js +36 -27
- package/dist/zip-BQS8qbGA.d.cts +70 -0
- package/dist/zip-DbfskMQi.d.ts +70 -0
- package/package.json +86 -87
- package/dist/chunk-PUVBFHOK.js +0 -43
- package/dist/crypto-Zynscwmj.d.cts +0 -33
- package/dist/crypto-Zynscwmj.d.ts +0 -33
- package/dist/version-BYVQ367i.d.cts +0 -62
- package/dist/version-BYVQ367i.d.ts +0 -62
- package/dist/{chunk-7JCGLFGU.js → chunk-LR7LR5WG.js} +3 -3
package/README.md
CHANGED
|
@@ -94,8 +94,8 @@ See all config in [types](#plugin)
|
|
|
94
94
|
in `vite.config.mts`
|
|
95
95
|
|
|
96
96
|
```ts
|
|
97
|
-
import { defineConfig } from 'vite'
|
|
98
97
|
import { debugStartup, electronWithUpdater } from 'electron-incremental-update/vite'
|
|
98
|
+
import { defineConfig } from 'vite'
|
|
99
99
|
|
|
100
100
|
export default defineConfig(async ({ command }) => {
|
|
101
101
|
const isBuild = command === 'build'
|
|
@@ -180,9 +180,9 @@ The update steps are similar to [electron-updater](https://github.com/electron-u
|
|
|
180
180
|
in `electron/main/index.ts`
|
|
181
181
|
|
|
182
182
|
```ts
|
|
183
|
-
import { UpdaterError, startupWithUpdater } from 'electron-incremental-update'
|
|
184
|
-
import { getPathFromAppNameAsar, getVersions } from 'electron-incremental-update/utils'
|
|
185
183
|
import { app } from 'electron'
|
|
184
|
+
import { startupWithUpdater, UpdaterError } from 'electron-incremental-update'
|
|
185
|
+
import { getPathFromAppNameAsar, getVersions } from 'electron-incremental-update/utils'
|
|
186
186
|
|
|
187
187
|
export default startupWithUpdater((updater) => {
|
|
188
188
|
await app.whenReady()
|
|
@@ -260,7 +260,7 @@ const plugin = electronWithUpdater({
|
|
|
260
260
|
db: './electron/native/db.ts',
|
|
261
261
|
img: './electron/native/img.ts',
|
|
262
262
|
},
|
|
263
|
-
postBuild: async ({ copyToEntryOutputDir }) => {
|
|
263
|
+
postBuild: async ({ copyToEntryOutputDir, copyModules }) => {
|
|
264
264
|
// for better-sqlite3
|
|
265
265
|
copyToEntryOutputDir({
|
|
266
266
|
from: './node_modules/better-sqlite3/build/Release/better_sqlite3.node',
|
|
@@ -273,6 +273,8 @@ const plugin = electronWithUpdater({
|
|
|
273
273
|
copyToEntryOutputDir({
|
|
274
274
|
from: `./node_modules/.pnpm/${fileName}/node_modules/@napi-rs/image-${archName}/image.${archName}.node`,
|
|
275
275
|
})
|
|
276
|
+
// or just copy specific dependency
|
|
277
|
+
copyModules({ modules: ['better-sqlite3'] })
|
|
276
278
|
},
|
|
277
279
|
},
|
|
278
280
|
},
|
|
@@ -470,6 +472,60 @@ function getPathFromEntryAsar(...paths: string[]): string
|
|
|
470
472
|
* @param callback callback function
|
|
471
473
|
*/
|
|
472
474
|
function handleUnexpectedErrors(callback: (err: unknown) => void): void
|
|
475
|
+
/**
|
|
476
|
+
* Safe get value from header
|
|
477
|
+
* @param headers response header
|
|
478
|
+
* @param key target header key
|
|
479
|
+
*/
|
|
480
|
+
function getHeader(headers: Record<string, Arrayable<string>>, key: any): any
|
|
481
|
+
function downloadUtil<T>(
|
|
482
|
+
url: string,
|
|
483
|
+
headers: Record<string, any>,
|
|
484
|
+
signal: AbortSignal,
|
|
485
|
+
onResponse: (
|
|
486
|
+
resp: IncomingMessage,
|
|
487
|
+
resolve: (data: T) => void,
|
|
488
|
+
reject: (e: any) => void
|
|
489
|
+
) => void
|
|
490
|
+
): Promise<T>
|
|
491
|
+
/**
|
|
492
|
+
* Default function to download json and parse to UpdateJson
|
|
493
|
+
* @param url target url
|
|
494
|
+
* @param headers extra headers
|
|
495
|
+
* @param signal abort signal
|
|
496
|
+
* @param resolveData on resolve
|
|
497
|
+
*/
|
|
498
|
+
function defaultDownloadJSON<T>(
|
|
499
|
+
url: string,
|
|
500
|
+
headers: Record<string, any>,
|
|
501
|
+
signal: AbortSignal,
|
|
502
|
+
resolveData?: ResolveDataFn
|
|
503
|
+
): Promise<T>
|
|
504
|
+
/**
|
|
505
|
+
* Default function to download json and parse to UpdateJson
|
|
506
|
+
* @param url target url
|
|
507
|
+
* @param headers extra headers
|
|
508
|
+
* @param signal abort signal
|
|
509
|
+
*/
|
|
510
|
+
function defaultDownloadUpdateJSON(
|
|
511
|
+
url: string,
|
|
512
|
+
headers: Record<string, any>,
|
|
513
|
+
signal: AbortSignal
|
|
514
|
+
): Promise<UpdateJSON>
|
|
515
|
+
/**
|
|
516
|
+
* Default function to download asar buffer,
|
|
517
|
+
* get total size from `Content-Length` header
|
|
518
|
+
* @param url target url
|
|
519
|
+
* @param headers extra headers
|
|
520
|
+
* @param signal abort signal
|
|
521
|
+
* @param onDownloading on downloading callback
|
|
522
|
+
*/
|
|
523
|
+
function defaultDownloadAsar(
|
|
524
|
+
url: string,
|
|
525
|
+
headers: Record<string, any>,
|
|
526
|
+
signal: AbortSignal,
|
|
527
|
+
onDownloading?: (progress: DownloadingInfo) => void
|
|
528
|
+
): Promise<Buffer>
|
|
473
529
|
```
|
|
474
530
|
|
|
475
531
|
### Types
|
|
@@ -923,15 +979,14 @@ export interface GeneratorOverrideFunctions {
|
|
|
923
979
|
version: string
|
|
924
980
|
) => Promisable<string>
|
|
925
981
|
/**
|
|
926
|
-
* Custom generate
|
|
982
|
+
* Custom generate update json function
|
|
927
983
|
* @param existingJson The existing JSON object.
|
|
928
984
|
* @param buffer file buffer
|
|
929
985
|
* @param signature generated signature
|
|
930
986
|
* @param version current version
|
|
931
987
|
* @param minVersion The minimum version
|
|
932
|
-
* @returns The updated version json
|
|
933
988
|
*/
|
|
934
|
-
|
|
989
|
+
generateUpdateJson?: (
|
|
935
990
|
existingJson: UpdateJSON,
|
|
936
991
|
signature: string,
|
|
937
992
|
version: string,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { readableSize } from './chunk-TPTWE33H.js';
|
|
2
|
-
import { convertLiteral, bytecodeModuleLoaderCode, bytecodeModuleLoader, convertArrowFunctionAndTemplate, compileToBytecode, useStrict, toRelativePath } from './chunk-
|
|
2
|
+
import { convertLiteral, bytecodeModuleLoaderCode, bytecodeModuleLoader, convertArrowFunctionAndTemplate, compileToBytecode, useStrict, toRelativePath } from './chunk-LR7LR5WG.js';
|
|
3
3
|
import { bytecodeLog, bytecodeId } from './chunk-5NKEXGI3.js';
|
|
4
|
-
import path from 'node:path';
|
|
5
4
|
import fs from 'node:fs';
|
|
6
|
-
import
|
|
5
|
+
import path from 'node:path';
|
|
7
6
|
import MagicString from 'magic-string';
|
|
7
|
+
import { createFilter, normalizePath } from 'vite';
|
|
8
8
|
|
|
9
9
|
function getBytecodeLoaderBlock(chunkFileName) {
|
|
10
10
|
return `require("${toRelativePath(bytecodeModuleLoader, normalizePath(chunkFileName))}");`;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { isUpdateJSON } from './chunk-AAAM44NW.js';
|
|
2
|
+
import crypto from 'node:crypto';
|
|
3
|
+
import electron from 'electron';
|
|
4
|
+
import zlib from 'node:zlib';
|
|
5
|
+
|
|
6
|
+
function hashBuffer(data, length) {
|
|
7
|
+
const hash = crypto.createHash("SHA256").update(data).digest("binary");
|
|
8
|
+
return Buffer.from(hash).subarray(0, length);
|
|
9
|
+
}
|
|
10
|
+
function aesEncrypt(plainText, key, iv) {
|
|
11
|
+
const cipher = crypto.createCipheriv("aes-256-cbc", key, iv);
|
|
12
|
+
return cipher.update(plainText, "utf8", "base64url") + cipher.final("base64url");
|
|
13
|
+
}
|
|
14
|
+
function defaultSignature(buffer, privateKey, cert, version) {
|
|
15
|
+
const sig = crypto.createSign("RSA-SHA256").update(buffer).sign(crypto.createPrivateKey(privateKey), "base64");
|
|
16
|
+
return aesEncrypt(`${sig}%${version}`, hashBuffer(cert, 32), hashBuffer(buffer, 16));
|
|
17
|
+
}
|
|
18
|
+
function aesDecrypt(encryptedText, key, iv) {
|
|
19
|
+
const decipher = crypto.createDecipheriv("aes-256-cbc", key, iv);
|
|
20
|
+
return decipher.update(encryptedText, "base64url", "utf8") + decipher.final("utf8");
|
|
21
|
+
}
|
|
22
|
+
function defaultVerifySignature(buffer, version, signature, cert) {
|
|
23
|
+
try {
|
|
24
|
+
const [sig, ver] = aesDecrypt(signature, hashBuffer(cert, 32), hashBuffer(buffer, 16)).split("%");
|
|
25
|
+
if (ver !== version) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return crypto.createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
|
|
29
|
+
} catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function getHeader(headers, key) {
|
|
34
|
+
const value = headers[key];
|
|
35
|
+
if (Array.isArray(value)) {
|
|
36
|
+
return value.length === 0 ? null : value[value.length - 1];
|
|
37
|
+
} else {
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function downloadUtil(url, headers, signal, onResponse) {
|
|
42
|
+
await electron.app.whenReady();
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
const request = electron.net.request({ url, method: "GET", redirect: "follow", headers, cache: "no-cache" });
|
|
45
|
+
signal.addEventListener("abort", () => request.abort(), { once: true });
|
|
46
|
+
request.on("response", (resp) => {
|
|
47
|
+
resp.on("aborted", () => reject(new Error("aborted")));
|
|
48
|
+
resp.on("error", () => reject(new Error("download error")));
|
|
49
|
+
onResponse(resp, resolve, reject);
|
|
50
|
+
});
|
|
51
|
+
request.on("error", reject);
|
|
52
|
+
request.end();
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function trimData(data) {
|
|
56
|
+
return data.trim().slice(0, 5e3).replace(/\s+/g, " ");
|
|
57
|
+
}
|
|
58
|
+
var defaultResolveDataFn = (data, resolve, reject) => {
|
|
59
|
+
try {
|
|
60
|
+
resolve(JSON.parse(data));
|
|
61
|
+
} catch {
|
|
62
|
+
reject(new Error(`Invalid json, "${trimData(data)}"`));
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
async function defaultDownloadJSON(url, headers, signal, resolveData = defaultResolveDataFn) {
|
|
66
|
+
return await downloadUtil(
|
|
67
|
+
url,
|
|
68
|
+
headers,
|
|
69
|
+
signal,
|
|
70
|
+
(resp, resolve, reject) => {
|
|
71
|
+
let data = "";
|
|
72
|
+
resp.on("data", (chunk) => data += chunk);
|
|
73
|
+
resp.on("end", () => resolveData(data, resolve, reject));
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
async function defaultDownloadUpdateJSON(url, headers, signal) {
|
|
78
|
+
return await defaultDownloadJSON(
|
|
79
|
+
url,
|
|
80
|
+
headers,
|
|
81
|
+
signal,
|
|
82
|
+
(data, resolve, reject) => {
|
|
83
|
+
try {
|
|
84
|
+
const json = JSON.parse(data);
|
|
85
|
+
if (isUpdateJSON(json)) {
|
|
86
|
+
resolve(json);
|
|
87
|
+
} else {
|
|
88
|
+
throw Error;
|
|
89
|
+
}
|
|
90
|
+
} catch {
|
|
91
|
+
reject(new Error(`Invalid update json, "${trimData(data)}"`));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
async function defaultDownloadAsar(url, headers, signal, onDownloading) {
|
|
97
|
+
let transferred = 0;
|
|
98
|
+
let time = Date.now();
|
|
99
|
+
return await downloadUtil(
|
|
100
|
+
url,
|
|
101
|
+
headers,
|
|
102
|
+
signal,
|
|
103
|
+
(resp, resolve) => {
|
|
104
|
+
const total = +getHeader(resp.headers, "content-length") || -1;
|
|
105
|
+
const data = [];
|
|
106
|
+
resp.on("data", (chunk) => {
|
|
107
|
+
const delta = chunk.length;
|
|
108
|
+
transferred += delta;
|
|
109
|
+
const current = Date.now();
|
|
110
|
+
onDownloading?.({
|
|
111
|
+
percent: total > 0 ? +(transferred / total).toFixed(2) * 100 : -1,
|
|
112
|
+
total,
|
|
113
|
+
transferred,
|
|
114
|
+
delta,
|
|
115
|
+
bps: delta / (current - time)
|
|
116
|
+
});
|
|
117
|
+
time = current;
|
|
118
|
+
data.push(chunk);
|
|
119
|
+
});
|
|
120
|
+
resp.on("end", () => resolve(Buffer.concat(data)));
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
async function defaultZipFile(buffer) {
|
|
125
|
+
return new Promise((resolve, reject) => {
|
|
126
|
+
zlib.brotliCompress(buffer, (err, buffer2) => err ? reject(err) : resolve(buffer2));
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
async function defaultUnzipFile(buffer) {
|
|
130
|
+
return new Promise((resolve, reject) => {
|
|
131
|
+
zlib.brotliDecompress(buffer, (err, buffer2) => err ? reject(err) : resolve(buffer2));
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export { aesDecrypt, aesEncrypt, defaultDownloadAsar, defaultDownloadJSON, defaultDownloadUpdateJSON, defaultSignature, defaultUnzipFile, defaultVerifySignature, defaultZipFile, downloadUtil, getHeader, hashBuffer };
|
|
@@ -96,5 +96,16 @@ function handleUnexpectedErrors(callback) {
|
|
|
96
96
|
process.on("uncaughtException", callback);
|
|
97
97
|
process.on("unhandledRejection", callback);
|
|
98
98
|
}
|
|
99
|
+
function reloadOnPreloadScriptChanged() {
|
|
100
|
+
if (isDev) {
|
|
101
|
+
process.on("message", (msg) => {
|
|
102
|
+
if (msg === "electron-vite&type=hot-reload") {
|
|
103
|
+
for (const window of electron.BrowserWindow.getAllWindows()) {
|
|
104
|
+
window.reload();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
99
110
|
|
|
100
|
-
export { beautifyDevTools, disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, importNative, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
|
|
111
|
+
export { beautifyDevTools, disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, importNative, isDev, isLinux, isMac, isWin, loadPage, reloadOnPreloadScriptChanged, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
|
package/dist/index.cjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var fs3 = require('fs');
|
|
4
|
-
var
|
|
4
|
+
var path2 = require('path');
|
|
5
5
|
var electron = require('electron');
|
|
6
|
-
var
|
|
6
|
+
var events = require('events');
|
|
7
7
|
|
|
8
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
9
|
|
|
10
10
|
var fs3__default = /*#__PURE__*/_interopDefault(fs3);
|
|
11
|
+
var path2__default = /*#__PURE__*/_interopDefault(path2);
|
|
11
12
|
var electron__default = /*#__PURE__*/_interopDefault(electron);
|
|
12
|
-
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
13
13
|
|
|
14
14
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
15
15
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
@@ -17,18 +17,12 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
17
17
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
18
18
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
19
19
|
});
|
|
20
|
-
|
|
21
|
-
// src/utils/version.ts
|
|
22
|
-
var is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
|
|
23
|
-
function isUpdateJSON(json) {
|
|
24
|
-
return is(json) && is(json?.beta);
|
|
25
|
-
}
|
|
26
20
|
var isDev = __EIU_IS_DEV__;
|
|
27
21
|
process.platform === "win32";
|
|
28
22
|
process.platform === "darwin";
|
|
29
23
|
process.platform === "linux";
|
|
30
24
|
function getPathFromAppNameAsar(...paths) {
|
|
31
|
-
return isDev ? "DEV.asar" :
|
|
25
|
+
return isDev ? "DEV.asar" : path2__default.default.join(path2__default.default.dirname(electron__default.default.app.getAppPath()), `${electron__default.default.app.name}.asar`, ...paths);
|
|
32
26
|
}
|
|
33
27
|
function getAppVersion() {
|
|
34
28
|
return isDev ? getEntryVersion() : fs3__default.default.readFileSync(getPathFromAppNameAsar("version"), "utf-8");
|
|
@@ -40,8 +34,11 @@ function restartApp() {
|
|
|
40
34
|
electron__default.default.app.relaunch();
|
|
41
35
|
electron__default.default.app.quit();
|
|
42
36
|
}
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
|
|
38
|
+
// src/utils/version.ts
|
|
39
|
+
var is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
|
|
40
|
+
function isUpdateJSON(json) {
|
|
41
|
+
return is(json) && is(json?.beta);
|
|
45
42
|
}
|
|
46
43
|
|
|
47
44
|
// src/entry/types.ts
|
|
@@ -136,18 +133,19 @@ var Updater = class extends events.EventEmitter {
|
|
|
136
133
|
if (!_data) {
|
|
137
134
|
return emitUnavailable("Failed to get update info", "UNAVAILABLE_ERROR");
|
|
138
135
|
}
|
|
139
|
-
const { signature, version, minimumVersion, url = "" } = this.receiveBeta ? _data.beta : _data;
|
|
136
|
+
const { signature, version, minimumVersion, url = "", ...rest } = this.receiveBeta ? _data.beta : _data;
|
|
140
137
|
const info = { signature, minimumVersion, version, url };
|
|
141
138
|
const extraVersionInfo = {
|
|
142
139
|
signature,
|
|
143
140
|
minimumVersion,
|
|
144
141
|
version,
|
|
145
142
|
appVersion: getAppVersion(),
|
|
146
|
-
entryVersion: getEntryVersion()
|
|
143
|
+
entryVersion: getEntryVersion(),
|
|
144
|
+
...rest
|
|
147
145
|
};
|
|
148
146
|
this.logger?.debug(`Checked update, version: ${version}, signature: ${signature}`);
|
|
149
147
|
if (isDev && !this.forceUpdate && !data) {
|
|
150
|
-
return emitUnavailable("Skip check update in dev mode. To force update, set `updater.forceUpdate` to true or call checkUpdate with UpdateJSON", "UNAVAILABLE_DEV"
|
|
148
|
+
return emitUnavailable("Skip check update in dev mode. To force update, set `updater.forceUpdate` to true or call checkUpdate with UpdateJSON", "UNAVAILABLE_DEV");
|
|
151
149
|
}
|
|
152
150
|
const isLowerVersion = this.provider.isLowerVersion;
|
|
153
151
|
try {
|
|
@@ -225,6 +223,8 @@ async function autoUpdate(updater) {
|
|
|
225
223
|
updater.quitAndInstall();
|
|
226
224
|
}
|
|
227
225
|
}
|
|
226
|
+
|
|
227
|
+
// src/entry/core.ts
|
|
228
228
|
function startupWithUpdater(fn) {
|
|
229
229
|
return fn;
|
|
230
230
|
}
|
|
@@ -235,7 +235,7 @@ var defaultOnInstall = (install, _, __, logger) => {
|
|
|
235
235
|
async function createElectronApp(appOptions = {}) {
|
|
236
236
|
const appNameAsarPath = getPathFromAppNameAsar();
|
|
237
237
|
const {
|
|
238
|
-
mainPath =
|
|
238
|
+
mainPath = isDev ? path2__default.default.join(electron__default.default.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "main", __EIU_MAIN_FILE__) : path2__default.default.join(path2__default.default.dirname(electron__default.default.app.getAppPath()), __EIU_ASAR_BASE_NAME__, "main", __EIU_MAIN_FILE__),
|
|
239
239
|
updater,
|
|
240
240
|
onInstall = defaultOnInstall,
|
|
241
241
|
beforeStart,
|
|
@@ -256,7 +256,7 @@ async function createElectronApp(appOptions = {}) {
|
|
|
256
256
|
__require(mainPath)(updaterInstance);
|
|
257
257
|
}
|
|
258
258
|
} catch (error) {
|
|
259
|
-
logger?.error("startup error", error);
|
|
259
|
+
logger?.error("startup error, exit", error);
|
|
260
260
|
onStartError?.(error, logger);
|
|
261
261
|
electron__default.default.app.quit();
|
|
262
262
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { EventEmitter } from 'node:events';
|
|
2
|
-
import { U as UpdateInfo, a as UpdateJSON } from './version-BYVQ367i.cjs';
|
|
3
|
-
import { I as IProvider, D as DownloadingInfo, U as UpdateJSONWithURL } from './types-C6lSLZWB.cjs';
|
|
4
1
|
import { Promisable } from '@subframe7536/type-utils';
|
|
2
|
+
import { I as IProvider, U as UpdateInfo, D as DownloadingInfo, a as UpdateJSON, b as UpdateJSONWithURL } from './types-C5M2xRjF.cjs';
|
|
3
|
+
import { EventEmitter } from 'node:events';
|
|
4
|
+
import 'node:url';
|
|
5
5
|
|
|
6
6
|
type UpdaterErrorCode = 'ERR_DOWNLOAD' | 'ERR_VALIDATE' | 'ERR_PARAM' | 'ERR_NETWORK';
|
|
7
7
|
type UpdaterUnavailableCode = 'UNAVAILABLE_ERROR' | 'UNAVAILABLE_DEV' | 'UNAVAILABLE_VERSION';
|
|
@@ -36,15 +36,23 @@ interface UpdaterOption {
|
|
|
36
36
|
*/
|
|
37
37
|
logger?: Logger;
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Update info with current app version and entry version
|
|
41
|
+
*/
|
|
39
42
|
type UpdateInfoWithExtraVersion = UpdateInfo & {
|
|
43
|
+
/**
|
|
44
|
+
* Current app version
|
|
45
|
+
*/
|
|
40
46
|
appVersion: string;
|
|
47
|
+
/**
|
|
48
|
+
* Current entry version
|
|
49
|
+
*/
|
|
41
50
|
entryVersion: string;
|
|
42
51
|
};
|
|
43
52
|
|
|
44
|
-
declare class Updater extends EventEmitter<{
|
|
45
|
-
'
|
|
46
|
-
'update-available': [
|
|
47
|
-
'update-not-available': [code: UpdaterUnavailableCode, msg: string, info?: UpdateInfoWithExtraVersion];
|
|
53
|
+
declare class Updater<T extends UpdateInfoWithExtraVersion = UpdateInfoWithExtraVersion> extends EventEmitter<{
|
|
54
|
+
'update-available': [data: T];
|
|
55
|
+
'update-not-available': [code: UpdaterUnavailableCode, msg: string, info?: T];
|
|
48
56
|
'error': [error: UpdaterError];
|
|
49
57
|
'download-progress': [info: DownloadingInfo];
|
|
50
58
|
'update-downloaded': any;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { EventEmitter } from 'node:events';
|
|
2
|
-
import { U as UpdateInfo, a as UpdateJSON } from './version-BYVQ367i.js';
|
|
3
|
-
import { I as IProvider, D as DownloadingInfo, U as UpdateJSONWithURL } from './types-nE_pIMPo.js';
|
|
4
1
|
import { Promisable } from '@subframe7536/type-utils';
|
|
2
|
+
import { I as IProvider, U as UpdateInfo, D as DownloadingInfo, a as UpdateJSON, b as UpdateJSONWithURL } from './types-C5M2xRjF.js';
|
|
3
|
+
import { EventEmitter } from 'node:events';
|
|
4
|
+
import 'node:url';
|
|
5
5
|
|
|
6
6
|
type UpdaterErrorCode = 'ERR_DOWNLOAD' | 'ERR_VALIDATE' | 'ERR_PARAM' | 'ERR_NETWORK';
|
|
7
7
|
type UpdaterUnavailableCode = 'UNAVAILABLE_ERROR' | 'UNAVAILABLE_DEV' | 'UNAVAILABLE_VERSION';
|
|
@@ -36,15 +36,23 @@ interface UpdaterOption {
|
|
|
36
36
|
*/
|
|
37
37
|
logger?: Logger;
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Update info with current app version and entry version
|
|
41
|
+
*/
|
|
39
42
|
type UpdateInfoWithExtraVersion = UpdateInfo & {
|
|
43
|
+
/**
|
|
44
|
+
* Current app version
|
|
45
|
+
*/
|
|
40
46
|
appVersion: string;
|
|
47
|
+
/**
|
|
48
|
+
* Current entry version
|
|
49
|
+
*/
|
|
41
50
|
entryVersion: string;
|
|
42
51
|
};
|
|
43
52
|
|
|
44
|
-
declare class Updater extends EventEmitter<{
|
|
45
|
-
'
|
|
46
|
-
'update-available': [
|
|
47
|
-
'update-not-available': [code: UpdaterUnavailableCode, msg: string, info?: UpdateInfoWithExtraVersion];
|
|
53
|
+
declare class Updater<T extends UpdateInfoWithExtraVersion = UpdateInfoWithExtraVersion> extends EventEmitter<{
|
|
54
|
+
'update-available': [data: T];
|
|
55
|
+
'update-not-available': [code: UpdaterUnavailableCode, msg: string, info?: T];
|
|
48
56
|
'error': [error: UpdaterError];
|
|
49
57
|
'download-progress': [info: DownloadingInfo];
|
|
50
58
|
'update-downloaded': any;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { isDev, getAppVersion, getEntryVersion, getPathFromAppNameAsar, restartApp
|
|
1
|
+
import { isDev, getAppVersion, getEntryVersion, getPathFromAppNameAsar, restartApp } from './chunk-YZGE4RFY.js';
|
|
2
2
|
import { isUpdateJSON, __require } from './chunk-AAAM44NW.js';
|
|
3
3
|
import fs2 from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import electron2 from 'electron';
|
|
4
6
|
import { EventEmitter } from 'node:events';
|
|
5
|
-
import electron from 'electron';
|
|
6
7
|
|
|
7
8
|
// src/entry/types.ts
|
|
8
9
|
var UpdaterError = class extends Error {
|
|
@@ -66,7 +67,7 @@ var Updater = class extends EventEmitter {
|
|
|
66
67
|
}
|
|
67
68
|
this.logger?.debug(`Download from \`${this.provider.name}\``);
|
|
68
69
|
try {
|
|
69
|
-
const result = format === "json" ? await this.provider.downloadJSON(
|
|
70
|
+
const result = format === "json" ? await this.provider.downloadJSON(electron2.app.name, __EIU_VERSION_PATH__, this.controller.signal) : await this.provider.downloadAsar(this.info, this.controller.signal, (info) => this.emit("download-progress", info));
|
|
70
71
|
this.logger?.debug(`Download ${format} success${format === "buffer" ? `, file size: ${result.length}` : ""}`);
|
|
71
72
|
return result;
|
|
72
73
|
} catch (e) {
|
|
@@ -96,18 +97,19 @@ var Updater = class extends EventEmitter {
|
|
|
96
97
|
if (!_data) {
|
|
97
98
|
return emitUnavailable("Failed to get update info", "UNAVAILABLE_ERROR");
|
|
98
99
|
}
|
|
99
|
-
const { signature, version, minimumVersion, url = "" } = this.receiveBeta ? _data.beta : _data;
|
|
100
|
+
const { signature, version, minimumVersion, url = "", ...rest } = this.receiveBeta ? _data.beta : _data;
|
|
100
101
|
const info = { signature, minimumVersion, version, url };
|
|
101
102
|
const extraVersionInfo = {
|
|
102
103
|
signature,
|
|
103
104
|
minimumVersion,
|
|
104
105
|
version,
|
|
105
106
|
appVersion: getAppVersion(),
|
|
106
|
-
entryVersion: getEntryVersion()
|
|
107
|
+
entryVersion: getEntryVersion(),
|
|
108
|
+
...rest
|
|
107
109
|
};
|
|
108
110
|
this.logger?.debug(`Checked update, version: ${version}, signature: ${signature}`);
|
|
109
111
|
if (isDev && !this.forceUpdate && !data) {
|
|
110
|
-
return emitUnavailable("Skip check update in dev mode. To force update, set `updater.forceUpdate` to true or call checkUpdate with UpdateJSON", "UNAVAILABLE_DEV"
|
|
112
|
+
return emitUnavailable("Skip check update in dev mode. To force update, set `updater.forceUpdate` to true or call checkUpdate with UpdateJSON", "UNAVAILABLE_DEV");
|
|
111
113
|
}
|
|
112
114
|
const isLowerVersion = this.provider.isLowerVersion;
|
|
113
115
|
try {
|
|
@@ -185,6 +187,8 @@ async function autoUpdate(updater) {
|
|
|
185
187
|
updater.quitAndInstall();
|
|
186
188
|
}
|
|
187
189
|
}
|
|
190
|
+
|
|
191
|
+
// src/entry/core.ts
|
|
188
192
|
function startupWithUpdater(fn) {
|
|
189
193
|
return fn;
|
|
190
194
|
}
|
|
@@ -195,7 +199,7 @@ var defaultOnInstall = (install, _, __, logger) => {
|
|
|
195
199
|
async function createElectronApp(appOptions = {}) {
|
|
196
200
|
const appNameAsarPath = getPathFromAppNameAsar();
|
|
197
201
|
const {
|
|
198
|
-
mainPath =
|
|
202
|
+
mainPath = isDev ? path.join(electron2.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "main", __EIU_MAIN_FILE__) : path.join(path.dirname(electron2.app.getAppPath()), __EIU_ASAR_BASE_NAME__, "main", __EIU_MAIN_FILE__),
|
|
199
203
|
updater,
|
|
200
204
|
onInstall = defaultOnInstall,
|
|
201
205
|
beforeStart,
|
|
@@ -216,9 +220,9 @@ async function createElectronApp(appOptions = {}) {
|
|
|
216
220
|
__require(mainPath)(updaterInstance);
|
|
217
221
|
}
|
|
218
222
|
} catch (error) {
|
|
219
|
-
logger?.error("startup error", error);
|
|
223
|
+
logger?.error("startup error, exit", error);
|
|
220
224
|
onStartError?.(error, logger);
|
|
221
|
-
|
|
225
|
+
electron2.app.quit();
|
|
222
226
|
}
|
|
223
227
|
}
|
|
224
228
|
var initApp = createElectronApp;
|