mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-03 22:41:09 +00:00
Keep DeckCraft print job feedback after leaving the printer settings
This commit is contained in:
@@ -197,6 +197,8 @@ impl SlideApp {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
print_spool: None,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
print_receipt: None,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
updates_rt: Default::default(),
|
||||
selpane: Default::default(),
|
||||
align_to: None,
|
||||
@@ -264,6 +266,24 @@ impl SlideApp {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn poll_print_receipt(&mut self, ctx: &egui::Context) {
|
||||
use std::sync::mpsc::TryRecvError;
|
||||
|
||||
let Some((printer, receipt)) = &self.print_receipt else { return };
|
||||
let status = match receipt.try_recv() {
|
||||
Ok(Ok(message)) => format!("Sent to {printer}: {message}"),
|
||||
Ok(Err(error)) => format!("Couldn't print: {error}"),
|
||||
Err(TryRecvError::Disconnected) => "Couldn't confirm whether the print job reached the printer".into(),
|
||||
Err(TryRecvError::Empty) => {
|
||||
ctx.request_repaint_after(std::time::Duration::from_millis(200));
|
||||
return;
|
||||
}
|
||||
};
|
||||
self.print_receipt = None;
|
||||
self.set_status(status);
|
||||
}
|
||||
|
||||
/// Displays a transient message in the status bar.
|
||||
pub fn set_status(&mut self, msg: impl Into<String>) {
|
||||
self.status = Some((msg.into(), self.clock.now() * 1000.0));
|
||||
@@ -386,6 +406,8 @@ impl SlideApp {
|
||||
if !Self::root_viewport_admitted(ctx) {
|
||||
return;
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
self.poll_print_receipt(ctx);
|
||||
self.tick_hidden_show(ctx, web_time::Instant::now());
|
||||
if WindowHost::of(ctx).injected_idle() {
|
||||
self.drain_intake(ctx);
|
||||
|
||||
@@ -58,7 +58,7 @@ pub static UI_COMMANDS: &[UiCommand] = &[
|
||||
UiCommand {
|
||||
id: "app.print",
|
||||
label: "Print",
|
||||
params: "{layout?, perPage?, slides?, includeHidden?, frame?, paper?: letter|a4|legal|a3, orientation?: portrait|landscape}",
|
||||
params: "{layout?, perPage?, slides?, includeHidden?, frame?, paper?: letter|a4|legal|a3, orientation?: portrait|landscape} (no options opens desktop print settings when a system spooler is installed)",
|
||||
},
|
||||
UiCommand { id: "app.about", label: "About DeckCraft", params: "{}" },
|
||||
UiCommand { id: "app.checkUpdates", label: "Check for Updates…", params: "{}" },
|
||||
|
||||
@@ -275,6 +275,11 @@ impl SlideApp {
|
||||
if self.session.active().is_none() {
|
||||
return Err("nothing to print: no presentation is open".into());
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if self.print_spool.is_some() && (p.is_null() || p.as_object().is_some_and(|args| args.is_empty())) {
|
||||
self.open_backstage(backstage::Page::Print);
|
||||
return Ok(json!({"printed": false, "page": "print"}));
|
||||
}
|
||||
return Ok(json!({"printed": self.print_pdf(p.clone())}));
|
||||
}
|
||||
"app.about" => self.open_dialog("about", p.clone()),
|
||||
|
||||
@@ -414,9 +414,6 @@ pub(super) fn export(app: &mut SlideApp, ui: &mut Ui, _cx: &mut BodyCx<'_>, bs:
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
type PrinterDiscovery = Rc<std::sync::mpsc::Receiver<Vec<craft::print::Printer>>>;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
type PrintReceipt = Rc<std::sync::mpsc::Receiver<Result<String, String>>>;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DirectPrint {
|
||||
@@ -424,14 +421,12 @@ pub struct DirectPrint {
|
||||
discovery: Option<PrinterDiscovery>,
|
||||
printer: String,
|
||||
copies: String,
|
||||
/// The job being sent: the printer it went to, and its result.
|
||||
job: Option<(String, PrintReceipt)>,
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
impl Default for DirectPrint {
|
||||
fn default() -> Self {
|
||||
DirectPrint { printers: None, discovery: None, printer: String::new(), copies: "1".into(), job: None }
|
||||
DirectPrint { printers: None, discovery: None, printer: String::new(), copies: "1".into() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -457,25 +452,8 @@ fn direct_print(app: &mut SlideApp, ui: &mut Ui, bs: &mut Backstage, doc: &deckc
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some((sent_to, rx)) = &dp.job {
|
||||
match rx.try_recv() {
|
||||
Ok(Ok(message)) => {
|
||||
app.set_status(format!("Sent to {sent_to}: {message}"));
|
||||
dp.job = None;
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
app.set_status(format!("Couldn't print: {e}"));
|
||||
dp.job = None;
|
||||
}
|
||||
Err(std::sync::mpsc::TryRecvError::Empty) => ui.ctx().request_repaint_after(std::time::Duration::from_millis(200)),
|
||||
Err(std::sync::mpsc::TryRecvError::Disconnected) => {
|
||||
app.set_status("Couldn't confirm whether the print job reached the printer");
|
||||
dp.job = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
let copies = dp.copies.trim().parse::<u32>().ok().filter(|c| (1..=999).contains(c));
|
||||
let sending = dp.job.is_some();
|
||||
let sending = app.print_receipt.is_some();
|
||||
let ready = slides.is_some() && !sending && !dp.printer.is_empty() && copies.is_some();
|
||||
let detail = if sending { "Sending the job to the printer…" } else { "Sends the slides straight to the printer chosen below." };
|
||||
if task_row(ui, Icon::Print, "Print", "Print", detail, ready)
|
||||
@@ -486,7 +464,8 @@ fn direct_print(app: &mut SlideApp, ui: &mut Ui, bs: &mut Backstage, doc: &deckc
|
||||
let dp = &mut bs.direct_print;
|
||||
let title = app.session.active().map(|d| d.title()).unwrap_or_else(|| "DeckCraft".into());
|
||||
let job = craft::print::Job { printer: Some(dp.printer.clone()), copies, collate: true, title, ..Default::default() };
|
||||
dp.job = Some((dp.printer.clone(), Rc::new(spool.submit(bytes, job))));
|
||||
app.print_receipt = Some((dp.printer.clone(), spool.submit(bytes, job)));
|
||||
ui.ctx().request_repaint();
|
||||
app.set_status(format!("Sending to {}…", dp.printer));
|
||||
}
|
||||
Err(e) => app.set_status(format!("Couldn't make the pages to print: {e}")),
|
||||
|
||||
@@ -652,6 +652,27 @@ fn direct_print_reports_the_spooler_failure_and_keeps_the_viewer() {
|
||||
assert!(h.query_by_label("Open as PDF instead").is_some());
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn print_from_quick_access_opens_settings_and_job_feedback_survives_leaving() {
|
||||
let mut h = new_app();
|
||||
h.state_mut().enable_direct_print();
|
||||
h.state_mut().run("app.qat", json!({"add": "app.print", "label": "Print"})).unwrap();
|
||||
let index = h.state().ui.qat.iter().position(|q| q.id == "app.print").unwrap();
|
||||
assert!(crate::qat::run_index(h.state_mut(), index));
|
||||
assert_eq!(page(&h), Some(Page::Print));
|
||||
assert!(h.state().print_receipt.is_none());
|
||||
|
||||
let (sender, receiver) = std::sync::mpsc::channel();
|
||||
h.state_mut().print_receipt = Some(("Studio printer".into(), receiver));
|
||||
h.state_mut().run("app.backstage", json!({"on": false})).unwrap();
|
||||
assert_eq!(page(&h), None);
|
||||
sender.send(Err("queue rejected these sheets".into())).unwrap();
|
||||
h.run_steps(3);
|
||||
assert!(h.state().print_receipt.is_none());
|
||||
assert!(h.state().status.as_ref().is_some_and(|(message, _)| message.contains("queue rejected these sheets")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn print_slides_follow_the_settings() {
|
||||
let mut s = Session::with_new();
|
||||
|
||||
@@ -223,6 +223,9 @@ pub struct SlideApp {
|
||||
print_previews: craft::platform::temp::TempFiles,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
print_spool: Option<craft::print::spool::Spool>,
|
||||
/// The printer and its pending receipt outlive the File > Print view.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
print_receipt: Option<(String, std::sync::mpsc::Receiver<Result<String, String>>)>,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
updates_rt: updates_ui::Runtime,
|
||||
/// Selection pane: folded groups and the Shift-run anchor.
|
||||
|
||||
Reference in New Issue
Block a user