Merge Binding

This commit is contained in:
Dobin Park 2021-10-11 07:34:42 +09:00
commit 4aae10173d
15 changed files with 137 additions and 96 deletions

View 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();
}
}
}
}

View file

@ -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; }
}
}

View file

@ -176,6 +176,7 @@ namespace Flow.Launcher.Core.Resource
dict["ItemSubTitleStyle"] is Style resultSubItemStyle &&
dict["ItemSubTitleSelectedStyle"] is Style resultSubItemSelectedStyle &&
dict["ItemTitleSelectedStyle"] is Style resultItemSelectedStyle &&
dict["ItemHotkeyStyle"] is Style resultHotkeyItemStyle &&
dict["ItemHotkeySelectedStyle"] is Style resultHotkeyItemSelectedStyle)
{
Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(Settings.ResultFont));
@ -184,7 +185,9 @@ namespace Flow.Launcher.Core.Resource
Setter fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(Settings.ResultFontStretch));
Setter[] setters = { fontFamily, fontStyle, fontWeight, fontStretch };
Array.ForEach(new[] { resultItemStyle, resultSubItemStyle, resultItemSelectedStyle, resultSubItemSelectedStyle, resultHotkeyItemSelectedStyle }, o => Array.ForEach(setters, p => o.Setters.Add(p)));
Array.ForEach(
new[] { resultItemStyle, resultSubItemStyle, resultItemSelectedStyle, resultSubItemSelectedStyle, resultHotkeyItemStyle, resultHotkeyItemSelectedStyle }, o
=> Array.ForEach(setters, p => o.Setters.Add(p)));
}
var windowStyle = dict["WindowStyle"] as Style;

View file

@ -110,7 +110,7 @@ namespace Flow.Launcher.Helper
return;
mainViewModel.MainWindowVisibility = Visibility.Visible;
mainViewModel.ChangeQueryText(hotkey.ActionKeyword);
mainViewModel.ChangeQueryText(hotkey.ActionKeyword, true);
});
}

View file

@ -48,12 +48,7 @@ namespace Flow.Launcher
public void ChangeQuery(string query, bool requery = false)
{
_mainVM.ChangeQueryText(query);
}
public void ChangeQueryText(string query, bool selectAll = false)
{
_mainVM.ChangeQueryText(query);
_mainVM.ChangeQueryText(query, requery);
}
public void RestartApp()

View file

@ -689,28 +689,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}"
@ -735,15 +735,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"/>
@ -762,7 +762,7 @@
<StackPanel>
<Border Background="White" Padding="0"
BorderThickness="0 1 0 0" BorderBrush="#e6e6e6"
VerticalAlignment="Center" HorizontalAlignment="Stretch">
@ -785,8 +785,8 @@
Content="{Binding SettingControl}"
Padding="1" Margin="0" VerticalAlignment="Stretch"
MaxWidth="750" MaxHeight="550">
</ContentControl>
</ContentControl>
</StackPanel>
<StackPanel>
@ -826,7 +826,7 @@
MouseUp="OnPluginDirecotyClick" Foreground="Blue"
HorizontalAlignment="Right" FontSize="12" VerticalAlignment="Center"/>
</StackPanel>
</ItemsControl>
</Border>
@ -872,8 +872,8 @@
</Border>
<Border Grid.Column="0" Grid.Row="1" Background="#f3f3f3" Padding="0 0 0 0">
<ListBox x:Name="StoreListBox"
ItemsSource="{Binding PluginViewModels}"
Margin="5, 1, 0, 0" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ItemsSource="{Binding ExternalPlugins}"
Margin="6, 0, 0, 0" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ItemContainerStyle="{StaticResource StoreList}"
ScrollViewer.IsDeferredScrollingEnabled="True" ScrollViewer.CanContentScroll="False"
Padding="0 0 0 0" Width="Auto" VerticalContentAlignment="Center" HorizontalAlignment="Stretch">
@ -881,6 +881,9 @@
<ItemsPanelTemplate>
<UniformGrid IsItemsHost="True" HorizontalAlignment="Left" Columns="2" Margin="0 0 6 18" VerticalAlignment="Top" SnapsToDevicePixels="True"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
@ -903,10 +906,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>
@ -918,11 +921,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 >
@ -946,18 +949,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>

View file

@ -285,9 +285,17 @@ namespace Flow.Launcher.ViewModel
/// but we don't want to move cursor to end when query is updated from TextBox
/// </summary>
/// <param name="queryText"></param>
public void ChangeQueryText(string queryText)
public void ChangeQueryText(string queryText, bool reQuery = false)
{
QueryText = queryText;
if (QueryText!=queryText)
{
// re-query is done in QueryText's setter method
QueryText = queryText;
}
else if (reQuery)
{
Query();
}
QueryTextCursorMovedToEnd = true;
}

View file

@ -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

View file

@ -17,7 +17,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
{
// Reserved keywords in oleDB
private const string reservedStringPattern = @"^[`\@\#\^,\&\/\\\$\%_]+$";
private const string reservedStringPattern = @"^[`\@\#\^,\&\/\\\$\%_;\[\]]+$";
internal static async Task<List<Result>> ExecuteWindowsIndexSearchAsync(string indexQueryString, string connectionString, Query query, CancellationToken token)
{

View file

@ -10,7 +10,7 @@
"Name": "Explorer",
"Description": "Search and manage files and folders. Explorer utilises Windows Index Search",
"Author": "Jeremy Wu",
"Version": "1.9.0",
"Version": "1.9.1",
"Language": "csharp",
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
"ExecuteFileName": "Flow.Launcher.Plugin.Explorer.dll",

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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>();
}
}
}
}

View file

@ -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

View file

@ -6,7 +6,7 @@
"Name": "Plugins Manager",
"Description": "Management of installing, uninstalling or updating Flow Launcher plugins",
"Author": "Jeremy Wu",
"Version": "1.8.5",
"Version": "1.9.0",
"Language": "csharp",
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
"ExecuteFileName": "Flow.Launcher.Plugin.PluginsManager.dll",