Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
442c32b6eb | ||
|
|
949a2aaac3 | ||
|
|
c77463f337 | ||
|
|
00377d6070 | ||
|
|
f393b4b3e9 | ||
|
|
75e6cfde15 | ||
|
|
7bfe5617d9 | ||
|
|
97cc96c243 | ||
|
|
1821ee2f61 |
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -107,7 +107,7 @@ jobs:
|
|||||||
else
|
else
|
||||||
current="${{ github.ref_name }}"
|
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
|
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
|
echo -e "\n\n</details>" >> release.md
|
||||||
fi
|
fi
|
||||||
- name: Release
|
- name: Release
|
||||||
|
|||||||
11
README.md
11
README.md
@@ -10,12 +10,12 @@ A multi-platform proxy client based on ClashMeta, simple and easy to use, open-s
|
|||||||
|
|
||||||
on Desktop:
|
on Desktop:
|
||||||
<p style="text-align: center;">
|
<p style="text-align: center;">
|
||||||
<img src="snapshots/desktop.gif">
|
<img alt="desktop" src="snapshots/desktop.gif">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
on Mobile:
|
on Mobile:
|
||||||
<p style="text-align: center;">
|
<p style="text-align: center;">
|
||||||
<img src="snapshots/mobile.gif">
|
<img alt="mobile" src="snapshots/mobile.gif">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
@@ -28,6 +28,10 @@ on Mobile:
|
|||||||
|
|
||||||
✨ Support subscription link, Dark mode
|
✨ Support subscription link, Dark mode
|
||||||
|
|
||||||
|
## Contact
|
||||||
|
|
||||||
|
[Telegram](https://t.me/+G-veVtwBOl4wODc1)
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
||||||
1. Update submodules
|
1. Update submodules
|
||||||
@@ -82,3 +86,6 @@ on Mobile:
|
|||||||
```bash
|
```bash
|
||||||
dart .\setup.dart
|
dart .\setup.dart
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -10,12 +10,12 @@
|
|||||||
|
|
||||||
on Desktop:
|
on Desktop:
|
||||||
<p style="text-align: center;">
|
<p style="text-align: center;">
|
||||||
<img src="snapshots/desktop.gif">
|
<img alt="desktop" src="snapshots/desktop.gif">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
on Mobile:
|
on Mobile:
|
||||||
<p style="text-align: center;">
|
<p style="text-align: center;">
|
||||||
<img src="snapshots/mobile.gif">
|
<img alt="mobile" src="snapshots/mobile.gif">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
@@ -28,6 +28,10 @@ on Mobile:
|
|||||||
|
|
||||||
✨ 支持一键导入订阅, 深色模式
|
✨ 支持一键导入订阅, 深色模式
|
||||||
|
|
||||||
|
## Contact
|
||||||
|
|
||||||
|
[Telegram](https://t.me/+G-veVtwBOl4wODc1)
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
||||||
1. 更新 submodules
|
1. 更新 submodules
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import io.flutter.embedding.engine.FlutterEngine
|
|||||||
class MainActivity : FlutterActivity() {
|
class MainActivity : FlutterActivity() {
|
||||||
|
|
||||||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||||
|
GlobalState.flutterEngine?.destroy()
|
||||||
super.configureFlutterEngine(flutterEngine)
|
super.configureFlutterEngine(flutterEngine)
|
||||||
flutterEngine.plugins.add(AppPlugin())
|
flutterEngine.plugins.add(AppPlugin())
|
||||||
flutterEngine.plugins.add(ProxyPlugin())
|
flutterEngine.plugins.add(ProxyPlugin())
|
||||||
|
|||||||
@@ -37,14 +37,12 @@ class FlClashTileService : TileService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onStartListening() {
|
override fun onStartListening() {
|
||||||
super.onStartListening()
|
super.onStartListening()
|
||||||
GlobalState.runState.value?.let { updateTile(it) }
|
GlobalState.runState.value?.let { updateTile(it) }
|
||||||
GlobalState.runState.observeForever(observer)
|
GlobalState.runState.observeForever(observer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressLint("StartActivityAndCollapseDeprecated")
|
@SuppressLint("StartActivityAndCollapseDeprecated")
|
||||||
private fun activityTransfer() {
|
private fun activityTransfer() {
|
||||||
val intent = Intent(this, TempActivity::class.java)
|
val intent = Intent(this, TempActivity::class.java)
|
||||||
@@ -88,7 +86,7 @@ class FlClashTileService : TileService() {
|
|||||||
if(currentTilePlugin == null){
|
if(currentTilePlugin == null){
|
||||||
initFlutterEngine()
|
initFlutterEngine()
|
||||||
}else{
|
}else{
|
||||||
currentTilePlugin?.handleStart()
|
currentTilePlugin.handleStart()
|
||||||
}
|
}
|
||||||
} else if(GlobalState.runState.value == RunState.START){
|
} else if(GlobalState.runState.value == RunState.START){
|
||||||
GlobalState.runState.value = RunState.PENDING
|
GlobalState.runState.value = RunState.PENDING
|
||||||
@@ -97,7 +95,6 @@ class FlClashTileService : TileService() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
GlobalState.runState.removeObserver(observer)
|
GlobalState.runState.removeObserver(observer)
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ class FlClashVpnService : VpnService() {
|
|||||||
|
|
||||||
private val CHANNEL = "FlClash"
|
private val CHANNEL = "FlClash"
|
||||||
|
|
||||||
var fd: Int? = null;
|
var fd: Int? = null
|
||||||
|
private val notificationId: Int = 1
|
||||||
|
|
||||||
private val passList = listOf(
|
private val passList = listOf(
|
||||||
"*zhihu.com",
|
"*zhihu.com",
|
||||||
@@ -100,11 +101,12 @@ class FlClashVpnService : VpnService() {
|
|||||||
fun startForeground(title: String, content: String) {
|
fun startForeground(title: String, content: String) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
val channel =
|
val channel =
|
||||||
NotificationChannel(CHANNEL, "FlClash", NotificationManager.IMPORTANCE_DEFAULT)
|
NotificationChannel(CHANNEL, "FlClash", NotificationManager.IMPORTANCE_LOW)
|
||||||
val manager = getSystemService(NotificationManager::class.java)
|
val manager = getSystemService(NotificationManager::class.java)
|
||||||
manager.createNotificationChannel(channel)
|
manager.createNotificationChannel(channel)
|
||||||
|
|
||||||
val intent = Intent(this, MainActivity::class.java)
|
val intent = Intent(this, MainActivity::class.java)
|
||||||
|
|
||||||
val pendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
val pendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
PendingIntent.getActivity(
|
PendingIntent.getActivity(
|
||||||
this,
|
this,
|
||||||
@@ -120,7 +122,9 @@ class FlClashVpnService : VpnService() {
|
|||||||
PendingIntent.FLAG_UPDATE_CURRENT
|
PendingIntent.FLAG_UPDATE_CURRENT
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val icon = IconCompat.createWithResource(this, this.applicationInfo.icon)
|
val icon = IconCompat.createWithResource(this, this.applicationInfo.icon)
|
||||||
|
|
||||||
val notification = with(NotificationCompat.Builder(this, CHANNEL)) {
|
val notification = with(NotificationCompat.Builder(this, CHANNEL)) {
|
||||||
setSmallIcon(icon)
|
setSmallIcon(icon)
|
||||||
setContentTitle(title)
|
setContentTitle(title)
|
||||||
@@ -132,12 +136,13 @@ class FlClashVpnService : VpnService() {
|
|||||||
build()
|
build()
|
||||||
}
|
}
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
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 {
|
} else {
|
||||||
startForeground(1, notification)
|
startForeground(notificationId, notification)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stopForeground() {
|
private fun stopForeground() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
stopForeground(Service.STOP_FOREGROUND_REMOVE)
|
stopForeground(Service.STOP_FOREGROUND_REMOVE)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
var currentConfig *config.RawConfig
|
var currentConfig = config.DefaultRawConfig()
|
||||||
|
|
||||||
var isInit = false
|
var isInit = false
|
||||||
|
|
||||||
@@ -235,6 +235,7 @@ func getProviders() *C.char {
|
|||||||
return C.CString(string(data))
|
return C.CString(string(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//export getProvider
|
//export getProvider
|
||||||
func getProvider(name *C.char) *C.char {
|
func getProvider(name *C.char) *C.char {
|
||||||
providerName := C.GoString(name)
|
providerName := C.GoString(name)
|
||||||
|
|||||||
@@ -69,43 +69,30 @@ class ClashCore {
|
|||||||
1;
|
1;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Group> getProxiesGroups() {
|
Future<List<Group>> getProxiesGroups() {
|
||||||
final proxiesRaw = clashFFI.getProxies();
|
final proxiesRaw = clashFFI.getProxies();
|
||||||
final proxies = json.decode(proxiesRaw.cast<Utf8>().toDartString());
|
final proxiesRawString = proxiesRaw.cast<Utf8>().toDartString();
|
||||||
final groupsRaw = List.from(proxies.values).where((e) {
|
return Isolate.run<List<Group>>(() {
|
||||||
final excludeName = !UsedProxyExtension.valueList
|
final proxies = json.decode(proxiesRawString);
|
||||||
.where((element) => element != UsedProxy.GLOBAL.name)
|
final groupsRaw = (proxies[UsedProxy.GLOBAL.name]["all"] as List)
|
||||||
.contains(e['name']);
|
.where((e) {
|
||||||
final validType = GroupTypeExtension.valueList.contains(e['type']);
|
final proxy = proxies[e];
|
||||||
return excludeName && validType;
|
final excludeName = !UsedProxyExtension.valueList
|
||||||
}).map(
|
.where((element) => element != UsedProxy.GLOBAL.name)
|
||||||
(e) {
|
.contains(proxy['name']);
|
||||||
e["all"] = ((e["all"] ?? []) as List)
|
final validType = GroupTypeExtension.valueList.contains(proxy['type']);
|
||||||
|
return excludeName && validType;
|
||||||
|
}).map((groupName) {
|
||||||
|
final group = proxies[groupName];
|
||||||
|
group["all"] = ((group["all"] ?? []) as List)
|
||||||
.map(
|
.map(
|
||||||
(name) => proxies[name],
|
(name) => proxies[name],
|
||||||
)
|
)
|
||||||
.toList();
|
.toList();
|
||||||
return e;
|
return group;
|
||||||
},
|
}).toList();
|
||||||
).toList()
|
return groupsRaw.map((e) => Group.fromJson(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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool changeProxy(ChangeProxyParams changeProxyParams) {
|
bool changeProxy(ChangeProxyParams changeProxyParams) {
|
||||||
|
|||||||
@@ -71,28 +71,10 @@ class AppController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
changeProxy() {
|
changeProxy() {
|
||||||
final currentGroupName =
|
globalState.changeProxy(
|
||||||
appState.getCurrentGroupName(config.currentGroupName, clashConfig.mode);
|
appState: appState,
|
||||||
final currentProxyName =
|
config: config,
|
||||||
appState.getCurrentProxyName(config.currentProxyName, clashConfig.mode);
|
clashConfig: clashConfig,
|
||||||
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,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +127,7 @@ class AppController {
|
|||||||
if (value == config.currentProfileId) return;
|
if (value == config.currentProfileId) return;
|
||||||
config.currentProfileId = value;
|
config.currentProfileId = value;
|
||||||
await updateClashConfig(isPatch: false);
|
await updateClashConfig(isPatch: false);
|
||||||
updateGroups();
|
await updateGroups();
|
||||||
changeProxy();
|
changeProxy();
|
||||||
appState.delayMap = {};
|
appState.delayMap = {};
|
||||||
saveConfigPreferences();
|
saveConfigPreferences();
|
||||||
@@ -162,13 +144,13 @@ class AppController {
|
|||||||
if (isNotNeedUpdate == false) continue;
|
if (isNotNeedUpdate == false) continue;
|
||||||
final result = await profile.update();
|
final result = await profile.update();
|
||||||
if (result.type == ResultType.error) continue;
|
if (result.type == ResultType.error) continue;
|
||||||
updateGroups();
|
await updateGroups();
|
||||||
changeProxy();
|
changeProxy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateGroups() {
|
Future<void> updateGroups() async {
|
||||||
globalState.updateGroups(appState);
|
await globalState.updateGroups(appState);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateSystemColorSchemes(SystemColorSchemes systemColorSchemes) {
|
updateSystemColorSchemes(SystemColorSchemes systemColorSchemes) {
|
||||||
@@ -226,7 +208,6 @@ class AppController {
|
|||||||
|
|
||||||
afterInit() async {
|
afterInit() async {
|
||||||
if (appState.isInit) {
|
if (appState.isInit) {
|
||||||
changeProxy();
|
|
||||||
if (config.autoRun) {
|
if (config.autoRun) {
|
||||||
await updateSystemProxy(true);
|
await updateSystemProxy(true);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ extension GroupTypeExtension on GroupType {
|
|||||||
)
|
)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
static GroupType? getGroupType(String? value) {
|
static GroupType? getGroupType(String value) {
|
||||||
if (value == null) return null;
|
|
||||||
final index = GroupTypeExtension.valueList.indexOf(value);
|
final index = GroupTypeExtension.valueList.indexOf(value);
|
||||||
if (index == -1) return null;
|
if (index == -1) return null;
|
||||||
return GroupType.values[index];
|
return GroupType.values[index];
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import 'package:collection/collection.dart';
|
|
||||||
import 'package:fl_clash/clash/clash.dart';
|
import 'package:fl_clash/clash/clash.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Selector<AppState, bool>(
|
return Selector<AppState, bool>(
|
||||||
@@ -87,14 +66,32 @@ class _ProxiesFragmentState extends State<ProxiesFragment>
|
|||||||
}
|
}
|
||||||
return child!;
|
return child!;
|
||||||
},
|
},
|
||||||
child: Selector2<AppState, ClashConfig, List<Group>>(
|
child: Selector3<AppState, Config, ClashConfig, ProxiesSelectorState>(
|
||||||
selector: (_, appState, clashConfig) =>
|
selector: (_, appState, config, clashConfig) {
|
||||||
appState.getCurrentGroups(clashConfig.mode),
|
final currentGroups = appState.getCurrentGroups(clashConfig.mode);
|
||||||
shouldRebuild: (prev, next) =>
|
final currentProxyName = appState.getCurrentGroupNameWithGroups(
|
||||||
!const ListEquality<Group>().equals(prev, next),
|
currentGroups,
|
||||||
builder: (_, groups, __) {
|
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===>");
|
debugPrint("[Proxies] update===>");
|
||||||
_updateTabController(groups.length);
|
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
@@ -108,7 +105,7 @@ class _ProxiesFragmentState extends State<ProxiesFragment>
|
|||||||
overlayColor:
|
overlayColor:
|
||||||
const MaterialStatePropertyAll(Colors.transparent),
|
const MaterialStatePropertyAll(Colors.transparent),
|
||||||
tabs: [
|
tabs: [
|
||||||
for (final group in groups)
|
for (final group in state.groups)
|
||||||
Tab(
|
Tab(
|
||||||
text: group.name,
|
text: group.name,
|
||||||
),
|
),
|
||||||
@@ -118,7 +115,7 @@ class _ProxiesFragmentState extends State<ProxiesFragment>
|
|||||||
child: TabBarView(
|
child: TabBarView(
|
||||||
controller: _tabController,
|
controller: _tabController,
|
||||||
children: [
|
children: [
|
||||||
for (final group in groups)
|
for (final group in state.groups)
|
||||||
KeepContainer(
|
KeepContainer(
|
||||||
child: ProxiesTabView(
|
child: ProxiesTabView(
|
||||||
group: group,
|
group: group,
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ Future<void> vpnService() async {
|
|||||||
TileListenerWithVpn(
|
TileListenerWithVpn(
|
||||||
onStop: () async {
|
onStop: () async {
|
||||||
await app?.tip(appLocalizations.stopVpn);
|
await app?.tip(appLocalizations.stopVpn);
|
||||||
|
await globalState.stopSystemProxy();
|
||||||
clashCore.shutdown();
|
clashCore.shutdown();
|
||||||
exit(0);
|
exit(0);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -165,19 +165,26 @@ class AppState with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String? getCurrentGroupName(String? groupName, Mode mode) {
|
String? getCurrentGroupNameWithGroups(
|
||||||
final currentGroups = getCurrentGroups(mode);
|
List<Group> groups,
|
||||||
|
String? groupName,
|
||||||
|
Mode mode,
|
||||||
|
) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case Mode.direct:
|
case Mode.direct:
|
||||||
return null;
|
return null;
|
||||||
case Mode.global:
|
case Mode.global:
|
||||||
return UsedProxy.GLOBAL.name;
|
return UsedProxy.GLOBAL.name;
|
||||||
case Mode.rule:
|
case Mode.rule:
|
||||||
return groupName ??
|
return groupName ?? (groups.isNotEmpty ? groups.first.name : null);
|
||||||
(currentGroups.isNotEmpty ? currentGroups.first.name : null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String? getCurrentGroupName(String? groupName, Mode mode) {
|
||||||
|
final currentGroups = getCurrentGroups(mode);
|
||||||
|
return getCurrentGroupNameWithGroups(currentGroups, groupName, mode);
|
||||||
|
}
|
||||||
|
|
||||||
String? getCurrentProxyName(String? proxyName, Mode mode) {
|
String? getCurrentProxyName(String? proxyName, Mode mode) {
|
||||||
final currentGroups = getCurrentGroups(mode);
|
final currentGroups = getCurrentGroups(mode);
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class Config extends ChangeNotifier {
|
|||||||
_isMinimizeOnExit = true,
|
_isMinimizeOnExit = true,
|
||||||
_isAccessControl = false,
|
_isAccessControl = false,
|
||||||
_accessControl = AccessControl(),
|
_accessControl = AccessControl(),
|
||||||
_isAnimateToPage = false;
|
_isAnimateToPage = true;
|
||||||
|
|
||||||
deleteProfileById(String id) {
|
deleteProfileById(String id) {
|
||||||
_profiles = profiles.where((element) => element.id != id).toList();
|
_profiles = profiles.where((element) => element.id != id).toList();
|
||||||
|
|||||||
@@ -1740,3 +1740,150 @@ abstract class _HomeNavigationSelectorState
|
|||||||
_$$HomeNavigationSelectorStateImplCopyWith<_$HomeNavigationSelectorStateImpl>
|
_$$HomeNavigationSelectorStateImplCopyWith<_$HomeNavigationSelectorStateImpl>
|
||||||
get copyWith => throw _privateConstructorUsedError;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import 'config.dart';
|
|||||||
import 'navigation.dart';
|
import 'navigation.dart';
|
||||||
import 'package.dart';
|
import 'package.dart';
|
||||||
import 'profile.dart';
|
import 'profile.dart';
|
||||||
|
import 'proxy.dart';
|
||||||
|
|
||||||
part 'generated/selector.freezed.dart';
|
part 'generated/selector.freezed.dart';
|
||||||
|
|
||||||
@@ -101,3 +102,12 @@ class HomeNavigationSelectorState with _$HomeNavigationSelectorState{
|
|||||||
required String? locale,
|
required String? locale,
|
||||||
}) = _HomeNavigationSelectorState;
|
}) = _HomeNavigationSelectorState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@freezed
|
||||||
|
class ProxiesSelectorState with _$ProxiesSelectorState{
|
||||||
|
const factory ProxiesSelectorState({
|
||||||
|
required int currentIndex,
|
||||||
|
required List<Group> groups,
|
||||||
|
}) = _ProxiesSelectorState;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import 'dart:io';
|
|||||||
import 'package:animations/animations.dart';
|
import 'package:animations/animations.dart';
|
||||||
import 'package:fl_clash/clash/clash.dart';
|
import 'package:fl_clash/clash/clash.dart';
|
||||||
import 'package:fl_clash/enum/enum.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/plugins/app.dart';
|
||||||
import 'package:fl_clash/widgets/scaffold.dart';
|
import 'package:fl_clash/widgets/scaffold.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -107,6 +108,41 @@ class GlobalState {
|
|||||||
);
|
);
|
||||||
updateGroups(appState);
|
updateGroups(appState);
|
||||||
updateCoreVersionInfo(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 {
|
updatePackages(AppState appState) async {
|
||||||
@@ -130,8 +166,8 @@ class GlobalState {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateGroups(AppState appState) {
|
Future<void> updateGroups(AppState appState) async {
|
||||||
appState.groups = clashCore.getProxiesGroups();
|
appState.groups = await clashCore.getProxiesGroups();
|
||||||
}
|
}
|
||||||
|
|
||||||
showMessage({
|
showMessage({
|
||||||
@@ -198,7 +234,7 @@ class GlobalState {
|
|||||||
required Config config,
|
required Config config,
|
||||||
}) {
|
}) {
|
||||||
final traffic = clashCore.getTraffic();
|
final traffic = clashCore.getTraffic();
|
||||||
if(appState != null){
|
if (appState != null) {
|
||||||
appState.addTraffic(traffic);
|
appState.addTraffic(traffic);
|
||||||
}
|
}
|
||||||
if (Platform.isAndroid) {
|
if (Platform.isAndroid) {
|
||||||
|
|||||||
@@ -258,10 +258,10 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: flutter_adaptive_scaffold
|
name: flutter_adaptive_scaffold
|
||||||
sha256: "600bbe237530a249f957f7d0f36273c20bd38d137e28e098c5231c30cadbe927"
|
sha256: "9a1d5e9f728815e27b7b612883db19107ba8a35a46a97c757ea00896cb027451"
|
||||||
url: "https://pub.flutter-io.cn"
|
url: "https://pub.flutter-io.cn"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.1.10+1"
|
version: "0.1.10+2"
|
||||||
flutter_lints:
|
flutter_lints:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
@@ -957,10 +957,10 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: win32_registry
|
name: win32_registry
|
||||||
sha256: "41fd8a189940d8696b1b810efb9abcf60827b6cbfab90b0c43e8439e3a39d85a"
|
sha256: "10589e0d7f4e053f2c61023a31c9ce01146656a70b7b7f0828c0b46d7da2a9bb"
|
||||||
url: "https://pub.flutter-io.cn"
|
url: "https://pub.flutter-io.cn"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.2"
|
version: "1.1.3"
|
||||||
window_manager:
|
window_manager:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
name: fl_clash
|
name: fl_clash
|
||||||
description: A multi-platform proxy client based on ClashMeta, simple and easy to use, open-source and ad-free.
|
description: A multi-platform proxy client based on ClashMeta, simple and easy to use, open-source and ad-free.
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
version: 0.7.0
|
version: 0.7.2
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.1.0 <4.0.0'
|
sdk: '>=3.1.0 <4.0.0'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user