setting to disable early access tools

This commit is contained in:
Fabian Freund
2024-06-05 17:19:43 +02:00
parent 692a962acf
commit bb23870bf8
10 changed files with 149 additions and 63 deletions
@@ -6,12 +6,14 @@ part 'settings.g.dart';
@CopyWith()
class Settings with FastEquatable {
final String? kagiSession;
final bool showEarlyAccessFeatures;
final bool incognitoMode;
final bool enableJavascript;
final bool launchUrlExternal;
Settings({
required this.kagiSession,
required this.showEarlyAccessFeatures,
required this.incognitoMode,
required this.enableJavascript,
required this.launchUrlExternal,
@@ -19,10 +21,12 @@ class Settings with FastEquatable {
Settings.withDefaults({
required this.kagiSession,
bool? showEarlyAccessFeatures,
bool? incognitoMode,
bool? enableJavascript,
bool? launchUrlExternal,
}) : incognitoMode = incognitoMode ?? true,
}) : showEarlyAccessFeatures = showEarlyAccessFeatures ?? true,
incognitoMode = incognitoMode ?? true,
enableJavascript = enableJavascript ?? true,
launchUrlExternal = launchUrlExternal ?? false;
@@ -32,6 +36,7 @@ class Settings with FastEquatable {
@override
List<Object?> get hashParameters => [
kagiSession,
showEarlyAccessFeatures,
incognitoMode,
enableJavascript,
launchUrlExternal,
@@ -9,6 +9,8 @@ part of 'settings.dart';
abstract class _$SettingsCWProxy {
Settings kagiSession(String? kagiSession);
Settings showEarlyAccessFeatures(bool showEarlyAccessFeatures);
Settings incognitoMode(bool incognitoMode);
Settings enableJavascript(bool enableJavascript);
@@ -23,6 +25,7 @@ abstract class _$SettingsCWProxy {
/// ````
Settings call({
String? kagiSession,
bool? showEarlyAccessFeatures,
bool? incognitoMode,
bool? enableJavascript,
bool? launchUrlExternal,
@@ -38,6 +41,10 @@ class _$SettingsCWProxyImpl implements _$SettingsCWProxy {
@override
Settings kagiSession(String? kagiSession) => this(kagiSession: kagiSession);
@override
Settings showEarlyAccessFeatures(bool showEarlyAccessFeatures) =>
this(showEarlyAccessFeatures: showEarlyAccessFeatures);
@override
Settings incognitoMode(bool incognitoMode) =>
this(incognitoMode: incognitoMode);
@@ -60,6 +67,7 @@ class _$SettingsCWProxyImpl implements _$SettingsCWProxy {
/// ````
Settings call({
Object? kagiSession = const $CopyWithPlaceholder(),
Object? showEarlyAccessFeatures = const $CopyWithPlaceholder(),
Object? incognitoMode = const $CopyWithPlaceholder(),
Object? enableJavascript = const $CopyWithPlaceholder(),
Object? launchUrlExternal = const $CopyWithPlaceholder(),
@@ -69,6 +77,12 @@ class _$SettingsCWProxyImpl implements _$SettingsCWProxy {
? _value.kagiSession
// ignore: cast_nullable_to_non_nullable
: kagiSession as String?,
showEarlyAccessFeatures:
showEarlyAccessFeatures == const $CopyWithPlaceholder() ||
showEarlyAccessFeatures == null
? _value.showEarlyAccessFeatures
// ignore: cast_nullable_to_non_nullable
: showEarlyAccessFeatures as bool,
incognitoMode:
incognitoMode == const $CopyWithPlaceholder() || incognitoMode == null
? _value.incognitoMode
@@ -10,6 +10,7 @@ typedef UpdateSettingsFunc = Settings Function(Settings currentSettings);
@Riverpod(keepAlive: true)
class SettingsRepository extends _$SettingsRepository {
static const _sessionStorageKey = 'b4ng_kagi_session';
static const _showEarlyAccessFeaturesKey = 'b4ng_show_early_access';
static const _incognitoStorageKey = 'b4ng_settings_incognito';
static const _javascriptStorageKey = 'b4ng_settings_js';
static const _launchExternalStorageKey = 'b4ng_settings_launch_external';
@@ -35,6 +36,16 @@ class SettingsRepository extends _$SettingsRepository {
);
}
if (newSettings.showEarlyAccessFeatures !=
oldSettings.showEarlyAccessFeatures) {
await _sharedPreferences.then(
(s) => s.setBool(
_showEarlyAccessFeaturesKey,
newSettings.showEarlyAccessFeatures,
),
);
}
if (newSettings.incognitoMode != oldSettings.incognitoMode) {
await _sharedPreferences.then(
(s) => s.setBool(_incognitoStorageKey, newSettings.incognitoMode),
@@ -66,6 +77,8 @@ class SettingsRepository extends _$SettingsRepository {
return Settings.withDefaults(
kagiSession: await _flutterSecureStorage.read(key: _sessionStorageKey),
showEarlyAccessFeatures:
sharedPreferences.getBool(_showEarlyAccessFeaturesKey),
incognitoMode: sharedPreferences.getBool(_incognitoStorageKey),
enableJavascript: sharedPreferences.getBool(_javascriptStorageKey),
launchUrlExternal: sharedPreferences.getBool(_launchExternalStorageKey),
@@ -7,7 +7,7 @@ part of 'settings_repository.dart';
// **************************************************************************
String _$settingsRepositoryHash() =>
r'2b715f29915e541cec5c7c0993c8099944989f48';
r'0beffd6449e5488e61beb181fefefd4aa24361b0';
/// See also [SettingsRepository].
@ProviderFor(SettingsRepository)