π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix(locker): keep scan crop adjustments optional
laurenspriem3cb520003954
diff --git a/mobile/apps/locker/changes/preserve-scanner-crop.md b/mobile/apps/locker/changes/preserve-scanner-crop.mdindex 7776fd850c..0d3fdb5f8c 100644--- a/mobile/apps/locker/changes/preserve-scanner-crop.md+++ b/mobile/apps/locker/changes/preserve-scanner-crop.md@@ -1 +1 @@-- Keep supported camera crops when reviewing and saving scans, including retakes. Ask for crop review when the photo cannot support the detected edges.+- Keep supported camera crops when reviewing and saving scans, including retakes. Preserve the full photo when the detected edges cannot be confirmed, with manual crop adjustment available as usual.diff --git a/mobile/apps/locker/lib/services/scanner/document_scanner_service.dart b/mobile/apps/locker/lib/services/scanner/document_scanner_service.dartindex 811ca3a47c..341380eecf 100644--- a/mobile/apps/locker/lib/services/scanner/document_scanner_service.dart+++ b/mobile/apps/locker/lib/services/scanner/document_scanner_service.dart@@ -176,7 +176,6 @@ class DocumentScannerService {sourceHeight: result.sourceHeight,width: result.outputWidth,height: result.outputHeight,- needsCropReview: result.needsCropReview,);} catch (e, s) {_logger.severe('processCapture failed', e, s);@@ -217,7 +216,6 @@ class DocumentScannerService {rotationDegrees: rotationDegrees,width: result.outputWidth,height: result.outputHeight,- needsCropReview: quad == null ? page.needsCropReview : false,);} catch (e, s) {_logger.severe('updatePage failed', e, s);diff --git a/mobile/apps/locker/lib/services/scanner/scan_session_controller.dart b/mobile/apps/locker/lib/services/scanner/scan_session_controller.dartindex 94a3f1e1bf..b7a8ba3c49 100644--- a/mobile/apps/locker/lib/services/scanner/scan_session_controller.dart+++ b/mobile/apps/locker/lib/services/scanner/scan_session_controller.dart@@ -207,9 +207,6 @@ class ScanSessionController extends ChangeNotifier {Future<File> buildPdf() async {await waitForPending();final pages = List.of(_pages);- if (pages.any((page) => page.needsCropReview)) {- throw StateError('Document crops must be reviewed before export');- }final fileName = _fileName;if (fileName == null) {throw StateError('fileName has not been set');diff --git a/mobile/apps/locker/lib/services/scanner/scanner_models.dart b/mobile/apps/locker/lib/services/scanner/scanner_models.dartindex 0cebf26d74..fa07f21406 100644--- a/mobile/apps/locker/lib/services/scanner/scanner_models.dart+++ b/mobile/apps/locker/lib/services/scanner/scanner_models.dart@@ -186,7 +186,6 @@ class ScannedPage {required this.sourceHeight,required this.width,required this.height,- this.needsCropReview = false,});final String id;@@ -197,8 +196,6 @@ class ScannedPage {final ScanQuad quad;- final bool needsCropReview;-final int rotationDegrees;final ScanColorMode resolvedColorMode;@@ -216,13 +213,11 @@ class ScannedPage {ScanColorMode? resolvedColorMode,int? width,int? height,- bool? needsCropReview,}) => ScannedPage(id: id,sourceJpeg: sourceJpeg,processedJpeg: processedJpeg ?? this.processedJpeg,quad: quad ?? this.quad,- needsCropReview: needsCropReview ?? this.needsCropReview,rotationDegrees: rotationDegrees ?? this.rotationDegrees,resolvedColorMode: resolvedColorMode ?? this.resolvedColorMode,sourceWidth: sourceWidth,diff --git a/mobile/apps/locker/lib/ui/pages/scanner/scanner_review_page.dart b/mobile/apps/locker/lib/ui/pages/scanner/scanner_review_page.dartindex 825da6caaf..ec32f8f8b1 100644--- a/mobile/apps/locker/lib/ui/pages/scanner/scanner_review_page.dart+++ b/mobile/apps/locker/lib/ui/pages/scanner/scanner_review_page.dart@@ -169,29 +169,6 @@ class _ScannerReviewPageState extends State<ScannerReviewPage>Future<File?> _buildPdf() async {await widget.session.waitForPending();if (!mounted) return null;- for (final page in widget.session.pages.where(- (page) => page.needsCropReview,- )) {- if (_pageController.hasClients) {- _jumpToPage(- widget.session.pages.indexWhere(- (candidate) => candidate.id == page.id,- ),- );- }- await Navigator.of(context).push(- MaterialPageRoute(- builder: (_) =>- ScannerCropPage(session: widget.session, pageId: page.id),- ),- );- if (!mounted ||- widget.session.pages.any(- (candidate) => candidate.id == page.id && candidate.needsCropReview,- )) {- return null;- }- }return widget.session.buildPdf();}@@ -603,18 +580,6 @@ class _ScannerReviewPageState extends State<ScannerReviewPage>},),),- if (pageCount > 0 && pages[current].needsCropReview)- Padding(- padding: const EdgeInsets.symmetric(- horizontal: Spacing.lg,- vertical: Spacing.sm,- ),- child: Text(- l10n.scannerCropReviewRequired,- textAlign: TextAlign.center,- style: TextStyles.mini.copyWith(color: colors.warning),- ),- ),if (pageCount > 0)Text(l10n.scanPageOfTotal(diff --git a/mobile/packages/strings/lib/l10n/arb/strings_en.arb b/mobile/packages/strings/lib/l10n/arb/strings_en.arbindex 6f4a38308a..9cbfb6e6b2 100644--- a/mobile/packages/strings/lib/l10n/arb/strings_en.arb+++ b/mobile/packages/strings/lib/l10n/arb/strings_en.arb@@ -3725,7 +3725,6 @@"scannerTorchOn": "Turn on torch","scannerCapture": "Capture","scannerPreparing": "Preparing scanner...",- "scannerCropReviewRequired": "Check the crop before saving to avoid cutting off part of the document.","scanProcessing": "Processing your scan...","scanPageOfTotal": "Page {current} of {total}","@scanPageOfTotal": {diff --git a/rust/bindings/frb/locker/src/api/document_scanner_api.rs b/rust/bindings/frb/locker/src/api/document_scanner_api.rsindex 4178e09380..6b29bda399 100644--- a/rust/bindings/frb/locker/src/api/document_scanner_api.rs+++ b/rust/bindings/frb/locker/src/api/document_scanner_api.rs@@ -56,7 +56,6 @@ pub struct RustReprocessOptions {pub struct RustScanResult {// Decoded-source coordinates (EXIF applied, before `rotation_degrees`); `None` when nothing was detected.pub quad: Option<RustQuad>,- pub needs_crop_review: bool,pub color_mode: RustColorMode,pub output_width: u32,pub output_height: u32,@@ -254,7 +253,6 @@ fn to_api_point(point: scan::Point) -> RustPoint {fn to_api_scan_result(result: scan::ScanResult) -> RustScanResult {RustScanResult {quad: result.quad.map(to_api_quad),- needs_crop_review: result.needs_crop_review,color_mode: to_api_color_mode(result.color_mode),output_width: result.output_width,output_height: result.output_height,diff --git a/rust/crates/ml/src/scan/scanner.rs b/rust/crates/ml/src/scan/scanner.rsindex b26df9f0cf..fee77a1224 100644--- a/rust/crates/ml/src/scan/scanner.rs+++ b/rust/crates/ml/src/scan/scanner.rs@@ -91,7 +91,6 @@ pub struct ReprocessOptions {#[derive(Debug, Clone, PartialEq)]pub struct ScanResult {pub quad: Option<Quad>,- pub needs_crop_review: bool,pub color_mode: ColorMode,pub output_width: u32,pub output_height: u32,@@ -246,18 +245,18 @@ impl ScannerSession {None => None,}};- let mut result = if let Some(quad) = quad {+ if let Some(quad) = quad {let plan = RenderPlan::new(quad, extent, 0, budget).map_err(ScanError::Pipeline)?;let mut page = plan.render(&bgr).map_err(ScanError::Pipeline)?;drop(bgr);let mode = render_document(&mut page.image, page.valid.as_deref(), None).map_err(ScanError::Pipeline)?;- finish(Some(quad), mode, extent, page.image, DEFAULT_JPEG_QUALITY)?+ finish(Some(quad), mode, extent, page.image, DEFAULT_JPEG_QUALITY)} else {let plan = RenderPlan::new(extent.full_frame(), extent, 0, budget).map_err(ScanError::Pipeline)?;if plan.width == bgr.width && plan.height == bgr.height {- finish(None, ColorMode::Color, extent, bgr, DEFAULT_JPEG_QUALITY)?+ finish(None, ColorMode::Color, extent, bgr, DEFAULT_JPEG_QUALITY)} else {let page = plan.render(&bgr).map_err(ScanError::Pipeline)?;drop(bgr);@@ -267,11 +266,9 @@ impl ScannerSession {extent,page.image,DEFAULT_JPEG_QUALITY,- )?+ )}- };- result.needs_crop_review = region.is_some() && quad.is_none();- Ok(result)+ }}pub fn reprocess(@@ -357,7 +354,6 @@ fn finish(Ok(ScanResult {quad,- needs_crop_review: false,color_mode,output_width,output_height,@@ -408,7 +404,6 @@ mod tests {let region = centered_region(120, 80);let result = session.process_capture_with_region(&bytes, Some(4_000_000), Some(region))?;let expected_quad = result.quad.expect("supported page must be cropped");- assert!(!result.needs_crop_review);assert!((result.output_width as i32 - 60).abs() <= 2);assert!((result.output_height as i32 - 40).abs() <= 2);let decoded = codec::decode_bgr(&result.processed_image)?;@@ -434,8 +429,8 @@ mod tests {}#[test]- fn unsupported_capture_region_keeps_source_until_explicit_reprocessing() -> Result<(), ScanError>- {+ fn unsupported_capture_region_preserves_source_and_allows_manual_adjustment()+ -> Result<(), ScanError> {let session = ScannerSession {segmenter: Segmenter::unavailable_for_render_tests(),};@@ -443,10 +438,9 @@ mod tests {let bytes = codec::encode_jpeg(source, 90)?;let result =session.process_capture_with_region(&bytes, None, Some(centered_region(120, 80)))?;- assert!(result.needs_crop_review);assert_eq!(result.quad, None);assert_eq!((result.output_width, result.output_height), (120, 80));- let confirmed = session.reprocess(+ let adjusted = session.reprocess(&bytes,&ReprocessOptions {quad: centered_region(120, 80)@@ -456,8 +450,7 @@ mod tests {max_pixels: None,},)?;- assert!(!confirmed.needs_crop_review);- assert_eq!((confirmed.output_width, confirmed.output_height), (60, 40));+ assert_eq!((adjusted.output_width, adjusted.output_height), (60, 40));Ok(())}@@ -498,7 +491,6 @@ mod tests {let bytes = codec::encode_jpeg(document_source()?, 90)?;let region = centered_region(120, 80);let expected = session.process_capture_with_region(&bytes, None, Some(region))?;- assert!(!expected.needs_crop_review);let corners = points(region.normalized_quad);for start in 1..4 {let shifted = CaptureRegion {@@ -554,7 +546,8 @@ mod tests {};let result = session.process_capture_with_region(&bytes, None, Some(region))?;assert_eq!(- result.needs_crop_review, wider,+ result.quad.is_none(),+ wider,"{width}x{height}, edge {edge}");if wider {@@ -668,7 +661,6 @@ mod tests {(capture.source_width, capture.source_height),(width, height));- assert!(!capture.needs_crop_review);assert!((capture.output_width as i32 - width as i32 / 2).abs() <= 2);assert!((capture.output_height as i32 - height as i32 / 2).abs() <= 2);let expected = session.reprocess(