From 909aa4038e2c6021690b69652c1c679bb12fdc38 Mon Sep 17 00:00:00 2001 From: chen08209 Date: Sat, 4 May 2024 00:14:07 +0800 Subject: [PATCH] Fix Proxies Select Error --- lib/clash/core.dart | 17 ++- lib/fragments/proxies.dart | 27 ++-- lib/models/generated/selector.freezed.dart | 145 +++++++++++++++++++++ lib/models/selector.dart | 7 + 4 files changed, 181 insertions(+), 15 deletions(-) diff --git a/lib/clash/core.dart b/lib/clash/core.dart index 823511f..b3b663a 100644 --- a/lib/clash/core.dart +++ b/lib/clash/core.dart @@ -74,14 +74,19 @@ class ClashCore { final proxiesRawString = proxiesRaw.cast().toDartString(); return Isolate.run>(() { final proxies = json.decode(proxiesRawString); - final groupNames = - (proxies[UsedProxy.GLOBAL.name]["all"] as List).where((e) { - final proxy = proxies[e]; - return GroupTypeExtension.valueList.contains(proxy['type']); - }); - final groupsRaw = [UsedProxy.GLOBAL.name, ...groupNames].map((groupName) { + final groupNames = [ + UsedProxy.GLOBAL.name, + ...(proxies[UsedProxy.GLOBAL.name]["all"] as List).where((e) { + final proxy = proxies[e]; + return GroupTypeExtension.valueList.contains(proxy['type']); + }) + ]; + final groupsRaw = groupNames.map((groupName) { final group = proxies[groupName]; group["all"] = ((group["all"] ?? []) as List) + .where( + (name) => !groupNames.contains(groupNames), + ) .map( (name) => proxies[name], ) diff --git a/lib/fragments/proxies.dart b/lib/fragments/proxies.dart index e594a19..0f47d80 100644 --- a/lib/fragments/proxies.dart +++ b/lib/fragments/proxies.dart @@ -194,7 +194,7 @@ class _ProxiesTabViewState extends State _controller.dispose(); } - get group => widget.group; + Group get group => widget.group; get measure => context.appController.measure; @@ -374,17 +374,26 @@ class _ProxiesTabViewState extends State return ObjectKey(item); }, builder: (_, proxy) { - return Selector3( + return Selector3( selector: (_, appState, config, clashConfig) => - appState.getCurrentProxyName( - config.currentProxyName, - clashConfig.mode, + ProxiesCardSelectorState( + currentGroupName: appState.getCurrentGroupName( + config.currentGroupName, + clashConfig.mode, + ), + currentProxyName: appState.getCurrentProxyName( + config.currentProxyName, + clashConfig.mode, + ), ), - builder: (_, value, __) { - final currentProxyName = - group.type == GroupType.Selector ? value : group.now; + builder: (_, state, __) { + final isSelected = group.type == GroupType.Selector + ? group.name == state.currentGroupName && + proxy.name == state.currentProxyName + : group.now == state.currentProxyName; return _card( - isSelected: proxy.name == currentProxyName, + isSelected: isSelected, onPressed: () { if (group.type == GroupType.Selector) { final config = context.read(); diff --git a/lib/models/generated/selector.freezed.dart b/lib/models/generated/selector.freezed.dart index 7399578..2de2b4f 100644 --- a/lib/models/generated/selector.freezed.dart +++ b/lib/models/generated/selector.freezed.dart @@ -1887,3 +1887,148 @@ abstract class _ProxiesSelectorState implements ProxiesSelectorState { _$$ProxiesSelectorStateImplCopyWith<_$ProxiesSelectorStateImpl> get copyWith => throw _privateConstructorUsedError; } + +/// @nodoc +mixin _$ProxiesCardSelectorState { + String? get currentGroupName => throw _privateConstructorUsedError; + String? get currentProxyName => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $ProxiesCardSelectorStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ProxiesCardSelectorStateCopyWith<$Res> { + factory $ProxiesCardSelectorStateCopyWith(ProxiesCardSelectorState value, + $Res Function(ProxiesCardSelectorState) then) = + _$ProxiesCardSelectorStateCopyWithImpl<$Res, ProxiesCardSelectorState>; + @useResult + $Res call({String? currentGroupName, String? currentProxyName}); +} + +/// @nodoc +class _$ProxiesCardSelectorStateCopyWithImpl<$Res, + $Val extends ProxiesCardSelectorState> + implements $ProxiesCardSelectorStateCopyWith<$Res> { + _$ProxiesCardSelectorStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? currentGroupName = freezed, + Object? currentProxyName = freezed, + }) { + return _then(_value.copyWith( + currentGroupName: freezed == currentGroupName + ? _value.currentGroupName + : currentGroupName // ignore: cast_nullable_to_non_nullable + as String?, + currentProxyName: freezed == currentProxyName + ? _value.currentProxyName + : currentProxyName // ignore: cast_nullable_to_non_nullable + as String?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$ProxiesCardSelectorStateImplCopyWith<$Res> + implements $ProxiesCardSelectorStateCopyWith<$Res> { + factory _$$ProxiesCardSelectorStateImplCopyWith( + _$ProxiesCardSelectorStateImpl value, + $Res Function(_$ProxiesCardSelectorStateImpl) then) = + __$$ProxiesCardSelectorStateImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({String? currentGroupName, String? currentProxyName}); +} + +/// @nodoc +class __$$ProxiesCardSelectorStateImplCopyWithImpl<$Res> + extends _$ProxiesCardSelectorStateCopyWithImpl<$Res, + _$ProxiesCardSelectorStateImpl> + implements _$$ProxiesCardSelectorStateImplCopyWith<$Res> { + __$$ProxiesCardSelectorStateImplCopyWithImpl( + _$ProxiesCardSelectorStateImpl _value, + $Res Function(_$ProxiesCardSelectorStateImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? currentGroupName = freezed, + Object? currentProxyName = freezed, + }) { + return _then(_$ProxiesCardSelectorStateImpl( + currentGroupName: freezed == currentGroupName + ? _value.currentGroupName + : currentGroupName // ignore: cast_nullable_to_non_nullable + as String?, + currentProxyName: freezed == currentProxyName + ? _value.currentProxyName + : currentProxyName // ignore: cast_nullable_to_non_nullable + as String?, + )); + } +} + +/// @nodoc + +class _$ProxiesCardSelectorStateImpl implements _ProxiesCardSelectorState { + const _$ProxiesCardSelectorStateImpl( + {required this.currentGroupName, required this.currentProxyName}); + + @override + final String? currentGroupName; + @override + final String? currentProxyName; + + @override + String toString() { + return 'ProxiesCardSelectorState(currentGroupName: $currentGroupName, currentProxyName: $currentProxyName)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$ProxiesCardSelectorStateImpl && + (identical(other.currentGroupName, currentGroupName) || + other.currentGroupName == currentGroupName) && + (identical(other.currentProxyName, currentProxyName) || + other.currentProxyName == currentProxyName)); + } + + @override + int get hashCode => + Object.hash(runtimeType, currentGroupName, currentProxyName); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$ProxiesCardSelectorStateImplCopyWith<_$ProxiesCardSelectorStateImpl> + get copyWith => __$$ProxiesCardSelectorStateImplCopyWithImpl< + _$ProxiesCardSelectorStateImpl>(this, _$identity); +} + +abstract class _ProxiesCardSelectorState implements ProxiesCardSelectorState { + const factory _ProxiesCardSelectorState( + {required final String? currentGroupName, + required final String? currentProxyName}) = + _$ProxiesCardSelectorStateImpl; + + @override + String? get currentGroupName; + @override + String? get currentProxyName; + @override + @JsonKey(ignore: true) + _$$ProxiesCardSelectorStateImplCopyWith<_$ProxiesCardSelectorStateImpl> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/models/selector.dart b/lib/models/selector.dart index 3486260..b85ee7a 100644 --- a/lib/models/selector.dart +++ b/lib/models/selector.dart @@ -111,3 +111,10 @@ class ProxiesSelectorState with _$ProxiesSelectorState{ }) = _ProxiesSelectorState; } +@freezed +class ProxiesCardSelectorState with _$ProxiesCardSelectorState{ + const factory ProxiesCardSelectorState({ + required String? currentGroupName, + required String? currentProxyName, + }) = _ProxiesCardSelectorState; +}