add setting for readability
This commit is contained in:
@@ -191,6 +191,13 @@ class KagiScreen extends HookConsumerWidget {
|
||||
readerabilityControllerProvider(controller),
|
||||
);
|
||||
|
||||
final enableReadability = ref.watch(
|
||||
settingsRepositoryProvider.select(
|
||||
(value) => (value.valueOrNull ?? Settings.withDefaults())
|
||||
.enableReadability,
|
||||
),
|
||||
);
|
||||
|
||||
final isReaderable = useValueListenable(
|
||||
activeWebView.isReaderable,
|
||||
);
|
||||
@@ -213,7 +220,8 @@ class KagiScreen extends HookConsumerWidget {
|
||||
);
|
||||
|
||||
return Visibility(
|
||||
visible: isReaderable == true || readerableApplied,
|
||||
visible: enableReadability &&
|
||||
(isReaderable == true || readerableApplied),
|
||||
child: InkWell(
|
||||
onTap: readerabilityState.isLoading
|
||||
? null
|
||||
|
||||
@@ -19,6 +19,7 @@ class Settings with FastEquatable {
|
||||
final ThemeMode themeMode;
|
||||
final KagiTool? quickAction;
|
||||
final bool quickActionVoiceInput;
|
||||
final bool enableReadability;
|
||||
|
||||
Settings({
|
||||
required this.kagiSession,
|
||||
@@ -32,6 +33,7 @@ class Settings with FastEquatable {
|
||||
required this.themeMode,
|
||||
required this.quickAction,
|
||||
required this.quickActionVoiceInput,
|
||||
required this.enableReadability,
|
||||
});
|
||||
|
||||
Settings.withDefaults({
|
||||
@@ -46,6 +48,7 @@ class Settings with FastEquatable {
|
||||
ThemeMode? themeMode,
|
||||
this.quickAction,
|
||||
bool? quickActionVoiceInput,
|
||||
bool? enableReadability,
|
||||
}) : showEarlyAccessFeatures = showEarlyAccessFeatures ?? true,
|
||||
incognitoMode = incognitoMode ?? true,
|
||||
enableJavascript = enableJavascript ?? true,
|
||||
@@ -54,7 +57,8 @@ class Settings with FastEquatable {
|
||||
blockHttpProtocol = blockHttpProtocol ?? false,
|
||||
enableHostList = enableHostList ?? {HostSource.stevenBlackUnified},
|
||||
themeMode = themeMode ?? ThemeMode.dark,
|
||||
quickActionVoiceInput = quickActionVoiceInput ?? false;
|
||||
quickActionVoiceInput = quickActionVoiceInput ?? false,
|
||||
enableReadability = enableReadability ?? true;
|
||||
|
||||
@override
|
||||
bool get cacheHash => true;
|
||||
@@ -72,5 +76,6 @@ class Settings with FastEquatable {
|
||||
themeMode,
|
||||
quickAction,
|
||||
quickActionVoiceInput,
|
||||
enableReadability,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ abstract class _$SettingsCWProxy {
|
||||
|
||||
Settings quickActionVoiceInput(bool quickActionVoiceInput);
|
||||
|
||||
Settings enableReadability(bool enableReadability);
|
||||
|
||||
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `Settings(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
|
||||
///
|
||||
/// Usage
|
||||
@@ -47,6 +49,7 @@ abstract class _$SettingsCWProxy {
|
||||
ThemeMode? themeMode,
|
||||
KagiTool? quickAction,
|
||||
bool? quickActionVoiceInput,
|
||||
bool? enableReadability,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -97,6 +100,10 @@ class _$SettingsCWProxyImpl implements _$SettingsCWProxy {
|
||||
Settings quickActionVoiceInput(bool quickActionVoiceInput) =>
|
||||
this(quickActionVoiceInput: quickActionVoiceInput);
|
||||
|
||||
@override
|
||||
Settings enableReadability(bool enableReadability) =>
|
||||
this(enableReadability: enableReadability);
|
||||
|
||||
@override
|
||||
|
||||
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `Settings(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
|
||||
@@ -117,6 +124,7 @@ class _$SettingsCWProxyImpl implements _$SettingsCWProxy {
|
||||
Object? themeMode = const $CopyWithPlaceholder(),
|
||||
Object? quickAction = const $CopyWithPlaceholder(),
|
||||
Object? quickActionVoiceInput = const $CopyWithPlaceholder(),
|
||||
Object? enableReadability = const $CopyWithPlaceholder(),
|
||||
}) {
|
||||
return Settings(
|
||||
kagiSession: kagiSession == const $CopyWithPlaceholder()
|
||||
@@ -174,6 +182,11 @@ class _$SettingsCWProxyImpl implements _$SettingsCWProxy {
|
||||
? _value.quickActionVoiceInput
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: quickActionVoiceInput as bool,
|
||||
enableReadability: enableReadability == const $CopyWithPlaceholder() ||
|
||||
enableReadability == null
|
||||
? _value.enableReadability
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: enableReadability as bool,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ enum _StorageKeys {
|
||||
enableHostList('enable_host_lists'),
|
||||
themeMode('theme_mode'),
|
||||
quickAction('enable_quick_action'),
|
||||
quickActionVoiceInput('enable_quick_action_voice_input');
|
||||
quickActionVoiceInput('enable_quick_action_voice_input'),
|
||||
enableReadability('enable_readability');
|
||||
|
||||
final String key;
|
||||
|
||||
@@ -132,6 +133,13 @@ class SettingsRepository extends _$SettingsRepository {
|
||||
);
|
||||
}
|
||||
|
||||
if (newSettings.enableReadability != oldSettings.enableReadability) {
|
||||
await sharedPreferences.setBool(
|
||||
_StorageKeys.enableReadability.key,
|
||||
newSettings.enableReadability,
|
||||
);
|
||||
}
|
||||
|
||||
ref.invalidateSelf();
|
||||
}
|
||||
}
|
||||
@@ -162,6 +170,8 @@ class SettingsRepository extends _$SettingsRepository {
|
||||
parseKagiTool(sharedPreferences.getInt(_StorageKeys.quickAction.key)),
|
||||
quickActionVoiceInput:
|
||||
sharedPreferences.getBool(_StorageKeys.quickActionVoiceInput.key),
|
||||
enableReadability:
|
||||
sharedPreferences.getBool(_StorageKeys.enableReadability.key),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ part of 'settings_repository.dart';
|
||||
// **************************************************************************
|
||||
|
||||
String _$settingsRepositoryHash() =>
|
||||
r'34d3c771d6ebb17cb9aa41211e035b4d1cbf2183';
|
||||
r'f7c42efda64f0fb647e5daf0a92c2d118596cc52';
|
||||
|
||||
/// See also [SettingsRepository].
|
||||
@ProviderFor(SettingsRepository)
|
||||
|
||||
@@ -241,6 +241,19 @@ class SettingsScreen extends HookConsumerWidget {
|
||||
);
|
||||
},
|
||||
),
|
||||
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,
|
||||
),
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:bang_navigator/features/settings/data/models/settings.dart';
|
||||
import 'package:bang_navigator/features/settings/data/repositories/settings_repository.dart';
|
||||
import 'package:bang_navigator/features/web_view/domain/providers.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
@@ -7,10 +9,17 @@ part 'readerability_script.g.dart';
|
||||
@Riverpod()
|
||||
class ReaderabilityScriptService extends _$ReaderabilityScriptService {
|
||||
late Future<String> _readerabilityScript;
|
||||
late bool _enableReadability;
|
||||
|
||||
@override
|
||||
Future<void> build(InAppWebViewController? controller) async {
|
||||
_readerabilityScript = ref.watch(readerabilityScriptProvider.future);
|
||||
_enableReadability = ref.watch(
|
||||
settingsRepositoryProvider.select(
|
||||
(value) =>
|
||||
(value.valueOrNull ?? Settings.withDefaults()).enableReadability,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _injectScript() async {
|
||||
@@ -20,7 +29,7 @@ class ReaderabilityScriptService extends _$ReaderabilityScriptService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> ensureScriptInjected() async {
|
||||
Future<void> _ensureScriptInjected() async {
|
||||
if (controller != null) {
|
||||
final injected = await controller!.evaluateJavascript(
|
||||
source:
|
||||
@@ -34,22 +43,26 @@ class ReaderabilityScriptService extends _$ReaderabilityScriptService {
|
||||
}
|
||||
|
||||
Future<bool> isReaderable() async {
|
||||
await ensureScriptInjected();
|
||||
if (_enableReadability) {
|
||||
await _ensureScriptInjected();
|
||||
|
||||
if (controller != null) {
|
||||
return await controller!.evaluateJavascript(
|
||||
source: 'isReaderable();',
|
||||
) as bool;
|
||||
if (controller != null) {
|
||||
return await controller!.evaluateJavascript(
|
||||
source: 'isReaderable();',
|
||||
) as bool;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<void> applyReaderable() async {
|
||||
await ensureScriptInjected();
|
||||
if (_enableReadability) {
|
||||
await _ensureScriptInjected();
|
||||
|
||||
if (controller != null) {
|
||||
await controller!.evaluateJavascript(source: 'applyReaderable();');
|
||||
if (controller != null) {
|
||||
await controller!.evaluateJavascript(source: 'applyReaderable();');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ part of 'readerability_script.dart';
|
||||
// **************************************************************************
|
||||
|
||||
String _$readerabilityScriptServiceHash() =>
|
||||
r'780980e6771d8d860e261fb4bc41236a60e0aaab';
|
||||
r'7a4fe65f683c31545b2f2bcb3ea199619be4bf4b';
|
||||
|
||||
/// Copied from Dart SDK
|
||||
class _SystemHash {
|
||||
|
||||
Reference in New Issue
Block a user