mirror of
https://github.com/hiddify/hiddify-next.git
synced 2026-06-05 21:05:07 +08:00
better support for events
This commit is contained in:
parent
956177a3cd
commit
07f7874506
@ -114,24 +114,29 @@ class CoreInterfaceMobile extends CoreInterface with InfraLogger {
|
||||
});
|
||||
|
||||
_isBgClientAvailable = true;
|
||||
for (var i = 0; i < 200; i++) {
|
||||
loggy.info("Waiting for starting core");
|
||||
for (var i = 0; i < 20; i++) {
|
||||
try {
|
||||
final res = await _status.get(timeout: const Duration(milliseconds: 100));
|
||||
final res = await _status.get(timeout: const Duration(seconds: 1));
|
||||
|
||||
switch (res) {
|
||||
case CoreStarted():
|
||||
break;
|
||||
case CoreStopped():
|
||||
if (res.alert != null) return res;
|
||||
if (res.alert != null) {
|
||||
return res;
|
||||
}
|
||||
|
||||
case CoreStopping():
|
||||
// return res;
|
||||
case CoreStarting():
|
||||
}
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
} on TimeoutException {
|
||||
// just retry
|
||||
}
|
||||
}
|
||||
loggy.info("Waiting for starting core finished");
|
||||
|
||||
if (!await waitUntilPort(portBack, true, null, maxTry: 10)) {
|
||||
await stopMethodChannel();
|
||||
|
||||
@ -19,8 +19,12 @@ sealed class CoreStatus with _$CoreStatus {
|
||||
switch (event?["status"]) {
|
||||
case "Stopped":
|
||||
final alertstr = event?["alert"] as String?;
|
||||
final alert = CoreAlert.values.firstOrNullWhere((e) => alertstr?.toLowerCase() == e.name.toLowerCase());
|
||||
final msgStr = event?["message"] as String?;
|
||||
var msgStr = event?["message"] as String?;
|
||||
var alert = CoreAlert.values.firstOrNullWhere((e) => alertstr?.toLowerCase() == e.name.toLowerCase());
|
||||
if ((alert == null) && (alertstr ?? "") != "") {
|
||||
msgStr = ((msgStr ?? "") != "") ? "$alertstr: $msgStr" : alertstr;
|
||||
alert = CoreAlert.unknown;
|
||||
}
|
||||
return CoreStatus.stopped(alert: alert, message: msgStr);
|
||||
|
||||
case "Starting":
|
||||
@ -100,4 +104,5 @@ enum CoreAlert {
|
||||
startService,
|
||||
alreadyStarted,
|
||||
startFailed,
|
||||
unknown,
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user