From 1ff4839be13cf0efcad04dbd9682c03a3d6059f3 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 29 Nov 2024 11:31:22 +0800 Subject: [PATCH] Bug fix https://github.com/2dust/v2rayN/issues/6160 --- v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs | 6 ++++-- v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index 3be5dcaa..9b016ca6 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -283,7 +283,6 @@ namespace ServiceLib.ViewModels try { Logging.SaveLog("MyAppExit Begin"); - //if (blWindowsShutDown) await SysProxyHandler.UpdateSysProxy(_config, true); await ConfigHandler.SaveConfig(_config); @@ -297,7 +296,10 @@ namespace ServiceLib.ViewModels catch { } finally { - _updateView?.Invoke(EViewAction.Shutdown, null); + if (!blWindowsShutDown) + { + _updateView?.Invoke(EViewAction.Shutdown, null); + } } } diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs index eebc9362..95f587bf 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs @@ -21,6 +21,7 @@ namespace v2rayN.Desktop.Views private WindowNotificationManager? _manager; private CheckUpdateView? _checkUpdateView; private BackupAndRestoreView? _backupAndRestoreView; + private bool _blCloseByUser = false; public MainWindow() { @@ -279,6 +280,11 @@ namespace v2rayN.Desktop.Views protected override async void OnClosing(WindowClosingEventArgs e) { + if (_blCloseByUser) + { + return; + } + Logging.SaveLog("OnClosing -> " + e.CloseReason.ToString()); switch (e.CloseReason) @@ -374,6 +380,8 @@ namespace v2rayN.Desktop.Views { return; } + + _blCloseByUser = true; StorageUI(); await ViewModel?.MyAppExitAsync(false);