Files

68 lines
2.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 客户端更新检测与安装(Windows)—— 接口文档
> 展播端(Tauri Windows 应用)检测后端是否有新版本安装包,下载并启动安装。仅 Windows。
## 一、检测更新接口
**`POST /api/update/check`**
请求体:
```json
{ "current": "0.1.0" } // 前端上报的当前安装版本(Tauri getVersion
```
响应:
```json
{
"ok": true,
"latest_version": "0.1.1",
"installer_name": "云超服昆创园OPC运营中心_0.1.1_x64-setup.exe",
"download_url": "/download",
"update_available": true
}
```
字段:
| 字段 | 说明 |
|---|---|
| `ok` | 是否成功 |
| `latest_version` | 最新版本号(从安装包文件名解析) |
| `installer_name` | 安装包文件名 |
| `download_url` | 安装包下载相对路径(前缀 `api_base` |
| `update_available` | 是否需要更新(`latest > current` |
**最新版本如何确定**:扫描 `backend/` 目录下 `*.setup.exe`,从文件名正则 `_(\d+\.\d+(?:\.\d+)?)` 提取版本号(如 `..._0.1.1_x64-setup.exe``0.1.1`)。文件名倒序取第一个。
## 二、下载安装包接口
**`GET /download`**(别名 `/11`)—— 返回 `backend/` 下最新安装包,`application/octet-stream` 附件下载。
## 三、前端流程
| 文件 | 逻辑 |
|---|---|
| `src/utils/updateCheck.js` | `getCurrentVersion()` 用 Tauri `getVersion()` 读真实版本 → `checkForUpdate()``/api/update/check``downloadAndInstall()` fetch 下载字节 |
| `src/components/UpdateNotify.jsx` | 检测到更新弹底部提示;点「下载更新」→ 下载 → 启动安装 → 应用退出 |
| Rust `install_update` | 写盘到 `%TEMP%` → 启动安装程序 → 0.8s 后 `app.exit(0)` |
触发时机:启动静默查一次 + 每 30 分钟自动查 + 点页眉 logo 主动查。
## 四、发布新版本步骤
1. 把新安装包放入 `backend/`,文件名带版本号:`云超服昆创园OPC运营中心_0.2.0_x64-setup.exe`
2. 同步改 `package.json``version`Tauri `getVersion` 读取它)。
3. 重启后端 + 重新打包前端 `yarn build:win`
4. 安装端检测到 `latest > current` → 弹更新提示 → 下载安装。
## 五、验证
```bash
curl -X POST http://192.168.1.9:10085/api/update/check \
-H "Content-Type: application/json" -d '{"current":"0.1.0"}'
```
`backend/` 有更高版本安装包时返回 `update_available: true`
## 六、注意
- 当前按「文件名倒序取第一个」判定最新;若目录同时存在多个版本(如 `0.9``0.10`),字符串倒序可能取错。多版本共存时应改为「解析全部版本号 → 取数值最大」。
- `downloadAndInstall``invoke` 传递安装包字节(约 2.5MB,JSON 数组稍慢);如需更快可改 Rust 端直接 HTTP 下载。