|
@@ -24,8 +24,7 @@ import 'package:web_socket_channel/io.dart';
|
|
|
final headers = {"User-Agent": "ccore-for-flutter/0.0.1"};
|
|
|
|
|
|
class ServiceController extends GetxController {
|
|
|
- late final dio ;
|
|
|
-
|
|
|
+ late final _dio ;
|
|
|
var serviceMode = false.obs;
|
|
|
var servicePort = 0.obs;
|
|
|
var coreStatus = RunningState.stoped.obs;
|
|
@@ -40,14 +39,19 @@ class ServiceController extends GetxController {
|
|
|
bool get isCanOperationCore =>
|
|
|
serviceStatus.value == RunningState.running && ![RunningState.starting, RunningState.stopping].contains(coreStatus.value);
|
|
|
|
|
|
- ServiceController();
|
|
|
+ ServiceController(
|
|
|
|
|
|
- Future<void> startService() async {
|
|
|
+ ) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Future<void> initConfig() async{
|
|
|
servicePort.value = controllers.config.config.value.port;
|
|
|
print('http://127.0.0.1:${servicePort.value}');
|
|
|
- dio = Dio(BaseOptions(baseUrl: 'http://127.0.0.1:${servicePort.value}', headers: headers));
|
|
|
-
|
|
|
+ _dio = Dio(BaseOptions(baseUrl: 'http://127.0.0.1:${servicePort.value}', headers: headers));
|
|
|
+ }
|
|
|
|
|
|
+ Future<void> startService() async {
|
|
|
serviceStatus.value = RunningState.starting;
|
|
|
if (Platform.isLinux) {
|
|
|
await fixBinaryExecutePermissions(Files.assetsClashService);
|
|
@@ -91,7 +95,7 @@ class ServiceController extends GetxController {
|
|
|
break;
|
|
|
}
|
|
|
try {
|
|
|
- await dio.post('/info');
|
|
|
+ await _dio.post('/info');
|
|
|
break;
|
|
|
} catch (_) {}
|
|
|
}
|
|
@@ -120,7 +124,7 @@ class ServiceController extends GetxController {
|
|
|
while (true) {
|
|
|
await Future.delayed(const Duration(milliseconds: 100));
|
|
|
try {
|
|
|
- await dio.post('/info');
|
|
|
+ await _dio.post('/info');
|
|
|
break;
|
|
|
} catch (_) {}
|
|
|
}
|
|
@@ -131,7 +135,7 @@ class ServiceController extends GetxController {
|
|
|
while (true) {
|
|
|
await Future.delayed(const Duration(milliseconds: 100));
|
|
|
try {
|
|
|
- await dio.post('/info');
|
|
|
+ await _dio.post('/info');
|
|
|
} catch (e) {
|
|
|
break;
|
|
|
}
|
|
@@ -139,7 +143,7 @@ class ServiceController extends GetxController {
|
|
|
}
|
|
|
|
|
|
Future<ClashServiceInfo> fetchInfo() async {
|
|
|
- final res = await dio.post('/info');
|
|
|
+ final res = await _dio.post('/info');
|
|
|
return ClashServiceInfo.fromJson(res.data);
|
|
|
}
|
|
|
|
|
@@ -149,14 +153,18 @@ class ServiceController extends GetxController {
|
|
|
|
|
|
Future<void> fetchStart(String name) async {
|
|
|
await fetchStop();
|
|
|
- final res = await dio.post<String>('/start', data: {
|
|
|
+ final res = await _dio.post<String>('/start', data: {
|
|
|
"args": ['-d', Paths.config.path, '-f', path.join(Paths.config.path, name)]
|
|
|
});
|
|
|
if (json.decode(res.data!)["code"] != 0) throw json.decode(res.data!)["msg"];
|
|
|
}
|
|
|
|
|
|
Future<void> fetchStop() async {
|
|
|
- await dio.post('/stop');
|
|
|
+ try {
|
|
|
+ await _dio.post('/stop');
|
|
|
+ } catch (e) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
Future<void> install() async {
|
|
@@ -193,6 +201,7 @@ class ServiceController extends GetxController {
|
|
|
while (true) {
|
|
|
await Future.delayed(const Duration(milliseconds: 200));
|
|
|
final info = await fetchInfo();
|
|
|
+ print("core --- info $info");
|
|
|
if (info.status == 'running') {
|
|
|
try {
|
|
|
await controllers.core.fetchHello();
|
|
@@ -212,7 +221,7 @@ class ServiceController extends GetxController {
|
|
|
if (controllers.config.config.value.setSystemProxy) await SystemProxy.instance.set(controllers.core.proxyConfig);
|
|
|
coreStatus.value = RunningState.running;
|
|
|
} catch (e) {
|
|
|
- log.error(e);
|
|
|
+ log.error("core -- $e");
|
|
|
BotToast.showText(text: e.toString());
|
|
|
coreStatus.value = RunningState.error;
|
|
|
}
|