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 ScanErrorwhy no picture cameUnavailable-- no scan dialog on this systemCancelled-- the user closed the dialog without a scanBusy-- a dialog is open alreadyFailed(String)-- the device or the system failed: what it said
struct Scanneda scanned picture: the file as the scanner wrote itname: String-- its name ("Scan.png")data: Vec<u8>-- its bytes
fn scan_available() -> boolwhether the system has a scan dialog herefn scan_start(title: &str) -> Result<(), ScanError>open the system's scan dialog in a window titledtitle; the answer comes through scan_pollfn scan_poll() -> Option<Result<Scanned, ScanError>>the open dialog's answer: None while it is open (or none was), then oncefn scan_open() -> boola dialog is open (its answer not taken yet)