From 396ba7043a755bdf84389a229adeb0057c6402ef Mon Sep 17 00:00:00 2001 From: XBB Date: Sun, 21 Jul 2024 15:54:42 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E9=9A=90=E8=97=8F=E6=89=98?= =?UTF-8?q?=E7=9B=98=E5=9B=BE=E6=A0=87=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaWpfGui/Constants/ConfigurationKeys.cs | 1 + src/MaaWpfGui/Res/Localizations/en-us.xaml | 2 ++ src/MaaWpfGui/Res/Localizations/ja-jp.xaml | 2 ++ src/MaaWpfGui/Res/Localizations/ko-kr.xaml | 2 ++ src/MaaWpfGui/Res/Localizations/zh-cn.xaml | 2 ++ src/MaaWpfGui/Res/Localizations/zh-tw.xaml | 2 ++ .../Services/Managers/IMainWindowManager.cs | 6 ++++++ .../Services/Managers/MainWindowManager.cs | 18 ++++++++++++++++-- .../ViewModels/UI/SettingsViewModel.cs | 18 ++++++++++++++---- src/MaaWpfGui/Views/UI/NotifyIcon.xaml | 1 + src/MaaWpfGui/Views/UI/NotifyIcon.xaml.cs | 9 +++++++++ .../UserControl/GUISettingsUserControl.xaml | 7 +++++++ 12 files changed, 64 insertions(+), 6 deletions(-) diff --git a/src/MaaWpfGui/Constants/ConfigurationKeys.cs b/src/MaaWpfGui/Constants/ConfigurationKeys.cs index eff871b089..b846b54e8c 100644 --- a/src/MaaWpfGui/Constants/ConfigurationKeys.cs +++ b/src/MaaWpfGui/Constants/ConfigurationKeys.cs @@ -30,6 +30,7 @@ namespace MaaWpfGui.Constants public const string ConfigurationCron = "Cron"; public const string Localization = "GUI.Localization"; + public const string UseTray = "GUI.UseTray"; public const string MinimizeToTray = "GUI.MinimizeToTray"; public const string HideCloseButton = "GUI.HideCloseButton"; public const string WindowTitleScrollable = "GUI.WindowTitleScrollable"; diff --git a/src/MaaWpfGui/Res/Localizations/en-us.xaml b/src/MaaWpfGui/Res/Localizations/en-us.xaml index 900bfc0b59..8027c3b680 100644 --- a/src/MaaWpfGui/Res/Localizations/en-us.xaml +++ b/src/MaaWpfGui/Res/Localizations/en-us.xaml @@ -320,6 +320,8 @@ Please do not check it when the stage OF-1 is not unlocked. Collect daily Orundum reward from the provisional mining permit Collect Special Access rewards Drone Usage + Display Tray Icon + Disable Tray Icon Hide to tray when minimized System Notification Hide close button diff --git a/src/MaaWpfGui/Res/Localizations/ja-jp.xaml b/src/MaaWpfGui/Res/Localizations/ja-jp.xaml index ec3eb63b0b..ee748d2385 100644 --- a/src/MaaWpfGui/Res/Localizations/ja-jp.xaml +++ b/src/MaaWpfGui/Res/Localizations/ja-jp.xaml @@ -323,6 +323,8 @@ 期間限定の採掘許可で毎日合成玉の報酬を受け取る スペシャルアクセス特典を集める ドローンの使用 + トレイアイコンを表示 + トレイアイコンを隠す 最小化した際にトレイに表示 重要な通知をポップアップする 「閉じる」ボタンを隠す diff --git a/src/MaaWpfGui/Res/Localizations/ko-kr.xaml b/src/MaaWpfGui/Res/Localizations/ko-kr.xaml index ca957e0de3..d1d2e66f4f 100644 --- a/src/MaaWpfGui/Res/Localizations/ko-kr.xaml +++ b/src/MaaWpfGui/Res/Localizations/ko-kr.xaml @@ -323,6 +323,8 @@ OF-1을 해금하지 않았다면 선택하지 말아 주세요. 기간 한정 채굴 허가로 매일 합성 옥 보상 받기 스페셜 액세스 보상 수집 드론 사용처 + 트레이 아이콘 표시 + 트레이 아이콘 숨기기 트레이로 최소화 중요 알림 팝업 닫기 버튼 숨기기 diff --git a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml index d8104b91db..e72c8a01c2 100644 --- a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml +++ b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml @@ -323,6 +323,8 @@ 领取限时开采许可的每日合成玉奖励 领取五周年赠送月卡奖励 无人机用途 + 显示托盘图标 + 隐藏托盘图标 最小化时隐藏至托盘 重要信息弹出系统通知 隐藏关闭按钮 diff --git a/src/MaaWpfGui/Res/Localizations/zh-tw.xaml b/src/MaaWpfGui/Res/Localizations/zh-tw.xaml index fde96a124a..549d95a8da 100644 --- a/src/MaaWpfGui/Res/Localizations/zh-tw.xaml +++ b/src/MaaWpfGui/Res/Localizations/zh-tw.xaml @@ -317,6 +317,8 @@ 領取限時開採許可的每日合成玉獎勵 領取特殊贈送月卡獎勵 無人機用途 + 顯示工作列圖標 + 隱藏工作列圖標 最小化時隱藏至工作列 重要訊息彈出系統通知 隱藏關閉按鈕 diff --git a/src/MaaWpfGui/Services/Managers/IMainWindowManager.cs b/src/MaaWpfGui/Services/Managers/IMainWindowManager.cs index 63606137fd..3f1607220b 100644 --- a/src/MaaWpfGui/Services/Managers/IMainWindowManager.cs +++ b/src/MaaWpfGui/Services/Managers/IMainWindowManager.cs @@ -52,6 +52,12 @@ namespace MaaWpfGui.Services.Managers /// Whether to minimize to taskBar. void SetMinimizeToTaskBar(bool shouldMinimizeToTaskBar); + /// + /// Sets whether to use the tray icon. + /// + /// Whether to use the tray icon. + void SetUseTrayIcon(bool useTrayIcon); + /// /// Get the main window if it is visible. /// diff --git a/src/MaaWpfGui/Services/Managers/MainWindowManager.cs b/src/MaaWpfGui/Services/Managers/MainWindowManager.cs index ab3b287f09..f1d08f6e39 100644 --- a/src/MaaWpfGui/Services/Managers/MainWindowManager.cs +++ b/src/MaaWpfGui/Services/Managers/MainWindowManager.cs @@ -15,6 +15,7 @@ using System; using System.Windows; using MaaWpfGui.Constants; using MaaWpfGui.Helper; +using MaaWpfGui.Views.UI; namespace MaaWpfGui.Services.Managers { @@ -27,10 +28,16 @@ namespace MaaWpfGui.Services.Managers private static Window MainWindow => Application.Current.MainWindow; /// - /// Gets or sets a value indicating whether whether minimize to tray. + /// Gets or sets a value indicating whether minimize to tray. /// private bool ShouldMinimizeToTaskBar { get; set; } + + /// + /// Gets or sets a value indicating whether to use tray icon. + /// + private bool ShouldUseTrayIcon { get; set; } + /// /// Initializes a new instance of the class. /// @@ -84,6 +91,13 @@ namespace MaaWpfGui.Services.Managers ShouldMinimizeToTaskBar = shouldMinimizeToTaskBar; } + /// + public void SetUseTrayIcon(bool useTrayIcon) + { + ShouldUseTrayIcon = useTrayIcon; + ((RootView)MainWindow).NotifyIcon.notifyIcon.Visibility = useTrayIcon ? Visibility.Visible : Visibility.Collapsed; + } + /// /// Handle the main window's state changed event /// @@ -91,7 +105,7 @@ namespace MaaWpfGui.Services.Managers /// The event arguments. private void MainWindowStateChanged(object sender, EventArgs e) { - if (ShouldMinimizeToTaskBar) + if (ShouldMinimizeToTaskBar && ShouldUseTrayIcon) { ChangeVisibility(MainWindow.WindowState != WindowState.Minimized); } diff --git a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs index fcaad2549b..8e40c99d06 100644 --- a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs @@ -4355,12 +4355,22 @@ namespace MaaWpfGui.ViewModels.UI new() { Display = LocalizationHelper.GetString("Switchable"), Value = "ClearInverse" }, ]; - /* + private bool _useTray = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.UseTray, bool.TrueString)); + /// - /// Gets a value indicating whether to use tray icon. + /// Gets or sets a value indicating whether to use tray icon. /// - public bool UseTray => true; - */ + public bool UseTray + { + get => _useTray; + set + { + SetAndNotify(ref _useTray, value); + ConfigurationHelper.SetValue(ConfigurationKeys.UseTray, value.ToString()); + Instances.MainWindowManager.SetUseTrayIcon(value); + } + } + private bool _minimizeToTray = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.MinimizeToTray, bool.FalseString)); diff --git a/src/MaaWpfGui/Views/UI/NotifyIcon.xaml b/src/MaaWpfGui/Views/UI/NotifyIcon.xaml index 6c9cd5501c..b575e73bf6 100644 --- a/src/MaaWpfGui/Views/UI/NotifyIcon.xaml +++ b/src/MaaWpfGui/Views/UI/NotifyIcon.xaml @@ -20,6 +20,7 @@ + diff --git a/src/MaaWpfGui/Views/UI/NotifyIcon.xaml.cs b/src/MaaWpfGui/Views/UI/NotifyIcon.xaml.cs index 850e16b99f..bf95cc223d 100644 --- a/src/MaaWpfGui/Views/UI/NotifyIcon.xaml.cs +++ b/src/MaaWpfGui/Views/UI/NotifyIcon.xaml.cs @@ -14,6 +14,7 @@ using System; using System.Windows; using System.Windows.Controls; +using MaaWpfGui.Constants; using MaaWpfGui.Helper; using MaaWpfGui.Main; using MaaWpfGui.ViewModels.UI; @@ -39,6 +40,7 @@ namespace MaaWpfGui.Views.UI private void InitIcon() { notifyIcon.Icon = AppIcon.GetIcon(); + notifyIcon.Visibility = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.UseTray, bool.TrueString)) ? Visibility.Visible : Visibility.Collapsed; notifyIcon.Click += NotifyIcon_MouseClick; notifyIcon.MouseDoubleClick += OnNotifyIconDoubleClick; @@ -46,6 +48,7 @@ namespace MaaWpfGui.Views.UI startMenu.Click += StartTask; stopMenu.Click += StopTask; forceShowMenu.Click += ForceShow; + useTrayMenu.Click += UseTray; exitMenu.Click += App_exit; foreach (var lang in LocalizationHelper.SupportedLanguages) @@ -104,6 +107,12 @@ namespace MaaWpfGui.Views.UI _logger.Information("WindowManager force show."); } + private void UseTray(object sender, RoutedEventArgs e) + { + Instances.SettingsViewModel.UseTray = !Instances.SettingsViewModel.UseTray; + _logger.Information("Use tray icon: {0}", Instances.SettingsViewModel.UseTray); + } + private void App_exit(object sender, RoutedEventArgs e) { if (Instances.TaskQueueViewModel.ConfirmExit()) diff --git a/src/MaaWpfGui/Views/UserControl/GUISettingsUserControl.xaml b/src/MaaWpfGui/Views/UserControl/GUISettingsUserControl.xaml index 0f47d50cbf..9a7916c20b 100644 --- a/src/MaaWpfGui/Views/UserControl/GUISettingsUserControl.xaml +++ b/src/MaaWpfGui/Views/UserControl/GUISettingsUserControl.xaml @@ -30,6 +30,13 @@ Margin="10" HorizontalAlignment="Left" VerticalAlignment="Center" + Content="{DynamicResource UseTray}" + IsChecked="{Binding UseTray}" /> + Date: Sun, 21 Jul 2024 23:28:04 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E4=BD=BF=E7=94=A8Visibility?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E9=9A=90=E8=97=8F=E5=88=B0=E6=89=98=E7=9B=98?= =?UTF-8?q?=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaWpfGui/Views/UserControl/GUISettingsUserControl.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MaaWpfGui/Views/UserControl/GUISettingsUserControl.xaml b/src/MaaWpfGui/Views/UserControl/GUISettingsUserControl.xaml index 9a7916c20b..99997ae69f 100644 --- a/src/MaaWpfGui/Views/UserControl/GUISettingsUserControl.xaml +++ b/src/MaaWpfGui/Views/UserControl/GUISettingsUserControl.xaml @@ -34,7 +34,7 @@ IsChecked="{Binding UseTray}" /> Date: Sun, 21 Jul 2024 23:28:38 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E4=BD=BF=E5=9C=A8=E9=9A=90=E8=97=8F?= =?UTF-8?q?=E5=88=B0=E6=89=98=E7=9B=98=E6=97=B6=E9=9A=90=E8=97=8F=E6=89=98?= =?UTF-8?q?=E7=9B=98=E5=9B=BE=E6=A0=87=E4=B8=8D=E5=8F=AF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaWpfGui/Services/Managers/MainWindowManager.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/MaaWpfGui/Services/Managers/MainWindowManager.cs b/src/MaaWpfGui/Services/Managers/MainWindowManager.cs index f1d08f6e39..5314ded5db 100644 --- a/src/MaaWpfGui/Services/Managers/MainWindowManager.cs +++ b/src/MaaWpfGui/Services/Managers/MainWindowManager.cs @@ -47,6 +47,9 @@ namespace MaaWpfGui.Services.Managers bool minimizeToTray = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.MinimizeToTray, bool.FalseString)); SetMinimizeToTaskBar(minimizeToTray); + + bool useTrayIcon = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.UseTray, bool.TrueString)); + SetUseTrayIcon(useTrayIcon); } /// @@ -127,6 +130,8 @@ namespace MaaWpfGui.Services.Managers MainWindow.ShowInTaskbar = false; MainWindow.Visibility = Visibility.Hidden; } + + ((RootView)MainWindow).NotifyIcon.useTrayMenu.Visibility = visible ? Visibility.Visible : Visibility.Collapsed; } public Window GetWindowIfVisible()