feat(tray): 支持静默启动和托盘单击切换
启动应用时不再自动打开主界面,方便配合开机自启在后台运行。 托盘左键单击现在会根据主界面显示状态进行打开或隐藏,保留托盘菜单和二次启动唤起主界面的行为。
This commit is contained in:
14
App.xaml.cs
14
App.xaml.cs
@@ -48,7 +48,6 @@ public partial class App : System.Windows.Application
|
|||||||
_server.Start(State.Settings.LocalPort);
|
_server.Start(State.Settings.LocalPort);
|
||||||
|
|
||||||
CreateTrayIcon();
|
CreateTrayIcon();
|
||||||
ShowMainWindow();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveState()
|
public void SaveState()
|
||||||
@@ -69,6 +68,17 @@ public partial class App : System.Windows.Application
|
|||||||
MainWindow.Activate();
|
MainWindow.Activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ToggleMainWindow()
|
||||||
|
{
|
||||||
|
if (MainWindow?.IsVisible == true)
|
||||||
|
{
|
||||||
|
MainWindow.Hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ShowMainWindow();
|
||||||
|
}
|
||||||
|
|
||||||
private void RegisterActivationListener()
|
private void RegisterActivationListener()
|
||||||
{
|
{
|
||||||
if (_activateEvent is null)
|
if (_activateEvent is null)
|
||||||
@@ -96,7 +106,7 @@ public partial class App : System.Windows.Application
|
|||||||
{
|
{
|
||||||
if (args.Button == Forms.MouseButtons.Left)
|
if (args.Button == Forms.MouseButtons.Left)
|
||||||
{
|
{
|
||||||
Dispatcher.Invoke(ShowMainWindow);
|
Dispatcher.Invoke(ToggleMainWindow);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
UpdateTrayMenu();
|
UpdateTrayMenu();
|
||||||
|
|||||||
Reference in New Issue
Block a user