Compare commits

...

16 Commits

Author SHA1 Message Date
chen08209
fc0767ed25 Update Selector 2 2024-05-04 01:14:56 +08:00
chen08209
dbf1724cca Update Version 2024-05-04 00:14:34 +08:00
chen08209
909aa4038e Fix Proxies Select Error 2024-05-04 00:14:07 +08:00
chen08209
2d0a7d8d46 Fix the problem that the proxy group is empty in global mode. 2024-05-03 23:08:06 +08:00
chen08209
ca96cd1d82 Fix the problem that the proxy group is empty in global mode. 2024-05-03 23:07:38 +08:00
chen08209
91ab1e5dac Add ProxyProvider2 2024-05-03 21:48:22 +08:00
chen08209
b3a5f74df8 Add ProxyProvider 2024-05-03 21:28:22 +08:00
chen08209
1f98be8ad8 Update Version 2024-05-03 15:33:46 +08:00
chen08209
453c7c98d0 Update ProxyGroup Sort 2024-05-03 15:33:45 +08:00
chen08209
91faed35c0 Fix Android quickStart VpnService some problems 2024-05-02 00:32:11 +08:00
chen08209
07bbaf6b6f Update version 2024-05-01 23:40:04 +08:00
chen08209
e8feb7c431 Set Android notification low importance 2024-05-01 23:40:03 +08:00
chen08209
4d16820526 Fix the issue that VpnService can't be closed correctly in special cases 2024-05-01 23:40:00 +08:00
chen08209
92294b49c6 Fix the problem that TileService is not destroyed correctly in some cases
Adjust tab animation defaults
2024-05-01 23:39:59 +08:00
chen08209
8a188a37c9 Add Telegram in README_zh_CN.md 2024-05-01 21:52:07 +08:00
chen08209
48af16c265 Add Telegram 2024-05-01 21:50:26 +08:00
19 changed files with 483 additions and 142 deletions

View File

@@ -107,7 +107,7 @@ jobs:
else
current="${{ github.ref_name }}"
echo -e "\n\n<details markdown=1><summary>All changes from $current to the latest commit:</summary>\n\n" >> release.md
gitchangelog "${prelease}.." >> release.md 2>&1 || echo "Error in gitchangelog"
gitchangelog "${prelease}" >> release.md 2>&1 || echo "Error in gitchangelog"
echo -e "\n\n</details>" >> release.md
fi
- name: Release

View File

