Add experimental feature notice
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:hiddify/core/utils/json_converters.dart';
|
||||
import 'package:hiddify/features/config_option/model/config_option_patch.dart';
|
||||
import 'package:hiddify/features/log/model/log_level.dart';
|
||||
import 'package:hiddify/singbox/model/singbox_config_enum.dart';
|
||||
import 'package:hiddify/utils/platform_utils.dart';
|
||||
|
||||
part 'config_option_entity.freezed.dart';
|
||||
part 'config_option_entity.g.dart';
|
||||
@@ -56,6 +57,17 @@ class ConfigOptionEntity with _$ConfigOptionEntity {
|
||||
serviceMode: ServiceMode.defaultMode,
|
||||
);
|
||||
|
||||
bool hasExperimentalOptions() {
|
||||
if (PlatformUtils.isDesktop && serviceMode == ServiceMode.tun) {
|
||||
return true;
|
||||
}
|
||||
if (enableTlsFragment || enableTlsMixedSniCase || enableTlsPadding) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
String format() {
|
||||
const encoder = JsonEncoder.withIndent(' ');
|
||||
return encoder.convert(toJson());
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.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:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'experimental_feature_notice.g.dart';
|
||||
|
||||
@riverpod
|
||||
class DisableExperimentalFeatureNotice
|
||||
extends _$DisableExperimentalFeatureNotice {
|
||||
static const _key = "disable_experimental_feature_notice";
|
||||
|
||||
@override
|
||||
bool build() {
|
||||
return ref.read(sharedPreferencesProvider).requireValue.getBool(_key) ??
|
||||
false;
|
||||
}
|
||||
|
||||
Future<void> change(bool pref) async {
|
||||
state = pref;
|
||||
await ref.read(sharedPreferencesProvider).requireValue.setBool(_key, pref);
|
||||
}
|
||||
}
|
||||
|
||||
class ExperimentalFeatureNoticeDialog extends HookConsumerWidget {
|
||||
const ExperimentalFeatureNoticeDialog({super.key});
|
||||
|
||||
Future<bool?> show(BuildContext context) async {
|
||||
return showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => this,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final t = ref.watch(translationsProvider);
|
||||
final shouldDisable =
|
||||
useState(ref.read(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,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
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),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,10 @@ import 'package:gap/gap.dart';
|
||||
import 'package:hiddify/core/localization/translations.dart';
|
||||
import 'package:hiddify/core/model/failures.dart';
|
||||
import 'package:hiddify/core/theme/theme_extensions.dart';
|
||||
import 'package:hiddify/features/config_option/notifier/config_option_notifier.dart';
|
||||
import 'package:hiddify/features/connection/model/connection_status.dart';
|
||||
import 'package:hiddify/features/connection/notifier/connection_notifier.dart';
|
||||
import 'package:hiddify/features/connection/widget/experimental_feature_notice.dart';
|
||||
import 'package:hiddify/gen/assets.gen.dart';
|
||||
import 'package:hiddify/utils/alerts.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
@@ -42,8 +44,30 @@ class ConnectionButton extends HookConsumerWidget {
|
||||
: buttonTheme.idleColor!;
|
||||
|
||||
return _ConnectionButton(
|
||||
onTap: () =>
|
||||
ref.read(connectionNotifierProvider.notifier).toggleConnection(),
|
||||
onTap: () async {
|
||||
var canConnect = true;
|
||||
if (status case Disconnected()) {
|
||||
final hasExperimental =
|
||||
await ref.read(configOptionNotifierProvider.future).then(
|
||||
(value) => value.hasExperimentalOptions(),
|
||||
onError: (_) => false,
|
||||
);
|
||||
final canShowNotice =
|
||||
!ref.read(disableExperimentalFeatureNoticeProvider);
|
||||
|
||||
if (hasExperimental && canShowNotice && context.mounted) {
|
||||
canConnect = await const ExperimentalFeatureNoticeDialog()
|
||||
.show(context) ??
|
||||
true;
|
||||
}
|
||||
}
|
||||
|
||||
if (canConnect) {
|
||||
await ref
|
||||
.read(connectionNotifierProvider.notifier)
|
||||
.toggleConnection();
|
||||
}
|
||||
},
|
||||
enabled: !status.isSwitching,
|
||||
label: status.present(t),
|
||||
buttonColor: connectionLogoColor,
|
||||
|
||||
Reference in New Issue
Block a user