wip
This commit is contained in:
@@ -59,7 +59,6 @@ class GeneralSettings with FastEquatable {
|
||||
final bool enableLocalAiFeatures;
|
||||
final TabType defaultCreateTabType;
|
||||
final TabType defaultIntentTabType;
|
||||
final bool proxyPrivateTabsTor;
|
||||
final bool autoHideTabBar;
|
||||
final TabBarSwipeAction tabBarSwipeAction;
|
||||
|
||||
@@ -71,7 +70,6 @@ class GeneralSettings with FastEquatable {
|
||||
required this.defaultSearchProvider,
|
||||
required this.defaultSearchSuggestionsProvider,
|
||||
required this.createChildTabsOption,
|
||||
required this.proxyPrivateTabsTor,
|
||||
required this.showExtensionShortcut,
|
||||
required this.enableLocalAiFeatures,
|
||||
required this.defaultCreateTabType,
|
||||
@@ -88,7 +86,6 @@ class GeneralSettings with FastEquatable {
|
||||
String? defaultSearchProvider,
|
||||
SearchSuggestionProviders? defaultSearchSuggestionsProvider,
|
||||
bool? createChildTabsOption,
|
||||
bool? proxyPrivateTabsTor,
|
||||
bool? showExtensionShortcut,
|
||||
bool? enableLocalAiFeatures,
|
||||
TabType? defaultCreateTabType,
|
||||
@@ -102,7 +99,6 @@ class GeneralSettings with FastEquatable {
|
||||
defaultSearchSuggestionsProvider =
|
||||
defaultSearchSuggestionsProvider ?? _fallbackAutocompleteProvider,
|
||||
createChildTabsOption = createChildTabsOption ?? false,
|
||||
proxyPrivateTabsTor = proxyPrivateTabsTor ?? false,
|
||||
showExtensionShortcut = showExtensionShortcut ?? false,
|
||||
enableLocalAiFeatures = enableLocalAiFeatures ?? true,
|
||||
defaultCreateTabType = defaultCreateTabType ?? TabType.regular,
|
||||
@@ -129,7 +125,6 @@ class GeneralSettings with FastEquatable {
|
||||
enableLocalAiFeatures,
|
||||
defaultCreateTabType,
|
||||
defaultIntentTabType,
|
||||
proxyPrivateTabsTor,
|
||||
autoHideTabBar,
|
||||
tabBarSwipeAction,
|
||||
];
|
||||
|
||||
@@ -25,8 +25,6 @@ abstract class _$GeneralSettingsCWProxy {
|
||||
|
||||
GeneralSettings createChildTabsOption(bool createChildTabsOption);
|
||||
|
||||
GeneralSettings proxyPrivateTabsTor(bool proxyPrivateTabsTor);
|
||||
|
||||
GeneralSettings showExtensionShortcut(bool showExtensionShortcut);
|
||||
|
||||
GeneralSettings enableLocalAiFeatures(bool enableLocalAiFeatures);
|
||||
@@ -53,7 +51,6 @@ abstract class _$GeneralSettingsCWProxy {
|
||||
String defaultSearchProvider,
|
||||
SearchSuggestionProviders defaultSearchSuggestionsProvider,
|
||||
bool createChildTabsOption,
|
||||
bool proxyPrivateTabsTor,
|
||||
bool showExtensionShortcut,
|
||||
bool enableLocalAiFeatures,
|
||||
TabType defaultCreateTabType,
|
||||
@@ -98,10 +95,6 @@ class _$GeneralSettingsCWProxyImpl implements _$GeneralSettingsCWProxy {
|
||||
GeneralSettings createChildTabsOption(bool createChildTabsOption) =>
|
||||
this(createChildTabsOption: createChildTabsOption);
|
||||
|
||||
@override
|
||||
GeneralSettings proxyPrivateTabsTor(bool proxyPrivateTabsTor) =>
|
||||
this(proxyPrivateTabsTor: proxyPrivateTabsTor);
|
||||
|
||||
@override
|
||||
GeneralSettings showExtensionShortcut(bool showExtensionShortcut) =>
|
||||
this(showExtensionShortcut: showExtensionShortcut);
|
||||
@@ -141,7 +134,6 @@ class _$GeneralSettingsCWProxyImpl implements _$GeneralSettingsCWProxy {
|
||||
Object? defaultSearchProvider = const $CopyWithPlaceholder(),
|
||||
Object? defaultSearchSuggestionsProvider = const $CopyWithPlaceholder(),
|
||||
Object? createChildTabsOption = const $CopyWithPlaceholder(),
|
||||
Object? proxyPrivateTabsTor = const $CopyWithPlaceholder(),
|
||||
Object? showExtensionShortcut = const $CopyWithPlaceholder(),
|
||||
Object? enableLocalAiFeatures = const $CopyWithPlaceholder(),
|
||||
Object? defaultCreateTabType = const $CopyWithPlaceholder(),
|
||||
@@ -182,10 +174,6 @@ class _$GeneralSettingsCWProxyImpl implements _$GeneralSettingsCWProxy {
|
||||
? _value.createChildTabsOption
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: createChildTabsOption as bool,
|
||||
proxyPrivateTabsTor: proxyPrivateTabsTor == const $CopyWithPlaceholder()
|
||||
? _value.proxyPrivateTabsTor
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: proxyPrivateTabsTor as bool,
|
||||
showExtensionShortcut:
|
||||
showExtensionShortcut == const $CopyWithPlaceholder()
|
||||
? _value.showExtensionShortcut
|
||||
@@ -241,7 +229,6 @@ GeneralSettings _$GeneralSettingsFromJson(Map<String, dynamic> json) =>
|
||||
json['defaultSearchSuggestionsProvider'],
|
||||
),
|
||||
createChildTabsOption: json['createChildTabsOption'] as bool?,
|
||||
proxyPrivateTabsTor: json['proxyPrivateTabsTor'] as bool?,
|
||||
showExtensionShortcut: json['showExtensionShortcut'] as bool?,
|
||||
enableLocalAiFeatures: json['enableLocalAiFeatures'] as bool?,
|
||||
defaultCreateTabType: $enumDecodeNullable(
|
||||
@@ -277,7 +264,6 @@ Map<String, dynamic> _$GeneralSettingsToJson(
|
||||
'enableLocalAiFeatures': instance.enableLocalAiFeatures,
|
||||
'defaultCreateTabType': _$TabTypeEnumMap[instance.defaultCreateTabType]!,
|
||||
'defaultIntentTabType': _$TabTypeEnumMap[instance.defaultIntentTabType]!,
|
||||
'proxyPrivateTabsTor': instance.proxyPrivateTabsTor,
|
||||
'autoHideTabBar': instance.autoHideTabBar,
|
||||
'tabBarSwipeAction': _$TabBarSwipeActionEnumMap[instance.tabBarSwipeAction]!,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import 'package:copy_with_extension/copy_with_extension.dart';
|
||||
import 'package:fast_equatable/fast_equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'tor_settings.g.dart';
|
||||
|
||||
@CopyWith()
|
||||
@JsonSerializable(includeIfNull: true, constructor: 'withDefaults')
|
||||
class TorSettings with FastEquatable {
|
||||
final bool proxyPrivateTabsTor;
|
||||
final bool autoConfig;
|
||||
|
||||
TorSettings({required this.proxyPrivateTabsTor, required this.autoConfig});
|
||||
|
||||
TorSettings.withDefaults({bool? proxyPrivateTabsTor, bool? autoConfig})
|
||||
: proxyPrivateTabsTor = proxyPrivateTabsTor ?? false,
|
||||
autoConfig = autoConfig ?? true;
|
||||
|
||||
factory TorSettings.fromJson(Map<String, dynamic> json) =>
|
||||
_$TorSettingsFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$TorSettingsToJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [proxyPrivateTabsTor, autoConfig];
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'tor_settings.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// CopyWithGenerator
|
||||
// **************************************************************************
|
||||
|
||||
abstract class _$TorSettingsCWProxy {
|
||||
TorSettings proxyPrivateTabsTor(bool proxyPrivateTabsTor);
|
||||
|
||||
TorSettings autoConfig(bool autoConfig);
|
||||
|
||||
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TorSettings(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
|
||||
///
|
||||
/// Usage
|
||||
/// ```dart
|
||||
/// TorSettings(...).copyWith(id: 12, name: "My name")
|
||||
/// ````
|
||||
TorSettings call({bool proxyPrivateTabsTor, bool autoConfig});
|
||||
}
|
||||
|
||||
/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfTorSettings.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfTorSettings.copyWith.fieldName(...)`
|
||||
class _$TorSettingsCWProxyImpl implements _$TorSettingsCWProxy {
|
||||
const _$TorSettingsCWProxyImpl(this._value);
|
||||
|
||||
final TorSettings _value;
|
||||
|
||||
@override
|
||||
TorSettings proxyPrivateTabsTor(bool proxyPrivateTabsTor) =>
|
||||
this(proxyPrivateTabsTor: proxyPrivateTabsTor);
|
||||
|
||||
@override
|
||||
TorSettings autoConfig(bool autoConfig) => this(autoConfig: autoConfig);
|
||||
|
||||
@override
|
||||
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TorSettings(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
|
||||
///
|
||||
/// Usage
|
||||
/// ```dart
|
||||
/// TorSettings(...).copyWith(id: 12, name: "My name")
|
||||
/// ````
|
||||
TorSettings call({
|
||||
Object? proxyPrivateTabsTor = const $CopyWithPlaceholder(),
|
||||
Object? autoConfig = const $CopyWithPlaceholder(),
|
||||
}) {
|
||||
return TorSettings(
|
||||
proxyPrivateTabsTor: proxyPrivateTabsTor == const $CopyWithPlaceholder()
|
||||
? _value.proxyPrivateTabsTor
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: proxyPrivateTabsTor as bool,
|
||||
autoConfig: autoConfig == const $CopyWithPlaceholder()
|
||||
? _value.autoConfig
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: autoConfig as bool,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension $TorSettingsCopyWith on TorSettings {
|
||||
/// Returns a callable class that can be used as follows: `instanceOfTorSettings.copyWith(...)` or like so:`instanceOfTorSettings.copyWith.fieldName(...)`.
|
||||
// ignore: library_private_types_in_public_api
|
||||
_$TorSettingsCWProxy get copyWith => _$TorSettingsCWProxyImpl(this);
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
TorSettings _$TorSettingsFromJson(Map<String, dynamic> json) =>
|
||||
TorSettings.withDefaults(
|
||||
proxyPrivateTabsTor: json['proxyPrivateTabsTor'] as bool?,
|
||||
autoConfig: json['autoConfig'] as bool?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$TorSettingsToJson(TorSettings instance) =>
|
||||
<String, dynamic>{
|
||||
'proxyPrivateTabsTor': instance.proxyPrivateTabsTor,
|
||||
'autoConfig': instance.autoConfig,
|
||||
};
|
||||
@@ -72,10 +72,6 @@ class GeneralSettingsRepository extends _$GeneralSettingsRepository {
|
||||
DriftSqlType.bool,
|
||||
db.typeMapping,
|
||||
),
|
||||
'proxyPrivateTabsTor': settings['proxyPrivateTabsTor']?.readAs(
|
||||
DriftSqlType.bool,
|
||||
db.typeMapping,
|
||||
),
|
||||
'showExtensionShortcut': settings['showExtensionShortcut']?.readAs(
|
||||
DriftSqlType.bool,
|
||||
db.typeMapping,
|
||||
|
||||
@@ -27,7 +27,7 @@ final generalSettingsWithDefaultsProvider =
|
||||
typedef GeneralSettingsWithDefaultsRef =
|
||||
AutoDisposeProviderRef<GeneralSettings>;
|
||||
String _$generalSettingsRepositoryHash() =>
|
||||
r'e311760a7773109a90c28275262883fcca348bbb';
|
||||
r'07eeaf811fac4b9c787cce7c29379a7329910ae5';
|
||||
|
||||
/// See also [GeneralSettingsRepository].
|
||||
@ProviderFor(GeneralSettingsRepository)
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:riverpod/riverpod.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/features/user/data/models/tor_settings.dart';
|
||||
import 'package:weblibre/features/user/data/providers.dart';
|
||||
|
||||
part 'tor_settings.g.dart';
|
||||
|
||||
typedef UpdateTorSettingsFunc =
|
||||
TorSettings Function(TorSettings currentSettings);
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class TorSettingsRepository extends _$TorSettingsRepository {
|
||||
final _partitionKey = 'tor';
|
||||
|
||||
TorSettings _deserializeSettings(List<MapEntry<String, DriftAny?>> entries) {
|
||||
final settings = Map.fromEntries(entries);
|
||||
|
||||
final db = ref.read(userDatabaseProvider);
|
||||
|
||||
return TorSettings.fromJson({
|
||||
'proxyPrivateTabsTor': settings['proxyPrivateTabsTor']?.readAs(
|
||||
DriftSqlType.bool,
|
||||
db.typeMapping,
|
||||
),
|
||||
'autoConfig': settings['autoConfig']?.readAs(
|
||||
DriftSqlType.bool,
|
||||
db.typeMapping,
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
//Eager fetch, when up to date settings are required
|
||||
Future<TorSettings> fetchSettings() {
|
||||
return ref
|
||||
.read(userDatabaseProvider)
|
||||
.settingDao
|
||||
.getAllSettingsOfPartitionKey(_partitionKey)
|
||||
.get()
|
||||
.then(_deserializeSettings);
|
||||
}
|
||||
|
||||
Future<void> updateSettings(UpdateTorSettingsFunc updateWithCurrent) async {
|
||||
final current = await fetchSettings();
|
||||
|
||||
final oldJson = current.toJson();
|
||||
final newJson = updateWithCurrent(current).toJson();
|
||||
|
||||
final db = ref.read(userDatabaseProvider);
|
||||
|
||||
return db.transaction(() async {
|
||||
for (final MapEntry(:key, :value) in newJson.entries) {
|
||||
if (oldJson[key] != value) {
|
||||
await db.settingDao.updateSetting(key, _partitionKey, value);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<TorSettings> build() {
|
||||
final db = ref.watch(userDatabaseProvider);
|
||||
|
||||
return db.settingDao
|
||||
.getAllSettingsOfPartitionKey(_partitionKey)
|
||||
.watch()
|
||||
.map((event) {
|
||||
return _deserializeSettings(event);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
TorSettings torSettingsWithDefaults(Ref ref) {
|
||||
return ref.watch(
|
||||
torSettingsRepositoryProvider.select(
|
||||
(value) => value.valueOrNull ?? TorSettings.withDefaults(),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'tor_settings.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$torSettingsWithDefaultsHash() =>
|
||||
r'b355678ae49e038f7e1b60f2d5da3f806349cba8';
|
||||
|
||||
/// See also [torSettingsWithDefaults].
|
||||
@ProviderFor(torSettingsWithDefaults)
|
||||
final torSettingsWithDefaultsProvider =
|
||||
AutoDisposeProvider<TorSettings>.internal(
|
||||
torSettingsWithDefaults,
|
||||
name: r'torSettingsWithDefaultsProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$torSettingsWithDefaultsHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
||||
// ignore: unused_element
|
||||
typedef TorSettingsWithDefaultsRef = AutoDisposeProviderRef<TorSettings>;
|
||||
String _$torSettingsRepositoryHash() =>
|
||||
r'686e8576453f33a0d2d0eb2869e29ca88e00bc37';
|
||||
|
||||
/// See also [TorSettingsRepository].
|
||||
@ProviderFor(TorSettingsRepository)
|
||||
final torSettingsRepositoryProvider =
|
||||
StreamNotifierProvider<TorSettingsRepository, TorSettings>.internal(
|
||||
TorSettingsRepository.new,
|
||||
name: r'torSettingsRepositoryProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$torSettingsRepositoryHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$TorSettingsRepository = StreamNotifier<TorSettings>;
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package
|
||||
Reference in New Issue
Block a user