Add more config options to settings
This commit is contained in:
@@ -134,6 +134,7 @@
|
||||
"directDnsDomainStrategy": "Direct DNS Domain Strategy",
|
||||
"mixedPort": "Mixed Port",
|
||||
"localDnsPort": "Local DNS Port",
|
||||
"tunImplementation": "TUN Implementation",
|
||||
"mtu": "MTU",
|
||||
"connectionTestUrl": "Connection Test URL",
|
||||
"urlTestInterval": "URL Test Interval",
|
||||
|
||||
@@ -134,6 +134,7 @@
|
||||
"directDnsDomainStrategy": "Direct DNS Domain Strategy",
|
||||
"mixedPort": "Mixed Port",
|
||||
"localDnsPort": "Local DNS Port",
|
||||
"tunImplementation": "TUN Implementation",
|
||||
"mtu": "MTU",
|
||||
"connectionTestUrl": "Connection Test URL",
|
||||
"urlTestInterval": "URL Test Interval",
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:hiddify/domain/singbox/singbox.dart';
|
||||
import 'package:hiddify/features/settings/widgets/widgets.dart';
|
||||
import 'package:hiddify/utils/utils.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:humanizer/humanizer.dart';
|
||||
|
||||
class ConfigOptionsPage extends HookConsumerWidget {
|
||||
const ConfigOptionsPage({super.key});
|
||||
@@ -145,6 +146,23 @@ class ConfigOptionsPage extends HookConsumerWidget {
|
||||
onChanged: ref.read(setSystemProxyStore.notifier).update,
|
||||
),
|
||||
],
|
||||
ListTile(
|
||||
title: Text(t.settings.config.tunImplementation),
|
||||
subtitle: Text(options.tunImplementation.name),
|
||||
onTap: () async {
|
||||
final tunImplementation = await SettingsPickerDialog(
|
||||
title: t.settings.config.tunImplementation,
|
||||
selected: options.tunImplementation,
|
||||
options: TunImplementation.values,
|
||||
getTitle: (e) => e.name,
|
||||
resetValue: _default.tunImplementation,
|
||||
).show(context);
|
||||
if (tunImplementation == null) return;
|
||||
await ref
|
||||
.read(tunImplementationStore.notifier)
|
||||
.update(tunImplementation);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text(t.settings.config.mixedPort),
|
||||
subtitle: Text(options.mixedPort.toString()),
|
||||
@@ -192,6 +210,28 @@ class ConfigOptionsPage extends HookConsumerWidget {
|
||||
await ref.read(connectionTestUrlStore.notifier).update(url);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text(t.settings.config.urlTestInterval),
|
||||
subtitle: Text(
|
||||
options.urlTestInterval.toApproximateTime(isRelativeToNow: false),
|
||||
),
|
||||
onTap: () async {
|
||||
final urlTestInterval = await SettingsSliderDialog(
|
||||
title: t.settings.config.urlTestInterval,
|
||||
initialValue: options.urlTestInterval.inMinutes.toDouble(),
|
||||
resetValue: _default.urlTestInterval.inMinutes.toDouble(),
|
||||
min: 1,
|
||||
max: 60,
|
||||
divisions: 60,
|
||||
labelGen: (value) => Duration(minutes: value.toInt())
|
||||
.toApproximateTime(isRelativeToNow: false),
|
||||
).show(context);
|
||||
if (urlTestInterval == null) return;
|
||||
await ref
|
||||
.read(urlTestIntervalStore.notifier)
|
||||
.update(Duration(minutes: urlTestInterval.toInt()));
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text(t.settings.config.clashApiPort),
|
||||
subtitle: Text(options.clashApiPort.toString()),
|
||||
|
||||
@@ -149,3 +149,75 @@ class SettingsPickerDialog<T> extends HookConsumerWidget with PresLogger {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SettingsSliderDialog extends HookConsumerWidget with PresLogger {
|
||||
const SettingsSliderDialog({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.initialValue,
|
||||
this.resetValue,
|
||||
this.min = 0,
|
||||
this.max = 1,
|
||||
this.divisions,
|
||||
this.labelGen,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final double initialValue;
|
||||
final double? resetValue;
|
||||
final double min;
|
||||
final double max;
|
||||
final int? divisions;
|
||||
final String Function(double value)? labelGen;
|
||||
|
||||
Future<double?> show(BuildContext context) async {
|
||||
return showDialog(
|
||||
context: context,
|
||||
useRootNavigator: true,
|
||||
builder: (context) => this,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final t = ref.watch(translationsProvider);
|
||||
final localizations = MaterialLocalizations.of(context);
|
||||
|
||||
final sliderValue = useState(initialValue);
|
||||
|
||||
return AlertDialog(
|
||||
title: Text(title),
|
||||
content: IntrinsicHeight(
|
||||
child: Slider(
|
||||
value: sliderValue.value,
|
||||
min: min,
|
||||
max: max,
|
||||
divisions: divisions,
|
||||
onChanged: (value) => sliderValue.value = value,
|
||||
label: labelGen?.call(sliderValue.value),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
if (resetValue != null)
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await Navigator.of(context).maybePop(resetValue);
|
||||
},
|
||||
child: Text(t.general.reset.toUpperCase()),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await Navigator.of(context).maybePop();
|
||||
},
|
||||
child: Text(localizations.cancelButtonLabel.toUpperCase()),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await Navigator.of(context).maybePop(sliderValue.value);
|
||||
},
|
||||
child: Text(localizations.okButtonLabel.toUpperCase()),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user