graceful-updater 1.1.2 → 1.2.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graceful-updater",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
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",
@@ -24,7 +24,7 @@
24
24
  "url": "https://github.com/electron-modules/graceful-updater"
25
25
  },
26
26
  "dependencies": {
27
- "eventemitter3": "^4.0.0",
27
+ "eventemitter3": "4",
28
28
  "graceful-updater-windows-helper": "1",
29
29
  "lodash": "4",
30
30
  "moment": "2",
@@ -1,120 +0,0 @@
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