|
@@ -80,26 +80,38 @@ class GlobalController extends GetxController {
|
|
|
Future<bool> checkAllCoresStopped() async {
|
|
|
bool allStopped = true;
|
|
|
|
|
|
-
|
|
|
+
|
|
|
if (Platform.isWindows) {
|
|
|
- allStopped = controllers.service.coreStatus.value == RunningState.running;
|
|
|
+ allStopped = controllers.service.coreStatus.value == RunningState.running;
|
|
|
} else if (Platform.isMacOS) {
|
|
|
if(await controllers.cc_service.isCanOperationService()){
|
|
|
allStopped = controllers.cc_service.coreStatus.value == RunningState.running;
|
|
|
} else {
|
|
|
- allStopped = controllers.service.coreStatus.value == RunningState.running;
|
|
|
+ allStopped = controllers.service.coreStatus.value == RunningState.running;
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ if (!allStopped) {
|
|
|
+ try {
|
|
|
+ if (Platform.isWindows) {
|
|
|
+ await controllers.service.startClashCore();
|
|
|
+ } else if (Platform.isMacOS) {
|
|
|
+ if (controllers.cc_service.serviceIsRuning) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ await controllers.service.startClashCore();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ await Future.delayed(Duration(seconds: 2));
|
|
|
+
|
|
|
+ return await checkAllCoresStopped();
|
|
|
+ } catch (e) {
|
|
|
+ LogHelper().e("启动内核失败: $e");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
return allStopped;
|
|
|
}
|
|
@@ -163,7 +175,16 @@ class GlobalController extends GetxController {
|
|
|
}
|
|
|
|
|
|
Future<void> fetchNodes() async {
|
|
|
- nodeModes.value = await ApiService().getNode("/api/client/v4/nodes?vless=1");
|
|
|
+ try {
|
|
|
+
|
|
|
+ if (!await checkAllCoresStopped()) {
|
|
|
+ throw Exception("内核未启动");
|
|
|
+ }
|
|
|
+
|
|
|
+ nodeModes.value = await ApiService().getNode("/api/client/v4/nodes?vless=1");
|
|
|
+ } catch (e) {
|
|
|
+ handleApiError(e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
Future<void> updateNode() async {
|
|
@@ -189,7 +210,13 @@ class GlobalController extends GetxController {
|
|
|
}
|
|
|
|
|
|
Future<void> swift(String name) async {
|
|
|
- try{
|
|
|
+ try {
|
|
|
+
|
|
|
+ if (!await checkAllCoresStopped()) {
|
|
|
+ throw Exception("内核未启动");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
var g = "proxy";
|
|
|
if(modesSelect.value == "global") {
|
|
|
g = "GLOBAL";
|
|
@@ -202,7 +229,7 @@ class GlobalController extends GetxController {
|
|
|
if (it.chains.contains(name)) controllers.core.fetchCloseConnections(it.id);
|
|
|
}
|
|
|
} catch (e) {
|
|
|
-
|
|
|
+ handleApiError(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -360,6 +387,10 @@ class GlobalController extends GetxController {
|
|
|
} else {
|
|
|
LogHelper().d('Other error: $error');
|
|
|
errorMsg.value = error.toString();
|
|
|
+ if (error.toString().contains("内核未启动")) {
|
|
|
+
|
|
|
+ msgStatus.value = "内核未启动,请稍后重试";
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|