ml wait initial load
This commit is contained in:
@@ -42,6 +42,8 @@ class TabState extends WebPageInfo {
|
|||||||
final bool isFullScreen;
|
final bool isFullScreen;
|
||||||
final bool isLoading;
|
final bool isLoading;
|
||||||
|
|
||||||
|
bool get isFinishedLoading => !isLoading && progress == 100;
|
||||||
|
|
||||||
final SecurityState securityInfoState;
|
final SecurityState securityInfoState;
|
||||||
final HistoryState historyState;
|
final HistoryState historyState;
|
||||||
final ReaderableState readerableState;
|
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/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/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/providers.dart';
|
||||||
|
import 'package:weblibre/features/geckoview/features/tabs/domain/repositories/container_topic.dart';
|
||||||
import 'package:weblibre/features/geckoview/utils/image_helper.dart';
|
import 'package:weblibre/features/geckoview/utils/image_helper.dart';
|
||||||
|
|
||||||
part 'tab_state.g.dart';
|
part 'tab_state.g.dart';
|
||||||
@@ -25,8 +26,7 @@ class TabStates extends _$TabStates {
|
|||||||
void _onTabContentStateChange(TabContentState contentState) {
|
void _onTabContentStateChange(TabContentState contentState) {
|
||||||
final current =
|
final current =
|
||||||
state[contentState.id] ?? TabState.$default(contentState.id);
|
state[contentState.id] ?? TabState.$default(contentState.id);
|
||||||
state = {...state}
|
final newState = current.copyWith(
|
||||||
..[contentState.id] = current.copyWith(
|
|
||||||
parentId: contentState.parentId,
|
parentId: contentState.parentId,
|
||||||
contextId: contentState.contextId,
|
contextId: contentState.contextId,
|
||||||
url: Uri.parse(contentState.url),
|
url: Uri.parse(contentState.url),
|
||||||
@@ -38,6 +38,14 @@ class TabStates extends _$TabStates {
|
|||||||
isFullScreen: contentState.isFullScreen,
|
isFullScreen: contentState.isFullScreen,
|
||||||
isLoading: contentState.isLoading,
|
isLoading: contentState.isLoading,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
state = {...state}..[contentState.id] = newState;
|
||||||
|
|
||||||
|
if (newState.isFinishedLoading) {
|
||||||
|
ref
|
||||||
|
.read(containerTopicRepositoryProvider.notifier)
|
||||||
|
.markInitialLoadComplete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onIconChange(IconChangeEvent event) async {
|
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')
|
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
||||||
// ignore: unused_element
|
// ignore: unused_element
|
||||||
typedef SelectedTabContainerIdRef = ProviderRef<AsyncValue<String?>>;
|
typedef SelectedTabContainerIdRef = ProviderRef<AsyncValue<String?>>;
|
||||||
String _$tabStatesHash() => r'e4d2f2b4ddd65beac8a1fd0d22bad1e0a26b41bd';
|
String _$tabStatesHash() => r'ec7e0905d77b2f82491c5b5af0d2ce1351a564f4';
|
||||||
|
|
||||||
/// See also [TabStates].
|
/// See also [TabStates].
|
||||||
@ProviderFor(TabStates)
|
@ProviderFor(TabStates)
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ part 'container_topic.g.dart';
|
|||||||
class ContainerTopicRepository extends _$ContainerTopicRepository {
|
class ContainerTopicRepository extends _$ContainerTopicRepository {
|
||||||
final _service = GeckoMlService();
|
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 _lock = Lock();
|
||||||
|
|
||||||
final _cache = LRUCache<Set<String>, String>(
|
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 {
|
Future<String?> getContainerTopic(Set<String> titles) async {
|
||||||
if (titles.isNotEmpty) {
|
if (titles.isNotEmpty) {
|
||||||
if (_cache.get(titles) case final String title) {
|
if (_cache.get(titles) case final String title) {
|
||||||
@@ -35,6 +43,8 @@ class ContainerTopicRepository extends _$ContainerTopicRepository {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
final title = await _lock.synchronized(() async {
|
final title = await _lock.synchronized(() async {
|
||||||
|
await _initialLoadComplete.future;
|
||||||
|
|
||||||
final title = await _service.getContainerTopic(titles);
|
final title = await _service.getContainerTopic(titles);
|
||||||
|
|
||||||
return _cache.set(titles, title);
|
return _cache.set(titles, title);
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ class _ContainerTopicProviderElement extends FutureProviderElement<String?>
|
|||||||
}
|
}
|
||||||
|
|
||||||
String _$containerTopicRepositoryHash() =>
|
String _$containerTopicRepositoryHash() =>
|
||||||
r'20ae14772821ac8a4ec0c16bc551e29098556189';
|
r'8dfc0bc8b4953b5230a1faa24c8b2f0a94ab1f04';
|
||||||
|
|
||||||
/// See also [ContainerTopicRepository].
|
/// See also [ContainerTopicRepository].
|
||||||
@ProviderFor(ContainerTopicRepository)
|
@ProviderFor(ContainerTopicRepository)
|
||||||
|
|||||||
Reference in New Issue
Block a user