electron-incremental-update 0.7.8 → 0.7.10
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 +9 -10
- package/dist/chunk-2JVXVTC5.mjs +9 -0
- package/dist/{chunk-SWXNCK6H.mjs → chunk-4TION32M.mjs} +19 -12
- package/dist/{chunk-2XHZMWRR.mjs → chunk-Q2K52LOG.mjs} +1 -8
- package/dist/chunk-ZFXKCRJC.mjs +11 -0
- package/dist/index.d.mts +79 -48
- package/dist/index.d.ts +79 -48
- package/dist/index.js +191 -161
- package/dist/index.mjs +158 -138
- package/dist/{updateJson-7e45d9e1.d.ts → updateJson.d.mts} +2 -1
- package/dist/updateJson.d.ts +12 -0
- package/dist/updateJson.js +33 -0
- package/dist/updateJson.mjs +7 -0
- package/dist/utils.d.mts +17 -7
- package/dist/utils.d.ts +17 -7
- package/dist/utils.js +16 -4
- package/dist/utils.mjs +2 -1
- package/dist/vite.d.mts +22 -19
- package/dist/vite.d.ts +22 -19
- package/dist/vite.js +14 -2
- package/dist/vite.mjs +6 -3
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
|
-
isUpdateJSON,
|
|
3
2
|
verify
|
|
4
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-Q2K52LOG.mjs";
|
|
5
4
|
import {
|
|
6
|
-
__require,
|
|
7
5
|
getEntryVersion,
|
|
8
6
|
getProductAsarPath,
|
|
9
7
|
getProductVersion,
|
|
10
8
|
parseVersion,
|
|
11
9
|
unzipFile,
|
|
12
10
|
waitAppReady
|
|
13
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-4TION32M.mjs";
|
|
12
|
+
import {
|
|
13
|
+
isUpdateJSON
|
|
14
|
+
} from "./chunk-2JVXVTC5.mjs";
|
|
15
|
+
import {
|
|
16
|
+
__require
|
|
17
|
+
} from "./chunk-ZFXKCRJC.mjs";
|
|
14
18
|
|
|
15
19
|
// src/index.ts
|
|
16
20
|
import { resolve } from "node:path";
|
|
@@ -18,15 +22,14 @@ import { existsSync as existsSync2, renameSync } from "node:fs";
|
|
|
18
22
|
import { app } from "electron";
|
|
19
23
|
|
|
20
24
|
// src/updater/index.ts
|
|
21
|
-
import { EventEmitter } from "node:events";
|
|
22
|
-
import { Buffer as Buffer2 } from "node:buffer";
|
|
23
25
|
import { existsSync } from "node:fs";
|
|
26
|
+
import { Buffer as Buffer2 } from "node:buffer";
|
|
24
27
|
import { rm, writeFile } from "node:fs/promises";
|
|
25
28
|
|
|
26
29
|
// src/updater/defaultFunctions.ts
|
|
27
30
|
import { Buffer } from "node:buffer";
|
|
28
31
|
import { net } from "electron";
|
|
29
|
-
async
|
|
32
|
+
var downloadJSONDefault = async (url, headers) => {
|
|
30
33
|
await waitAppReady();
|
|
31
34
|
return new Promise((resolve2, reject) => {
|
|
32
35
|
const request = net.request({
|
|
@@ -58,10 +61,10 @@ async function downloadJSONDefault(url, updater, headers) {
|
|
|
58
61
|
});
|
|
59
62
|
request.end();
|
|
60
63
|
});
|
|
61
|
-
}
|
|
62
|
-
async
|
|
64
|
+
};
|
|
65
|
+
var downloadBufferDefault = async (url, headers, total, onDownloading) => {
|
|
63
66
|
await waitAppReady();
|
|
64
|
-
let
|
|
67
|
+
let current = 0;
|
|
65
68
|
return new Promise((resolve2, reject) => {
|
|
66
69
|
const request = net.request({
|
|
67
70
|
url,
|
|
@@ -74,8 +77,12 @@ async function downloadBufferDefault(url, updater, headers) {
|
|
|
74
77
|
request.on("response", (res) => {
|
|
75
78
|
let data = [];
|
|
76
79
|
res.on("data", (chunk) => {
|
|
77
|
-
|
|
78
|
-
|
|
80
|
+
current += chunk.length;
|
|
81
|
+
onDownloading?.({
|
|
82
|
+
percent: `${+(current / total).toFixed(2) * 100}%`,
|
|
83
|
+
total,
|
|
84
|
+
current
|
|
85
|
+
});
|
|
79
86
|
data.push(chunk);
|
|
80
87
|
});
|
|
81
88
|
res.on("end", () => {
|
|
@@ -86,15 +93,24 @@ async function downloadBufferDefault(url, updater, headers) {
|
|
|
86
93
|
});
|
|
87
94
|
request.end();
|
|
88
95
|
});
|
|
89
|
-
}
|
|
90
|
-
var compareVersionDefault = (
|
|
91
|
-
const oldV = parseVersion(
|
|
92
|
-
const newV = parseVersion(
|
|
93
|
-
|
|
94
|
-
|
|
96
|
+
};
|
|
97
|
+
var compareVersionDefault = (version1, version2) => {
|
|
98
|
+
const oldV = parseVersion(version1);
|
|
99
|
+
const newV = parseVersion(version2);
|
|
100
|
+
function compareStrings(str1, str2) {
|
|
101
|
+
if (str1 === "") {
|
|
102
|
+
return str2 !== "";
|
|
103
|
+
} else if (str2 === "") {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return str1 < str2;
|
|
95
107
|
}
|
|
96
|
-
|
|
97
|
-
|
|
108
|
+
for (let key of Object.keys(oldV)) {
|
|
109
|
+
if (key === "stage" && compareStrings(oldV[key], newV[key])) {
|
|
110
|
+
return true;
|
|
111
|
+
} else if (oldV[key] !== newV[key]) {
|
|
112
|
+
return oldV[key] < newV[key];
|
|
113
|
+
}
|
|
98
114
|
}
|
|
99
115
|
return false;
|
|
100
116
|
};
|
|
@@ -118,158 +134,160 @@ var VerifyFailedError = class extends Error {
|
|
|
118
134
|
this.cert = cert;
|
|
119
135
|
}
|
|
120
136
|
};
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
debug && updater.emit("debug", msg);
|
|
137
|
+
var DownloadError = class extends Error {
|
|
138
|
+
constructor() {
|
|
139
|
+
super("download update error");
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
var IncrementalUpdater = class {
|
|
143
|
+
info;
|
|
144
|
+
option;
|
|
145
|
+
asarPath;
|
|
146
|
+
gzipPath;
|
|
147
|
+
tmpFilePath;
|
|
148
|
+
logger;
|
|
149
|
+
onDownloading;
|
|
150
|
+
get productName() {
|
|
151
|
+
return this.option.productName;
|
|
152
|
+
}
|
|
153
|
+
set productName(name) {
|
|
154
|
+
this.option.productName = name;
|
|
155
|
+
}
|
|
156
|
+
get receiveBeta() {
|
|
157
|
+
return !!this.option.receiveBeta;
|
|
158
|
+
}
|
|
159
|
+
set receiveBeta(receiveBeta) {
|
|
160
|
+
this.option.receiveBeta = receiveBeta;
|
|
146
161
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
162
|
+
constructor(option) {
|
|
163
|
+
this.option = option;
|
|
164
|
+
this.asarPath = getProductAsarPath(this.productName);
|
|
165
|
+
this.gzipPath = `${this.asarPath}.gz`;
|
|
166
|
+
this.tmpFilePath = `${this.asarPath}.tmp`;
|
|
167
|
+
}
|
|
168
|
+
async needUpdate(version, minVersion) {
|
|
169
|
+
const compare = this.option.overrideFunctions?.compareVersion ?? compareVersionDefault;
|
|
170
|
+
const productVersion = getProductVersion(this.option.productName);
|
|
150
171
|
const entryVersion = getEntryVersion();
|
|
151
172
|
if (await compare(entryVersion, minVersion)) {
|
|
152
173
|
throw new MinimumVersionError(entryVersion, minVersion);
|
|
153
174
|
}
|
|
154
|
-
|
|
155
|
-
return await compare(productVersion,
|
|
175
|
+
this.logger?.info(`check update: current version is ${productVersion}, new version is ${version}`);
|
|
176
|
+
return await compare(productVersion, version);
|
|
156
177
|
}
|
|
157
|
-
async
|
|
158
|
-
if (existsSync(tmpFilePath)) {
|
|
159
|
-
|
|
160
|
-
await rm(tmpFilePath);
|
|
178
|
+
async parseData(format, data) {
|
|
179
|
+
if (existsSync(this.tmpFilePath)) {
|
|
180
|
+
this.logger?.warn(`remove tmp file: ${this.tmpFilePath}`);
|
|
181
|
+
await rm(this.tmpFilePath);
|
|
182
|
+
}
|
|
183
|
+
if (existsSync(this.gzipPath)) {
|
|
184
|
+
this.logger?.warn(`remove .gz file: ${this.gzipPath}`);
|
|
185
|
+
await rm(this.gzipPath);
|
|
161
186
|
}
|
|
162
|
-
if (
|
|
163
|
-
|
|
164
|
-
|
|
187
|
+
if (!["string", "object", "undefined"].includes(typeof data)) {
|
|
188
|
+
throw new TypeError(`invalid type at format '${format}': ${data}`);
|
|
189
|
+
}
|
|
190
|
+
if (typeof data === "object" && (format === "json" && isUpdateJSON(data) || format === "buffer" && Buffer2.isBuffer(data))) {
|
|
191
|
+
return data;
|
|
165
192
|
}
|
|
166
193
|
if (typeof data === "object") {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
if (!data) {
|
|
193
|
-
log(`no ${info.name}, fallback to use repository`);
|
|
194
|
-
if (!repository) {
|
|
195
|
-
throw new Error(`${info.name} or repository are not set`);
|
|
196
|
-
}
|
|
197
|
-
if (format === "buffer" && !version2) {
|
|
198
|
-
throw new Error("version are not set");
|
|
199
|
-
}
|
|
200
|
-
data = info.repoFallback;
|
|
194
|
+
throw new TypeError(`invalid type at format '${format}': ${data}`);
|
|
195
|
+
}
|
|
196
|
+
const ua = this.option.downloadConfig?.userAgent || "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36";
|
|
197
|
+
const headers = {
|
|
198
|
+
Accept: `application/${format === "json" ? "json" : "octet-stream"}`,
|
|
199
|
+
UserAgent: ua,
|
|
200
|
+
...this.option.downloadConfig?.extraHeader
|
|
201
|
+
};
|
|
202
|
+
this.logger?.info(`download headers: ${JSON.stringify(headers, null, 2)}`);
|
|
203
|
+
const config = format === "json" ? {
|
|
204
|
+
name: "updateJsonURL",
|
|
205
|
+
url: this.option.updateJsonURL,
|
|
206
|
+
repoFallback: `${this.option.repository.replace("github.com", "raw.githubusercontent.com")}/master/version.json`,
|
|
207
|
+
fn: this.option.overrideFunctions?.downloadJSON ?? downloadJSONDefault
|
|
208
|
+
} : {
|
|
209
|
+
name: "releaseAsarURL",
|
|
210
|
+
url: this.option.releaseAsarURL,
|
|
211
|
+
repoFallback: `${this.option.repository}/releases/download/v${this.info?.version}/${this.productName}-${this.info?.version}.asar.gz`,
|
|
212
|
+
fn: this.option.overrideFunctions?.downloadBuffer ?? downloadBufferDefault
|
|
213
|
+
};
|
|
214
|
+
data ??= config.url;
|
|
215
|
+
if (!data) {
|
|
216
|
+
this.logger?.debug(`no ${config.name}, fallback to use repository`);
|
|
217
|
+
if (!this.option.repository) {
|
|
218
|
+
throw new Error(`${config.name} or repository are not set`);
|
|
201
219
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
log(`download ${format} success${format === "buffer" ? `, file size: ${ret.length}` : ""}`);
|
|
205
|
-
if (format === "buffer") {
|
|
206
|
-
updater.emit("downloadBuffer", ret);
|
|
220
|
+
if (format === "buffer" && !this.info?.version) {
|
|
221
|
+
throw new Error("version are not set");
|
|
207
222
|
}
|
|
223
|
+
data = config.repoFallback;
|
|
224
|
+
}
|
|
225
|
+
this.logger?.info(`download ${format} from ${data}`);
|
|
226
|
+
try {
|
|
227
|
+
const ret = format === "json" ? await config.fn(data, headers) : await config.fn(data, headers, this.info.size, this.onDownloading);
|
|
228
|
+
this.logger?.info(`download ${format} success${format === "buffer" ? `, file size: ${ret.length}` : ""}`);
|
|
208
229
|
return ret;
|
|
209
|
-
}
|
|
210
|
-
throw new
|
|
230
|
+
} catch (e) {
|
|
231
|
+
throw new DownloadError();
|
|
211
232
|
}
|
|
212
233
|
}
|
|
213
|
-
|
|
214
|
-
updater.debug = debug;
|
|
215
|
-
updater.receiveBeta = receiveBeta;
|
|
216
|
-
updater.checkUpdate = async (data) => {
|
|
234
|
+
async checkUpdate(data) {
|
|
217
235
|
try {
|
|
218
|
-
let {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
minimumVersion,
|
|
223
|
-
beta
|
|
224
|
-
} = await parseData("json", data);
|
|
225
|
-
if (receiveBeta) {
|
|
226
|
-
_ver = beta.version;
|
|
227
|
-
_sig = beta.signature;
|
|
236
|
+
let { signature, size, version, minimumVersion, beta } = await this.parseData("json", data);
|
|
237
|
+
if (this.receiveBeta) {
|
|
238
|
+
version = beta.version;
|
|
239
|
+
signature = beta.signature;
|
|
228
240
|
minimumVersion = beta.minimumVersion;
|
|
229
241
|
size = beta.size;
|
|
230
242
|
}
|
|
231
|
-
|
|
232
|
-
if (!await needUpdate(
|
|
233
|
-
|
|
243
|
+
this.logger?.info(`checked version: ${version}, size: ${size}, signature: ${signature}`);
|
|
244
|
+
if (!await this.needUpdate(version, minimumVersion)) {
|
|
245
|
+
this.logger?.info(`update unavailable: ${version} is the latest version`);
|
|
234
246
|
return void 0;
|
|
235
247
|
} else {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
248
|
+
this.logger?.info(`update available: ${version}`);
|
|
249
|
+
this.info = {
|
|
250
|
+
signature,
|
|
251
|
+
minimumVersion,
|
|
252
|
+
version,
|
|
253
|
+
size
|
|
254
|
+
};
|
|
255
|
+
return { size, version };
|
|
240
256
|
}
|
|
241
257
|
} catch (error) {
|
|
242
|
-
|
|
258
|
+
this.logger?.error("check update failed", error);
|
|
243
259
|
return error;
|
|
244
260
|
}
|
|
245
|
-
}
|
|
246
|
-
|
|
261
|
+
}
|
|
262
|
+
async download(data, sig) {
|
|
247
263
|
try {
|
|
248
|
-
const _sig = sig ?? signature;
|
|
264
|
+
const _sig = sig ?? this.info?.signature;
|
|
249
265
|
if (!_sig) {
|
|
250
266
|
throw new Error("signature are not set, please checkUpdate first or set the second parameter");
|
|
251
267
|
}
|
|
252
|
-
const buffer = await parseData("buffer", data
|
|
253
|
-
|
|
254
|
-
const _verify = verifySignaure ?? verify;
|
|
255
|
-
const _ver = await _verify(buffer, _sig, SIGNATURE_CERT);
|
|
268
|
+
const buffer = await this.parseData("buffer", data);
|
|
269
|
+
this.logger?.info("verify start");
|
|
270
|
+
const _verify = this.option.overrideFunctions?.verifySignaure ?? verify;
|
|
271
|
+
const _ver = await _verify(buffer, _sig, this.option.SIGNATURE_CERT);
|
|
256
272
|
if (!_ver) {
|
|
257
|
-
throw new VerifyFailedError(_sig, SIGNATURE_CERT);
|
|
273
|
+
throw new VerifyFailedError(_sig, this.option.SIGNATURE_CERT);
|
|
258
274
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
await writeFile(gzipPath, buffer);
|
|
262
|
-
|
|
263
|
-
await unzipFile(gzipPath, tmpFilePath);
|
|
264
|
-
|
|
265
|
-
|
|
275
|
+
this.logger?.info("verify success");
|
|
276
|
+
this.logger?.info(`write to ${this.gzipPath}`);
|
|
277
|
+
await writeFile(this.gzipPath, buffer);
|
|
278
|
+
this.logger?.info(`extract to ${this.tmpFilePath}`);
|
|
279
|
+
await unzipFile(this.gzipPath, this.tmpFilePath);
|
|
280
|
+
this.logger?.info(`download success${typeof _ver === "string" ? `, version: ${_ver}` : ""}`);
|
|
281
|
+
this.info = void 0;
|
|
266
282
|
return true;
|
|
267
283
|
} catch (error) {
|
|
268
|
-
|
|
284
|
+
this.logger?.error("download asar failed", error);
|
|
269
285
|
return error;
|
|
270
286
|
}
|
|
271
|
-
}
|
|
272
|
-
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
function createUpdater(option) {
|
|
290
|
+
return new IncrementalUpdater(option);
|
|
273
291
|
}
|
|
274
292
|
|
|
275
293
|
// src/index.ts
|
|
@@ -315,6 +333,8 @@ function initApp(appOptions) {
|
|
|
315
333
|
};
|
|
316
334
|
}
|
|
317
335
|
export {
|
|
336
|
+
DownloadError,
|
|
337
|
+
IncrementalUpdater,
|
|
318
338
|
MinimumVersionError,
|
|
319
339
|
VerifyFailedError,
|
|
320
340
|
createUpdater,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type UpdateInfo = {
|
|
2
|
+
signature: string;
|
|
3
|
+
minimumVersion: string;
|
|
4
|
+
version: string;
|
|
5
|
+
size: number;
|
|
6
|
+
};
|
|
7
|
+
type UpdateJSON = UpdateInfo & {
|
|
8
|
+
beta: UpdateInfo;
|
|
9
|
+
};
|
|
10
|
+
declare function isUpdateJSON(json: any): json is UpdateJSON;
|
|
11
|
+
|
|
12
|
+
export { UpdateInfo, UpdateJSON, isUpdateJSON };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/updateJson.ts
|
|
21
|
+
var updateJson_exports = {};
|
|
22
|
+
__export(updateJson_exports, {
|
|
23
|
+
isUpdateJSON: () => isUpdateJSON
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(updateJson_exports);
|
|
26
|
+
function isUpdateJSON(json) {
|
|
27
|
+
const is = (j) => "signature" in j && "version" in j && "size" in j && "minimumVersion" in j;
|
|
28
|
+
return is(json) && "beta" in json && is(json.beta);
|
|
29
|
+
}
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
isUpdateJSON
|
|
33
|
+
});
|
package/dist/utils.d.mts
CHANGED
|
@@ -9,6 +9,8 @@ declare function getProductAsarPath(name: string): string;
|
|
|
9
9
|
declare function getEntryVersion(): string;
|
|
10
10
|
/**
|
|
11
11
|
* get the version of application (name.asar)
|
|
12
|
+
*
|
|
13
|
+
* if is dev, return {@link getEntryVersion}
|
|
12
14
|
* @param name - The name of the application
|
|
13
15
|
*/
|
|
14
16
|
declare function getProductVersion(name: string): string;
|
|
@@ -23,11 +25,11 @@ declare class NoSuchNativeModuleError extends Error {
|
|
|
23
25
|
*/
|
|
24
26
|
declare function requireNative<T = any>(packageName: string): T;
|
|
25
27
|
/**
|
|
26
|
-
*
|
|
28
|
+
* parse Github CDN URL for accelerating the speed of downloading
|
|
27
29
|
*/
|
|
28
30
|
declare function parseGithubCdnURL(repository: string, cdnPrefix: string, relativeFilePath: string): string;
|
|
29
31
|
/**
|
|
30
|
-
* get group of
|
|
32
|
+
* get group of Github file CDN prefix for accelerating the speed of downloading project files
|
|
31
33
|
*/
|
|
32
34
|
declare function getGithubFileCdnGroup(): {
|
|
33
35
|
cdnPrefix: string;
|
|
@@ -40,16 +42,24 @@ declare function getGithubReleaseCdnGroup(): {
|
|
|
40
42
|
cdnPrefix: string;
|
|
41
43
|
source: string;
|
|
42
44
|
}[];
|
|
45
|
+
/**
|
|
46
|
+
* Restarts the Electron app.
|
|
47
|
+
*/
|
|
43
48
|
declare function restartApp(): void;
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
/**
|
|
50
|
+
* ensure app is ready.
|
|
51
|
+
*/
|
|
52
|
+
declare function waitAppReady(duration?: number): Promise<void>;
|
|
53
|
+
declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<unknown>;
|
|
46
54
|
declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
|
|
47
55
|
declare function handleUnexpectedErrors(callback: (err: Error) => void): void;
|
|
48
|
-
|
|
56
|
+
interface Version {
|
|
49
57
|
major: number;
|
|
50
58
|
minor: number;
|
|
51
59
|
patch: number;
|
|
52
60
|
stage: string;
|
|
53
|
-
|
|
61
|
+
stageVersion: number;
|
|
62
|
+
}
|
|
63
|
+
declare function parseVersion(version: string): Version;
|
|
54
64
|
|
|
55
|
-
export { NoSuchNativeModuleError, getEntryVersion, getGithubFileCdnGroup, getGithubReleaseCdnGroup, getProductAsarPath, getProductVersion, handleUnexpectedErrors, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
|
|
65
|
+
export { NoSuchNativeModuleError, Version, getEntryVersion, getGithubFileCdnGroup, getGithubReleaseCdnGroup, getProductAsarPath, getProductVersion, handleUnexpectedErrors, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
|
package/dist/utils.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ declare function getProductAsarPath(name: string): string;
|
|
|
9
9
|
declare function getEntryVersion(): string;
|
|
10
10
|
/**
|
|
11
11
|
* get the version of application (name.asar)
|
|
12
|
+
*
|
|
13
|
+
* if is dev, return {@link getEntryVersion}
|
|
12
14
|
* @param name - The name of the application
|
|
13
15
|
*/
|
|
14
16
|
declare function getProductVersion(name: string): string;
|
|
@@ -23,11 +25,11 @@ declare class NoSuchNativeModuleError extends Error {
|
|
|
23
25
|
*/
|
|
24
26
|
declare function requireNative<T = any>(packageName: string): T;
|
|
25
27
|
/**
|
|
26
|
-
*
|
|
28
|
+
* parse Github CDN URL for accelerating the speed of downloading
|
|
27
29
|
*/
|
|
28
30
|
declare function parseGithubCdnURL(repository: string, cdnPrefix: string, relativeFilePath: string): string;
|
|
29
31
|
/**
|
|
30
|
-
* get group of
|
|
32
|
+
* get group of Github file CDN prefix for accelerating the speed of downloading project files
|
|
31
33
|
*/
|
|
32
34
|
declare function getGithubFileCdnGroup(): {
|
|
33
35
|
cdnPrefix: string;
|
|
@@ -40,16 +42,24 @@ declare function getGithubReleaseCdnGroup(): {
|
|
|
40
42
|
cdnPrefix: string;
|
|
41
43
|
source: string;
|
|
42
44
|
}[];
|
|
45
|
+
/**
|
|
46
|
+
* Restarts the Electron app.
|
|
47
|
+
*/
|
|
43
48
|
declare function restartApp(): void;
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
/**
|
|
50
|
+
* ensure app is ready.
|
|
51
|
+
*/
|
|
52
|
+
declare function waitAppReady(duration?: number): Promise<void>;
|
|
53
|
+
declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<unknown>;
|
|
46
54
|
declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
|
|
47
55
|
declare function handleUnexpectedErrors(callback: (err: Error) => void): void;
|
|
48
|
-
|
|
56
|
+
interface Version {
|
|
49
57
|
major: number;
|
|
50
58
|
minor: number;
|
|
51
59
|
patch: number;
|
|
52
60
|
stage: string;
|
|
53
|
-
|
|
61
|
+
stageVersion: number;
|
|
62
|
+
}
|
|
63
|
+
declare function parseVersion(version: string): Version;
|
|
54
64
|
|
|
55
|
-
export { NoSuchNativeModuleError, getEntryVersion, getGithubFileCdnGroup, getGithubReleaseCdnGroup, getProductAsarPath, getProductVersion, handleUnexpectedErrors, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
|
|
65
|
+
export { NoSuchNativeModuleError, Version, getEntryVersion, getGithubFileCdnGroup, getGithubReleaseCdnGroup, getProductAsarPath, getProductVersion, handleUnexpectedErrors, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
|
package/dist/utils.js
CHANGED
|
@@ -111,11 +111,11 @@ function waitAppReady(duration = 1e3) {
|
|
|
111
111
|
}, duration);
|
|
112
112
|
import_electron.app.whenReady().then(() => {
|
|
113
113
|
clearTimeout(timeout);
|
|
114
|
-
resolve(
|
|
114
|
+
resolve();
|
|
115
115
|
});
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
|
-
async function unzipFile(gzipPath, targetFilePath) {
|
|
118
|
+
async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
|
|
119
119
|
if (!(0, import_node_fs.existsSync)(gzipPath)) {
|
|
120
120
|
throw new Error(`path to zipped file not exist: ${gzipPath}`);
|
|
121
121
|
}
|
|
@@ -161,10 +161,22 @@ function parseVersion(version) {
|
|
|
161
161
|
throw new TypeError(`invalid version: ${version}`);
|
|
162
162
|
}
|
|
163
163
|
const [major, minor, patch] = match.slice(1, 4).map(Number);
|
|
164
|
-
|
|
164
|
+
const ret = {
|
|
165
|
+
major,
|
|
166
|
+
minor,
|
|
167
|
+
patch,
|
|
168
|
+
stage: "",
|
|
169
|
+
stageVersion: -1
|
|
170
|
+
};
|
|
171
|
+
if (match[4]) {
|
|
172
|
+
let [stage, _v] = match[4].split(".");
|
|
173
|
+
ret.stage = stage;
|
|
174
|
+
ret.stageVersion = Number(_v) || -1;
|
|
175
|
+
}
|
|
176
|
+
if (isNaN(major) || isNaN(minor) || isNaN(patch) || isNaN(ret.stageVersion)) {
|
|
165
177
|
throw new TypeError(`invalid version: ${version}`);
|
|
166
178
|
}
|
|
167
|
-
return
|
|
179
|
+
return ret;
|
|
168
180
|
}
|
|
169
181
|
// Annotate the CommonJS export names for ESM import in node:
|
|
170
182
|
0 && (module.exports = {
|