Skip to content

Commit 3d06404

Browse files
committed
Move PluginsManifest to Flow.Launcher.Core & Change PluginStore Binding to PluginsManifest
1 parent ccb565e commit 3d06404

File tree

8 files changed

+117
-85
lines changed

8 files changed

+117
-85
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using Flow.Launcher.Infrastructure.Http;
2+
using Flow.Launcher.Infrastructure.Logger;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text.Json;
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
9+
namespace Flow.Launcher.Core.ExternalPlugins
10+
{
11+
public static class PluginsManifest
12+
{
13+
static PluginsManifest()
14+
{
15+
UpdateTask = UpdateManifestAsync();
16+
}
17+
18+
public static List<UserPlugin> UserPlugins { get; private set; } = new List<UserPlugin>();
19+
20+
public static Task UpdateTask { get; private set; }
21+
22+
private static readonly SemaphoreSlim manifestUpdateLock = new(1);
23+
24+
public static Task UpdateManifestAsync()
25+
{
26+
if (manifestUpdateLock.CurrentCount == 0)
27+
{
28+
return UpdateTask;
29+
}
30+
31+
return UpdateTask = DownloadManifestAsync();
32+
}
33+
34+
private async static Task DownloadManifestAsync()
35+
{
36+
try
37+
{
38+
await manifestUpdateLock.WaitAsync().ConfigureAwait(false);
39+
40+
await using var jsonStream = await Http.GetStreamAsync("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/plugin_api_v2/plugins.json")
41+
.ConfigureAwait(false);
42+
43+
UserPlugins = await JsonSerializer.DeserializeAsync<List<UserPlugin>>(jsonStream).ConfigureAwait(false);
44+
}
45+
catch (Exception e)
46+
{
47+
Log.Exception("|PluginManagement.GetManifest|Encountered error trying to download plugins manifest", e);
48+
49+
UserPlugins = new List<UserPlugin>();
50+
}
51+
finally
52+
{
53+
manifestUpdateLock.Release();
54+
}
55+
}
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-

2-
namespace Flow.Launcher.Plugin.PluginsManager.Models
1+
namespace Flow.Launcher.Core.ExternalPlugins
32
{
4-
public class UserPlugin
3+
public record UserPlugin
54
{
65
public string ID { get; set; }
76
public string Name { get; set; }
@@ -12,5 +11,6 @@ public class UserPlugin
1211
public string Website { get; set; }
1312
public string UrlDownload { get; set; }
1413
public string UrlSourceCode { get; set; }
14+
public string IcoPath { get; set; }
1515
}
1616
}

Flow.Launcher/SettingWindow.xaml

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -657,28 +657,28 @@
657657
ToolTip="Change Plugin Results Priority"
658658
Margin="5 0 0 0" Cursor="Hand"
659659
Click="OnPluginPriorityClick">
660-
<!--#region Priority Button Style-->
660+
<!--#region Priority Button Style-->
661661
<Button.Resources>
662662
<Style TargetType="Border">
663663
<Setter Property="CornerRadius" Value="2"/>
664664
</Style>
665665
</Button.Resources>
666666
<Button.Style>
667-
<Style TargetType="Button">
668-
<Setter Property="Padding" Value="12 8 12 8" />
669-
<Setter Property="BorderThickness" Value="0" />
670-
<Setter Property="FontWeight" Value="DemiBold" />
671-
<Setter Property="Foreground" Value="Black" />
667+
<Style TargetType="Button">
668+
<Setter Property="Padding" Value="12 8 12 8" />
669+
<Setter Property="BorderThickness" Value="0" />
670+
<Setter Property="FontWeight" Value="DemiBold" />
671+
<Setter Property="Foreground" Value="Black" />
672672
<Style.Triggers>
673673
<DataTrigger Binding="{Binding ElementName=PriorityButton, UpdateSourceTrigger=PropertyChanged, Path=Content}" Value="0">
674674
<Setter Property="Foreground" Value="#878787" />
675675
<Setter Property="FontWeight" Value="Normal" />
676676
</DataTrigger>
677677
</Style.Triggers>
678-
</Style>
679-
</Button.Style>
680-
<!--#endregion-->
681-
</Button>
678+
</Style>
679+
</Button.Style>
680+
<!--#endregion-->
681+
</Button>
682682
</Border>
683683
</StackPanel>
684684
<ui:ToggleSwitch Grid.Column="4" OffContent="{DynamicResource disable}"
@@ -703,15 +703,15 @@
703703
Style="{DynamicResource SettingTitleLabel}"
704704
Margin="0 0 0 0" VerticalAlignment="Center" HorizontalAlignment="Left" DockPanel.Dock="Left"/>
705705

706-
707-
<Button Grid.Column="2" Content="{Binding ActionKeywordsText}"
706+
707+
<Button Grid.Column="2" Content="{Binding ActionKeywordsText}"
708708
DockPanel.Dock="Right"
709709
Visibility="{Binding ActionKeywordsVisibility}"
710710
ToolTip="Change Action Keywords"
711711
Margin="5 0 0 0" Cursor="Hand" FontWeight="Bold"
712712
Click="OnPluginActionKeywordsClick" HorizontalAlignment="Right"
713713
Width="100" Height="40">
714-
714+
715715
<Button.Resources>
716716
<Style TargetType="Border">
717717
<Setter Property="CornerRadius" Value="2"/>
@@ -730,7 +730,7 @@
730730

731731
<StackPanel>
732732

733-
733+
734734
<Border Background="White" Padding="0"
735735
BorderThickness="0 1 0 0" BorderBrush="#e6e6e6"
736736
VerticalAlignment="Center" HorizontalAlignment="Stretch">
@@ -753,8 +753,8 @@
753753
Content="{Binding SettingControl}"
754754
Padding="1" Margin="0" VerticalAlignment="Stretch"
755755
MaxWidth="750" MaxHeight="550">
756-
</ContentControl>
757-
756+
</ContentControl>
757+
758758
</StackPanel>
759759

760760
<StackPanel>
@@ -794,7 +794,7 @@
794794
MouseUp="OnPluginDirecotyClick" Foreground="Blue"
795795
HorizontalAlignment="Right" FontSize="12" VerticalAlignment="Center"/>
796796
</StackPanel>
797-
797+
798798
</ItemsControl>
799799
</Border>
800800

@@ -840,7 +840,7 @@
840840
</Border>
841841
<Border Grid.Column="0" Grid.Row="1" Background="#f3f3f3" Padding="0 0 0 0">
842842
<ListBox x:Name="StoreListBox"
843-
ItemsSource="{Binding PluginViewModels}"
843+
ItemsSource="{Binding ExternalPlugins}"
844844
Margin="6, 0, 0, 0" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
845845
ItemContainerStyle="{StaticResource StoreList}"
846846
ScrollViewer.IsDeferredScrollingEnabled="True" ScrollViewer.CanContentScroll="False"
@@ -849,9 +849,9 @@
849849
<ItemsPanelTemplate>
850850
<UniformGrid IsItemsHost="True" HorizontalAlignment="Left" Columns="2" Margin="0 0 12 18" VerticalAlignment="Top" />
851851
</ItemsPanelTemplate>
852-
853-
854-
852+
853+
854+
855855
</ListBox.ItemsPanel>
856856
<ListBox.ItemTemplate>
857857
<DataTemplate>
@@ -874,10 +874,10 @@
874874
</Style.Triggers>
875875
</Style>
876876
</StackPanel.Style>
877-
<Image Source="{Binding Image, IsAsync=True}"
878-
Width="32" Height="32" Margin="8 0 6 0"
879-
VerticalAlignment="Center"/>
880-
</StackPanel>
877+
<Image Source="{Binding IcoPath, IsAsync=True}"
878+
Width="32" Height="32" Margin="8 0 6 0"
879+
VerticalAlignment="Center"/>
880+
</StackPanel>
881881
<StackPanel Grid.Column="1" Margin="0 0 8 0" VerticalAlignment="Center" Panel.ZIndex="0">
882882
<StackPanel.Style>
883883
<Style>
@@ -889,11 +889,11 @@
889889
</Style.Triggers>
890890
</Style>
891891
</StackPanel.Style>
892-
<TextBlock Text="{Binding PluginPair.Metadata.Name}"
892+
<TextBlock Text="{Binding Name}"
893893
TextWrapping="WrapWithOverflow" Padding="0 0 20 0"
894-
ToolTip="{Binding PluginPair.Metadata.Version}" />
894+
ToolTip="{Binding Version}" />
895895
<TextBlock Opacity="0.5" TextWrapping="WrapWithOverflow" Margin="0 2 0 0" Padding="0 0 20 0">
896-
<Run Text="{Binding PluginPair.Metadata.Description}" FontSize="12" />
896+
<Run Text="{Binding Description}" FontSize="12" />
897897
</TextBlock>
898898

899899
</StackPanel >
@@ -917,18 +917,18 @@
917917
<Grid.ColumnDefinitions>
918918
<ColumnDefinition Width="{Binding ActualWidth,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}}" />
919919
</Grid.ColumnDefinitions>
920-
920+
921921
<StackPanel Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Stretch">
922922
<StackPanel Orientation="Horizontal">
923-
<TextBlock Text="{Binding PluginPair.Metadata.Name}" FontWeight="Bold"
923+
<TextBlock Text="{Binding Name}" FontWeight="Bold"
924924
TextWrapping="WrapWithOverflow" Padding="0 0 0 0" Margin="20 0 0 0"
925-
ToolTip="{Binding PluginPair.Metadata.Name}" />
926-
<TextBlock Text="{Binding PluginPair.Metadata.Version}"
925+
ToolTip="{Binding Name}" />
926+
<TextBlock Text="{Binding Version}"
927927
TextWrapping="WrapWithOverflow" Padding="0 0 20 0" Margin="10 0 0 0"
928-
ToolTip="{Binding PluginPair.Metadata.Version}" />
928+
ToolTip="{Binding Version}" />
929929
</StackPanel>
930930
<TextBlock Opacity="0.5" TextWrapping="Wrap" Margin="20 2 0 0" Padding="0 0 20 0" >
931-
<Run Text="{Binding PluginPair.Metadata.Author}" FontSize="12" />
931+
<Run Text="{Binding Author}" FontSize="12" />
932932
</TextBlock>
933933
</StackPanel>
934934

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Windows.Media.Imaging;
1010
using Flow.Launcher.Core;
1111
using Flow.Launcher.Core.Configuration;
12+
using Flow.Launcher.Core.ExternalPlugins;
1213
using Flow.Launcher.Core.Plugin;
1314
using Flow.Launcher.Core.Resource;
1415
using Flow.Launcher.Helper;
@@ -237,6 +238,14 @@ public IList<PluginViewModel> PluginViewModels
237238
}
238239
}
239240

