From d6ede2318327f02834c4d40234b5dbf5531542d9 Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Wed, 11 Mar 2026 10:31:33 +0100 Subject: [PATCH] feat(servo-shell): wire appd WebSocket port discovery at startup appd_ws_port() -> u16: - Checks WEFT_APPD_WS_PORT env var first. - Falls back to reading XDG_RUNTIME_DIR/weft/appd.wsport. - Falls back to hardcoded default 7410. run() now calls appd_ws_port() and passes the result to embed_servo. embed_servo signature updated to accept ws_port: u16. When the Servo embedder is implemented, it injects the port as window.WEFT_APPD_WS_PORT before loading the system UI HTML. --- crates/weft-servo-shell/src/main.rs | 30 +++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/crates/weft-servo-shell/src/main.rs b/crates/weft-servo-shell/src/main.rs index 86dfc34..45b2e5f 100644 --- a/crates/weft-servo-shell/src/main.rs +++ b/crates/weft-servo-shell/src/main.rs @@ -24,7 +24,10 @@ fn run() -> anyhow::Result<()> { let html_path = system_ui_html_path()?; tracing::info!(path = %html_path.display(), "system UI entry point located"); - embed_servo(&wayland_display, &html_path) + let ws_port = appd_ws_port(); + tracing::info!(ws_port, "appd WebSocket port"); + + embed_servo(&wayland_display, &html_path, ws_port) } fn system_ui_html_path() -> anyhow::Result { @@ -42,7 +45,30 @@ fn system_ui_html_path() -> anyhow::Result { ) } -fn embed_servo(_wayland_display: &str, _html_path: &std::path::Path) -> anyhow::Result<()> { +fn appd_ws_port() -> u16 { + if let Ok(explicit) = std::env::var("WEFT_APPD_WS_PORT") + && let Ok(n) = explicit.trim().parse::() + { + return n; + } + if let Ok(runtime_dir) = std::env::var("XDG_RUNTIME_DIR") { + let port_file = std::path::Path::new(&runtime_dir) + .join("weft") + .join("appd.wsport"); + if let Ok(contents) = std::fs::read_to_string(&port_file) + && let Ok(n) = contents.trim().parse::() + { + return n; + } + } + 7410 +} + +fn embed_servo( + _wayland_display: &str, + _html_path: &std::path::Path, + _ws_port: u16, +) -> anyhow::Result<()> { anyhow::bail!( "Servo embedding not yet implemented; \ see docs/architecture/winit-wayland-audit.md for gap assessment"