From 1c48cc5e6f0e1b1a14570298c534b9fdb6acbfdc Mon Sep 17 00:00:00 2001 From: ptt <1928627998@qq.com> Date: Sat, 29 Aug 2026 23:35:06 +0800 Subject: [PATCH 1/3] Fix theme reset window size --- .../UserSettings/Settings.cs | 6 +- .../SettingsPaneThemeViewModelTest.cs | 58 +++++++++++++++++++ .../ViewModels/SettingsPaneThemeViewModel.cs | 2 + 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 Flow.Launcher.Test/SettingsPaneThemeViewModelTest.cs diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index cca9d494262..264890b0366 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -91,7 +91,8 @@ public bool ShowOpenResultHotkey } } - public double WindowSize { get; set; } = 580; + public const double DefaultWindowSize = 580; + public double WindowSize { get; set; } = DefaultWindowSize; public string PreviewHotkey { get; set; } = $"F1"; public string AutoCompleteHotkey { get; set; } = $"{KeyConstant.Ctrl} + Tab"; public string AutoCompleteHotkey2 { get; set; } = $""; @@ -500,7 +501,8 @@ public bool KeepMaxResults } } - public int MaxResultsToShow { get; set; } = 5; + public const int DefaultMaxResultsToShow = 5; + public int MaxResultsToShow { get; set; } = DefaultMaxResultsToShow; public int ActivateTimes { get; set; } diff --git a/Flow.Launcher.Test/SettingsPaneThemeViewModelTest.cs b/Flow.Launcher.Test/SettingsPaneThemeViewModelTest.cs new file mode 100644 index 00000000000..bc7692e6b94 --- /dev/null +++ b/Flow.Launcher.Test/SettingsPaneThemeViewModelTest.cs @@ -0,0 +1,58 @@ +using System.Collections.Generic; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Threading; +using System.Windows; +using Flow.Launcher.Core.Resource; +using Flow.Launcher.Infrastructure.UserSettings; +using Flow.Launcher.Plugin; +using Flow.Launcher.SettingPages.ViewModels; +using Moq; +using NUnit.Framework; +using NUnit.Framework.Legacy; + +namespace Flow.Launcher.Test; + +[TestFixture] +internal class SettingsPaneThemeViewModelTest +{ + [Test] + [Apartment(ApartmentState.STA)] + public void GivenCustomizedSearchWindowSize_WhenThemeIsReset_ThenSizeDefaultsAndNotificationsAreRestored() + { + _ = Application.Current ?? new Application(); + var settings = new Settings + { + WindowSize = 720, + MaxResultsToShow = 8 + }; + var changedProperties = new List(); + settings.PropertyChanged += (_, args) => changedProperties.Add(args.PropertyName); + var theme = new Theme(Mock.Of(), settings); + var viewModel = CreateViewModel(settings, theme); + + viewModel.Reset(); + + ClassicAssert.AreEqual(580, settings.WindowSize); + ClassicAssert.AreEqual(5, settings.MaxResultsToShow); + CollectionAssert.AreEquivalent( + new[] { nameof(Settings.WindowSize), nameof(Settings.MaxResultsToShow) }, + changedProperties); + } + + private static SettingsPaneThemeViewModel CreateViewModel(Settings settings, Theme theme) + { + var viewModel = (SettingsPaneThemeViewModel)RuntimeHelpers.GetUninitializedObject( + typeof(SettingsPaneThemeViewModel)); + typeof(SettingsPaneThemeViewModel) + .GetField("k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic) + .SetValue(viewModel, settings); + typeof(SettingsPaneThemeViewModel) + .GetField("_theme", BindingFlags.Instance | BindingFlags.NonPublic) + .SetValue(viewModel, theme); + typeof(SettingsPaneThemeViewModel) + .GetField("DefaultFont", BindingFlags.Instance | BindingFlags.NonPublic) + .SetValue(viewModel, settings.QueryBoxFont); + return viewModel; + } +} diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs index c8c4d5fdf32..73d0a09fe6c 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs @@ -530,6 +530,8 @@ public void Reset() WindowHeightSize = 42; ItemHeightSize = 58; + Settings.WindowSize = Settings.DefaultWindowSize; + Settings.MaxResultsToShow = Settings.DefaultMaxResultsToShow; } [RelayCommand] From 2219f5b773c4ed27c54c1dc6666c90b61ae3a5db Mon Sep 17 00:00:00 2001 From: pttydou <1928627998@qq.com> Date: Thu, 3 Sep 2026 10:08:43 +0800 Subject: [PATCH 2/3] Remove theme reset unit test --- .../SettingsPaneThemeViewModelTest.cs | 58 ------------------- 1 file changed, 58 deletions(-) delete mode 100644 Flow.Launcher.Test/SettingsPaneThemeViewModelTest.cs diff --git a/Flow.Launcher.Test/SettingsPaneThemeViewModelTest.cs b/Flow.Launcher.Test/SettingsPaneThemeViewModelTest.cs deleted file mode 100644 index bc7692e6b94..00000000000 --- a/Flow.Launcher.Test/SettingsPaneThemeViewModelTest.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System.Collections.Generic; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Threading; -using System.Windows; -using Flow.Launcher.Core.Resource; -using Flow.Launcher.Infrastructure.UserSettings; -using Flow.Launcher.Plugin; -using Flow.Launcher.SettingPages.ViewModels; -using Moq; -using NUnit.Framework; -using NUnit.Framework.Legacy; - -namespace Flow.Launcher.Test; - -[TestFixture] -internal class SettingsPaneThemeViewModelTest -{ - [Test] - [Apartment(ApartmentState.STA)] - public void GivenCustomizedSearchWindowSize_WhenThemeIsReset_ThenSizeDefaultsAndNotificationsAreRestored() - { - _ = Application.Current ?? new Application(); - var settings = new Settings - { - WindowSize = 720, - MaxResultsToShow = 8 - }; - var changedProperties = new List(); - settings.PropertyChanged += (_, args) => changedProperties.Add(args.PropertyName); - var theme = new Theme(Mock.Of(), settings); - var viewModel = CreateViewModel(settings, theme); - - viewModel.Reset(); - - ClassicAssert.AreEqual(580, settings.WindowSize); - ClassicAssert.AreEqual(5, settings.MaxResultsToShow); - CollectionAssert.AreEquivalent( - new[] { nameof(Settings.WindowSize), nameof(Settings.MaxResultsToShow) }, - changedProperties); - } - - private static SettingsPaneThemeViewModel CreateViewModel(Settings settings, Theme theme) - { - var viewModel = (SettingsPaneThemeViewModel)RuntimeHelpers.GetUninitializedObject( - typeof(SettingsPaneThemeViewModel)); - typeof(SettingsPaneThemeViewModel) - .GetField("k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic) - .SetValue(viewModel, settings); - typeof(SettingsPaneThemeViewModel) - .GetField("_theme", BindingFlags.Instance | BindingFlags.NonPublic) - .SetValue(viewModel, theme); - typeof(SettingsPaneThemeViewModel) - .GetField("DefaultFont", BindingFlags.Instance | BindingFlags.NonPublic) - .SetValue(viewModel, settings.QueryBoxFont); - return viewModel; - } -} From 01212ab5ba2229bcd36fe1a8382e4809354f5918 Mon Sep 17 00:00:00 2001 From: ptt <1928627998@qq.com> Date: Thu, 3 Sep 2026 21:25:17 +0800 Subject: [PATCH 3/3] Ensure theme reset reapplies window size --- .../UserSettings/Settings.cs | 13 +++++++++++++ .../ViewModels/SettingsPaneThemeViewModel.cs | 3 +-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 264890b0366..e997df1280d 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -504,6 +504,19 @@ public bool KeepMaxResults public const int DefaultMaxResultsToShow = 5; public int MaxResultsToShow { get; set; } = DefaultMaxResultsToShow; + public void ResetSearchWindowSize() + { + if (WindowSize == DefaultWindowSize) + OnPropertyChanged(nameof(WindowSize)); + else + WindowSize = DefaultWindowSize; + + if (MaxResultsToShow == DefaultMaxResultsToShow) + OnPropertyChanged(nameof(MaxResultsToShow)); + else + MaxResultsToShow = DefaultMaxResultsToShow; + } + public int ActivateTimes { get; set; } public ObservableCollection CustomPluginHotkeys { get; set; } = new ObservableCollection(); diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs index 73d0a09fe6c..7c250c85f8f 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs @@ -530,8 +530,7 @@ public void Reset() WindowHeightSize = 42; ItemHeightSize = 58; - Settings.WindowSize = Settings.DefaultWindowSize; - Settings.MaxResultsToShow = Settings.DefaultMaxResultsToShow; + Settings.ResetSearchWindowSize(); } [RelayCommand]