|
@@ -42,6 +42,7 @@ class HomeController extends GetxController {
|
|
|
var localUsers = LocalUser().obs;
|
|
|
var userMode = User().obs;
|
|
|
var UsersysConfig = SysConfig().obs;
|
|
|
+
|
|
|
var connectStatus = Rx<ConnectionStatus>(ConnectionStatus.disconnected);
|
|
|
var nodeModes = <NodeMode>[];
|
|
|
bool get isRunning => connectStatus.value == ConnectionStatus.stopped && controllers.global.allowStatusUpdate;
|
|
@@ -113,13 +114,18 @@ class HomeController extends GetxController {
|
|
|
updateStatus(ConnectionStatus.disconnected);
|
|
|
return;
|
|
|
} else {
|
|
|
+ controllers.global.updateMsg("开始连接...");
|
|
|
await controllers.config.setBreakConnections(true);
|
|
|
controllers.global.allowStatusUpdate = true;
|
|
|
var routeModes = controllers.global.routeModesSelect.value;
|
|
|
if(routeModes == "tun"){
|
|
|
+ controllers.global.updateMsg("正在启动网卡模式...");
|
|
|
controllers.config.clashCoreTunEnable.value = true;
|
|
|
controllers.global.startTunMode();
|
|
|
- await controllers.service.startTunService();
|
|
|
+ if(controllers.service.serviceMode.value == false){
|
|
|
+ await controllers.service.serviceModeSwitch(true);
|
|
|
+ }
|
|
|
+
|
|
|
final coreStatus = controllers.service.coreStatus.value;
|
|
|
if (coreStatus == RunningState.running){
|
|
|
await controllers.service.reloadClashCore();
|
|
@@ -129,25 +135,36 @@ class HomeController extends GetxController {
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
-
|
|
|
+ controllers.global.updateMsg("正在启动系统模式...");
|
|
|
controllers.config.clashCoreTunEnable.value = false;
|
|
|
controllers.global.startSysMode();
|
|
|
final coreStatus = controllers.service.coreStatus.value;
|
|
|
if (coreStatus == RunningState.running){
|
|
|
+ controllers.global.updateMsg("正在重启内核...");
|
|
|
await controllers.service.reloadClashCore();
|
|
|
}
|
|
|
else{
|
|
|
+ controllers.global.updateMsg("正在启动内核...");
|
|
|
await controllers.service.startClashCore();
|
|
|
}
|
|
|
- await controllers.global.systemProxySwitch(true);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
updateStatus(ConnectionStatus.connecting);
|
|
|
- await Future.delayed(const Duration(seconds: 3));
|
|
|
- await controllers.global.updateNode();
|
|
|
- await controllers.global.updateDate();
|
|
|
- await controllers.tray.updateTray();
|
|
|
- updateStatus(ConnectionStatus.stopped);
|
|
|
+ Future.delayed(const Duration(seconds: 3), () async {
|
|
|
+ updateStatus(ConnectionStatus.stopped);
|
|
|
+ await controllers.global.updateNode();
|
|
|
+ // await controllers.global.updateDate();
|
|
|
+ await controllers.tray.updateTray();
|
|
|
+ controllers.global.updateMsg("连接完成...");
|
|
|
+ if(routeModes != "tun"){
|
|
|
+ await controllers.global.systemProxySwitch(true);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ controllers.global.updateMsg("设置系统代理完成...");
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -160,22 +177,32 @@ class HomeController extends GetxController {
|
|
|
|
|
|
|
|
|
Future<void> stopVpn() async {
|
|
|
- controllers.global.allowStatusUpdate = false;
|
|
|
+ controllers.global.updateMsg("正在停止...");
|
|
|
+ await controllers.global.systemProxySwitch(false);
|
|
|
await controllers.config.setBreakConnections(true);
|
|
|
+ await controllers.tray.updateTray();
|
|
|
+
|
|
|
// // 停止服务
|
|
|
await controllers.service.stopClashCore();
|
|
|
- await controllers.global.systemProxySwitch(false);
|
|
|
- updateStatus(ConnectionStatus.disconnected);
|
|
|
+ controllers.global.updateMsg("正在停止.等待5秒防止端口无法释放");
|
|
|
+ Future.delayed(const Duration(seconds: 5), () async {
|
|
|
+ controllers.global.allowStatusUpdate = false;
|
|
|
+ updateStatus(ConnectionStatus.disconnected);
|
|
|
+ controllers.global.updateMsg("停止完成,点击立即加速");
|
|
|
+ });
|
|
|
}
|
|
|
Future<void> fetchAuthUser() async {
|
|
|
try {
|
|
|
- if (connectStatus.value == ConnectionStatus.stopped || connectStatus.value == ConnectionStatus.connecting) {
|
|
|
+ if (controllers.global.allowStatusUpdate && connectStatus.value == ConnectionStatus.stopped || connectStatus.value == ConnectionStatus.connecting) {
|
|
|
+ controllers.global.updateMsg("当前连接状态未停止,不要多次启动...");
|
|
|
return;
|
|
|
}
|
|
|
+ controllers.global.updateMsg("正在身份验证...");
|
|
|
final ret = await ApiService().fetchAuthUser(KAuthUser);
|
|
|
if(controllers.global.selectedNode.value == null){
|
|
|
controllers.global.selectedNode.value = ret;
|
|
|
controllers.global.selectNode(ret);
|
|
|
+ controllers.global.updateMsg("获取自动节点完成...");
|
|
|
}
|
|
|
await handleButtonClick();
|
|
|
} catch (e) {
|