Allow sending scan from device to computer for some HP All-in-One Printers - Scan to computer
How captured scans move from the printer to their destination(s), and why the capture loop stays responsive.
Short version: capturing and delivering a scan are now decoupled. Capturing stays close to the printer; delivering happens on a background FIFO queue (and the PDF merge in a dedicated worker thread), so the loop keeps polling during slow uploads or heavy processing.
In listen and adf-autoscan mode the app used to wait for the whole
post-processing (PDF merge, uploads, webhook delivery, cleanup) before polling
the printer again. A large scan or a slow destination could make the loop miss
the next scan event or trip the printer’s userActionTimeout /
waitScanNewPageRequest timeouts.
src/postProcessing.ts): generate PDF → announce →
deliver → deliver sidecars → webhook → log → cleanup, threaded through a
shared context. --post-command-pdf runs on each generated PDF as soon as
it exists (the merged PDF, so after the merge, not before it) and
--post-command-image on the page images; both always ahead of delivery.
Files a command writes beside the scan are detected here and delivered with
it (S3 and Nextcloud only, see the
README).
With --reveal, the scan still on disk after the cleanup is then shown in
the system file manager (see the README).src/queue/processingQueue.ts): each captured
scan is enqueued and drained in order by a single background worker, in
memory. Order is preserved; capture returns to the printer immediately. If
the process dies mid-job, the captured files stay on disk (cleanup only runs
once delivery finished) and the delivery can be redone by hand.src/pdfMergeWorker.ts): the jspdf merge runs
in a worker thread, so health checks and printer HTTP responses stay
responsive during a big merge.single-scan keeps its synchronous contract: it exits only once delivery
completed (success or failure), so the exit code still reflects the upload
outcome.--keep-files is decided at the end of each job, as before.test/processingQueue.test.ts covers the queue (enqueue returns before the
work completes, FIFO order, awaited single-job path). PDF merge and delivery
are covered by the existing suites; scripts/live-test.sh smoke-tests the
main flows against a real printer.