electron-incremental-update 2.0.0-beta.1 → 2.0.0-beta.2
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 +3 -3
- package/dist/{chunk-RSLOPAIZ.js → chunk-BG22XZAB.js} +23 -13
- package/dist/{decrypt-BNBcodiO.d.cts → decrypt-D9WdXYjH.d.cts} +1 -1
- package/dist/{decrypt-BNBcodiO.d.ts → decrypt-D9WdXYjH.d.ts} +1 -1
- package/dist/index.cjs +88 -74
- package/dist/index.d.cts +22 -30
- package/dist/index.d.ts +22 -30
- package/dist/index.js +88 -74
- package/dist/provider.cjs +15 -6
- package/dist/provider.d.cts +3 -3
- package/dist/provider.d.ts +3 -3
- package/dist/provider.js +15 -6
- package/dist/{types-DxPmQmaq.d.cts → types-COqp44eg.d.cts} +13 -5
- package/dist/{types-seJf3Wbc.d.ts → types-CPq1MrYZ.d.ts} +13 -5
- package/dist/utils.cjs +23 -13
- package/dist/utils.d.cts +3 -3
- package/dist/utils.d.ts +3 -3
- package/dist/utils.js +1 -1
- package/dist/vite.js +31 -19
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
isUpdateJSON,
|
|
8
8
|
restartApp,
|
|
9
9
|
unzipFile
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-BG22XZAB.js";
|
|
11
11
|
|
|
12
12
|
// src/entry.ts
|
|
13
13
|
import { join } from "node:path";
|
|
@@ -16,23 +16,25 @@ import { app as app2 } from "electron";
|
|
|
16
16
|
|
|
17
17
|
// src/updater/core.ts
|
|
18
18
|
import { existsSync, rmSync, writeFileSync } from "node:fs";
|
|
19
|
+
import { EventEmitter } from "node:stream";
|
|
19
20
|
import { app } from "electron";
|
|
20
21
|
|
|
21
22
|
// src/updater/types.ts
|
|
22
23
|
var ErrorInfo = {
|
|
23
24
|
download: "Download failed",
|
|
24
25
|
validate: "Validate failed",
|
|
25
|
-
param: "Missing params"
|
|
26
|
-
version: "Unsatisfied version"
|
|
26
|
+
param: "Missing params"
|
|
27
27
|
};
|
|
28
28
|
var UpdaterError = class extends Error {
|
|
29
|
+
code;
|
|
29
30
|
constructor(msg, info) {
|
|
30
|
-
super(msg + ": " + info);
|
|
31
|
+
super(ErrorInfo[msg] + ": " + info);
|
|
32
|
+
this.code = msg;
|
|
31
33
|
}
|
|
32
34
|
};
|
|
33
35
|
|
|
34
36
|
// src/updater/core.ts
|
|
35
|
-
var Updater = class {
|
|
37
|
+
var Updater = class extends EventEmitter {
|
|
36
38
|
CERT = __EIU_SIGNATURE_CERT__;
|
|
37
39
|
info;
|
|
38
40
|
options;
|
|
@@ -44,19 +46,10 @@ var Updater = class {
|
|
|
44
46
|
* updater logger
|
|
45
47
|
*/
|
|
46
48
|
logger;
|
|
47
|
-
/**
|
|
48
|
-
* downloading progress hook
|
|
49
|
-
* @param progress download progress
|
|
50
|
-
* @example
|
|
51
|
-
* updater.onDownloading = ({ percent, total, current }) => {
|
|
52
|
-
* console.log(`download progress: ${percent}, total: ${total}, current: ${current}`)
|
|
53
|
-
* }
|
|
54
|
-
*/
|
|
55
|
-
onDownloading;
|
|
56
49
|
/**
|
|
57
50
|
* URL handler hook
|
|
58
51
|
*
|
|
59
|
-
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public
|
|
52
|
+
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public CDNs}
|
|
60
53
|
* @param url source url
|
|
61
54
|
* @param isDownloadAsar whether is download asar
|
|
62
55
|
*/
|
|
@@ -76,6 +69,7 @@ var Updater = class {
|
|
|
76
69
|
* @param option UpdaterOption
|
|
77
70
|
*/
|
|
78
71
|
constructor(provider, option = {}) {
|
|
72
|
+
super();
|
|
79
73
|
this.provider = provider;
|
|
80
74
|
this.options = option;
|
|
81
75
|
if (option.SIGNATURE_CERT) {
|
|
@@ -84,25 +78,20 @@ var Updater = class {
|
|
|
84
78
|
if (option.logger) {
|
|
85
79
|
this.logger = option.logger;
|
|
86
80
|
}
|
|
81
|
+
if (isDev && !this.logger) {
|
|
82
|
+
this.logger = {
|
|
83
|
+
info: (...args) => console.log("[EIU-INFO ]", ...args),
|
|
84
|
+
debug: (...args) => console.log("[EIU-DEBUG]", ...args),
|
|
85
|
+
warn: (...args) => console.log("[EIU-WARN ]", ...args),
|
|
86
|
+
error: (...args) => console.error("[EIU-ERROR]", ...args)
|
|
87
|
+
};
|
|
88
|
+
this.logger.info("no logger set, enable dev-only logger");
|
|
89
|
+
}
|
|
87
90
|
this.asarPath = getPathFromAppNameAsar();
|
|
88
91
|
this.gzipPath = `${this.asarPath}.gz`;
|
|
89
92
|
this.tmpFilePath = `${this.asarPath}.tmp`;
|
|
90
93
|
}
|
|
91
|
-
async
|
|
92
|
-
if (isDev) {
|
|
93
|
-
this.logger?.warn(`in dev mode, skip check update`);
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
const isLowerVersion = this.provider.isLowerVersion;
|
|
97
|
-
const entryVersion = getEntryVersion();
|
|
98
|
-
const appVersion = getAppVersion();
|
|
99
|
-
if (await isLowerVersion(entryVersion, minVersion)) {
|
|
100
|
-
throw new UpdaterError(ErrorInfo.version, `entry version (${entryVersion}) < minimumVersion (${minVersion})`);
|
|
101
|
-
}
|
|
102
|
-
this.logger?.info(`check update: current version is ${appVersion}, new version is ${version}`);
|
|
103
|
-
return await isLowerVersion(appVersion, version);
|
|
104
|
-
}
|
|
105
|
-
async parseData(format, data) {
|
|
94
|
+
async fetch(format, data) {
|
|
106
95
|
if (existsSync(this.tmpFilePath)) {
|
|
107
96
|
this.logger?.warn(`remove tmp file: ${this.tmpFilePath}`);
|
|
108
97
|
rmSync(this.tmpFilePath);
|
|
@@ -115,71 +104,96 @@ var Updater = class {
|
|
|
115
104
|
if (format === "json" && isUpdateJSON(data) || format === "buffer" && Buffer.isBuffer(data)) {
|
|
116
105
|
return data;
|
|
117
106
|
} else {
|
|
118
|
-
|
|
107
|
+
this.err("invalid type", "param", `invalid type at format '${format}': ${JSON.stringify(data)}`);
|
|
108
|
+
return;
|
|
119
109
|
}
|
|
120
110
|
}
|
|
121
111
|
this.logger?.debug(`download from ${this.provider.name}`);
|
|
122
112
|
try {
|
|
123
|
-
const result = format === "json" ? await this.provider.downloadJSON(data ?? __EIU_VERSION_PATH__) : await this.provider.
|
|
113
|
+
const result = format === "json" ? await this.provider.downloadJSON(data ?? __EIU_VERSION_PATH__) : await this.provider.downloadAsar(app.name, this.info, (data2) => this.emit("download-progress", data2));
|
|
124
114
|
this.logger?.debug(`download ${format} success${format === "buffer" ? `, file size: ${result.length}` : ""}`);
|
|
125
115
|
return result;
|
|
126
116
|
} catch (e) {
|
|
127
|
-
this.
|
|
128
|
-
throw new UpdaterError(ErrorInfo.download, `download ${format} failed: ${e}`);
|
|
117
|
+
this.err(`download ${format} failed`, "download", `download ${format} failed: ${e}`);
|
|
129
118
|
}
|
|
130
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* handle error message and emit error event
|
|
122
|
+
*/
|
|
123
|
+
err(msg, code, errorInfo) {
|
|
124
|
+
const err = new UpdaterError(code, errorInfo);
|
|
125
|
+
this.logger?.error(msg, err);
|
|
126
|
+
this.emit("error", err);
|
|
127
|
+
}
|
|
131
128
|
async checkUpdate(data) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
this.logger?.debug(`checked update, version: ${version}, size: ${size}, signature: ${signature}`);
|
|
141
|
-
if (!await this.needUpdate(version, minimumVersion)) {
|
|
142
|
-
this.logger?.info(`update unavailable: ${version} is the latest version`);
|
|
143
|
-
return { success: false, data: version };
|
|
144
|
-
} else {
|
|
145
|
-
this.logger?.info(`update available: ${version}`);
|
|
146
|
-
this.info = { signature, minimumVersion, version, size };
|
|
147
|
-
return { success: true, data: this.info };
|
|
148
|
-
}
|
|
149
|
-
} catch (error) {
|
|
150
|
-
this.logger?.error("check update failed", error);
|
|
151
|
-
return {
|
|
152
|
-
success: false,
|
|
153
|
-
data: error instanceof UpdaterError ? error : new UpdaterError(ErrorInfo.download, error.toString())
|
|
154
|
-
};
|
|
129
|
+
const emitUnavailable = (msg) => {
|
|
130
|
+
this.logger?.info(msg);
|
|
131
|
+
this.emit("update-unavailable", msg);
|
|
132
|
+
};
|
|
133
|
+
const _data = await this.fetch("json", data);
|
|
134
|
+
if (!_data) {
|
|
135
|
+
emitUnavailable("failed to get update info");
|
|
136
|
+
return false;
|
|
155
137
|
}
|
|
138
|
+
let { signature, size, version, minimumVersion, beta } = _data;
|
|
139
|
+
if (this.receiveBeta) {
|
|
140
|
+
version = beta.version;
|
|
141
|
+
signature = beta.signature;
|
|
142
|
+
minimumVersion = beta.minimumVersion;
|
|
143
|
+
size = beta.size;
|
|
144
|
+
}
|
|
145
|
+
this.logger?.debug(`checked update, version: ${version}, size: ${size}, signature: ${signature}`);
|
|
146
|
+
if (isDev) {
|
|
147
|
+
emitUnavailable("in dev mode, skip check update");
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
const isLowerVersion = this.provider.isLowerVersion;
|
|
151
|
+
const entryVersion = getEntryVersion();
|
|
152
|
+
const appVersion = getAppVersion();
|
|
153
|
+
if (isLowerVersion(entryVersion, minimumVersion)) {
|
|
154
|
+
emitUnavailable(`entry version (${entryVersion}) < minimumVersion (${minimumVersion})`);
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
this.logger?.info(`check update: current version is ${appVersion}, new version is ${version}`);
|
|
158
|
+
if (!isLowerVersion(appVersion, version)) {
|
|
159
|
+
emitUnavailable(`current version (${appVersion}) < new version (${version})`);
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
this.logger?.info(`update available: ${version}`);
|
|
163
|
+
this.info = { signature, minimumVersion, version, size };
|
|
164
|
+
this.emit("update-available", this.info);
|
|
165
|
+
return true;
|
|
156
166
|
}
|
|
157
167
|
async download(data, sig) {
|
|
168
|
+
if (!this.info) {
|
|
169
|
+
this.err("download failed", "param", "no update info, call `checkUpdate` first");
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
const _sig = sig ?? this.info.signature;
|
|
173
|
+
const buffer = await this.fetch("buffer", data ? Buffer.from(data) : void 0);
|
|
174
|
+
if (!buffer) {
|
|
175
|
+
this.err("download failed", "param", "no update asar file buffer");
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
this.logger?.debug("verify start");
|
|
179
|
+
const _ver = await this.provider.verifySignaure(buffer, _sig, this.CERT);
|
|
180
|
+
if (!_ver) {
|
|
181
|
+
this.err("verify failed", "validate", "invalid signature / certificate pair");
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
this.logger?.debug("verify success");
|
|
158
185
|
try {
|
|
159
|
-
if (!this.info) {
|
|
160
|
-
throw new UpdaterError(ErrorInfo.param, "no update info");
|
|
161
|
-
}
|
|
162
|
-
const _sig = sig ?? this.info.signature;
|
|
163
|
-
const buffer = await this.parseData("buffer", data);
|
|
164
|
-
this.logger?.debug("verify start");
|
|
165
|
-
const _ver = await this.provider.verifySignaure(buffer, _sig, this.CERT);
|
|
166
|
-
if (!_ver) {
|
|
167
|
-
throw new UpdaterError(ErrorInfo.validate, "invalid signature or certificate");
|
|
168
|
-
}
|
|
169
|
-
this.logger?.debug("verify success");
|
|
170
186
|
this.logger?.debug(`write to ${this.gzipPath}`);
|
|
171
187
|
writeFileSync(this.gzipPath, buffer);
|
|
172
188
|
this.logger?.debug(`extract to ${this.tmpFilePath}`);
|
|
173
189
|
await unzipFile(this.gzipPath, this.tmpFilePath);
|
|
174
190
|
this.logger?.info(`download success, version: ${_ver}`);
|
|
175
191
|
this.info = void 0;
|
|
176
|
-
|
|
192
|
+
this.emit("update-downloaded");
|
|
193
|
+
return true;
|
|
177
194
|
} catch (error) {
|
|
178
|
-
this.
|
|
179
|
-
return
|
|
180
|
-
success: false,
|
|
181
|
-
data: error instanceof UpdaterError ? error : new UpdaterError(ErrorInfo.download, error.toString())
|
|
182
|
-
};
|
|
195
|
+
this.err("unwrap asar failed", "download", `fail to unwrap asar file, ${error}`);
|
|
196
|
+
return false;
|
|
183
197
|
}
|
|
184
198
|
}
|
|
185
199
|
/**
|
package/dist/provider.cjs
CHANGED
|
@@ -125,7 +125,7 @@ function verifySignatureDefault(buffer, signature, cert) {
|
|
|
125
125
|
const [sig, version] = decrypt(signature, hashString(cert, 32), hashString(buffer, 16)).split("%");
|
|
126
126
|
const result = (0, import_node_crypto2.createVerify)("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
|
|
127
127
|
return result ? version : void 0;
|
|
128
|
-
} catch
|
|
128
|
+
} catch {
|
|
129
129
|
return void 0;
|
|
130
130
|
}
|
|
131
131
|
}
|
|
@@ -161,19 +161,28 @@ async function downloadUpdateJSONDefault(url, headers) {
|
|
|
161
161
|
} else {
|
|
162
162
|
throw Error;
|
|
163
163
|
}
|
|
164
|
-
} catch
|
|
164
|
+
} catch {
|
|
165
165
|
reject(new Error("invalid update json"));
|
|
166
166
|
}
|
|
167
167
|
});
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
170
|
async function downloadAsarBufferDefault(url, headers, total, onDownloading) {
|
|
171
|
-
let
|
|
171
|
+
let transferred = 0;
|
|
172
|
+
let time = Date.now();
|
|
172
173
|
return await downlaodFn(url, headers, (resp, resolve) => {
|
|
173
174
|
let data = [];
|
|
174
175
|
resp.on("data", (chunk) => {
|
|
175
|
-
|
|
176
|
-
|
|
176
|
+
transferred += chunk.length;
|
|
177
|
+
const current = Date.now();
|
|
178
|
+
onDownloading?.({
|
|
179
|
+
percent: +(transferred / total).toFixed(2) * 100,
|
|
180
|
+
total,
|
|
181
|
+
transferred,
|
|
182
|
+
delta: chunk.length,
|
|
183
|
+
bps: chunk.length / ((current - time) * 1e3)
|
|
184
|
+
});
|
|
185
|
+
time = current;
|
|
177
186
|
data.push(chunk);
|
|
178
187
|
});
|
|
179
188
|
resp.on("end", () => resolve(Buffer.concat(data)));
|
|
@@ -210,7 +219,7 @@ var GitHubProvider = class {
|
|
|
210
219
|
{ userAgent: this.ua, accept: "application/json", ...this.extraHeaders }
|
|
211
220
|
);
|
|
212
221
|
}
|
|
213
|
-
async
|
|
222
|
+
async downloadAsar(name, { version, size }, onDownloading) {
|
|
214
223
|
return await downloadAsarBufferDefault(
|
|
215
224
|
this.parseURL(true, `releases/download/v${version}/${name}-${version}.asar.gz`),
|
|
216
225
|
{ userAgent: this.ua, accept: "application/octet-stream", ...this.extraHeaders },
|
package/dist/provider.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as isLowerVersionDefault, U as UpdateJSON, a as UpdateInfo } from './version-CffZWDhZ.cjs';
|
|
2
|
-
import { v as verifySignatureDefault } from './decrypt-
|
|
3
|
-
import { U as URLHandler, I as IProvider, D as DownloadingInfo, O as OnDownloading } from './types-
|
|
2
|
+
import { v as verifySignatureDefault } from './decrypt-D9WdXYjH.cjs';
|
|
3
|
+
import { U as URLHandler, I as IProvider, D as DownloadingInfo, O as OnDownloading } from './types-COqp44eg.cjs';
|
|
4
4
|
import '@subframe7536/type-utils';
|
|
5
5
|
|
|
6
6
|
interface GitHubProviderOptions {
|
|
@@ -28,7 +28,7 @@ declare class GitHubProvider implements IProvider {
|
|
|
28
28
|
isLowerVersion: typeof isLowerVersionDefault;
|
|
29
29
|
verifySignaure: typeof verifySignatureDefault;
|
|
30
30
|
downloadJSON(versionPath: string): Promise<UpdateJSON>;
|
|
31
|
-
|
|
31
|
+
downloadAsar(name: string, { version, size }: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
declare function downloadUpdateJSONDefault(url: string, headers: Record<string, any>): Promise<UpdateJSON>;
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as isLowerVersionDefault, U as UpdateJSON, a as UpdateInfo } from './version-CffZWDhZ.js';
|
|
2
|
-
import { v as verifySignatureDefault } from './decrypt-
|
|
3
|
-
import { U as URLHandler, I as IProvider, D as DownloadingInfo, O as OnDownloading } from './types-
|
|
2
|
+
import { v as verifySignatureDefault } from './decrypt-D9WdXYjH.js';
|
|
3
|
+
import { U as URLHandler, I as IProvider, D as DownloadingInfo, O as OnDownloading } from './types-CPq1MrYZ.js';
|
|
4
4
|
import '@subframe7536/type-utils';
|
|
5
5
|
|
|
6
6
|
interface GitHubProviderOptions {
|
|
@@ -28,7 +28,7 @@ declare class GitHubProvider implements IProvider {
|
|
|
28
28
|
isLowerVersion: typeof isLowerVersionDefault;
|
|
29
29
|
verifySignaure: typeof verifySignatureDefault;
|
|
30
30
|
downloadJSON(versionPath: string): Promise<UpdateJSON>;
|
|
31
|
-
|
|
31
|
+
downloadAsar(name: string, { version, size }: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
declare function downloadUpdateJSONDefault(url: string, headers: Record<string, any>): Promise<UpdateJSON>;
|
package/dist/provider.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
isUpdateJSON,
|
|
4
4
|
verifySignatureDefault,
|
|
5
5
|
waitAppReady
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-BG22XZAB.js";
|
|
7
7
|
|
|
8
8
|
// src/provider/download.ts
|
|
9
9
|
import { net } from "electron";
|
|
@@ -33,19 +33,28 @@ async function downloadUpdateJSONDefault(url, headers) {
|
|
|
33
33
|
} else {
|
|
34
34
|
throw Error;
|
|
35
35
|
}
|
|
36
|
-
} catch
|
|
36
|
+
} catch {
|
|
37
37
|
reject(new Error("invalid update json"));
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
async function downloadAsarBufferDefault(url, headers, total, onDownloading) {
|
|
43
|
-
let
|
|
43
|
+
let transferred = 0;
|
|
44
|
+
let time = Date.now();
|
|
44
45
|
return await downlaodFn(url, headers, (resp, resolve) => {
|
|
45
46
|
let data = [];
|
|
46
47
|
resp.on("data", (chunk) => {
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
transferred += chunk.length;
|
|
49
|
+
const current = Date.now();
|
|
50
|
+
onDownloading?.({
|
|
51
|
+
percent: +(transferred / total).toFixed(2) * 100,
|
|
52
|
+
total,
|
|
53
|
+
transferred,
|
|
54
|
+
delta: chunk.length,
|
|
55
|
+
bps: chunk.length / ((current - time) * 1e3)
|
|
56
|
+
});
|
|
57
|
+
time = current;
|
|
49
58
|
data.push(chunk);
|
|
50
59
|
});
|
|
51
60
|
resp.on("end", () => resolve(Buffer.concat(data)));
|
|
@@ -82,7 +91,7 @@ var GitHubProvider = class {
|
|
|
82
91
|
{ userAgent: this.ua, accept: "application/json", ...this.extraHeaders }
|
|
83
92
|
);
|
|
84
93
|
}
|
|
85
|
-
async
|
|
94
|
+
async downloadAsar(name, { version, size }, onDownloading) {
|
|
86
95
|
return await downloadAsarBufferDefault(
|
|
87
96
|
this.parseURL(true, `releases/download/v${version}/${name}-${version}.asar.gz`),
|
|
88
97
|
{ userAgent: this.ua, accept: "application/octet-stream", ...this.extraHeaders },
|
|
@@ -5,9 +5,13 @@ type URLHandler = (url: string, isDownloadAsar: boolean) => string;
|
|
|
5
5
|
type OnDownloading = (progress: DownloadingInfo) => void;
|
|
6
6
|
interface DownloadingInfo {
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* download delta
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
delta: number;
|
|
11
|
+
/**
|
|
12
|
+
* downloaded percent, 0 ~ 100
|
|
13
|
+
*/
|
|
14
|
+
percent: number;
|
|
11
15
|
/**
|
|
12
16
|
* total size
|
|
13
17
|
*/
|
|
@@ -15,7 +19,11 @@ interface DownloadingInfo {
|
|
|
15
19
|
/**
|
|
16
20
|
* downloaded size
|
|
17
21
|
*/
|
|
18
|
-
|
|
22
|
+
transferred: number;
|
|
23
|
+
/**
|
|
24
|
+
* download speed, bytes per second
|
|
25
|
+
*/
|
|
26
|
+
bps: number;
|
|
19
27
|
}
|
|
20
28
|
interface IProvider {
|
|
21
29
|
/**
|
|
@@ -40,14 +48,14 @@ interface IProvider {
|
|
|
40
48
|
* @param updateInfo existing update info
|
|
41
49
|
* @param onDownloading hook for on downloading
|
|
42
50
|
*/
|
|
43
|
-
|
|
51
|
+
downloadAsar: (name: string, updateInfo: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void) => Promise<Buffer>;
|
|
44
52
|
/**
|
|
45
53
|
* compare version
|
|
46
54
|
* @param oldVer old version string
|
|
47
55
|
* @param newVer new version string
|
|
48
56
|
* @returns if version1 < version2
|
|
49
57
|
*/
|
|
50
|
-
isLowerVersion: (oldVer: string, newVer: string) =>
|
|
58
|
+
isLowerVersion: (oldVer: string, newVer: string) => boolean;
|
|
51
59
|
/**
|
|
52
60
|
* verify asar signature
|
|
53
61
|
* @param buffer file buffer
|
|
@@ -5,9 +5,13 @@ type URLHandler = (url: string, isDownloadAsar: boolean) => string;
|
|
|
5
5
|
type OnDownloading = (progress: DownloadingInfo) => void;
|
|
6
6
|
interface DownloadingInfo {
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* download delta
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
delta: number;
|
|
11
|
+
/**
|
|
12
|
+
* downloaded percent, 0 ~ 100
|
|
13
|
+
*/
|
|
14
|
+
percent: number;
|
|
11
15
|
/**
|
|
12
16
|
* total size
|
|
13
17
|
*/
|
|
@@ -15,7 +19,11 @@ interface DownloadingInfo {
|
|
|
15
19
|
/**
|
|
16
20
|
* downloaded size
|
|
17
21
|
*/
|
|
18
|
-
|
|
22
|
+
transferred: number;
|
|
23
|
+
/**
|
|
24
|
+
* download speed, bytes per second
|
|
25
|
+
*/
|
|
26
|
+
bps: number;
|
|
19
27
|
}
|
|
20
28
|
interface IProvider {
|
|
21
29
|
/**
|
|
@@ -40,14 +48,14 @@ interface IProvider {
|
|
|
40
48
|
* @param updateInfo existing update info
|
|
41
49
|
* @param onDownloading hook for on downloading
|
|
42
50
|
*/
|
|
43
|
-
|
|
51
|
+
downloadAsar: (name: string, updateInfo: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void) => Promise<Buffer>;
|
|
44
52
|
/**
|
|
45
53
|
* compare version
|
|
46
54
|
* @param oldVer old version string
|
|
47
55
|
* @param newVer new version string
|
|
48
56
|
* @returns if version1 < version2
|
|
49
57
|
*/
|
|
50
|
-
isLowerVersion: (oldVer: string, newVer: string) =>
|
|
58
|
+
isLowerVersion: (oldVer: string, newVer: string) => boolean;
|
|
51
59
|
/**
|
|
52
60
|
* verify asar signature
|
|
53
61
|
* @param buffer file buffer
|
package/dist/utils.cjs
CHANGED
|
@@ -77,7 +77,9 @@ function restartApp() {
|
|
|
77
77
|
import_electron.app.quit();
|
|
78
78
|
}
|
|
79
79
|
function setAppUserModelId(id) {
|
|
80
|
-
|
|
80
|
+
if (isWin) {
|
|
81
|
+
import_electron.app.setAppUserModelId(id ?? `org.${import_electron.app.name}`);
|
|
82
|
+
}
|
|
81
83
|
}
|
|
82
84
|
function disableHWAccForWin7() {
|
|
83
85
|
if (require("os").release().startsWith("6.1")) {
|
|
@@ -86,15 +88,19 @@ function disableHWAccForWin7() {
|
|
|
86
88
|
}
|
|
87
89
|
function singleInstance(window) {
|
|
88
90
|
const result = import_electron.app.requestSingleInstanceLock();
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
window
|
|
92
|
-
|
|
93
|
-
window.
|
|
91
|
+
if (result) {
|
|
92
|
+
import_electron.app.on("second-instance", () => {
|
|
93
|
+
if (window) {
|
|
94
|
+
window.show();
|
|
95
|
+
if (window.isMinimized()) {
|
|
96
|
+
window.restore();
|
|
97
|
+
}
|
|
98
|
+
window.focus();
|
|
94
99
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
100
|
+
});
|
|
101
|
+
} else {
|
|
102
|
+
import_electron.app.quit();
|
|
103
|
+
}
|
|
98
104
|
return result;
|
|
99
105
|
}
|
|
100
106
|
function setPortableAppDataPath(dirName = "data") {
|
|
@@ -116,7 +122,11 @@ function waitAppReady(timeout = 1e3) {
|
|
|
116
122
|
});
|
|
117
123
|
}
|
|
118
124
|
function loadPage(win, htmlFilePath = "index.html") {
|
|
119
|
-
|
|
125
|
+
if (isDev) {
|
|
126
|
+
win.loadURL(process.env.VITE_DEV_SERVER_URL + htmlFilePath);
|
|
127
|
+
} else {
|
|
128
|
+
win.loadFile(getPathFromAppNameAsar("renderer", htmlFilePath));
|
|
129
|
+
}
|
|
120
130
|
}
|
|
121
131
|
function getPathFromPreload(...paths) {
|
|
122
132
|
return isDev ? (0, import_node_path.join)(import_electron.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
|
|
@@ -142,7 +152,7 @@ async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
|
|
|
142
152
|
reject(err);
|
|
143
153
|
}
|
|
144
154
|
(0, import_node_fs2.writeFileSync)(targetFilePath, buffer2);
|
|
145
|
-
resolve(
|
|
155
|
+
resolve();
|
|
146
156
|
});
|
|
147
157
|
});
|
|
148
158
|
}
|
|
@@ -162,7 +172,7 @@ async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
|
|
|
162
172
|
reject(err);
|
|
163
173
|
}
|
|
164
174
|
(0, import_node_fs3.writeFileSync)(targetFilePath, buffer);
|
|
165
|
-
resolve(
|
|
175
|
+
resolve();
|
|
166
176
|
});
|
|
167
177
|
});
|
|
168
178
|
}
|
|
@@ -242,7 +252,7 @@ function verifySignatureDefault(buffer, signature2, cert) {
|
|
|
242
252
|
const [sig, version] = decrypt(signature2, hashString(cert, 32), hashString(buffer, 16)).split("%");
|
|
243
253
|
const result = (0, import_node_crypto2.createVerify)("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
|
|
244
254
|
return result ? version : void 0;
|
|
245
|
-
} catch
|
|
255
|
+
} catch {
|
|
246
256
|
return void 0;
|
|
247
257
|
}
|
|
248
258
|
}
|
package/dist/utils.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BrowserWindow } from 'electron';
|
|
2
2
|
export { a as UpdateInfo, U as UpdateJSON, V as Version, h as handleUnexpectedErrors, i as isLowerVersionDefault, b as isUpdateJSON, p as parseVersion } from './version-CffZWDhZ.cjs';
|
|
3
|
-
export { d as decrypt, v as verifySignatureDefault } from './decrypt-
|
|
3
|
+
export { d as decrypt, v as verifySignatureDefault } from './decrypt-D9WdXYjH.cjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* compile time dev check
|
|
@@ -69,9 +69,9 @@ declare function getPathFromPreload(...paths: string[]): string;
|
|
|
69
69
|
declare function getPathFromPublic(...paths: string[]): string;
|
|
70
70
|
declare function getPathFromEntryAsar(...paths: string[]): string;
|
|
71
71
|
|
|
72
|
-
declare function zipFile(filePath: string, targetFilePath?: string): Promise<
|
|
72
|
+
declare function zipFile(filePath: string, targetFilePath?: string): Promise<void>;
|
|
73
73
|
|
|
74
|
-
declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<
|
|
74
|
+
declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<void>;
|
|
75
75
|
|
|
76
76
|
declare function encrypt(plainText: string, key: Buffer, iv: Buffer): string;
|
|
77
77
|
declare function signature(buffer: Buffer, privateKey: string, cert: string, version: string): string;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BrowserWindow } from 'electron';
|
|
2
2
|
export { a as UpdateInfo, U as UpdateJSON, V as Version, h as handleUnexpectedErrors, i as isLowerVersionDefault, b as isUpdateJSON, p as parseVersion } from './version-CffZWDhZ.js';
|
|
3
|
-
export { d as decrypt, v as verifySignatureDefault } from './decrypt-
|
|
3
|
+
export { d as decrypt, v as verifySignatureDefault } from './decrypt-D9WdXYjH.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* compile time dev check
|
|
@@ -69,9 +69,9 @@ declare function getPathFromPreload(...paths: string[]): string;
|
|
|
69
69
|
declare function getPathFromPublic(...paths: string[]): string;
|
|
70
70
|
declare function getPathFromEntryAsar(...paths: string[]): string;
|
|
71
71
|
|
|
72
|
-
declare function zipFile(filePath: string, targetFilePath?: string): Promise<
|
|
72
|
+
declare function zipFile(filePath: string, targetFilePath?: string): Promise<void>;
|
|
73
73
|
|
|
74
|
-
declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<
|
|
74
|
+
declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<void>;
|
|
75
75
|
|
|
76
76
|
declare function encrypt(plainText: string, key: Buffer, iv: Buffer): string;
|
|
77
77
|
declare function signature(buffer: Buffer, privateKey: string, cert: string, version: string): string;
|