Skip to content

Commit e0f7722

Browse files
committed
Add StringMatcherBehaviorChanged event to Settings
Introduce StringMatcherBehaviorChanged event in Settings, triggered on changes to string matching properties. Expose the event via PublicAPIInstance for plugin subscriptions. Update Program plugin to reset cache on event, and ensure proper event unsubscription in Dispose. Refactor IgnoreAccents property for consistency.
1 parent c945d08 commit e0f7722

3 files changed

Lines changed: 47 additions & 14 deletions

File tree

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
4+
using System.ComponentModel;
45
using System.Text.Json.Serialization;
56
using System.Windows;
67
using System.Windows.Media;
@@ -30,6 +31,22 @@ public void Initialize()
3031
var settingWindowFont = new FontFamily(SettingWindowFont);
3132
Application.Current.Resources["SettingWindowFont"] = settingWindowFont;
3233
Application.Current.Resources["ContentControlThemeFontFamily"] = settingWindowFont;
34+
35+
PropertyChanged += Settings_PropertyChanged;
36+
}
37+
38+
private void Settings_PropertyChanged(object sender, PropertyChangedEventArgs e)
39+
{
40+
switch (e.PropertyName)
41+
{
42+
case nameof(QuerySearchPrecision):
43+
case nameof(ShouldUsePinyin):
44+
case nameof(UseDoublePinyin):
45+
case nameof(DoublePinyinSchema):
46+
case nameof(IgnoreAccents):
47+
StringMatcherBehaviorChanged?.Invoke(this, EventArgs.Empty);
48+
break;
49+
}
3350
}
3451

3552
public void Save()
@@ -357,20 +374,6 @@ public bool ShouldUsePinyin
357374
}
358375
}
359376

360-
private bool _IgnoreAccents = false;
361-
public bool IgnoreAccents
362-
{
363-
get => _IgnoreAccents;
364-
set
365-
{
366-
if (_IgnoreAccents != value)
367-
{
368-
_IgnoreAccents = value;
369-
OnPropertyChanged();
370-
}
371-
}
372-
}
373-
374377
private bool _useDoublePinyin = false;
375378
public bool UseDoublePinyin
376379
{
@@ -420,6 +423,20 @@ public SearchPrecisionScore QuerySearchPrecision
420423
}
421424
}
422425

426+
private bool _IgnoreAccents = false;
427+
public bool IgnoreAccents
428+
{
429+
get => _IgnoreAccents;
430+
set
431+
{
432+
if (_IgnoreAccents != value)
433+
{
434+
_IgnoreAccents = value;
435+
OnPropertyChanged();
436+
}
437+
}
438+
}
439+
423440
public bool AutoUpdates { get; set; } = false;
424441

425442
public double WindowLeft { get; set; }

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,12 @@ public event ActualApplicationThemeChangedEventHandler ActualApplicationThemeCha
623623

624624
public string GetLogDirectory() => DataLocation.VersionLogDirectory;
625625

626+
public event EventHandler StringMatcherBehaviorChanged
627+
{
628+
add => _settings.StringMatcherBehaviorChanged += value;
629+
remove => _settings.StringMatcherBehaviorChanged -= value;
630+
}
631+
626632
#endregion
627633

628634
#region Private Methods

Plugins/Flow.Launcher.Plugin.Program/Main.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,22 @@ static void MoveFile(string sourcePath, string destinationPath)
327327
WatchProgramUpdate();
328328
}
329329

330+
Context.API.StringMatcherBehaviorChanged += API_StringMatcherBehaviorChanged;
331+
330332
static void WatchProgramUpdate()
331333
{
332334
Win32.WatchProgramUpdate(_settings);
333335
_ = UWPPackage.WatchPackageChangeAsync();
334336
}
335337
}
336338

339+
private void API_StringMatcherBehaviorChanged(object sender, EventArgs e)
340+
{
341+
// Since cache stores the search results based on the old string matcher behavior,
342+
// we need to reset the cache when the string matcher behavior changes
343+
ResetCache();
344+
}
345+
337346
public static async Task IndexWin32ProgramsAsync(bool resetCache)
338347
{
339348
await _win32sLock.WaitAsync();
@@ -558,6 +567,7 @@ public async Task ReloadDataAsync()
558567

559568
public void Dispose()
560569
{
570+
Context.API.StringMatcherBehaviorChanged -= API_StringMatcherBehaviorChanged;
561571
Win32.Dispose();
562572
}
563573
}

0 commit comments

Comments
 (0)