@@ -10,12 +10,12 @@ A multi-platform proxy client based on ClashMeta, simple and easy to use, open-s
on Desktop:
<p style="text-align: center;">
<img src="snapshots/desktop.gif">
<img alt="desktop" src="snapshots/desktop.gif">
</p>
on Mobile:
<p style="text-align: center;">
<img src="snapshots/mobile.gif">
<img alt="mobile" src="snapshots/mobile.gif">
</p>
## Features
@@ -28,6 +28,10 @@ on Mobile:
✨ Support subscription link, Dark mode
## Contact
[Telegram](https://t.me/+G-veVtwBOl4wODc1)
## Build
1. Update submodules
@@ -82,3 +86,6 @@ on Mobile:
```bash
dart .\setup.dart
```

View File

@@ -10,12 +10,12 @@
on Desktop:
<p style="text-align: center;">
<img src="snapshots/desktop.gif">
<img alt="desktop" src="snapshots/desktop.gif">
</p>
on Mobile:
<p style="text-align: center;">
<img src="snapshots/mobile.gif">
<img alt="mobile" src="snapshots/mobile.gif">
</p>
## Features
@@ -28,6 +28,10 @@ on Mobile:
✨ 支持一键导入订阅, 深色模式
## Contact
[Telegram](https://t.me/+G-veVtwBOl4wODc1)
## Build
1. 更新 submodules

View File

@@ -10,6 +10,7 @@ import io.flutter.embedding.engine.FlutterEngine
class MainActivity : FlutterActivity() {
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
GlobalState.flutterEngine?.destroy()
super.configureFlutterEngine(flutterEngine)
flutterEngine.plugins.add(AppPlugin())
flutterEngine.plugins.add(ProxyPlugin())

View File

@@ -37,14 +37,12 @@ class FlClashTileService : TileService() {
}
}
override fun onStartListening() {
super.onStartListening()
GlobalState.runState.value?.let { updateTile(it) }
GlobalState.runState.observeForever(observer)
}
@SuppressLint("StartActivityAndCollapseDeprecated")
private fun activityTransfer() {
val intent = Intent(this, TempActivity::class.java)
@@ -88,7 +86,7 @@ class FlClashTileService : TileService() {
if(currentTilePlugin == null){
initFlutterEngine()
}else{
currentTilePlugin?.handleStart()
currentTilePlugin.handleStart()
}
} else if(GlobalState.runState.value == RunState.START){
GlobalState.runState.value = RunState.PENDING
@@ -97,7 +95,6 @@ class FlClashTileService : TileService() {
}
override fun onDestroy() {
GlobalState.runState.removeObserver(observer)
super.onDestroy()

View File

@@ -25,7 +25,8 @@ class FlClashVpnService : VpnService() {
private val CHANNEL = "FlClash"
var fd: Int? = null;
var fd: Int? = null
private val notificationId: Int = 1
private val passList = listOf(
"*zhihu.com",
@@ -100,11 +101,12 @@ class FlClashVpnService : VpnService() {
fun startForeground(title: String, content: String) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel =
NotificationChannel(CHANNEL, "FlClash", NotificationManager.IMPORTANCE_DEFAULT)
NotificationChannel(CHANNEL, "FlClash", NotificationManager.IMPORTANCE_LOW)
val manager = getSystemService(NotificationManager::class.java)
manager.createNotificationChannel(channel)
val intent = Intent(this, MainActivity::class.java)
val pendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PendingIntent.getActivity(
this,
@@ -120,7 +122,9 @@ class FlClashVpnService : VpnService() {
PendingIntent.FLAG_UPDATE_CURRENT
)
}
val icon = IconCompat.createWithResource(this, this.applicationInfo.icon)
val notification = with(NotificationCompat.Builder(this, CHANNEL)) {
setSmallIcon(icon)
setContentTitle(title)
@@ -132,12 +136,13 @@ class FlClashVpnService : VpnService() {
build()
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
startForeground(1, notification, FOREGROUND_SERVICE_TYPE_SPECIAL_USE)
startForeground(notificationId, notification, FOREGROUND_SERVICE_TYPE_SPECIAL_USE)
} else {
startForeground(1, notification)
startForeground(notificationId, notification)
}
}
}
private fun stopForeground() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
stopForeground(Service.STOP_FOREGROUND_REMOVE)

View File

@@ -21,7 +21,7 @@ import (
"unsafe"
)
var currentConfig *config.RawConfig
var currentConfig = config.DefaultRawConfig()
var isInit = false
@@ -82,7 +82,7 @@ func updateConfig(s *C.char) bool {
//export getProxies
func getProxies() *C.char {
data, err := json.Marshal(tunnel.Proxies())
data, err := json.Marshal(tunnel.ProxiesWithProviders())
if err != nil {
return C.CString("")
}
@@ -98,7 +98,7 @@ func changeProxy(s *C.char) bool {
log.Infoln("Unmarshal ChangeProxyParams %v", err)
return false
}
proxies := tunnel.Proxies()
proxies := tunnel.ProxiesWithProviders()
proxy := proxies[*params.GroupName]
if proxy == nil {
return false
@@ -148,7 +148,7 @@ func asyncTestDelay(s *C.char) {
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*time.Duration(params.Timeout))
defer cancel()
proxies := tunnel.Proxies()
proxies := tunnel.ProxiesWithProviders()
proxy := proxies[params.ProxyName]
delayData := &Delay{

View File

@@ -69,43 +69,32 @@ class ClashCore {
1;
}
List<Group> getProxiesGroups() {
Future<List<Group>> getProxiesGroups() {
final proxiesRaw = clashFFI.getProxies();
final proxies = json.decode(proxiesRaw.cast<Utf8>().toDartString());
final groupsRaw = List.from(proxies.values).where((e) {
final excludeName = !UsedProxyExtension.valueList
.where((element) => element != UsedProxy.GLOBAL.name)
.contains(e['name']);
final validType = GroupTypeExtension.valueList.contains(e['type']);
return excludeName && validType;
}).map(
(e) {
e["all"] = ((e["all"] ?? []) as List)
final proxiesRawString = proxiesRaw.cast<Utf8>().toDartString();
return Isolate.run<List<Group>>(() {
final proxies = json.decode(proxiesRawString);
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],
)
.toList();
return e;
},
).toList()
..sort(
(a, b) {
final aIndex = GroupTypeExtension.getGroupType(a['type'])?.index;
final bIndex = GroupTypeExtension.getGroupType(b['type'])?.index;
if (a == null && b == null) {
return 0;
}
if (a == null) {
return 1;
}
if (b == null) {
return -1;
}
return aIndex! - bIndex!;
},
);
final groups = groupsRaw.map((e) => Group.fromJson(e)).toList();
return groups;
return group;
}).toList();
return groupsRaw.map((e) => Group.fromJson(e)).toList();
});
}
bool changeProxy(ChangeProxyParams changeProxyParams) {

View File

@@ -71,28 +71,10 @@ class AppController {
}
changeProxy() {
final currentGroupName =
appState.getCurrentGroupName(config.currentGroupName, clashConfig.mode);
final currentProxyName =
appState.getCurrentProxyName(config.currentProxyName, clashConfig.mode);
if (config.profiles.isEmpty || currentProxyName == null) {
updateSystemProxy(false);
return;
}
if (currentGroupName == null) return;
final groupIndex = appState.groups.indexWhere(
(element) => element.name == currentGroupName,
);
if (groupIndex == -1) return;
final proxyIndex = appState.groups[groupIndex].all.indexWhere(
(element) => element.name == currentProxyName,
);
if (proxyIndex == -1) return;
clashCore.changeProxy(
ChangeProxyParams(
groupName: currentGroupName,
proxyName: currentProxyName,
),
globalState.changeProxy(
appState: appState,
config: config,
clashConfig: clashConfig,
);
}
@@ -145,7 +127,7 @@ class AppController {
if (value == config.currentProfileId) return;
config.currentProfileId = value;
await updateClashConfig(isPatch: false);
updateGroups();
await updateGroups();
changeProxy();
appState.delayMap = {};
saveConfigPreferences();
@@ -162,13 +144,13 @@ class AppController {
if (isNotNeedUpdate == false) continue;
final result = await profile.update();
if (result.type == ResultType.error) continue;
updateGroups();
await updateGroups();
changeProxy();
}
}
updateGroups() {
globalState.updateGroups(appState);
Future<void> updateGroups() async {
await globalState.updateGroups(appState);
}
updateSystemColorSchemes(SystemColorSchemes systemColorSchemes) {
@@ -226,7 +208,6 @@ class AppController {
afterInit() async {
if (appState.isInit) {
changeProxy();
if (config.autoRun) {
await updateSystemProxy(true);
} else {

View File

@@ -9,8 +9,7 @@ extension GroupTypeExtension on GroupType {
)
.toList();
static GroupType? getGroupType(String? value) {
if (value == null) return null;
static GroupType? getGroupType(String value) {
final index = GroupTypeExtension.valueList.indexOf(value);
if (index == -1) return null;
return GroupType.values[index];

View File

@@ -1,4 +1,3 @@
import 'package:collection/collection.dart';
import 'package:fl_clash/clash/clash.dart';
import 'package:flutter/material.dart';
import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart';
@@ -57,26 +56,6 @@ class _ProxiesFragmentState extends State<ProxiesFragment>
});
}
_updateTabController(length) {
if (_tabController != null) {
_tabController!.dispose();
_tabController = null;
}
_tabController = TabController(
length: length,
vsync: this,
);
}
@override
void dispose() {
if (_tabController != null) {
_tabController!.dispose();
_tabController = null;
}
super.dispose();
}
@override
Widget build(BuildContext context) {
return Selector<AppState, bool>(
@@ -87,14 +66,32 @@ class _ProxiesFragmentState extends State<ProxiesFragment>
}
return child!;
},
child: Selector2<AppState, ClashConfig, List<Group>>(
selector: (_, appState, clashConfig) =>
appState.getCurrentGroups(clashConfig.mode),
shouldRebuild: (prev, next) =>
!const ListEquality<Group>().equals(prev, next),
builder: (_, groups, __) {
child: Selector3<AppState, Config, ClashConfig, ProxiesSelectorState>(
selector: (_, appState, config, clashConfig) {
final currentGroups = appState.getCurrentGroups(clashConfig.mode);
final currentProxyName = appState.getCurrentGroupNameWithGroups(
currentGroups,
config.currentGroupName,
clashConfig.mode,
);
final currentIndex = currentGroups
.indexWhere((element) => element.name == currentProxyName);
return ProxiesSelectorState(
currentIndex: currentIndex != -1 ? currentIndex : 0,
groups: currentGroups,
);
},
builder: (_, state, __) {
if (_tabController != null) {
_tabController!.dispose();
_tabController = null;
}
_tabController = TabController(
length: state.groups.length,
vsync: this,
initialIndex: state.currentIndex,
);
debugPrint("[Proxies] update===>");
_updateTabController(groups.length);
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
@@ -108,7 +105,7 @@ class _ProxiesFragmentState extends State<ProxiesFragment>
overlayColor:
const MaterialStatePropertyAll(Colors.transparent),
tabs: [
for (final group in groups)
for (final group in state.groups)
Tab(
text: group.name,
),
@@ -118,7 +115,7 @@ class _ProxiesFragmentState extends State<ProxiesFragment>
child: TabBarView(
controller: _tabController,
children: [
for (final group in groups)
for (final group in state.groups)
KeepContainer(
child: ProxiesTabView(
group: group,
@@ -197,7 +194,7 @@ class _ProxiesTabViewState extends State<ProxiesTabView>
_controller.dispose();
}
get group => widget.group;
Group get group => widget.group;
get measure => context.appController.measure;
@@ -369,7 +366,20 @@ class _ProxiesTabViewState extends State<ProxiesTabView>
}) {
return SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: AnimateGrid<Proxy>(
child: Selector3<AppState, Config, ClashConfig, ProxiesCardSelectorState>(
selector: (_, appState, config, clashConfig) =>
ProxiesCardSelectorState(
currentGroupName: appState.getCurrentGroupName(
config.currentGroupName,
clashConfig.mode,
),
currentProxyName: appState.getCurrentProxyName(
config.currentProxyName,
clashConfig.mode,
),
),
builder: (_, state, __) {
return AnimateGrid<Proxy>(
items: _getProxies(group.all, proxiesSortType),
columns: columns,
itemHeight: _getItemHeight(),
@@ -377,17 +387,12 @@ class _ProxiesTabViewState extends State<ProxiesTabView>
return ObjectKey(item);
},
builder: (_, proxy) {
return Selector3<AppState, Config, ClashConfig, String?>(
selector: (_, appState, config, clashConfig) =>
appState.getCurrentProxyName(
config.currentProxyName,
clashConfig.mode,
),
builder: (_, value, __) {
final currentProxyName =
group.type == GroupType.Selector ? value : group.now;
final isSelected = group.type == GroupType.Selector
? group.name == state.currentGroupName &&
proxy.name == state.currentProxyName
: group.now == proxy.name;
return _card(
isSelected: proxy.name == currentProxyName,
isSelected: isSelected,
onPressed: () {
if (group.type == GroupType.Selector) {
final config = context.read<Config>();

View File

@@ -78,6 +78,7 @@ Future<void> vpnService() async {
TileListenerWithVpn(
onStop: () async {
await app?.tip(appLocalizations.stopVpn);
await globalState.stopSystemProxy();
clashCore.shutdown();
exit(0);
},

View File

@@ -165,19 +165,26 @@ class AppState with ChangeNotifier {
}
}
String? getCurrentGroupName(String? groupName, Mode mode) {
final currentGroups = getCurrentGroups(mode);
String? getCurrentGroupNameWithGroups(
List<Group> groups,
String? groupName,
Mode mode,
) {
switch (mode) {
case Mode.direct:
return null;
case Mode.global:
return UsedProxy.GLOBAL.name;
case Mode.rule:
return groupName ??
(currentGroups.isNotEmpty ? currentGroups.first.name : null);
return groupName ?? (groups.isNotEmpty ? groups.first.name : null);
}
}
String? getCurrentGroupName(String? groupName, Mode mode) {
final currentGroups = getCurrentGroups(mode);
return getCurrentGroupNameWithGroups(currentGroups, groupName, mode);
}
String? getCurrentProxyName(String? proxyName, Mode mode) {
final currentGroups = getCurrentGroups(mode);
switch (mode) {

View File

@@ -87,7 +87,7 @@ class Config extends ChangeNotifier {
_isMinimizeOnExit = true,
_isAccessControl = false,
_accessControl = AccessControl(),
_isAnimateToPage = false;
_isAnimateToPage = true;
deleteProfileById(String id) {
_profiles = profiles.where((element) => element.id != id).toList();

View File

@@ -1740,3 +1740,295 @@ abstract class _HomeNavigationSelectorState
_$$HomeNavigationSelectorStateImplCopyWith<_$HomeNavigationSelectorStateImpl>
get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$ProxiesSelectorState {
int get currentIndex => throw _privateConstructorUsedError;
List<Group> get groups => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$ProxiesSelectorStateCopyWith<ProxiesSelectorState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ProxiesSelectorStateCopyWith<$Res> {
factory $ProxiesSelectorStateCopyWith(ProxiesSelectorState value,
$Res Function(ProxiesSelectorState) then) =
_$ProxiesSelectorStateCopyWithImpl<$Res, ProxiesSelectorState>;
@useResult
$Res call({int currentIndex, List<Group> groups});
}
/// @nodoc
class _$ProxiesSelectorStateCopyWithImpl<$Res,
$Val extends ProxiesSelectorState>
implements $ProxiesSelectorStateCopyWith<$Res> {
_$ProxiesSelectorStateCopyWithImpl(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? currentIndex = null,
Object? groups = null,
}) {
return _then(_value.copyWith(
currentIndex: null == currentIndex
? _value.currentIndex
: currentIndex // ignore: cast_nullable_to_non_nullable
as int,
groups: null == groups
? _value.groups
: groups // ignore: cast_nullable_to_non_nullable
as List<Group>,
) as $Val);
}
}
/// @nodoc
abstract class _$$ProxiesSelectorStateImplCopyWith<$Res>
implements $ProxiesSelectorStateCopyWith<$Res> {
factory _$$ProxiesSelectorStateImplCopyWith(_$ProxiesSelectorStateImpl value,
$Res Function(_$ProxiesSelectorStateImpl) then) =
__$$ProxiesSelectorStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({int currentIndex, List<Group> groups});
}
/// @nodoc
class __$$ProxiesSelectorStateImplCopyWithImpl<$Res>
extends _$ProxiesSelectorStateCopyWithImpl<$Res, _$ProxiesSelectorStateImpl>
implements _$$ProxiesSelectorStateImplCopyWith<$Res> {
__$$ProxiesSelectorStateImplCopyWithImpl(_$ProxiesSelectorStateImpl _value,
$Res Function(_$ProxiesSelectorStateImpl) _then)
: super(_value, _then);
@pragma('vm:prefer-inline')
@override
$Res call({
Object? currentIndex = null,
Object? groups = null,
}) {
return _then(_$ProxiesSelectorStateImpl(
currentIndex: null == currentIndex
? _value.currentIndex
: currentIndex // ignore: cast_nullable_to_non_nullable
as int,
groups: null == groups
? _value._groups
: groups // ignore: cast_nullable_to_non_nullable
as List<Group>,
));
}
}
/// @nodoc
class _$ProxiesSelectorStateImpl implements _ProxiesSelectorState {
const _$ProxiesSelectorStateImpl(
{required this.currentIndex, required final List<Group> groups})
: _groups = groups;
@override
final int currentIndex;
final List<Group> _groups;
@override
List<Group> get groups {
if (_groups is EqualUnmodifiableListView) return _groups;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_groups);
}
@override
String toString() {
return 'ProxiesSelectorState(currentIndex: $currentIndex, groups: $groups)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ProxiesSelectorStateImpl &&
(identical(other.currentIndex, currentIndex) ||
other.currentIndex == currentIndex) &&
const DeepCollectionEquality().equals(other._groups, _groups));
}
@override
int get hashCode => Object.hash(
runtimeType, currentIndex, const DeepCollectionEquality().hash(_groups));
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$ProxiesSelectorStateImplCopyWith<_$ProxiesSelectorStateImpl>
get copyWith =>
__$$ProxiesSelectorStateImplCopyWithImpl<_$ProxiesSelectorStateImpl>(
this, _$identity);
}
abstract class _ProxiesSelectorState implements ProxiesSelectorState {
const factory _ProxiesSelectorState(
{required final int currentIndex,
required final List<Group> groups}) = _$ProxiesSelectorStateImpl;
@override
int get currentIndex;
@override
List<Group> get groups;
@override
@JsonKey(ignore: true)
_$$ProxiesSelectorStateImplCopyWith<_$ProxiesSelectorStateImpl>
get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$ProxiesCardSelectorState {
String? get currentGroupName => throw _privateConstructorUsedError;
String? get currentProxyName => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$ProxiesCardSelectorStateCopyWith<ProxiesCardSelectorState> 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;
}

View File

@@ -5,6 +5,7 @@ import 'config.dart';
import 'navigation.dart';
import 'package.dart';
import 'profile.dart';
import 'proxy.dart';
part 'generated/selector.freezed.dart';
@@ -101,3 +102,19 @@ class HomeNavigationSelectorState with _$HomeNavigationSelectorState{
required String? locale,
}) = _HomeNavigationSelectorState;
}
@freezed
class ProxiesSelectorState with _$ProxiesSelectorState{
const factory ProxiesSelectorState({
required int currentIndex,
required List<Group> groups,
}) = _ProxiesSelectorState;
}
@freezed
class ProxiesCardSelectorState with _$ProxiesCardSelectorState{
const factory ProxiesCardSelectorState({
required String? currentGroupName,
required String? currentProxyName,
}) = _ProxiesCardSelectorState;
}

View File

@@ -5,6 +5,7 @@ import 'dart:io';
import 'package:animations/animations.dart';
import 'package:fl_clash/clash/clash.dart';
import 'package:fl_clash/enum/enum.dart';
import 'package:fl_clash/models/clash_config.dart';
import 'package:fl_clash/plugins/app.dart';
import 'package:fl_clash/widgets/scaffold.dart';
import 'package:flutter/material.dart';
@@ -107,6 +108,41 @@ class GlobalState {
);
updateGroups(appState);
updateCoreVersionInfo(appState);
changeProxy(
appState: appState,
config: config,
clashConfig: clashConfig,
);
}
changeProxy({
required AppState appState,
required Config config,
required ClashConfig clashConfig,
}) {
final currentGroupName =
appState.getCurrentGroupName(config.currentGroupName, clashConfig.mode);
final currentProxyName =
appState.getCurrentProxyName(config.currentProxyName, clashConfig.mode);
if (config.profiles.isEmpty || currentProxyName == null) {
stopSystemProxy();
return;
}
if (currentGroupName == null) return;
final groupIndex = appState.groups.indexWhere(
(element) => element.name == currentGroupName,
);
if (groupIndex == -1) return;
final proxyIndex = appState.groups[groupIndex].all.indexWhere(
(element) => element.name == currentProxyName,
);
if (proxyIndex == -1) return;
clashCore.changeProxy(
ChangeProxyParams(
groupName: currentGroupName,
proxyName: currentProxyName,
),
);
}
updatePackages(AppState appState) async {
@@ -130,8 +166,8 @@ class GlobalState {
);
}
updateGroups(AppState appState) {
appState.groups = clashCore.getProxiesGroups();
Future<void> updateGroups(AppState appState) async {
appState.groups = await clashCore.getProxiesGroups();
}
showMessage({

View File

@@ -258,10 +258,10 @@ packages:
dependency: "direct main"
description:
name: flutter_adaptive_scaffold
sha256: "600bbe237530a249f957f7d0f36273c20bd38d137e28e098c5231c30cadbe927"
sha256: "9a1d5e9f728815e27b7b612883db19107ba8a35a46a97c757ea00896cb027451"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.10+1"
version: "0.1.10+2"
flutter_lints:
dependency: "direct dev"
description:
@@ -957,10 +957,10 @@ packages:
dependency: "direct main"
description:
name: win32_registry
sha256: "41fd8a189940d8696b1b810efb9abcf60827b6cbfab90b0c43e8439e3a39d85a"
sha256: "10589e0d7f4e053f2c61023a31c9ce01146656a70b7b7f0828c0b46d7da2a9bb"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.2"
version: "1.1.3"
window_manager:
dependency: "direct main"
description:

View File

@@ -1,7 +1,7 @@
name: fl_clash
description: A multi-platform proxy client based on ClashMeta, simple and easy to use, open-source and ad-free.
publish_to: 'none'
version: 0.7.0
version: 0.7.7
environment:
sdk: '>=3.1.0 <4.0.0'