From 79452921282887aac22de6d5891067aaae382e48 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 24 Apr 2025 22:01:38 +0800 Subject: [PATCH] Update context menu font when setting is changed --- .../UserSettings/Settings.cs | 1 - Flow.Launcher/MainWindow.xaml.cs | 76 +++++++++++-------- 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index e623ba400..cf194b366 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -115,7 +115,6 @@ namespace Flow.Launcher.Infrastructure.UserSettings _settingWindowFont = value; Application.Current.Resources["SettingWindowFont"] = new FontFamily(value); Application.Current.Resources["ContentControlThemeFontFamily"] = new FontFamily(value); - // TODO: Context Menu Font } } } diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index bf7a45b1d..ae05d1124 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -140,7 +140,8 @@ namespace Flow.Launcher _viewModel.Show(); } - // Show notify icon when flowlauncher is hidden + // Initialize context menu & notify icon + InitializeContextMenu(); InitializeNotifyIcon(); // Initialize color scheme @@ -270,6 +271,9 @@ namespace Flow.Launcher case nameof(Settings.KeepMaxResults): SetupResizeMode(); break; + case nameof(Settings.SettingWindowFont): + InitializeContextMenu(); + break; } }; @@ -563,6 +567,44 @@ namespace Flow.Launcher Icon = Constant.Version == "1.0.0" ? Properties.Resources.dev : Properties.Resources.app, Visible = !_settings.HideNotifyIcon }; + + _notifyIcon.MouseClick += (o, e) => + { + switch (e.Button) + { + case MouseButtons.Left: + _viewModel.ToggleFlowLauncher(); + break; + case MouseButtons.Right: + + _contextMenu.IsOpen = true; + // Get context menu handle and bring it to the foreground + if (PresentationSource.FromVisual(_contextMenu) is HwndSource hwndSource) + { + Win32Helper.SetForegroundWindow(hwndSource.Handle); + } + + _contextMenu.Focus(); + break; + } + }; + } + + private void UpdateNotifyIconText() + { + var menu = _contextMenu; + ((MenuItem)menu.Items[0]).Header = App.API.GetTranslation("iconTrayOpen") + + " (" + _settings.Hotkey + ")"; + ((MenuItem)menu.Items[1]).Header = App.API.GetTranslation("GameMode"); + ((MenuItem)menu.Items[2]).Header = App.API.GetTranslation("PositionReset"); + ((MenuItem)menu.Items[3]).Header = App.API.GetTranslation("iconTraySettings"); + ((MenuItem)menu.Items[4]).Header = App.API.GetTranslation("iconTrayExit"); + } + + private void InitializeContextMenu() + { + var menu = _contextMenu; + menu.Items.Clear(); var openIcon = new FontIcon { Glyph = "\ue71e" }; var open = new MenuItem { @@ -608,38 +650,6 @@ namespace Flow.Launcher _contextMenu.Items.Add(positionreset); _contextMenu.Items.Add(settings); _contextMenu.Items.Add(exit); - - _notifyIcon.MouseClick += (o, e) => - { - switch (e.Button) - { - case MouseButtons.Left: - _viewModel.ToggleFlowLauncher(); - break; - case MouseButtons.Right: - - _contextMenu.IsOpen = true; - // Get context menu handle and bring it to the foreground - if (PresentationSource.FromVisual(_contextMenu) is HwndSource hwndSource) - { - Win32Helper.SetForegroundWindow(hwndSource.Handle); - } - - _contextMenu.Focus(); - break; - } - }; - } - - private void UpdateNotifyIconText() - { - var menu = _contextMenu; - ((MenuItem)menu.Items[0]).Header = App.API.GetTranslation("iconTrayOpen") + - " (" + _settings.Hotkey + ")"; - ((MenuItem)menu.Items[1]).Header = App.API.GetTranslation("GameMode"); - ((MenuItem)menu.Items[2]).Header = App.API.GetTranslation("PositionReset"); - ((MenuItem)menu.Items[3]).Header = App.API.GetTranslation("iconTraySettings"); - ((MenuItem)menu.Items[4]).Header = App.API.GetTranslation("iconTrayExit"); } #endregion