From 91faed35c00a53fd98b245000207e4e1c7aab915 Mon Sep 17 00:00:00 2001 From: chen08209 Date: Thu, 2 May 2024 00:32:11 +0800 Subject: [PATCH] Fix Android quickStart VpnService some problems --- lib/controller.dart | 27 ++++----------------------- lib/state.dart | 38 +++++++++++++++++++++++++++++++++++++- pubspec.lock | 8 ++++---- pubspec.yaml | 2 +- 4 files changed, 46 insertions(+), 29 deletions(-) diff --git a/lib/controller.dart b/lib/controller.dart index 418ead3..de2be84 100644 --- a/lib/controller.dart +++ b/lib/controller.dart @@ -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, ); } @@ -226,7 +208,6 @@ class AppController { afterInit() async { if (appState.isInit) { - changeProxy(); if (config.autoRun) { await updateSystemProxy(true); } else { diff --git a/lib/state.dart b/lib/state.dart index b60ed7a..92cb91c 100644 --- a/lib/state.dart +++ b/lib/state.dart @@ -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 { @@ -198,7 +234,7 @@ class GlobalState { required Config config, }) { final traffic = clashCore.getTraffic(); - if(appState != null){ + if (appState != null) { appState.addTraffic(traffic); } if (Platform.isAndroid) { diff --git a/pubspec.lock b/pubspec.lock index d654ac7..1c467a6 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: diff --git a/pubspec.yaml b/pubspec.yaml index 9a6298c..ae95393 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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.1 +version: 0.7.1+1 environment: sdk: '>=3.1.0 <4.0.0'