修复安卓bug
Build Windows / build (push) Has been cancelled

This commit is contained in:
2025-10-03 15:20:49 +08:00
parent 866938abab
commit d87c58ac26
3 changed files with 213 additions and 3 deletions
@@ -537,7 +537,7 @@ class KRHomeController extends GetxController {
kr_isSwitching = true;
if (value) {
await KRSingBoxImp.instance.kr_start();
// 添加延迟验证,确保状态正确更新
Future.delayed(const Duration(seconds: 2), () {
kr_forceSyncConnectionStatus();
@@ -547,6 +547,10 @@ class KRHomeController extends GetxController {
}
} catch (e) {
KRLogUtil.kr_e('切换失败: $e', tag: 'HomeController');
// 当启动失败时(如VPN权限被拒绝),强制同步状态
Future.delayed(const Duration(milliseconds: 100), () {
kr_forceSyncConnectionStatus();
});
} finally {
// 确保在任何情况下都会重置标志
kr_isSwitching = false;
@@ -430,7 +430,7 @@ class KRSingBoxImp {
KRLogUtil.kr_i('🚀 开始启动 SingBox...', tag: 'SingBox');
KRLogUtil.kr_i('📁 配置文件路径: $_cutPath', tag: 'SingBox');
KRLogUtil.kr_i('📝 配置名称: $kr_configName', tag: 'SingBox');
// 检查配置文件是否存在
final configFile = File(_cutPath);
if (await configFile.exists()) {
@@ -440,20 +440,26 @@ class KRSingBoxImp {
} else {
KRLogUtil.kr_w('⚠️ 配置文件不存在: $_cutPath', tag: 'SingBox');
}
await kr_singBox.start(_cutPath, kr_configName, false).map(
(r) {
KRLogUtil.kr_i('✅ SingBox 启动成功', tag: 'SingBox');
},
).mapLeft((err) {
KRLogUtil.kr_e('❌ SingBox 启动失败: $err', tag: 'SingBox');
// 确保状态重置为Stopped,触发UI更新
kr_status.value = SingboxStopped();
// 强制刷新状态以触发观察者
kr_status.refresh();
throw err;
}).run();
} catch (e, stackTrace) {
KRLogUtil.kr_e('💥 SingBox 启动异常: $e', tag: 'SingBox');
KRLogUtil.kr_e('📚 错误堆栈: $stackTrace', tag: 'SingBox');
// 确保状态重置为Stopped,触发UI更新
kr_status.value = SingboxStopped();
// 强制刷新状态以触发观察者
kr_status.refresh();
rethrow;
}
}