diff --git a/src/MaaWpfGui/Helper/ToastNotification.cs b/src/MaaWpfGui/Helper/ToastNotification.cs index 3d3f82febb..4a1edd2265 100644 --- a/src/MaaWpfGui/Helper/ToastNotification.cs +++ b/src/MaaWpfGui/Helper/ToastNotification.cs @@ -64,6 +64,8 @@ namespace MaaWpfGui.Helper public static Action ShowBalloonTip { get; set; } + public static Action AddMenuItemOnFirst { get; set; } + /// /// Checks toast system. /// @@ -306,6 +308,8 @@ namespace MaaWpfGui.Helper /// 返回类本身,可继续调用其它方法 public ToastNotification AddButtonLeft(string text, Action action) { + AddMenuItemOnFirst(text, action); // TODO: 整理过时代码 + _buttonLeftText = text; _buttonLeftAction = action; _buttonSystemText = text; @@ -322,6 +326,8 @@ namespace MaaWpfGui.Helper // ReSharper disable once UnusedMember.Global public ToastNotification AddButtonRight(string text, Action action) { + AddMenuItemOnFirst(text, action); // TODO: 整理过时代码 + _buttonRightText = text; _buttonRightAction = action; _buttonSystemText = text; diff --git a/src/MaaWpfGui/Views/UI/NotifyIcon.xaml.cs b/src/MaaWpfGui/Views/UI/NotifyIcon.xaml.cs index 879a7f8b1d..f3724ea5fb 100644 --- a/src/MaaWpfGui/Views/UI/NotifyIcon.xaml.cs +++ b/src/MaaWpfGui/Views/UI/NotifyIcon.xaml.cs @@ -11,6 +11,7 @@ // but WITHOUT ANY WARRANTY // +using System; using System.Windows; using System.Windows.Controls; using MaaWpfGui.Helper; @@ -25,12 +26,15 @@ namespace MaaWpfGui.Views.UI public partial class NotifyIcon : System.Windows.Controls.UserControl { private static readonly ILogger _logger = Log.ForContext(); + private readonly int _menuItemNum; public NotifyIcon() { InitializeComponent(); InitIcon(); + _menuItemNum = notifyIcon.ContextMenu.Items.Count; ToastNotification.ShowBalloonTip = notifyIcon.ShowBalloonTip; + ToastNotification.AddMenuItemOnFirst = AddMenuItemOnFirst; } private void InitIcon() @@ -60,6 +64,20 @@ namespace MaaWpfGui.Views.UI } } + private void AddMenuItemOnFirst(string text, Action action) + { + var menuItem = new MenuItem() { Header = text }; + menuItem.Click += (sender, e) => { action?.Invoke(); }; + if (notifyIcon.ContextMenu.Items.Count == _menuItemNum) + { + notifyIcon.ContextMenu.Items.Insert(0, menuItem); + } + else + { + notifyIcon.ContextMenu.Items[0] = menuItem; + } + } + private void NotifyIcon_MouseClick(object sender, RoutedEventArgs e) { Instances.MainWindowManager?.SwitchWindowState();