mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-03 15:21:17 -05:00
Isolate Windows VectorCraft PDF printing and retain queue receipts
Dispatch the private helper before interactive startup and wait for typed submission evidence on the existing background path. Preserve the explicitly selected raw PDF and driver-specific preparation. Refs #9261 and storytold/craft-libs#4859.
This commit is contained in:
@@ -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)]
|
||||
|
||||
@@ -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<u8>, settings: craft::print::Job) -> Result<String, String> {
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user