electron-updator 0.1.3 → 0.1.5
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 -6
- package/build/app-updator.js +24 -33
- package/build/mac-updator.js +1 -5
- package/build/utils/download-file.js +5 -1
- package/build/utils/index.js +1 -1
- package/build/windows-updator.js +8 -6
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
[![NPM version][npm-image]][npm-url]
|
|
4
4
|
[![CI][ci-image]][ci-url]
|
|
5
|
-
[![Test coverage][codecov-image]][codecov-url]
|
|
6
5
|
[![node version][node-image]][node-url]
|
|
7
6
|
[![npm download][download-image]][download-url]
|
|
8
7
|
|
|
@@ -10,8 +9,6 @@
|
|
|
10
9
|
[npm-url]: https://npmjs.org/package/electron-updator
|
|
11
10
|
[ci-image]: https://github.com/electron-modules/electron-updator/actions/workflows/ci.yml/badge.svg
|
|
12
11
|
[ci-url]: https://github.com/electron-modules/electron-updator/actions/workflows/ci.yml
|
|
13
|
-
[codecov-image]: https://img.shields.io/codecov/c/github/electron-modules/electron-updator.svg?logo=codecov
|
|
14
|
-
[codecov-url]: https://codecov.io/gh/electron-modules/electron-updator
|
|
15
12
|
[node-image]: https://img.shields.io/badge/node.js-%3E=_16-green.svg
|
|
16
13
|
[node-url]: http://nodejs.org/download/
|
|
17
14
|
[download-image]: https://img.shields.io/npm/dm/electron-updator.svg
|
|
@@ -28,11 +25,11 @@ $ npm i electron-updator --save
|
|
|
28
25
|
|
|
29
26
|
## Contributors
|
|
30
27
|
|
|
31
|
-
|[<img src="https://avatars.githubusercontent.com/u/1011681?v=4" width="100px;"/><br/><sub><b>xudafeng</b></sub>](https://github.com/xudafeng)<br/>|[<img src="https://avatars.githubusercontent.com/u/
|
|
32
|
-
| :---: | :---: |
|
|
28
|
+
|[<img src="https://avatars.githubusercontent.com/u/4081746?v=4" width="100px;"/><br/><sub><b>zlyi</b></sub>](https://github.com/zlyi)<br/>|[<img src="https://avatars.githubusercontent.com/u/1011681?v=4" width="100px;"/><br/><sub><b>xudafeng</b></sub>](https://github.com/xudafeng)<br/>|[<img src="https://avatars.githubusercontent.com/u/52845048?v=4" width="100px;"/><br/><sub><b>snapre</b></sub>](https://github.com/snapre)<br/>|
|
|
29
|
+
| :---: | :---: | :---: |
|
|
33
30
|
|
|
34
31
|
|
|
35
|
-
This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `
|
|
32
|
+
This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Tue Jan 31 2023 14:31:40 GMT+0800`.
|
|
36
33
|
|
|
37
34
|
<!-- GITCONTRIBUTOR_END -->
|
|
38
35
|
|
package/build/app-updator.js
CHANGED
|
@@ -14,7 +14,7 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
|
14
14
|
this.logger = this._wrapLogger(options.logger);
|
|
15
15
|
this.app = app || new elelctron_app_adapter_1.ElectronAppAdapter();
|
|
16
16
|
this.startTimeStamp = new Date().getTime();
|
|
17
|
-
this.logger.info('
|
|
17
|
+
this.logger.info('ElectronUpdator#constructor');
|
|
18
18
|
this.availableUpdate = {
|
|
19
19
|
resourcePath: '',
|
|
20
20
|
latestAsarPath: '',
|
|
@@ -41,30 +41,17 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
|
41
41
|
return _logger;
|
|
42
42
|
}
|
|
43
43
|
setState(state) {
|
|
44
|
-
this.logger.info(`
|
|
44
|
+
this.logger.info(`ElectronUpdator#setState${state}`);
|
|
45
45
|
this.state = state;
|
|
46
46
|
}
|
|
47
47
|
setFeedUrl(url) {
|
|
48
|
-
this.logger.info(`
|
|
48
|
+
this.logger.info(`ElectronUpdator#setFeedUrl:url is ${url}`);
|
|
49
49
|
if (url && this.options) {
|
|
50
50
|
this.options.url = url;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
async checkForUpdates(executeType = constants_1.ExecuteType.Auto) {
|
|
54
|
-
this.logger.info(`
|
|
55
|
-
if (executeType === constants_1.ExecuteType.User) {
|
|
56
|
-
if (this.state === "downloaded" /* StateType.Downloaded */) {
|
|
57
|
-
this.logger.info(`AppUpdator#checkForUpdates:UPDATE_DOWNLOADED`);
|
|
58
|
-
this.emit(constants_1.EventType.UPDATE_DOWNLOADED, {
|
|
59
|
-
executeType,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
this.logger.info(`AppUpdator#checkForUpdates:UPDATE_NOT_AVAILABLE`);
|
|
64
|
-
this.emit(constants_1.EventType.UPDATE_NOT_AVAILABLE, { updateInfo: this.updateInfo });
|
|
65
|
-
}
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
54
|
+
this.logger.info(`ElectronUpdator#checkForUpdates:state is ${this.state}`);
|
|
68
55
|
this.setState("idle" /* StateType.Idle */);
|
|
69
56
|
try {
|
|
70
57
|
// 新一轮更新流程,更新 TimeStamp
|
|
@@ -76,17 +63,20 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
|
76
63
|
const needUpdate = this.options?.needUpdate(updateInfoResponse);
|
|
77
64
|
if (!needUpdate) {
|
|
78
65
|
this.logger.info(`updateInfo is ${JSON.stringify(this.updateInfo)},needUpdate is false`);
|
|
79
|
-
this.emit(constants_1.EventType.UPDATE_NOT_AVAILABLE, {
|
|
66
|
+
this.emit(constants_1.EventType.UPDATE_NOT_AVAILABLE, {
|
|
67
|
+
updateInfo: this.updateInfo,
|
|
68
|
+
executeType,
|
|
69
|
+
});
|
|
80
70
|
this.setState("idle" /* StateType.Idle */);
|
|
81
71
|
return;
|
|
82
72
|
}
|
|
83
|
-
this.logger.info(
|
|
73
|
+
this.logger.info('ElectronUpdator#checkForUpdates:needUpdate is true');
|
|
84
74
|
this.availableUpdate = this.doGetAvailableUpdateInfo(this.updateInfo);
|
|
85
|
-
if (!this.options?.autoDownload) {
|
|
86
|
-
this.logger.info(
|
|
75
|
+
if (!this.options?.autoDownload || executeType === constants_1.ExecuteType.User) {
|
|
76
|
+
this.logger.info('ElectronUpdator#checkForUpdates:emit UPDATE_AVAILABLE');
|
|
87
77
|
this.emit(constants_1.EventType.UPDATE_AVAILABLE, {
|
|
88
|
-
executeType,
|
|
89
78
|
updateInfo: this.updateInfo,
|
|
79
|
+
executeType,
|
|
90
80
|
});
|
|
91
81
|
return;
|
|
92
82
|
}
|
|
@@ -99,11 +89,11 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
|
99
89
|
}
|
|
100
90
|
}
|
|
101
91
|
async downloadUpdate(executeType = constants_1.ExecuteType.User) {
|
|
102
|
-
this.logger.info(`
|
|
92
|
+
this.logger.info(`ElectronUpdator#downloadUpdate:executeType is ${executeType}`);
|
|
103
93
|
await this.downloadUpdateFile(this.updateInfo);
|
|
104
94
|
const result = await this.preCheck();
|
|
105
95
|
if (result.success) {
|
|
106
|
-
this.logger.info(
|
|
96
|
+
this.logger.info('ElectronUpdator#downloadUpdate:emit UPDATE_DOWNLOADED');
|
|
107
97
|
this.emit(constants_1.EventType.UPDATE_DOWNLOADED, {
|
|
108
98
|
executeType,
|
|
109
99
|
});
|
|
@@ -114,8 +104,9 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
|
114
104
|
}
|
|
115
105
|
}
|
|
116
106
|
async quitAndInstall() {
|
|
117
|
-
this.logger.info(`
|
|
107
|
+
this.logger.info(`ElectronUpdator#quitAndInstall:state is ${this.state}`);
|
|
118
108
|
if (this.state !== "downloaded" /* StateType.Downloaded */) {
|
|
109
|
+
this.downloadUpdate();
|
|
119
110
|
return;
|
|
120
111
|
}
|
|
121
112
|
this.setState("idle" /* StateType.Idle */);
|
|
@@ -128,7 +119,7 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
|
128
119
|
result = await this.doQuitAndInstallAsar();
|
|
129
120
|
}
|
|
130
121
|
if (result.success) {
|
|
131
|
-
this.logger.warn(
|
|
122
|
+
this.logger.warn('ElectronUpdator#quitAndInstall:install success');
|
|
132
123
|
this.emit(constants_1.EventType.BEFORE_QUIT_FOR_UPDATE);
|
|
133
124
|
}
|
|
134
125
|
else {
|
|
@@ -141,21 +132,21 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
|
141
132
|
}
|
|
142
133
|
}
|
|
143
134
|
async preCheckForAsar() {
|
|
144
|
-
this.logger.info(
|
|
135
|
+
this.logger.info('ElectronUpdator#preCheckForAsar');
|
|
145
136
|
return await this.unzip();
|
|
146
137
|
}
|
|
147
138
|
async preCheck() {
|
|
148
|
-
this.logger.info(
|
|
139
|
+
this.logger.info('ElectronUpdator#preCheck');
|
|
149
140
|
const { resourcePath } = this.availableUpdate;
|
|
150
141
|
if (this.state !== "downloaded" /* StateType.Downloaded */) {
|
|
151
142
|
return {
|
|
152
143
|
success: false,
|
|
153
|
-
error: new Error(`
|
|
144
|
+
error: new Error(`ElectronUpdator#preCheck:update status(${this.state}) error`),
|
|
154
145
|
};
|
|
155
146
|
}
|
|
156
147
|
// 清理老包
|
|
157
148
|
try {
|
|
158
|
-
this.logger.info(
|
|
149
|
+
this.logger.info('ElectronUpdator#preCheck:cleanOldArchive');
|
|
159
150
|
await (0, utils_1.cleanOldArchive)(resourcePath);
|
|
160
151
|
}
|
|
161
152
|
catch (e) {
|
|
@@ -189,7 +180,7 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
|
189
180
|
}
|
|
190
181
|
async downloadUpdateFile(updateInfo) {
|
|
191
182
|
if (this.state !== "checking-for-update" /* StateType.CheckingForUpdate */) {
|
|
192
|
-
throw new Error(`
|
|
183
|
+
throw new Error(`ElectronUpdator#downloadUpdateFile:update status(${this.state}) error`);
|
|
193
184
|
}
|
|
194
185
|
const { url, signature } = updateInfo.files[0];
|
|
195
186
|
const { downloadTargetDir } = this.availableUpdate;
|
|
@@ -205,7 +196,7 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
|
205
196
|
this.emit(constants_1.EventType.UPDATE_DOWNLOAD_PROGRESS, data);
|
|
206
197
|
},
|
|
207
198
|
});
|
|
208
|
-
this.logger.info(
|
|
199
|
+
this.logger.info('ElectronUpdator#downloadUpdateFile:Downloaded');
|
|
209
200
|
this.setState("downloaded" /* StateType.Downloaded */);
|
|
210
201
|
}
|
|
211
202
|
catch (e) {
|
|
@@ -215,7 +206,7 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
|
215
206
|
}
|
|
216
207
|
}
|
|
217
208
|
async unzip() {
|
|
218
|
-
this.logger.info(
|
|
209
|
+
this.logger.info('ElectronUpdator#unzip:start');
|
|
219
210
|
try {
|
|
220
211
|
const result = await this.doUnzip();
|
|
221
212
|
if (!result.success) {
|
package/build/mac-updator.js
CHANGED
|
@@ -91,16 +91,12 @@ class MacUpdator extends app_updator_1.AppUpdator {
|
|
|
91
91
|
error,
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
|
-
this.logger.warn('AppUpdator#quitAndInstall:install success');
|
|
95
|
-
this.emit(constants_1.EventType.BEFORE_QUIT_FOR_UPDATE);
|
|
96
|
-
// 重启应用
|
|
97
|
-
this.app.relaunch();
|
|
98
94
|
return {
|
|
99
95
|
success: true,
|
|
100
96
|
};
|
|
101
97
|
}
|
|
102
98
|
async doQuitAndInstallPackage() {
|
|
103
|
-
this.logger.info('
|
|
99
|
+
this.logger.info('ElectronUpdator#doQuitAndInstallPackage:start');
|
|
104
100
|
return await (0, install_macos_dmg_1.default)(this.options, this.logger, this.availableUpdate, this.updateInfo);
|
|
105
101
|
}
|
|
106
102
|
}
|
|
@@ -20,6 +20,7 @@ const downloadFile = async ({ logger, url, signature, targetDir, progressHandle
|
|
|
20
20
|
logger.info('downloadFile#downloadFile (start)');
|
|
21
21
|
const writeStream = (0, _1.createWriteStream)(targetDir);
|
|
22
22
|
let currentLength = 0;
|
|
23
|
+
let currentProgress = 0;
|
|
23
24
|
progressHandle({
|
|
24
25
|
status: constants_1.DownloadProgressStatus.Begin,
|
|
25
26
|
});
|
|
@@ -37,9 +38,12 @@ const downloadFile = async ({ logger, url, signature, targetDir, progressHandle
|
|
|
37
38
|
try {
|
|
38
39
|
currentLength += data.length;
|
|
39
40
|
const progress = (currentLength / totalLength) * 100;
|
|
41
|
+
if (progress > currentProgress) {
|
|
42
|
+
currentProgress++;
|
|
43
|
+
}
|
|
40
44
|
progressHandle({
|
|
41
45
|
status: constants_1.DownloadProgressStatus.Downloading,
|
|
42
|
-
progress,
|
|
46
|
+
progress: currentProgress,
|
|
43
47
|
url,
|
|
44
48
|
signature,
|
|
45
49
|
data,
|
package/build/utils/index.js
CHANGED
|
@@ -5,12 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getExecuteFile = exports.requestUpdateInfo = exports.existFile = exports.cleanOldArchive = exports.spawnAsync = exports.waitUntil = exports.sleep = exports.getMacOSAppPath = exports.sudoPrompt = exports.existsSync = exports.createWriteStream = exports.isMac = exports.isWin = exports.execAsync = exports.rimrafAsync = exports.readdirAsync = exports.existsAsync = exports.renameAsync = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const child_process_1 = require("child_process");
|
|
9
8
|
const util_1 = __importDefault(require("util"));
|
|
10
9
|
const urllib_1 = __importDefault(require("urllib"));
|
|
11
10
|
const sudo_prompt_alt_1 = __importDefault(require("sudo-prompt-alt"));
|
|
12
11
|
exports.sudoPrompt = sudo_prompt_alt_1.default;
|
|
13
12
|
const rimraf_alt_1 = __importDefault(require("rimraf-alt"));
|
|
13
|
+
const child_process_1 = require("child_process");
|
|
14
14
|
const original_fs_1 = require("original-fs");
|
|
15
15
|
Object.defineProperty(exports, "existsSync", { enumerable: true, get: function () { return original_fs_1.existsSync; } });
|
|
16
16
|
Object.defineProperty(exports, "createWriteStream", { enumerable: true, get: function () { return original_fs_1.createWriteStream; } });
|
package/build/windows-updator.js
CHANGED
|
@@ -12,7 +12,7 @@ const app_updator_1 = require("./app-updator");
|
|
|
12
12
|
const utils_1 = require("./utils");
|
|
13
13
|
class WindowsUpdator extends app_updator_1.AppUpdator {
|
|
14
14
|
doGetAvailableUpdateInfo(updateInfo) {
|
|
15
|
-
this.logger.info(
|
|
15
|
+
this.logger.info('WindowsUpdator#doGetAvailableUpdateInfo:start');
|
|
16
16
|
let resourcePath = path_1.default.resolve(this.app.userDataPath);
|
|
17
17
|
const latestAsarPath = path_1.default.resolve(resourcePath, 'latest.asar');
|
|
18
18
|
const latestAppPath = path_1.default.resolve(resourcePath, 'latest');
|
|
@@ -27,12 +27,12 @@ class WindowsUpdator extends app_updator_1.AppUpdator {
|
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
async doPreCheckForPackage() {
|
|
30
|
-
this.logger.info(
|
|
30
|
+
this.logger.info('WindowsUpdator#doPreCheckForPackage:start');
|
|
31
31
|
// Windows 全量安装默认预检正常
|
|
32
32
|
return Promise.resolve({ success: true });
|
|
33
33
|
}
|
|
34
34
|
async doUnzip() {
|
|
35
|
-
this.logger.info(
|
|
35
|
+
this.logger.info('WindowsUpdator#doUnzip:start');
|
|
36
36
|
try {
|
|
37
37
|
const { downloadTargetDir, resourcePath } = this.availableUpdate;
|
|
38
38
|
const unzipExe = (0, utils_1.getExecuteFile)('unzip.exe');
|
|
@@ -45,13 +45,13 @@ class WindowsUpdator extends app_updator_1.AppUpdator {
|
|
|
45
45
|
error,
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
-
this.logger.info(
|
|
48
|
+
this.logger.info('WindowsUpdator#doUnzip:success');
|
|
49
49
|
return {
|
|
50
50
|
success: true,
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
async doQuitAndInstallPackage() {
|
|
54
|
-
this.logger.info(
|
|
54
|
+
this.logger.info('WindowsUpdator#doQuitAndInstallPackage:success');
|
|
55
55
|
const { downloadTargetDir } = this.availableUpdate;
|
|
56
56
|
try {
|
|
57
57
|
// Windows 全量安装
|
|
@@ -67,7 +67,7 @@ class WindowsUpdator extends app_updator_1.AppUpdator {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
async doQuitAndInstallAsar() {
|
|
70
|
-
this.logger.info(
|
|
70
|
+
this.logger.info('WindowsUpdator#doQuitAndInstallAsar:start');
|
|
71
71
|
const productName = this.options?.productName;
|
|
72
72
|
const { resourcePath } = this.availableUpdate;
|
|
73
73
|
const exePath = this.app.exePath;
|
|
@@ -76,6 +76,8 @@ class WindowsUpdator extends app_updator_1.AppUpdator {
|
|
|
76
76
|
const executeCommand = `"${updateExePath}" "${targetPath}" "${resourcePath}" "${productName}.exe" "${exePath}"`;
|
|
77
77
|
try {
|
|
78
78
|
await (0, sudo_prompt_exec_1.sudoPromptExec)(this.options, this.logger, executeCommand);
|
|
79
|
+
this.logger.warn('ElectronUpdator#quitAndInstall:install success');
|
|
80
|
+
this.emit(constants_1.EventType.BEFORE_QUIT_FOR_UPDATE);
|
|
79
81
|
return Promise.resolve({ success: true });
|
|
80
82
|
}
|
|
81
83
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-updator",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "electron-updator is a software updator management solution for Electron applications, It is convenient to complete full software update and dynamic update.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "sh ./build.sh",
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"eventemitter3": "^4.0.0",
|
|
29
|
-
"lodash": "4
|
|
30
|
-
"moment": "2
|
|
29
|
+
"lodash": "4",
|
|
30
|
+
"moment": "2",
|
|
31
31
|
"rimraf-alt": "*",
|
|
32
32
|
"sudo-prompt-alt": "9",
|
|
33
|
-
"urllib": "2
|
|
33
|
+
"urllib": "2"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@applint/spec": "^1.2.0",
|
|
@@ -48,6 +48,8 @@
|
|
|
48
48
|
"electron": "18",
|
|
49
49
|
"electron-windows": "18",
|
|
50
50
|
"eslint": "^7.32.0",
|
|
51
|
+
"eslint-config-egg": "^9.0.0",
|
|
52
|
+
"eslint-plugin-no-only-tests": "^2.6.0",
|
|
51
53
|
"git-contributor": "*",
|
|
52
54
|
"husky": "^7.0.4",
|
|
53
55
|
"mm": "^3.0.2",
|
|
@@ -67,4 +69,4 @@
|
|
|
67
69
|
}
|
|
68
70
|
},
|
|
69
71
|
"license": "MIT"
|
|
70
|
-
}
|
|
72
|
+
}
|