From 40c90d5b3b9c41b230c340e9c364030173a3c152 Mon Sep 17 00:00:00 2001 From: Weheal <77955152+Waheal@users.noreply.github.com> Date: Tue, 7 Oct 2025 10:02:53 +0800 Subject: [PATCH] Fix: AutoHideStartup's bug of displaying window before hiding it. (#8083) * Fix: AutoHideStartup's bug of displaying window before hiding it. * Disable AutoHideStartup for Linux * Revert "Disable AutoHideStartup for Linux" This reverts commit 09f27e345575f9044c035a7fea055a83f5136fa2. --------- Co-authored-by: 2dust <31833384+2dust@users.noreply.github.com> --- v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs | 4 +++- v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs | 11 +++++++++++ v2rayN/v2rayN/Views/MainWindow.xaml.cs | 10 ++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index 06ca3184..f938bf45 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -274,7 +274,7 @@ public class MainWindowViewModel : MyReactiveObject BlReloadEnabled = true; await Reload(); - await AutoHideStartup(); + // await AutoHideStartup(); } #endregion Init @@ -576,6 +576,7 @@ public class MainWindowViewModel : MyReactiveObject await CoreManager.Instance.LoadCore(node); } + /* private async Task AutoHideStartup() { if (_config.UiItem.AutoHideStartup) @@ -584,6 +585,7 @@ public class MainWindowViewModel : MyReactiveObject } await Task.CompletedTask; } + */ #endregion core job diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs index 82d33833..169bd8da 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs @@ -31,6 +31,12 @@ public partial class MainWindow : WindowBase _config = AppManager.Instance.Config; _manager = new WindowNotificationManager(TopLevel.GetTopLevel(this)) { MaxItems = 3, Position = NotificationPosition.TopRight }; + if (_config.UiItem.AutoHideStartup) + { + this.ShowActivated = false; + this.WindowState = WindowState.Minimized; + } + this.KeyDown += MainWindow_KeyDown; menuSettingsSetUWP.Click += menuSettingsSetUWP_Click; menuPromotion.Click += menuPromotion_Click; @@ -438,6 +444,11 @@ public partial class MainWindow : WindowBase protected override void OnLoaded(object? sender, RoutedEventArgs e) { base.OnLoaded(sender, e); + if (_config.UiItem.AutoHideStartup) + { + this.ShowHideWindow(false); + _config.UiItem.ShowInTaskbar = true; + } RestoreUI(); } diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml.cs b/v2rayN/v2rayN/Views/MainWindow.xaml.cs index c7fbaf86..c4201275 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/MainWindow.xaml.cs @@ -25,6 +25,12 @@ public partial class MainWindow _config = AppManager.Instance.Config; ThreadPool.RegisterWaitForSingleObject(App.ProgramStarted, OnProgramStarted, null, -1, false); + if (_config.UiItem.AutoHideStartup) + { + this.ShowActivated = false; + this.WindowState = WindowState.Minimized; + } + App.Current.SessionEnding += Current_SessionEnding; this.Closing += MainWindow_Closing; this.PreviewKeyDown += MainWindow_PreviewKeyDown; @@ -390,6 +396,10 @@ public partial class MainWindow protected override void OnLoaded(object? sender, RoutedEventArgs e) { base.OnLoaded(sender, e); + if (_config.UiItem.AutoHideStartup) + { + ShowHideWindow(false); + } RestoreUI(); }