push
This commit is contained in:
@@ -1,18 +1,34 @@
|
||||
import 'package:lensai/features/user/domain/repositories/settings.dart';
|
||||
import 'package:lensai/features/user/domain/repositories/engine_settings.dart';
|
||||
import 'package:lensai/features/user/domain/repositories/general_settings.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'save_settings.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class SaveSettingsController extends _$SaveSettingsController {
|
||||
class SaveGeneralSettingsController extends _$SaveGeneralSettingsController {
|
||||
@override
|
||||
FutureOr<void> build() {}
|
||||
|
||||
Future<void> save(UpdateSettingsFunc updateSettings) async {
|
||||
Future<void> save(UpdateGeneralSettingsFunc updateSettings) async {
|
||||
state = const AsyncLoading();
|
||||
state = await AsyncValue.guard(
|
||||
() => ref
|
||||
.read(settingsRepositoryProvider.notifier)
|
||||
.read(generalSettingsRepositoryProvider.notifier)
|
||||
.updateSettings(updateSettings),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class SaveEngineSettingsController extends _$SaveEngineSettingsController {
|
||||
@override
|
||||
FutureOr<void> build() {}
|
||||
|
||||
Future<void> save(UpdateEngineSettingsFunc updateSettings) async {
|
||||
state = const AsyncLoading();
|
||||
state = await AsyncValue.guard(
|
||||
() => ref
|
||||
.read(engineSettingsRepositoryProvider.notifier)
|
||||
.updateSettings(updateSettings),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,22 +6,39 @@ part of 'save_settings.dart';
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$saveSettingsControllerHash() =>
|
||||
r'7ffcef95b48dce1f80b56fb3580282ff3df240b4';
|
||||
String _$saveGeneralSettingsControllerHash() =>
|
||||
r'ad8b60839cbcb05a964f57e32fc5d9c1aba30377';
|
||||
|
||||
/// See also [SaveSettingsController].
|
||||
@ProviderFor(SaveSettingsController)
|
||||
final saveSettingsControllerProvider =
|
||||
AsyncNotifierProvider<SaveSettingsController, void>.internal(
|
||||
SaveSettingsController.new,
|
||||
name: r'saveSettingsControllerProvider',
|
||||
/// See also [SaveGeneralSettingsController].
|
||||
@ProviderFor(SaveGeneralSettingsController)
|
||||
final saveGeneralSettingsControllerProvider =
|
||||
AsyncNotifierProvider<SaveGeneralSettingsController, void>.internal(
|
||||
SaveGeneralSettingsController.new,
|
||||
name: r'saveGeneralSettingsControllerProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$saveSettingsControllerHash,
|
||||
: _$saveGeneralSettingsControllerHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$SaveSettingsController = AsyncNotifier<void>;
|
||||
typedef _$SaveGeneralSettingsController = AsyncNotifier<void>;
|
||||
String _$saveEngineSettingsControllerHash() =>
|
||||
r'4ca0ee76a41a72a8e6eacdb0e39045c667390c00';
|
||||
|
||||
/// See also [SaveEngineSettingsController].
|
||||
@ProviderFor(SaveEngineSettingsController)
|
||||
final saveEngineSettingsControllerProvider =
|
||||
AsyncNotifierProvider<SaveEngineSettingsController, void>.internal(
|
||||
SaveEngineSettingsController.new,
|
||||
name: r'saveEngineSettingsControllerProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$saveEngineSettingsControllerHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$SaveEngineSettingsController = AsyncNotifier<void>;
|
||||
// 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
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import 'package:fading_scroll/fading_scroll.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:lensai/features/bangs/data/models/bang.dart';
|
||||
import 'package:lensai/features/bangs/domain/repositories/data.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/sections.dart';
|
||||
|
||||
class BangSettingsScreen extends HookConsumerWidget {
|
||||
const BangSettingsScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Bang Settings')),
|
||||
body: FadingScroll(
|
||||
fadingSize: 25,
|
||||
builder: (context, controller) {
|
||||
return ListView(
|
||||
controller: controller,
|
||||
children: [
|
||||
CustomListTile(
|
||||
title: 'Bang Frequencies',
|
||||
subtitle: 'Tracked usage for Bang recommendations',
|
||||
suffix: FilledButton.icon(
|
||||
onPressed: () async {
|
||||
await ref
|
||||
.read(bangDataRepositoryProvider.notifier)
|
||||
.resetFrequencies();
|
||||
},
|
||||
icon: const Icon(Icons.delete),
|
||||
label: const Text('Clear'),
|
||||
),
|
||||
),
|
||||
const SettingSubSection(name: 'Repositories'),
|
||||
const BangGroupListTile(
|
||||
group: BangGroup.general,
|
||||
title: 'General Bangs',
|
||||
subtitle: 'Automatically syncs every 7 days',
|
||||
),
|
||||
const BangGroupListTile(
|
||||
group: BangGroup.assistant,
|
||||
title: 'Assistant Bangs',
|
||||
subtitle: 'Automatically syncs every 7 days',
|
||||
),
|
||||
const BangGroupListTile(
|
||||
group: BangGroup.kagi,
|
||||
title: 'Kagi Bangs',
|
||||
subtitle: 'Automatically syncs every 7 days',
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
import 'package:fading_scroll/fading_scroll.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.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/user/data/models/general_settings.dart';
|
||||
import 'package:lensai/features/user/domain/providers.dart';
|
||||
import 'package:lensai/features/user/domain/repositories/cache.dart';
|
||||
import 'package:lensai/features/user/domain/repositories/general_settings.dart';
|
||||
|
||||
class GeneralSettingsScreen extends HookConsumerWidget {
|
||||
const GeneralSettingsScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
final generalSettings = ref.watch(generalSettingsRepositoryProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('General Settings')),
|
||||
body: FadingScroll(
|
||||
fadingSize: 25,
|
||||
builder: (context, controller) {
|
||||
return ListView(
|
||||
controller: controller,
|
||||
children: [
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const ListTile(
|
||||
title: Text('Theme'),
|
||||
leading: Icon(Icons.palette),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
Center(
|
||||
child: SegmentedButton<ThemeMode>(
|
||||
segments: const [
|
||||
ButtonSegment(
|
||||
value: ThemeMode.system,
|
||||
icon: Icon(Icons.brightness_auto),
|
||||
label: Text('System'),
|
||||
),
|
||||
ButtonSegment(
|
||||
value: ThemeMode.light,
|
||||
icon: Icon(Icons.light_mode),
|
||||
label: Text('Light'),
|
||||
),
|
||||
ButtonSegment(
|
||||
value: ThemeMode.dark,
|
||||
icon: Icon(Icons.dark_mode),
|
||||
label: Text('Dark'),
|
||||
),
|
||||
],
|
||||
selected: {generalSettings.themeMode},
|
||||
onSelectionChanged: (value) async {
|
||||
await ref
|
||||
.read(saveGeneralSettingsControllerProvider
|
||||
.notifier)
|
||||
.save(
|
||||
(currentSettings) => currentSettings.copyWith
|
||||
.themeMode(value.first),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SwitchListTile.adaptive(
|
||||
title: const Text('Enable Reader Mode'),
|
||||
subtitle: const Text(
|
||||
'Optional browser app bar tool that extracts and simplifies web pages for improved readability by removing ads, sidebars, and other non-essential elements.',
|
||||
),
|
||||
secondary: const Icon(MdiIcons.bookOpen),
|
||||
value: generalSettings.enableReadability,
|
||||
onChanged: (value) async {
|
||||
await ref
|
||||
.read(saveGeneralSettingsControllerProvider.notifier)
|
||||
.save(
|
||||
(currentSettings) =>
|
||||
currentSettings.copyWith.enableReadability(value),
|
||||
);
|
||||
},
|
||||
),
|
||||
Consumer(
|
||||
builder: (context, ref, child) {
|
||||
final size = ref.watch(
|
||||
iconCacheSizeMegabytesProvider.select(
|
||||
(value) => value.valueOrNull,
|
||||
),
|
||||
);
|
||||
|
||||
return CustomListTile(
|
||||
title: 'Icon Cache',
|
||||
subtitle: 'Stored favicons',
|
||||
prefix: Padding(
|
||||
padding: const EdgeInsets.only(right: 16.0),
|
||||
child: Icon(
|
||||
Icons.image,
|
||||
size: 24,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
content: Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
child: DefaultTextStyle(
|
||||
style: GoogleFonts.robotoMono(
|
||||
textStyle: DefaultTextStyle.of(context).style,
|
||||
),
|
||||
child: Table(
|
||||
columnWidths: const {0: FixedColumnWidth(100)},
|
||||
children: [
|
||||
TableRow(
|
||||
children: [
|
||||
const Text('Size'),
|
||||
Text('${size?.toStringAsFixed(2) ?? 0} MB'),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
suffix: FilledButton.icon(
|
||||
onPressed: () async {
|
||||
await ref
|
||||
.read(cacheRepositoryProvider.notifier)
|
||||
.clearCache();
|
||||
},
|
||||
icon: const Icon(Icons.delete),
|
||||
label: const Text('Clear'),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,48 +1,15 @@
|
||||
import 'package:fading_scroll/fading_scroll.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:lensai/core/routing/routes.dart';
|
||||
import 'package:lensai/features/bangs/data/models/bang.dart';
|
||||
import 'package:lensai/features/bangs/domain/repositories/data.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/user/data/models/settings.dart';
|
||||
import 'package:lensai/features/user/domain/providers.dart';
|
||||
import 'package:lensai/features/user/domain/repositories/cache.dart';
|
||||
import 'package:lensai/features/user/domain/repositories/settings.dart';
|
||||
|
||||
class SettingsScreen extends HookConsumerWidget {
|
||||
const SettingsScreen({super.key});
|
||||
|
||||
Widget _buildSection(ThemeData theme, String name) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(name, style: theme.textTheme.titleLarge),
|
||||
const Divider(),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget _buildSubSection(ThemeData theme, String name) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
|
||||
child: Text(
|
||||
name,
|
||||
style: theme.textTheme.titleLarge?.copyWith(fontSize: 18),
|
||||
),
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
final settings = ref.watch(settingsRepositoryProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Settings')),
|
||||
body: FadingScroll(
|
||||
@@ -50,189 +17,61 @@ class SettingsScreen extends HookConsumerWidget {
|
||||
builder: (context, controller) {
|
||||
return ListView(
|
||||
controller: controller,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
||||
children: [
|
||||
_buildSection(theme, 'General'),
|
||||
Card(
|
||||
color: Theme.of(context).highlightColor,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: ListTile(
|
||||
title: const Text('Browser Hardening'),
|
||||
trailing: IconButton(
|
||||
onPressed: () async {
|
||||
await context.push(BrowserHardeningRoute().location);
|
||||
},
|
||||
icon: const Icon(Icons.chevron_right),
|
||||
title: const Text('General'),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
vertical: 8.0,
|
||||
horizontal: 16.0,
|
||||
),
|
||||
leading: const Icon(Icons.settings),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () async {
|
||||
await context.push(GeneralSettingsRoute().location);
|
||||
},
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Theme',
|
||||
style: theme.textTheme.bodyLarge,
|
||||
),
|
||||
Center(
|
||||
child: SegmentedButton<ThemeMode>(
|
||||
segments: const [
|
||||
ButtonSegment(
|
||||
value: ThemeMode.system,
|
||||
icon: Icon(Icons.brightness_auto),
|
||||
label: Text('System'),
|
||||
),
|
||||
ButtonSegment(
|
||||
value: ThemeMode.light,
|
||||
icon: Icon(Icons.light_mode),
|
||||
label: Text('Light'),
|
||||
),
|
||||
ButtonSegment(
|
||||
value: ThemeMode.dark,
|
||||
icon: Icon(Icons.dark_mode),
|
||||
label: Text('Dark'),
|
||||
),
|
||||
],
|
||||
selected: {settings.themeMode},
|
||||
onSelectionChanged: (value) async {
|
||||
await ref
|
||||
.read(saveSettingsControllerProvider.notifier)
|
||||
.save(
|
||||
(currentSettings) => currentSettings.copyWith
|
||||
.themeMode(value.first),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SwitchListTile.adaptive(
|
||||
title: const Text('Incognito Mode'),
|
||||
subtitle: const Text(
|
||||
'Deletes all browsing data upon app restart for enhanced privacy.',
|
||||
),
|
||||
value: settings.incognitoMode,
|
||||
onChanged: (value) async {
|
||||
await ref.read(saveSettingsControllerProvider.notifier).save(
|
||||
(currentSettings) =>
|
||||
currentSettings.copyWith.incognitoMode(value),
|
||||
);
|
||||
},
|
||||
),
|
||||
SwitchListTile.adaptive(
|
||||
title: const Text('Enable JavaScript'),
|
||||
subtitle: const Text(
|
||||
'While turning off JavaScript boosts security, privacy, and speed, it may cause some sites to not work as intended.',
|
||||
),
|
||||
value: settings.enableJavascript,
|
||||
onChanged: (value) async {
|
||||
await ref.read(saveSettingsControllerProvider.notifier).save(
|
||||
(currentSettings) =>
|
||||
currentSettings.copyWith.enableJavascript(value),
|
||||
);
|
||||
},
|
||||
),
|
||||
SwitchListTile.adaptive(
|
||||
title: const Text('Block HTTP Protocol'),
|
||||
subtitle: const Text(
|
||||
'Prevents the loading of unsecure HTTP content. When enabled, only secure HTTPS content is allowed.',
|
||||
),
|
||||
value: settings.blockHttpProtocol,
|
||||
onChanged: (value) async {
|
||||
await ref.read(saveSettingsControllerProvider.notifier).save(
|
||||
(currentSettings) =>
|
||||
currentSettings.copyWith.blockHttpProtocol(value),
|
||||
);
|
||||
},
|
||||
),
|
||||
SwitchListTile.adaptive(
|
||||
title: const Text('Enable Reader Mode'),
|
||||
subtitle: const Text(
|
||||
'Optional browser app bar tool that extracts and simplifies web pages for improved readability by removing ads, sidebars, and other non-essential elements.',
|
||||
),
|
||||
value: settings.enableReadability,
|
||||
onChanged: (value) async {
|
||||
await ref.read(saveSettingsControllerProvider.notifier).save(
|
||||
(currentSettings) =>
|
||||
currentSettings.copyWith.enableReadability(value),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(
|
||||
height: 16,
|
||||
height: 8,
|
||||
),
|
||||
_buildSection(theme, 'Bangs'),
|
||||
CustomListTile(
|
||||
title: 'Bang Frequencies',
|
||||
subtitle: 'Tracked usage for Bang recommendations',
|
||||
suffix: FilledButton.icon(
|
||||
onPressed: () async {
|
||||
await ref
|
||||
.read(bangDataRepositoryProvider.notifier)
|
||||
.resetFrequencies();
|
||||
Card(
|
||||
color: Theme.of(context).highlightColor,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: ListTile(
|
||||
title: const Text('Web Engine'),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
vertical: 8.0,
|
||||
horizontal: 16.0,
|
||||
),
|
||||
leading: const Icon(MdiIcons.web),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () async {
|
||||
await context.push(WebEngineSettingsRoute().location);
|
||||
},
|
||||
icon: const Icon(Icons.delete),
|
||||
label: const Text('Clear'),
|
||||
),
|
||||
),
|
||||
Consumer(
|
||||
builder: (context, ref, child) {
|
||||
final size = ref.watch(
|
||||
iconCacheSizeMegabytesProvider.select(
|
||||
(value) => value.valueOrNull,
|
||||
),
|
||||
);
|
||||
|
||||
return CustomListTile(
|
||||
title: 'Icon Cache',
|
||||
subtitle: 'Stored favicons for Bangs',
|
||||
content: Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
child: DefaultTextStyle(
|
||||
style: GoogleFonts.robotoMono(
|
||||
textStyle: DefaultTextStyle.of(context).style,
|
||||
),
|
||||
child: Table(
|
||||
columnWidths: const {0: FixedColumnWidth(100)},
|
||||
children: [
|
||||
TableRow(
|
||||
children: [
|
||||
const Text('Size'),
|
||||
Text('${size?.toStringAsFixed(2) ?? 0} MB'),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
suffix: FilledButton.icon(
|
||||
onPressed: () async {
|
||||
await ref
|
||||
.read(cacheRepositoryProvider.notifier)
|
||||
.clearCache();
|
||||
},
|
||||
icon: const Icon(Icons.delete),
|
||||
label: const Text('Clear'),
|
||||
),
|
||||
);
|
||||
},
|
||||
const SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
_buildSubSection(theme, 'Repositories'),
|
||||
const BangGroupListTile(
|
||||
group: BangGroup.general,
|
||||
title: 'General Bangs',
|
||||
subtitle: 'Automatically syncs every 7 days',
|
||||
),
|
||||
const BangGroupListTile(
|
||||
group: BangGroup.assistant,
|
||||
title: 'Assistant Bangs',
|
||||
subtitle: 'Automatically syncs every 7 days',
|
||||
),
|
||||
const BangGroupListTile(
|
||||
group: BangGroup.kagi,
|
||||
title: 'Kagi Bangs',
|
||||
subtitle: 'Automatically syncs every 7 days',
|
||||
Card(
|
||||
color: Theme.of(context).highlightColor,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: ListTile(
|
||||
title: const Text('Bangs'),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
vertical: 8.0,
|
||||
horizontal: 16.0,
|
||||
),
|
||||
leading: const Icon(MdiIcons.exclamationThick),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () async {
|
||||
await context.push(BangSettingsRoute().location);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
+20
-12
@@ -4,17 +4,20 @@ import 'package:go_router/go_router.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:lensai/core/routing/routes.dart';
|
||||
import 'package:lensai/data/models/equatable_iterable.dart';
|
||||
import 'package:lensai/extensions/nullable.dart';
|
||||
import 'package:lensai/features/geckoview/features/preferences/data/repositories/preference_settings.dart';
|
||||
import 'package:lensai/features/geckoview/features/tabs/utils/setting_groups_serializer.dart';
|
||||
import 'package:lensai/features/settings/presentation/widgets/hardening_group_icon.dart';
|
||||
import 'package:lensai/presentation/widgets/failure_widget.dart';
|
||||
|
||||
class BrowserHardeningScreen extends HookConsumerWidget {
|
||||
const BrowserHardeningScreen();
|
||||
class WebEngineHardeningScreen extends HookConsumerWidget {
|
||||
const WebEngineHardeningScreen();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final preferenceGroups =
|
||||
ref.watch(preferenceSettingsGeneralRepositoryProvider);
|
||||
final preferenceGroups = ref.watch(
|
||||
unifiedPreferenceSettingsRepositoryProvider(PreferencePartition.user),
|
||||
);
|
||||
|
||||
final allGroupsActive = useMemoized(
|
||||
() =>
|
||||
@@ -28,7 +31,7 @@ class BrowserHardeningScreen extends HookConsumerWidget {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Browser Hardening')),
|
||||
appBar: AppBar(title: const Text('Web Engine Hardening')),
|
||||
body: preferenceGroups.when(
|
||||
data: (data) {
|
||||
return Column(
|
||||
@@ -49,7 +52,9 @@ class BrowserHardeningScreen extends HookConsumerWidget {
|
||||
),
|
||||
onChanged: (value) async {
|
||||
final notifier = ref.read(
|
||||
preferenceSettingsGeneralRepositoryProvider.notifier,
|
||||
unifiedPreferenceSettingsRepositoryProvider(
|
||||
PreferencePartition.user,
|
||||
).notifier,
|
||||
);
|
||||
|
||||
if (value) {
|
||||
@@ -71,9 +76,9 @@ class BrowserHardeningScreen extends HookConsumerWidget {
|
||||
Expanded(
|
||||
child: ListTile(
|
||||
title: Text(group.key),
|
||||
subtitle: (group.value.description != null)
|
||||
? Text(group.value.description!)
|
||||
: null,
|
||||
subtitle: group.value.description.mapNotNull(
|
||||
(description) => Text(description),
|
||||
),
|
||||
leading: HardeningGroupIcon(
|
||||
isActive: group.value.isActive,
|
||||
isPartlyActive: group.value.isPartlyActive,
|
||||
@@ -81,7 +86,7 @@ class BrowserHardeningScreen extends HookConsumerWidget {
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () async {
|
||||
await context.push(
|
||||
BrowserHardeningGroupRoute(
|
||||
WebEngineHardeningGroupRoute(
|
||||
group: group.key,
|
||||
).location,
|
||||
);
|
||||
@@ -100,8 +105,11 @@ class BrowserHardeningScreen extends HookConsumerWidget {
|
||||
error: (error, stackTrace) => FailureWidget(
|
||||
title: 'Could not load preference settings',
|
||||
exception: error,
|
||||
onRetry: () =>
|
||||
ref.refresh(preferenceSettingsGeneralRepositoryProvider),
|
||||
onRetry: () => ref.refresh(
|
||||
unifiedPreferenceSettingsRepositoryProvider(
|
||||
PreferencePartition.user,
|
||||
),
|
||||
),
|
||||
),
|
||||
loading: () => const SizedBox.shrink(),
|
||||
),
|
||||
+40
-27
@@ -1,18 +1,24 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:lensai/extensions/nullable.dart';
|
||||
import 'package:lensai/features/geckoview/features/preferences/data/repositories/preference_settings.dart';
|
||||
import 'package:lensai/features/geckoview/features/tabs/utils/setting_groups_serializer.dart';
|
||||
import 'package:lensai/features/settings/presentation/widgets/hardening_group_icon.dart';
|
||||
import 'package:lensai/presentation/widgets/failure_widget.dart';
|
||||
|
||||
class BrowserHardeningGroupScreen extends HookConsumerWidget {
|
||||
class WebEngineHardeningGroupScreen extends HookConsumerWidget {
|
||||
final String groupName;
|
||||
|
||||
const BrowserHardeningGroupScreen({super.key, required this.groupName});
|
||||
const WebEngineHardeningGroupScreen({super.key, required this.groupName});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final settings =
|
||||
ref.watch(preferenceSettingsGroupRepositoryProvider(groupName));
|
||||
final settings = ref.watch(
|
||||
preferenceSettingsGroupRepositoryProvider(
|
||||
PreferencePartition.user,
|
||||
groupName,
|
||||
),
|
||||
);
|
||||
|
||||
final theme = Theme.of(context);
|
||||
|
||||
@@ -36,18 +42,20 @@ class BrowserHardeningGroupScreen extends HookConsumerWidget {
|
||||
color: theme.colorScheme.onPrimaryContainer,
|
||||
),
|
||||
),
|
||||
subtitle: (group.description != null)
|
||||
? Text(
|
||||
group.description!,
|
||||
style: TextStyle(
|
||||
color: theme.colorScheme.onPrimaryContainer,
|
||||
),
|
||||
)
|
||||
: null,
|
||||
subtitle: group.description.mapNotNull(
|
||||
(description) => Text(
|
||||
description,
|
||||
style: TextStyle(
|
||||
color: theme.colorScheme.onPrimaryContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
onChanged: (value) async {
|
||||
final notifier = ref.read(
|
||||
preferenceSettingsGroupRepositoryProvider(groupName)
|
||||
.notifier,
|
||||
preferenceSettingsGroupRepositoryProvider(
|
||||
PreferencePartition.user,
|
||||
groupName,
|
||||
).notifier,
|
||||
);
|
||||
|
||||
if (value) {
|
||||
@@ -71,16 +79,17 @@ class BrowserHardeningGroupScreen extends HookConsumerWidget {
|
||||
Expanded(
|
||||
child: SwitchListTile(
|
||||
value: setting.value.isActive,
|
||||
title: Text(setting.value.title),
|
||||
subtitle: (setting.value.description != null)
|
||||
? Text(setting.value.description!)
|
||||
: null,
|
||||
title: Text(setting.value.title ?? setting.key),
|
||||
subtitle: setting.value.description.mapNotNull(
|
||||
(description) => Text(description),
|
||||
),
|
||||
secondary: HardeningGroupIcon(
|
||||
isActive: setting.value.isActive,
|
||||
),
|
||||
onChanged: (value) async {
|
||||
final notifier = ref.read(
|
||||
preferenceSettingsGroupRepositoryProvider(
|
||||
PreferencePartition.user,
|
||||
groupName,
|
||||
).notifier,
|
||||
);
|
||||
@@ -96,16 +105,16 @@ class BrowserHardeningGroupScreen extends HookConsumerWidget {
|
||||
else
|
||||
Expanded(
|
||||
child: ListTile(
|
||||
title: Text(setting.value.title),
|
||||
subtitle: (setting.value.description != null)
|
||||
? Text(setting.value.description!)
|
||||
: null,
|
||||
title: Text(setting.value.title ?? setting.key),
|
||||
subtitle: setting.value.description.mapNotNull(
|
||||
(description) => Text(description),
|
||||
),
|
||||
leading: HardeningGroupIcon(
|
||||
isActive: setting.value.isActive,
|
||||
),
|
||||
trailing: Padding(
|
||||
padding: const EdgeInsets.only(right: 18.0),
|
||||
child: const Icon(Icons.check),
|
||||
trailing: const Padding(
|
||||
padding: EdgeInsets.only(right: 18.0),
|
||||
child: Icon(Icons.check),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -121,8 +130,12 @@ class BrowserHardeningGroupScreen extends HookConsumerWidget {
|
||||
error: (error, stackTrace) => FailureWidget(
|
||||
title: 'Could not load preference settings',
|
||||
exception: error,
|
||||
onRetry: () =>
|
||||
ref.refresh(preferenceSettingsGroupRepositoryProvider(groupName)),
|
||||
onRetry: () => ref.refresh(
|
||||
preferenceSettingsGroupRepositoryProvider(
|
||||
PreferencePartition.user,
|
||||
groupName,
|
||||
),
|
||||
),
|
||||
),
|
||||
loading: () => const SizedBox.shrink(),
|
||||
),
|
||||
@@ -0,0 +1,315 @@
|
||||
import 'package:fading_scroll/fading_scroll.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
||||
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:lensai/core/routing/routes.dart';
|
||||
import 'package:lensai/extensions/nullable.dart';
|
||||
import 'package:lensai/features/settings/presentation/controllers/save_settings.dart';
|
||||
import 'package:lensai/features/user/data/models/engine_settings.dart';
|
||||
import 'package:lensai/features/user/data/models/general_settings.dart';
|
||||
import 'package:lensai/features/user/domain/repositories/engine_settings.dart';
|
||||
import 'package:lensai/features/user/domain/repositories/general_settings.dart';
|
||||
|
||||
class WebEngineSettingsScreen extends HookConsumerWidget {
|
||||
const WebEngineSettingsScreen();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final generalSettings = ref.watch(generalSettingsRepositoryProvider);
|
||||
final engineSettings = ref.watch(engineSettingsRepositoryProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Web Engine Settings')),
|
||||
body: FadingScroll(
|
||||
fadingSize: 25,
|
||||
builder: (context, controller) {
|
||||
return ListView(
|
||||
controller: controller,
|
||||
children: [
|
||||
SwitchListTile.adaptive(
|
||||
title: const Text('Incognito Mode'),
|
||||
subtitle: const Text(
|
||||
'Deletes all browsing data upon app restart for enhanced privacy.',
|
||||
),
|
||||
secondary: const Icon(MdiIcons.incognito),
|
||||
value: generalSettings.deleteBrowsingDataOnQuit != null,
|
||||
onChanged: (value) async {
|
||||
await ref
|
||||
.read(saveGeneralSettingsControllerProvider.notifier)
|
||||
.save(
|
||||
(currentSettings) => value
|
||||
? currentSettings.copyWith
|
||||
.deleteBrowsingDataOnQuit({})
|
||||
: currentSettings.copyWith
|
||||
.deleteBrowsingDataOnQuit(null),
|
||||
);
|
||||
},
|
||||
),
|
||||
if (generalSettings.deleteBrowsingDataOnQuit != null)
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8),
|
||||
child: Column(
|
||||
children: [
|
||||
for (final type in DeleteBrowsingDataType.values)
|
||||
CheckboxListTile.adaptive(
|
||||
value: generalSettings.deleteBrowsingDataOnQuit!
|
||||
.contains(type),
|
||||
controlAffinity: ListTileControlAffinity.leading,
|
||||
title: Text(type.title),
|
||||
subtitle: type.description
|
||||
.mapNotNull((description) => Text(description)),
|
||||
onChanged: (value) async {
|
||||
final notifier = ref.read(
|
||||
saveGeneralSettingsControllerProvider.notifier,
|
||||
);
|
||||
|
||||
if (value == true) {
|
||||
await notifier.save(
|
||||
(currentSettings) => currentSettings.copyWith
|
||||
.deleteBrowsingDataOnQuit({
|
||||
...currentSettings.deleteBrowsingDataOnQuit!,
|
||||
type,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
await notifier.save(
|
||||
(currentSettings) => currentSettings.copyWith
|
||||
.deleteBrowsingDataOnQuit(
|
||||
{
|
||||
...currentSettings
|
||||
.deleteBrowsingDataOnQuit!,
|
||||
}..remove(type),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SwitchListTile.adaptive(
|
||||
title: const Text('Enable JavaScript'),
|
||||
subtitle: const Text(
|
||||
'While turning off JavaScript boosts security, privacy, and speed, it may cause some sites to not work as intended.',
|
||||
),
|
||||
secondary: const Icon(MdiIcons.languageJavascript),
|
||||
value: engineSettings.javascriptEnabled,
|
||||
onChanged: (value) async {
|
||||
await ref
|
||||
.read(saveEngineSettingsControllerProvider.notifier)
|
||||
.save(
|
||||
(currentSettings) =>
|
||||
currentSettings.copyWith.javascriptEnabled(value),
|
||||
);
|
||||
},
|
||||
),
|
||||
SwitchListTile.adaptive(
|
||||
title: const Text('Enable Global Privacy Control (GPC)'),
|
||||
secondary: const Icon(MdiIcons.incognitoCircleOff),
|
||||
value: engineSettings.globalPrivacyControlEnabled,
|
||||
onChanged: (value) async {
|
||||
await ref
|
||||
.read(saveEngineSettingsControllerProvider.notifier)
|
||||
.save(
|
||||
(currentSettings) => currentSettings.copyWith
|
||||
.globalPrivacyControlEnabled(value),
|
||||
);
|
||||
},
|
||||
),
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const ListTile(
|
||||
title: Text('Block insecure HTTP connections'),
|
||||
leading: Icon(MdiIcons.lockOpen),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
Center(
|
||||
child: SegmentedButton<HttpsOnlyMode>(
|
||||
segments: const [
|
||||
ButtonSegment(
|
||||
value: HttpsOnlyMode.disabled,
|
||||
label: Text('Disabled'),
|
||||
),
|
||||
ButtonSegment(
|
||||
value: HttpsOnlyMode.enabled,
|
||||
label: Text('Enabled'),
|
||||
),
|
||||
ButtonSegment(
|
||||
value: HttpsOnlyMode.privateOnly,
|
||||
label: Text('Private mode only'),
|
||||
),
|
||||
],
|
||||
selected: {engineSettings.httpsOnlyMode},
|
||||
onSelectionChanged: (value) async {
|
||||
await ref
|
||||
.read(
|
||||
saveEngineSettingsControllerProvider.notifier,
|
||||
)
|
||||
.save(
|
||||
(currentSettings) => currentSettings.copyWith
|
||||
.httpsOnlyMode(value.first),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const ListTile(
|
||||
title: Text('Enhanced Tracking Protection'),
|
||||
leading: Icon(MdiIcons.incognitoCircleOff),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
RadioListTile<TrackingProtectionPolicy>.adaptive(
|
||||
value: TrackingProtectionPolicy.none,
|
||||
title: const Text('Disabled'),
|
||||
groupValue: engineSettings.trackingProtectionPolicy,
|
||||
onChanged: (value) async {
|
||||
await ref
|
||||
.read(
|
||||
saveEngineSettingsControllerProvider.notifier,
|
||||
)
|
||||
.save(
|
||||
(currentSettings) => currentSettings.copyWith
|
||||
.trackingProtectionPolicy(value),
|
||||
);
|
||||
},
|
||||
),
|
||||
RadioListTile<TrackingProtectionPolicy>.adaptive(
|
||||
value: TrackingProtectionPolicy.recommended,
|
||||
title: const Text('Standard'),
|
||||
subtitle: const Text(
|
||||
'Pages will load normally, but block fewer trackers.',
|
||||
),
|
||||
groupValue: engineSettings.trackingProtectionPolicy,
|
||||
onChanged: (value) async {
|
||||
await ref
|
||||
.read(
|
||||
saveEngineSettingsControllerProvider.notifier,
|
||||
)
|
||||
.save(
|
||||
(currentSettings) => currentSettings.copyWith
|
||||
.trackingProtectionPolicy(value),
|
||||
);
|
||||
},
|
||||
),
|
||||
RadioListTile<TrackingProtectionPolicy>.adaptive(
|
||||
value: TrackingProtectionPolicy.strict,
|
||||
title: const Text('Strict'),
|
||||
subtitle: const Text(
|
||||
'Stronger tracking protection and faster performance, but some sites may not work properly.',
|
||||
),
|
||||
groupValue: engineSettings.trackingProtectionPolicy,
|
||||
onChanged: (value) async {
|
||||
await ref
|
||||
.read(
|
||||
saveEngineSettingsControllerProvider.notifier,
|
||||
)
|
||||
.save(
|
||||
(currentSettings) => currentSettings.copyWith
|
||||
.trackingProtectionPolicy(value),
|
||||
);
|
||||
},
|
||||
),
|
||||
RadioListTile<TrackingProtectionPolicy>.adaptive(
|
||||
value: TrackingProtectionPolicy.custom,
|
||||
title: const Text('Custom'),
|
||||
subtitle: const Text(
|
||||
'Choose which trackers and scripts to block.',
|
||||
),
|
||||
groupValue: engineSettings.trackingProtectionPolicy,
|
||||
onChanged: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const ListTile(
|
||||
title: Text('Cookie Banner Blocker'),
|
||||
leading: Icon(MdiIcons.cookieSettings),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
CheckboxListTile.adaptive(
|
||||
value: engineSettings.cookieBannerHandlingMode ==
|
||||
CookieBannerHandlingMode.rejectAll,
|
||||
title: const Text('In normal browsing'),
|
||||
controlAffinity: ListTileControlAffinity.leading,
|
||||
onChanged: (value) async {
|
||||
await ref
|
||||
.read(
|
||||
saveEngineSettingsControllerProvider.notifier,
|
||||
)
|
||||
.save(
|
||||
(currentSettings) => currentSettings.copyWith
|
||||
.cookieBannerHandlingMode(
|
||||
value!
|
||||
? CookieBannerHandlingMode.rejectAll
|
||||
: CookieBannerHandlingMode.disabled,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
CheckboxListTile.adaptive(
|
||||
value: engineSettings
|
||||
.cookieBannerHandlingModePrivateBrowsing ==
|
||||
CookieBannerHandlingMode.rejectAll,
|
||||
title: const Text('In private browsing'),
|
||||
controlAffinity: ListTileControlAffinity.leading,
|
||||
onChanged: (value) async {
|
||||
await ref
|
||||
.read(
|
||||
saveEngineSettingsControllerProvider.notifier,
|
||||
)
|
||||
.save(
|
||||
(currentSettings) => currentSettings.copyWith
|
||||
.cookieBannerHandlingModePrivateBrowsing(
|
||||
value!
|
||||
? CookieBannerHandlingMode.rejectAll
|
||||
: CookieBannerHandlingMode.disabled,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('Web Engine Hardening'),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
vertical: 8.0,
|
||||
horizontal: 16.0,
|
||||
),
|
||||
leading: const Icon(MdiIcons.shieldLock),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () async {
|
||||
await context.push(WebEngineHardeningRoute().location);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SettingSection extends StatelessWidget {
|
||||
final String name;
|
||||
|
||||
const SettingSection({required this.name});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(name, style: Theme.of(context).textTheme.titleLarge),
|
||||
const Divider(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SettingSubSection extends StatelessWidget {
|
||||
final String name;
|
||||
|
||||
const SettingSubSection({required this.name});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
|
||||
child: Text(
|
||||
name,
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(fontSize: 18),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user