Skip to content

Commit c945d08

Browse files
committed
Update StringMatcher to react to QuerySearchPrecision changes
StringMatcher now listens to Settings.PropertyChanged and updates UserSettingSearchPrecision when QuerySearchPrecision changes. Removed direct assignment from Settings setter to centralize update logic within StringMatcher.
1 parent 4cbe223 commit c945d08

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

Flow.Launcher.Infrastructure/StringMatcher.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ public StringMatcher(IAlphabet alphabet, Settings settings)
2121
_alphabet = alphabet;
2222
_settings = settings;
2323
UserSettingSearchPrecision = _settings.QuerySearchPrecision;
24+
25+
_settings.PropertyChanged += (sender, e) =>
26+
{
27+
switch (e.PropertyName)
28+
{
29+
case nameof(Settings.QuerySearchPrecision):
30+
UserSettingSearchPrecision = _settings.QuerySearchPrecision;
31+
break;
32+
}
33+
};
2434
}
2535

2636
// This is a workaround to allow unit tests to set the instance

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Collections.ObjectModel;
34
using System.Text.Json.Serialization;
45
using System.Windows;
56
using System.Windows.Media;
6-
using CommunityToolkit.Mvvm.DependencyInjection;
77
using Flow.Launcher.Infrastructure.Hotkey;
88
using Flow.Launcher.Infrastructure.Logger;
99
using Flow.Launcher.Infrastructure.Storage;
@@ -16,7 +16,8 @@ namespace Flow.Launcher.Infrastructure.UserSettings
1616
public class Settings : BaseModel, IHotkeySettings
1717
{
1818
private FlowLauncherJsonStorage<Settings> _storage;
19-
private StringMatcher _stringMatcher = null;
19+
20+
public event EventHandler StringMatcherBehaviorChanged;
2021

2122
public void SetStorage(FlowLauncherJsonStorage<Settings> storage)
2223
{
@@ -25,9 +26,6 @@ public void SetStorage(FlowLauncherJsonStorage<Settings> storage)
2526

2627
public void Initialize()
2728
{
28-
// Initialize dependency injection instances after Ioc.Default is created
29-
_stringMatcher = Ioc.Default.GetRequiredService<StringMatcher>();
30-
3129
// Initialize application resources after application is created
3230
var settingWindowFont = new FontFamily(SettingWindowFont);
3331
Application.Current.Resources["SettingWindowFont"] = settingWindowFont;
@@ -417,8 +415,7 @@ public SearchPrecisionScore QuerySearchPrecision
417415
if (_querySearchPrecision != value)
418416
{
419417
_querySearchPrecision = value;
420-
if (_stringMatcher != null)
421-
_stringMatcher.UserSettingSearchPrecision = value;
418+
OnPropertyChanged();
422419
}
423420
}
424421
}

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,5 +637,10 @@ public interface IPublicAPI
637637
/// </summary>
638638
/// <returns></returns>
639639
string GetLogDirectory();
640+
641+
/// <summary>
642+
/// Invoked when the behavior of string matcher has changed which can effect the result of <see cref="MatchResult"/>.
643+
/// </summary>
644+
event EventHandler StringMatcherBehaviorChanged;
640645
}
641646
}

0 commit comments

Comments
 (0)