electron-updator 0.1.5 → 0.1.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/build/app-updator.js +22 -19
- package/build/common/constants.js +23 -1
- package/build/index.js +7 -2
- package/build/mac-updator.js +0 -3
- package/build/utils/install-macos-dmg.js +4 -0
- package/build/utils/sudo-prompt-exec.js +1 -1
- package/build/windows-updator.js +1 -1
- package/package.json +5 -5
package/build/app-updator.js
CHANGED
@@ -9,7 +9,7 @@ const elelctron_app_adapter_1 = require("./elelctron-app-adapter");
|
|
9
9
|
class AppUpdator extends eventemitter3_1.EventEmitter {
|
10
10
|
constructor(options, app) {
|
11
11
|
super();
|
12
|
-
this.state =
|
12
|
+
this.state = constants_1.StateType.Idle;
|
13
13
|
this.options = options;
|
14
14
|
this.logger = this._wrapLogger(options.logger);
|
15
15
|
this.app = app || new elelctron_app_adapter_1.ElectronAppAdapter();
|
@@ -52,11 +52,11 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
52
52
|
}
|
53
53
|
async checkForUpdates(executeType = constants_1.ExecuteType.Auto) {
|
54
54
|
this.logger.info(`ElectronUpdator#checkForUpdates:state is ${this.state}`);
|
55
|
-
this.setState(
|
55
|
+
this.setState(constants_1.StateType.Idle);
|
56
56
|
try {
|
57
57
|
// 新一轮更新流程,更新 TimeStamp
|
58
58
|
this.startTimeStamp = new Date().getTime();
|
59
|
-
this.setState(
|
59
|
+
this.setState(constants_1.StateType.CheckingForUpdate);
|
60
60
|
this.emit(constants_1.EventType.CHECKING_FOR_UPDATE);
|
61
61
|
const updateInfoResponse = await (0, utils_1.requestUpdateInfo)(this.options);
|
62
62
|
this.updateInfo = (this.options?.responseFormatter ? this.options?.responseFormatter(updateInfoResponse) : updateInfoResponse);
|
@@ -67,7 +67,7 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
67
67
|
updateInfo: this.updateInfo,
|
68
68
|
executeType,
|
69
69
|
});
|
70
|
-
this.setState(
|
70
|
+
this.setState(constants_1.StateType.Idle);
|
71
71
|
return;
|
72
72
|
}
|
73
73
|
this.logger.info('ElectronUpdator#checkForUpdates:needUpdate is true');
|
@@ -85,13 +85,13 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
85
85
|
catch (e) {
|
86
86
|
e.customMessage = e.customMessage ? e.customMessage : `${constants_1.InstallResultType.CheckForUpdatesError}_${e.message}`;
|
87
87
|
this.logError(e);
|
88
|
-
this.setState(
|
88
|
+
this.setState(constants_1.StateType.Idle);
|
89
89
|
}
|
90
90
|
}
|
91
91
|
async downloadUpdate(executeType = constants_1.ExecuteType.User) {
|
92
92
|
this.logger.info(`ElectronUpdator#downloadUpdate:executeType is ${executeType}`);
|
93
|
-
await this.downloadUpdateFile(this.updateInfo);
|
94
|
-
const result = await this.preCheck();
|
93
|
+
await this.downloadUpdateFile(this.updateInfo, executeType);
|
94
|
+
const result = await this.preCheck(executeType);
|
95
95
|
if (result.success) {
|
96
96
|
this.logger.info('ElectronUpdator#downloadUpdate:emit UPDATE_DOWNLOADED');
|
97
97
|
this.emit(constants_1.EventType.UPDATE_DOWNLOADED, {
|
@@ -100,16 +100,16 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
100
100
|
}
|
101
101
|
else {
|
102
102
|
this.logError(result.error);
|
103
|
-
this.setState(
|
103
|
+
this.setState(constants_1.StateType.Idle);
|
104
104
|
}
|
105
105
|
}
|
106
106
|
async quitAndInstall() {
|
107
107
|
this.logger.info(`ElectronUpdator#quitAndInstall:state is ${this.state}`);
|
108
|
-
if (this.state !==
|
108
|
+
if (this.state !== constants_1.StateType.Downloaded) {
|
109
109
|
this.downloadUpdate();
|
110
110
|
return;
|
111
111
|
}
|
112
|
-
this.setState(
|
112
|
+
this.setState(constants_1.StateType.Idle);
|
113
113
|
try {
|
114
114
|
let result = { success: false };
|
115
115
|
if (this.updateInfo?.updateType === constants_1.UpdateType.Package) {
|
@@ -135,10 +135,10 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
135
135
|
this.logger.info('ElectronUpdator#preCheckForAsar');
|
136
136
|
return await this.unzip();
|
137
137
|
}
|
138
|
-
async preCheck() {
|
138
|
+
async preCheck(executeType) {
|
139
139
|
this.logger.info('ElectronUpdator#preCheck');
|
140
140
|
const { resourcePath } = this.availableUpdate;
|
141
|
-
if (this.state !==
|
141
|
+
if (this.state !== constants_1.StateType.Downloaded) {
|
142
142
|
return {
|
143
143
|
success: false,
|
144
144
|
error: new Error(`ElectronUpdator#preCheck:update status(${this.state}) error`),
|
@@ -171,20 +171,23 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
171
171
|
};
|
172
172
|
}
|
173
173
|
if (this.updateInfo?.updateType === constants_1.UpdateType.Package) {
|
174
|
-
|
174
|
+
if (executeType === constants_1.ExecuteType.Auto) {
|
175
|
+
// 自动安装时,才进行预检查,提升安装效率
|
176
|
+
result = await this.doPreCheckForPackage();
|
177
|
+
}
|
175
178
|
}
|
176
179
|
else {
|
177
180
|
result = await this.preCheckForAsar();
|
178
181
|
}
|
179
182
|
return result;
|
180
183
|
}
|
181
|
-
async downloadUpdateFile(updateInfo) {
|
182
|
-
if (this.state !==
|
184
|
+
async downloadUpdateFile(updateInfo, executeType) {
|
185
|
+
if (this.state !== constants_1.StateType.CheckingForUpdate) {
|
183
186
|
throw new Error(`ElectronUpdator#downloadUpdateFile:update status(${this.state}) error`);
|
184
187
|
}
|
185
188
|
const { url, signature } = updateInfo.files[0];
|
186
189
|
const { downloadTargetDir } = this.availableUpdate;
|
187
|
-
this.setState(
|
190
|
+
this.setState(constants_1.StateType.Downloading);
|
188
191
|
try {
|
189
192
|
await (0, download_file_1.downloadFile)({
|
190
193
|
logger: this.logger,
|
@@ -193,14 +196,14 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
193
196
|
targetDir: downloadTargetDir,
|
194
197
|
emit: this.emit,
|
195
198
|
progressHandle: (data) => {
|
196
|
-
this.emit(constants_1.EventType.UPDATE_DOWNLOAD_PROGRESS, data);
|
199
|
+
this.emit(constants_1.EventType.UPDATE_DOWNLOAD_PROGRESS, { ...data, executeType });
|
197
200
|
},
|
198
201
|
});
|
199
202
|
this.logger.info('ElectronUpdator#downloadUpdateFile:Downloaded');
|
200
|
-
this.setState(
|
203
|
+
this.setState(constants_1.StateType.Downloaded);
|
201
204
|
}
|
202
205
|
catch (e) {
|
203
|
-
this.setState(
|
206
|
+
this.setState(constants_1.StateType.Idle);
|
204
207
|
e.customMessage = `${constants_1.InstallResultType.DownloadError}_${e.message}`;
|
205
208
|
this.logError(e);
|
206
209
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.EventType = exports.DownloadProgressStatus = exports.ExecuteType = exports.UpdateType = exports.InstallResultType = exports.OldArchivePrefix = void 0;
|
3
|
+
exports.EventType = exports.DownloadProgressStatus = exports.ExecuteType = exports.UpdateType = exports.StateType = exports.InstallResultType = exports.OldArchivePrefix = void 0;
|
4
4
|
/**
|
5
5
|
* 更新包备份前缀
|
6
6
|
*/
|
@@ -15,6 +15,28 @@ var InstallResultType;
|
|
15
15
|
InstallResultType["UpdateSuccess"] = "update-success";
|
16
16
|
InstallResultType["CheckForUpdatesError"] = "check-for-updates-error";
|
17
17
|
})(InstallResultType = exports.InstallResultType || (exports.InstallResultType = {}));
|
18
|
+
/**
|
19
|
+
* 更新状态
|
20
|
+
*/
|
21
|
+
var StateType;
|
22
|
+
(function (StateType) {
|
23
|
+
/**
|
24
|
+
* 空闲
|
25
|
+
*/
|
26
|
+
StateType["Idle"] = "idle";
|
27
|
+
/**
|
28
|
+
* 检查更新中
|
29
|
+
*/
|
30
|
+
StateType["CheckingForUpdate"] = "checking-for-update";
|
31
|
+
/**
|
32
|
+
* 下载中
|
33
|
+
*/
|
34
|
+
StateType["Downloading"] = "downloading";
|
35
|
+
/**
|
36
|
+
* 下载完成
|
37
|
+
*/
|
38
|
+
StateType["Downloaded"] = "downloaded";
|
39
|
+
})(StateType = exports.StateType || (exports.StateType = {}));
|
18
40
|
/**
|
19
41
|
* 更新类型
|
20
42
|
*/
|
package/build/index.js
CHANGED
@@ -4,7 +4,12 @@ const constants_1 = require("./common/constants");
|
|
4
4
|
const mac_updator_1 = require("./mac-updator");
|
5
5
|
const windows_updator_1 = require("./windows-updator");
|
6
6
|
exports.default = {
|
7
|
-
UpdateType: constants_1.UpdateType,
|
8
|
-
|
7
|
+
UpdateType: constants_1.UpdateType,
|
8
|
+
EventType: constants_1.EventType,
|
9
|
+
ExecuteType: constants_1.ExecuteType,
|
10
|
+
StateType: constants_1.StateType,
|
11
|
+
MacUpdator: mac_updator_1.MacUpdator,
|
12
|
+
WindowsUpdator: windows_updator_1.WindowsUpdator,
|
13
|
+
DownloadProgressStatus: constants_1.DownloadProgressStatus,
|
9
14
|
};
|
10
15
|
//# sourceMappingURL=index.js.map
|
package/build/mac-updator.js
CHANGED
@@ -10,9 +10,6 @@ const constants_1 = require("./common/constants");
|
|
10
10
|
const install_macos_dmg_1 = __importDefault(require("./utils/install-macos-dmg"));
|
11
11
|
const utils_1 = require("./utils");
|
12
12
|
class MacUpdator extends app_updator_1.AppUpdator {
|
13
|
-
constructor(options) {
|
14
|
-
super(options);
|
15
|
-
}
|
16
13
|
doGetAvailableUpdateInfo(updateInfo) {
|
17
14
|
this.logger.info('MacUpdator#doGetAvailableUpdateInfo:start');
|
18
15
|
const exePath = this.app.exePath;
|
@@ -51,6 +51,7 @@ exports.default = async (updatorOptions, logger, availableUpdate, updateInfo, pr
|
|
51
51
|
if (preCheck) {
|
52
52
|
_log(logger, error);
|
53
53
|
}
|
54
|
+
// eslint-disable-next-line
|
54
55
|
return {
|
55
56
|
success: false,
|
56
57
|
error,
|
@@ -75,6 +76,7 @@ exports.default = async (updatorOptions, logger, availableUpdate, updateInfo, pr
|
|
75
76
|
if (preCheck) {
|
76
77
|
_log(logger, error);
|
77
78
|
}
|
79
|
+
// eslint-disable-next-line
|
78
80
|
return {
|
79
81
|
success: false,
|
80
82
|
error,
|
@@ -109,6 +111,7 @@ exports.default = async (updatorOptions, logger, availableUpdate, updateInfo, pr
|
|
109
111
|
});
|
110
112
|
if (!tmpPathExist) {
|
111
113
|
const error = new Error('cp to tmp path fail');
|
114
|
+
// eslint-disable-next-line
|
112
115
|
return {
|
113
116
|
success: false,
|
114
117
|
error,
|
@@ -131,6 +134,7 @@ exports.default = async (updatorOptions, logger, availableUpdate, updateInfo, pr
|
|
131
134
|
if (!appExist) {
|
132
135
|
const error = new Error('cp to app fail');
|
133
136
|
await (0, index_1.spawnAsync)('mv', [tmpPath, appPath]);
|
137
|
+
// eslint-disable-next-line
|
134
138
|
return {
|
135
139
|
success: false,
|
136
140
|
error,
|
@@ -8,7 +8,7 @@ function sudoPromptExec(appUpdatorOptions, logger, shell) {
|
|
8
8
|
};
|
9
9
|
return new Promise((resolve, reject) => {
|
10
10
|
logger.warn(`update#sudoPromptExec_shell_${shell}`);
|
11
|
-
index_1.sudoPrompt.exec(shell, options, (error, stdout
|
11
|
+
index_1.sudoPrompt.exec(shell, options, (error, stdout) => {
|
12
12
|
if (error) {
|
13
13
|
reject(error);
|
14
14
|
logger.error(`update#sudoPromptExec_error_${error}`);
|
package/build/windows-updator.js
CHANGED
@@ -13,7 +13,7 @@ const utils_1 = require("./utils");
|
|
13
13
|
class WindowsUpdator extends app_updator_1.AppUpdator {
|
14
14
|
doGetAvailableUpdateInfo(updateInfo) {
|
15
15
|
this.logger.info('WindowsUpdator#doGetAvailableUpdateInfo:start');
|
16
|
-
|
16
|
+
const 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');
|
19
19
|
let downloadTargetDir = `${latestAsarPath}.zip`;
|
package/package.json
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "electron-updator",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.6",
|
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",
|
7
7
|
"test": "egg-bin test test/**/index.test.ts",
|
8
|
-
"lint": "eslint --fix --quiet --ext .js,.
|
8
|
+
"lint": "eslint --fix --quiet --ext .js,.ts ./src",
|
9
9
|
"prepublishOnly": "npm run build",
|
10
10
|
"contributor": "git-contributor",
|
11
11
|
"dev": "ttsc -p tsconfig.json -watch"
|
@@ -48,8 +48,8 @@
|
|
48
48
|
"electron": "18",
|
49
49
|
"electron-windows": "18",
|
50
50
|
"eslint": "^7.32.0",
|
51
|
-
"eslint-config-egg": "^
|
52
|
-
"eslint-plugin-no-only-tests": "^
|
51
|
+
"eslint-config-egg": "^12.1.0",
|
52
|
+
"eslint-plugin-no-only-tests": "^3.1.0",
|
53
53
|
"git-contributor": "*",
|
54
54
|
"husky": "^7.0.4",
|
55
55
|
"mm": "^3.0.2",
|
@@ -69,4 +69,4 @@
|
|
69
69
|
}
|
70
70
|
},
|
71
71
|
"license": "MIT"
|
72
|
-
}
|
72
|
+
}
|