mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Move PluginsManifest to Flow.Launcher.Core & Change PluginStore Binding to PluginsManifest
This commit is contained in:
parent
ccb565e70a
commit
3d06404614
8 changed files with 117 additions and 85 deletions
57
Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs
Normal file
57
Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
using Flow.Launcher.Infrastructure.Http;
|
||||
using Flow.Launcher.Infrastructure.Logger;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Flow.Launcher.Core.ExternalPlugins
|
||||
{
|
||||
public static class PluginsManifest
|
||||
{
|
||||
static PluginsManifest()
|
||||
{
|
||||
UpdateTask = UpdateManifestAsync();
|
||||
}
|
||||
|
||||
public static List<UserPlugin> UserPlugins { get; private set; } = new List<UserPlugin>();
|
||||
|
||||
public static Task UpdateTask { get; private set; }
|
||||
|
||||
private static readonly SemaphoreSlim manifestUpdateLock = new(1);
|
||||
|
||||
public static Task UpdateManifestAsync()
|
||||
{
|
||||
if (manifestUpdateLock.CurrentCount == 0)
|
||||
{
|
||||
return UpdateTask;
|
||||
}
|
||||
|
||||
return UpdateTask = DownloadManifestAsync();
|
||||
}
|
||||
|
||||
private async static Task DownloadManifestAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
await manifestUpdateLock.WaitAsync().ConfigureAwait(false);
|
||||
|
||||
await using var jsonStream = await Http.GetStreamAsync("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/plugin_api_v2/plugins.json")
|
||||
.ConfigureAwait(false);
|
||||
|
||||
UserPlugins = await JsonSerializer.DeserializeAsync<List<UserPlugin>>(jsonStream).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Exception("|PluginManagement.GetManifest|Encountered error trying to download plugins manifest", e);
|
||||
|
||||
UserPlugins = new List<UserPlugin>();
|
||||
}
|
||||
finally
|
||||
{
|
||||
manifestUpdateLock.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
namespace Flow.Launcher.Plugin.PluginsManager.Models
|
||||
namespace Flow.Launcher.Core.ExternalPlugins
|
||||
{
|
||||
public class UserPlugin
|
||||
public record UserPlugin
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
|
@ -12,5 +11,6 @@ namespace Flow.Launcher.Plugin.PluginsManager.Models
|
|||
public string Website { get; set; }
|
||||
public string UrlDownload { get; set; }
|
||||
public string UrlSourceCode { get; set; }
|
||||
public string IcoPath { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -657,28 +657,28 @@
|
|||
ToolTip="Change Plugin Results Priority"
|
||||
Margin="5 0 0 0" Cursor="Hand"
|
||||
Click="OnPluginPriorityClick">
|
||||
<!--#region Priority Button Style-->
|
||||
<!--#region Priority Button Style-->
|
||||
<Button.Resources>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="CornerRadius" Value="2"/>
|
||||
</Style>
|
||||
</Button.Resources>
|
||||
<Button.Style>
|
||||
<Style TargetType="Button">
|
||||
<Setter Property="Padding" Value="12 8 12 8" />
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
<Setter Property="FontWeight" Value="DemiBold" />
|
||||
<Setter Property="Foreground" Value="Black" />
|
||||
<Style TargetType="Button">
|
||||
<Setter Property="Padding" Value="12 8 12 8" />
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
<Setter Property="FontWeight" Value="DemiBold" />
|
||||
<Setter Property="Foreground" Value="Black" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding ElementName=PriorityButton, UpdateSourceTrigger=PropertyChanged, Path=Content}" Value="0">
|
||||
<Setter Property="Foreground" Value="#878787" />
|
||||
<Setter Property="FontWeight" Value="Normal" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
<!--#endregion-->
|
||||
</Button>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
<!--#endregion-->
|
||||
</Button>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
<ui:ToggleSwitch Grid.Column="4" OffContent="{DynamicResource disable}"
|
||||
|
|
@ -703,15 +703,15 @@
|
|||
Style="{DynamicResource SettingTitleLabel}"
|
||||
Margin="0 0 0 0" VerticalAlignment="Center" HorizontalAlignment="Left" DockPanel.Dock="Left"/>
|
||||
|
||||
|
||||
<Button Grid.Column="2" Content="{Binding ActionKeywordsText}"
|
||||
|
||||
<Button Grid.Column="2" Content="{Binding ActionKeywordsText}"
|
||||
DockPanel.Dock="Right"
|
||||
Visibility="{Binding ActionKeywordsVisibility}"
|
||||
ToolTip="Change Action Keywords"
|
||||
Margin="5 0 0 0" Cursor="Hand" FontWeight="Bold"
|
||||
Click="OnPluginActionKeywordsClick" HorizontalAlignment="Right"
|
||||
Width="100" Height="40">
|
||||
|
||||
|
||||
<Button.Resources>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="CornerRadius" Value="2"/>
|
||||
|
|
@ -730,7 +730,7 @@
|
|||
|
||||
<StackPanel>
|
||||
|
||||
|
||||
|
||||
<Border Background="White" Padding="0"
|
||||
BorderThickness="0 1 0 0" BorderBrush="#e6e6e6"
|
||||
VerticalAlignment="Center" HorizontalAlignment="Stretch">
|
||||
|
|
@ -753,8 +753,8 @@
|
|||
Content="{Binding SettingControl}"
|
||||
Padding="1" Margin="0" VerticalAlignment="Stretch"
|
||||
MaxWidth="750" MaxHeight="550">
|
||||
</ContentControl>
|
||||
|
||||
</ContentControl>
|
||||
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel>
|
||||
|
|
@ -794,7 +794,7 @@
|
|||
MouseUp="OnPluginDirecotyClick" Foreground="Blue"
|
||||
HorizontalAlignment="Right" FontSize="12" VerticalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
|
||||
|
||||
</ItemsControl>
|
||||
</Border>
|
||||
|
||||
|
|
@ -840,7 +840,7 @@
|
|||
</Border>
|
||||
<Border Grid.Column="0" Grid.Row="1" Background="#f3f3f3" Padding="0 0 0 0">
|
||||
<ListBox x:Name="StoreListBox"
|
||||
ItemsSource="{Binding PluginViewModels}"
|
||||
ItemsSource="{Binding ExternalPlugins}"
|
||||
Margin="6, 0, 0, 0" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
ItemContainerStyle="{StaticResource StoreList}"
|
||||
ScrollViewer.IsDeferredScrollingEnabled="True" ScrollViewer.CanContentScroll="False"
|
||||
|
|
@ -849,9 +849,9 @@
|
|||
<ItemsPanelTemplate>
|
||||
<UniformGrid IsItemsHost="True" HorizontalAlignment="Left" Columns="2" Margin="0 0 12 18" VerticalAlignment="Top" />
|
||||
</ItemsPanelTemplate>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ListBox.ItemsPanel>
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
|
|
@ -874,10 +874,10 @@
|
|||
</Style.Triggers>
|
||||
</Style>
|
||||
</StackPanel.Style>
|
||||
<Image Source="{Binding Image, IsAsync=True}"
|
||||
Width="32" Height="32" Margin="8 0 6 0"
|
||||
VerticalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
<Image Source="{Binding IcoPath, IsAsync=True}"
|
||||
Width="32" Height="32" Margin="8 0 6 0"
|
||||
VerticalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="1" Margin="0 0 8 0" VerticalAlignment="Center" Panel.ZIndex="0">
|
||||
<StackPanel.Style>
|
||||
<Style>
|
||||
|
|
@ -889,11 +889,11 @@
|
|||
</Style.Triggers>
|
||||
</Style>
|
||||
</StackPanel.Style>
|
||||
<TextBlock Text="{Binding PluginPair.Metadata.Name}"
|
||||
<TextBlock Text="{Binding Name}"
|
||||
TextWrapping="WrapWithOverflow" Padding="0 0 20 0"
|
||||
ToolTip="{Binding PluginPair.Metadata.Version}" />
|
||||
ToolTip="{Binding Version}" />
|
||||
<TextBlock Opacity="0.5" TextWrapping="WrapWithOverflow" Margin="0 2 0 0" Padding="0 0 20 0">
|
||||
<Run Text="{Binding PluginPair.Metadata.Description}" FontSize="12" />
|
||||
<Run Text="{Binding Description}" FontSize="12" />
|
||||
</TextBlock>
|
||||
|
||||
</StackPanel >
|
||||
|
|
@ -917,18 +917,18 @@
|
|||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="{Binding ActualWidth,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}}" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
|
||||
<StackPanel Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Stretch">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding PluginPair.Metadata.Name}" FontWeight="Bold"
|
||||
<TextBlock Text="{Binding Name}" FontWeight="Bold"
|
||||
TextWrapping="WrapWithOverflow" Padding="0 0 0 0" Margin="20 0 0 0"
|
||||
ToolTip="{Binding PluginPair.Metadata.Name}" />
|
||||
<TextBlock Text="{Binding PluginPair.Metadata.Version}"
|
||||
ToolTip="{Binding Name}" />
|
||||
<TextBlock Text="{Binding Version}"
|
||||
TextWrapping="WrapWithOverflow" Padding="0 0 20 0" Margin="10 0 0 0"
|
||||
ToolTip="{Binding PluginPair.Metadata.Version}" />
|
||||
ToolTip="{Binding Version}" />
|
||||
</StackPanel>
|
||||
<TextBlock Opacity="0.5" TextWrapping="Wrap" Margin="20 2 0 0" Padding="0 0 20 0" >
|
||||
<Run Text="{Binding PluginPair.Metadata.Author}" FontSize="12" />
|
||||
<Run Text="{Binding Author}" FontSize="12" />
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ using System.Windows.Media;
|
|||
using System.Windows.Media.Imaging;
|
||||
using Flow.Launcher.Core;
|
||||
using Flow.Launcher.Core.Configuration;
|
||||
using Flow.Launcher.Core.ExternalPlugins;
|
||||
using Flow.Launcher.Core.Plugin;
|
||||
using Flow.Launcher.Core.Resource;
|
||||
using Flow.Launcher.Helper;
|
||||
|
|
@ -237,6 +238,14 @@ namespace Flow.Launcher.ViewModel
|
|||
}
|
||||
}
|
||||
|
||||
public IList<UserPlugin> ExternalPlugins
|
||||
{
|
||||
get
|
||||
{
|
||||
return PluginsManifest.UserPlugins;
|
||||
}
|
||||
}
|
||||
|
||||
public Control SettingProvider
|
||||
{
|
||||
get
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.Plugin.PluginsManager.Models;
|
||||
using Flow.Launcher.Core.ExternalPlugins;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
viewModel = new SettingsViewModel(context, Settings);
|
||||
contextMenu = new ContextMenu(Context);
|
||||
pluginManager = new PluginsManager(Context, Settings);
|
||||
_manifestUpdateTask = pluginManager.UpdateManifest().ContinueWith(_ =>
|
||||
_manifestUpdateTask = pluginManager.UpdateManifestAsync().ContinueWith(_ =>
|
||||
{
|
||||
lastUpdateTime = DateTime.Now;
|
||||
}, TaskContinuationOptions.OnlyOnRanToCompletion);
|
||||
|
|
@ -62,7 +62,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
|
||||
if ((DateTime.Now - lastUpdateTime).TotalHours > 12 && _manifestUpdateTask.IsCompleted) // 12 hours
|
||||
{
|
||||
_manifestUpdateTask = pluginManager.UpdateManifest().ContinueWith(t =>
|
||||
_manifestUpdateTask = pluginManager.UpdateManifestAsync().ContinueWith(t =>
|
||||
{
|
||||
lastUpdateTime = DateTime.Now;
|
||||
}, TaskContinuationOptions.OnlyOnRanToCompletion);
|
||||
|
|
@ -93,7 +93,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
|
||||
public async Task ReloadDataAsync()
|
||||
{
|
||||
await pluginManager.UpdateManifest();
|
||||
await pluginManager.UpdateManifestAsync();
|
||||
lastUpdateTime = DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
using Flow.Launcher.Infrastructure.Http;
|
||||
using Flow.Launcher.Infrastructure.Logger;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Flow.Launcher.Plugin.PluginsManager.Models
|
||||
{
|
||||
internal class PluginsManifest
|
||||
{
|
||||
internal List<UserPlugin> UserPlugins { get; private set; } = new List<UserPlugin>();
|
||||
|
||||
internal async Task DownloadManifest()
|
||||
{
|
||||
try
|
||||
{
|
||||
await using var jsonStream = await Http.GetStreamAsync("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/plugin_api_v2/plugins.json")
|
||||
.ConfigureAwait(false);
|
||||
|
||||
UserPlugins = await JsonSerializer.DeserializeAsync<List<UserPlugin>>(jsonStream).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Exception("|PluginManagement.GetManifest|Encountered error trying to download plugins manifest", e);
|
||||
|
||||
UserPlugins = new List<UserPlugin>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
using Flow.Launcher.Core.ExternalPlugins;
|
||||
using Flow.Launcher.Core.Plugin;
|
||||
using Flow.Launcher.Infrastructure;
|
||||
using Flow.Launcher.Infrastructure.Http;
|
||||
using Flow.Launcher.Infrastructure.Logger;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.Plugin.PluginsManager.Models;
|
||||
using Flow.Launcher.Plugin.SharedCommands;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -17,8 +17,6 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
{
|
||||
internal class PluginsManager
|
||||
{
|
||||
private PluginsManifest pluginsManifest;
|
||||
|
||||
private PluginInitContext Context { get; set; }
|
||||
|
||||
private Settings Settings { get; set; }
|
||||
|
|
@ -43,7 +41,6 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
|
||||
internal PluginsManager(PluginInitContext context, Settings settings)
|
||||
{
|
||||
pluginsManifest = new PluginsManifest();
|
||||
Context = context;
|
||||
Settings = settings;
|
||||
}
|
||||
|
|
@ -51,7 +48,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
private Task _downloadManifestTask = Task.CompletedTask;
|
||||
|
||||
|
||||
internal Task UpdateManifest()
|
||||
internal Task UpdateManifestAsync()
|
||||
{
|
||||
if (_downloadManifestTask.Status == TaskStatus.Running)
|
||||
{
|
||||
|
|
@ -59,7 +56,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
}
|
||||
else
|
||||
{
|
||||
_downloadManifestTask = pluginsManifest.DownloadManifest();
|
||||
_downloadManifestTask = PluginsManifest.UpdateTask;
|
||||
_downloadManifestTask.ContinueWith(_ =>
|
||||
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_update_failed_title"),
|
||||
Context.API.GetTranslation("plugin_pluginsmanager_update_failed_subtitle"), icoPath, false),
|
||||
|
|
@ -171,9 +168,9 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
|
||||
internal async ValueTask<List<Result>> RequestUpdate(string search, CancellationToken token)
|
||||
{
|
||||
if (!pluginsManifest.UserPlugins.Any())
|
||||
if (!PluginsManifest.UserPlugins.Any())
|
||||
{
|
||||
await UpdateManifest();
|
||||
await UpdateManifestAsync();
|
||||
}
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
|
@ -190,7 +187,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
|
||||
var resultsForUpdate =
|
||||
from existingPlugin in Context.API.GetAllPlugins()
|
||||
join pluginFromManifest in pluginsManifest.UserPlugins
|
||||
join pluginFromManifest in PluginsManifest.UserPlugins
|
||||
on existingPlugin.Metadata.ID equals pluginFromManifest.ID
|
||||
where existingPlugin.Metadata.Version.CompareTo(pluginFromManifest.Version) <
|
||||
0 // if current version precedes manifest version
|
||||
|
|
@ -307,9 +304,9 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
|
||||
internal async ValueTask<List<Result>> RequestInstallOrUpdate(string searchName, CancellationToken token)
|
||||
{
|
||||
if (!pluginsManifest.UserPlugins.Any())
|
||||
if (!PluginsManifest.UserPlugins.Any())
|
||||
{
|
||||
await UpdateManifest();
|
||||
await UpdateManifestAsync();
|
||||
}
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
|
@ -317,7 +314,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
var searchNameWithoutKeyword = searchName.Replace(Settings.HotKeyInstall, string.Empty).Trim();
|
||||
|
||||
var results =
|
||||
pluginsManifest
|
||||
PluginsManifest
|
||||
.UserPlugins
|
||||
.Select(x =>
|
||||
new Result
|
||||
|
|
|
|||
Loading…
Reference in a new issue