fix: 处理order_status异步
This commit is contained in:
@@ -25,6 +25,7 @@ import '../../singbox/model/singbox_status.dart';
|
||||
import 'package:kaer_with_panels/app/widgets/dialogs/hi_dialog.dart';
|
||||
import 'package:kaer_with_panels/app/services/api_service/kr_auth_api.dart';
|
||||
import 'package:kaer_with_panels/app/services/kr_subscribe_service.dart';
|
||||
import 'package:kaer_with_panels/app/utils/kr_common_util.dart';
|
||||
|
||||
class KRAppRunData {
|
||||
static final KRAppRunData _instance = KRAppRunData._internal();
|
||||
@@ -326,6 +327,88 @@ class KRAppRunData {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> kr_loginOut_loading() async{
|
||||
KRCommonUtil.kr_showLoading();
|
||||
// 先将登录状态设置为 false,防止重连
|
||||
kr_isLogin.value = false;
|
||||
KRLogUtil.kr_i('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━', tag: 'AppRunData');
|
||||
KRLogUtil.kr_i('开始重新进行设备登录', tag: 'AppRunData');
|
||||
KRLogUtil.kr_i('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━', tag: 'AppRunData');
|
||||
// === 停止 VPN 服务 ===
|
||||
try {
|
||||
// 检查 SingBox 服务状态并停止
|
||||
if (KRSingBoxImp.instance.kr_status.value is SingboxStarted) {
|
||||
await KRSingBoxImp.instance.kr_stop();
|
||||
KRLogUtil.kr_i('VPN 服务已停止', tag: 'Logout');
|
||||
}
|
||||
} catch (e) {
|
||||
KRCommonUtil.kr_hideLoading();
|
||||
KRLogUtil.kr_e('停止 VPN 服务失败: $e', tag: 'Logout');
|
||||
}
|
||||
|
||||
// 断开 Socket 连接
|
||||
await _kr_disconnectSocket();
|
||||
|
||||
// 清理用户信息
|
||||
kr_token = null;
|
||||
kr_account.value = null;
|
||||
kr_userId.value = null;
|
||||
kr_loginType = null;
|
||||
kr_areaCode = null;
|
||||
|
||||
// 删除存储的用户信息
|
||||
await KRSecureStorage().kr_deleteData(key: _keyUserInfo);
|
||||
|
||||
// 重置公告显示状态
|
||||
KRAnnouncementService().kr_reset();
|
||||
|
||||
// 🔧 修复4: 清理订阅服务数据 - 防止未登录用户访问订阅
|
||||
try {
|
||||
final subscribeService = Get.find<dynamic>(tag: 'KRSubscribeService');
|
||||
if (subscribeService != null && subscribeService is KRSubscribeService) {
|
||||
KRLogUtil.kr_i('🧹 清理订阅服务数据...', tag: 'AppRunData');
|
||||
await subscribeService.kr_logout();
|
||||
KRLogUtil.kr_i('✅ 订阅服务数据已清理', tag: 'AppRunData');
|
||||
}
|
||||
} catch (e) {
|
||||
KRCommonUtil.kr_hideLoading();
|
||||
// 忽略异常:如果订阅服务未初始化或不可用,直接继续
|
||||
KRLogUtil.kr_d('⚠️ 无法获取订阅服务,跳过清理: $e', tag: 'AppRunData');
|
||||
}
|
||||
|
||||
// 5️⃣ 执行设备登录
|
||||
final success = await kr_checkAndPerformDeviceLogin();
|
||||
|
||||
if (!success) {
|
||||
KRCommonUtil.kr_hideLoading();
|
||||
// 设备登录失败 → 提示用户重试
|
||||
HIDialog.show(
|
||||
message: '设备登录失败,请检查网络或重试',
|
||||
confirmText: '重试',
|
||||
preventBackDismiss: true,
|
||||
onConfirm: () async {
|
||||
await kr_loginOut(); // 递归重试
|
||||
},
|
||||
);
|
||||
return; // 阻止跳首页
|
||||
}
|
||||
|
||||
// 等待一小段时间,确保登录状态已经更新
|
||||
await Future.delayed(const Duration(milliseconds: 300));
|
||||
|
||||
// 刷新订阅信息
|
||||
KRLogUtil.kr_i('🔄 开始刷新订阅信息...', tag: 'DeviceManagement');
|
||||
try {
|
||||
await KRSubscribeService().kr_refreshAll();
|
||||
KRLogUtil.kr_i('✅ 订阅信息刷新成功', tag: 'DeviceManagement');
|
||||
} catch (e) {
|
||||
KRCommonUtil.kr_hideLoading();
|
||||
KRLogUtil.kr_e('订阅信息刷新失败: $e', tag: 'DeviceManagement');
|
||||
}
|
||||
KRCommonUtil.kr_hideLoading();
|
||||
Get.offAllNamed(Routes.KR_HOME);
|
||||
}
|
||||
|
||||
/// 检查并执行设备登录
|
||||
Future<bool> kr_checkAndPerformDeviceLogin() async {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user