* claim: #12222 * Web app: clippy for wasm passes with -D warnings (#12222) cargo clippy -p solidcraft-web --target wasm32-unknown-unknown stopped at drop(file) in safe_write.rs and showed 12 more warnings only that target has. Each is fixed where it is: - safe_write::create_atomic and control_auth::write_token_file_with close their File by scope (a block; Result::map's closure) instead of drop(), which clippy's drop_non_drop flags where File is a stub. - Native-only imports, the AHEAD constant and the point-cloud worker's Condvar are behind cfg(not(target_arch = "wasm32")); Exported::bodies and Start::Later, read or built only natively, allow dead_code there. - home::ask_present uses ctx in its browser branch; the browser blur stub's begin returns a Scope, as the native one does. - The web app drops three map_err(JsValue::from) on dyn_into's error, which is a JsValue already. Native builds behave the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: thocsmith <193096300+thocsmith@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: bherbruck <brennen.herbruck@gmail.com>
This commit is contained in:
12 files changed
+42
-19
No files matched your search
@@ -676,7 +676,7 @@ pub fn take_drops(files: &Rc<Files>, 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::<Function>().map_err(JsValue::from)) else { return };
|
||||
let Ok(request) = Reflect::get(&locks, &"request".into()).and_then(|f| f.dyn_into::<Function>()) else { return };
|
||||
// A promise that never settles: the lock is let go only when the page goes.
|
||||
let hold = Closure::<dyn FnMut(JsValue) -> js_sys::Promise>::new(|_lock: JsValue| js_sys::Promise::new(&mut |_, _| {}));
|
||||
let name = format!("{}{page}", keep::LOCK_PREFIX);
|
||||
|
||||
@@ -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::<js_sys::Function>().map_err(JsValue::from))
|
||||
.and_then(|f| f.dyn_into::<js_sys::Function>())
|
||||
.and_then(|f| f.call0(&offer))
|
||||
.and_then(|p| p.dyn_into::<js_sys::Promise>().map_err(JsValue::from));
|
||||
.and_then(|p| p.dyn_into::<js_sys::Promise>());
|
||||
match shown {
|
||||
// Accepted or dismissed, the browser handles it; a refusal is only logged.
|
||||
Ok(p) => wasm_bindgen_futures::spawn_local(async move {
|
||||
|
||||
@@ -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<String>,
|
||||
/// The bodies laid on their print face, and the ones that couldn't be.
|
||||
pub laid: super::print_face::Laid,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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()?;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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<u8>) {}
|
||||
pub fn set_available(&mut self, _: bool) {}
|
||||
pub fn set_tier_cap(&mut self, _: usize) {}
|
||||
|
||||
@@ -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<Inner>,
|
||||
/// Wakes the worker thread (the browser build answers on the window thread instead).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
asked: Condvar,
|
||||
}
|
||||
|
||||
|
||||
@@ -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<solidcraft_engine::Evaluated>, Option<std::sync::Arc<solidcraft_engine::doc::KeptResults>>),
|
||||
|
||||
@@ -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 _;
|
||||
|
||||
@@ -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::{
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user