From bfa67e8a7352a2ca29bc95fc8e3fd87fe46be835 Mon Sep 17 00:00:00 2001 From: speakeloudest Date: Mon, 12 Jan 2026 20:34:11 -0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=80=80=E5=87=BA=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0vpn=E6=98=AF=E5=90=A6=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hi_user_info/views/hi_user_info_view.dart | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/app/modules/hi_user_info/views/hi_user_info_view.dart b/lib/app/modules/hi_user_info/views/hi_user_info_view.dart index cbab546..f557686 100755 --- a/lib/app/modules/hi_user_info/views/hi_user_info_view.dart +++ b/lib/app/modules/hi_user_info/views/hi_user_info_view.dart @@ -20,6 +20,9 @@ import 'package:kaer_with_panels/app/modules/kr_home/controllers/kr_home_control import 'package:kaer_with_panels/app/widgets/dialogs/hi_dialog.dart'; import 'package:kaer_with_panels/app/common/app_config.dart'; import 'package:kaer_with_panels/app/widgets/kr_subscription_expiry_text.dart'; +import 'package:kaer_with_panels/singbox/model/singbox_status.dart'; +import 'package:kaer_with_panels/app/services/singbox_imp/kr_sing_box_imp.dart'; +import 'package:kaer_with_panels/app/utils/kr_log_util.dart'; class HIUserInfoView extends GetView { const HIUserInfoView({super.key}); @@ -75,7 +78,8 @@ class HIUserInfoView extends GetView { .value; final isDeviceLogin = account != null && account.startsWith('9000'); - final accountText = (account ==null || isDeviceLogin) + final accountText = (account == null || + isDeviceLogin) ? '待绑定' : '${KRAppRunData.getInstance().kr_account.value.toString()}'; return Text( @@ -316,6 +320,8 @@ class HIUserInfoView extends GetView { cancelText: '确认', confirmText: '返回', onCancel: () async { + // 如果删的是当前设备,应该先关闭vpn的连接 + await _stopVpnIfRunning(); final currentDevice = controller.devices.firstWhere( (device) => device['is_current'] == true, @@ -500,7 +506,7 @@ class HIUserInfoView extends GetView { confirmText: KRAppRunData.getInstance().isDeviceLogin() ? '前往' : null, cancelText: KRAppRunData.getInstance().isDeviceLogin() ? '取消' : null, onConfirm: () { - if(KRAppRunData.getInstance().isDeviceLogin()) { + if (KRAppRunData.getInstance().isDeviceLogin()) { Get.toNamed( Routes.MR_LOGIN, arguments: {'entry': 'bind_email'}, @@ -606,4 +612,16 @@ class HIUserInfoView extends GetView { return Icons.devices; } } + + /// 停止VPN如果正在运行 + Future _stopVpnIfRunning() async { + try { + if (KRSingBoxImp.instance.kr_status.value is SingboxStarted) { + KRLogUtil.kr_i('正在删除当前设备,先停止 VPN 连接...', tag: 'HIUserInfoView'); + await KRSingBoxImp.instance.kr_stop(); + } + } catch (e) { + KRLogUtil.kr_e('停止 VPN 失败: $e', tag: 'HIUserInfoView'); + } + } }