feat: Add LAN WebUI support for remote browser control#3972
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…live The previous tauri::async_runtime::spawn dropped the WebUiServer handle, causing the server to stop immediately after startup. Use std::thread::spawn with its own tokio runtime and block forever to keep the server alive. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…tching Expose fetch_models_for_config command via HTTP API so browser clients can fetch available models from providers. Also export commandClient object from commandClient.ts to fix import errors. Fixes: - Add /api/models/fetch POST endpoint to webui.rs - Add FetchModelsRequest struct - Map fetch_models_for_config to /api/models/fetch in commandClient - Export commandClient object with invoke/listen methods - Update model-fetch.ts to use commandClient instead of direct Tauri invoke Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
b74e2f0 to
183be5c
Compare
- Add /api/webui/start, /api/webui/stop, /api/webui/restart routes - Add WebUI settings tab (enable/disable, port, host, token) - Add dynamic start/stop/restart via Tauri commands - Add static file serving with SPA fallback (ServeDir) - Add WebUI documentation to README - Add settings persistence (webui_enabled, port, host, token) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 06d9dee415
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (window.location.port === "15722") return window.location.origin; | ||
|
|
||
| const protocol = window.location.protocol || "http:"; | ||
| const hostname = window.location.hostname || "127.0.0.1"; | ||
| return `${protocol}//${hostname}:15722`; |
There was a problem hiding this comment.
Use the current origin for non-default WebUI ports
When the WebUI is served on any configured port other than 15722, the browser client loads from that port but all API calls are redirected back to http(s)://<host>:15722 by this fallback. For example, setting webuiPort/CC_SWITCH_WEBUI_PORT to 18000 makes http://host:18000/ render the app, then /api/settings, provider switches, etc. are fetched from port 15722 and fail unless another server happens to be running there. The production WebUI should use window.location.origin whenever it is being served by the embedded server, not only for the default port.
Useful? React with 👍 / 👎.
| let dist_path = exe_dir | ||
| .as_ref() | ||
| .map(|dir| dir.join("dist")) | ||
| .filter(|p| p.exists()) | ||
| .or_else(|| { | ||
| // Fallback: check workspace root during development | ||
| let cwd = std::env::current_dir().ok()?; | ||
| let workspace_dist = cwd.join("dist"); | ||
| workspace_dist.exists().then_some(workspace_dist) | ||
| }); |
There was a problem hiding this comment.
Serve packaged frontend assets instead of exe_dir/dist
In a packaged Tauri build, frontendDist is embedded/bundled for the WebView and this commit does not add a bundle.resources entry that places a physical dist directory next to the executable. As a result, installed users won't have either exe_dir/dist or the development cwd/dist, so the WebUI starts in “API only” mode and http://<host>:15722/ cannot load the remote-control UI despite the feature being advertised as auto-starting in the built app.
Useful? React with 👍 / 👎.
概述
增加了局域网 WebUI 支持,允许通过浏览器远程控制 cc-switch。
主要变更
后端
src-tauri/src/webui.rs, 808 行)前端
src/lib/commandClient.ts, 208 行)使用方式
启动 WebUI 服务器
CC_SWITCH_WEBUI=1 \ CC_SWITCH_WEBUI_HOST=0.0.0.0 \ CC_SWITCH_WEBUI_PORT=15722 \ CC_SWITCH_WEBUI_TOKEN='your-random-token' \ ./cc-switch浏览器访问
首次访问时带
?token=参数,浏览器会自动保存到 localStorage,后续访问无需再带。环境变量
CC_SWITCH_WEBUIfalseCC_SWITCH_WEBUI_HOST127.0.0.1CC_SWITCH_WEBUI_PORT15722CC_SWITCH_WEBUI_TOKEN已验证功能
安全性
127.0.0.1,仅本地访问CC_SWITCH_WEBUI_HOST=0.0.0.0CC_SWITCH_WEBUI_TOKEN后)*(可根据需要收紧)相关提交
🤖 Generated with Claude Code