graceful-updater 1.1.2-beta.0 → 1.1.2
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 +0 -22
- package/build/mac-updator copy.js +120 -0
- package/build/mac-updator.js +8 -18
- package/build/windows-updator.js +0 -6
- package/package.json +2 -2
package/build/app-updator.js
CHANGED
@@ -136,28 +136,6 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
|
|
136
136
|
this.dispatchError(e);
|
137
137
|
}
|
138
138
|
}
|
139
|
-
async install() {
|
140
|
-
this.logger.info(`install:state is ${this.state}`);
|
141
|
-
let result = { success: false };
|
142
|
-
this.setState(constants_1.StateType.Idle);
|
143
|
-
try {
|
144
|
-
this.emit(constants_1.EventType.BEFORE_QUIT_FOR_UPDATE);
|
145
|
-
if (this.updateInfo?.updateType === constants_1.UpdateType.Package) {
|
146
|
-
result = await this.doInstallPackage();
|
147
|
-
}
|
148
|
-
else {
|
149
|
-
result = await this.doInstallAsar();
|
150
|
-
}
|
151
|
-
if (!result.success) {
|
152
|
-
result.message = `error: ${result.error?.message}`;
|
153
|
-
this.dispatchError(result.error);
|
154
|
-
}
|
155
|
-
}
|
156
|
-
catch (e) {
|
157
|
-
this.dispatchError(e);
|
158
|
-
}
|
159
|
-
return result;
|
160
|
-
}
|
161
139
|
async preCheckForAsar() {
|
162
140
|
this.logger.info('preCheckForAsar');
|
163
141
|
return await this.unzip();
|
@@ -0,0 +1,120 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.MacUpdator = void 0;
|
7
|
+
const path_1 = __importDefault(require("path"));
|
8
|
+
const app_updator_1 = require("./app-updator");
|
9
|
+
const constants_1 = require("./common/constants");
|
10
|
+
const install_macos_dmg_1 = __importDefault(require("./utils/install-macos-dmg"));
|
11
|
+
const utils_1 = require("./utils");
|
12
|
+
class MacUpdator extends app_updator_1.AppUpdator {
|
13
|
+
doGetAvailableUpdateInfo(updateInfo) {
|
14
|
+
this.logger.info('MacUpdator#doGetAvailableUpdateInfo:start');
|
15
|
+
const resourcePath = path_1.default.resolve(this.app.userDataPath);
|
16
|
+
const latestAsarPath = path_1.default.resolve(resourcePath, constants_1.FileName.TARGET_REPLACEMENT_ASAR);
|
17
|
+
const latestAppPath = path_1.default.resolve(resourcePath, 'latest');
|
18
|
+
let downloadTargetDir = `${latestAsarPath}.zip`;
|
19
|
+
if (updateInfo.updateType === constants_1.UpdateType.Package) {
|
20
|
+
downloadTargetDir = `${latestAppPath}.dmg`;
|
21
|
+
}
|
22
|
+
return {
|
23
|
+
resourcePath,
|
24
|
+
downloadTargetDir,
|
25
|
+
latestAsarPath,
|
26
|
+
};
|
27
|
+
}
|
28
|
+
async doPreCheckForPackage() {
|
29
|
+
this.logger.info('MacUpdator#doPreCheckForPackage:start');
|
30
|
+
// Mac 全量安装前,先进行 dmg 安装检查
|
31
|
+
return await (0, install_macos_dmg_1.default)(this.options, this.logger, this.availableUpdate, this.updateInfo, true);
|
32
|
+
}
|
33
|
+
/**
|
34
|
+
* 资源解压
|
35
|
+
* @return
|
36
|
+
*/
|
37
|
+
async doUnzip() {
|
38
|
+
const { resourcePath, downloadTargetDir, latestAsarPath } = this.availableUpdate;
|
39
|
+
this.logger.info('MacUpdator#doUnzip:start, unzip %s, to %s', downloadTargetDir, resourcePath);
|
40
|
+
try {
|
41
|
+
// 直接解压
|
42
|
+
await (0, utils_1.execAsync)(`unzip -o '${downloadTargetDir}'`, {
|
43
|
+
cwd: resourcePath,
|
44
|
+
maxBuffer: 2 ** 28,
|
45
|
+
});
|
46
|
+
if (!await (0, utils_1.existsAsync)(latestAsarPath)) {
|
47
|
+
const zipInfo = await (0, utils_1.execAsync)(`unzip -Z -1 '${downloadTargetDir}'`, {
|
48
|
+
cwd: resourcePath,
|
49
|
+
maxBuffer: 2 ** 28,
|
50
|
+
});
|
51
|
+
const fileName = zipInfo?.stdout?.trim();
|
52
|
+
if (fileName !== constants_1.FileName.TARGET_REPLACEMENT_ASAR) {
|
53
|
+
const currentAsarPath = path_1.default.join(resourcePath, fileName);
|
54
|
+
await (0, utils_1.renameAsync)(currentAsarPath, latestAsarPath);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
return {
|
58
|
+
success: true,
|
59
|
+
};
|
60
|
+
}
|
61
|
+
catch (error) {
|
62
|
+
return {
|
63
|
+
success: false,
|
64
|
+
error,
|
65
|
+
};
|
66
|
+
}
|
67
|
+
}
|
68
|
+
async doQuitAndInstallAsar() {
|
69
|
+
this.logger.info('MacUpdator#doQuitAndInstallAsar:start');
|
70
|
+
if (!this.availableUpdate) {
|
71
|
+
this.logger.error('MacUpdator#doQuitAndInstallAsar:not availableUpdate');
|
72
|
+
return Promise.resolve({ success: false });
|
73
|
+
}
|
74
|
+
const { resourcePath, latestAsarPath } = this.availableUpdate;
|
75
|
+
const oldAsarPath = path_1.default.resolve(resourcePath, `${constants_1.OldArchivePrefix}${new Date().getTime()}.asar`);
|
76
|
+
const exePath = this.app.exePath;
|
77
|
+
const currentPath = path_1.default.resolve(exePath, '..', '..', 'Resources');
|
78
|
+
const currentAsarPath = path_1.default.resolve(currentPath, 'app.asar');
|
79
|
+
try {
|
80
|
+
// 将老包改名 app.asar => old-xxxx.asar
|
81
|
+
if (await (0, utils_1.existsAsync)(currentAsarPath)) {
|
82
|
+
await (0, utils_1.renameAsync)(currentAsarPath, oldAsarPath);
|
83
|
+
}
|
84
|
+
}
|
85
|
+
catch (error) {
|
86
|
+
return {
|
87
|
+
success: false,
|
88
|
+
error,
|
89
|
+
};
|
90
|
+
}
|
91
|
+
try {
|
92
|
+
// 新包替换
|
93
|
+
await (0, utils_1.renameAsync)(latestAsarPath, currentAsarPath);
|
94
|
+
}
|
95
|
+
catch (error) {
|
96
|
+
// 替换出错,需要把老包还原
|
97
|
+
await (0, utils_1.renameAsync)(oldAsarPath, currentAsarPath);
|
98
|
+
return {
|
99
|
+
success: false,
|
100
|
+
error,
|
101
|
+
};
|
102
|
+
}
|
103
|
+
this.logger.warn('MacUpdator#quitAndInstall:install success');
|
104
|
+
this.app.relaunch();
|
105
|
+
return {
|
106
|
+
success: true,
|
107
|
+
};
|
108
|
+
}
|
109
|
+
async doQuitAndInstallPackage() {
|
110
|
+
this.logger.info('MacUpdator#doQuitAndInstallPackage:start');
|
111
|
+
const result = await (0, install_macos_dmg_1.default)(this.options, this.logger, this.availableUpdate, this.updateInfo);
|
112
|
+
if (result.success) {
|
113
|
+
this.logger.warn('quitAndInstall:install success');
|
114
|
+
this.app.relaunch();
|
115
|
+
}
|
116
|
+
return result;
|
117
|
+
}
|
118
|
+
}
|
119
|
+
exports.MacUpdator = MacUpdator;
|
120
|
+
//# sourceMappingURL=mac-updator%20copy.js.map
|
package/build/mac-updator.js
CHANGED
@@ -12,12 +12,12 @@ const utils_1 = require("./utils");
|
|
12
12
|
class MacUpdator extends app_updator_1.AppUpdator {
|
13
13
|
doGetAvailableUpdateInfo(updateInfo) {
|
14
14
|
this.logger.info('MacUpdator#doGetAvailableUpdateInfo:start');
|
15
|
-
const
|
15
|
+
const exePath = this.app.exePath;
|
16
|
+
const resourcePath = path_1.default.resolve(exePath, '..', '..', 'Resources');
|
16
17
|
const latestAsarPath = path_1.default.resolve(resourcePath, constants_1.FileName.TARGET_REPLACEMENT_ASAR);
|
17
|
-
const latestAppPath = path_1.default.resolve(resourcePath, 'latest');
|
18
18
|
let downloadTargetDir = `${latestAsarPath}.zip`;
|
19
19
|
if (updateInfo.updateType === constants_1.UpdateType.Package) {
|
20
|
-
downloadTargetDir =
|
20
|
+
downloadTargetDir = path_1.default.resolve(path_1.default.resolve(this.app.userDataPath), 'latest.dmg');
|
21
21
|
}
|
22
22
|
return {
|
23
23
|
resourcePath,
|
@@ -66,14 +66,6 @@ class MacUpdator extends app_updator_1.AppUpdator {
|
|
66
66
|
}
|
67
67
|
}
|
68
68
|
async doQuitAndInstallAsar() {
|
69
|
-
const result = await this.doInstallAsar();
|
70
|
-
if (result.success) {
|
71
|
-
this.logger.warn('MacUpdator#quitAndInstall:install success');
|
72
|
-
this.app.relaunch();
|
73
|
-
}
|
74
|
-
return result;
|
75
|
-
}
|
76
|
-
async doInstallAsar() {
|
77
69
|
this.logger.info('MacUpdator#doQuitAndInstallAsar:start');
|
78
70
|
if (!this.availableUpdate) {
|
79
71
|
this.logger.error('MacUpdator#doQuitAndInstallAsar:not availableUpdate');
|
@@ -106,23 +98,21 @@ class MacUpdator extends app_updator_1.AppUpdator {
|
|
106
98
|
error,
|
107
99
|
};
|
108
100
|
}
|
101
|
+
this.logger.warn('MacUpdator#quitAndInstall:install success');
|
102
|
+
this.app.relaunch();
|
109
103
|
return {
|
110
104
|
success: true,
|
111
105
|
};
|
112
106
|
}
|
113
107
|
async doQuitAndInstallPackage() {
|
114
|
-
|
108
|
+
this.logger.info('MacUpdator#doQuitAndInstallPackage:start');
|
109
|
+
const result = await (0, install_macos_dmg_1.default)(this.options, this.logger, this.availableUpdate, this.updateInfo);
|
115
110
|
if (result.success) {
|
116
|
-
this.logger.warn('
|
111
|
+
this.logger.warn('quitAndInstall:install success');
|
117
112
|
this.app.relaunch();
|
118
113
|
}
|
119
114
|
return result;
|
120
115
|
}
|
121
|
-
async doInstallPackage() {
|
122
|
-
this.logger.info('MacUpdator#doQuitAndInstallPackage:start');
|
123
|
-
const result = await (0, install_macos_dmg_1.default)(this.options, this.logger, this.availableUpdate, this.updateInfo);
|
124
|
-
return result;
|
125
|
-
}
|
126
116
|
}
|
127
117
|
exports.MacUpdator = MacUpdator;
|
128
118
|
//# sourceMappingURL=mac-updator.js.map
|
package/build/windows-updator.js
CHANGED
@@ -63,9 +63,6 @@ class WindowsUpdator extends app_updator_1.AppUpdator {
|
|
63
63
|
success: true,
|
64
64
|
};
|
65
65
|
}
|
66
|
-
async doInstallPackage() {
|
67
|
-
return { success: false };
|
68
|
-
}
|
69
66
|
async doQuitAndInstallPackage() {
|
70
67
|
this.logger.info('WindowsUpdator#doQuitAndInstallPackage:success');
|
71
68
|
const { downloadTargetDir } = this.availableUpdate;
|
@@ -83,9 +80,6 @@ class WindowsUpdator extends app_updator_1.AppUpdator {
|
|
83
80
|
return Promise.resolve({ success: false, error });
|
84
81
|
}
|
85
82
|
}
|
86
|
-
async doInstallAsar() {
|
87
|
-
return { success: false };
|
88
|
-
}
|
89
83
|
async doQuitAndInstallAsar() {
|
90
84
|
this.logger.info('WindowsUpdator#doQuitAndInstallAsar:start');
|
91
85
|
const productName = this.options?.productName;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "graceful-updater",
|
3
|
-
"version": "1.1.2
|
3
|
+
"version": "1.1.2",
|
4
4
|
"description": "graceful-updater 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",
|
@@ -70,4 +70,4 @@
|
|
70
70
|
}
|
71
71
|
},
|
72
72
|
"license": "MIT"
|
73
|
-
}
|
73
|
+
}
|