add timeout for new tab suggestion
This commit is contained in:
+14
@@ -30,10 +30,12 @@ import 'package:lensai/utils/ui_helper.dart';
|
|||||||
|
|
||||||
class BrowserView extends StatefulHookConsumerWidget {
|
class BrowserView extends StatefulHookConsumerWidget {
|
||||||
final Duration screenshotPeriod;
|
final Duration screenshotPeriod;
|
||||||
|
final Duration suggestionTimeout;
|
||||||
final Future<void> Function()? postInitializationStep;
|
final Future<void> Function()? postInitializationStep;
|
||||||
|
|
||||||
const BrowserView({
|
const BrowserView({
|
||||||
this.screenshotPeriod = const Duration(seconds: 10),
|
this.screenshotPeriod = const Duration(seconds: 10),
|
||||||
|
this.suggestionTimeout = const Duration(seconds: 10),
|
||||||
this.postInitializationStep,
|
this.postInitializationStep,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -48,6 +50,8 @@ class _BrowserViewState extends ConsumerState<BrowserView>
|
|||||||
//This is managed by widget state changes to resume a timer
|
//This is managed by widget state changes to resume a timer
|
||||||
bool _timerPaused = false;
|
bool _timerPaused = false;
|
||||||
|
|
||||||
|
DateTime? _suggestionCountTime;
|
||||||
|
|
||||||
Future<void> _timerTick(Timer timer) async {
|
Future<void> _timerTick(Timer timer) async {
|
||||||
await ref
|
await ref
|
||||||
.read(selectedTabSessionNotifierProvider)
|
.read(selectedTabSessionNotifierProvider)
|
||||||
@@ -198,6 +202,10 @@ class _BrowserViewState extends ConsumerState<BrowserView>
|
|||||||
ref
|
ref
|
||||||
.read(localAuthenticationServiceProvider.notifier)
|
.read(localAuthenticationServiceProvider.notifier)
|
||||||
.evictCacheOnBackground();
|
.evictCacheOnBackground();
|
||||||
|
|
||||||
|
if (state == AppLifecycleState.paused) {
|
||||||
|
_suggestionCountTime = DateTime.now();
|
||||||
|
}
|
||||||
case AppLifecycleState.resumed:
|
case AppLifecycleState.resumed:
|
||||||
if (_timerPaused) {
|
if (_timerPaused) {
|
||||||
_periodicScreenshotUpdate = Timer.periodic(
|
_periodicScreenshotUpdate = Timer.periodic(
|
||||||
@@ -207,12 +215,18 @@ class _BrowserViewState extends ConsumerState<BrowserView>
|
|||||||
_timerPaused = false;
|
_timerPaused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_suggestionCountTime == null ||
|
||||||
|
DateTime.now().difference(_suggestionCountTime!) >
|
||||||
|
widget.suggestionTimeout) {
|
||||||
showSuggestNewTabMessage(
|
showSuggestNewTabMessage(
|
||||||
context,
|
context,
|
||||||
onAdd: () async {
|
onAdd: () async {
|
||||||
await const SearchRoute(tabType: TabType.regular).push(context);
|
await const SearchRoute(tabType: TabType.regular).push(context);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
_suggestionCountTime = DateTime.now();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user