graceful-updater 1.1.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.
package/README.en.md CHANGED
@@ -15,6 +15,9 @@
15
15
  [download-url]: https://npmjs.org/package/graceful-updater
16
16
 
17
17
  > Software updates solution for Electron applications, It is convenient to complete full software update and dynamic update.
18
+
19
+ English | [简体中文](./README.md)
20
+
18
21
  ## Installment
19
22
 
20
23
  ```bash
@@ -26,7 +29,7 @@ $ npm i graceful-updater --save
26
29
  please visit: https://github.com/electron-modules/electron-modules-sample
27
30
 
28
31
  ```typescript
29
- // 1. 构造 options
32
+ // 1. options
30
33
  const options = {
31
34
  url: getFeedUrl(),
32
35
  logger: console, // logger
@@ -43,9 +46,10 @@ const options = {
43
46
  res.project_version > currentBuildNumber;
44
47
  },
45
48
  };
46
- // 2. 初始化 updator 实例
49
+ // 2. initialization
47
50
  const electronUpdator = new MacUpdator(options);
48
- // 3. 绑定全局事件
51
+
52
+ // 3. Bind events
49
53
  electronUpdator.on(EventType.UPDATE_DOWNLOADED, (...args) => {
50
54
  console.log('updator >> %s, args: %j', EventType.UPDATE_DOWNLOADED, args);
51
55
  });
