From 38c9a029e4f3bc193d20538dd9af8c2668efd43f Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 18 Nov 2026 17:22:46 -0500 Subject: [PATCH] compile fix 5 (rest): L-218 page-body callees take PageSession + PageGeometry / open_intake (swarm/cfix5); committed by the lead --- crates/ui-egui/src/app/input.rs | 57 +++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/crates/ui-egui/src/app/input.rs b/crates/ui-egui/src/app/input.rs index 858ed934fb..efebab3445 100644 --- a/crates/ui-egui/src/app/input.rs +++ b/crates/ui-egui/src/app/input.rs @@ -1,11 +1,68 @@ use craft::ui::runtime::drag::OsFile; // PLAN: assumed path of `OsFile` in the facade (ui-contract `runtime/drag.rs`) use super::PdfCraftApp; +use craft::platform::open::{DroppedFile, Intake}; /// The name a dropped file is opened under when the OS gave none. const DROPPED_NAME: &str = "dropped.pdf"; +/// The action a `--combine` launch sends with its files (`single_instance::deliver`). +#[cfg(not(target_arch = "wasm32"))] +const COMBINE_ACTION: &str = "combine"; + +/// Raises the window for an open request from the OS. +fn bring_to_front(ctx: &egui::Context) { + ctx.send_viewport_cmd(egui::ViewportCommand::Minimized(false)); + ctx.send_viewport_cmd(egui::ViewportCommand::Focus); +} + +fn os_file(file: DroppedFile) -> OsFile { + OsFile { name: file.name, path: file.path, mime: String::new(), bytes: file.bytes } +} + impl PdfCraftApp { + /// Opens what the file intake holds, batch by batch in arrival order: another launch's paths + /// like File ▸ Open, its `combine` files in the Combine files tab, bytes as a new tab, drops + /// as [`Self::open_dropped`]. A batch from the OS brings the window to the front. + pub(crate) fn open_intake(&mut self, ctx: &egui::Context) { + for batch in self.intake.take() { + match batch { + Intake::Open(paths) => { + #[cfg(not(target_arch = "wasm32"))] + for path in &paths { + self.open_path(&path.to_string_lossy()); + } + #[cfg(target_arch = "wasm32")] + drop(paths); + bring_to_front(ctx); + } + Intake::OpenFor { paths, action } => { + #[cfg(not(target_arch = "wasm32"))] + { + let paths: Vec = paths.iter().map(|p| p.to_string_lossy().into_owned()).collect(); + if action == COMBINE_ACTION { + self.combine_paths(&paths); + } else { + for path in &paths { + self.open_path(path); + } + } + } + #[cfg(target_arch = "wasm32")] + drop((paths, action)); + bring_to_front(ctx); + } + Intake::Bytes { name, bytes } => { + let name = if name.is_empty() { DROPPED_NAME.to_string() } else { name }; + if let Err(error) = self.open_bytes(&name, None, bytes.to_vec()) { + self.notify_fmt("Couldn't open {name}: {e}", &[("name", &name), ("e", &error)]); + } + } + Intake::Dropped { files, .. } => self.open_dropped(files.into_iter().map(os_file).collect()), + } + } + } + /// Opens the files dropped on the window: a file with a path like File ▸ Open, one that /// arrived as bytes (the web) as a new tab. pub(crate) fn open_dropped(&mut self, files: Vec) {