From 09b68ada48f83c129fa1574ab0cdcd170eee937b Mon Sep 17 00:00:00 2001 From: home-PC Date: Tue, 19 May 2026 02:03:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(tray):=20=E6=94=AF=E6=8C=81=E9=9D=99?= =?UTF-8?q?=E9=BB=98=E5=90=AF=E5=8A=A8=E5=92=8C=E6=89=98=E7=9B=98=E5=8D=95?= =?UTF-8?q?=E5=87=BB=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 启动应用时不再自动打开主界面,方便配合开机自启在后台运行。 托盘左键单击现在会根据主界面显示状态进行打开或隐藏,保留托盘菜单和二次启动唤起主界面的行为。 --- App.xaml.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/App.xaml.cs b/App.xaml.cs index efa027c..d09da39 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -48,7 +48,6 @@ public partial class App : System.Windows.Application _server.Start(State.Settings.LocalPort); CreateTrayIcon(); - ShowMainWindow(); } public void SaveState() @@ -69,6 +68,17 @@ public partial class App : System.Windows.Application MainWindow.Activate(); } + public void ToggleMainWindow() + { + if (MainWindow?.IsVisible == true) + { + MainWindow.Hide(); + return; + } + + ShowMainWindow(); + } + private void RegisterActivationListener() { if (_activateEvent is null) @@ -96,7 +106,7 @@ public partial class App : System.Windows.Application { if (args.Button == Forms.MouseButtons.Left) { - Dispatcher.Invoke(ShowMainWindow); + Dispatcher.Invoke(ToggleMainWindow); } }; UpdateTrayMenu();