electron-updator 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- package/build/app-updator.js +16 -25
- package/build/mac-updator.js +0 -4
- package/build/utils/download-file.js +5 -1
- package/build/windows-updator.js +8 -6
- package/package.json +4 -2
package/build/app-updator.js
CHANGED
@@ -52,19 +52,6 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
52
52
|
}
|
53
53
|
async checkForUpdates(executeType = constants_1.ExecuteType.Auto) {
|
54
54
|
this.logger.info(`AppUpdator#checkForUpdates:state is ${this.state}`);
|
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
|
-
}
|
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('AppUpdator#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('AppUpdator#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
|
}
|
@@ -103,7 +93,7 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
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('AppUpdator#downloadUpdate:emit UPDATE_DOWNLOADED');
|
107
97
|
this.emit(constants_1.EventType.UPDATE_DOWNLOADED, {
|
108
98
|
executeType,
|
109
99
|
});
|
@@ -116,6 +106,7 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
116
106
|
async quitAndInstall() {
|
117
107
|
this.logger.info(`AppUpdator#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('AppUpdator#quitAndInstall:install success');
|
132
123
|
this.emit(constants_1.EventType.BEFORE_QUIT_FOR_UPDATE);
|
133
124
|
}
|
134
125
|
else {
|
@@ -141,11 +132,11 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
141
132
|
}
|
142
133
|
}
|
143
134
|
async preCheckForAsar() {
|
144
|
-
this.logger.info(
|
135
|
+
this.logger.info('AppUpdator#preCheckForAsar');
|
145
136
|
return await this.unzip();
|
146
137
|
}
|
147
138
|
async preCheck() {
|
148
|
-
this.logger.info(
|
139
|
+
this.logger.info('AppUpdator#preCheck');
|
149
140
|
const { resourcePath } = this.availableUpdate;
|
150
141
|
if (this.state !== "downloaded" /* StateType.Downloaded */) {
|
151
142
|
return {
|
@@ -155,7 +146,7 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
155
146
|
}
|
156
147
|
// 清理老包
|
157
148
|
try {
|
158
|
-
this.logger.info(
|
149
|
+
this.logger.info('AppUpdator#preCheck:cleanOldArchive');
|
159
150
|
await (0, utils_1.cleanOldArchive)(resourcePath);
|
160
151
|
}
|
161
152
|
catch (e) {
|
@@ -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('AppUpdator#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('AppUpdator#unzip:start');
|
219
210
|
try {
|
220
211
|
const result = await this.doUnzip();
|
221
212
|
if (!result.success) {
|
package/build/mac-updator.js
CHANGED
@@ -91,10 +91,6 @@ 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
|
};
|
@@ -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/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('AppUpdator#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.4",
|
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",
|
@@ -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
|
+
}
|