electron-incremental-update 2.3.4 → 2.3.6
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/index.cjs +23 -8
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +21 -6
- package/dist/vite.js +5 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var fs2 = require('fs');
|
|
4
4
|
var path2 = require('path');
|
|
5
5
|
var electron = require('electron');
|
|
6
6
|
var events = require('events');
|
|
7
7
|
|
|
8
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var fs2__default = /*#__PURE__*/_interopDefault(fs2);
|
|
11
11
|
var path2__default = /*#__PURE__*/_interopDefault(path2);
|
|
12
12
|
var electron__default = /*#__PURE__*/_interopDefault(electron);
|
|
13
13
|
|
|
@@ -25,7 +25,7 @@ function getPathFromAppNameAsar(...paths) {
|
|
|
25
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);
|
|
26
26
|
}
|
|
27
27
|
function getAppVersion() {
|
|
28
|
-
return isDev ? getEntryVersion() :
|
|
28
|
+
return isDev ? getEntryVersion() : fs2__default.default.readFileSync(getPathFromAppNameAsar("version"), "utf-8");
|
|
29
29
|
}
|
|
30
30
|
function getEntryVersion() {
|
|
31
31
|
return electron__default.default.app.getVersion();
|
|
@@ -55,6 +55,7 @@ var Updater = class extends events.EventEmitter {
|
|
|
55
55
|
CERT;
|
|
56
56
|
controller;
|
|
57
57
|
info;
|
|
58
|
+
tmpFilePath;
|
|
58
59
|
provider;
|
|
59
60
|
/**
|
|
60
61
|
* Updater logger
|
|
@@ -118,12 +119,24 @@ var Updater = class extends events.EventEmitter {
|
|
|
118
119
|
this.err(`Fetch ${format} failed`, "ERR_NETWORK", e instanceof Error ? e.message : e.toString());
|
|
119
120
|
}
|
|
120
121
|
}
|
|
122
|
+
cleanup() {
|
|
123
|
+
if (this.tmpFilePath && fs2__default.default.existsSync(this.tmpFilePath)) {
|
|
124
|
+
try {
|
|
125
|
+
fs2__default.default.unlinkSync(this.tmpFilePath);
|
|
126
|
+
this.tmpFilePath = void 0;
|
|
127
|
+
this.logger?.debug("Cleaned up temporary update file");
|
|
128
|
+
} catch (error) {
|
|
129
|
+
this.logger?.warn(`Failed to clean up temporary update file: ${error}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
121
133
|
/**
|
|
122
134
|
* Handle error message and emit error event
|
|
123
135
|
*/
|
|
124
136
|
err(msg, code, errorInfo) {
|
|
125
137
|
const err = new UpdaterError(code, errorInfo);
|
|
126
138
|
this.logger?.error(`[${code}] ${msg}`, err);
|
|
139
|
+
this.cleanup();
|
|
127
140
|
this.emit("error", err);
|
|
128
141
|
}
|
|
129
142
|
async checkForUpdates(data) {
|
|
@@ -234,14 +247,15 @@ var Updater = class extends events.EventEmitter {
|
|
|
234
247
|
}
|
|
235
248
|
this.logger?.debug("Validation end");
|
|
236
249
|
try {
|
|
237
|
-
|
|
238
|
-
this.logger?.debug(`Install to ${tmpFilePath}`);
|
|
239
|
-
|
|
250
|
+
this.tmpFilePath = `${getPathFromAppNameAsar()}.tmp`;
|
|
251
|
+
this.logger?.debug(`Install to ${this.tmpFilePath}`);
|
|
252
|
+
fs2__default.default.writeFileSync(this.tmpFilePath, await this.provider.unzipFile(buffer));
|
|
240
253
|
this.logger?.info(`Download success, version: ${_version}`);
|
|
241
254
|
this.info = void 0;
|
|
242
255
|
this.emit("update-downloaded");
|
|
243
256
|
return true;
|
|
244
257
|
} catch (error) {
|
|
258
|
+
this.cleanup();
|
|
245
259
|
this.err(
|
|
246
260
|
"Download failed",
|
|
247
261
|
"ERR_DOWNLOAD",
|
|
@@ -262,6 +276,7 @@ var Updater = class extends events.EventEmitter {
|
|
|
262
276
|
return;
|
|
263
277
|
}
|
|
264
278
|
this.controller.abort();
|
|
279
|
+
this.cleanup();
|
|
265
280
|
this.logger?.info("Cancel update");
|
|
266
281
|
this.emit("update-cancelled");
|
|
267
282
|
this.controller = new AbortController();
|
|
@@ -294,9 +309,9 @@ async function createElectronApp(appOptions = {}) {
|
|
|
294
309
|
const logger = updaterInstance.logger;
|
|
295
310
|
try {
|
|
296
311
|
const tempAsarPath = `${appNameAsarPath}.tmp`;
|
|
297
|
-
if (
|
|
312
|
+
if (fs2__default.default.existsSync(tempAsarPath)) {
|
|
298
313
|
logger?.info(`Installing new asar from ${tempAsarPath}`);
|
|
299
|
-
await onInstall(() =>
|
|
314
|
+
await onInstall(() => fs2__default.default.renameSync(tempAsarPath, appNameAsarPath), tempAsarPath, appNameAsarPath, logger);
|
|
300
315
|
}
|
|
301
316
|
await beforeStart?.(mainPath, logger);
|
|
302
317
|
if (__EIU_IS_ESM__) {
|
package/dist/index.d.cts
CHANGED
|
@@ -61,6 +61,7 @@ declare class Updater<T extends UpdateInfoWithExtraVersion = UpdateInfoWithExtra
|
|
|
61
61
|
private CERT;
|
|
62
62
|
private controller;
|
|
63
63
|
private info?;
|
|
64
|
+
private tmpFilePath?;
|
|
64
65
|
provider?: IProvider;
|
|
65
66
|
/**
|
|
66
67
|
* Updater logger
|
|
@@ -86,6 +87,7 @@ declare class Updater<T extends UpdateInfoWithExtraVersion = UpdateInfoWithExtra
|
|
|
86
87
|
* else if data is `UpdateJSON`, return it
|
|
87
88
|
*/
|
|
88
89
|
private fetch;
|
|
90
|
+
private cleanup;
|
|
89
91
|
/**
|
|
90
92
|
* Handle error message and emit error event
|
|
91
93
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ declare class Updater<T extends UpdateInfoWithExtraVersion = UpdateInfoWithExtra
|
|
|
61
61
|
private CERT;
|
|
62
62
|
private controller;
|
|
63
63
|
private info?;
|
|
64
|
+
private tmpFilePath?;
|
|
64
65
|
provider?: IProvider;
|
|
65
66
|
/**
|
|
66
67
|
* Updater logger
|
|
@@ -86,6 +87,7 @@ declare class Updater<T extends UpdateInfoWithExtraVersion = UpdateInfoWithExtra
|
|
|
86
87
|
* else if data is `UpdateJSON`, return it
|
|
87
88
|
*/
|
|
88
89
|
private fetch;
|
|
90
|
+
private cleanup;
|
|
89
91
|
/**
|
|
90
92
|
* Handle error message and emit error event
|
|
91
93
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isDev, getEntryVersion, getAppVersion, getPathFromAppNameAsar, restartApp } from './chunk-QKKPETVJ.js';
|
|
2
2
|
import { isUpdateJSON, __require } from './chunk-AAAM44NW.js';
|
|
3
|
-
import
|
|
3
|
+
import fs from 'node:fs';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import electron2 from 'electron';
|
|
6
6
|
import { EventEmitter } from 'node:events';
|
|
@@ -19,6 +19,7 @@ var Updater = class extends EventEmitter {
|
|
|
19
19
|
CERT;
|
|
20
20
|
controller;
|
|
21
21
|
info;
|
|
22
|
+
tmpFilePath;
|
|
22
23
|
provider;
|
|
23
24
|
/**
|
|
24
25
|
* Updater logger
|
|
@@ -82,12 +83,24 @@ var Updater = class extends EventEmitter {
|
|
|
82
83
|
this.err(`Fetch ${format} failed`, "ERR_NETWORK", e instanceof Error ? e.message : e.toString());
|
|
83
84
|
}
|
|
84
85
|
}
|
|
86
|
+
cleanup() {
|
|
87
|
+
if (this.tmpFilePath && fs.existsSync(this.tmpFilePath)) {
|
|
88
|
+
try {
|
|
89
|
+
fs.unlinkSync(this.tmpFilePath);
|
|
90
|
+
this.tmpFilePath = void 0;
|
|
91
|
+
this.logger?.debug("Cleaned up temporary update file");
|
|
92
|
+
} catch (error) {
|
|
93
|
+
this.logger?.warn(`Failed to clean up temporary update file: ${error}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
85
97
|
/**
|
|
86
98
|
* Handle error message and emit error event
|
|
87
99
|
*/
|
|
88
100
|
err(msg, code, errorInfo) {
|
|
89
101
|
const err = new UpdaterError(code, errorInfo);
|
|
90
102
|
this.logger?.error(`[${code}] ${msg}`, err);
|
|
103
|
+
this.cleanup();
|
|
91
104
|
this.emit("error", err);
|
|
92
105
|
}
|
|
93
106
|
async checkForUpdates(data) {
|
|
@@ -198,14 +211,15 @@ var Updater = class extends EventEmitter {
|
|
|
198
211
|
}
|
|
199
212
|
this.logger?.debug("Validation end");
|
|
200
213
|
try {
|
|
201
|
-
|
|
202
|
-
this.logger?.debug(`Install to ${tmpFilePath}`);
|
|
203
|
-
|
|
214
|
+
this.tmpFilePath = `${getPathFromAppNameAsar()}.tmp`;
|
|
215
|
+
this.logger?.debug(`Install to ${this.tmpFilePath}`);
|
|
216
|
+
fs.writeFileSync(this.tmpFilePath, await this.provider.unzipFile(buffer));
|
|
204
217
|
this.logger?.info(`Download success, version: ${_version}`);
|
|
205
218
|
this.info = void 0;
|
|
206
219
|
this.emit("update-downloaded");
|
|
207
220
|
return true;
|
|
208
221
|
} catch (error) {
|
|
222
|
+
this.cleanup();
|
|
209
223
|
this.err(
|
|
210
224
|
"Download failed",
|
|
211
225
|
"ERR_DOWNLOAD",
|
|
@@ -226,6 +240,7 @@ var Updater = class extends EventEmitter {
|
|
|
226
240
|
return;
|
|
227
241
|
}
|
|
228
242
|
this.controller.abort();
|
|
243
|
+
this.cleanup();
|
|
229
244
|
this.logger?.info("Cancel update");
|
|
230
245
|
this.emit("update-cancelled");
|
|
231
246
|
this.controller = new AbortController();
|
|
@@ -258,9 +273,9 @@ async function createElectronApp(appOptions = {}) {
|
|
|
258
273
|
const logger = updaterInstance.logger;
|
|
259
274
|
try {
|
|
260
275
|
const tempAsarPath = `${appNameAsarPath}.tmp`;
|
|
261
|
-
if (
|
|
276
|
+
if (fs.existsSync(tempAsarPath)) {
|
|
262
277
|
logger?.info(`Installing new asar from ${tempAsarPath}`);
|
|
263
|
-
await onInstall(() =>
|
|
278
|
+
await onInstall(() => fs.renameSync(tempAsarPath, appNameAsarPath), tempAsarPath, appNameAsarPath, logger);
|
|
264
279
|
}
|
|
265
280
|
await beforeStart?.(mainPath, logger);
|
|
266
281
|
if (__EIU_IS_ESM__) {
|
package/dist/vite.js
CHANGED
|
@@ -681,8 +681,11 @@ var debugStartup = async (args) => {
|
|
|
681
681
|
}
|
|
682
682
|
};
|
|
683
683
|
async function filterErrorMessageStartup(args, filter) {
|
|
684
|
-
await args.startup(void 0, { stdio: ["inherit", "
|
|
684
|
+
await args.startup(void 0, { stdio: ["inherit", "pipe", "pipe", "ipc"] });
|
|
685
685
|
const elec = process.electronApp;
|
|
686
|
+
elec.stdout.addListener("data", (data) => {
|
|
687
|
+
console.log(data.toString().trimEnd());
|
|
688
|
+
});
|
|
686
689
|
elec.stderr.addListener("data", (data) => {
|
|
687
690
|
const message = data.toString();
|
|
688
691
|
if (filter(message)) {
|
|
@@ -892,7 +895,7 @@ async function electronWithUpdater(options) {
|
|
|
892
895
|
...electronPluginOptions,
|
|
893
896
|
updater: { buildAsarOption, buildEntryOption, buildVersionOption }
|
|
894
897
|
},
|
|
895
|
-
(key, value) => (key === "privateKey" || key === "cert") && shouldShowKey ?
|
|
898
|
+
(key, value) => (key === "privateKey" || key === "cert") && shouldShowKey ? `<${key.toUpperCase()}>` : value,
|
|
896
899
|
2
|
|
897
900
|
),
|
|
898
901
|
{ timestamp: true }
|
package/package.json
CHANGED