feat: implement fixed local API port settings for desktop app, allowing users to specify a port for consistent access, with corresponding UI and translations

This commit is contained in:
wizardchen
2026-04-11 16:02:52 +08:00
committed by lyingbug
parent 3f0f69815f
commit d99e2cbac3
13 changed files with 392 additions and 279 deletions
+13
View File
@@ -163,3 +163,16 @@ data/
```
备份只需复制整个 `data/` 目录。
## 桌面版(Wails)与 Chrome 扩展
桌面 **WeKnora Lite** 内置的 HTTP API 默认监听 **`127.0.0.1` 上的随机端口**(避免每次启动占用固定端口、并减少系统防火墙提示)。浏览器里的 **Chrome 扩展**与网页不同,需要你在扩展里填写明确的 API 地址(例如 `http://127.0.0.1:<端口>/api/v1`),因此会遇到两类问题:
1. **端口每次变**:重启桌面应用后端口可能变化,扩展里保存的地址会失效。
2. **扩展权限**:上架的扩展须在 `manifest.json` 的 `host_permissions`(或同类字段)中声明对 **`http://127.0.0.1/*`** 和/或 **`http://localhost/*`** 的访问,否则无法请求本机 Lite服务。
**推荐做法**
- 在桌面应用内打开 **设置 → API 信息**,在 **「本地 API 端口(桌面版)」** 中填写固定端口(如 `37841`)并保存,**重启应用** 后端口即固定;配置会写入用户配置目录下的 `desktop-prefs.json`。
- 启动桌面应用后,在同一页复制 **API 根路径**(与 `http://127.0.0.1:<端口>/api/v1` 一致),粘贴到扩展配置;扩展侧 API Key 与网页版租户 API Key 相同。
- 若扩展仍无法连接:确认扩展已声明上述 `host_permissions`;可尝试把地址里的主机从 `localhost` 改成 **`127.0.0.1`**(或反之)以排除解析差异。