@@ -92,41 +96,92 @@ electronUpdator.on(EventType.UPDATE_DOWNLOAD_PROGRESS, (data) => {
92
96
 
93
97
  ### Options
94
98
 
95
- | 字段 | 类型 | 是否必须 | 描述 | 备注 |
99
+ | Param | Type | Required | Description | Default value |
96
100
  | --- | --- | --- | --- | --- |
97
- | url | String | 必须 | 检测更新的远程地址,返回数据遵循 UpdateInfo 字段 | |
98
- | ifNeedUpdate | Function | 非必须 | 返回是否需要更新 | |
99
- | updateInfoFormatter | Function | 非必须 | 服务端返回数据格式适配 | 如果返回的格式无法与需要的字段相匹配时,参数进行格式化 |
100
- | logger | Object | 非必须 | 日志 | |
101
- | productName | String | 产品名 | 应用名 | |
101
+ | url | String | Yes | Check for update remote address, and the returned data follows the `UpdateInfo` object | |
102
+ | ifNeedUpdate | Function | Yes | Check if update is required | |
103
+ | updateInfoFormatter | Function | No | The server returns data format adaptation. If the returned format cannot match the `UpdateInfo`, this method can be used to format |
104
+ | logger | Object | No | Log method | `console` |
105
+ | productName | String | Yes | Application Name | |
106
+ | autoDownload | String | No | Whether to download automatically | false |
107
+
102
108
 
103
109
  ### UpdateInfo
104
110
 
105
- | 字段 | 类型 | 是否必须 | 描述 | 备注 |
111
+ | Param | Type | Required | Description | Default value |
106
112
  | --- | --- | --- | --- | --- |
107
- | version | String | 必须 | 版本号 | |
108
- | projectVersion | Number | 必须 | 构建号 | |
109
- | files | Array<Object> | 必须 | 需要下载的文件列表 | |
110
- | updateType | Enum<String> | 必须 | 更新类型,是否动态替换更新 | Package or Asar |
111
- | releaseNotes | Array<String> | 必须 | 更新日志 | |
113
+ | version | String | Yes | version | |
114
+ | projectVersion | Number | No | project version | |
115
+ | files | Array\<Object\> | Yes | The list of files to be downloaded. The returned data follows the `File` object | |
116
+ | updateType | Enum\<String\> | Yes | Update type, full update or dynamic update.Package is full update,Asar is dynamic update | |
117
+ | releaseNotes | Array\<String\> | Yes | The release notes. | |
118
+
119
+ ### File
120
+
121
+ | Param | Type | Required | Description | Default value |
122
+ | --- | --- | --- | --- | --- |
123
+ | url | String | No | download address | |
124
+ | signature | String | No | download address signature | |
125
+ | updateType | Enum\<String\> | Yes | Update type, full update or dynamic update.Package is full update,Asar is dynamic update | |
112
126
 
113
127
  ### Methods
114
128
 
115
- 1. checkForUpdates()
129
+ 1. checkForUpdates(ExecuteType)
130
+
131
+ - `ExecuteType` ExecuteType(User or Auto)
132
+
133
+ Check whether there is content to be updated. If the `ExecuteType` is User, the `update-available` event will be triggered directly after the update is detected. Otherwise, the `update-available` event will be triggered after the package is automatically downloaded
134
+
135
+ 2. setFeedUrl(url)
136
+
137
+ - url: New update URL
138
+ According to the needs of different scenarios, dynamically set the URL for checking updates
116
139
 
117
- 检测是否有需要更新的内容
140
+ 2. downloadUpdate(ExecuteType)
118
141
 
119
- 2. downloadUpdate()
142
+ - `ExecuteType` ExecuteType(User or Auto)
143
+
144
+ Start downloading the installation package. If the `ExecuteType` is User, no pre-check will be performed. After the download is completed, the `update-downloaded` event will be triggered directly. Otherwise, the `update-downloaded` event will be triggered after the internal pre-check is completed
120
145
 
121
- 开始下载
122
146
 
123
147
  3. quitAndInstall()
148
+ Exit the app and start the installation. If the installation package has been downloaded, the application will be restarted directly and the new version will be installed. Otherwise, enter the download process
124
149
 
125
150
  ### Events
126
151
 
127
152
  1. checking-for-update
128
153
 
129
- 当开始检查更新的时候触发
154
+ Triggered when checking for updates
155
+
156
+ 2. update-available
157
+ - params: update info
158
+ - params.updateInfo: `UpdateInfo`
159
+
160
+ Triggered when an available update is checked
161
+
162
+ 3. update-not-available
163
+ - params: update info
164
+ - params.updateInfo: `UpdateInfo`
165
+
166
+ Triggered when no updates are checked
167
+
168
+ 4. update-download-progress
169
+
170
+ - params: status and file info the download process.
171
+ - params.status: download status `begin`, `downloading`, `end`
172
+ - params.progress: Current download progress percentage. 0 ~ 100
173
+ - params.data: The file stream of downloaded content can be used for signature verification
174
+
175
+ Triggering during download
176
+
177
+ 5. update-downloaded
178
+
179
+ Triggered when the download is complete
180
+
181
+ 6. error
182
+ - params: `Error`
183
+
184
+ Triggered when an error occurs inside the updater
130
185
 
131
186
  <!-- GITCONTRIBUTOR_START -->
132
187
 
package/README.md CHANGED
@@ -14,16 +14,19 @@
14
14
  [download-image]: https://img.shields.io/npm/dm/graceful-updater.svg
15
15
  [download-url]: https://npmjs.org/package/graceful-updater
16
16
 
17
- > Software updates solution for Electron applications, It is convenient to complete full software update and dynamic update.
17
+ > Electron 应用软件更新解决方案,方便完成软件的全量更新和动态更新。
18
+
19
+ [English](./README.en.md) | 简体中文
20
+
18
21
  ## Installment
19
22
 
20
23
  ```bash
21
24
  $ npm i graceful-updater --save
22
25
  ```
23
26
 
24
- ## Sample
27
+ ## 样例
25
28
 
26
- please visit: https://github.com/electron-modules/electron-modules-sample
29
+ 点击查看: https://github.com/electron-modules/electron-modules-sample
27
30
 
28
31
  ```typescript
29
32
  // 1. 构造 options
@@ -88,46 +91,98 @@ electronUpdator.on(EventType.UPDATE_DOWNLOAD_PROGRESS, (data) => {
88
91
  });
89
92
  ```
90
93
 
91
- ## Documents
94
+ ## 文档
92
95
 
93
- ### Options
96
+ ### 参数
94
97
 
95
- | 字段 | 类型 | 是否必须 | 描述 | 备注 |
98
+ | 字段 | 类型 | 是否必须 | 说明 | 默认值 |
96
99
  | --- | --- | --- | --- | --- |
97
- | url | String | 必须 | 检测更新的远程地址,返回数据遵循 UpdateInfo 字段 | |
98
- | ifNeedUpdate | Function | 非必须 | 返回是否需要更新 | |
99
- | updateInfoFormatter | Function | 非必须 | 服务端返回数据格式适配 | 如果返回的格式无法与需要的字段相匹配时,参数进行格式化 |
100
- | logger | Object | 非必须 | 日志 | |
101
- | productName | String | 产品名 | 应用名 | |
100
+ | url | String | 必须 | 检测更新的远程地址,返回数据遵循 `UpdateInfo` 对象 | |
101
+ | ifNeedUpdate | Function | 必须 | 返回是否需要更新 | |
102
+ | updateInfoFormatter | Function | 非必须 | 服务端返回数据格式适配。如果返回的格式无法与 `UpdateInfo` 相匹配时,可通过此方法进行格式化 |
103
+ | logger | Object | 非必须 | 日志 | `console` |
104
+ | productName | String | 必须 | 应用完整名称 | |
105
+ | autoDownload | String | 非必须 | 是否自动下载 | false |
106
+
102
107
 
103
108
  ### UpdateInfo
104
109
 
105
- | 字段 | 类型 | 是否必须 | 描述 | 备注 |
110
+ | 字段 | 类型 | 是否必须 | 说明 | 默认值 |
106
111
  | --- | --- | --- | --- | --- |
107
112
  | version | String | 必须 | 版本号 | |
108
- | projectVersion | Number | 必须 | 构建号 | |
109
- | files | Array<Object> | 必须 | 需要下载的文件列表 | |
110
- | updateType | Enum<String> | 必须 | 更新类型,是否动态替换更新 | Package or Asar |
111
- | releaseNotes | Array<String> | 必须 | 更新日志 | |
113
+ | projectVersion | Number | 非必须 | 构建号 | |
114
+ | files | Array\<Object\> | 必须 | 需要下载的文件列表,返回数据遵循 `File` 对象 | |
115
+ | updateType | Enum\<String\> | 必须 | 更新类型,全量更新或者动态更新。Package 为全量更新,Asar 为动态更新 | |
116
+ | releaseNotes | Array\<String\> | 必须 | 更新日志 | |
117
+
118
+ ### File
119
+
120
+ | 字段 | 类型 | 是否必须 | 说明 | 默认值 |
121
+ | --- | --- | --- | --- | --- |
122
+ | url | String | 必须 | 下载地址 | |
123
+ | signature | String | 非必须 | 下载签名 | |
124
+ | updateType | Enum\<String\> | 必须 | 更新类型,针对动态更新或全量更新提供的下载地址。Package or Asar | |
112
125
 
113
- ### Methods
126
+ ### 方法
114
127
 
115
- 1. checkForUpdates()
128
+ 1. checkForUpdates(ExecuteType)
116
129
 
117
- 检测是否有需要更新的内容
130
+ - `ExecuteType` 执行类型(User or Auto)
118
131
 
119
- 2. downloadUpdate()
132
+ 检测是否有需要更新的内容,如果 `ExecuteType` 为 User,则检查到更新后直接触发 `update-available` 事件,否则将自动下载完成安装包后触发 `update-available` 事件
120
133
 
121
- 开始下载
134
+ 2. setFeedUrl(url)
135
+
136
+ - url 新的更新 URL
137
+ 根据不同场景需要,动态设置检查更新的 URL
138
+
139
+ 2. downloadUpdate(ExecuteType)
140
+
141
+ - `ExecuteType` 执行类型(User or Auto)
142
+
143
+ 开始下载安装包,如果 `ExecuteType` 为 User,则不进行预检查,下载完成后直接触发 `update-downloaded` 事件,否则完成内部完成预检查后再触发 `update-downloaded` 事件
122
144
 
123
145
  3. quitAndInstall()
146
+ 退出应用并开始安装。如果安装包已下载完成,将直接重启应用并进行新版本安装。否则进入下载流程
147
+
124
148
 
125
- ### Events
149
+ ### 事件
126
150
 
127
151
  1. checking-for-update
128
152
 
129
153
  当开始检查更新的时候触发
130
154
 
155
+ 2. update-available
156
+ - params:更新信息
157
+ - params.updateInfo:本次更新的信息 `UpdateInfo`
158
+
159
+ 检测到有可用更新时触发
160
+
161
+ 3. update-not-available
162
+ - params:更新信息
163
+ - params.updateInfo:本次更新的信息 `UpdateInfo`
164
+
165
+ 检测到无可用更新时触发
166
+
167
+ 4. update-download-progress
168
+
169
+ - params:下载过程中的进度及文件流信息。
170
+ - params.status 下载状态。 `begin` 开始下载,`downloading` 下载中,`end` 下载结束
171
+ - params.progress 当前下载进度百分比,0 ~ 100
172
+ - params.data 下载内容的文件流,可利用此数据进行签名校验
173
+
174
+
175
+ 正在下载过程中触发
176
+
177
+ 5. update-downloaded
178
+
179
+ 完成下载时触发
180
+
181
+ 6. error
182
+ - params:错误信息 `Error`
183
+
184
+ 更新程序内部出现错误时触发
185
+
131
186
  <!-- GITCONTRIBUTOR_START -->
132
187
 
133
188
  ## Contributors
@@ -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.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",
28
+ "graceful-updater-windows-helper": "1.0.3-beta.1",
29
29
  "lodash": "4",
30
30
  "moment": "2",
31
31
  "nanoid": "^3.3.4",