switch to new gecko pref api

This commit is contained in:
Fabian Freund
2025-10-18 10:03:50 +02:00
parent c8a4657c98
commit 641d3c7d64
16 changed files with 355 additions and 263 deletions
@@ -34,7 +34,7 @@ final class EngineBoundIntentStreamProvider
}
String _$engineBoundIntentStreamHash() =>
r'd47f50ee8f548fe0416b8ed01bb02adbd79b3386';
r'fa7c3e0277b25e8129a12feaadf39db6b65a1cd5';
abstract class _$EngineBoundIntentStream
extends $StreamNotifier<SharedContent> {
@@ -19,6 +19,7 @@
*/
import 'package:copy_with_extension/copy_with_extension.dart';
import 'package:fast_equatable/fast_equatable.dart';
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
import 'package:json_annotation/json_annotation.dart';
part 'preference_setting.g.dart';
@@ -55,9 +56,9 @@ class PreferenceSetting with FastEquatable {
final Object value;
@JsonKey(includeFromJson: false, includeToJson: false)
final Object? actualValue;
final GeckoPrefValue? current;
bool get isActive => value == actualValue;
bool get isActive => value == current?.value;
final String? title;
final String? description;
@@ -69,7 +70,7 @@ class PreferenceSetting with FastEquatable {
required this.value,
required this.title,
required this.description,
this.actualValue,
this.current,
this.requireUserOptIn = false,
this.shouldBeDefault = false,
});
@@ -82,7 +83,7 @@ class PreferenceSetting with FastEquatable {
@override
List<Object?> get hashParameters => [
value,
actualValue,
current,
title,
description,
requireUserOptIn,
@@ -80,7 +80,7 @@ abstract class _$PreferenceSettingCWProxy {
PreferenceSetting description(String? description);
PreferenceSetting actualValue(Object? actualValue);
PreferenceSetting current(GeckoPrefValue? current);
PreferenceSetting requireUserOptIn(bool requireUserOptIn);
@@ -97,7 +97,7 @@ abstract class _$PreferenceSettingCWProxy {
Object value,
String? title,
String? description,
Object? actualValue,
GeckoPrefValue? current,
bool requireUserOptIn,
bool shouldBeDefault,
});
@@ -121,8 +121,7 @@ class _$PreferenceSettingCWProxyImpl implements _$PreferenceSettingCWProxy {
call(description: description);
@override
PreferenceSetting actualValue(Object? actualValue) =>
call(actualValue: actualValue);
PreferenceSetting current(GeckoPrefValue? current) => call(current: current);
@override
PreferenceSetting requireUserOptIn(bool requireUserOptIn) =>
@@ -144,7 +143,7 @@ class _$PreferenceSettingCWProxyImpl implements _$PreferenceSettingCWProxy {
Object? value = const $CopyWithPlaceholder(),
Object? title = const $CopyWithPlaceholder(),
Object? description = const $CopyWithPlaceholder(),
Object? actualValue = const $CopyWithPlaceholder(),
Object? current = const $CopyWithPlaceholder(),
Object? requireUserOptIn = const $CopyWithPlaceholder(),
Object? shouldBeDefault = const $CopyWithPlaceholder(),
}) {
@@ -161,10 +160,10 @@ class _$PreferenceSettingCWProxyImpl implements _$PreferenceSettingCWProxy {
? _value.description
// ignore: cast_nullable_to_non_nullable
: description as String?,
actualValue: actualValue == const $CopyWithPlaceholder()
? _value.actualValue
current: current == const $CopyWithPlaceholder()
? _value.current
// ignore: cast_nullable_to_non_nullable
: actualValue as Object?,
: current as GeckoPrefValue?,
requireUserOptIn:
requireUserOptIn == const $CopyWithPlaceholder() ||
requireUserOptIn == null
@@ -65,7 +65,7 @@ Future<PreferenceSettingGroup> _preferenceSettingGroup(
class _PreferenceRepository extends _$PreferenceRepository {
final _prefManager = GeckoPrefService();
// Use BehaviorSubject instead of StreamController
late BehaviorSubject<Map<String, Object>> _prefSubject;
late BehaviorSubject<Map<String, GeckoPrefValue>> _prefSubject;
Future<void> _updatePrefs() async {
final prefs = await _prefManager.getAllPrefs();
@@ -83,8 +83,8 @@ class _PreferenceRepository extends _$PreferenceRepository {
}
@override
Raw<Stream<Map<String, Object>>> build() {
_prefSubject = BehaviorSubject<Map<String, Object>>();
Raw<Stream<Map<String, GeckoPrefValue>>> build() {
_prefSubject = BehaviorSubject<Map<String, GeckoPrefValue>>();
ref.onDispose(() async {
await _prefSubject.close();
@@ -157,10 +157,8 @@ class UnifiedPreferenceSettingsRepository
groupName,
group.copyWith.settings(
group.settings.map(
(prefName, setting) => MapEntry(
prefName,
setting.copyWith.actualValue(prefs[prefName]),
),
(prefName, setting) =>
MapEntry(prefName, setting.copyWith.current(prefs[prefName])),
),
),
),
@@ -234,7 +232,7 @@ class PreferenceSettingsGroupRepository
yield* prefStream.map(
(prefs) => _statelessSettingGroup!.copyWith.settings(
_statelessSettingGroup!.settings.map(
(key, value) => MapEntry(key, value.copyWith.actualValue(prefs[key])),
(key, value) => MapEntry(key, value.copyWith.current(prefs[key])),
),
),
);
@@ -229,7 +229,7 @@ final class _PreferenceRepositoryProvider
extends
$NotifierProvider<
_PreferenceRepository,
Raw<Stream<Map<String, Object>>>
Raw<Stream<Map<String, GeckoPrefValue>>>
> {
const _PreferenceRepositoryProvider._()
: super(
@@ -250,22 +250,21 @@ final class _PreferenceRepositoryProvider
_PreferenceRepository create() => _PreferenceRepository();
/// {@macro riverpod.override_with_value}
Override overrideWithValue(Raw<Stream<Map<String, Object>>> value) {
Override overrideWithValue(Raw<Stream<Map<String, GeckoPrefValue>>> value) {
return $ProviderOverride(
origin: this,
providerOverride: $SyncValueProvider<Raw<Stream<Map<String, Object>>>>(
value,
),
providerOverride:
$SyncValueProvider<Raw<Stream<Map<String, GeckoPrefValue>>>>(value),
);
}
}
String _$_preferenceRepositoryHash() =>
r'b2b7f75b3d30842b3006bb18af89f7ff90ba4ce7';
r'9a98b95677d4070def531ea1e5b900892045a1ef';
abstract class _$PreferenceRepository
extends $Notifier<Raw<Stream<Map<String, Object>>>> {
Raw<Stream<Map<String, Object>>> build();
extends $Notifier<Raw<Stream<Map<String, GeckoPrefValue>>>> {
Raw<Stream<Map<String, GeckoPrefValue>>> build();
@$mustCallSuper
@override
void runBuild() {
@@ -273,17 +272,17 @@ abstract class _$PreferenceRepository
final ref =
this.ref
as $Ref<
Raw<Stream<Map<String, Object>>>,
Raw<Stream<Map<String, Object>>>
Raw<Stream<Map<String, GeckoPrefValue>>>,
Raw<Stream<Map<String, GeckoPrefValue>>>
>;
final element =
ref.element
as $ClassProviderElement<
AnyNotifier<
Raw<Stream<Map<String, Object>>>,
Raw<Stream<Map<String, Object>>>
Raw<Stream<Map<String, GeckoPrefValue>>>,
Raw<Stream<Map<String, GeckoPrefValue>>>
>,
Raw<Stream<Map<String, Object>>>,
Raw<Stream<Map<String, GeckoPrefValue>>>,
Object?,
Object?
>;
@@ -341,7 +340,7 @@ final class UnifiedPreferenceSettingsRepositoryProvider
}
String _$unifiedPreferenceSettingsRepositoryHash() =>
r'23c0da1fdc975bbfb88b3cf82f242dbe0d50cd87';
r'800e74a051113b4ebc3631b6ade55d66cb7e1af1';
final class UnifiedPreferenceSettingsRepositoryFamily extends $Family
with
@@ -455,7 +454,7 @@ final class PreferenceSettingsGroupRepositoryProvider
}
String _$preferenceSettingsGroupRepositoryHash() =>
r'05db908036ffa999886f4e9dc4429aa85f8957f9';
r'8e025cdea5cef8a6ea029db6f9ebcd86abf906d8';
final class PreferenceSettingsGroupRepositoryFamily extends $Family
with
@@ -42,7 +42,7 @@ final class GeckoInferenceRepositoryProvider
}
String _$geckoInferenceRepositoryHash() =>
r'5f99fd1e46a8ae291b63df044fe11917cd5d415c';
r'c4f52d2edfb8c5763577a17697202016645177da';
abstract class _$GeckoInferenceRepository extends $Notifier<void> {
void build();
@@ -268,7 +268,7 @@ final class TopicSuggestionProvider
}
}
String _$topicSuggestionHash() => r'5401b1cd91e53be6ad1b4c7a39a5253d380e05d4';
String _$topicSuggestionHash() => r'97480102ecfe9458d25cb4666cf4577333e26d66';
final class TopicSuggestionFamily extends $Family
with
@@ -390,7 +390,7 @@ final class ContainerTabSuggestionsProvider
}
String _$containerTabSuggestionsHash() =>
r'9e7e9b9d245959fcf8c87cb8822313ded801ebc0';
r'1b681736215826886241aea834f99ebfb9761197';
final class ContainerTabSuggestionsFamily extends $Family
with $FunctionalFamilyOverride<FutureOr<List<String>?>, String?> {
@@ -34,7 +34,7 @@ final class EngineSettingsRepositoryProvider
}
String _$engineSettingsRepositoryHash() =>
r'33acd89e783d8d91b9b56e86411fdfcab24a2c54';
r'17a4e505320e92a90ed8b62db263c283c5eaa839';
abstract class _$EngineSettingsRepository
extends $StreamNotifier<EngineSettings> {