JFLib

plat/scan.rs#

Source: lib/plat/scan.rs

scan -- pictures from a scanner through the system's own dialog

  scan_available() -> bool      the system has a scan dialog here (macOS; elsewhere not yet)
  scan_start(title) -> Result<(), ScanError>   the dialog in a window titled `title`: the user
                                 chooses the device, previews, sets the area and the resolution
                                 and scans; Busy while one is open, Unavailable where there is
                                 none.  Call it from the UI thread.
  scan_poll() -> Option<Result<Scanned, ScanError>>   None while the dialog is open (or none
                                 was), then once: the scanned file, Cancelled (the window closed
                                 without a scan) or Failed (the device or the system)
  scan_open() -> bool            a dialog is open (its answer not taken yet)

Scanned: the file as the scanner wrote it -- its name and bytes (macOS: PNG unless the user
chose another format in the dialog); the app decodes it like a file it opened.  The answer
wakes the UI (plat::wake).  Scanning needs no right of the app's manifest: the user starts it
and chooses in the system's dialog, as in the file dialog.

macOS (apple_mac_scan.rs): ImageKit's device browser (local and network scanners: USB,
AirScan / eSCL, Bonjour) beside its scanner view (IKScannerDeviceView over ImageCaptureCore,
the dialog Preview shows), the scan written to a folder of its own in the temp folder, read
and removed.  An app under the App Sandbox needs the USB and network entitlements for it.
Windows (WIA) and Linux (SANE) follow; until then Unavailable there, in the browser and on
Android and iOS.
  • enum ScanError why no picture came

    • Unavailable -- no scan dialog on this system
    • Cancelled -- the user closed the dialog without a scan
    • Busy -- a dialog is open already
    • Failed(String) -- the device or the system failed: what it said
  • struct Scanned a scanned picture: the file as the scanner wrote it

    • name: String -- its name ("Scan.png")
    • data: Vec<u8> -- its bytes
  • fn scan_available() -> bool whether the system has a scan dialog here

  • fn scan_start(title: &str) -> Result<(), ScanError> open the system's scan dialog in a window titled title; the answer comes through scan_poll

  • fn scan_poll() -> Option<Result<Scanned, ScanError>> the open dialog's answer: None while it is open (or none was), then once

  • fn scan_open() -> bool a dialog is open (its answer not taken yet)

Source: docs/API.md in the JFLib repository.