From 000d8a1687ef20c4879adaef249302bcf98b54eb Mon Sep 17 00:00:00 2001 From: Helen Kwok <107752876+helenkwok@users.noreply.github.com> Date: Fri, 18 Sep 2026 15:18:54 +0930 Subject: [PATCH] Fix wasm32 build: gate the font download and XREF open call sites crate::network and the open crate are desktop-only, but the community-font download (font_repo.rs) and the XREF row Open action call them unconditionally, so cargo check --target wasm32-unknown-unknown fails on main. Gate both; on the web download_fonts returns an error, since the web build has no network client or fonts folder. --- src/app/update/mod.rs | 1 + src/io/font_repo.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/app/update/mod.rs b/src/app/update/mod.rs index 5d650515d..05ffe3d3f 100644 --- a/src/app/update/mod.rs +++ b/src/app/update/mod.rs @@ -2482,6 +2482,7 @@ impl OpenCADStudio { if is_dwg { return self.update(Message::OpenRecent(std::path::PathBuf::from(found))); } else { + #[cfg(not(target_arch = "wasm32"))] let _ = open::that_detached(&found); } } else { diff --git a/src/io/font_repo.rs b/src/io/font_repo.rs index f4f4162e6..8df774c66 100644 --- a/src/io/font_repo.rs +++ b/src/io/font_repo.rs @@ -13,8 +13,10 @@ use std::path::{Path, PathBuf}; use acadrust::CadDocument; /// The community folder's GitHub contents API (lists name + download URL). +#[cfg(not(target_arch = "wasm32"))] const REPO_API_URL: &str = "https://api.github.com/repos/HakanSeven12/OpenCADStudio/contents/fonts"; +#[cfg(not(target_arch = "wasm32"))] const MAX_FONT_BYTES: u64 = 16 * 1024 * 1024; /// Local store for fonts downloaded from the community repository. Text @@ -104,6 +106,7 @@ pub fn local_font_file(name: &str) -> Option { } /// List the community folder through the GitHub contents API. +#[cfg(not(target_arch = "wasm32"))] fn fetch_repo_fonts() -> Result, String> { let agent = crate::network::agent(std::time::Duration::from_secs(15)); let mut response = agent @@ -121,6 +124,7 @@ fn fetch_repo_fonts() -> Result, String> { /// Parse the GitHub contents-API response: /// `[{"name":"romans.shx","download_url":"https://…"}, …]`. +#[cfg(not(target_arch = "wasm32"))] fn parse_contents(body: &str) -> Result, String> { let value: serde_json::Value = serde_json::from_str(body).map_err(|e| format!("Unexpected font listing: {e}"))?; @@ -143,6 +147,7 @@ fn parse_contents(body: &str) -> Result, String> { /// Download every `missing` font that exists in the community folder into the /// local fonts directory. Returns the (requested, saved-path) pairs that were /// actually fetched; names absent from the repository are skipped. +#[cfg(not(target_arch = "wasm32"))] pub fn download_fonts( missing: &[String], source: &FontSource, @@ -201,8 +206,21 @@ pub fn download_fonts( Ok(downloaded) } +/// The web build has no network client, and no fonts folder to save into. +#[cfg(target_arch = "wasm32")] +pub fn download_fonts( + missing: &[String], + _source: &FontSource, +) -> Result, String> { + if missing.is_empty() { + return Ok(Vec::new()); + } + Err("Downloading fonts is not available in the web app.".to_string()) +} + /// Escape path characters that would break a URL (spaces and non-ASCII file /// names are common in font sets). +#[cfg(not(target_arch = "wasm32"))] fn percent_encode_path(file: &str) -> String { let mut out = String::with_capacity(file.len()); for byte in file.bytes() {