selectable suggestion provider

This commit is contained in:
Fabian Freund
2025-06-27 16:30:12 +02:00
parent 3c1176bf79
commit bf190276cc
19 changed files with 586 additions and 47 deletions
@@ -2,10 +2,12 @@ import 'package:copy_with_extension/copy_with_extension.dart';
import 'package:fast_equatable/fast_equatable.dart';
import 'package:flutter/material.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:weblibre/features/search/domain/entities/abstract/i_search_suggestion_provider.dart';
part 'general_settings.g.dart';
const _fallbackSearchProvider = 'ddg';
const _fallbackAutocompleteProvider = SearchSuggestionProviders.ddg;
enum DeleteBrowsingDataType {
tabs('Open tabs'),
@@ -29,6 +31,7 @@ class GeneralSettings with FastEquatable {
final bool enforceReadability;
final Set<DeleteBrowsingDataType>? deleteBrowsingDataOnQuit;
final String defaultSearchProvider;
final SearchSuggestionProviders defaultSearchSuggestionsProvider;
final bool createChildTabsOption;
final bool proxyPrivateTabsTor;
@@ -39,6 +42,7 @@ class GeneralSettings with FastEquatable {
required this.enforceReadability,
required this.deleteBrowsingDataOnQuit,
required this.defaultSearchProvider,
required this.defaultSearchSuggestionsProvider,
required this.createChildTabsOption,
required this.proxyPrivateTabsTor,
});
@@ -49,12 +53,15 @@ class GeneralSettings with FastEquatable {
bool? enforceReadability,
this.deleteBrowsingDataOnQuit,
String? defaultSearchProvider,
SearchSuggestionProviders? defaultSearchSuggestionsProvider,
bool? createChildTabsOption,
bool? proxyPrivateTabsTor,
}) : themeMode = themeMode ?? ThemeMode.dark,
enableReadability = enableReadability ?? true,
enforceReadability = enforceReadability ?? false,
defaultSearchProvider = defaultSearchProvider ?? _fallbackSearchProvider,
defaultSearchSuggestionsProvider =
defaultSearchSuggestionsProvider ?? _fallbackAutocompleteProvider,
createChildTabsOption = createChildTabsOption ?? false,
proxyPrivateTabsTor = proxyPrivateTabsTor ?? false;
@@ -70,6 +77,7 @@ class GeneralSettings with FastEquatable {
enforceReadability,
deleteBrowsingDataOnQuit,
defaultSearchProvider,
defaultSearchSuggestionsProvider,
createChildTabsOption,
proxyPrivateTabsTor,
];
@@ -19,6 +19,10 @@ abstract class _$GeneralSettingsCWProxy {
GeneralSettings defaultSearchProvider(String defaultSearchProvider);
GeneralSettings defaultSearchSuggestionsProvider(
SearchSuggestionProviders defaultSearchSuggestionsProvider,
);
GeneralSettings createChildTabsOption(bool createChildTabsOption);
GeneralSettings proxyPrivateTabsTor(bool proxyPrivateTabsTor);
@@ -35,6 +39,7 @@ abstract class _$GeneralSettingsCWProxy {
bool enforceReadability,
Set<DeleteBrowsingDataType>? deleteBrowsingDataOnQuit,
String defaultSearchProvider,
SearchSuggestionProviders defaultSearchSuggestionsProvider,
bool createChildTabsOption,
bool proxyPrivateTabsTor,
});
@@ -66,6 +71,11 @@ class _$GeneralSettingsCWProxyImpl implements _$GeneralSettingsCWProxy {
GeneralSettings defaultSearchProvider(String defaultSearchProvider) =>
this(defaultSearchProvider: defaultSearchProvider);
@override
GeneralSettings defaultSearchSuggestionsProvider(
SearchSuggestionProviders defaultSearchSuggestionsProvider,
) => this(defaultSearchSuggestionsProvider: defaultSearchSuggestionsProvider);
@override
GeneralSettings createChildTabsOption(bool createChildTabsOption) =>
this(createChildTabsOption: createChildTabsOption);
@@ -87,6 +97,7 @@ class _$GeneralSettingsCWProxyImpl implements _$GeneralSettingsCWProxy {
Object? enforceReadability = const $CopyWithPlaceholder(),
Object? deleteBrowsingDataOnQuit = const $CopyWithPlaceholder(),
Object? defaultSearchProvider = const $CopyWithPlaceholder(),
Object? defaultSearchSuggestionsProvider = const $CopyWithPlaceholder(),
Object? createChildTabsOption = const $CopyWithPlaceholder(),
Object? proxyPrivateTabsTor = const $CopyWithPlaceholder(),
}) {
@@ -113,6 +124,11 @@ class _$GeneralSettingsCWProxyImpl implements _$GeneralSettingsCWProxy {
? _value.defaultSearchProvider
// ignore: cast_nullable_to_non_nullable
: defaultSearchProvider as String,
defaultSearchSuggestionsProvider:
defaultSearchSuggestionsProvider == const $CopyWithPlaceholder()
? _value.defaultSearchSuggestionsProvider
// ignore: cast_nullable_to_non_nullable
: defaultSearchSuggestionsProvider as SearchSuggestionProviders,
createChildTabsOption:
createChildTabsOption == const $CopyWithPlaceholder()
? _value.createChildTabsOption
@@ -146,6 +162,10 @@ GeneralSettings _$GeneralSettingsFromJson(Map<String, dynamic> json) =>
?.map((e) => $enumDecode(_$DeleteBrowsingDataTypeEnumMap, e))
.toSet(),
defaultSearchProvider: json['defaultSearchProvider'] as String?,
defaultSearchSuggestionsProvider: $enumDecodeNullable(
_$SearchSuggestionProvidersEnumMap,
json['defaultSearchSuggestionsProvider'],
),
createChildTabsOption: json['createChildTabsOption'] as bool?,
proxyPrivateTabsTor: json['proxyPrivateTabsTor'] as bool?,
);
@@ -159,6 +179,9 @@ Map<String, dynamic> _$GeneralSettingsToJson(GeneralSettings instance) =>
?.map((e) => _$DeleteBrowsingDataTypeEnumMap[e]!)
.toList(),
'defaultSearchProvider': instance.defaultSearchProvider,
'defaultSearchSuggestionsProvider':
_$SearchSuggestionProvidersEnumMap[instance
.defaultSearchSuggestionsProvider]!,
'createChildTabsOption': instance.createChildTabsOption,
'proxyPrivateTabsTor': instance.proxyPrivateTabsTor,
};
@@ -177,3 +200,10 @@ const _$DeleteBrowsingDataTypeEnumMap = {
DeleteBrowsingDataType.permissions: 'permissions',
DeleteBrowsingDataType.downloads: 'downloads',
};
const _$SearchSuggestionProvidersEnumMap = {
SearchSuggestionProviders.brave: 'brave',
SearchSuggestionProviders.ddg: 'ddg',
SearchSuggestionProviders.kagi: 'kagi',
SearchSuggestionProviders.qwant: 'qwant',
};