diff --git a/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs b/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs index 0ebbdb318..7e9e22063 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs @@ -51,7 +51,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings } metadata.Disabled = settings.Disabled; metadata.Priority = settings.Priority; - metadata.SearchDelayTime = settings.SearchDelayTime; + metadata.SearchDelay = settings.SearchDelay; } else { @@ -63,7 +63,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings ActionKeywords = metadata.ActionKeywords, Disabled = metadata.Disabled, Priority = metadata.Priority, - SearchDelayTime = metadata.SearchDelayTime, + SearchDelay = metadata.SearchDelay, }; } } @@ -76,7 +76,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings public string Version { get; set; } public List ActionKeywords { get; set; } // a reference of the action keywords from plugin manager public int Priority { get; set; } - public int SearchDelayTime { get; set; } + public int SearchDelay { 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 82e4468d4..3de2bdb61 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -285,16 +285,19 @@ namespace Flow.Launcher.Infrastructure.UserSettings OnPropertyChanged(); } } - public int SearchInputDelay { get; set; } = 120; + public int SearchDelay { get; set; } = 120; + + // TODO: Remove debug codes. + public const int SearchDelayInterval = 30 * 60; [JsonIgnore] - public List SearchInputDelayRange { get; } = new() + public List SearchDelayRange { get; } = new() { 30, 60, 90, 120, 150, 180, 210, 240, 270, 300 }; [JsonIgnore] - public List PluginSearchInputDelayRange { get; } = new() + public List PluginSearchDelayRange { get; } = new() { 0, 30, 60, 90, 120, 150 }; diff --git a/Flow.Launcher.Plugin/PluginMetadata.cs b/Flow.Launcher.Plugin/PluginMetadata.cs index 3cb025c77..5300c2550 100644 --- a/Flow.Launcher.Plugin/PluginMetadata.cs +++ b/Flow.Launcher.Plugin/PluginMetadata.cs @@ -34,7 +34,7 @@ namespace Flow.Launcher.Plugin public List ActionKeywords { get; set; } - public int SearchDelayTime { get; set; } + public int SearchDelay { get; set; } public string IcoPath { get; set;} diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index d41165c81..a615bfa2f 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -880,8 +880,18 @@ namespace Flow.Launcher conversion => (sender, eventArg) => conversion(sender, eventArg), add => QueryTextBox.TextChanged += add, remove => QueryTextBox.TextChanged -= remove) - .Throttle(TimeSpan.FromMilliseconds(_settings.SearchInputDelay)) - .Do(@event => Dispatcher.Invoke(() => PerformSearchQuery((TextBox)@event.Sender))) + .Throttle(TimeSpan.FromMilliseconds(_settings.SearchDelay * 10)) + .Do(@event => Dispatcher.Invoke(() => PerformSearchQuery(0, (TextBox)@event.Sender))) + .Throttle(TimeSpan.FromMilliseconds(Settings.SearchDelayInterval)) + .Do(@event => Dispatcher.Invoke(() => PerformSearchQuery(30, (TextBox)@event.Sender))) + .Throttle(TimeSpan.FromMilliseconds(Settings.SearchDelayInterval)) + .Do(@event => Dispatcher.Invoke(() => PerformSearchQuery(60, (TextBox)@event.Sender))) + .Throttle(TimeSpan.FromMilliseconds(Settings.SearchDelayInterval)) + .Do(@event => Dispatcher.Invoke(() => PerformSearchQuery(90, (TextBox)@event.Sender))) + .Throttle(TimeSpan.FromMilliseconds(Settings.SearchDelayInterval)) + .Do(@event => Dispatcher.Invoke(() => PerformSearchQuery(120, (TextBox)@event.Sender))) + .Throttle(TimeSpan.FromMilliseconds(Settings.SearchDelayInterval)) + .Do(@event => Dispatcher.Invoke(() => PerformSearchQuery(150, (TextBox)@event.Sender))) .Subscribe(); } else @@ -893,14 +903,19 @@ namespace Flow.Launcher private void QueryTextBox_TextChanged(object sender, TextChangedEventArgs e) { var textBox = (TextBox)sender; - PerformSearchQuery(textBox); + PerformSearchQuery(null, textBox); } - private void PerformSearchQuery(TextBox textBox) + // If delayInputTime is null, we will query plugins with all plugin search delay times + private void PerformSearchQuery(int? searchDelay, TextBox textBox) { - var text = textBox.Text; - _viewModel.QueryText = text; - _viewModel.Query(); + // Only update query text when search delay is null or 0 + if (searchDelay.GetValueOrDefault(0) == 0) + { + var text = textBox.Text; + _viewModel.QueryText = text; + } + _viewModel.Query(searchDelay); } #endregion diff --git a/Flow.Launcher/Resources/Controls/InstalledPluginSearchDelay.xaml b/Flow.Launcher/Resources/Controls/InstalledPluginSearchDelay.xaml index 8d69c08d9..80fd7525b 100644 --- a/Flow.Launcher/Resources/Controls/InstalledPluginSearchDelay.xaml +++ b/Flow.Launcher/Resources/Controls/InstalledPluginSearchDelay.xaml @@ -38,8 +38,8 @@ Cursor="Hand" DockPanel.Dock="Right" FontWeight="Bold" - ItemsSource="{Binding PluginSearchInputDelayRange}" - SelectedItem="{Binding PluginSearchDelayTime}" + ItemsSource="{Binding PluginSearchDelayRange}" + SelectedItem="{Binding PluginSearchDelay}" ToolTip="{DynamicResource pluginSearchDelayTooltip}" /> diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs index 6e97543db..d8fe8bb50 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs @@ -139,7 +139,7 @@ public partial class SettingsPaneGeneralViewModel : BaseModel } } - public IEnumerable SearchInputDelayRange => Settings.SearchInputDelayRange; + public IEnumerable SearchDelayRange => Settings.SearchDelayRange; public List LastQueryModes { get; } = DropdownDataGeneric.GetValues("LastQuery"); diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml b/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml index ffb58d094..bde74c653 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml @@ -189,8 +189,8 @@ Sub="{DynamicResource searchDelayTimeToolTip}"> + ItemsSource="{Binding SearchDelayRange}" + SelectedItem="{Binding Settings.SearchDelay}" /> diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 373ecdece..c5658516a 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -274,14 +274,14 @@ namespace Flow.Launcher.ViewModel { if (SelectedIsFromQueryResults()) { - QueryResults(isReQuery: true); + QueryResults(null, isReQuery: true); } } public void ReQuery(bool reselect) { BackToQueryResults(); - QueryResults(isReQuery: true, reSelect: reselect); + QueryResults(null, isReQuery: true, reSelect: reselect); } [RelayCommand] @@ -630,14 +630,14 @@ namespace Flow.Launcher.ViewModel { // re-query is done in QueryText's setter method QueryText = queryText; - Query(); + Query(null); // set to false so the subsequent set true triggers // PropertyChanged and MoveQueryTextToEnd is called QueryTextCursorMovedToEnd = false; } else if (isReQuery) { - Query(isReQuery: true); + Query(null, isReQuery: true); } QueryTextCursorMovedToEnd = true; @@ -690,12 +690,12 @@ namespace Flow.Launcher.ViewModel // http://stackoverflow.com/posts/25895769/revisions if (string.IsNullOrEmpty(QueryText)) { - Query(); + Query(null); } else { QueryText = string.Empty; - Query(); + Query(null); } } @@ -979,19 +979,27 @@ namespace Flow.Launcher.ViewModel #region Query - public void Query(bool isReQuery = false) + public void Query(int? searchDelay, bool isReQuery = false) { if (SelectedIsFromQueryResults()) { - QueryResults(isReQuery); + QueryResults(searchDelay, isReQuery); } else if (ContextMenuSelected()) { - QueryContextMenu(); + // Only query history when search delay is null or 0 + if (searchDelay.GetValueOrDefault(0) == 0) + { + QueryContextMenu(); + } } else if (HistorySelected()) { - QueryHistory(); + // Only query history when search delay is null or 0 + if (searchDelay.GetValueOrDefault(0) == 0) + { + QueryHistory(); + } } } @@ -1081,7 +1089,7 @@ namespace Flow.Launcher.ViewModel private readonly IReadOnlyList _emptyResult = new List(); - private async void QueryResults(bool isReQuery = false, bool reSelect = true) + private async void QueryResults(int? searchDelay, bool isReQuery = false, bool reSelect = true) { _updateSource?.Cancel(); @@ -1157,12 +1165,44 @@ namespace Flow.Launcher.ViewModel // plugins is ICollection, meaning LINQ will get the Count and preallocate Array - var tasks = plugins.Select(plugin => plugin.Metadata.Disabled switch + Task[] tasks; + if (searchDelay.HasValue) { - false => QueryTask(plugin, reSelect), - true => Task.CompletedTask - }).ToArray(); + var searchDelayValue = searchDelay.Value; + tasks = plugins.Select(plugin => (plugin.Metadata.Disabled || plugin.Metadata.SearchDelay != searchDelayValue) switch + { + false => QueryTask(plugin, reSelect), + true => Task.CompletedTask + }).ToArray(); + // TODO: Remove debug codes. + System.Diagnostics.Debug.WriteLine($"Querying {searchDelayValue}ms"); + foreach (var plugin in plugins) + { + if (!(plugin.Metadata.Disabled || plugin.Metadata.SearchDelay != searchDelayValue)) + { + System.Diagnostics.Debug.WriteLine($"Querying {plugin.Metadata.Name}"); + } + } + } + else + { + tasks = plugins.Select(plugin => plugin.Metadata.Disabled switch + { + false => QueryTask(plugin, reSelect), + true => Task.CompletedTask + }).ToArray(); + + // TODO: Remove debug codes. + System.Diagnostics.Debug.WriteLine($"Querying null ms"); + foreach (var plugin in plugins) + { + if (!plugin.Metadata.Disabled) + { + System.Diagnostics.Debug.WriteLine($"Querying {plugin.Metadata.Name}"); + } + } + } try { diff --git a/Flow.Launcher/ViewModel/PluginViewModel.cs b/Flow.Launcher/ViewModel/PluginViewModel.cs index 230a76e7a..e44443ac0 100644 --- a/Flow.Launcher/ViewModel/PluginViewModel.cs +++ b/Flow.Launcher/ViewModel/PluginViewModel.cs @@ -84,16 +84,16 @@ namespace Flow.Launcher.ViewModel } } - public IEnumerable PluginSearchInputDelayRange { get; } = - Ioc.Default.GetRequiredService().PluginSearchInputDelayRange; + public IEnumerable PluginSearchDelayRange { get; } = + Ioc.Default.GetRequiredService().PluginSearchDelayRange; - public int PluginSearchDelayTime + public int PluginSearchDelay { - get => PluginPair.Metadata.SearchDelayTime; + get => PluginPair.Metadata.SearchDelay; set { - PluginPair.Metadata.SearchDelayTime = value; - PluginSettingsObject.SearchDelayTime = value; + PluginPair.Metadata.SearchDelay = value; + PluginSettingsObject.SearchDelay = value; } }