diff --git a/Flow.Launcher.Infrastructure/StringMatcher.cs b/Flow.Launcher.Infrastructure/StringMatcher.cs index f5f02cbfc..55aa0a1ec 100644 --- a/Flow.Launcher.Infrastructure/StringMatcher.cs +++ b/Flow.Launcher.Infrastructure/StringMatcher.cs @@ -25,11 +25,9 @@ namespace Flow.Launcher.Infrastructure _alphabet = alphabet; } - public static StringMatcher Instance { get; internal set; } - public static MatchResult FuzzySearch(string query, string stringToCompare) { - return Instance.FuzzyMatch(query, stringToCompare); + return Ioc.Default.GetRequiredService().FuzzyMatch(query, stringToCompare); } public MatchResult FuzzyMatch(string query, string stringToCompare) diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 2a9d901fa..d3f44530c 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -3,6 +3,7 @@ using System.Collections.ObjectModel; using System.Drawing; using System.Text.Json.Serialization; using System.Windows; +using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.Infrastructure.Hotkey; using Flow.Launcher.Infrastructure.Storage; using Flow.Launcher.Plugin; @@ -14,12 +15,18 @@ namespace Flow.Launcher.Infrastructure.UserSettings public class Settings : BaseModel, IHotkeySettings { private FlowLauncherJsonStorage _storage; + private StringMatcher _stringMatcher = null; - public void Initialize(FlowLauncherJsonStorage storage) + public void SetStorage(FlowLauncherJsonStorage storage) { _storage = storage; } + public void Initialize() + { + _stringMatcher = Ioc.Default.GetRequiredService(); + } + public void Save() { _storage.Save(); @@ -192,7 +199,6 @@ namespace Flow.Launcher.Infrastructure.UserSettings } }; - /// /// when false Alphabet static service will always return empty results /// @@ -210,8 +216,8 @@ namespace Flow.Launcher.Infrastructure.UserSettings set { _querySearchPrecision = value; - if (StringMatcher.Instance != null) - StringMatcher.Instance.UserSettingSearchPrecision = value; + if (_stringMatcher != null) + _stringMatcher.UserSettingSearchPrecision = value; } } diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index b52ae7196..b435b566f 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -37,7 +37,7 @@ namespace Flow.Launcher // Initialize settings var storage = new FlowLauncherJsonStorage(); _settings = storage.Load(); - _settings.Initialize(storage); + _settings.SetStorage(storage); _settings.WMPInstalled = WindowsMediaPlayerHelper.IsWindowsMediaPlayerInstalled(); // Configure the dependency injection container @@ -55,8 +55,9 @@ namespace Flow.Launcher ).Build(); Ioc.Default.ConfigureServices(host.Services); - // Initialize the public API first + // Initialize the public API and Settings first API = Ioc.Default.GetRequiredService(); + _settings.Initialize(); } [STAThread] @@ -90,9 +91,7 @@ namespace Flow.Launcher AbstractPluginEnvironment.PreStartPluginExecutablePathUpdate(_settings); - var stringMatcher = Ioc.Default.GetRequiredService(); - StringMatcher.Instance = stringMatcher; - stringMatcher.UserSettingSearchPrecision = _settings.QuerySearchPrecision; + Ioc.Default.GetRequiredService().UserSettingSearchPrecision = _settings.QuerySearchPrecision; InternationalizationManager.Instance.Settings = _settings; InternationalizationManager.Instance.ChangeLanguage(_settings.Language);