← Commit history

2.11.1: dock webview claim never delays the serve URL

John Lauer ·fd56fd0b2b ·1mo ago ·parent 0f58d45
7 files changed +50−21
Cargo.lock+1−1
@@ -10,7 +10,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"  [[package]] name = "adom-lbr"-version = "2.11.0"+version = "2.11.1" dependencies = [  "altium-codec",  "anyhow",
Cargo.toml+1−1
@@ -1,6 +1,6 @@ [package] name = "adom-lbr"-version = "2.11.0"+version = "2.11.1" edition = "2021" description = "adom-lbr generator / EDA translator: the canonical adom-lbr JSON is the hub, with native converters to Altium (.SchLib/.PcbLib/.IntLib), EAGLE/Fusion (.lbr), and KiCad. Altium output is written natively — no Altium needed at conversion time." 
VERSION+1−1
@@ -1 +1 @@-2.11.0+2.11.1
package.json+1−1
@@ -1,6 +1,6 @@ {   "slug": "adom-lbr",-  "version": "2.11.0",+  "version": "2.11.1",   "type": "app",   "description": "adom-lbr \u2014 the EDA library translator. Bring a component in from any supported EDA tool and convert it to any other (KiCad \u21c4 Altium \u21c4 EAGLE/Fusion) through one canonical adom-lbr JSON \u2014 symbol + footprint + 3D + pin\u2194pad map. Altium is written natively (no Altium needed). Includes the adom-lbr Manager: browse wiki components and view symbol/footprint/3D + the per-EDA layer stackup.",   "dependencies": {},
page.json+9−12
@@ -1,8 +1,8 @@ {   "slug": "adom-lbr",-  "version": "2.11.0",+  "version": "2.11.1",   "type": "app",-  "description": "adom-lbr — the EDA library translator. Bring a component in from any supported EDA tool and convert it to any other (KiCad ⇄ Altium ⇄ EAGLE/Fusion) through one canonical adom-lbr JSON — symbol + footprint + 3D + pin↔pad map. Altium is written natively (no Altium needed). Includes the adom-lbr Manager: browse wiki components and view symbol/footprint/3D + the per-EDA layer stackup.",+  "description": "adom-lbr \u2014 the EDA library translator. Bring a component in from any supported EDA tool and convert it to any other (KiCad \u21c4 Altium \u21c4 EAGLE/Fusion) through one canonical adom-lbr JSON \u2014 symbol + footprint + 3D + pin\u2194pad map. Altium is written natively (no Altium needed). Includes the adom-lbr Manager: browse wiki components and view symbol/footprint/3D + the per-EDA layer stackup.",   "dependencies": {},   "tags": [     "eda",@@ -52,24 +52,21 @@   ],   "files": [     "bin/**",-    "assets/**",     "SKILL.md",-    "skills/**",     "README.md",     "install.sh",     "uninstall.sh",-    "screenshots/**",-    "dockbar.json"+    "screenshots/**"   ],-  "discovery_pitch": "Convert electronic-component symbols + footprints between any two EDA tools — KiCad, Altium (written natively, no Altium needed), and EAGLE/Fusion — through one canonical adom-lbr JSON, silk/courtyard/fab layers preserved. Plus a Manager to browse and inspect any wiki part.",+  "discovery_pitch": "Convert electronic-component symbols + footprints between any two EDA tools \u2014 KiCad, Altium (written natively, no Altium needed), and EAGLE/Fusion \u2014 through one canonical adom-lbr JSON, silk/courtyard/fab layers preserved. Plus a Manager to browse and inspect any wiki part.",   "sample_prompts": [     {       "prompt": "Convert this KiCad symbol and footprint to an Altium SchLib and PcbLib",-      "label": "KiCad → Altium"+      "label": "KiCad \u2192 Altium"     },     {       "prompt": "Import this Altium footprint into the adom-lbr JSON",-      "label": "Altium → JSON"+      "label": "Altium \u2192 JSON"     },     {       "prompt": "Bundle this part into a single Altium IntLib",@@ -77,15 +74,15 @@     },     {       "prompt": "Convert this Altium SchLib and PcbLib to a KiCad symbol and footprint",-      "label": "Altium → KiCad"+      "label": "Altium \u2192 KiCad"     },     {       "prompt": "Export this adom-lbr JSON to a KiCad .kicad_sym and .kicad_mod",-      "label": "JSON → KiCad"+      "label": "JSON \u2192 KiCad"     },     {       "prompt": "Open the adom-lbr Manager to browse wiki components and view the layer stackup",       "label": "Browse parts"     }   ]-}\ No newline at end of file+}
src/dock.rs+24−5
@@ -584,11 +584,30 @@ pub fn claim_dock_webview(port: u16) {     if name.trim().is_empty() {         return;     }+    claim_named_webview(&name, port);+}++/// The claim itself, in a thread: adom-cli can take many seconds on a box+/// without Hydrogen, and the URL must print the moment the socket answers.+pub fn claim_named_webview(name: &str, port: u16) {+    let name = name.to_string();     let url = direct_url(port);-    let _ = Command::new("adom-cli")-        .args(["hydrogen", "webview", "open-or-refresh", "--name", &name, "--url", &url])-        .stdin(Stdio::null()).stdout(Stdio::null()).stderr(Stdio::null())-        .status();+    std::thread::spawn(move || {+        let _ = Command::new("adom-cli")+            .args(["hydrogen", "webview", "open-or-refresh", "--name", &name, "--url", &url])+            .stdin(Stdio::null()).stdout(Stdio::null()).stderr(Stdio::null())+            .status();+    });+}++/// Reuse path: this process exits right away, so ask the RUNNING server to+/// claim the tab (it has all the time in the world).+fn ask_server_to_claim(port: u16) {+    let name = std::env::var("ADOM_DOCK_WEBVIEW").unwrap_or_default();+    if name.trim().is_empty() {+        return;+    }+    let _ = curl_json(&format!("http://127.0.0.1:{port}/api/claim-webview"), Some(&json!({"name": name})), 2); }  /// The dock entry point. Returns Ok(true) when a server is (now) serving and@@ -614,7 +633,7 @@ pub fn serve_entry(port: u16, print_url: bool, foreground: bool) -> anyhow::Resu     if theirs.is_some() {         if print_url { println!("{}", direct_url(port)); }         else { eprintln!("adom-lbr dashboard {VERSION} already serving on {port}; nothing to do"); }-        claim_dock_webview(port);+        ask_server_to_claim(port);         return Ok(true);     }     if foreground {
src/manage.rs+13
@@ -57,6 +57,8 @@ fn my_owner() -> String { }  static OWNER_CACHE: Mutex<Option<(std::time::Instant, String)>> = Mutex::new(None);+static SERVER_PORT: Mutex<u16> = Mutex::new(8785);+fn port_of_server() -> u16 { *SERVER_PORT.lock().unwrap() }  /// The wiki component list is slow (~8s) but stable — fetch it once, serve /// instantly after. First click blocks; the rest are snappy.@@ -89,6 +91,7 @@ pub fn run(port: u16) -> Result<()> {     let server = Server::http(format!("{bind}:{port}"))         .map_err(|e| anyhow::anyhow!("bind {bind}:{port}: {e}"))?;     dock::mark_started();+    *SERVER_PORT.lock().unwrap() = port;     println!("OK: adom-lbr dashboard {} on {}", dock::VERSION, dock::direct_url(port));     println!("Hint: the dock reads /api/status; the component list comes from {WIKI}; click a row to open the viewer.");     // Socket is bound, so the tab we claim lands on a page that answers.@@ -160,6 +163,16 @@ fn route_inner(method: &Method, url: &str, path: &str, body: &str) -> Response<C             Err(e) => json_resp(&json!({"status":"error","error":format!("bad body: {e}")}).to_string()),         },         (Method::Post, "/api/settings/reset") => json_resp(&dock::reset_settings().to_string()),+        (Method::Post, "/api/claim-webview") => {+            let name = serde_json::from_str::<Value>(body).ok()+                .and_then(|v| v.get("name").and_then(|n| n.as_str()).map(String::from))+                .unwrap_or_default();+            if name.trim().is_empty() {+                return json_resp(&json!({"status":"error","error":"name required"}).to_string());+            }+            dock::claim_named_webview(&name, port_of_server());+            json_resp(&json!({"status":"ok","claimed":name}).to_string())+        }         (Method::Get, "/api/durations") => json_resp(&dock::durations().to_string()),         (Method::Post, p) if p.starts_with("/api/lifecycle/") => {             let action = &p["/api/lifecycle/".len()..];