ml wait initial load

This commit is contained in:
Fabian Freund
2025-07-22 00:24:30 +02:00
parent 544a9d3e88
commit 647727e093
5 changed files with 35 additions and 15 deletions
@@ -42,6 +42,8 @@ class TabState extends WebPageInfo {
final bool isFullScreen;
final bool isLoading;
bool get isFinishedLoading => !isLoading && progress == 100;
final SecurityState securityInfoState;
final HistoryState historyState;
final ReaderableState readerableState;
@@ -16,6 +16,7 @@ import 'package:weblibre/features/geckoview/domain/providers.dart';
import 'package:weblibre/features/geckoview/domain/providers/selected_tab.dart';
import 'package:weblibre/features/geckoview/features/find_in_page/domain/repositories/find_in_page.dart';
import 'package:weblibre/features/geckoview/features/tabs/domain/providers.dart';
import 'package:weblibre/features/geckoview/features/tabs/domain/repositories/container_topic.dart';
import 'package:weblibre/features/geckoview/utils/image_helper.dart';
part 'tab_state.g.dart';
@@ -25,19 +26,26 @@ class TabStates extends _$TabStates {
void _onTabContentStateChange(TabContentState contentState) {
final current =
state[contentState.id] ?? TabState.$default(contentState.id);
state = {...state}
..[contentState.id] = current.copyWith(
parentId: contentState.parentId,
contextId: contentState.contextId,
url: Uri.parse(contentState.url),
title: (contentState.title.isNotEmpty)
? contentState.title
: current.title,
progress: contentState.progress,
isPrivate: contentState.isPrivate,
isFullScreen: contentState.isFullScreen,
isLoading: contentState.isLoading,
);
final newState = current.copyWith(
parentId: contentState.parentId,
contextId: contentState.contextId,
url: Uri.parse(contentState.url),
title: (contentState.title.isNotEmpty)
? contentState.title
: current.title,
progress: contentState.progress,
isPrivate: contentState.isPrivate,
isFullScreen: contentState.isFullScreen,
isLoading: contentState.isLoading,
);
state = {...state}..[contentState.id] = newState;
if (newState.isFinishedLoading) {
ref
.read(containerTopicRepositoryProvider.notifier)
.markInitialLoadComplete();
}
}
Future<void> _onIconChange(IconChangeEvent event) async {
@@ -193,7 +193,7 @@ final selectedTabContainerIdProvider = Provider<AsyncValue<String?>>.internal(
@Deprecated('Will be removed in 3.0. Use Ref instead')
// ignore: unused_element
typedef SelectedTabContainerIdRef = ProviderRef<AsyncValue<String?>>;
String _$tabStatesHash() => r'e4d2f2b4ddd65beac8a1fd0d22bad1e0a26b41bd';
String _$tabStatesHash() => r'ec7e0905d77b2f82491c5b5af0d2ce1351a564f4';
/// See also [TabStates].
@ProviderFor(TabStates)
@@ -15,6 +15,8 @@ part 'container_topic.g.dart';
class ContainerTopicRepository extends _$ContainerTopicRepository {
final _service = GeckoMlService();
//Wait for first complete page laod of any website after startup to ensure everything is ready
final _initialLoadComplete = Completer();
final _lock = Lock();
final _cache = LRUCache<Set<String>, String>(
@@ -27,6 +29,12 @@ class ContainerTopicRepository extends _$ContainerTopicRepository {
},
);
void markInitialLoadComplete() {
if (!_initialLoadComplete.isCompleted) {
_initialLoadComplete.complete();
}
}
Future<String?> getContainerTopic(Set<String> titles) async {
if (titles.isNotEmpty) {
if (_cache.get(titles) case final String title) {
@@ -35,6 +43,8 @@ class ContainerTopicRepository extends _$ContainerTopicRepository {
try {
final title = await _lock.synchronized(() async {
await _initialLoadComplete.future;
final title = await _service.getContainerTopic(titles);
return _cache.set(titles, title);
@@ -147,7 +147,7 @@ class _ContainerTopicProviderElement extends FutureProviderElement<String?>
}
String _$containerTopicRepositoryHash() =>
r'20ae14772821ac8a4ec0c16bc551e29098556189';
r'8dfc0bc8b4953b5230a1faa24c8b2f0a94ab1f04';
/// See also [ContainerTopicRepository].
@ProviderFor(ContainerTopicRepository)