feat: 在托盘图标右键前往 Release 页

This commit is contained in:
枫雨
2023-08-30 22:31:28 +08:00
committed by uye
parent 240cd9069a
commit 7e19caa2f6
2 changed files with 24 additions and 0 deletions

View File

@@ -64,6 +64,8 @@ namespace MaaWpfGui.Helper
public static Action<string, string, NotifyIconInfoType> ShowBalloonTip { get; set; }
public static Action<string, Action> AddMenuItemOnFirst { get; set; }
/// <summary>
/// Checks toast system.
/// </summary>
@@ -306,6 +308,8 @@ namespace MaaWpfGui.Helper
/// <returns>返回类本身,可继续调用其它方法</returns>
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;

View File

@@ -11,6 +11,7 @@
// but WITHOUT ANY WARRANTY
// </copyright>
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<NotifyIcon>();
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();