diff --git a/v2rayN/v2rayN.Desktop/App.axaml.cs b/v2rayN/v2rayN.Desktop/App.axaml.cs index 898de4e8..d3bbde67 100644 --- a/v2rayN/v2rayN.Desktop/App.axaml.cs +++ b/v2rayN/v2rayN.Desktop/App.axaml.cs @@ -33,7 +33,15 @@ public partial class App : Application AppHandler.Instance.InitComponents(); desktop.Exit += OnExit; - desktop.MainWindow = new MainWindow(); + var mainWindow = new MainWindow(); + if (!AppHandler.Instance.Config.UiItem.AutoHideStartup) + { + desktop.MainWindow = mainWindow; + } + else + { + desktop.MainWindow = null; + } } base.OnFrameworkInitializationCompleted(); diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs index 95f587bf..225de77f 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs @@ -397,6 +397,10 @@ namespace v2rayN.Desktop.Views if (bl) { this.Show(); + if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + desktop.MainWindow = this; + } if (this.WindowState == WindowState.Minimized) { this.WindowState = WindowState.Normal; diff --git a/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs index f97e0e85..1fdf2791 100644 --- a/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs @@ -77,10 +77,13 @@ namespace v2rayN.Desktop.Views { if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { - desktop.MainWindow.Icon = AvaUtils.GetAppIcon(_config.SystemProxyItem.SysProxyType); - var iconslist = TrayIcon.GetIcons(Application.Current); - iconslist[0].Icon = desktop.MainWindow.Icon; - TrayIcon.SetIcons(Application.Current, iconslist); + if (desktop.MainWindow != null) + { + desktop.MainWindow.Icon = AvaUtils.GetAppIcon(_config.SystemProxyItem.SysProxyType); + var iconslist = TrayIcon.GetIcons(Application.Current); + iconslist[0].Icon = desktop.MainWindow.Icon; + TrayIcon.SetIcons(Application.Current, iconslist); + } } }