Change proxies page
This commit is contained in:
@@ -25,6 +25,7 @@ class GroupWithProxies with _$GroupWithProxies {
|
|||||||
for (final proxy in proxies) {
|
for (final proxy in proxies) {
|
||||||
if (proxy is ClashProxyGroup) {
|
if (proxy is ClashProxyGroup) {
|
||||||
// if (mode != TunnelMode.global && proxy.name == "GLOBAL") continue;
|
// if (mode != TunnelMode.global && proxy.name == "GLOBAL") continue;
|
||||||
|
if (proxy.name == "GLOBAL") continue;
|
||||||
final current = <ClashProxy>[];
|
final current = <ClashProxy>[];
|
||||||
for (final name in proxy.all) {
|
for (final name in proxy.all) {
|
||||||
current.addAll(proxies.where((e) => e.name == name).toList());
|
current.addAll(proxies.where((e) => e.name == name).toList());
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
||||||
import 'package:hiddify/core/core_providers.dart';
|
import 'package:hiddify/core/core_providers.dart';
|
||||||
import 'package:hiddify/domain/failures.dart';
|
import 'package:hiddify/domain/failures.dart';
|
||||||
import 'package:hiddify/features/common/common.dart';
|
import 'package:hiddify/features/common/common.dart';
|
||||||
@@ -10,7 +9,6 @@ import 'package:hiddify/utils/utils.dart';
|
|||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:recase/recase.dart';
|
import 'package:recase/recase.dart';
|
||||||
|
|
||||||
// TODO: rewrite, bugs with scroll
|
|
||||||
class ProxiesPage extends HookConsumerWidget with PresLogger {
|
class ProxiesPage extends HookConsumerWidget with PresLogger {
|
||||||
const ProxiesPage({super.key});
|
const ProxiesPage({super.key});
|
||||||
|
|
||||||
@@ -18,9 +16,8 @@ class ProxiesPage extends HookConsumerWidget with PresLogger {
|
|||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final t = ref.watch(translationsProvider);
|
final t = ref.watch(translationsProvider);
|
||||||
|
|
||||||
final notifier = ref.watch(proxiesNotifierProvider.notifier);
|
|
||||||
final asyncProxies = ref.watch(proxiesNotifierProvider);
|
final asyncProxies = ref.watch(proxiesNotifierProvider);
|
||||||
final proxies = asyncProxies.asData?.value ?? [];
|
final notifier = ref.watch(proxiesNotifierProvider.notifier);
|
||||||
final delays = ref.watch(proxiesDelayNotifierProvider);
|
final delays = ref.watch(proxiesDelayNotifierProvider);
|
||||||
|
|
||||||
final selectActiveProxyMutation = useMutation(
|
final selectActiveProxyMutation = useMutation(
|
||||||
@@ -28,14 +25,9 @@ class ProxiesPage extends HookConsumerWidget with PresLogger {
|
|||||||
CustomToast.error(t.presentError(error)).show(context),
|
CustomToast.error(t.presentError(error)).show(context),
|
||||||
);
|
);
|
||||||
|
|
||||||
final tabController = useTabController(
|
|
||||||
initialLength: proxies.length,
|
|
||||||
keys: [proxies.length],
|
|
||||||
);
|
|
||||||
|
|
||||||
switch (asyncProxies) {
|
switch (asyncProxies) {
|
||||||
case AsyncData(value: final proxies):
|
case AsyncData(value: final groups):
|
||||||
if (proxies.isEmpty) {
|
if (groups.isEmpty) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: CustomScrollView(
|
body: CustomScrollView(
|
||||||
slivers: [
|
slivers: [
|
||||||
@@ -55,101 +47,93 @@ class ProxiesPage extends HookConsumerWidget with PresLogger {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final tabs = [
|
final select = groups.first;
|
||||||
for (final groupWithProxies in proxies)
|
|
||||||
Tab(
|
|
||||||
child: Text(
|
|
||||||
groupWithProxies.group.name.toUpperCase(),
|
|
||||||
style: TextStyle(
|
|
||||||
color: Theme.of(context).appBarTheme.foregroundColor,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
];
|
|
||||||
|
|
||||||
final tabViews = [
|
return Scaffold(
|
||||||
for (final groupWithProxies in proxies)
|
body: CustomScrollView(
|
||||||
SafeArea(
|
slivers: [
|
||||||
top: false,
|
NestedTabAppBar(
|
||||||
bottom: false,
|
title: Text(t.proxies.pageTitle.titleCase),
|
||||||
child: Builder(
|
actions: [
|
||||||
builder: (BuildContext context) {
|
PopupMenuButton(
|
||||||
return CustomScrollView(
|
itemBuilder: (_) {
|
||||||
key: PageStorageKey<String>(
|
return [
|
||||||
groupWithProxies.group.name,
|
PopupMenuItem(
|
||||||
|
onTap: ref
|
||||||
|
.read(proxiesDelayNotifierProvider.notifier)
|
||||||
|
.cancelDelayTest,
|
||||||
|
child: Text(
|
||||||
|
t.proxies.cancelTestButtonText.sentenceCase,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SliverLayoutBuilder(
|
||||||
|
builder: (context, constraints) {
|
||||||
|
final width = constraints.crossAxisExtent;
|
||||||
|
if (!PlatformUtils.isDesktop && width < 648) {
|
||||||
|
return SliverList.builder(
|
||||||
|
itemBuilder: (_, index) {
|
||||||
|
final proxy = select.proxies[index];
|
||||||
|
return ProxyTile(
|
||||||
|
proxy,
|
||||||
|
selected: select.group.now == proxy.name,
|
||||||
|
delay: delays[proxy.name],
|
||||||
|
onSelect: () async {
|
||||||
|
if (selectActiveProxyMutation.state.isInProgress) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
selectActiveProxyMutation.setFuture(
|
||||||
|
notifier.changeProxy(
|
||||||
|
select.group.name,
|
||||||
|
proxy.name,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
itemCount: select.proxies.length,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return SliverGrid.builder(
|
||||||
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
|
crossAxisCount: (width / 268).floor(),
|
||||||
|
mainAxisExtent: 68,
|
||||||
),
|
),
|
||||||
slivers: <Widget>[
|
itemBuilder: (context, index) {
|
||||||
SliverList.builder(
|
final proxy = select.proxies[index];
|
||||||
itemBuilder: (_, index) {
|
return ProxyTile(
|
||||||
final proxy = groupWithProxies.proxies[index];
|
proxy,
|
||||||
return ProxyTile(
|
selected: select.group.now == proxy.name,
|
||||||
proxy,
|
delay: delays[proxy.name],
|
||||||
selected: groupWithProxies.group.now == proxy.name,
|
onSelect: () async {
|
||||||
delay: delays[proxy.name],
|
if (selectActiveProxyMutation.state.isInProgress) {
|
||||||
onSelect: () async {
|
return;
|
||||||
if (selectActiveProxyMutation
|
}
|
||||||
.state.isInProgress) {
|
selectActiveProxyMutation.setFuture(
|
||||||
return;
|
notifier.changeProxy(
|
||||||
}
|
select.group.name,
|
||||||
selectActiveProxyMutation.setFuture(
|
proxy.name,
|
||||||
notifier.changeProxy(
|
),
|
||||||
groupWithProxies.group.name,
|
|
||||||
proxy.name,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
itemCount: groupWithProxies.proxies.length,
|
);
|
||||||
),
|
},
|
||||||
],
|
itemCount: select.proxies.length,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
];
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
body: NestedScrollView(
|
|
||||||
headerSliverBuilder: (context, innerBoxIsScrolled) {
|
|
||||||
return <Widget>[
|
|
||||||
NestedTabAppBar(
|
|
||||||
title: Text(t.proxies.pageTitle.titleCase),
|
|
||||||
forceElevated: innerBoxIsScrolled,
|
|
||||||
actions: [
|
|
||||||
PopupMenuButton(
|
|
||||||
itemBuilder: (_) {
|
|
||||||
return [
|
|
||||||
PopupMenuItem(
|
|
||||||
onTap: ref
|
|
||||||
.read(proxiesDelayNotifierProvider.notifier)
|
|
||||||
.cancelDelayTest,
|
|
||||||
child: Text(
|
|
||||||
t.proxies.cancelTestButtonText.sentenceCase,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
];
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
bottom: TabBar(
|
|
||||||
controller: tabController,
|
|
||||||
isScrollable: true,
|
|
||||||
tabs: tabs,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
];
|
|
||||||
},
|
|
||||||
body: TabBarView(
|
|
||||||
controller: tabController,
|
|
||||||
children: tabViews,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
onPressed: () async =>
|
onPressed: () async =>
|
||||||
// TODO: improve
|
// TODO: improve
|
||||||
ref.read(proxiesDelayNotifierProvider.notifier).testDelay(
|
ref.read(proxiesDelayNotifierProvider.notifier).testDelay(
|
||||||
proxies[tabController.index].proxies.map((e) => e.name),
|
select.proxies.map((e) => e.name),
|
||||||
),
|
),
|
||||||
tooltip: t.proxies.delayTestTooltip.titleCase,
|
tooltip: t.proxies.delayTestTooltip.titleCase,
|
||||||
child: const Icon(Icons.bolt),
|
child: const Icon(Icons.bolt),
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:hiddify/domain/clash/clash.dart';
|
import 'package:hiddify/domain/clash/clash.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
|
||||||
// TODO: rewrite
|
|
||||||
class ProxyTile extends HookConsumerWidget {
|
class ProxyTile extends HookConsumerWidget {
|
||||||
const ProxyTile(
|
const ProxyTile(
|
||||||
this.proxy, {
|
this.proxy, {
|
||||||
@@ -22,6 +21,7 @@ class ProxyTile extends HookConsumerWidget {
|
|||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||||
title: Text(
|
title: Text(
|
||||||
switch (proxy) {
|
switch (proxy) {
|
||||||
ClashProxyGroup(:final name) => name.toUpperCase(),
|
ClashProxyGroup(:final name) => name.toUpperCase(),
|
||||||
@@ -44,31 +44,32 @@ class ProxyTile extends HookConsumerWidget {
|
|||||||
TextSpan(
|
TextSpan(
|
||||||
children: [
|
children: [
|
||||||
TextSpan(text: proxy.type.label),
|
TextSpan(text: proxy.type.label),
|
||||||
if (proxy.udp)
|
// if (proxy.udp)
|
||||||
WidgetSpan(
|
// WidgetSpan(
|
||||||
child: Padding(
|
// child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
// padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||||
child: DecoratedBox(
|
// child: DecoratedBox(
|
||||||
decoration: BoxDecoration(
|
// decoration: BoxDecoration(
|
||||||
border: Border.all(
|
// border: Border.all(
|
||||||
color: theme.colorScheme.tertiaryContainer,
|
// color: theme.colorScheme.tertiaryContainer,
|
||||||
),
|
// ),
|
||||||
borderRadius: BorderRadius.circular(6),
|
// borderRadius: BorderRadius.circular(6),
|
||||||
),
|
// ),
|
||||||
child: Text(
|
// child: Text(
|
||||||
" UDP ",
|
// " UDP ",
|
||||||
style: TextStyle(
|
// style: TextStyle(
|
||||||
fontSize: theme.textTheme.labelSmall?.fontSize,
|
// fontSize: theme.textTheme.labelSmall?.fontSize,
|
||||||
),
|
// ),
|
||||||
),
|
// ),
|
||||||
),
|
// ),
|
||||||
),
|
// ),
|
||||||
),
|
// ),
|
||||||
if (proxy case ClashProxyGroup(:final now)) ...[
|
if (proxy case ClashProxyGroup(:final now)) ...[
|
||||||
TextSpan(text: " ($now)"),
|
TextSpan(text: " ($now)"),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
trailing: delay != null ? Text(delay.toString()) : null,
|
trailing: delay != null ? Text(delay.toString()) : null,
|
||||||
selected: selected,
|
selected: selected,
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ class MiscellaneousSettingTiles extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(t.settings.miscellaneous.concurrentTestCount.titleCase),
|
title: Text(t.settings.miscellaneous.concurrentTestCount.titleCase),
|
||||||
subtitle: Text(concurrentTestCount.toString()),
|
trailing: Text(concurrentTestCount.toString()),
|
||||||
|
leadingAndTrailingTextStyle: Theme.of(context).textTheme.bodyMedium,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
final val = await SettingsInputDialog<int>(
|
final val = await SettingsInputDialog<int>(
|
||||||
title: t.settings.miscellaneous.concurrentTestCount.titleCase,
|
title: t.settings.miscellaneous.concurrentTestCount.titleCase,
|
||||||
|
|||||||
Reference in New Issue
Block a user