From 26b14c4b5f405031ee6e10fc7798d7dd61dfa6c7 Mon Sep 17 00:00:00 2001 From: DB p Date: Fri, 7 Oct 2022 16:34:08 +0900 Subject: [PATCH 01/14] Add Install/New/Updated Label in plugin store --- .../ExternalPlugins/UserPlugin.cs | 11 +++- .../Converters/BoolToVisibilityConverter.cs | 43 ++++++++++++++++ Flow.Launcher/Languages/en.xaml | 8 +++ Flow.Launcher/SettingWindow.xaml | 34 ++++++++++--- .../ViewModel/SettingWindowViewModel.cs | 51 ++++++++++++++++++- 5 files changed, 137 insertions(+), 10 deletions(-) create mode 100644 Flow.Launcher/Converters/BoolToVisibilityConverter.cs diff --git a/Flow.Launcher.Core/ExternalPlugins/UserPlugin.cs b/Flow.Launcher.Core/ExternalPlugins/UserPlugin.cs index f98815c1a9f..0bea2e0e165 100644 --- a/Flow.Launcher.Core/ExternalPlugins/UserPlugin.cs +++ b/Flow.Launcher.Core/ExternalPlugins/UserPlugin.cs @@ -1,4 +1,6 @@ -namespace Flow.Launcher.Core.ExternalPlugins +using System; + +namespace Flow.Launcher.Core.ExternalPlugins { public record UserPlugin { @@ -12,5 +14,12 @@ public record UserPlugin public string UrlDownload { get; set; } public string UrlSourceCode { get; set; } public string IcoPath { get; set; } + public DateTime LatestReleaseDate { get; set; } + public DateTime DateAdded { get; set; } + + /* Label Data for Plugin Store */ + public bool LabelNew { get; set; } + public bool LabelInstalled { get; set; } + public bool LabelUpdated { get; set; } } } diff --git a/Flow.Launcher/Converters/BoolToVisibilityConverter.cs b/Flow.Launcher/Converters/BoolToVisibilityConverter.cs new file mode 100644 index 00000000000..ad474d693b1 --- /dev/null +++ b/Flow.Launcher/Converters/BoolToVisibilityConverter.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; + +namespace Flow.Launcher.Converters +{ + public class BoolToVisibilityConverter : IValueConverter + { + public object Convert(object value, System.Type targetType, object parameter, CultureInfo culture) + { + if (parameter != null) + { + if (value is true) + { + return Visibility.Collapsed; + } + + else + { + return Visibility.Visible; + } + } + else { + if (value is true) + { + return Visibility.Visible; + } + + else { + return Visibility.Collapsed; + } + } + } + + public object ConvertBack(object value, System.Type targetType, object parameter, CultureInfo culture) => throw new System.InvalidOperationException(); + } +} diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index b2018254c6f..e047fd685ce 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -88,6 +88,14 @@ Plugin Store Refresh Install + Installed + Plug-in already installed + New + This is a newly registered plug-in in 7 days + Updated + This plug-in has been updated within the last 5 days + + Theme diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 7fc58377775..d9ec94f98f6 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -38,6 +38,7 @@ + @@ -1513,11 +1514,27 @@ VerticalAlignment="Top" Background="#f14551" CornerRadius="4" - Visibility="Collapsed"> + ToolTip="{DynamicResource LabelNewToolTip}" + Visibility="{Binding LabelNew, Converter={StaticResource BoolToVisibilityConverter}}"> + Foreground="{DynamicResource Color01B}" + Text="{DynamicResource LabelNew}" /> + + + + ToolTip="{DynamicResource LabelInstalledToolTip}" + Visibility="{Binding LabelInstalled, Converter={StaticResource BoolToVisibilityConverter}}"> + Foreground="{DynamicResource Color01B}" + Text="{DynamicResource LabelInstalled}" /> @@ -1670,7 +1688,9 @@ HorizontalAlignment="Right" VerticalAlignment="Center" Click="OnExternalPluginInstallClick" - Content="{DynamicResource install}" /> + Content="{DynamicResource install}" + Visibility="{Binding LabelInstalled, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter='!'}" /> + diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index a63e54f3b0a..3a21a38cb26 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -1,11 +1,14 @@ using System; +using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Net; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; +using System.Windows.Documents; using System.Windows.Media; using System.Windows.Media.Imaging; using Flow.Launcher.Core; @@ -19,6 +22,8 @@ using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; using Flow.Launcher.Plugin.SharedModels; +using Microsoft.FSharp.Data.UnitSystems.SI.UnitNames; +using Windows.Management.Deployment.Preview; namespace Flow.Launcher.ViewModel { @@ -241,7 +246,8 @@ public string TestProxy() #region plugin - public static string Plugin => @"https://github.com/Flow-Launcher/Flow.Launcher.PluginsManifest"; + //public static string Plugin => @"https://github.com/Flow-Launcher/Flow.Launcher.PluginsManifest"; + public static string Plugin => @"https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/plugin_api_v2/plugins.json"; public PluginViewModel SelectedPlugin { get; set; } public IList PluginViewModels @@ -261,10 +267,51 @@ public IList ExternalPlugins { get { - return PluginsManifest.UserPlugins; + return LabelMaker(PluginsManifest.UserPlugins); } } + private IList LabelMaker(IList list) + { + foreach (UserPlugin item in list) + { + item.LabelNew = false; + item.LabelInstalled = false; + item.LabelUpdated = false; + + foreach (var vm in PluginViewModels) + { + + var id = vm.PluginPair.Metadata.ID; + if (item.ID == vm.PluginPair.Metadata.ID) // Add Installed Label + { + item.LabelInstalled = true; + } + + TimeSpan UpdatedDay = DateTime.Now.Subtract(item.LatestReleaseDate); + int LastUpdated = UpdatedDay.Days; + + if (LastUpdated <= 5) // Add Updated Label + { + item.LabelUpdated = true; + } + } + TimeSpan AddedDay = DateTime.Now.Subtract(item.DateAdded); + int DateAdded = AddedDay.Days; + if (DateAdded <= 7) + { + + //item.LabelNew = true; // Add New Label + //item.LabelUpdated = false; // Hide Updated Label when Added New Label. New and Update doesn't show both same time. + } + } + + // New first, Updated second. Installed to bottom of list. + list = list.OrderByDescending(x => x.LabelNew).OrderByDescending(x => x.LabelUpdated).ThenBy(y => y.LabelInstalled).ToList(); + + return list; + } + public Control SettingProvider { get From 15df419a5e1185ac67853ee97d812b8dfb6b3ec6 Mon Sep 17 00:00:00 2001 From: DB p Date: Sat, 8 Oct 2022 09:47:38 +0900 Subject: [PATCH 02/14] - Change list order - remove comment --- Flow.Launcher/ViewModel/SettingWindowViewModel.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index 6e76e31c196..fd0f49c821e 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -267,8 +267,7 @@ public string TestProxy() #region plugin - //public static string Plugin => @"https://github.com/Flow-Launcher/Flow.Launcher.PluginsManifest"; - public static string Plugin => @"https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/plugin_api_v2/plugins.json"; + public static string Plugin => @"https://github.com/Flow-Launcher/Flow.Launcher.PluginsManifest"; public PluginViewModel SelectedPlugin { get; set; } public IList PluginViewModels @@ -322,8 +321,8 @@ private IList LabelMaker(IList list) if (DateAdded <= 7) { - //item.LabelNew = true; // Add New Label - //item.LabelUpdated = false; // Hide Updated Label when Added New Label. New and Update doesn't show both same time. + item.LabelNew = true; // Add New Label + item.LabelUpdated = false; // Hide Updated Label when Added New Label. New and Update doesn't show both same time. } } From bc47671129d9b223951e3131c5f69cd4778f02e5 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Sat, 8 Oct 2022 01:57:41 -0500 Subject: [PATCH 03/14] User ViewModel to separate logic --- .../ExternalPlugins/UserPlugin.cs | 4 -- .../ViewModel/PluginStoreItemViewModel.cs | 27 +++++++++++ .../ViewModel/SettingWindowViewModel.cs | 46 +++---------------- 3 files changed, 34 insertions(+), 43 deletions(-) create mode 100644 Flow.Launcher/ViewModel/PluginStoreItemViewModel.cs diff --git a/Flow.Launcher.Core/ExternalPlugins/UserPlugin.cs b/Flow.Launcher.Core/ExternalPlugins/UserPlugin.cs index 0bea2e0e165..bb1279b2c61 100644 --- a/Flow.Launcher.Core/ExternalPlugins/UserPlugin.cs +++ b/Flow.Launcher.Core/ExternalPlugins/UserPlugin.cs @@ -17,9 +17,5 @@ public record UserPlugin public DateTime LatestReleaseDate { get; set; } public DateTime DateAdded { get; set; } - /* Label Data for Plugin Store */ - public bool LabelNew { get; set; } - public bool LabelInstalled { get; set; } - public bool LabelUpdated { get; set; } } } diff --git a/Flow.Launcher/ViewModel/PluginStoreItemViewModel.cs b/Flow.Launcher/ViewModel/PluginStoreItemViewModel.cs new file mode 100644 index 00000000000..94b435f1a3a --- /dev/null +++ b/Flow.Launcher/ViewModel/PluginStoreItemViewModel.cs @@ -0,0 +1,27 @@ +using System; +using Flow.Launcher.Core.ExternalPlugins; +using Flow.Launcher.Core.Plugin; +using Flow.Launcher.Plugin; + +namespace Flow.Launcher.ViewModel +{ + public class PluginStoreItemViewModel : BaseModel + { + public PluginStoreItemViewModel(UserPlugin plugin) + { + _plugin = plugin; + } + + private UserPlugin _plugin; + + public string Name => _plugin.Name; + public string Description => _plugin.Description; + public string Author => _plugin.Author; + public string Version => _plugin.Version; + + + public bool LabelNew => _plugin.LatestReleaseDate-DateTime.Now < TimeSpan.FromDays(7); + public bool LabelInstalled => PluginManager.GetPluginForId(_plugin.ID) != null; + public bool LabelUpdated => _plugin.DateAdded -DateTime.Now < TimeSpan.FromDays(7); + } +} diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index fd0f49c821e..99a05548fda 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -283,7 +283,7 @@ public IList PluginViewModels } } - public IList ExternalPlugins + public IList ExternalPlugins { get { @@ -291,45 +291,13 @@ public IList ExternalPlugins } } - private IList LabelMaker(IList list) + private IList LabelMaker(IList list) { - foreach (UserPlugin item in list) - { - item.LabelNew = false; - item.LabelInstalled = false; - item.LabelUpdated = false; - - foreach (var vm in PluginViewModels) - { - - var id = vm.PluginPair.Metadata.ID; - if (item.ID == vm.PluginPair.Metadata.ID) // Add Installed Label - { - item.LabelInstalled = true; - } - - TimeSpan UpdatedDay = DateTime.Now.Subtract(item.LatestReleaseDate); - int LastUpdated = UpdatedDay.Days; - - if (LastUpdated <= 5) // Add Updated Label - { - item.LabelUpdated = true; - } - } - TimeSpan AddedDay = DateTime.Now.Subtract(item.DateAdded); - int DateAdded = AddedDay.Days; - if (DateAdded <= 7) - { - - item.LabelNew = true; // Add New Label - item.LabelUpdated = false; // Hide Updated Label when Added New Label. New and Update doesn't show both same time. - } - } - - // New first, Updated second. Installed to bottom of list. - list = list.OrderByDescending(x => x.LabelNew).OrderByDescending(x => x.LabelUpdated).ThenBy(y => y.LabelInstalled).ToList(); - - return list; + return list.Select(p=>new PluginStoreItemViewModel(p)) + .OrderBy(p=>p.LabelNew) + .ThenByDescending(p=>p.LabelUpdated) + .ThenBy(p=>p.LabelInstalled) + .ToList(); } public Control SettingProvider From e3e0545c9d96f1ca5503a407732443c60d717d3c Mon Sep 17 00:00:00 2001 From: DB p Date: Sat, 8 Oct 2022 18:27:17 +0900 Subject: [PATCH 04/14] - Fix Mode to oneway - Add sources - Hide Updated label when LabelNew --- Flow.Launcher/SettingWindow.xaml | 4 ++-- Flow.Launcher/ViewModel/PluginStoreItemViewModel.cs | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index bd4cca0bbfc..74798235a31 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -1625,7 +1625,7 @@ + Text="{Binding Description, Mode=OneWay}" /> @@ -1687,7 +1687,7 @@ Foreground="{DynamicResource Color04B}" NavigateUri="{Binding Website}" RequestNavigate="OnRequestNavigate"> - + diff --git a/Flow.Launcher/ViewModel/PluginStoreItemViewModel.cs b/Flow.Launcher/ViewModel/PluginStoreItemViewModel.cs index 94b435f1a3a..60651173859 100644 --- a/Flow.Launcher/ViewModel/PluginStoreItemViewModel.cs +++ b/Flow.Launcher/ViewModel/PluginStoreItemViewModel.cs @@ -16,12 +16,16 @@ public PluginStoreItemViewModel(UserPlugin plugin) public string Name => _plugin.Name; public string Description => _plugin.Description; + public string IcoPath => _plugin.IcoPath; public string Author => _plugin.Author; + public string Website => _plugin.Website; + public string Language => _plugin.Language; + public string UrlDownload => _plugin.UrlDownload; + public string UrlSourceCode => _plugin.UrlSourceCode; public string Version => _plugin.Version; - public bool LabelNew => _plugin.LatestReleaseDate-DateTime.Now < TimeSpan.FromDays(7); public bool LabelInstalled => PluginManager.GetPluginForId(_plugin.ID) != null; - public bool LabelUpdated => _plugin.DateAdded -DateTime.Now < TimeSpan.FromDays(7); + public bool LabelUpdated => _plugin.DateAdded -DateTime.Now < TimeSpan.FromDays(5) && !LabelNew; } } From b7e51e5e69c5c5450b7645f544281e3be2d86187 Mon Sep 17 00:00:00 2001 From: DB p Date: Sat, 8 Oct 2022 18:32:42 +0900 Subject: [PATCH 05/14] Fix Install Button --- Flow.Launcher/SettingWindow.xaml.cs | 2 +- Flow.Launcher/ViewModel/PluginStoreItemViewModel.cs | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index e681d78ab23..db46b6f2488 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -306,7 +306,7 @@ private void OnPluginStoreRefreshClick(object sender, RoutedEventArgs e) private void OnExternalPluginInstallClick(object sender, RoutedEventArgs e) { - if (sender is Button { DataContext: UserPlugin plugin }) + if (sender is Button { DataContext: PluginStoreItemViewModel plugin }) { var pluginsManagerPlugin = PluginManager.GetPluginForId("9f8f9b14-2518-4907-b211-35ab6290dee7"); var actionKeyword = pluginsManagerPlugin.Metadata.ActionKeywords.Count == 0 ? "" : pluginsManagerPlugin.Metadata.ActionKeywords[0]; diff --git a/Flow.Launcher/ViewModel/PluginStoreItemViewModel.cs b/Flow.Launcher/ViewModel/PluginStoreItemViewModel.cs index 60651173859..e0235b5ac56 100644 --- a/Flow.Launcher/ViewModel/PluginStoreItemViewModel.cs +++ b/Flow.Launcher/ViewModel/PluginStoreItemViewModel.cs @@ -14,16 +14,17 @@ public PluginStoreItemViewModel(UserPlugin plugin) private UserPlugin _plugin; + public string ID => _plugin.ID; public string Name => _plugin.Name; public string Description => _plugin.Description; - public string IcoPath => _plugin.IcoPath; public string Author => _plugin.Author; - public string Website => _plugin.Website; + public string Version => _plugin.Version; public string Language => _plugin.Language; + public string Website => _plugin.Website; public string UrlDownload => _plugin.UrlDownload; public string UrlSourceCode => _plugin.UrlSourceCode; - public string Version => _plugin.Version; - + public string IcoPath => _plugin.IcoPath; + public bool LabelNew => _plugin.LatestReleaseDate-DateTime.Now < TimeSpan.FromDays(7); public bool LabelInstalled => PluginManager.GetPluginForId(_plugin.ID) != null; public bool LabelUpdated => _plugin.DateAdded -DateTime.Now < TimeSpan.FromDays(5) && !LabelNew; From 6b2a78e1f2a6b2dcf983d1cd5fac40fa9bcfbd52 Mon Sep 17 00:00:00 2001 From: DB p Date: Tue, 11 Oct 2022 21:37:43 +0900 Subject: [PATCH 06/14] - Add Uninstall / Update Btn - Adjust Strings --- Flow.Launcher/Languages/en.xaml | 5 ++-- Flow.Launcher/SettingWindow.xaml | 30 ++++++++++++++----- Flow.Launcher/SettingWindow.xaml.cs | 22 ++++++++++++++ .../ViewModel/PluginStoreItemViewModel.cs | 7 +++-- 4 files changed, 51 insertions(+), 13 deletions(-) diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index 149dcb817d1..2dd61329a0c 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -84,13 +84,14 @@ Query time: | Version Website - Uninstall Plugin Store Refresh - Install + Install + Uninstall + Update Installed Plug-in already installed New diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 74798235a31..0a87ba677fc 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -1320,7 +1320,7 @@ FontSize="11" Foreground="{DynamicResource PluginInfoColor}" MouseUp="OnExternalPluginUninstallClick" - Text="{DynamicResource plugin_uninstall}" + Text="{DynamicResource uninstallbtn}" TextDecorations="Underline" /> - + +