better support for events

This commit is contained in:
hiddify 2026-02-20 18:08:46 +03:30
parent 956177a3cd
commit 07f7874506
2 changed files with 15 additions and 5 deletions

View File

@ -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();

View File

@ -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,
}