graceful-updater 1.1.1-beta.0 → 1.1.1-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.
@@ -13,6 +13,7 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
13
13
  this.state = constants_1.StateType.Idle;
14
14
  this.options = options;
15
15
  this.logger = this._wrapLogger(options.logger);
16
+ this._windowHelperExeDir = this.options.getWindowsHelperExeDir?.();
16
17
  this.app = app || new elelctron_app_adapter_1.ElectronAppAdapter();
17
18
  this.startUuid = this._getStartUuid();
18
19
  this.logger.info('constructor');
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.requestUpdateInfo = exports.existFile = exports.cleanOldArchive = exports.spawnAsync = exports.waitUntil = exports.sleep = exports.getMacOSAppPath = exports.sudoPrompt = exports.existsSync = exports.createWriteStream = exports.isMac = exports.isWin = exports.execAsync = exports.rimrafAsync = exports.readdirAsync = exports.existsAsync = exports.renameAsync = void 0;
6
+ exports.getExecuteFile = exports.requestUpdateInfo = exports.existFile = exports.cleanOldArchive = exports.spawnAsync = exports.waitUntil = exports.sleep = exports.getMacOSAppPath = exports.sudoPrompt = exports.existsSync = exports.createWriteStream = exports.isMac = exports.isWin = exports.execAsync = exports.rimrafAsync = exports.readdirAsync = exports.existsAsync = exports.renameAsync = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const util_1 = __importDefault(require("util"));
9
9
  const urllib_1 = __importDefault(require("urllib"));
@@ -115,4 +115,8 @@ const requestUpdateInfo = async (options) => {
115
115
  return res.data;
116
116
  };
117
117
  exports.requestUpdateInfo = requestUpdateInfo;
118
+ const getExecuteFile = (helperExeFileDir, file) => {
119
+ return path_1.default.join(helperExeFileDir, file);
120
+ };
121
+ exports.getExecuteFile = getExecuteFile;
118
122
  //# sourceMappingURL=index.js.map
