From d08b3f4d4d9d7bfafc9e036b99db9f34e25309e7 Mon Sep 17 00:00:00 2001 From: uye <99072975+ABA2396@users.noreply.github.com> Date: Fri, 2 Aug 2024 21:01:00 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MAA.sln.DotSettings | 3 +- src/MaaWpfGui/Views/UI/NotifyIcon.xaml.cs | 42 +++++++++++++++-------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/MAA.sln.DotSettings b/MAA.sln.DotSettings index 237d1451e0..1fa37b254d 100644 --- a/MAA.sln.DotSettings +++ b/MAA.sln.DotSettings @@ -1,4 +1,4 @@ - + EN KR JP @@ -32,6 +32,7 @@ XYAZ True True + True True True True diff --git a/src/MaaWpfGui/Views/UI/NotifyIcon.xaml.cs b/src/MaaWpfGui/Views/UI/NotifyIcon.xaml.cs index 3f758dd767..c178656fa0 100644 --- a/src/MaaWpfGui/Views/UI/NotifyIcon.xaml.cs +++ b/src/MaaWpfGui/Views/UI/NotifyIcon.xaml.cs @@ -25,7 +25,7 @@ namespace MaaWpfGui.Views.UI /// /// 托盘图标。 /// - public partial class NotifyIcon : System.Windows.Controls.UserControl + public partial class NotifyIcon { private static readonly ILogger _logger = Log.ForContext(); private readonly int _menuItemNum; @@ -34,7 +34,10 @@ namespace MaaWpfGui.Views.UI { InitializeComponent(); InitIcon(); - _menuItemNum = notifyIcon.ContextMenu.Items.Count; + if (notifyIcon.ContextMenu is not null) + { + _menuItemNum = notifyIcon.ContextMenu.Items.Count; + } } private void InitIcon() @@ -60,7 +63,7 @@ namespace MaaWpfGui.Views.UI } var langMenu = new MenuItem() { Header = lang.Value }; - langMenu.Click += (sender, e) => + langMenu.Click += (_, _) => { Instances.SettingsViewModel.Language = lang.Key; }; @@ -69,10 +72,17 @@ namespace MaaWpfGui.Views.UI } } + // 不知道是干嘛的,先留着 + // ReSharper disable once UnusedMember.Local private void AddMenuItemOnFirst(string text, Action action) { - var menuItem = new MenuItem() { Header = text }; - menuItem.Click += (sender, e) => { action?.Invoke(); }; + var menuItem = new MenuItem { Header = text }; + menuItem.Click += (_, _) => { action?.Invoke(); }; + if (notifyIcon.ContextMenu is null) + { + return; + } + if (notifyIcon.ContextMenu.Items.Count == _menuItemNum) { notifyIcon.ContextMenu.Items.Insert(0, menuItem); @@ -83,12 +93,12 @@ namespace MaaWpfGui.Views.UI } } - private void NotifyIcon_MouseClick(object sender, RoutedEventArgs e) + private static void NotifyIcon_MouseClick(object sender, RoutedEventArgs e) { Instances.MainWindowManager?.SwitchWindowState(); } - private void StartTask(object sender, RoutedEventArgs e) + private static void StartTask(object sender, RoutedEventArgs e) { // taskQueueViewModel意外为null了是不是也可以考虑Log一下 // 先放个log点方便跟踪 @@ -96,25 +106,25 @@ namespace MaaWpfGui.Views.UI _logger.Information("Tray service task started."); } - private void StopTask(object sender, RoutedEventArgs e) + private static void StopTask(object sender, RoutedEventArgs e) { Instances.TaskQueueViewModel?.Stop(); _logger.Information("Tray service task stop."); } - private void ForceShow(object sender, RoutedEventArgs e) + private static void ForceShow(object sender, RoutedEventArgs e) { Instances.MainWindowManager?.ForceShow(); _logger.Information("WindowManager force show."); } - private void UseTray(object sender, RoutedEventArgs e) + private static void UseTray(object sender, RoutedEventArgs e) { Instances.SettingsViewModel.UseTray = !Instances.SettingsViewModel.UseTray; _logger.Information("Use tray icon: {0}", Instances.SettingsViewModel.UseTray); } - private void App_restart(object sender, RoutedEventArgs e) + private static void App_restart(object sender, RoutedEventArgs e) { if (Instances.TaskQueueViewModel.ConfirmExit()) { @@ -122,7 +132,7 @@ namespace MaaWpfGui.Views.UI } } - private void App_exit(object sender, RoutedEventArgs e) + private static void App_exit(object sender, RoutedEventArgs e) { if (Instances.TaskQueueViewModel.ConfirmExit()) { @@ -130,14 +140,16 @@ namespace MaaWpfGui.Views.UI } } - private void App_show(object sender, RoutedEventArgs e) + // ReSharper disable UnusedParameter.Local + private static void App_show(object sender, RoutedEventArgs e) { Instances.MainWindowManager?.Show(); } + // ReSharper restore UnusedParameter.Local - private void OnNotifyIconDoubleClick(object sender, RoutedEventArgs e) + private static void OnNotifyIconDoubleClick(object sender, RoutedEventArgs e) { - Instances.MainWindowManager?.Show(); + App_show(sender, e); } } }