diff --git a/apps/vectorcraft/src/main.rs b/apps/vectorcraft/src/main.rs index 4b1c77e0f1..d6be1b5dbe 100644 --- a/apps/vectorcraft/src/main.rs +++ b/apps/vectorcraft/src/main.rs @@ -573,9 +573,12 @@ fn finish_pending_update(nightly: bool) { } fn main() -> std::process::ExitCode { - // The launch profile first: a nightly build self-isolates or uses the Launcher's profile here, - // before the update helper, the logger, fonts or any saved state, and `--version` is answered - // here too. + #[cfg(windows)] + if let Some(code) = craft::print::spool::isolated::helper_main() { + std::process::exit(code); + } + // Interactive launches initialize their profile before the update helper, logging, fonts or + // saved state. A nightly uses the Launcher's profile or self-isolates. This also handles `--version`. let Some(arguments) = prepare_launch() else { return std::process::ExitCode::SUCCESS }; let nightly = launch_profile::current().is_nightly(); #[cfg(windows)] diff --git a/apps/vectorcraft/src/printing.rs b/apps/vectorcraft/src/printing.rs index ddfcb52c8c..e4db29ff71 100644 --- a/apps/vectorcraft/src/printing.rs +++ b/apps/vectorcraft/src/printing.rs @@ -353,13 +353,35 @@ mod system { } let settings = settings(job); #[cfg(windows)] - if settings.printer.as_deref().is_some_and(|printer| craft::print::xps_driver(printer) == Some(false)) - && let Some(flat) = super::legacy_spool_copy::flatten(job.pdf, settings.grayscale) { - return craft::print::submit(&flat.pdf, &settings).map_err(|e| e.to_string()); + let prepared = settings + .printer + .as_deref() + .filter(|printer| craft::print::xps_driver(printer) == Some(false)) + .and_then(|_| super::legacy_spool_copy::flatten(job.pdf, settings.grayscale)); + let pdf = prepared.map_or_else(|| job.pdf.to_vec(), |flat| flat.pdf); + submit_driver(pdf, settings) } + #[cfg(not(windows))] craft::print::submit(job.pdf, &settings).map_err(|e| e.to_string()) } + + /// The Print service already runs on the app's background worker. Keep the driver in the + /// private helper and wait here for its queue receipt so the app stays up after a driver exit. + #[cfg(windows)] + fn submit_driver(pdf: Vec, settings: craft::print::Job) -> Result { + let spool = craft::print::spool::Spool::new(std::sync::Arc::new(craft::host::InlineJobs)); + let outcome = spool + .submit_with_receipt(pdf, settings) + .recv() + .map_err(|_| "The print worker stopped. The final outcome is unknown. Check the printer's queue before printing again.".to_owned())?; + outcome + .map(|receipt| match receipt.job_id { + Some(id) => format!("{}. Queue job {id}", receipt.message), + None => receipt.message, + }) + .map_err(|error| error.to_string()) + } /// The spooler's settings for `job`. Copies, layout, marks and colour management are already in the PDF. Preserve /// its physical sheet size and the queue's duplex default without printing copies twice. The driver's paper /// keyword goes to CUPS as `media`, so the queue feeds the paper the job was laid out for.