@@ -36,10 +36,10 @@ class WindowsUpdator extends app_updator_1.AppUpdator {
36
36
  const { downloadTargetDir, resourcePath, latestAsarPath } = this.availableUpdate;
37
37
  this.logger.info('WindowsUpdator#doUnzip:start');
38
38
  try {
39
- const unzipExe = graceful_updater_windows_helper_1.unzipExeFilePath;
39
+ const unzipExe = (0, utils_1.getExecuteFile)(this._windowHelperExeDir, graceful_updater_windows_helper_1.unzipExeFileName);
40
40
  const executeCommand = `"${unzipExe}" -o "${downloadTargetDir}" -d "${resourcePath}"`;
41
41
  await (0, utils_1.execAsync)(executeCommand);
42
- if (!await (0, utils_1.existsAsync)(latestAsarPath)) {
42
+ if (!(await (0, utils_1.existsAsync)(latestAsarPath))) {
43
43
  const zipInfoCommand = `"${unzipExe}" -Z -1 "${downloadTargetDir}"`;
44
44
  const zipInfo = await (0, utils_1.execAsync)(zipInfoCommand, {
45
45
  cwd: resourcePath,
@@ -85,7 +85,7 @@ class WindowsUpdator extends app_updator_1.AppUpdator {
85
85
  const productName = this.options?.productName;
86
86
  const { resourcePath } = this.availableUpdate;
87
87
  const exePath = this.app.exePath;
88
- const updateExePath = graceful_updater_windows_helper_1.installerExeFilePath;
88
+ const updateExePath = (0, utils_1.getExecuteFile)(this._windowHelperExeDir, graceful_updater_windows_helper_1.installerExeFileName);
89
89
  const targetPath = path_1.default.resolve(exePath, '..', 'resources');
90
90
  const executeCommand = `"${updateExePath}" "${targetPath}" "${resourcePath}" "${productName}.exe" "${exePath}"`;
91
91
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graceful-updater",
3
- "version": "1.1.1-beta.0",
3
+ "version": "1.1.1-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",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "eventemitter3": "^4.0.0",
28
- "graceful-updater-windows-helper": "1.0.3-beta.0",
28
+ "graceful-updater-windows-helper": "1.0.3-beta.1",
29
29
  "lodash": "4",
30
30
  "moment": "2",
31
31
  "nanoid": "^3.3.4",
@@ -1,143 +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
- const os_1 = __importDefault(require("os"));
7
- const path_1 = __importDefault(require("path"));
8
- const _1 = require(".");
9
- const index_1 = require("./index");
10
- const _log = (logger, e) => {
11
- const message = (e.stack || e).toString();
12
- logger.error?.(message);
13
- };
14
- exports.default = async (updatorOptions, logger, availableUpdate, updateInfo, preCheck = false) => {
15
- const { productName } = updatorOptions || {};
16
- const { downloadTargetDir } = availableUpdate || {};
17
- const appPath = (0, _1.getMacOSAppPath)();
18
- const tmpPath = path_1.default.join(os_1.default.tmpdir(), String(new Date().getTime())); // 本地临时文件使用的目录
19
- const volumesPath = path_1.default.join('/Volumes', updatorOptions.dmgTitleFormatter ? updatorOptions.dmgTitleFormatter(updatorOptions, updateInfo) : productName);
20
- const volumesAppPath = path_1.default.join(volumesPath, `${productName}.app`);
21
- // step 1: 检测是否支持 hdiutil;
22
- try {
23
- const res = (await (0, index_1.spawnAsync)('which', ['hdiutil']));
24
- if (!res.includes('/bin/hdiutil')) {
25
- throw new Error('hdiutil not found');
26
- }
27
- }
28
- catch (error) {
29
- if (preCheck) {
30
- _log(logger, error);
31
- }
32
- return {
33
- success: false,
34
- error,
35
- };
36
- }
37
- // step 2: eject 一次 volume 下的 app,兜底,避免上一次结束时执行失败
38
- try {
39
- await (0, index_1.spawnAsync)('hdiutil', ['eject', volumesPath]);
40
- }
41
- catch (e) {
42
- // 如果前一次更新时 eject 成功,这里文件不存在会报错,是个正常的 case,不用处理上报
43
- }
44
- const volumeAppNotExist = await (0, _1.waitUntil)(() => !(0, index_1.existsSync)(volumesAppPath), {
45
- ms: 300,
46
- retryTime: 5,
47
- });
48
- if (!volumeAppNotExist) {
49
- const error = new Error('volume not exists');
50
- if (preCheck) {
51
- _log(logger, error);
52
- }
53
- return {
54
- success: false,
55
- error,
56
- };
57
- }
58
- // step 3: 执行 hdiutil attach,挂载 dmg
59
- try {
60
- await (0, index_1.spawnAsync)('hdiutil', ['attach', downloadTargetDir]);
61
- }
62
- catch (error) {
63
- _log(logger, error);
64
- }
65
- // 判断有没有新的 dmg 文件,没有的话提示用户重新下载
66
- const volumeAppExist = await (0, _1.waitUntil)(() => (0, index_1.existsSync)(volumesAppPath), {
67
- ms: 300,
68
- retryTime: 5,
69
- });
70
- if (!volumeAppExist) {
71
- const error = new Error('attach fail');
72
- if (preCheck) {
73
- _log(logger, error);
74
- }
75
- return {
76
- success: false,
77
- error,
78
- };
79
- }
80
- if (preCheck) {
81
- // 如果是预检查,直接返回
82
- try {
83
- await (0, index_1.spawnAsync)('hdiutil', ['eject', volumesPath]);
84
- }
85
- catch (error) {
86
- _log(logger, error);
87
- }
88
- return {
89
- success: true,
90
- };
91
- }
92
- // step 4: 将当前目录下的 app 移到临时目录,如果后续操作失败了兜底用
93
- try {
94
- await (0, index_1.spawnAsync)('mv', [appPath, tmpPath]);
95
- }
96
- catch (error) {
97
- error.customMessage = 'step4 mv to tmp path error';
98
- _log(logger, error);
99
- }
100
- // 看临时目录文件是否移动成功
101
- const tmpPathExist = await (0, _1.waitUntil)(() => (0, index_1.existsSync)(tmpPath), {
102
- ms: 300,
103
- retryTime: 5,
104
- });
105
- if (!tmpPathExist) {
106
- const error = new Error('cp to tmp path fail');
107
- return {
108
- success: false,
109
- error,
110
- };
111
- }
112
- // step 5: 将新的 app 文件移动到 Applications 目录下,如果失败 or 查不到移入文件,将临时目录下的文件移动回来
113
- try {
114
- await (0, index_1.spawnAsync)('cp', ['-R', volumesAppPath, appPath]);
115
- }
116
- catch (error) {
117
- _log(logger, error);
118
- }
119
- const appExist = await (0, _1.waitUntil)(() => (0, index_1.existsSync)(appPath), {
120
- ms: 300,
121
- retryTime: 5,
122
- });
123
- // 查不到新移入的 dmg,将原 dmg 再移动回来
124
- if (!appExist) {
125
- const error = new Error('cp to app fail');
126
- await (0, index_1.spawnAsync)('mv', [tmpPath, appPath]);
127
- return {
128
- success: false,
129
- error,
130
- };
131
- }
132
- // step 6: 执行 hdiutil eject,推出
133
- try {
134
- await (0, index_1.spawnAsync)('hdiutil', ['eject', volumesPath]);
135
- }
136
- catch (error) {
137
- _log(logger, error);
138
- }
139
- return {
140
- success: true,
141
- };
142
- };
143
- //# sourceMappingURL=install-macos-dmg%E7%9A%84%E5%89%AF%E6%9C%AC.js.map