Skip to content

Commit 26b14c4

Browse files
committed
Add Install/New/Updated Label in plugin store
1 parent f8cef1d commit 26b14c4

File tree

5 files changed

+137
-10
lines changed

5 files changed

+137
-10
lines changed

Flow.Launcher.Core/ExternalPlugins/UserPlugin.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Flow.Launcher.Core.ExternalPlugins
1+
using System;
2+
3+
namespace Flow.Launcher.Core.ExternalPlugins
24
{
35
public record UserPlugin
46
{
@@ -12,5 +14,12 @@ public record UserPlugin
1214
public string UrlDownload { get; set; }
1315
public string UrlSourceCode { get; set; }
1416
public string IcoPath { get; set; }
17+
public DateTime LatestReleaseDate { get; set; }
18+
public DateTime DateAdded { get; set; }
19+
20+
/* Label Data for Plugin Store */
21+
public bool LabelNew { get; set; }
22+
public bool LabelInstalled { get; set; }
23+
public bool LabelUpdated { get; set; }
1524
}
1625
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
using System.Windows.Controls;
9+
using System.Windows.Data;
10+
11+
namespace Flow.Launcher.Converters
12+
{
13+
public class BoolToVisibilityConverter : IValueConverter
14+
{
15+
public object Convert(object value, System.Type targetType, object parameter, CultureInfo culture)
16+
{
17+
if (parameter != null)
18+
{
19+
if (value is true)
20+
{
21+
return Visibility.Collapsed;
22+
}
23+
24+
else
25+
{
26+
return Visibility.Visible;
27+
}
28+
}
29+
else {
30+
if (value is true)
31+
{
32+
return Visibility.Visible;
33+
}
34+
35+
else {
36+
return Visibility.Collapsed;
37+
}
38+
}
39+
}
40+
41+
public object ConvertBack(object value, System.Type targetType, object parameter, CultureInfo culture) => throw new System.InvalidOperationException();
42+
}
43+
}

Flow.Launcher/Languages/en.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@
8888
<system:String x:Key="pluginStore">Plugin Store</system:String>
8989
<system:String x:Key="refresh">Refresh</system:String>
9090
<system:String x:Key="install">Install</system:String>
91+
<system:String x:Key="LabelInstalled">Installed</system:String>
92+
<system:String x:Key="LabelInstalledToolTip">Plug-in already installed</system:String>
93+
<system:String x:Key="LabelNew">New</system:String>
94+
<system:String x:Key="LabelNewToolTip">This is a newly registered plug-in in 7 days</system:String>
95+
<system:String x:Key="LabelUpdated">Updated</system:String>
96+
<system:String x:Key="LabelUpdatedToolTip">This plug-in has been updated within the last 5 days</system:String>
97+
98+
9199

92100
<!-- Setting Theme -->
93101
<system:String x:Key="theme">Theme</system:String>

Flow.Launcher/SettingWindow.xaml

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
<Window.Resources>
4040
<converters:BorderClipConverter x:Key="BorderClipConverter" />
41+
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
4142
<CollectionViewSource x:Key="SortedFonts" Source="{Binding Source={x:Static Fonts.SystemFontFamilies}}">
4243
<CollectionViewSource.SortDescriptions>
4344
<scm:SortDescription PropertyName="Source" />
@@ -1513,11 +1514,27 @@
15131514
VerticalAlignment="Top"
15141515
Background="#f14551"
15151516
CornerRadius="4"
1516-
Visibility="Collapsed">
1517+
ToolTip="{DynamicResource LabelNewToolTip}"
1518+
Visibility="{Binding LabelNew, Converter={StaticResource BoolToVisibilityConverter}}">
15171519
<TextBlock
15181520
FontSize="11"
1519-
Foreground="White"
1520-
Text="New" />
1521+
Foreground="{DynamicResource Color01B}"
1522+
Text="{DynamicResource LabelNew}" />
1523+
</Border>
1524+
<Border
1525+
x:Name="LabelUpdated"
1526+
Margin="0,10,8,0"
1527+
Padding="6,2,6,2"
1528+
HorizontalAlignment="Right"
1529+
VerticalAlignment="Top"
1530+
Background="#45BD59"
1531+
CornerRadius="4"
1532+
ToolTip="{DynamicResource LabelUpdatedToolTip}"
1533+
Visibility="{Binding LabelUpdated, Converter={StaticResource BoolToVisibilityConverter}}">
1534+
<TextBlock
1535+
FontSize="11"
1536+
Foreground="{DynamicResource Color01B}"
1537+
Text="{DynamicResource LabelUpdated}" />
15211538
</Border>
15221539
<Border
15231540
x:Name="Labelinstalled"
@@ -1527,11 +1544,12 @@
15271544
VerticalAlignment="Top"
15281545
Background="{DynamicResource ToggleSwitchFillOn}"
15291546
CornerRadius="4"
1530-
Visibility="Collapsed">
1547+
ToolTip="{DynamicResource LabelInstalledToolTip}"
1548+
Visibility="{Binding LabelInstalled, Converter={StaticResource BoolToVisibilityConverter}}">
15311549
<TextBlock
15321550
FontSize="11"
1533-
Foreground="White"
1534-
Text="Installed" />
1551+
Foreground="{DynamicResource Color01B}"
1552+
Text="{DynamicResource LabelInstalled}" />
15351553
</Border>
15361554
</StackPanel>
15371555

@@ -1670,7 +1688,9 @@
16701688
HorizontalAlignment="Right"
16711689
VerticalAlignment="Center"
16721690
Click="OnExternalPluginInstallClick"
1673-
Content="{DynamicResource install}" />
1691+
Content="{DynamicResource install}"
1692+
Visibility="{Binding LabelInstalled, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter='!'}" />
1693+
<!-- Hide Install Button when installed Item -->
16741694
</Border>
16751695
</Grid>
16761696
</StackPanel>

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
4+
using System.Diagnostics;
35
using System.IO;
46
using System.Linq;
57
using System.Net;
68
using System.Threading.Tasks;
79
using System.Windows;
810
using System.Windows.Controls;
11+
using System.Windows.Documents;
912
using System.Windows.Media;
1013
using System.Windows.Media.Imaging;
1114
using Flow.Launcher.Core;
@@ -19,6 +22,8 @@
1922
using Flow.Launcher.Infrastructure.UserSettings;
2023
using Flow.Launcher.Plugin;
2124
using Flow.Launcher.Plugin.SharedModels;
25+
using Microsoft.FSharp.Data.UnitSystems.SI.UnitNames;
26+
using Windows.Management.Deployment.Preview;
2227

2328
namespace Flow.Launcher.ViewModel
2429
{
@@ -241,7 +246,8 @@ public string TestProxy()
241246

242247
#region plugin
243248

244-
public static string Plugin => @"https://github.com/Flow-Launcher/Flow.Launcher.PluginsManifest";
249+
//public static string Plugin => @"https://github.com/Flow-Launcher/Flow.Launcher.PluginsManifest";
250+
public static string Plugin => @"https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/plugin_api_v2/plugins.json";
245251
public PluginViewModel SelectedPlugin { get; set; }
246252

247253
public IList<PluginViewModel> PluginViewModels
@@ -261,10 +267,51 @@ public IList<UserPlugin> ExternalPlugins
261267
{
262268
get
263269
{
264-
return PluginsManifest.UserPlugins;
270+
return LabelMaker(PluginsManifest.UserPlugins);
265271
}
266272
}
267273

274+
private IList<UserPlugin> LabelMaker(IList<UserPlugin> list)
275+
{
276+
foreach (UserPlugin item in list)
277+
{
278+
item.LabelNew = false;
279+
item.LabelInstalled = false;
280+
item.LabelUpdated = false;
281+
282+
foreach (var vm in PluginViewModels)
283+
{
284+
285+
var id = vm.PluginPair.Metadata.ID;
286+
if (item.ID == vm.PluginPair.Metadata.ID) // Add Installed Label
287+
{
288+
item.LabelInstalled = true;
289+
}
290+
291+
TimeSpan UpdatedDay = DateTime.Now.Subtract(item.LatestReleaseDate);
292+
int LastUpdated = UpdatedDay.Days;
293+
294+
if (LastUpdated <= 5) // Add Updated Label
295+
{
296+
item.LabelUpdated = true;
297+
}
298+
}
299+
TimeSpan AddedDay = DateTime.Now.Subtract(item.DateAdded);
300+
int DateAdded = AddedDay.Days;
301+
if (DateAdded <= 7)
302+
{
303+
304+
//item.LabelNew = true; // Add New Label
305+
//item.LabelUpdated = false; // Hide Updated Label when Added New Label. New and Update doesn't show both same time.
306+
}
307+
}
308+
309+
// New first, Updated second. Installed to bottom of list.
310+
list = list.OrderByDescending(x => x.LabelNew).OrderByDescending(x => x.LabelUpdated).ThenBy(y => y.LabelInstalled).ToList();
311+
312+
return list;
313+
}
314+
268315
public Control SettingProvider
269316
{
270317
get

0 commit comments

Comments
 (0)