From f9545df30873f4fd303a3eb428def1486603a656 Mon Sep 17 00:00:00 2001 From: problematicconsumer Date: Wed, 26 Jul 2023 23:35:51 +0330 Subject: [PATCH] Add separate page for clash overrides --- lib/core/router/routes/desktop_routes.dart | 7 +- lib/core/router/routes/mobile_routes.dart | 7 +- lib/core/router/routes/shared_routes.dart | 14 +++ .../settings/view/clash_overrides_page.dart | 103 ++++++++++++++++++ lib/features/settings/view/settings_page.dart | 11 +- lib/features/settings/view/view.dart | 1 + ...setting_tiles.dart => override_tiles.dart} | 88 --------------- lib/features/settings/widgets/widgets.dart | 2 +- 8 files changed, 140 insertions(+), 93 deletions(-) create mode 100644 lib/features/settings/view/clash_overrides_page.dart rename lib/features/settings/widgets/{clash_setting_tiles.dart => override_tiles.dart} (57%) diff --git a/lib/core/router/routes/desktop_routes.dart b/lib/core/router/routes/desktop_routes.dart index 302a8403..880804ab 100644 --- a/lib/core/router/routes/desktop_routes.dart +++ b/lib/core/router/routes/desktop_routes.dart @@ -20,7 +20,12 @@ part 'desktop_routes.g.dart'; ), TypedGoRoute(path: ProxiesRoute.path), TypedGoRoute(path: LogsRoute.path), - TypedGoRoute(path: SettingsRoute.path), + TypedGoRoute( + path: SettingsRoute.path, + routes: [ + TypedGoRoute(path: ClashOverridesRoute.path), + ], + ), TypedGoRoute(path: AboutRoute.path), ], ) diff --git a/lib/core/router/routes/mobile_routes.dart b/lib/core/router/routes/mobile_routes.dart index a0bd977b..41bf4760 100644 --- a/lib/core/router/routes/mobile_routes.dart +++ b/lib/core/router/routes/mobile_routes.dart @@ -46,7 +46,12 @@ class LogsRoute extends GoRouteData { } } -@TypedGoRoute(path: SettingsRoute.path) +@TypedGoRoute( + path: SettingsRoute.path, + routes: [ + TypedGoRoute(path: ClashOverridesRoute.path), + ], +) class SettingsRoute extends GoRouteData { const SettingsRoute(); static const path = '/settings'; diff --git a/lib/core/router/routes/shared_routes.dart b/lib/core/router/routes/shared_routes.dart index 12c07e4b..300046b9 100644 --- a/lib/core/router/routes/shared_routes.dart +++ b/lib/core/router/routes/shared_routes.dart @@ -4,6 +4,7 @@ import 'package:hiddify/features/home/view/view.dart'; import 'package:hiddify/features/profile_detail/view/view.dart'; import 'package:hiddify/features/profiles/view/view.dart'; import 'package:hiddify/features/proxies/view/view.dart'; +import 'package:hiddify/features/settings/view/view.dart'; import 'package:hiddify/utils/utils.dart'; part 'shared_routes.g.dart'; @@ -102,3 +103,16 @@ class ProfileDetailsRoute extends GoRouteData { ); } } + +class ClashOverridesRoute extends GoRouteData { + const ClashOverridesRoute(); + static const path = 'clash-overrides'; + + @override + Page buildPage(BuildContext context, GoRouterState state) { + return const MaterialPage( + fullscreenDialog: true, + child: ClashOverridesPage(), + ); + } +} diff --git a/lib/features/settings/view/clash_overrides_page.dart b/lib/features/settings/view/clash_overrides_page.dart new file mode 100644 index 00000000..7280ebf5 --- /dev/null +++ b/lib/features/settings/view/clash_overrides_page.dart @@ -0,0 +1,103 @@ +import 'package:flutter/material.dart'; +import 'package:hiddify/core/core_providers.dart'; +import 'package:hiddify/core/prefs/prefs.dart'; +import 'package:hiddify/domain/clash/clash.dart'; +import 'package:hiddify/features/settings/widgets/widgets.dart'; +import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:recase/recase.dart'; + +class ClashOverridesPage extends HookConsumerWidget { + const ClashOverridesPage({super.key}); + + @override + Widget build(BuildContext context, WidgetRef ref) { + final t = ref.watch(translationsProvider); + + final overrides = + ref.watch(prefsControllerProvider.select((value) => value.clash)); + final notifier = ref.watch(prefsControllerProvider.notifier); + + return Scaffold( + body: CustomScrollView( + slivers: [ + SliverAppBar( + title: Text(t.settings.clash.sectionTitle.titleCase), + pinned: true, + ), + SliverList.list( + children: [ + InputOverrideTile( + title: t.settings.clash.overrides.httpPort, + value: overrides.httpPort, + resetValue: ClashConfig.initial.httpPort, + onChange: (value) => notifier.patchClashOverrides( + ClashConfigPatch(httpPort: value), + ), + ), + InputOverrideTile( + title: t.settings.clash.overrides.socksPort, + value: overrides.socksPort, + resetValue: ClashConfig.initial.socksPort, + onChange: (value) => notifier.patchClashOverrides( + ClashConfigPatch(socksPort: value), + ), + ), + InputOverrideTile( + title: t.settings.clash.overrides.redirPort, + value: overrides.redirPort, + onChange: (value) => notifier.patchClashOverrides( + ClashConfigPatch(redirPort: value), + ), + ), + InputOverrideTile( + title: t.settings.clash.overrides.tproxyPort, + value: overrides.tproxyPort, + onChange: (value) => notifier.patchClashOverrides( + ClashConfigPatch(tproxyPort: value), + ), + ), + InputOverrideTile( + title: t.settings.clash.overrides.mixedPort, + value: overrides.mixedPort, + resetValue: ClashConfig.initial.mixedPort, + onChange: (value) => notifier.patchClashOverrides( + ClashConfigPatch(mixedPort: value), + ), + ), + ToggleOverrideTile( + title: t.settings.clash.overrides.allowLan, + value: overrides.allowLan, + onChange: (value) => notifier.patchClashOverrides( + ClashConfigPatch(allowLan: value), + ), + ), + ToggleOverrideTile( + title: t.settings.clash.overrides.ipv6, + value: overrides.ipv6, + onChange: (value) => notifier.patchClashOverrides( + ClashConfigPatch(ipv6: value), + ), + ), + ChoiceOverrideTile( + title: t.settings.clash.overrides.mode, + value: overrides.mode, + options: TunnelMode.values, + onChange: (value) => notifier.patchClashOverrides( + ClashConfigPatch(mode: value), + ), + ), + ChoiceOverrideTile( + title: t.settings.clash.overrides.logLevel, + value: overrides.logLevel, + options: LogLevel.values, + onChange: (value) => notifier.patchClashOverrides( + ClashConfigPatch(logLevel: value), + ), + ), + ], + ), + ], + ), + ); + } +} diff --git a/lib/features/settings/view/settings_page.dart b/lib/features/settings/view/settings_page.dart index bbac71cf..d3ece07e 100644 --- a/lib/features/settings/view/settings_page.dart +++ b/lib/features/settings/view/settings_page.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:gap/gap.dart'; import 'package:hiddify/core/core_providers.dart'; +import 'package:hiddify/core/router/router.dart'; import 'package:hiddify/features/settings/widgets/widgets.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:recase/recase.dart'; @@ -32,8 +33,14 @@ class SettingsPage extends HookConsumerWidget { _SettingsSectionHeader(t.settings.network.sectionTitle.titleCase), const NetworkSettingTiles(), divider, - _SettingsSectionHeader(t.settings.clash.sectionTitle.titleCase), - const ClashSettingTiles(), + ListTile( + title: Text(t.settings.clash.sectionTitle.titleCase), + leading: const Icon(Icons.edit_document), + contentPadding: const EdgeInsets.symmetric(horizontal: 16), + onTap: () async { + await const ClashOverridesRoute().push(context); + }, + ), const Gap(16), ], ), diff --git a/lib/features/settings/view/view.dart b/lib/features/settings/view/view.dart index 10ba3ace..8d3cfc42 100644 --- a/lib/features/settings/view/view.dart +++ b/lib/features/settings/view/view.dart @@ -1 +1,2 @@ +export 'clash_overrides_page.dart'; export 'settings_page.dart'; diff --git a/lib/features/settings/widgets/clash_setting_tiles.dart b/lib/features/settings/widgets/override_tiles.dart similarity index 57% rename from lib/features/settings/widgets/clash_setting_tiles.dart rename to lib/features/settings/widgets/override_tiles.dart index 383edd86..7d3627a0 100644 --- a/lib/features/settings/widgets/clash_setting_tiles.dart +++ b/lib/features/settings/widgets/override_tiles.dart @@ -1,98 +1,10 @@ import 'package:flutter/material.dart'; import 'package:fpdart/fpdart.dart'; import 'package:hiddify/core/core_providers.dart'; -import 'package:hiddify/core/prefs/prefs.dart'; -import 'package:hiddify/domain/clash/clash.dart'; import 'package:hiddify/features/settings/widgets/settings_input_dialog.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:recase/recase.dart'; -class ClashSettingTiles extends HookConsumerWidget { - const ClashSettingTiles({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final t = ref.watch(translationsProvider); - - final overrides = - ref.watch(prefsControllerProvider.select((value) => value.clash)); - final notifier = ref.watch(prefsControllerProvider.notifier); - - return Column( - children: [ - InputOverrideTile( - title: t.settings.clash.overrides.httpPort, - value: overrides.httpPort, - resetValue: ClashConfig.initial.httpPort, - onChange: (value) => notifier.patchClashOverrides( - ClashConfigPatch(httpPort: value), - ), - ), - InputOverrideTile( - title: t.settings.clash.overrides.socksPort, - value: overrides.socksPort, - resetValue: ClashConfig.initial.socksPort, - onChange: (value) => notifier.patchClashOverrides( - ClashConfigPatch(socksPort: value), - ), - ), - InputOverrideTile( - title: t.settings.clash.overrides.redirPort, - value: overrides.redirPort, - onChange: (value) => notifier.patchClashOverrides( - ClashConfigPatch(redirPort: value), - ), - ), - InputOverrideTile( - title: t.settings.clash.overrides.tproxyPort, - value: overrides.tproxyPort, - onChange: (value) => notifier.patchClashOverrides( - ClashConfigPatch(tproxyPort: value), - ), - ), - InputOverrideTile( - title: t.settings.clash.overrides.mixedPort, - value: overrides.mixedPort, - resetValue: ClashConfig.initial.mixedPort, - onChange: (value) => notifier.patchClashOverrides( - ClashConfigPatch(mixedPort: value), - ), - ), - ToggleOverrideTile( - title: t.settings.clash.overrides.allowLan, - value: overrides.allowLan, - onChange: (value) => notifier.patchClashOverrides( - ClashConfigPatch(allowLan: value), - ), - ), - ToggleOverrideTile( - title: t.settings.clash.overrides.ipv6, - value: overrides.ipv6, - onChange: (value) => notifier.patchClashOverrides( - ClashConfigPatch(ipv6: value), - ), - ), - ChoiceOverrideTile( - title: t.settings.clash.overrides.mode, - value: overrides.mode, - options: TunnelMode.values, - onChange: (value) => notifier.patchClashOverrides( - ClashConfigPatch(mode: value), - ), - ), - ChoiceOverrideTile( - title: t.settings.clash.overrides.logLevel, - value: overrides.logLevel, - options: LogLevel.values, - onChange: (value) => notifier.patchClashOverrides( - ClashConfigPatch(logLevel: value), - ), - ), - ], - ); - } -} - class InputOverrideTile extends HookConsumerWidget { const InputOverrideTile({ super.key, diff --git a/lib/features/settings/widgets/widgets.dart b/lib/features/settings/widgets/widgets.dart index 4dcd11bc..9a6bad09 100644 --- a/lib/features/settings/widgets/widgets.dart +++ b/lib/features/settings/widgets/widgets.dart @@ -1,3 +1,3 @@ -export 'clash_setting_tiles.dart'; export 'general_setting_tiles.dart'; export 'network_setting_tiles.dart'; +export 'override_tiles.dart';