π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Support long press to trigger OCR detection immediately
Amrithesh Kakkoth Ente693b040bfac0
diff --git a/mobile/apps/photos/lib/ui/viewer/file/inline_text_detection.dart b/mobile/apps/photos/lib/ui/viewer/file/inline_text_detection.dartindex 1ab4b5c171..51f1b69691 100644--- a/mobile/apps/photos/lib/ui/viewer/file/inline_text_detection.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/inline_text_detection.dart@@ -48,6 +48,8 @@ class _InlineTextDetectionState extends State<InlineTextDetection> {int _requestId = 0;bool _overlayActive = false;Timer? _activationTimer;+ bool _userTriggered = false;+ Offset? _pendingLongPressPosition;@overridevoid initState() {@@ -76,6 +78,8 @@ class _InlineTextDetectionState extends State<InlineTextDetection> {setState(() {_localFilePath = null;_overlayActive = false;+ _userTriggered = false;+ _pendingLongPressPosition = null;});}@@ -125,7 +129,7 @@ class _InlineTextDetectionState extends State<InlineTextDetection> {setState(() {_localFilePath = cached.localPath;});- if (cached.hasText) _scheduleActivation(requestId);+ if (cached.hasText) _activateOrSchedule(requestId);return;}@@ -161,8 +165,9 @@ class _InlineTextDetectionState extends State<InlineTextDetection> {_localFilePath = result.localPath;});- // If text found, schedule activation after 1 second delay- if (hasText) _scheduleActivation(requestId);+ // If text found, activate immediately if user already long pressed,+ // otherwise schedule activation after 1 second delay.+ if (hasText) _activateOrSchedule(requestId);} catch (error, stackTrace) {_logger.severe("Text detection pre-check failed", error, stackTrace);if (!mounted || requestId != _requestId) return;@@ -170,6 +175,17 @@ class _InlineTextDetectionState extends State<InlineTextDetection> {}}+ void _activateOrSchedule(int requestId) {+ if (_userTriggered) {+ // User already long pressed β skip delay, activate immediately+ setState(() {+ _overlayActive = true;+ });+ } else {+ _scheduleActivation(requestId);+ }+ }+void _scheduleActivation(int requestId) {_activationTimer?.cancel();_activationTimer = Timer(const Duration(seconds: 1), () {@@ -180,19 +196,46 @@ class _InlineTextDetectionState extends State<InlineTextDetection> {});}+ void _handleLongPress(LongPressStartDetails details) {+ if (_overlayActive) return; // Already active, let overlay handle it+ _activationTimer?.cancel();+ setState(() {+ _userTriggered = true;+ _pendingLongPressPosition = details.globalPosition;+ });+ // If hasText already completed and file path is ready, activate now+ if (_localFilePath != null) {+ setState(() {+ _overlayActive = true;+ });+ }+ // Otherwise _evaluateFile will activate when hasText completes+ }+@overrideWidget build(BuildContext context) {if (!_isEligible || widget.file is TrashFile) {return const SizedBox.shrink();}- if (!_overlayActive || _localFilePath == null) {- return const SizedBox.shrink();- }-final isZoomedNotifier = InheritedDetailPageState.maybeOf(context)?.isZoomedNotifier;+ // During the wait period (hasText passed but 1s timer hasn't fired),+ // show a transparent gesture layer to capture long press.+ if (!_overlayActive || _localFilePath == null) {+ if (!_isEligible || widget.isGuestView) {+ return const SizedBox.shrink();+ }+ return Positioned.fill(+ child: GestureDetector(+ behavior: HitTestBehavior.translucent,+ onLongPressStart: _handleLongPress,+ child: const SizedBox.expand(),+ ),+ );+ }+return ValueListenableBuilder<bool>(valueListenable: isZoomedNotifier ?? ValueNotifier(false),builder: (context, isZoomed, _) {@@ -217,12 +260,13 @@ class _InlineTextDetectionState extends State<InlineTextDetection> {return TextDetectorWidget(key: ValueKey("ocr_$_localFilePath"),imagePath: _localFilePath!,- autoDetect: true,+ autoDetect: !_userTriggered,backgroundColor: Colors.transparent,showUnselectedBoundaries: true,overlayOnly: true,showProcessingOverlay: false,showEditorHint: false,+ initialInteractionPosition: _pendingLongPressPosition,controller: _detectorController,strings: TextDetectorStrings(processingOverlayMessage: l10n.ocrProcessingOverlayMessage,