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