summaryrefslogtreecommitdiffhomepage
path: root/packages/desktop/src-tauri
diff options
context:
space:
mode:
authorBrendan Allan <[email protected]>2026-02-20 12:18:39 +0800
committerBrendan Allan <[email protected]>2026-02-20 12:18:39 +0800
commit1c2416b6deb1eee856d1fddbf08300cf851a19fc (patch)
tree39da283d0d2ad02c2c092099bf47ab726ef9244b /packages/desktop/src-tauri
parentd86c10816d75837c8f85e7b1ab0de5ff37ecf77b (diff)
downloadopencode-1c2416b6deb1eee856d1fddbf08300cf851a19fc.tar.gz
opencode-1c2416b6deb1eee856d1fddbf08300cf851a19fc.zip
desktop: don't spawn sidecar if default is localhost server
Diffstat (limited to 'packages/desktop/src-tauri')
-rw-r--r--packages/desktop/src-tauri/src/lib.rs19
-rw-r--r--packages/desktop/src-tauri/src/server.rs6
2 files changed, 20 insertions, 5 deletions
diff --git a/packages/desktop/src-tauri/src/lib.rs b/packages/desktop/src-tauri/src/lib.rs
index c6a7d13e6..7ea3aaa8a 100644
--- a/packages/desktop/src-tauri/src/lib.rs
+++ b/packages/desktop/src-tauri/src/lib.rs
@@ -40,7 +40,9 @@ use crate::windows::{LoadingWindow, MainWindow};
#[derive(Clone, serde::Serialize, specta::Type, Debug)]
struct ServerReadyData {
url: String,
+ username: Option<String>,
password: Option<String>,
+ is_sidecar: bool
}
#[derive(Clone, Copy, serde::Serialize, specta::Type, Debug)]
@@ -605,6 +607,7 @@ async fn initialize(app: AppHandle) {
child,
health_check,
url,
+ username,
password,
} => {
let app = app.clone();
@@ -631,7 +634,7 @@ async fn initialize(app: AppHandle) {
app.state::<ServerState>().set_child(Some(child));
- Ok(ServerReadyData { url, password })
+ Ok(ServerReadyData { url, username,password, is_sidecar: true })
}
.map(move |res| {
let _ = server_ready_tx.send(res);
@@ -641,7 +644,9 @@ async fn initialize(app: AppHandle) {
ServerConnection::Existing { url } => {
let _ = server_ready_tx.send(Ok(ServerReadyData {
url: url.to_string(),
+ username: None,
password: None,
+ is_sidecar: false,
}));
None
}
@@ -719,6 +724,7 @@ enum ServerConnection {
},
CLI {
url: String,
+ username: Option<String>,
password: Option<String>,
child: CommandChild,
health_check: server::HealthCheck,
@@ -730,11 +736,15 @@ async fn setup_server_connection(app: AppHandle) -> ServerConnection {
tracing::info!(?custom_url, "Attempting server connection");
- if let Some(url) = custom_url
- && server::check_health_or_ask_retry(&app, &url).await
+ if let Some(url) = &custom_url
+ && server::check_health_or_ask_retry(&app, url).await
{
tracing::info!(%url, "Connected to custom server");
- return ServerConnection::Existing { url: url.clone() };
+ // If the default server is already local, no need to also spawn a sidecar
+ if server::is_localhost_url(url) {
+ return ServerConnection::Existing { url: url.clone() };
+ }
+ // Remote default server: fall through and also spawn a local sidecar
}
let local_port = get_sidecar_port();
@@ -755,6 +765,7 @@ async fn setup_server_connection(app: AppHandle) -> ServerConnection {
ServerConnection::CLI {
url: local_url,
+ username: Some("opencode".to_string()),
password: Some(password),
child,
health_check,
diff --git a/packages/desktop/src-tauri/src/server.rs b/packages/desktop/src-tauri/src/server.rs
index a13b450bb..2c43c1cc8 100644
--- a/packages/desktop/src-tauri/src/server.rs
+++ b/packages/desktop/src-tauri/src/server.rs
@@ -150,7 +150,7 @@ pub async fn check_health(url: &str, password: Option<&str>) -> bool {
return false;
};
- let mut builder = reqwest::Client::builder().timeout(Duration::from_secs(3));
+ let mut builder = reqwest::Client::builder().timeout(Duration::from_secs(7));
if url_is_localhost(&url) {
// Some environments set proxy variables (HTTP_PROXY/HTTPS_PROXY/ALL_PROXY) without
@@ -178,6 +178,10 @@ pub async fn check_health(url: &str, password: Option<&str>) -> bool {
.unwrap_or(false)
}
+pub fn is_localhost_url(url: &str) -> bool {
+ reqwest::Url::parse(url).is_ok_and(|u| url_is_localhost(&u))
+}
+
fn url_is_localhost(url: &reqwest::Url) -> bool {
url.host_str().is_some_and(|host| {
host.eq_ignore_ascii_case("localhost")