remove deprecated content blocking
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import 'package:copy_with_extension/copy_with_extension.dart';
|
||||
import 'package:fast_equatable/fast_equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lensai/features/content_block/data/models/host.dart';
|
||||
import 'package:lensai/features/kagi/data/entities/modes.dart';
|
||||
|
||||
part 'settings.g.dart';
|
||||
@@ -13,9 +12,7 @@ class Settings with FastEquatable {
|
||||
final bool incognitoMode;
|
||||
final bool enableJavascript;
|
||||
final bool launchUrlExternal;
|
||||
final bool enableContentBlocking;
|
||||
final bool blockHttpProtocol;
|
||||
final Set<HostSource> enableHostList;
|
||||
final ThemeMode themeMode;
|
||||
final KagiTool? quickAction;
|
||||
final bool quickActionVoiceInput;
|
||||
@@ -27,9 +24,7 @@ class Settings with FastEquatable {
|
||||
required this.incognitoMode,
|
||||
required this.enableJavascript,
|
||||
required this.launchUrlExternal,
|
||||
required this.enableContentBlocking,
|
||||
required this.blockHttpProtocol,
|
||||
required this.enableHostList,
|
||||
required this.themeMode,
|
||||
required this.quickAction,
|
||||
required this.quickActionVoiceInput,
|
||||
@@ -44,7 +39,6 @@ class Settings with FastEquatable {
|
||||
bool? launchUrlExternal,
|
||||
bool? enableContentBlocking,
|
||||
bool? blockHttpProtocol,
|
||||
Set<HostSource>? enableHostList,
|
||||
ThemeMode? themeMode,
|
||||
this.quickAction,
|
||||
bool? quickActionVoiceInput,
|
||||
@@ -53,9 +47,7 @@ class Settings with FastEquatable {
|
||||
incognitoMode = incognitoMode ?? true,
|
||||
enableJavascript = enableJavascript ?? true,
|
||||
launchUrlExternal = launchUrlExternal ?? false,
|
||||
enableContentBlocking = enableContentBlocking ?? true,
|
||||
blockHttpProtocol = blockHttpProtocol ?? false,
|
||||
enableHostList = enableHostList ?? {HostSource.stevenBlackUnified},
|
||||
themeMode = themeMode ?? ThemeMode.dark,
|
||||
quickActionVoiceInput = quickActionVoiceInput ?? false,
|
||||
enableReadability = enableReadability ?? true;
|
||||
@@ -70,9 +62,7 @@ class Settings with FastEquatable {
|
||||
incognitoMode,
|
||||
enableJavascript,
|
||||
launchUrlExternal,
|
||||
enableContentBlocking,
|
||||
blockHttpProtocol,
|
||||
enableHostList,
|
||||
themeMode,
|
||||
quickAction,
|
||||
quickActionVoiceInput,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:lensai/features/settings/data/models/settings.dart';
|
||||
import 'package:lensai/features/settings/utils/preference_parser.dart';
|
||||
@@ -15,9 +14,7 @@ enum _StorageKeys {
|
||||
incognito('enabe_incognito'),
|
||||
javascript('enable_js'),
|
||||
launchExternal('enable_launch_external'),
|
||||
contentBlocking('enable_content_blocking'),
|
||||
blockHttpProtocol('block_http'),
|
||||
enableHostList('enable_host_lists'),
|
||||
themeMode('theme_mode'),
|
||||
quickAction('enable_quick_action'),
|
||||
quickActionVoiceInput('enable_quick_action_voice_input'),
|
||||
@@ -81,14 +78,6 @@ class SettingsRepository extends _$SettingsRepository {
|
||||
);
|
||||
}
|
||||
|
||||
if (newSettings.enableContentBlocking !=
|
||||
oldSettings.enableContentBlocking) {
|
||||
await sharedPreferences.setBool(
|
||||
_StorageKeys.contentBlocking.key,
|
||||
newSettings.enableContentBlocking,
|
||||
);
|
||||
}
|
||||
|
||||
if (newSettings.blockHttpProtocol != oldSettings.blockHttpProtocol) {
|
||||
await sharedPreferences.setBool(
|
||||
_StorageKeys.blockHttpProtocol.key,
|
||||
@@ -96,16 +85,6 @@ class SettingsRepository extends _$SettingsRepository {
|
||||
);
|
||||
}
|
||||
|
||||
if (!const DeepCollectionEquality.unordered().equals(
|
||||
newSettings.enableHostList,
|
||||
oldSettings.enableHostList,
|
||||
)) {
|
||||
await sharedPreferences.setStringList(
|
||||
_StorageKeys.enableHostList.key,
|
||||
newSettings.enableHostList.map((list) => list.name).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
if (newSettings.themeMode != oldSettings.themeMode) {
|
||||
await sharedPreferences.setInt(
|
||||
_StorageKeys.themeMode.key,
|
||||
@@ -157,13 +136,8 @@ class SettingsRepository extends _$SettingsRepository {
|
||||
enableJavascript: sharedPreferences.getBool(_StorageKeys.javascript.key),
|
||||
launchUrlExternal:
|
||||
sharedPreferences.getBool(_StorageKeys.launchExternal.key),
|
||||
enableContentBlocking:
|
||||
sharedPreferences.getBool(_StorageKeys.contentBlocking.key),
|
||||
blockHttpProtocol:
|
||||
sharedPreferences.getBool(_StorageKeys.blockHttpProtocol.key),
|
||||
enableHostList: parseHostSources(
|
||||
sharedPreferences.getStringList(_StorageKeys.enableHostList.key),
|
||||
),
|
||||
themeMode:
|
||||
parseThemeMode(sharedPreferences.getInt(_StorageKeys.themeMode.key)),
|
||||
quickAction:
|
||||
|
||||
@@ -7,14 +7,12 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:lensai/features/bangs/data/models/bang.dart';
|
||||
import 'package:lensai/features/bangs/domain/providers.dart';
|
||||
import 'package:lensai/features/bangs/domain/repositories/data.dart';
|
||||
import 'package:lensai/features/content_block/data/models/host.dart';
|
||||
import 'package:lensai/features/kagi/data/entities/modes.dart';
|
||||
import 'package:lensai/features/settings/data/models/settings.dart';
|
||||
import 'package:lensai/features/settings/data/repositories/settings_repository.dart';
|
||||
import 'package:lensai/features/settings/presentation/controllers/save_settings.dart';
|
||||
import 'package:lensai/features/settings/presentation/widgets/bang_group_list_tile.dart';
|
||||
import 'package:lensai/features/settings/presentation/widgets/custom_list_tile.dart';
|
||||
import 'package:lensai/features/settings/presentation/widgets/host_list_tile.dart';
|
||||
import 'package:lensai/features/settings/utils/session_link_extractor.dart';
|
||||
import 'package:lensai/presentation/hooks/listenable_callback.dart';
|
||||
import 'package:lensai/utils/ui_helper.dart' as ui_helper;
|
||||
@@ -335,56 +333,7 @@ class SettingsScreen extends HookConsumerWidget {
|
||||
: null,
|
||||
),
|
||||
_buildSection(theme, 'Content Blocking'),
|
||||
SwitchListTile.adaptive(
|
||||
title: const Text('Enable Content Blocking'),
|
||||
subtitle: const Text(
|
||||
'Prevents access to unwanted websites and ads, as defined in the selected lists below.',
|
||||
),
|
||||
value: settings.enableContentBlocking,
|
||||
onChanged: (value) async {
|
||||
await ref.read(saveSettingsControllerProvider.notifier).save(
|
||||
(currentSettings) => currentSettings.copyWith
|
||||
.enableContentBlocking(value),
|
||||
);
|
||||
},
|
||||
),
|
||||
_buildSubSection(theme, 'Lists'),
|
||||
HostListTile(
|
||||
enableContentBlocking: settings.enableContentBlocking,
|
||||
enableHostLists: settings.enableHostList,
|
||||
source: HostSource.stevenBlackUnified,
|
||||
title: 'StevenBlack: Unified',
|
||||
subtitle:
|
||||
'Blocks domains containing adware, malware and trackers.',
|
||||
),
|
||||
HostListTile(
|
||||
enableContentBlocking: settings.enableContentBlocking,
|
||||
enableHostLists: settings.enableHostList,
|
||||
source: HostSource.stevenBlackFakeNews,
|
||||
title: 'StevenBlack: Fake News',
|
||||
subtitle: 'Blocks domains known for spreading fake news.',
|
||||
),
|
||||
HostListTile(
|
||||
enableContentBlocking: settings.enableContentBlocking,
|
||||
enableHostLists: settings.enableHostList,
|
||||
source: HostSource.stevenBlackGambling,
|
||||
title: 'StevenBlack: Gambling',
|
||||
subtitle: 'Blocks domains related to gambling.',
|
||||
),
|
||||
HostListTile(
|
||||
enableContentBlocking: settings.enableContentBlocking,
|
||||
enableHostLists: settings.enableHostList,
|
||||
source: HostSource.stevenBlackPorn,
|
||||
title: 'StevenBlack: Porn',
|
||||
subtitle: 'Blocks adult content domains.',
|
||||
),
|
||||
HostListTile(
|
||||
enableContentBlocking: settings.enableContentBlocking,
|
||||
enableHostLists: settings.enableHostList,
|
||||
source: HostSource.stevenBlackSocial,
|
||||
title: 'StevenBlack: Social',
|
||||
subtitle: 'Blocks social media domains.',
|
||||
),
|
||||
const SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:lensai/features/content_block/data/models/host.dart';
|
||||
import 'package:lensai/features/content_block/domain/providers.dart';
|
||||
import 'package:lensai/features/content_block/domain/repositories/sync.dart';
|
||||
import 'package:lensai/features/settings/data/models/settings.dart';
|
||||
import 'package:lensai/features/settings/presentation/controllers/save_settings.dart';
|
||||
import 'package:lensai/features/settings/presentation/widgets/custom_list_tile.dart';
|
||||
import 'package:lensai/features/settings/presentation/widgets/sync_details_table.dart';
|
||||
|
||||
class HostListTile extends HookConsumerWidget {
|
||||
final bool enabled;
|
||||
|
||||
final bool enableContentBlocking;
|
||||
final Set<HostSource> enableHostLists;
|
||||
final HostSource source;
|
||||
|
||||
final String title;
|
||||
final String subtitle;
|
||||
|
||||
const HostListTile({
|
||||
required this.enableContentBlocking,
|
||||
required this.enableHostLists,
|
||||
required this.source,
|
||||
required this.title,
|
||||
required this.subtitle,
|
||||
this.enabled = true,
|
||||
super.key,
|
||||
});
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final enabled = enableHostLists.contains(source);
|
||||
|
||||
final lastSync = ref.watch(
|
||||
lastSyncOfSourceProvider(source).select((value) => value.valueOrNull),
|
||||
);
|
||||
|
||||
final count = ref.watch(
|
||||
hostCountOfSourceProvider(source).select((value) => value.valueOrNull),
|
||||
);
|
||||
|
||||
Future<void> toggleHostLists(HostSource source) async {
|
||||
final lists = enabled
|
||||
? ({...enableHostLists}..remove(source))
|
||||
: {...enableHostLists, source};
|
||||
|
||||
await ref.read(saveSettingsControllerProvider.notifier).save(
|
||||
(currentSettings) => currentSettings.copyWith.enableHostList(lists),
|
||||
);
|
||||
}
|
||||
|
||||
return CustomListTile(
|
||||
enabled: enableContentBlocking,
|
||||
title: title,
|
||||
subtitle: subtitle,
|
||||
prefix: Checkbox.adaptive(
|
||||
value: enableHostLists.contains(source),
|
||||
onChanged: enableContentBlocking
|
||||
? (_) async {
|
||||
await toggleHostLists(source);
|
||||
}
|
||||
: null,
|
||||
),
|
||||
suffix: FilledButton.icon(
|
||||
onPressed: (enabled && enableContentBlocking)
|
||||
? () async {
|
||||
await ref
|
||||
.read(hostSyncRepositoryProvider.notifier)
|
||||
.syncHostSource(source, null);
|
||||
}
|
||||
: null,
|
||||
icon: const Icon(Icons.sync),
|
||||
label: const Text('Sync'),
|
||||
),
|
||||
content: (enabled && enableContentBlocking)
|
||||
? Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
child: SyncDetailsTable(count, lastSync),
|
||||
)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,6 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lensai/features/content_block/data/models/host.dart';
|
||||
import 'package:lensai/features/kagi/data/entities/modes.dart';
|
||||
|
||||
Set<HostSource>? parseHostSources(List<String>? input) => input
|
||||
?.map(
|
||||
(list) =>
|
||||
HostSource.values.firstWhereOrNull((source) => source.name == list),
|
||||
)
|
||||
.nonNulls
|
||||
.toSet();
|
||||
|
||||
ThemeMode? parseThemeMode(int? index) {
|
||||
if (index != null && index < ThemeMode.values.length) {
|
||||
return ThemeMode.values[index];
|
||||
|
||||
Reference in New Issue
Block a user