electron-incremental-update 2.0.0-beta.7 → 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/{chunk-DFNDKSE6.js → chunk-4MH6ZXCY.js} +12 -12
- package/dist/{chunk-N77WQ5WB.js → chunk-KZSYEXLO.js} +9 -9
- package/dist/index.cjs +43 -52
- package/dist/index.d.cts +130 -9
- package/dist/index.d.ts +130 -9
- package/dist/index.js +36 -51
- package/dist/provider.cjs +25 -9
- package/dist/provider.d.cts +17 -1
- package/dist/provider.d.ts +17 -1
- package/dist/provider.js +17 -6
- package/dist/{types-CItP6bL-.d.ts → types-D7OK98ln.d.ts} +3 -28
- package/dist/{types-CItP6bL-.d.cts → types-mEfMjnlV.d.cts} +3 -28
- package/dist/utils.cjs +24 -25
- package/dist/utils.d.cts +3 -11
- package/dist/utils.d.ts +3 -11
- package/dist/utils.js +2 -11
- package/dist/version-DgfjJQUx.d.cts +27 -0
- package/dist/version-DgfjJQUx.d.ts +27 -0
- package/dist/vite.d.ts +7 -4
- package/dist/vite.js +164 -125
- package/package.json +8 -6
- package/dist/core-DJdvtwvU.d.ts +0 -134
- package/dist/core-ZUlLHadf.d.cts +0 -134
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { isDev, getEntryVersion, getAppVersion, getPathFromAppNameAsar, restartApp } from './chunk-
|
|
1
|
+
import { isDev, getEntryVersion, getAppVersion, getPathFromAppNameAsar, restartApp } from './chunk-4MH6ZXCY.js';
|
|
2
2
|
import { isUpdateJSON, __require } from './chunk-72ZAJ7AF.js';
|
|
3
|
-
import
|
|
4
|
-
import { writeFileSync, existsSync, renameSync } from 'node:fs';
|
|
5
|
-
import { app } from 'electron';
|
|
3
|
+
import fs2 from 'node:fs';
|
|
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) {
|
|
@@ -137,14 +142,14 @@ var Updater = class extends EventEmitter {
|
|
|
137
142
|
}
|
|
138
143
|
this.logger?.debug("verify start");
|
|
139
144
|
if (!await this.provider.verifySignaure(buffer, _version, _sig, this.CERT)) {
|
|
140
|
-
this.err("download failed", "validate", "invalid
|
|
145
|
+
this.err("download failed", "validate", "invalid update asar file");
|
|
141
146
|
return false;
|
|
142
147
|
}
|
|
143
148
|
this.logger?.debug("verify success");
|
|
144
149
|
try {
|
|
145
150
|
const tmpFilePath = getPathFromAppNameAsar() + ".tmp";
|
|
146
151
|
this.logger?.debug(`install to ${tmpFilePath}`);
|
|
147
|
-
writeFileSync(tmpFilePath, await this.provider.unzipFile(buffer));
|
|
152
|
+
fs2.writeFileSync(tmpFilePath, await this.provider.unzipFile(buffer));
|
|
148
153
|
this.logger?.info(`download success, version: ${_version}`);
|
|
149
154
|
this.info = void 0;
|
|
150
155
|
this.emit("update-downloaded");
|
|
@@ -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,28 +188,20 @@ 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`;
|
|
214
|
-
if (existsSync(tempAsarPath)) {
|
|
199
|
+
if (fs2.existsSync(tempAsarPath)) {
|
|
215
200
|
logger?.info(`installing new asar: ${tempAsarPath}`);
|
|
216
|
-
await onInstall(() => renameSync(tempAsarPath, appNameAsarPath), tempAsarPath, appNameAsarPath, logger);
|
|
201
|
+
await onInstall(() => fs2.renameSync(tempAsarPath, appNameAsarPath), tempAsarPath, appNameAsarPath, logger);
|
|
217
202
|
}
|
|
218
|
-
const mainFilePath = join(
|
|
219
|
-
isDev ? join(app.getAppPath(), __EIU_MAIN_DEV_DIR__) : appNameAsarPath,
|
|
203
|
+
const mainFilePath = path.join(
|
|
204
|
+
isDev ? path.join(app.getAppPath(), __EIU_MAIN_DEV_DIR__) : appNameAsarPath,
|
|
220
205
|
"main",
|
|
221
206
|
__EIU_MAIN_FILE__
|
|
222
207
|
);
|
|
@@ -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
|
@@ -5,6 +5,11 @@ var electron = require('electron');
|
|
|
5
5
|
var crypto = require('crypto');
|
|
6
6
|
var zlib = require('zlib');
|
|
7
7
|
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
11
|
+
var zlib__default = /*#__PURE__*/_interopDefault(zlib);
|
|
12
|
+
|
|
8
13
|
// src/provider/github.ts
|
|
9
14
|
|
|
10
15
|
// src/utils/version.ts
|
|
@@ -68,8 +73,7 @@ function getHeader(response, headerKey) {
|
|
|
68
73
|
async function downloadFn(url, headers, onResponse) {
|
|
69
74
|
await electron.app.whenReady();
|
|
70
75
|
return new Promise((resolve, reject) => {
|
|
71
|
-
const request = electron.net.request({ url, method: "GET", redirect: "follow" });
|
|
72
|
-
Object.keys(headers).forEach((key) => request.setHeader(key, headers[key]));
|
|
76
|
+
const request = electron.net.request({ url, method: "GET", redirect: "follow", headers });
|
|
73
77
|
request.on("response", (resp) => {
|
|
74
78
|
resp.on("aborted", () => reject(new Error("aborted")));
|
|
75
79
|
resp.on("error", () => reject(new Error("download error")));
|
|
@@ -121,11 +125,11 @@ async function defaultDownloadAsar(url, headers, onDownloading) {
|
|
|
121
125
|
});
|
|
122
126
|
}
|
|
123
127
|
function hashBuffer(data, length) {
|
|
124
|
-
const hash =
|
|
128
|
+
const hash = crypto__default.default.createHash("SHA256").update(data).digest("binary");
|
|
125
129
|
return Buffer.from(hash).subarray(0, length);
|
|
126
130
|
}
|
|
127
131
|
function aesDecrypt(encryptedText, key, iv) {
|
|
128
|
-
const decipher =
|
|
132
|
+
const decipher = crypto__default.default.createDecipheriv("aes-256-cbc", key, iv);
|
|
129
133
|
return decipher.update(encryptedText, "base64url", "utf8") + decipher.final("utf8");
|
|
130
134
|
}
|
|
131
135
|
function defaultVerifySignature(buffer, version, signature, cert) {
|
|
@@ -134,14 +138,14 @@ function defaultVerifySignature(buffer, version, signature, cert) {
|
|
|
134
138
|
if (ver !== version) {
|
|
135
139
|
return false;
|
|
136
140
|
}
|
|
137
|
-
return
|
|
141
|
+
return crypto__default.default.createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
|
|
138
142
|
} catch {
|
|
139
143
|
return false;
|
|
140
144
|
}
|
|
141
145
|
}
|
|
142
146
|
async function defaultUnzipFile(buffer) {
|
|
143
147
|
return new Promise((resolve, reject) => {
|
|
144
|
-
|
|
148
|
+
zlib__default.default.brotliDecompress(buffer, (err, buffer2) => {
|
|
145
149
|
if (err) {
|
|
146
150
|
reject(err);
|
|
147
151
|
} else {
|
|
@@ -154,8 +158,17 @@ async function defaultUnzipFile(buffer) {
|
|
|
154
158
|
// src/provider/base.ts
|
|
155
159
|
var BaseProvider = class {
|
|
156
160
|
name = "BaseProvider";
|
|
161
|
+
/**
|
|
162
|
+
* @inheritdoc
|
|
163
|
+
*/
|
|
157
164
|
isLowerVersion = defaultIsLowerVersion;
|
|
165
|
+
/**
|
|
166
|
+
* @inheritdoc
|
|
167
|
+
*/
|
|
158
168
|
verifySignaure = defaultVerifySignature;
|
|
169
|
+
/**
|
|
170
|
+
* @inheritdoc
|
|
171
|
+
*/
|
|
159
172
|
unzipFile = defaultUnzipFile;
|
|
160
173
|
};
|
|
161
174
|
|
|
@@ -174,6 +187,9 @@ var GitHubProvider = class extends BaseProvider {
|
|
|
174
187
|
constructor(options) {
|
|
175
188
|
super();
|
|
176
189
|
this.options = options;
|
|
190
|
+
if (!options.branch) {
|
|
191
|
+
this.options.branch = "HEAD";
|
|
192
|
+
}
|
|
177
193
|
}
|
|
178
194
|
get urlHandler() {
|
|
179
195
|
return this.options.urlHandler;
|
|
@@ -190,14 +206,14 @@ var GitHubProvider = class extends BaseProvider {
|
|
|
190
206
|
}
|
|
191
207
|
async downloadJSON(versionPath) {
|
|
192
208
|
return await defaultDownloadUpdateJSON(
|
|
193
|
-
await this.parseURL(false, `${this.options.branch
|
|
194
|
-
{
|
|
209
|
+
await this.parseURL(false, `${this.options.branch}/${versionPath}`),
|
|
210
|
+
{ Accept: "application/json", ...this.options.extraHeaders }
|
|
195
211
|
);
|
|
196
212
|
}
|
|
197
213
|
async downloadAsar(name, info, onDownloading) {
|
|
198
214
|
return await defaultDownloadAsar(
|
|
199
215
|
await this.parseURL(true, `releases/download/v${info.version}/${name}-${info.version}.asar.gz`),
|
|
200
|
-
{
|
|
216
|
+
{ Accept: "application/octet-stream", ...this.options.extraHeaders },
|
|
201
217
|
onDownloading
|
|
202
218
|
);
|
|
203
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
|
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,13 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as defaultIsLowerVersion, U as UpdateJSON, a as UpdateInfo } from './version-DgfjJQUx.js';
|
|
2
|
+
import { I as IProvider, D as DownloadingInfo, U as URLHandler, O as OnDownloading } from './types-D7OK98ln.js';
|
|
2
3
|
import { f as defaultVerifySignature, a as defaultUnzipFile } from './zip-DPF5IFkK.js';
|
|
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
|
|
package/dist/provider.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defaultVerifySignature, defaultUnzipFile } from './chunk-
|
|
1
|
+
import { defaultVerifySignature, defaultUnzipFile } from './chunk-KZSYEXLO.js';
|
|
2
2
|
import { defaultIsLowerVersion, isUpdateJSON } from './chunk-72ZAJ7AF.js';
|
|
3
3
|
import { URL } from 'node:url';
|
|
4
4
|
import { app, net } from 'electron';
|
|
@@ -14,8 +14,7 @@ function getHeader(response, headerKey) {
|
|
|
14
14
|
async function downloadFn(url, headers, onResponse) {
|
|
15
15
|
await app.whenReady();
|
|
16
16
|
return new Promise((resolve, reject) => {
|
|
17
|
-
const request = net.request({ url, method: "GET", redirect: "follow" });
|
|
18
|
-
Object.keys(headers).forEach((key) => request.setHeader(key, headers[key]));
|
|
17
|
+
const request = net.request({ url, method: "GET", redirect: "follow", headers });
|
|
19
18
|
request.on("response", (resp) => {
|
|
20
19
|
resp.on("aborted", () => reject(new Error("aborted")));
|
|
21
20
|
resp.on("error", () => reject(new Error("download error")));
|
|
@@ -70,8 +69,17 @@ async function defaultDownloadAsar(url, headers, onDownloading) {
|
|
|
70
69
|
// src/provider/base.ts
|
|
71
70
|
var BaseProvider = class {
|
|
72
71
|
name = "BaseProvider";
|
|
72
|
+
/**
|
|
73
|
+
* @inheritdoc
|
|
74
|
+
*/
|
|
73
75
|
isLowerVersion = defaultIsLowerVersion;
|
|
76
|
+
/**
|
|
77
|
+
* @inheritdoc
|
|
78
|
+
*/
|
|
74
79
|
verifySignaure = defaultVerifySignature;
|
|
80
|
+
/**
|
|
81
|
+
* @inheritdoc
|
|
82
|
+
*/
|
|
75
83
|
unzipFile = defaultUnzipFile;
|
|
76
84
|
};
|
|
77
85
|
|
|
@@ -90,6 +98,9 @@ var GitHubProvider = class extends BaseProvider {
|
|
|
90
98
|
constructor(options) {
|
|
91
99
|
super();
|
|
92
100
|
this.options = options;
|
|
101
|
+
if (!options.branch) {
|
|
102
|
+
this.options.branch = "HEAD";
|
|
103
|
+
}
|
|
93
104
|
}
|
|
94
105
|
get urlHandler() {
|
|
95
106
|
return this.options.urlHandler;
|
|
@@ -106,14 +117,14 @@ var GitHubProvider = class extends BaseProvider {
|
|
|
106
117
|
}
|
|
107
118
|
async downloadJSON(versionPath) {
|
|
108
119
|
return await defaultDownloadUpdateJSON(
|
|
109
|
-
await this.parseURL(false, `${this.options.branch
|
|
110
|
-
{
|
|
120
|
+
await this.parseURL(false, `${this.options.branch}/${versionPath}`),
|
|
121
|
+
{ Accept: "application/json", ...this.options.extraHeaders }
|
|
111
122
|
);
|
|
112
123
|
}
|
|
113
124
|
async downloadAsar(name, info, onDownloading) {
|
|
114
125
|
return await defaultDownloadAsar(
|
|
115
126
|
await this.parseURL(true, `releases/download/v${info.version}/${name}-${info.version}.asar.gz`),
|
|
116
|
-
{
|
|
127
|
+
{ Accept: "application/octet-stream", ...this.options.extraHeaders },
|
|
117
128
|
onDownloading
|
|
118
129
|
);
|
|
119
130
|
}
|
|
@@ -1,30 +1,5 @@
|
|
|
1
1
|
import { Promisable } from '@subframe7536/type-utils';
|
|
2
|
-
|
|
3
|
-
interface Version {
|
|
4
|
-
major: number;
|
|
5
|
-
minor: number;
|
|
6
|
-
patch: number;
|
|
7
|
-
stage: string;
|
|
8
|
-
stageVersion: number;
|
|
9
|
-
}
|
|
10
|
-
declare function parseVersion(version: string): Version;
|
|
11
|
-
declare function defaultIsLowerVersion(oldVer: string, newVer: string): boolean;
|
|
12
|
-
/**
|
|
13
|
-
* update info json
|
|
14
|
-
*/
|
|
15
|
-
type UpdateInfo = {
|
|
16
|
-
signature: string;
|
|
17
|
-
minimumVersion: string;
|
|
18
|
-
version: string;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* {@link UpdateInfo} with beta
|
|
22
|
-
*/
|
|
23
|
-
type UpdateJSON = UpdateInfo & {
|
|
24
|
-
beta: UpdateInfo;
|
|
25
|
-
};
|
|
26
|
-
declare function isUpdateJSON(json: any): json is UpdateJSON;
|
|
27
|
-
declare function defaultVersionJsonGenerator(existingJson: UpdateJSON, signature: string, version: string, minimumVersion: string): UpdateJSON;
|
|
2
|
+
import { U as UpdateJSON, a as UpdateInfo } from './version-DgfjJQUx.js';
|
|
28
3
|
|
|
29
4
|
type URLHandler = (url: URL, isDownloadAsar: boolean) => Promisable<URL | string | undefined | null>;
|
|
30
5
|
type OnDownloading = (progress: DownloadingInfo) => void;
|
|
@@ -68,7 +43,7 @@ interface IProvider {
|
|
|
68
43
|
onDownloading?: OnDownloading;
|
|
69
44
|
/**
|
|
70
45
|
* download update json
|
|
71
|
-
* @param versionPath parsed version path
|
|
46
|
+
* @param versionPath parsed version path in project
|
|
72
47
|
*/
|
|
73
48
|
downloadJSON: (versionPath: string) => Promise<UpdateJSON>;
|
|
74
49
|
/**
|
|
@@ -101,4 +76,4 @@ interface IProvider {
|
|
|
101
76
|
verifySignaure: (buffer: Buffer, version: string, signature: string, cert: string) => Promisable<boolean>;
|
|
102
77
|
}
|
|
103
78
|
|
|
104
|
-
export {
|
|
79
|
+
export type { DownloadingInfo as D, IProvider as I, OnDownloading as O, URLHandler as U };
|
|
@@ -1,30 +1,5 @@
|
|
|
1
1
|
import { Promisable } from '@subframe7536/type-utils';
|
|
2
|
-
|
|
3
|
-
interface Version {
|
|
4
|
-
major: number;
|
|
5
|
-
minor: number;
|
|
6
|
-
patch: number;
|
|
7
|
-
stage: string;
|
|
8
|
-
stageVersion: number;
|
|
9
|
-
}
|
|
10
|
-
declare function parseVersion(version: string): Version;
|
|
11
|
-
declare function defaultIsLowerVersion(oldVer: string, newVer: string): boolean;
|
|
12
|
-
/**
|
|
13
|
-
* update info json
|
|
14
|
-
*/
|
|
15
|
-
type UpdateInfo = {
|
|
16
|
-
signature: string;
|
|
17
|
-
minimumVersion: string;
|
|
18
|
-
version: string;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* {@link UpdateInfo} with beta
|
|
22
|
-
*/
|
|
23
|
-
type UpdateJSON = UpdateInfo & {
|
|
24
|
-
beta: UpdateInfo;
|
|
25
|
-
};
|
|
26
|
-
declare function isUpdateJSON(json: any): json is UpdateJSON;
|
|
27
|
-
declare function defaultVersionJsonGenerator(existingJson: UpdateJSON, signature: string, version: string, minimumVersion: string): UpdateJSON;
|
|
2
|
+
import { U as UpdateJSON, a as UpdateInfo } from './version-DgfjJQUx.cjs';
|
|
28
3
|
|
|
29
4
|
type URLHandler = (url: URL, isDownloadAsar: boolean) => Promisable<URL | string | undefined | null>;
|
|
30
5
|
type OnDownloading = (progress: DownloadingInfo) => void;
|
|
@@ -68,7 +43,7 @@ interface IProvider {
|
|
|
68
43
|
onDownloading?: OnDownloading;
|
|
69
44
|
/**
|
|
70
45
|
* download update json
|
|
71
|
-
* @param versionPath parsed version path
|
|
46
|
+
* @param versionPath parsed version path in project
|
|
72
47
|
*/
|
|
73
48
|
downloadJSON: (versionPath: string) => Promise<UpdateJSON>;
|
|
74
49
|
/**
|
|
@@ -101,4 +76,4 @@ interface IProvider {
|
|
|
101
76
|
verifySignaure: (buffer: Buffer, version: string, signature: string, cert: string) => Promisable<boolean>;
|
|
102
77
|
}
|
|
103
78
|
|
|
104
|
-
export {
|
|
79
|
+
export type { DownloadingInfo as D, IProvider as I, OnDownloading as O, URLHandler as U };
|
package/dist/utils.cjs
CHANGED
|
@@ -6,6 +6,13 @@ var electron = require('electron');
|
|
|
6
6
|
var zlib = require('zlib');
|
|
7
7
|
var crypto = require('crypto');
|
|
8
8
|
|
|
9
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
12
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
13
|
+
var zlib__default = /*#__PURE__*/_interopDefault(zlib);
|
|
14
|
+
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
15
|
+
|
|
9
16
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
10
17
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
11
18
|
}) : x)(function(x) {
|
|
@@ -16,17 +23,17 @@ var isDev = __EIU_IS_DEV__;
|
|
|
16
23
|
var isWin = process.platform === "win32";
|
|
17
24
|
var isMac = process.platform === "darwin";
|
|
18
25
|
var isLinux = process.platform === "linux";
|
|
19
|
-
function getPathFromAppNameAsar(...
|
|
20
|
-
return isDev ? "DEV.asar" :
|
|
26
|
+
function getPathFromAppNameAsar(...paths) {
|
|
27
|
+
return isDev ? "DEV.asar" : path__default.default.join(path__default.default.dirname(electron.app.getAppPath()), `${electron.app.name}.asar`, ...paths);
|
|
21
28
|
}
|
|
22
29
|
function getAppVersion() {
|
|
23
|
-
return isDev ? getEntryVersion() :
|
|
30
|
+
return isDev ? getEntryVersion() : fs__default.default.readFileSync(getPathFromAppNameAsar("version"), "utf-8");
|
|
24
31
|
}
|
|
25
32
|
function getEntryVersion() {
|
|
26
33
|
return electron.app.getVersion();
|
|
27
34
|
}
|
|
28
35
|
function requireNative(moduleName) {
|
|
29
|
-
return __require(
|
|
36
|
+
return __require(path__default.default.join(electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, moduleName));
|
|
30
37
|
}
|
|
31
38
|
function restartApp() {
|
|
32
39
|
electron.app.relaunch();
|
|
@@ -60,9 +67,9 @@ function singleInstance(window) {
|
|
|
60
67
|
return result;
|
|
61
68
|
}
|
|
62
69
|
function setPortableAppDataPath(dirName = "data") {
|
|
63
|
-
const portablePath =
|
|
64
|
-
if (!
|
|
65
|
-
|
|
70
|
+
const portablePath = path__default.default.join(path__default.default.dirname(electron.app.getPath("exe")), dirName);
|
|
71
|
+
if (!fs__default.default.existsSync(portablePath)) {
|
|
72
|
+
fs__default.default.mkdirSync(portablePath);
|
|
66
73
|
}
|
|
67
74
|
electron.app.setPath("appData", portablePath);
|
|
68
75
|
}
|
|
@@ -74,13 +81,13 @@ function loadPage(win, htmlFilePath = "index.html") {
|
|
|
74
81
|
}
|
|
75
82
|
}
|
|
76
83
|
function getPathFromPreload(...paths) {
|
|
77
|
-
return isDev ?
|
|
84
|
+
return isDev ? path__default.default.join(electron.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
|
|
78
85
|
}
|
|
79
86
|
function getPathFromPublic(...paths) {
|
|
80
|
-
return isDev ?
|
|
87
|
+
return isDev ? path__default.default.join(electron.app.getAppPath(), "public", ...paths) : getPathFromAppNameAsar("renderer", ...paths);
|
|
81
88
|
}
|
|
82
89
|
function getPathFromEntryAsar(...paths) {
|
|
83
|
-
return
|
|
90
|
+
return path__default.default.join(electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
|
|
84
91
|
}
|
|
85
92
|
function handleUnexpectedErrors(callback) {
|
|
86
93
|
process.on("uncaughtException", callback);
|
|
@@ -88,7 +95,7 @@ function handleUnexpectedErrors(callback) {
|
|
|
88
95
|
}
|
|
89
96
|
async function defaultZipFile(buffer) {
|
|
90
97
|
return new Promise((resolve, reject) => {
|
|
91
|
-
|
|
98
|
+
zlib__default.default.brotliCompress(buffer, (err, buffer2) => {
|
|
92
99
|
if (err) {
|
|
93
100
|
reject(err);
|
|
94
101
|
} else {
|
|
@@ -99,7 +106,7 @@ async function defaultZipFile(buffer) {
|
|
|
99
106
|
}
|
|
100
107
|
async function defaultUnzipFile(buffer) {
|
|
101
108
|
return new Promise((resolve, reject) => {
|
|
102
|
-
|
|
109
|
+
zlib__default.default.brotliDecompress(buffer, (err, buffer2) => {
|
|
103
110
|
if (err) {
|
|
104
111
|
reject(err);
|
|
105
112
|
} else {
|
|
@@ -171,19 +178,19 @@ function defaultVersionJsonGenerator(existingJson, signature, version, minimumVe
|
|
|
171
178
|
return existingJson;
|
|
172
179
|
}
|
|
173
180
|
function hashBuffer(data, length) {
|
|
174
|
-
const hash =
|
|
181
|
+
const hash = crypto__default.default.createHash("SHA256").update(data).digest("binary");
|
|
175
182
|
return Buffer.from(hash).subarray(0, length);
|
|
176
183
|
}
|
|
177
184
|
function aesEncrypt(plainText, key, iv) {
|
|
178
|
-
const cipher =
|
|
185
|
+
const cipher = crypto__default.default.createCipheriv("aes-256-cbc", key, iv);
|
|
179
186
|
return cipher.update(plainText, "utf8", "base64url") + cipher.final("base64url");
|
|
180
187
|
}
|
|
181
188
|
function defaultSignature(buffer, privateKey, cert, version) {
|
|
182
|
-
const sig =
|
|
189
|
+
const sig = crypto__default.default.createSign("RSA-SHA256").update(buffer).sign(crypto__default.default.createPrivateKey(privateKey), "base64");
|
|
183
190
|
return aesEncrypt(`${sig}%${version}`, hashBuffer(cert, 32), hashBuffer(buffer, 16));
|
|
184
191
|
}
|
|
185
192
|
function aesDecrypt(encryptedText, key, iv) {
|
|
186
|
-
const decipher =
|
|
193
|
+
const decipher = crypto__default.default.createDecipheriv("aes-256-cbc", key, iv);
|
|
187
194
|
return decipher.update(encryptedText, "base64url", "utf8") + decipher.final("utf8");
|
|
188
195
|
}
|
|
189
196
|
function defaultVerifySignature(buffer, version, signature, cert) {
|
|
@@ -192,22 +199,14 @@ function defaultVerifySignature(buffer, version, signature, cert) {
|
|
|
192
199
|
if (ver !== version) {
|
|
193
200
|
return false;
|
|
194
201
|
}
|
|
195
|
-
return
|
|
202
|
+
return crypto__default.default.createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
|
|
196
203
|
} catch {
|
|
197
204
|
return false;
|
|
198
205
|
}
|
|
199
206
|
}
|
|
200
207
|
|
|
201
|
-
// src/utils/updater.ts
|
|
202
|
-
async function autoUpdate(updater) {
|
|
203
|
-
if (await updater.checkUpdate() && await updater.downloadUpdate()) {
|
|
204
|
-
updater.quitAndInstall();
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
208
|
exports.aesDecrypt = aesDecrypt;
|
|
209
209
|
exports.aesEncrypt = aesEncrypt;
|
|
210
|
-
exports.autoUpdate = autoUpdate;
|
|
211
210
|
exports.defaultIsLowerVersion = defaultIsLowerVersion;
|
|
212
211
|
exports.defaultSignature = defaultSignature;
|
|
213
212
|
exports.defaultUnzipFile = defaultUnzipFile;
|
package/dist/utils.d.cts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { BrowserWindow } from 'electron';
|
|
2
2
|
export { e as aesDecrypt, b as aesEncrypt, c as defaultSignature, a as defaultUnzipFile, f as defaultVerifySignature, d as defaultZipFile, h as hashBuffer } from './zip-DPF5IFkK.cjs';
|
|
3
|
-
export {
|
|
4
|
-
import { U as Updater } from './core-ZUlLHadf.cjs';
|
|
5
|
-
import '@subframe7536/type-utils';
|
|
6
|
-
import 'node:events';
|
|
3
|
+
export { a as UpdateInfo, U as UpdateJSON, V as Version, d as defaultIsLowerVersion, b as defaultVersionJsonGenerator, i as isUpdateJSON, p as parseVersion } from './version-DgfjJQUx.cjs';
|
|
7
4
|
|
|
8
5
|
/**
|
|
9
6
|
* compile time dev check
|
|
@@ -17,7 +14,7 @@ declare const isLinux: boolean;
|
|
|
17
14
|
*
|
|
18
15
|
* if is in dev, **always** return `'DEV.asar'`
|
|
19
16
|
*/
|
|
20
|
-
declare function getPathFromAppNameAsar(...
|
|
17
|
+
declare function getPathFromAppNameAsar(...paths: string[]): string;
|
|
21
18
|
/**
|
|
22
19
|
* get app version, if is in dev, return `getEntryVersion()`
|
|
23
20
|
*/
|
|
@@ -72,9 +69,4 @@ declare function getPathFromEntryAsar(...paths: string[]): string;
|
|
|
72
69
|
*/
|
|
73
70
|
declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
|
|
74
71
|
|
|
75
|
-
|
|
76
|
-
* auto check update, download and install
|
|
77
|
-
*/
|
|
78
|
-
declare function autoUpdate(updater: Updater): Promise<void>;
|
|
79
|
-
|
|
80
|
-
export { autoUpdate, disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
|
|
72
|
+
export { disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
|