diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..e3ff66fc1c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# The DXF writer goldens are compared byte for byte with the writer's output (LF line endings). +crates/cad/tests/data/*.dxf -text diff --git a/.github/nightly-signing-policy.json b/.github/nightly-signing-policy.json index 507caffe10..6b6099e7b6 100644 --- a/.github/nightly-signing-policy.json +++ b/.github/nightly-signing-policy.json @@ -130,7 +130,15 @@ "unsigned_artifact_name": "nightly-unsigned-linux-x86_64", "trust": { "fingerprint": "2B76741B414AAD6CD33E631213A005C0B9D7C3ED" - } + }, + "package_formats": [ + "appimage", + "arch", + "deb", + "flatpak", + "oci", + "rpm" + ] }, "macos-aarch64": { "unsigned_artifact_name": "nightly-unsigned-macos-aarch64", diff --git a/apps/vectorcraft-web/src/file_drops.rs b/apps/vectorcraft-web/src/file_drops.rs new file mode 100644 index 0000000000..1b98d7b57b --- /dev/null +++ b/apps/vectorcraft-web/src/file_drops.rs @@ -0,0 +1,98 @@ +//! The hand-off from the browser's input hook to the visible UI pass. + +use std::cell::Cell; + +use egui::{DroppedFileHandle, Pos2, RawInput}; + +/// CSS pixels from the canvas origin, and whether Shift was held. +pub(crate) type DragPosition = (f32, f32, bool); + +pub(crate) struct DropBatch { + pub(crate) files: Vec, + pub(crate) pos: Option, + pub(crate) shift: bool, +} + +#[derive(Default)] +pub(crate) struct FileDrops(Vec); + +impl FileDrops { + pub(crate) fn capture(&mut self, raw: &mut RawInput) { + // The shared router reads dropped files at the start of the pass, before the web UI runs. + self.0.append(&mut raw.dropped_files); + } + + pub(crate) fn take(&mut self, ctx: &egui::Context, position: &Cell>) -> Option { + let files = std::mem::take(&mut self.0); + if files.is_empty() { + return None; + } + let at = position.take(); + let z = ctx.zoom_factor(); + let pos = at.map(|(x, y, _)| egui::pos2(x / z, y / z)); + let shift = at.is_some_and(|(_, _, shift)| shift); + Some(DropBatch { files, pos, shift }) + } +} + +#[cfg(all(test, not(target_arch = "wasm32")))] +mod tests { + use std::path::Path; + use std::sync::Arc; + use std::sync::atomic::{AtomicUsize, Ordering}; + + use super::*; + + #[derive(Debug)] + struct Svg; + + impl egui::DroppedFile for Svg { + fn path(&self) -> &Path { + Path::new("drawing.svg") + } + + fn bytes(&self) -> Result, String> { + Err("test file has no contents".into()) + } + } + + fn check_handoff(at: Option, expected_pos: Option, expected_shift: bool) { + let ctx = egui::Context::default(); + let shared_files = Arc::new(AtomicUsize::new(0)); + ctx.on_begin_pass("observe dropped files before the app UI", { + let shared_files = shared_files.clone(); + Arc::new(move |ui| { + shared_files.fetch_add(ui.ctx().input(|input| input.raw.dropped_files.len()), Ordering::Relaxed); + }) + }); + let mut drops = FileDrops::default(); + let position = Cell::new(at); + let svg = Arc::new(Svg) as DroppedFileHandle; + let mut raw = RawInput { dropped_files: vec![svg.clone()], ..Default::default() }; + + drops.capture(&mut raw); + let mut delivered = Vec::new(); + ctx.run_ui(raw, |ui| delivered.extend(drops.take(ui.ctx(), &position))).textures_delta.clear(); + let mut next = RawInput::default(); + drops.capture(&mut next); + ctx.run_ui(next, |ui| delivered.extend(drops.take(ui.ctx(), &position))).textures_delta.clear(); + + assert_eq!(shared_files.load(Ordering::Relaxed), 0, "the shared router must not see browser-owned drops"); + assert_eq!(delivered.len(), 1, "the browser UI must receive exactly one batch"); + let batch = &delivered[0]; + assert_eq!(batch.files.len(), 1, "the browser UI must receive exactly one file"); + assert!(Arc::ptr_eq(&batch.files[0], &svg)); + assert_eq!((batch.pos, batch.shift), (expected_pos, expected_shift)); + assert!(position.get().is_none()); + } + + #[test] + fn a_positioned_browser_drop_reaches_the_web_ui_once() { + check_handoff(Some((53.0, 27.0, true)), Some(egui::pos2(53.0, 27.0)), true); + } + + #[test] + fn a_browser_drop_without_a_position_reaches_the_web_ui_once() { + check_handoff(None, None, false); + } +} diff --git a/apps/vectorcraft-web/src/main.rs b/apps/vectorcraft-web/src/main.rs index 696c09aab1..f8a6015fa4 100644 --- a/apps/vectorcraft-web/src/main.rs +++ b/apps/vectorcraft-web/src/main.rs @@ -22,6 +22,8 @@ #[cfg(target_arch = "wasm32")] mod api; +#[cfg(any(target_arch = "wasm32", test))] +mod file_drops; #[cfg(target_arch = "wasm32")] mod fonts; #[cfg(any(target_arch = "wasm32", test))] diff --git a/apps/vectorcraft-web/src/web.rs b/apps/vectorcraft-web/src/web.rs index 0272b70a3f..64a596e5ba 100644 --- a/apps/vectorcraft-web/src/web.rs +++ b/apps/vectorcraft-web/src/web.rs @@ -22,6 +22,7 @@ use vectorcraft_ui_egui::print::{PrintJob, PrintService, Printer}; use vectorcraft_ui_egui::{Services, VectorcraftApp}; use wasm_bindgen::JsCast as _; +use crate::file_drops::{DragPosition, DropBatch, FileDrops}; use crate::locks::WebLocks; use crate::pencil::SharedPointers; @@ -39,7 +40,7 @@ struct OpenInboxes { /// Where the pointer was over the canvas during the last file drag (CSS px from its top-left) and /// whether Shift was held: where dropped files land. -type DragPos = Rc>>; +type DragPos = Rc>>; /// A picture or file pasted into the page, read and waiting for the next frame with the modifiers /// held at the paste, and the context to wake for it (the current runner's). @@ -176,7 +177,7 @@ async fn run(host: Host, canvas: web_sys::HtmlCanvasElement, moving: Option