Skip to content

Print: choose a printer and copies (CUPS on Linux and macOS) - #561

Open
NikitkaRa wants to merge 1 commit into
storytold:mainfrom
NikitkaRa:print-to-printer
Open

NikitkaRa wants to merge 1 commit into
storytold:mainfrom
NikitkaRa:print-to-printer

Conversation

@NikitkaRa

Copy link
Copy Markdown
Contributor

Summary

  • File ▸ Print could only open a PDF in the system viewer and leave printer choice to the viewer. When the host can list printers, the Print page now shows a Printer list, with "PDF viewer (choose a printer there)" first and then the system's printers. Choosing a printer also shows Copies (1–999). Print then sends the PDF of the chosen pages straight to that printer and reports "Sent to …" or the error in the status bar.
  • New Services::printers and Services::print_file hooks. The desktop app fills them on Unix with CUPS: lpstat -e lists the printers, and lp -d <printer> -n <copies> -t DeckCraft -- <file> prints. Printer names that could be read as options are refused.
  • Windows (no print command) and the web (download) keep the existing path, and so does anything else without a printer list.
  • docs/gaps.md: the File tab depth row notes that printer choice exists on CUPS systems.

No issue exists for this. It's the gaps.md "printer choice" item. There's no overlap with the open browser-print PR, which is web only.

Test plan

  • print_sends_the_pdf_to_a_chosen_printer (ui-egui harness): the host's printers are listed and the page starts on the viewer. With a printer and 3 copies chosen, Print hands a real PDF to print_file with those values and no viewer URL is opened
  • lpstat_lines_are_printer_names: parsing lpstat -e output, "No destinations" gives none, and a printer name that looks like an option is refused
  • Existing print_previews_pages_and_prints_a_pdf still passes (the viewer path)
  • cargo xtask ci
  • Manual check on a machine with a real CUPS printer (the box has no display or printer)

File > Print could only open a PDF in the system viewer. When the host
lists printers, the Print page now has a Printer list (the PDF viewer
first, then the system's printers) and Copies; with a printer chosen
the PDF of the chosen pages goes straight to it.

The desktop app lists printers with `lpstat -e` and prints with
`lp -d <printer> -n <copies> -- <file>`, refusing names that could be
read as options. Windows and the web keep the viewer / download path.

Co-authored-by: Cursor <cursoragent@cursor.com>

@FredApps FredApps left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReviewerA — source-read COMMENT (not an approval)

I read the head of the diff: printing lets the user choose a printer and the number of copies, through CUPS on Linux and macOS. The application runs lpstat -e to list printers and lp to print, and on Windows opens the PDF in the viewer as before. Running external commands is acceptable here if the arguments are passed as a vector (no shell) and values from the user (printer name, copies) are validated: a printer name that starts with - could be taken as an option by lp, so the name must follow -d as an argument or be checked against the list that lpstat returned; the copy count must be a bounded integer. The PDF is written to a temporary file with restricted permissions, and removed after printing. I have not run it, and no exact-head CI result exists for this head. Nothing was run.

I ran nothing and have no exact-head CI result for this PR, so this is not an approval. Where a diff was long I read its code hunks rather than every generated or documentation line.

Status: waiting_author.

@aiongg aiongg added the missing feature The reference application has it and we do not, or only part of it label Nov 4, 2026

@aiongg aiongg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-generated review (Opus). Not a maintainer decision.

Changes needed (not certain):

On Linux and macOS, the Print page now has a Printer list and a Copies count, and the PDF goes straight to the system print spooler. Windows and the web still use the viewer and download paths. The argument handling is safe; threading and how much code is duplicated need attention.

  • apps/deckcraft/src/main.rs:146-153: arguments go to lp as a vector after -d and --, option-like names are refused, and copies are clamped. This is safe against argument injection.
  • crates/ui-egui/src/backstage.rs:1042-1043: lpstat -e runs on the UI thread when the Print page first shows. -e also lists network-discovered printers and can take seconds, so the window freezes meanwhile. Listing printers on a worker would avoid that.
  • crates/ui-egui/src/lib.rs:836: lp also runs synchronously in the frame that handles the click.
  • The craft-libs print crate already lists CUPS printers and submits jobs with copies (streaming through stdin, with no temp file) and has a Windows backend. DeckCraft already depends on craft-libs, so using it would avoid a second CUPS implementation and would cover Windows.
  • apps/deckcraft/src/main.rs:151: the job title is always 'DeckCraft'. The presentation's title would make jobs easier to find in the queue.
  • crates/ui-egui/src/lib.rs:827-828: app.print now accepts printer and copies from the control channel. These params are not documented, and the name is not checked against the listed printers.

Claims checked:

  • verified: When the host can list printers, the Print page shows a Printer list with the PDF viewer entry first, followed by the system's printers. (crates/ui-egui/src/backstage.rs:1042-1045 fetches services.printers once. backstage.rs:1061-1073 shows the ComboBox only when the list is not empty, with the vie…
  • verified: Choosing a printer shows Copies (1–999). (crates/ui-egui/src/backstage.rs:1074-1079: a DragValue with range 1..=999, shown only when a printer is chosen.)
  • verified: Print sends the PDF of the chosen pages straight to the chosen printer and reports 'Sent to …' or the error in the status bar, with no viewer opened. (crates/ui-egui/src/backstage.rs:1052-1058 adds printer/copies to the print_params. crates/ui-egui/src/lib.rs:827-847 strips them, runs file.export,…
  • verified: On Unix, the desktop app gets the printer list from the system print spooler and submits the file to the chosen printer with a copy count and a job title. Printer names that could be read as options are refused. (apps/deckcraft/src/main.rs:123-124 fills the hooks under cfg!(unix). main.rs:135-140 r…
  • verified: Windows, the web and hosts without a printer list keep the existing path. (apps/deckcraft/src/main.rs:123-124 gives None when not unix. crates/ui-egui/src/lib.rs:816-820 still downloads when pick_save is None. backstage.rs:1061 hides the list when it is empty, so direct stays false.)
  • verified: docs/gaps.md notes that printer choice exists on CUPS systems. (docs/gaps.md:288-289 drops 'printer choice' from the missing list and adds that it is CUPS-only (Linux and macOS).)

Recommendation: update the pull request; it will be reviewed again.

Reviewed at 632badf.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

missing feature The reference application has it and we do not, or only part of it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants