Skip to content

Commit 8c387d0

Browse files
committed
Improve code quality & Add oneway bind mode
1 parent 102636f commit 8c387d0

File tree

2 files changed

+42
-33
lines changed

2 files changed

+42
-33
lines changed

Flow.Launcher/Resources/Controls/InstalledPluginDisplay.xaml

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
<UserControl x:Class="Flow.Launcher.Resources.Controls.InstalledPluginDisplay"
2-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6-
xmlns:ui="http://schemas.modernwpf.com/2019"
7-
xmlns:viewModel="clr-namespace:Flow.Launcher.ViewModel"
8-
xmlns:cc="clr-namespace:Flow.Launcher.Resources.Controls"
9-
mc:Ignorable="d"
10-
d:DataContext="{d:DesignInstance viewModel:PluginViewModel}"
11-
d:DesignHeight="300" d:DesignWidth="300">
1+
<UserControl
2+
x:Class="Flow.Launcher.Resources.Controls.InstalledPluginDisplay"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:cc="clr-namespace:Flow.Launcher.Resources.Controls"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
xmlns:ui="http://schemas.modernwpf.com/2019"
9+
xmlns:viewModel="clr-namespace:Flow.Launcher.ViewModel"
10+
d:DataContext="{d:DesignInstance viewModel:PluginViewModel}"
11+
d:DesignHeight="300"
12+
d:DesignWidth="300"
13+
mc:Ignorable="d">
1214
<Expander
1315
Padding="0"
1416
BorderThickness="0"
@@ -28,7 +30,7 @@
2830
Grid.Column="0"
2931
Width="32"
3032
Height="32"
31-
Source="{Binding Image, IsAsync=True}" />
33+
Source="{Binding Image, Mode=OneWay, IsAsync=True}" />
3234
<StackPanel Grid.Column="1" Margin="16 0 14 0">
3335
<TextBlock
3436
Foreground="{DynamicResource Color05B}"
@@ -37,12 +39,15 @@
3739
ToolTip="{Binding PluginPair.Metadata.Version}" />
3840
<TextBlock
3941
Margin="0 2 0 0"
40-
Foreground="{DynamicResource Color04B}"
4142
FontSize="12"
43+
Foreground="{DynamicResource Color04B}"
4244
Text="{Binding PluginPair.Metadata.Description}"
4345
TextWrapping="WrapWithOverflow" />
4446
</StackPanel>
45-
<StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Right">
47+
<StackPanel
48+
Grid.Column="2"
49+
HorizontalAlignment="Right"
50+
Orientation="Horizontal">
4651
<TextBlock
4752
Margin="0 0 8 0"
4853
VerticalAlignment="Center"
@@ -70,9 +75,7 @@
7075
<Setter Property="FontWeight" Value="DemiBold" />
7176
<Setter Property="Foreground" Value="{DynamicResource Color05B}" />
7277
<Style.Triggers>
73-
<DataTrigger
74-
Binding="{Binding ElementName=PriorityButton, UpdateSourceTrigger=PropertyChanged, Path=Content}"
75-
Value="0">
78+
<DataTrigger Binding="{Binding ElementName=PriorityButton, UpdateSourceTrigger=PropertyChanged, Path=Content}" Value="0">
7679
<Setter Property="Foreground" Value="{DynamicResource Color08B}" />
7780
<Setter Property="FontWeight" Value="Normal" />
7881
</DataTrigger>
@@ -98,9 +101,9 @@
98101
<ContentControl Content="{Binding BottomPart2}" />
99102

100103
<Border
101-
BorderThickness="0 1 0 0"
104+
Background="{DynamicResource Color00B}"
102105
BorderBrush="{DynamicResource Color03B}"
103-
Background="{DynamicResource Color00B}">
106+
BorderThickness="0 1 0 0">
104107
<Border.Style>
105108
<Style TargetType="Border">
106109
<Style.Triggers>

Flow.Launcher/ViewModel/PluginViewModel.cs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
using System.Linq;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
24
using System.Windows;
3-
using System.Windows.Media;
4-
using Flow.Launcher.Plugin;
5-
using Flow.Launcher.Infrastructure.Image;
6-
using Flow.Launcher.Core.Plugin;
75
using System.Windows.Controls;
8-
using CommunityToolkit.Mvvm.Input;
9-
using Flow.Launcher.Core.Resource;
10-
using Flow.Launcher.Resources.Controls;
11-
using System.Collections.Generic;
6+
using System.Windows.Media;
127
using CommunityToolkit.Mvvm.DependencyInjection;
8+
using CommunityToolkit.Mvvm.Input;
9+
using Flow.Launcher.Core.Plugin;
10+
using Flow.Launcher.Infrastructure.Image;
1311
using Flow.Launcher.Infrastructure.UserSettings;
12+
using Flow.Launcher.Plugin;
13+
using Flow.Launcher.Resources.Controls;
1414

1515
namespace Flow.Launcher.ViewModel
1616
{
@@ -31,7 +31,7 @@ public PluginPair PluginPair
3131
}
3232
}
3333

34-
private string PluginManagerActionKeyword
34+
private static string PluginManagerActionKeyword
3535
{
3636
get
3737
{
@@ -46,17 +46,18 @@ private string PluginManagerActionKeyword
4646
}
4747
}
4848

49-
private async void LoadIconAsync()
49+
private async Task LoadIconAsync()
5050
{
5151
Image = await ImageLoader.LoadAsync(PluginPair.Metadata.IcoPath);
52+
OnPropertyChanged(nameof(Image));
5253
}
5354

5455
public ImageSource Image
5556
{
5657
get
5758
{
5859
if (_image == ImageLoader.MissingImage)
59-
LoadIconAsync();
60+
_ = LoadIconAsync();
6061

6162
return _image;
6263
}
@@ -118,11 +119,16 @@ public Control SettingControl
118119
: null;
119120
private ImageSource _image = ImageLoader.MissingImage;
120121

121-
public Visibility ActionKeywordsVisibility => PluginPair.Metadata.HideActionKeywordPanel ? Visibility.Collapsed : Visibility.Visible;
122+
public Visibility ActionKeywordsVisibility => PluginPair.Metadata.HideActionKeywordPanel ?
123+
Visibility.Collapsed : Visibility.Visible;
122124
public string InitilizaTime => PluginPair.Metadata.InitTime + "ms";
123125
public string QueryTime => PluginPair.Metadata.AvgQueryTime + "ms";
124-
public string Version => InternationalizationManager.Instance.GetTranslation("plugin_query_version") + " " + PluginPair.Metadata.Version;
125-
public string InitAndQueryTime => InternationalizationManager.Instance.GetTranslation("plugin_init_time") + " " + PluginPair.Metadata.InitTime + "ms, " + InternationalizationManager.Instance.GetTranslation("plugin_query_time") + " " + PluginPair.Metadata.AvgQueryTime + "ms";
126+
public string Version => App.API.GetTranslation("plugin_query_version") + " " + PluginPair.Metadata.Version;
127+
public string InitAndQueryTime =>
128+
App.API.GetTranslation("plugin_init_time") + " " +
129+
PluginPair.Metadata.InitTime + "ms, " +
130+
App.API.GetTranslation("plugin_query_time") + " " +
131+
PluginPair.Metadata.AvgQueryTime + "ms";
126132
public string ActionKeywordsText => string.Join(Query.ActionKeywordSeparator, PluginPair.Metadata.ActionKeywords);
127133
public int Priority => PluginPair.Metadata.Priority;
128134
public Infrastructure.UserSettings.Plugin PluginSettingsObject { get; set; }

0 commit comments

Comments
 (0)