From 3bcb5da99c7117241694ad1b742b3a62c20b39d0 Mon Sep 17 00:00:00 2001 From: Yusyuriv Date: Wed, 15 May 2024 22:56:58 +0600 Subject: [PATCH] Implement plugin store settings pane --- .../SettingsPanePluginStoreViewModel.cs | 37 ++++++++++ .../Views/SettingsPanePluginStore.xaml | 50 +++++++------ .../Views/SettingsPanePluginStore.xaml.cs | 70 ++++++++++++++----- .../ViewModel/PluginStoreItemViewModel.cs | 21 +++--- 4 files changed, 131 insertions(+), 47 deletions(-) create mode 100644 Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginStoreViewModel.cs diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginStoreViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginStoreViewModel.cs new file mode 100644 index 000000000..e06931011 --- /dev/null +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginStoreViewModel.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using CommunityToolkit.Mvvm.Input; +using Flow.Launcher.Core.ExternalPlugins; +using Flow.Launcher.Infrastructure; +using Flow.Launcher.Plugin; +using Flow.Launcher.ViewModel; + +namespace Flow.Launcher.SettingPages.ViewModels; + +public partial class SettingsPanePluginStoreViewModel : BaseModel +{ + public string FilterText { get; set; } = string.Empty; + + public IList ExternalPlugins => PluginsManifest.UserPlugins + .Select(p => new PluginStoreItemViewModel(p)) + .OrderByDescending(p => p.Category == PluginStoreItemViewModel.NewRelease) + .ThenByDescending(p => p.Category == PluginStoreItemViewModel.RecentlyUpdated) + .ThenByDescending(p => p.Category == PluginStoreItemViewModel.None) + .ThenByDescending(p => p.Category == PluginStoreItemViewModel.Installed) + .ToList(); + + [RelayCommand] + private async Task RefreshExternalPluginsAsync() + { + await PluginsManifest.UpdateManifestAsync(); + OnPropertyChanged(nameof(ExternalPlugins)); + } + + public bool SatisfiesFilter(PluginStoreItemViewModel plugin) + { + return string.IsNullOrEmpty(FilterText) || + StringMatcher.FuzzySearch(FilterText, plugin.Name).IsSearchPrecisionScoreMet() || + StringMatcher.FuzzySearch(FilterText, plugin.Description).IsSearchPrecisionScoreMet(); + } +} diff --git a/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml b/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml index bed68e86a..3b13f2e5a 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml +++ b/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml @@ -1,25 +1,27 @@ - - - - - - - - - + + + + + + + @@ -38,7 +40,7 @@ FontSize="30" Style="{StaticResource PageTitle}" Text="{DynamicResource pluginStore}" - TextAlignment="left" /> + TextAlignment="Left" /> + VirtualizingPanel.ScrollUnit="Pixel"> - + @@ -273,7 +274,9 @@ HorizontalAlignment="Stretch" VerticalAlignment="Center" Content="{DynamicResource installbtn}" - Visibility="{Binding LabelInstalled, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter='!'}" /> + Visibility="{Binding LabelInstalled, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter='!'}" + Command="{Binding ShowCommandQueryCommand}" + CommandParameter="install" />