From e3a90442a91d5a26b653dfb8563a29a951712998 Mon Sep 17 00:00:00 2001 From: fonaix Date: Sun, 1 Dec 2024 04:13:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=97=B6=EF=BC=8C=E9=97=AA=E4=B8=80=E4=B8=8B?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- v2rayN/v2rayN.Desktop/App.axaml.cs | 12 ++++++++++-- v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs | 4 ++++ v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs | 8 ++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) 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 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..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); } }