mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-17 18:01:26 +08:00
@@ -12,13 +12,14 @@
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Timers;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using MaaWpfGui.Constants;
|
||||
using MaaWpfGui.Helper;
|
||||
using MaaWpfGui.Main;
|
||||
using MaaWpfGui.ViewModels.UI;
|
||||
using MaaWpfGui.ViewModels.UserControl.Settings;
|
||||
using Serilog;
|
||||
|
||||
namespace MaaWpfGui.Views.UI
|
||||
@@ -30,10 +31,24 @@ namespace MaaWpfGui.Views.UI
|
||||
{
|
||||
private static readonly ILogger _logger = Log.ForContext<NotifyIcon>();
|
||||
private readonly int _menuItemNum;
|
||||
private static Timer _clickTimer;
|
||||
private static bool _canClick = true;
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern uint GetDoubleClickTime();
|
||||
|
||||
public NotifyIcon()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
uint doubleClickTime = GetDoubleClickTime();
|
||||
_clickTimer = new(doubleClickTime);
|
||||
_clickTimer.AutoReset = false;
|
||||
_clickTimer.Elapsed += (s, e) =>
|
||||
{
|
||||
_canClick = true;
|
||||
};
|
||||
|
||||
InitIcon();
|
||||
if (notifyIcon.ContextMenu is not null)
|
||||
{
|
||||
@@ -47,7 +62,7 @@ namespace MaaWpfGui.Views.UI
|
||||
notifyIcon.Visibility = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.UseTray, bool.TrueString)) ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
notifyIcon.Click += NotifyIcon_MouseClick;
|
||||
notifyIcon.MouseDoubleClick += OnNotifyIconDoubleClick;
|
||||
notifyIcon.MouseDoubleClick += NotifyIcon_MouseClick;
|
||||
|
||||
startMenu.Click += StartTask;
|
||||
stopMenu.Click += StopTask;
|
||||
@@ -96,6 +111,13 @@ namespace MaaWpfGui.Views.UI
|
||||
|
||||
private static void NotifyIcon_MouseClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!_canClick)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_clickTimer.Start();
|
||||
_canClick = false;
|
||||
Instances.MainWindowManager?.SwitchWindowState();
|
||||
}
|
||||
|
||||
@@ -147,10 +169,5 @@ namespace MaaWpfGui.Views.UI
|
||||
{
|
||||
Instances.MainWindowManager?.Show();
|
||||
}
|
||||
|
||||
private static void OnNotifyIconDoubleClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
App_show(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user