From 7e3ca2671be09524cf8ac2d3b6e26af0922f11eb Mon Sep 17 00:00:00 2001 From: Fabian Freund Date: Sat, 3 May 2025 23:50:08 +0200 Subject: [PATCH] add timeout for new tab suggestion --- .../widgets/browser_modules/browser_view.dart | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/app/lib/features/geckoview/features/browser/presentation/widgets/browser_modules/browser_view.dart b/app/lib/features/geckoview/features/browser/presentation/widgets/browser_modules/browser_view.dart index e247e029..090f9410 100644 --- a/app/lib/features/geckoview/features/browser/presentation/widgets/browser_modules/browser_view.dart +++ b/app/lib/features/geckoview/features/browser/presentation/widgets/browser_modules/browser_view.dart @@ -30,10 +30,12 @@ import 'package:lensai/utils/ui_helper.dart'; class BrowserView extends StatefulHookConsumerWidget { final Duration screenshotPeriod; + final Duration suggestionTimeout; final Future Function()? postInitializationStep; const BrowserView({ this.screenshotPeriod = const Duration(seconds: 10), + this.suggestionTimeout = const Duration(seconds: 10), this.postInitializationStep, }); @@ -48,6 +50,8 @@ class _BrowserViewState extends ConsumerState //This is managed by widget state changes to resume a timer bool _timerPaused = false; + DateTime? _suggestionCountTime; + Future _timerTick(Timer timer) async { await ref .read(selectedTabSessionNotifierProvider) @@ -198,6 +202,10 @@ class _BrowserViewState extends ConsumerState ref .read(localAuthenticationServiceProvider.notifier) .evictCacheOnBackground(); + + if (state == AppLifecycleState.paused) { + _suggestionCountTime = DateTime.now(); + } case AppLifecycleState.resumed: if (_timerPaused) { _periodicScreenshotUpdate = Timer.periodic( @@ -207,12 +215,18 @@ class _BrowserViewState extends ConsumerState _timerPaused = false; } - showSuggestNewTabMessage( - context, - onAdd: () async { - await const SearchRoute(tabType: TabType.regular).push(context); - }, - ); + if (_suggestionCountTime == null || + DateTime.now().difference(_suggestionCountTime!) > + widget.suggestionTimeout) { + showSuggestNewTabMessage( + context, + onAdd: () async { + await const SearchRoute(tabType: TabType.regular).push(context); + }, + ); + + _suggestionCountTime = DateTime.now(); + } } }