mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 17:57:01 +08:00
feat: 在托盘图标右键前往 Release 页
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user