diff --git a/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs b/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs index da92a3583..7fb9b895a 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs @@ -120,10 +120,9 @@ namespace Flow.Launcher.Infrastructure.UserSettings public int Priority { get; set; } [JsonIgnore] - public SearchDelayTime? DefaultSearchDelayTime { get; set; } + public int? DefaultSearchDelayTime { get; set; } - [JsonConverter(typeof(JsonStringEnumConverter))] - public SearchDelayTime? SearchDelayTime { get; set; } + public int? SearchDelayTime { get; set; } /// /// Used only to save the state of the plugin in settings diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 6cb20d12f..d89340e19 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -322,8 +322,10 @@ namespace Flow.Launcher.Infrastructure.UserSettings public bool SearchQueryResultsWithDelay { get; set; } - [JsonConverter(typeof(JsonStringEnumConverter))] - public SearchDelayTime SearchDelayTime { get; set; } = SearchDelayTime.Normal; + [JsonIgnore] + public IEnumerable SearchDelayTimeRange = new List { 50, 100, 150, 200, 250, 300, 350, 400, 450, 500 }; + + public int SearchDelayTime { get; set; } = 150; [JsonConverter(typeof(JsonStringEnumConverter))] public SearchWindowScreens SearchWindowScreen { get; set; } = SearchWindowScreens.Cursor; diff --git a/Flow.Launcher.Plugin/PluginMetadata.cs b/Flow.Launcher.Plugin/PluginMetadata.cs index 1496765ce..da10bc6a5 100644 --- a/Flow.Launcher.Plugin/PluginMetadata.cs +++ b/Flow.Launcher.Plugin/PluginMetadata.cs @@ -99,10 +99,9 @@ namespace Flow.Launcher.Plugin public bool HideActionKeywordPanel { get; set; } /// - /// Plugin search delay time. Null means use default search delay time. + /// Plugin search delay time in ms. Null means use default search delay time. /// - [JsonConverter(typeof(JsonStringEnumConverter))] - public SearchDelayTime? SearchDelayTime { get; set; } = null; + public int? SearchDelayTime { get; set; } = null; /// /// Plugin icon path. diff --git a/Flow.Launcher.Plugin/SearchDelayTime.cs b/Flow.Launcher.Plugin/SearchDelayTime.cs deleted file mode 100644 index ae1daabe0..000000000 --- a/Flow.Launcher.Plugin/SearchDelayTime.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace Flow.Launcher.Plugin; - -/// -/// Enum for search delay time -/// -public enum SearchDelayTime -{ - /// - /// Very long search delay time. 250ms. - /// - VeryLong, - - /// - /// Long search delay time. 200ms. - /// - Long, - - /// - /// Normal search delay time. 150ms. Default value. - /// - Normal, - - /// - /// Short search delay time. 100ms. - /// - Short, - - /// - /// Very short search delay time. 50ms. - /// - VeryShort -} diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index 78486dad4..5d9b16e0b 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -380,9 +380,7 @@ Search Delay Time Setting - Select the search delay time you like to use for the plugin. Select "{0}" if you don't want to specify any, and the plugin will use default search delay time. - Current search delay time - New search delay time + Input the search delay time in ms you like to use for the plugin. Input empty if you don't want to specify any, and the plugin will use default search delay time. Custom Query Hotkey diff --git a/Flow.Launcher/Resources/Controls/InstalledPluginDisplay.xaml b/Flow.Launcher/Resources/Controls/InstalledPluginDisplay.xaml index 615904d66..5ba011fed 100644 --- a/Flow.Launcher/Resources/Controls/InstalledPluginDisplay.xaml +++ b/Flow.Launcher/Resources/Controls/InstalledPluginDisplay.xaml @@ -85,7 +85,12 @@ Foreground="{DynamicResource Color08B}" Text="{DynamicResource searchDelay}" ToolTip="{DynamicResource searchDelayToolTip}" /> - + diff --git a/Flow.Launcher/Resources/Controls/InstalledPluginSearchDelay.xaml b/Flow.Launcher/Resources/Controls/InstalledPluginSearchDelay.xaml deleted file mode 100644 index 0fd98bfac..000000000 --- a/Flow.Launcher/Resources/Controls/InstalledPluginSearchDelay.xaml +++ /dev/null @@ -1,49 +0,0 @@ - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Flow.Launcher/SearchDelayTimeWindow.xaml.cs b/Flow.Launcher/SearchDelayTimeWindow.xaml.cs deleted file mode 100644 index 4a3c9f5a7..000000000 --- a/Flow.Launcher/SearchDelayTimeWindow.xaml.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System.Linq; -using System.Windows; -using Flow.Launcher.Plugin; -using Flow.Launcher.SettingPages.ViewModels; -using Flow.Launcher.ViewModel; -using static Flow.Launcher.SettingPages.ViewModels.SettingsPaneGeneralViewModel; - -namespace Flow.Launcher; - -public partial class SearchDelayTimeWindow : Window -{ - private readonly PluginViewModel _pluginViewModel; - - public SearchDelayTimeWindow(PluginViewModel pluginViewModel) - { - InitializeComponent(); - _pluginViewModel = pluginViewModel; - } - - private void SearchDelayTimeWindow_OnLoaded(object sender, RoutedEventArgs e) - { - tbSearchDelayTimeTips.Text = string.Format(App.API.GetTranslation("searchDelayTime_tips"), - App.API.GetTranslation("default")); - tbOldSearchDelayTime.Text = _pluginViewModel.SearchDelayTimeText; - var searchDelayTimes = DropdownDataGeneric.GetValues("SearchDelayTime"); - SearchDelayTimeData selected = null; - // Because default value is SearchDelayTime.VeryShort, we need to get selected value before adding default value - if (_pluginViewModel.PluginSearchDelayTime != null) - { - selected = searchDelayTimes.FirstOrDefault(x => x.Value == _pluginViewModel.PluginSearchDelayTime); - } - // Add default value to the beginning of the list - // When _pluginViewModel.PluginSearchDelayTime equals null, we will select this - searchDelayTimes.Insert(0, new SearchDelayTimeData { Display = App.API.GetTranslation("default"), LocalizationKey = "default" }); - selected ??= searchDelayTimes.FirstOrDefault(); - cbDelay.ItemsSource = searchDelayTimes; - cbDelay.SelectedItem = selected; - cbDelay.Focus(); - } - - private void BtnCancel_OnClick(object sender, RoutedEventArgs e) - { - Close(); - } - - private void btnDone_OnClick(object sender, RoutedEventArgs _) - { - // Update search delay time - var selected = cbDelay.SelectedItem as SearchDelayTimeData; - SearchDelayTime? changedValue = selected?.LocalizationKey != "default" ? selected.Value : null; - _pluginViewModel.PluginSearchDelayTime = changedValue; - - // Update search delay time text and close window - _pluginViewModel.OnSearchDelayTimeChanged(); - Close(); - } -} diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs index cec8c318c..74e2d8340 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Windows.Forms; +using CommunityToolkit.Mvvm.DependencyInjection; using CommunityToolkit.Mvvm.Input; using Flow.Launcher.Core; using Flow.Launcher.Core.Configuration; @@ -31,7 +32,25 @@ public partial class SettingsPaneGeneralViewModel : BaseModel public class SearchWindowAlignData : DropdownDataGeneric { } public class SearchPrecisionData : DropdownDataGeneric { } public class LastQueryModeData : DropdownDataGeneric { } - public class SearchDelayTimeData : DropdownDataGeneric { } + public class SearchDelayTimeData + { + public string Display { get; set; } + public int Value { get; set; } + + public static List GetValues() + { + var settings = Ioc.Default.GetRequiredService(); + var data = new List(); + + foreach (var value in settings.SearchDelayTimeRange) + { + var display = $"{value}ms"; + data.Add(new SearchDelayTimeData { Display = display, Value = value }); + } + + return data; + } + } public bool StartFlowLauncherOnSystemStartup { @@ -144,19 +163,15 @@ public partial class SettingsPaneGeneralViewModel : BaseModel public List LastQueryModes { get; } = DropdownDataGeneric.GetValues("LastQuery"); - public List SearchDelayTimes { get; } = - DropdownDataGeneric.GetValues("SearchDelayTime"); + public List SearchDelayTimes { get; } = SearchDelayTimeData.GetValues(); public SearchDelayTimeData SearchDelayTime { - get => SearchDelayTimes.FirstOrDefault(x => x.Value == Settings.SearchDelayTime) ?? - SearchDelayTimes.FirstOrDefault(x => x.Value == Plugin.SearchDelayTime.Normal) ?? - SearchDelayTimes.FirstOrDefault(); + get => SearchDelayTimes.FirstOrDefault(x => x.Value == Settings.SearchDelayTime); set { - if (value == null) - return; - + if (value == null) return; + if (Settings.SearchDelayTime != value.Value) { Settings.SearchDelayTime = value.Value; @@ -170,7 +185,6 @@ public partial class SettingsPaneGeneralViewModel : BaseModel DropdownDataGeneric.UpdateLabels(SearchWindowAligns); DropdownDataGeneric.UpdateLabels(SearchPrecisionScores); DropdownDataGeneric.UpdateLabels(LastQueryModes); - DropdownDataGeneric.UpdateLabels(SearchDelayTimes); } public string Language diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml b/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml index e36c647a2..10e2b549a 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml @@ -196,18 +196,21 @@ - + - - + Sub="{DynamicResource searchDelayTimeToolTip}" + Type="InsideFit"> - + 250, - SearchDelayTime.Long => 200, - SearchDelayTime.Normal => 150, - SearchDelayTime.Short => 100, - SearchDelayTime.VeryShort => 50, - _ => 150 - }; + var searchDelayTime = plugin.Metadata.SearchDelayTime ?? Settings.SearchDelayTime; await Task.Delay(searchDelayTime, token); diff --git a/Flow.Launcher/ViewModel/PluginViewModel.cs b/Flow.Launcher/ViewModel/PluginViewModel.cs index 2016d9c98..bf61b1902 100644 --- a/Flow.Launcher/ViewModel/PluginViewModel.cs +++ b/Flow.Launcher/ViewModel/PluginViewModel.cs @@ -95,7 +95,7 @@ namespace Flow.Launcher.ViewModel } } - public SearchDelayTime? PluginSearchDelayTime + public int? PluginSearchDelayTime { get => PluginPair.Metadata.SearchDelayTime; set @@ -192,12 +192,5 @@ namespace Flow.Launcher.ViewModel var changeKeywordsWindow = new ActionKeywords(this); changeKeywordsWindow.ShowDialog(); } - - [RelayCommand] - private void SetSearchDelayTime() - { - var searchDelayTimeWindow = new SearchDelayTimeWindow(this); - searchDelayTimeWindow.ShowDialog(); - } } } diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json b/Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json index 64681f803..c8b6310a7 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json @@ -32,5 +32,5 @@ "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.WebSearch.dll", "IcoPath": "Images\\web_search.png", - "SearchDelayTime": "VeryLong" + "SearchDelayTime": 450 }