Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ public/material-icons/
*.njsproj
*.sln
*.sw?

# Local tool dirs / reference checkouts (not part of the repo)
.hermes/
.omo/
opencode/
nul
3 changes: 2 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import tseslint from 'typescript-eslint'
import { defineConfig, globalIgnores } from 'eslint/config'

export default defineConfig([
globalIgnores(['dist', 'node_modules', 'public/material-icons', 'src-tauri/target/**']),
// opencode/ 是本地参考用的外部仓库,不属于本项目源码
globalIgnores(['dist', 'node_modules', 'public/material-icons', 'src-tauri/target/**', 'opencode']),
{
files: ['**/*.{ts,tsx}'],
extends: [
Expand Down
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"clsx": "^2.1.1",
"diff": "^8.0.4",
"dompurify": "^3.4.11",
"fuzzysort": "^4.0.2",
"i18next": "^26.0.1",
"i18next-browser-languagedetector": "^8.2.1",
"katex": "^0.16.38",
Expand Down
4 changes: 4 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ futures-util = "0.3"
log = "0.4"
papaya = "0.2.3"
rapidhash = { version = "4.4.1", features = ["unsafe"] }
regex = "1"
reqwest = { version = "0.12", default-features = false, features = [
"rustls-tls",
"stream"
Expand All @@ -32,8 +33,10 @@ tauri-plugin-log = "2"
tauri-plugin-notification = "2"
tauri-plugin-opener = "2"
tauri-plugin-single-instance = "2"
tokio = { version = "1", features = ["macros", "rt-multi-thread", "sync", "time"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread", "sync", "time", "process"] }
tokio-tungstenite = { version = "0.24", features = ["rustls-tls-webpki-roots"] }
tokio-util = "0.7"
uuid = { version = "1", features = ["v4"] }

[build-dependencies]
tauri-build = { version = "2", features = [] }
Expand Down
16 changes: 11 additions & 5 deletions src-tauri/src/app/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
pub mod bridge;
#[cfg(not(target_os = "android"))]
pub mod opencode;
#[cfg(not(target_os = "android"))]
pub mod utils;
pub mod bridge;
#[cfg(not(target_os = "android"))]
pub mod opencode;
#[cfg(not(target_os = "android"))]
pub mod utils;
#[cfg(target_os = "windows")]
pub mod wsl_types;
#[cfg(target_os = "windows")]
pub mod wsl_runtime;
#[cfg(target_os = "windows")]
pub mod wsl_commands;
54 changes: 44 additions & 10 deletions src-tauri/src/app/commands/opencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,46 @@ struct SpawnedOpencodeServe {

/// 检查 opencode 服务是否在运行(通过 health endpoint)
pub async fn is_service_running(url: &str) -> bool {
let health_url = format!("{}/global/health", url.trim_end_matches('/'));
match reqwest::Client::builder()
is_service_running_with_auth(url, None).await
}

/// 带可选 Basic 鉴权的健康检查,对齐官方实现:
/// 依次尝试 /api/health 与 /global/health;WSL 侧 serve 启用了密码保护,
/// 不带凭据会收到 401 而误判为未就绪。
pub async fn is_service_running_with_auth(url: &str, auth: Option<(&str, &str)>) -> bool {
let base = url.trim_end_matches('/');
let client = match reqwest::Client::builder()
.connect_timeout(Duration::from_secs(3))
.build()
{
Ok(client) => client
.get(&health_url)
.timeout(Duration::from_secs(5))
.send()
.await
.map(|r| r.status().is_success())
.unwrap_or(false),
Err(_) => false,
Ok(c) => c,
Err(_) => return false,
};

let mut request = client.get(format!("{}/api/health", base));
if let Some((username, password)) = auth {
request = request.basic_auth(username, Some(password));
}
if request
.timeout(Duration::from_secs(5))
.send()
.await
.map(|r| r.status().is_success())
.unwrap_or(false)
{
return true;
}

let mut request = client.get(format!("{}/global/health", base));
if let Some((username, password)) = auth {
request = request.basic_auth(username, Some(password));
}
request
.timeout(Duration::from_secs(5))
.send()
.await
.map(|r| r.status().is_success())
.unwrap_or(false)
}

/// 启动 opencode serve 进程
Expand Down Expand Up @@ -371,6 +397,14 @@ pub async fn confirm_close_app(
state: State<'_, ServiceState>,
stop_service: bool,
) -> Result<(), String> {
// 我们启动的 WSL 内 opencode 进程随应用退出统一清理,避免后台残留
#[cfg(target_os = "windows")]
{
use tauri::Manager;
let wsl_state = window.app_handle().state::<super::wsl_commands::WslState>();
super::wsl_commands::stop_all_wsl_servers(&wsl_state).await;
}

if stop_service {
let pid = state.child_pid.swap(0, Ordering::SeqCst);
if pid > 0 {
Expand Down
Loading
Loading