@sellerartifact/electron-app-updater 0.0.6 → 0.0.7

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.
Files changed (2) hide show
  1. package/README.md +66 -7
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,22 +1,81 @@
1
- # Rslib Project
1
+ # electron-app-updater
2
2
 
3
- ## Setup
3
+ 用于 Electron 主进程的轻量更新工具。它从版本接口获取最新版本信息;检测到版本变化时,下载新的构建脚本、记录版本号,并重启应用。
4
4
 
5
- Install the dependencies:
5
+ ## 安装
6
6
 
7
7
  ```bash
8
- pnpm install
8
+ pnpm add @sellerartifact/electron-app-updater
9
+ ```
10
+
11
+ ## 使用
12
+
13
+ 在 Electron 的主进程中创建更新器,并在合适的时机调用 `checkVersion()`。传入的 `app` 与 `dialog` 通常来自 `electron` 包。
14
+
15
+ ```ts
16
+ import { app, dialog } from 'electron';
17
+ import { ElectronAppUpdater } from '@sellerartifact/electron-app-updater';
18
+
19
+ const updater = new ElectronAppUpdater({
20
+ checkVersionUrl: 'https://example.com/api/app-version',
21
+ app,
22
+ dialog,
23
+ });
24
+
25
+ app.whenReady().then(async () => {
26
+ const isLatest = await updater.checkVersion();
27
+
28
+ if (isLatest) {
29
+ console.log('当前已是最新版本');
30
+ }
31
+ });
32
+ ```
33
+
34
+ `checkVersion()` 在远端版本与本地版本一致时返回 `true`。检测到新版本时,它会执行更新和重启流程,并返回 `false`。
35
+
36
+ ## 版本接口
37
+
38
+ `checkVersionUrl` 指向的接口需要返回以下结构,其中 `url` 是可直接下载的 JavaScript 文件地址:
39
+
40
+ ```json
41
+ {
42
+ "result": {
43
+ "version": 2,
44
+ "url": "https://example.com/releases/build.js"
45
+ }
46
+ }
47
+ ```
48
+
49
+ 版本号使用严格不等比较,因此接口应始终返回稳定、可比较的版本值,例如递增数字。
50
+
51
+ ## 配置
52
+
53
+ | 参数 | 必填 | 默认值 | 说明 |
54
+ | -------------------- | ---- | ------------- | --------------------------------------------------- |
55
+ | `checkVersionUrl` | 是 | - | 版本接口地址。 |
56
+ | `app` | 是 | - | Electron 的 `app` 实例,用于重启和退出应用。 |
57
+ | `dialog` | 是 | - | Electron 的 `dialog` 实例,用于显示发现更新的提示。 |
58
+ | `configJSONFileName` | 否 | `config.json` | 本地版本记录文件名。 |
59
+ | `buildJSFileName` | 否 | `build.js` | 下载后写入的构建脚本文件名。 |
60
+
61
+ 当前版本信息和构建脚本固定存放在 `./resources/app/src/main`:
62
+
63
+ ```text
64
+ resources/app/src/main/
65
+ config.json
66
+ build.js
9
67
  ```
10
68
 
11
- ## Get Started
69
+ 更新时会先将远端版本写入 `config.json`,再用下载内容覆盖 `build.js`,约 1.2 秒后调用 `app.relaunch()` 和 `app.exit(0)`。请确保该目录存在且应用对其有写入权限。
12
70
 
13
- Build the library:
71
+ ## 开发
14
72
 
15
73
  ```bash
74
+ pnpm install
16
75
  pnpm build
17
76
  ```
18
77
 
19
- Build the library in watch mode:
78
+ 监听构建:
20
79
 
21
80
  ```bash
22
81
  pnpm dev
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sellerartifact/electron-app-updater",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -30,4 +30,4 @@
30
30
  "dependencies": {
31
31
  "axios": "^1.7.7"
32
32
  }
33
- }
33
+ }