graceful-updater 1.1.1 → 1.1.2-beta.1
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 -0
- package/build/mac-updator.js +21 -10
- package/build/windows-updator.js +6 -0
- package/package.json +2 -2
package/build/app-updator.js
CHANGED
@@ -136,6 +136,28 @@ 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
|
+
}
|
139
161
|
async preCheckForAsar() {
|
140
162
|
this.logger.info('preCheckForAsar');
|
141
163
|
return await this.unzip();
|
package/build/mac-updator.js
CHANGED
@@ -12,8 +12,7 @@ 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
|
16
|
-
const resourcePath = path_1.default.resolve(exePath, '..', '..', 'Resources');
|
15
|
+
const resourcePath = path_1.default.resolve(this.app.userDataPath);
|
17
16
|
const latestAsarPath = path_1.default.resolve(resourcePath, constants_1.FileName.TARGET_REPLACEMENT_ASAR);
|
18
17
|
const latestAppPath = path_1.default.resolve(resourcePath, 'latest');
|
19
18
|
let downloadTargetDir = `${latestAsarPath}.zip`;
|
@@ -40,12 +39,12 @@ class MacUpdator extends app_updator_1.AppUpdator {
|
|
40
39
|
this.logger.info('MacUpdator#doUnzip:start, unzip %s, to %s', downloadTargetDir, resourcePath);
|
41
40
|
try {
|
42
41
|
// 直接解压
|
43
|
-
await (0, utils_1.execAsync)(`unzip -o ${downloadTargetDir}`, {
|
42
|
+
await (0, utils_1.execAsync)(`unzip -o '${downloadTargetDir}'`, {
|
44
43
|
cwd: resourcePath,
|
45
44
|
maxBuffer: 2 ** 28,
|
46
45
|
});
|
47
46
|
if (!await (0, utils_1.existsAsync)(latestAsarPath)) {
|
48
|
-
const zipInfo = await (0, utils_1.execAsync)(`unzip -Z -1 ${downloadTargetDir}`, {
|
47
|
+
const zipInfo = await (0, utils_1.execAsync)(`unzip -Z -1 '${downloadTargetDir}'`, {
|
49
48
|
cwd: resourcePath,
|
50
49
|
maxBuffer: 2 ** 28,
|
51
50
|
});
|
@@ -67,6 +66,14 @@ class MacUpdator extends app_updator_1.AppUpdator {
|
|
67
66
|
}
|
68
67
|
}
|
69
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() {
|
70
77
|
this.logger.info('MacUpdator#doQuitAndInstallAsar:start');
|
71
78
|
if (!this.availableUpdate) {
|
72
79
|
this.logger.error('MacUpdator#doQuitAndInstallAsar:not availableUpdate');
|
@@ -74,7 +81,9 @@ class MacUpdator extends app_updator_1.AppUpdator {
|
|
74
81
|
}
|
75
82
|
const { resourcePath, latestAsarPath } = this.availableUpdate;
|
76
83
|
const oldAsarPath = path_1.default.resolve(resourcePath, `${constants_1.OldArchivePrefix}${new Date().getTime()}.asar`);
|
77
|
-
const
|
84
|
+
const exePath = this.app.exePath;
|
85
|
+
const currentPath = path_1.default.resolve(exePath, '..', '..', 'Resources');
|
86
|
+
const currentAsarPath = path_1.default.resolve(currentPath, 'app.asar');
|
78
87
|
try {
|
79
88
|
// 将老包改名 app.asar => old-xxxx.asar
|
80
89
|
if (await (0, utils_1.existsAsync)(currentAsarPath)) {
|
@@ -99,21 +108,23 @@ class MacUpdator extends app_updator_1.AppUpdator {
|
|
99
108
|
error,
|
100
109
|
};
|
101
110
|
}
|
102
|
-
this.logger.warn('MacUpdator#quitAndInstall:install success');
|
103
|
-
this.app.relaunch();
|
104
111
|
return {
|
105
112
|
success: true,
|
106
113
|
};
|
107
114
|
}
|
108
115
|
async doQuitAndInstallPackage() {
|
109
|
-
this.
|
110
|
-
const result = await (0, install_macos_dmg_1.default)(this.options, this.logger, this.availableUpdate, this.updateInfo);
|
116
|
+
const result = await this.doInstallPackage();
|
111
117
|
if (result.success) {
|
112
|
-
this.logger.warn('quitAndInstall:install success');
|
118
|
+
this.logger.warn('MacUpdator#quitAndInstall:install success');
|
113
119
|
this.app.relaunch();
|
114
120
|
}
|
115
121
|
return result;
|
116
122
|
}
|
123
|
+
async doInstallPackage() {
|
124
|
+
this.logger.info('MacUpdator#doQuitAndInstallPackage:start');
|
125
|
+
const result = await (0, install_macos_dmg_1.default)(this.options, this.logger, this.availableUpdate, this.updateInfo);
|
126
|
+
return result;
|
127
|
+
}
|
117
128
|
}
|
118
129
|
exports.MacUpdator = MacUpdator;
|
119
130
|
//# sourceMappingURL=mac-updator.js.map
|
package/build/windows-updator.js
CHANGED
@@ -63,6 +63,9 @@ class WindowsUpdator extends app_updator_1.AppUpdator {
|
|
63
63
|
success: true,
|
64
64
|
};
|
65
65
|
}
|
66
|
+
async doInstallPackage() {
|
67
|
+
return { success: false };
|
68
|
+
}
|
66
69
|
async doQuitAndInstallPackage() {
|
67
70
|
this.logger.info('WindowsUpdator#doQuitAndInstallPackage:success');
|
68
71
|
const { downloadTargetDir } = this.availableUpdate;
|
@@ -80,6 +83,9 @@ class WindowsUpdator extends app_updator_1.AppUpdator {
|
|
80
83
|
return Promise.resolve({ success: false, error });
|
81
84
|
}
|
82
85
|
}
|
86
|
+
async doInstallAsar() {
|
87
|
+
return { success: false };
|
88
|
+
}
|
83
89
|
async doQuitAndInstallAsar() {
|
84
90
|
this.logger.info('WindowsUpdator#doQuitAndInstallAsar:start');
|
85
91
|
const productName = this.options?.productName;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "graceful-updater",
|
3
|
-
"version": "1.1.1",
|
3
|
+
"version": "1.1.2-beta.1",
|
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
|
+
}
|