From 7f0397a97fa49ee21446e31f8d2220cd105b7061 Mon Sep 17 00:00:00 2001 From: problematicconsumer Date: Fri, 8 Mar 2024 17:15:17 +0330 Subject: [PATCH] Change experimental feature notice --- assets/translations/strings_en.i18n.json | 1 + .../data/config_option_repository.dart | 4 +- .../overview/config_options_page.dart | 14 +-- .../widget/experimental_feature_notice.dart | 115 +++++++++--------- .../home/widget/connection_button.dart | 2 +- 5 files changed, 68 insertions(+), 68 deletions(-) diff --git a/assets/translations/strings_en.i18n.json b/assets/translations/strings_en.i18n.json index 36d7604f..f1dcf569 100644 --- a/assets/translations/strings_en.i18n.json +++ b/assets/translations/strings_en.i18n.json @@ -36,6 +36,7 @@ "disconnecting": "Disconnecting", "connected": "Connected", "reconnect": "Reconnect", + "connectAnyWay": "Connect", "experimentalNotice": "Experimental Features In Use", "experimentalNoticeMsg": "You've enabled some experimental features which might affect connection quality and cause unexpected errors. You can always change or reset these options from Config options page.", "disableExperimentalNotice": "Don't show again" diff --git a/lib/features/config_option/data/config_option_repository.dart b/lib/features/config_option/data/config_option_repository.dart index e0ef080a..9c11b6d4 100644 --- a/lib/features/config_option/data/config_option_repository.dart +++ b/lib/features/config_option/data/config_option_repository.dart @@ -276,7 +276,9 @@ abstract class ConfigOptions { ref.watch(enableTlsMixedSniCase) || ref.watch(enableTlsPadding) || ref.watch(enableMux) || - ref.watch(enableWarp)) { + ref.watch(enableWarp) || + ref.watch(bypassLan) || + ref.watch(allowConnectionFromLan)) { return true; } diff --git a/lib/features/config_option/overview/config_options_page.dart b/lib/features/config_option/overview/config_options_page.dart index bc9764ff..120cc164 100644 --- a/lib/features/config_option/overview/config_options_page.dart +++ b/lib/features/config_option/overview/config_options_page.dart @@ -284,10 +284,11 @@ class ConfigOptionsPage extends HookConsumerWidget { .update, ), const SettingsDivider(), - SettingsSection(t.settings.config.section.tlsTricks), + SettingsSection( + experimental(t.settings.config.section.tlsTricks), + ), SwitchListTile( - title: - Text(experimental(t.settings.config.enableTlsFragment)), + title: Text(t.settings.config.enableTlsFragment), value: ref.watch(ConfigOptions.enableTlsFragment), onChanged: ref .watch(ConfigOptions.enableTlsFragment.notifier) @@ -312,17 +313,14 @@ class ConfigOptionsPage extends HookConsumerWidget { formatInputValue: (value) => value.format(), ), SwitchListTile( - title: Text( - experimental(t.settings.config.enableTlsMixedSniCase), - ), + title: Text(t.settings.config.enableTlsMixedSniCase), value: ref.watch(ConfigOptions.enableTlsMixedSniCase), onChanged: ref .watch(ConfigOptions.enableTlsMixedSniCase.notifier) .update, ), SwitchListTile( - title: - Text(experimental(t.settings.config.enableTlsPadding)), + title: Text(t.settings.config.enableTlsPadding), value: ref.watch(ConfigOptions.enableTlsPadding), onChanged: ref .watch(ConfigOptions.enableTlsPadding.notifier) diff --git a/lib/features/connection/widget/experimental_feature_notice.dart b/lib/features/connection/widget/experimental_feature_notice.dart index 8016ad60..54c210da 100644 --- a/lib/features/connection/widget/experimental_feature_notice.dart +++ b/lib/features/connection/widget/experimental_feature_notice.dart @@ -1,29 +1,20 @@ +import 'package:fluentui_system_icons/fluentui_system_icons.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; +import 'package:gap/gap.dart'; import 'package:hiddify/core/localization/translations.dart'; -import 'package:hiddify/core/preferences/preferences_provider.dart'; import 'package:hiddify/core/router/routes.dart'; +import 'package:hiddify/core/utils/preferences_utils.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; -part 'experimental_feature_notice.g.dart'; +bool _testExperimentalNotice = false; -@riverpod -class DisableExperimentalFeatureNotice - extends _$DisableExperimentalFeatureNotice { - static const _key = "disable_experimental_feature_notice"; - - @override - bool build() { - return ref.read(sharedPreferencesProvider).requireValue.getBool(_key) ?? - false; - } - - Future change(bool pref) async { - state = pref; - await ref.read(sharedPreferencesProvider).requireValue.setBool(_key, pref); - } -} +final disableExperimentalFeatureNoticeProvider = + PreferencesNotifier.createAutoDispose( + "disable_experimental_feature_notice", + false, + overrideValue: _testExperimentalNotice && kDebugMode ? false : null, +); class ExperimentalFeatureNoticeDialog extends HookConsumerWidget { const ExperimentalFeatureNoticeDialog({super.key}); @@ -38,48 +29,56 @@ class ExperimentalFeatureNoticeDialog extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { final t = ref.watch(translationsProvider); - final shouldDisable = - useState(ref.read(disableExperimentalFeatureNoticeProvider)); + final disableNotice = ref.watch(disableExperimentalFeatureNoticeProvider); - return PopScope( - onPopInvoked: (didPop) async { - await ref - .read(disableExperimentalFeatureNoticeProvider.notifier) - .change(shouldDisable.value); - }, - child: AlertDialog( - title: Text(t.home.connection.experimentalNotice), - content: SingleChildScrollView( - child: SizedBox( - width: 468, - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text(t.home.connection.experimentalNoticeMsg), - CheckboxListTile( - value: shouldDisable.value, - title: Text(t.home.connection.disableExperimentalNotice), - onChanged: (value) => shouldDisable.value = value ?? false, - ), - ], - ), + return AlertDialog( + title: Text(t.home.connection.experimentalNotice), + content: SingleChildScrollView( + child: SizedBox( + width: 468, + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(t.home.connection.experimentalNoticeMsg), + const Gap(8), + CheckboxListTile( + value: disableNotice, + title: Text(t.home.connection.disableExperimentalNotice), + secondary: const Icon(FluentIcons.eye_off_24_regular), + onChanged: (value) async => ref + .read(disableExperimentalFeatureNoticeProvider.notifier) + .update(value ?? false), + dense: true, + ), + ListTile( + title: Text(t.settings.config.pageTitle), + leading: const Icon(FluentIcons.box_edit_24_regular), + trailing: const Icon(FluentIcons.chevron_right_20_regular), + onTap: () async { + await Navigator.of(context).maybePop(false); + if (context.mounted) { + const ConfigOptionsRoute().push(context); + } + }, + dense: true, + ), + ], ), ), - actions: [ - TextButton( - onPressed: () async { - await Navigator.of(context).maybePop(false); - if (context.mounted) const ConfigOptionsRoute().push(context); - }, - child: Text(t.settings.config.pageTitle), - ), - TextButton( - onPressed: () => Navigator.of(context).maybePop(true), - child: Text(MaterialLocalizations.of(context).okButtonLabel), - ), - ], ), + actions: [ + TextButton( + onPressed: () => Navigator.of(context).maybePop(false), + child: Text( + MaterialLocalizations.of(context).cancelButtonLabel.toUpperCase(), + ), + ), + TextButton( + onPressed: () => Navigator.of(context).maybePop(true), + child: Text(t.home.connection.connectAnyWay.toUpperCase()), + ), + ], ); } } diff --git a/lib/features/home/widget/connection_button.dart b/lib/features/home/widget/connection_button.dart index 79abc455..c6bbb447 100644 --- a/lib/features/home/widget/connection_button.dart +++ b/lib/features/home/widget/connection_button.dart @@ -47,7 +47,7 @@ class ConnectionButton extends HookConsumerWidget { final canShowNotice = !ref.read(disableExperimentalFeatureNoticeProvider); if (hasExperimental && canShowNotice && context.mounted) { return await const ExperimentalFeatureNoticeDialog().show(context) ?? - true; + false; } return true; }