fix: use TCP instead of Unix socket on Windows in dashboard relay (#1038)

`relay_command_to_daemon` in stream.rs used `tokio::net::UnixStream`
unconditionally, which doesn't compile on Windows. Add platform-
conditional code matching the existing pattern in daemon.rs and
connection.rs: Unix sockets on unix, TCP on Windows.
This commit is contained in:
Chris Tate
2026-03-26 13:36:22 -07:00
committed by GitHub
parent f9174513c2
commit 995a47fdb0
2 changed files with 22 additions and 10 deletions
+1 -1
View File
@@ -144,7 +144,7 @@ fn get_port_path(session: &str) -> PathBuf {
} }
#[cfg(windows)] #[cfg(windows)]
fn get_port_for_session(session: &str) -> u16 { pub fn get_port_for_session(session: &str) -> u16 {
let mut hash: i32 = 0; let mut hash: i32 = 0;
for c in session.chars() { for c in session.chars() {
hash = ((hash << 5).wrapping_sub(hash)).wrapping_add(c as i32); hash = ((hash << 5).wrapping_sub(hash)).wrapping_add(c as i32);
+21 -9
View File
@@ -10,6 +10,8 @@ use tokio::sync::{broadcast, watch, Mutex, Notify, RwLock};
use tokio_tungstenite::tungstenite::Message; use tokio_tungstenite::tungstenite::Message;
use super::cdp::client::CdpClient; use super::cdp::client::CdpClient;
#[cfg(windows)]
use crate::connection::get_port_for_session;
use crate::connection::get_socket_dir; use crate::connection::get_socket_dir;
use crate::install::get_dashboard_dir; use crate::install::get_dashboard_dir;
@@ -1183,7 +1185,7 @@ fn extract_http_body(request: &str) -> Option<&str> {
.or_else(|| request.find("\n\n").map(|pos| &request[pos + 2..])) .or_else(|| request.find("\n\n").map(|pos| &request[pos + 2..]))
} }
/// Relay a command JSON body to the daemon's Unix socket and return the response. /// Relay a command JSON body to the daemon and return the response.
async fn relay_command_to_daemon(session_name: &str, body: &str) -> Result<String, String> { async fn relay_command_to_daemon(session_name: &str, body: &str) -> Result<String, String> {
let mut cmd: Value = serde_json::from_str(body).map_err(|e| format!("Invalid JSON: {}", e))?; let mut cmd: Value = serde_json::from_str(body).map_err(|e| format!("Invalid JSON: {}", e))?;
@@ -1198,17 +1200,27 @@ async fn relay_command_to_daemon(session_name: &str, body: &str) -> Result<Strin
cmd["id"] = json!(id); cmd["id"] = json!(id);
} }
let socket_path = get_socket_dir().join(format!("{}.sock", session_name));
let stream = tokio::net::UnixStream::connect(&socket_path)
.await
.map_err(|e| format!("Failed to connect to daemon: {}", e))?;
let (reader, mut writer) = tokio::io::split(stream);
let mut json_str = serde_json::to_string(&cmd).map_err(|e| e.to_string())?; let mut json_str = serde_json::to_string(&cmd).map_err(|e| e.to_string())?;
json_str.push('\n'); json_str.push('\n');
#[cfg(unix)]
let stream = {
let socket_path = get_socket_dir().join(format!("{}.sock", session_name));
tokio::net::UnixStream::connect(&socket_path)
.await
.map_err(|e| format!("Failed to connect to daemon: {}", e))?
};
#[cfg(windows)]
let stream = {
let port = get_port_for_session(session_name);
tokio::net::TcpStream::connect(format!("127.0.0.1:{}", port))
.await
.map_err(|e| format!("Failed to connect to daemon: {}", e))?
};
let (reader, mut writer) = tokio::io::split(stream);
writer writer
.write_all(json_str.as_bytes()) .write_all(json_str.as_bytes())
.await .await