diff --git a/apps/solidcraft-web/src/files.rs b/apps/solidcraft-web/src/files.rs index bf74e7a6c..3835a53d3 100644 --- a/apps/solidcraft-web/src/files.rs +++ b/apps/solidcraft-web/src/files.rs @@ -676,7 +676,7 @@ pub fn take_drops(files: &Rc, raw: &mut egui::RawInput, theme: bool) { /// any later page. fn hold_page_lock(page: &str) { let Some(locks) = web_locks() else { return }; - let Ok(request) = Reflect::get(&locks, &"request".into()).and_then(|f| f.dyn_into::().map_err(JsValue::from)) else { return }; + let Ok(request) = Reflect::get(&locks, &"request".into()).and_then(|f| f.dyn_into::()) else { return }; // A promise that never settles: the lock is let go only when the page goes. let hold = Closure:: js_sys::Promise>::new(|_lock: JsValue| js_sys::Promise::new(&mut |_, _| {})); let name = format!("{}{page}", keep::LOCK_PREFIX); diff --git a/apps/solidcraft-web/src/install.rs b/apps/solidcraft-web/src/install.rs index e8ae0bd91..54791e07b 100644 --- a/apps/solidcraft-web/src/install.rs +++ b/apps/solidcraft-web/src/install.rs @@ -23,9 +23,9 @@ fn prompt() { let _ = js_sys::Reflect::set(&window, &OFFER.into(), &JsValue::NULL); } let shown = js_sys::Reflect::get(&offer, &"prompt".into()) - .and_then(|f| f.dyn_into::().map_err(JsValue::from)) + .and_then(|f| f.dyn_into::()) .and_then(|f| f.call0(&offer)) - .and_then(|p| p.dyn_into::().map_err(JsValue::from)); + .and_then(|p| p.dyn_into::()); match shown { // Accepted or dismissed, the browser handles it; a refusal is only logged. Ok(p) => wasm_bindgen_futures::spawn_local(async move { diff --git a/crates/engine/src/cmd/file_easyprint.rs b/crates/engine/src/cmd/file_easyprint.rs index 720cf7694..ec9bcc959 100644 --- a/crates/engine/src/cmd/file_easyprint.rs +++ b/crates/engine/src/cmd/file_easyprint.rs @@ -17,7 +17,9 @@ pub(super) struct Exported { pub ext: &'static str, /// A 3MF was asked for and couldn't be written, so this is an STL. pub fell_back: bool, - /// The bodies that went in: the ones named, else the selected ones. + /// The bodies that went in: the ones named, else the selected ones (read by `file.send`, which + /// the browser build doesn't have). + #[cfg_attr(target_arch = "wasm32", allow(dead_code))] pub bodies: Vec, /// The bodies laid on their print face, and the ones that couldn't be. pub laid: super::print_face::Laid, diff --git a/crates/engine/src/cmd/sketch_drag.rs b/crates/engine/src/cmd/sketch_drag.rs index 1d987bd04..95a60f203 100644 --- a/crates/engine/src/cmd/sketch_drag.rs +++ b/crates/engine/src/cmd/sketch_drag.rs @@ -38,7 +38,8 @@ const MAX_STEPS: usize = 64; /// shorter than a step over this; at most `MAX_STEPS` such solves per drag. const HALVINGS: usize = 16; /// Steps of a drag that isn't live solved at once past a failed step, at most (see -/// [`drag_entity`] and [`ahead_batch`]). +/// [`drag_entity`] and [`ahead_batch`]). The browser build solves one at a time. +#[cfg(not(target_arch = "wasm32"))] const AHEAD: usize = 8; /// An arc whose sweep gets this close (radians) to 0 or a full turn has run into its start. const SWEEP_EPS: f64 = 1e-6; diff --git a/crates/engine/src/control_auth.rs b/crates/engine/src/control_auth.rs index 6645a1cfb..1ed228ce4 100644 --- a/crates/engine/src/control_auth.rs +++ b/crates/engine/src/control_auth.rs @@ -305,12 +305,15 @@ fn write_token_file_with(path: &Path, token: &str, restrict: impl FnOnce(&Path) std::fs::set_permissions(dir, std::fs::Permissions::from_mode(0o700))?; opts.mode(0o600); } - let mut f = opts.open(path)?; - if let Err(e) = restrict(path) { - drop(f); - let _ = std::fs::remove_file(path); - return Err(e); - } + let opened = opts.open(path)?; + // On a refusal the file goes with the closure, so it is closed before it is removed. + let mut f = match restrict(path).map(|()| opened) { + Ok(f) => f, + Err(e) => { + let _ = std::fs::remove_file(path); + return Err(e); + } + }; f.write_all(token.as_bytes())?; f.write_all(b"\n")?; f.sync_all()?; diff --git a/crates/io/src/safe_write.rs b/crates/io/src/safe_write.rs index baf309ea0..4130c79e2 100644 --- a/crates/io/src/safe_write.rs +++ b/crates/io/src/safe_write.rs @@ -293,9 +293,11 @@ pub fn create_atomic(path: &Path, bytes: &[u8]) -> std::io::Result<()> { } let tmp = temp_beside(path, "create"); // Only remove a temporary file that this invocation successfully created. - let mut file = OpenOptions::new().write(true).create_new(true).open(&tmp)?; - let result = file.write_all(bytes).and_then(|_| flush(&file)); - drop(file); + // The file closes at the end of this block, before it is linked into place. + let result = { + let mut file = OpenOptions::new().write(true).create_new(true).open(&tmp)?; + file.write_all(bytes).and_then(|_| flush(&file)) + }; let result = result.and_then(|_| fs::hard_link(&tmp, path)); let _ = fs::remove_file(&tmp); if result.is_ok() { diff --git a/crates/ui-egui/src/blur.rs b/crates/ui-egui/src/blur.rs index d310c733e..fa02c444e 100644 --- a/crates/ui-egui/src/blur.rs +++ b/crates/ui-egui/src/blur.rs @@ -192,6 +192,8 @@ mod implementation { pub struct State { radius: f32, } + /// A frame's blur, as the native [`State::begin`] gives it; here there is nothing to end. + pub struct Scope; impl State { pub fn install(&mut self, _: &egui_wgpu::RenderState, _: bool) {} pub fn set_radius(&mut self, radius: f32) -> Result<(), &'static str> { @@ -210,7 +212,9 @@ mod implementation { pub fn counters(&self) -> Counters { Counters::default() } - pub fn begin(&mut self, _: &egui::Context, _: bool) {} + pub fn begin(&mut self, _: &egui::Context, _: bool) -> Scope { + Scope + } pub fn set_surface_alpha(&mut self, _: Option) {} pub fn set_available(&mut self, _: bool) {} pub fn set_tier_cap(&mut self, _: usize) {} diff --git a/crates/ui-egui/src/browser/point_cloud_tracks.rs b/crates/ui-egui/src/browser/point_cloud_tracks.rs index d9bb5aab6..08dc05ffe 100644 --- a/crates/ui-egui/src/browser/point_cloud_tracks.rs +++ b/crates/ui-egui/src/browser/point_cloud_tracks.rs @@ -5,7 +5,9 @@ //! for the values the coloured property takes over what is kept: the ramp's automatic range. use std::collections::HashMap; -use std::sync::{Arc, Condvar, Mutex}; +#[cfg(not(target_arch = "wasm32"))] +use std::sync::Condvar; +use std::sync::{Arc, Mutex}; use egui::Color32; use solidcraft_engine::doc::point_cloud::{Filter, PALETTE, PLAIN, PointCloud, byte, height_ramp}; @@ -128,6 +130,8 @@ struct Inner { #[derive(Default)] struct Shared { inner: Mutex, + /// Wakes the worker thread (the browser build answers on the window thread instead). + #[cfg(not(target_arch = "wasm32"))] asked: Condvar, } diff --git a/crates/ui-egui/src/deferred.rs b/crates/ui-egui/src/deferred.rs index ad801ed55..44b0ade71 100644 --- a/crates/ui-egui/src/deferred.rs +++ b/crates/ui-egui/src/deferred.rs @@ -76,7 +76,8 @@ pub struct DocJobs { /// How a command asked to run off the window thread goes. enum Start { - /// It computes off the window thread. + /// It computes off the window thread (never in the browser build, which has one thread). + #[cfg_attr(target_arch = "wasm32", allow(dead_code))] Later(Deferred), /// It runs now, with what was evaluated for it ahead (if anything). Now(Option, Option>), diff --git a/crates/ui-egui/src/dialogs_library.rs b/crates/ui-egui/src/dialogs_library.rs index 05a09f801..4dce9941d 100644 --- a/crates/ui-egui/src/dialogs_library.rs +++ b/crates/ui-egui/src/dialogs_library.rs @@ -1,4 +1,5 @@ //! The first local appearance-library consumer, inside the existing Appearance panel. +#[cfg(not(target_arch = "wasm32"))] use crate::dialogs_appearance::selected_params; #[cfg(not(target_arch = "wasm32"))] use crate::ui_kit::BackingTooltipExt as _; diff --git a/crates/ui-egui/src/file_load.rs b/crates/ui-egui/src/file_load.rs index 45b087649..a8402ad79 100644 --- a/crates/ui-egui/src/file_load.rs +++ b/crates/ui-egui/src/file_load.rs @@ -12,6 +12,7 @@ //! linked design being read and its rebuild's progress. use crate::ui_kit::{Container, Surface}; +#[cfg(not(target_arch = "wasm32"))] use solidcraft_engine::geom::prelude::*; use std::collections::VecDeque; use std::sync::{ diff --git a/crates/ui-egui/src/home.rs b/crates/ui-egui/src/home.rs index a39295ec6..004aed9d5 100644 --- a/crates/ui-egui/src/home.rs +++ b/crates/ui-egui/src/home.rs @@ -588,9 +588,13 @@ fn ask_present(h: &mut HomeState, ctx: &egui::Context, recent: &[String]) { } } } + // The browser's files are in memory, so they are looked up here; no thread wakes the page. #[cfg(target_arch = "wasm32")] - for p in recent { - h.present.insert(p.clone(), solidcraft_engine::io::vfs::exists(p)); + { + let _ = ctx; + for p in recent { + h.present.insert(p.clone(), solidcraft_engine::io::vfs::exists(p)); + } } }