241+
public IList<UserPlugin> ExternalPlugins
242+
{
243+
get
244+
{
245+
return PluginsManifest.UserPlugins;
246+
}
247+
}
248+
240249
public Control SettingProvider
241250
{
242251
get

Plugins/Flow.Launcher.Plugin.PluginsManager/ContextMenu.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using Flow.Launcher.Infrastructure.UserSettings;
2-
using Flow.Launcher.Plugin.PluginsManager.Models;
1+
using Flow.Launcher.Core.ExternalPlugins;
2+
using Flow.Launcher.Infrastructure.UserSettings;
33
using System;
44
using System.Collections.Generic;
55
using System.Text;

Plugins/Flow.Launcher.Plugin.PluginsManager/Main.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public Task InitAsync(PluginInitContext context)
3838
viewModel = new SettingsViewModel(context, Settings);
3939
contextMenu = new ContextMenu(Context);
4040
pluginManager = new PluginsManager(Context, Settings);
41-
_manifestUpdateTask = pluginManager.UpdateManifest().ContinueWith(_ =>
41+
_manifestUpdateTask = pluginManager.UpdateManifestAsync().ContinueWith(_ =>
4242
{
4343
lastUpdateTime = DateTime.Now;
4444
}, TaskContinuationOptions.OnlyOnRanToCompletion);
@@ -62,7 +62,7 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
6262

6363
if ((DateTime.Now - lastUpdateTime).TotalHours > 12 && _manifestUpdateTask.IsCompleted) // 12 hours
6464
{
65-
_manifestUpdateTask = pluginManager.UpdateManifest().ContinueWith(t =>
65+
_manifestUpdateTask = pluginManager.UpdateManifestAsync().ContinueWith(t =>
6666
{
6767
lastUpdateTime = DateTime.Now;
6868
}, TaskContinuationOptions.OnlyOnRanToCompletion);
@@ -93,7 +93,7 @@ public string GetTranslatedPluginDescription()
9393

9494
public async Task ReloadDataAsync()
9595
{
96-
await pluginManager.UpdateManifest();
96+
await pluginManager.UpdateManifestAsync();
9797
lastUpdateTime = DateTime.Now;
9898
}
9999
}

Plugins/Flow.Launcher.Plugin.PluginsManager/Models/PluginsManifest.cs

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)