Flow.Launcher/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginStoreViewModel.cs

172 lines
4.6 KiB
C#
Raw Normal View History

2025-06-09 12:28:18 +00:00
using System;
using System.Collections.Generic;
2024-05-15 16:56:58 +00:00
using System.Linq;
using System.Threading.Tasks;
2025-07-18 07:26:07 +00:00
using System.Windows;
2024-05-15 16:56:58 +00:00
using CommunityToolkit.Mvvm.Input;
2025-06-29 14:35:14 +00:00
using Flow.Launcher.Core.Plugin;
2024-05-15 16:56:58 +00:00
using Flow.Launcher.Plugin;
using Flow.Launcher.ViewModel;
namespace Flow.Launcher.SettingPages.ViewModels;
public partial class SettingsPanePluginStoreViewModel : BaseModel
{
private string filterText = string.Empty;
public string FilterText
{
get => filterText;
set
{
if (filterText != value)
{
filterText = value;
OnPropertyChanged();
}
}
}
private bool showDotNet = true;
public bool ShowDotNet
{
get => showDotNet;
set
{
if (showDotNet != value)
{
showDotNet = value;
OnPropertyChanged();
}
}
}
private bool showPython = true;
public bool ShowPython
{
get => showPython;
set
{
if (showPython != value)
{
showPython = value;
OnPropertyChanged();
}
}
}
private bool showNodeJs = true;
public bool ShowNodeJs
{
get => showNodeJs;
set
{
if (showNodeJs != value)
{
showNodeJs = value;
OnPropertyChanged();
}
}
}
private bool showExecutable = true;
public bool ShowExecutable
{
get => showExecutable;
set
{
if (showExecutable != value)
{
showExecutable = value;
OnPropertyChanged();
}
}
}
2024-05-15 16:56:58 +00:00
public IList<PluginStoreItemViewModel> ExternalPlugins => App.API.GetPluginManifest()?
.Select(p => new PluginStoreItemViewModel(p))
2024-05-15 16:56:58 +00:00
.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()
{
if (await App.API.UpdatePluginManifestAsync())
2025-02-10 04:01:21 +00:00
{
OnPropertyChanged(nameof(ExternalPlugins));
}
2024-05-15 16:56:58 +00:00
}
2025-06-09 12:28:18 +00:00
[RelayCommand]
private async Task InstallPluginAsync()
{
var file = GetFileFromDialog(
App.API.GetTranslation("SelectZipFile"),
$"{App.API.GetTranslation("ZipFiles")} (*.zip)|*.zip");
if (!string.IsNullOrEmpty(file))
2025-06-29 14:35:14 +00:00
await PluginInstaller.InstallPluginAndCheckRestartAsync(file);
2025-06-09 12:28:18 +00:00
}
2025-07-14 08:24:09 +00:00
[RelayCommand]
private async Task CheckPluginUpdatesAsync()
{
2025-07-18 07:26:07 +00:00
await PluginInstaller.CheckForPluginUpdatesAsync((plugins) =>
{
Application.Current.Dispatcher.Invoke(() =>
{
var pluginUpdateWindow = new PluginUpdateWindow(plugins);
pluginUpdateWindow.ShowDialog();
});
}, silentUpdate: false);
2025-07-14 08:24:09 +00:00
}
2025-06-09 12:28:18 +00:00
private static string GetFileFromDialog(string title, string filter = "")
{
var dlg = new Microsoft.Win32.OpenFileDialog
2025-06-09 12:28:18 +00:00
{
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Downloads",
Multiselect = false,
CheckFileExists = true,
CheckPathExists = true,
Title = title,
Filter = filter
};
var result = dlg.ShowDialog();
if (result == true)
return dlg.FileName;
2025-06-09 12:28:18 +00:00
return string.Empty;
2025-06-09 12:28:18 +00:00
}
2024-05-15 16:56:58 +00:00
public bool SatisfiesFilter(PluginStoreItemViewModel plugin)
{
// Check plugin language
var pluginShown = false;
if (AllowedLanguage.IsDotNet(plugin.Language))
{
pluginShown = ShowDotNet;
}
else if (AllowedLanguage.IsPython(plugin.Language))
{
pluginShown = ShowPython;
}
else if (AllowedLanguage.IsNodeJs(plugin.Language))
{
pluginShown = ShowNodeJs;
}
else if (AllowedLanguage.IsExecutable(plugin.Language))
{
pluginShown = ShowExecutable;
}
if (!pluginShown) return false;
// Check plugin name & description
2024-05-15 16:56:58 +00:00
return string.IsNullOrEmpty(FilterText) ||
App.API.FuzzySearch(FilterText, plugin.Name).IsSearchPrecisionScoreMet() ||
App.API.FuzzySearch(FilterText, plugin.Description).IsSearchPrecisionScoreMet();
2024-05-15 16:56:58 +00:00
}
}