diff --git a/v2rayN/v2rayN.Desktop/App.axaml.cs b/v2rayN/v2rayN.Desktop/App.axaml.cs index 898de4e8..192434f9 100644 --- a/v2rayN/v2rayN.Desktop/App.axaml.cs +++ b/v2rayN/v2rayN.Desktop/App.axaml.cs @@ -31,9 +31,17 @@ public partial class App : Application if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { AppHandler.Instance.InitComponents(); - + desktop.ShutdownMode = Avalonia.Controls.ShutdownMode.OnExplicitShutdown; 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 fa214786..7699692b 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs @@ -396,6 +396,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..f1c07e88 100644 --- a/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs @@ -77,9 +77,13 @@ namespace v2rayN.Desktop.Views { if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { - desktop.MainWindow.Icon = AvaUtils.GetAppIcon(_config.SystemProxyItem.SysProxyType); + var icon = AvaUtils.GetAppIcon(_config.SystemProxyItem.SysProxyType); + if (desktop.MainWindow != null) + { + desktop.MainWindow.Icon = icon; + } var iconslist = TrayIcon.GetIcons(Application.Current); - iconslist[0].Icon = desktop.MainWindow.Icon; + iconslist[0].Icon = icon; TrayIcon.SetIcons(Application.Current, iconslist); } }