From 22c343a85e93a6d44441f50c85471733fb4ae489 Mon Sep 17 00:00:00 2001 From: Nixevol Date: Wed, 20 May 2026 15:16:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=A1=8C=E9=9D=A2?= =?UTF-8?q?=E7=89=88=E9=85=8D=E7=BD=AE=E8=AF=B7=E6=B1=82=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + app/api/routers/health.py | 2 +- app/api/routers/service.py | 2 +- app/main.py | 5 ++++- docs/project_context.md | 7 +++++++ frontend/src/AppShell.vue | 2 +- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 4 ++-- src-tauri/tauri.conf.json | 5 +++-- 9 files changed, 21 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d11979f..e712cf2 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,7 @@ dist\desktop\*-setup.exe 桌面版使用 Tauri 启动 Python sidecar。sidecar 默认监听 `127.0.0.1:19082`,运行数据写入系统 app data 目录,不写入安装目录。 首次启动会把安装包内置的 `Configure.json` 和 `ReportScript.sql` 复制到运行数据目录;Windows 下通常是 `%APPDATA%\com.nixevol.capacityreport\`。安装目录中的 `_up_` 只是 Tauri 打包资源目录,程序运行时不会直接编辑它。 Windows 桌面版使用 NSIS 安装器,卸载时会询问是否同时删除 `%APPDATA%\com.nixevol.capacityreport\` 中的配置、脚本、授权、缓存和日志。 +桌面版 release 包已启用 DevTools,如需排查前端请求,可在窗口中按 `F12` 或右键打开开发者工具。 构建桌面版需要 Rust 和 Tauri CLI。脚本会在缺少 Tauri CLI 时自动执行: diff --git a/app/api/routers/health.py b/app/api/routers/health.py index 7e93057..7211ae0 100644 --- a/app/api/routers/health.py +++ b/app/api/routers/health.py @@ -32,7 +32,7 @@ async def health_check(): return { "status": "healthy" if is_healthy else "unhealthy", "timestamp": datetime.now().isoformat(), - "version": "2.0.2", + "version": "2.0.3", "uptime_pid": os.getpid(), "checks": checks, } diff --git a/app/api/routers/service.py b/app/api/routers/service.py index 350c879..847c1fd 100644 --- a/app/api/routers/service.py +++ b/app/api/routers/service.py @@ -54,7 +54,7 @@ async def restart_service(): async def get_service_status(): return { "status": "running", - "version": "2.0.2", + "version": "2.0.3", "platform": platform.system(), "supervisor": is_supervisor_running(), "container": is_container_runtime(), diff --git a/app/main.py b/app/main.py index 9c5757c..ce3b5a7 100644 --- a/app/main.py +++ b/app/main.py @@ -12,7 +12,7 @@ from app.auth import verify_jwt_token from app.config import BASE_DIR -APP_VERSION = "2.0.2" +APP_VERSION = "2.0.3" APP_HOST = "0.0.0.0" APP_PORT = 9081 FRONTEND_DIST_DIR = BASE_DIR / "frontend" / "dist" @@ -43,6 +43,9 @@ def create_app() -> FastAPI: async def jwt_middleware(request: Request, call_next): + if request.method == "OPTIONS": + return await call_next(request) + path = request.url.path if path.startswith("/api/") and path != "/api/login": auth_header = request.headers.get("Authorization") diff --git a/docs/project_context.md b/docs/project_context.md index 852d043..35cf88a 100644 --- a/docs/project_context.md +++ b/docs/project_context.md @@ -1,4 +1,11 @@ # 项目上下文记录 +## 2026-05-20:修复桌面版跨源预检导致配置网络错误 + +- 桌面版前端访问 `127.0.0.1:19082` 属于 WebView 跨源请求,带 `Authorization` 或上传配置文件时浏览器会先发 `OPTIONS` 预检;`app/main.py` 的 JWT 中间件现在直接放行 `OPTIONS`,让 FastAPI CORS 中间件返回允许头,避免配置读取和配置上传显示“网络错误”。 +- 桌面版版本提升为 `2.0.3`,同步更新 `app/main.py`、健康检查、服务状态、Tauri 配置、Cargo 包版本和侧边栏版本号,避免同版本安装包覆盖时难以确认是否装到新包。 +- `src-tauri/Cargo.toml` 启用 Tauri `devtools` feature,`tauri.conf.json` 主窗口设置 `devtools: true`;Windows release 桌面包可按 `F12` 或右键打开开发者工具排查真实请求。 +- 已用真实 uvicorn 服务验证 `Origin: http://tauri.localhost` 下 `/api/config/full` 和 `/api/config/upload` 的 `OPTIONS` 预检均返回 200,并且登录后 `/api/config/full` 可正常返回;随后执行 `scripts\build.bat desktop` 生成 `dist\desktop\CapacityReport_2.0.3_x64-setup.exe`,静默安装启动后验证 `/health` 返回 `2.0.3`、配置读取正常、脚本读取正常、配置上传返回 200。 + ## 2026-05-20:修复桌面版残留 sidecar 和卸载用户数据选择 - `src-tauri/src/main.rs` 启动 sidecar 前会先清理占用 `19082` 的旧 `capareport-server` 监听进程,避免卸载/重装或异常退出后连到旧服务;启动后不只检查端口可连接,还会请求 `/health` 返回 HTTP 200 才继续。 diff --git a/frontend/src/AppShell.vue b/frontend/src/AppShell.vue index 032322e..aed4f2d 100644 --- a/frontend/src/AppShell.vue +++ b/frontend/src/AppShell.vue @@ -25,7 +25,7 @@ diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 12b7a52..f3c9ff5 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -235,7 +235,7 @@ dependencies = [ [[package]] name = "capacity-report-desktop" -version = "2.0.2" +version = "2.0.3" dependencies = [ "tauri", "tauri-build", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 3b5eff9..c8c9b98 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "capacity-report-desktop" -version = "2.0.2" +version = "2.0.3" description = "CapacityReport desktop shell" authors = ["NIXEVOL"] edition = "2021" @@ -9,7 +9,7 @@ edition = "2021" tauri-build = { version = "2", features = [] } [dependencies] -tauri = { version = "2", features = [] } +tauri = { version = "2", features = ["devtools"] } tauri-plugin-shell = "2" [features] diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 61c59c4..d37db2b 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "CapacityReport", - "version": "2.0.2", + "version": "2.0.3", "identifier": "com.nixevol.capacityreport", "build": { "frontendDist": "../frontend/dist" @@ -14,7 +14,8 @@ "width": 1280, "height": 820, "minWidth": 1100, - "minHeight": 720 + "minHeight": 720, + "devtools": true } ], "security": {