From fd39b60f7b5904dcee03c1772f87fd1e94f89aac Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Sat, 31 Jul 2021 15:44:41 +0800 Subject: [PATCH 1/6] Add Glyph Support --- Flow.Launcher.Plugin/Result.cs | 10 +++++++++- Flow.Launcher/ResultListBox.xaml | 5 ++++- Flow.Launcher/ViewModel/ResultViewModel.cs | 11 ++++++++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Flow.Launcher.Plugin/Result.cs b/Flow.Launcher.Plugin/Result.cs index ac9c10df05b..171b30c2675 100644 --- a/Flow.Launcher.Plugin/Result.cs +++ b/Flow.Launcher.Plugin/Result.cs @@ -47,7 +47,15 @@ public string IcoPath public delegate ImageSource IconDelegate(); - public IconDelegate Icon; + /// + /// Delegate to Get Image Source + /// + public IconDelegate Icon { get; set; } + + /// + /// Information for Glyph Icon + /// + public GlyphInfo Glyph { get; init; } /// diff --git a/Flow.Launcher/ResultListBox.xaml b/Flow.Launcher/ResultListBox.xaml index 2f9d06d814e..877b82a0697 100644 --- a/Flow.Launcher/ResultListBox.xaml +++ b/Flow.Launcher/ResultListBox.xaml @@ -42,7 +42,10 @@ + Source="{Binding Image.Value}" Visibility="{Binding ShowImage}" /> + diff --git a/Flow.Launcher/ViewModel/ResultViewModel.cs b/Flow.Launcher/ViewModel/ResultViewModel.cs index c91bbb1074f..ce4b23d2184 100644 --- a/Flow.Launcher/ViewModel/ResultViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultViewModel.cs @@ -66,7 +66,9 @@ public ResultViewModel(Result result, Settings settings) { OnPropertyChanged(nameof(Image)); }); - } + + Glyph = Result.Glyph; + } Settings = settings; } @@ -74,7 +76,8 @@ public ResultViewModel(Result result, Settings settings) public Settings Settings { get; private set; } public Visibility ShowOpenResultHotkey => Settings.ShowOpenResultHotkey ? Visibility.Visible : Visibility.Hidden; - + public Visibility ShowIcon => Result.IcoPath != null || Result.Icon is not null || Glyph == null ? Visibility.Visible : Visibility.Hidden; + public Visibility ShowGlyph => Glyph is not null ? Visibility.Visible : Visibility.Hidden; public string OpenResultModifiers => Settings.OpenResultModifiers; public string ShowTitleToolTip => string.IsNullOrEmpty(Result.TitleToolTip) @@ -87,6 +90,8 @@ public ResultViewModel(Result result, Settings settings) public LazyAsync Image { get; set; } + public GlyphInfo Glyph { get; set; } + private async ValueTask SetImage() { var imagePath = Result.IcoPath; @@ -106,7 +111,7 @@ private async ValueTask SetImage() if (ImageLoader.CacheContainImage(imagePath)) // will get here either when icoPath has value\icon delegate is null\when had exception in delegate return ImageLoader.Load(imagePath); - + return await Task.Run(() => ImageLoader.Load(imagePath)); } From 2af29f83769915cc8273d900540f29c84dc23241 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Sat, 31 Jul 2021 16:07:14 +0800 Subject: [PATCH 2/6] Create GlyphInfo.cs Add GlyphInfo File --- Flow.Launcher.Plugin/GlyphInfo.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Flow.Launcher.Plugin/GlyphInfo.cs diff --git a/Flow.Launcher.Plugin/GlyphInfo.cs b/Flow.Launcher.Plugin/GlyphInfo.cs new file mode 100644 index 00000000000..d24624d8f50 --- /dev/null +++ b/Flow.Launcher.Plugin/GlyphInfo.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; + +namespace Flow.Launcher.Plugin +{ + public record GlyphInfo(string FontFamily, string Glyph); +} From b86a2a8f5f42d7a23a7cb011ca58524f6b6646c9 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Fri, 6 Aug 2021 17:04:19 +0800 Subject: [PATCH 3/6] Handle Font file --- Flow.Launcher/ViewModel/ResultViewModel.cs | 38 ++++++++++++++-------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/Flow.Launcher/ViewModel/ResultViewModel.cs b/Flow.Launcher/ViewModel/ResultViewModel.cs index ce4b23d2184..c8664dc36f4 100644 --- a/Flow.Launcher/ViewModel/ResultViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultViewModel.cs @@ -6,6 +6,7 @@ using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; +using System.IO; namespace Flow.Launcher.ViewModel { @@ -60,14 +61,25 @@ public ResultViewModel(Result result, Settings settings) Result = result; Image = new LazyAsync( - SetImage, - ImageLoader.DefaultImage, - () => - { - OnPropertyChanged(nameof(Image)); - }); - - Glyph = Result.Glyph; + SetImage, + ImageLoader.DefaultImage, + () => + { + OnPropertyChanged(nameof(Image)); + }); + + if (Result.Glyph.FontFamily.Contains('/')) + { + var fontPath = Result.Glyph.FontFamily; + Glyph = Path.IsPathRooted(fontPath) ? Result.Glyph : Result.Glyph with + { + FontFamily = Path.Combine(Result.PluginDirectory, fontPath) + }; + } + else + { + Glyph = Result.Glyph; + } } Settings = settings; @@ -81,12 +93,12 @@ public ResultViewModel(Result result, Settings settings) public string OpenResultModifiers => Settings.OpenResultModifiers; public string ShowTitleToolTip => string.IsNullOrEmpty(Result.TitleToolTip) - ? Result.Title - : Result.TitleToolTip; + ? Result.Title + : Result.TitleToolTip; public string ShowSubTitleToolTip => string.IsNullOrEmpty(Result.SubTitleToolTip) - ? Result.SubTitle - : Result.SubTitleToolTip; + ? Result.SubTitle + : Result.SubTitleToolTip; public LazyAsync Image { get; set; } @@ -140,4 +152,4 @@ public override string ToString() return Result.ToString(); } } -} +} \ No newline at end of file From 9eeb04ec1363ab103318b4df859c9f3a918d892d Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Fri, 6 Aug 2021 17:15:10 +0800 Subject: [PATCH 4/6] fix logic --- Flow.Launcher/ViewModel/ResultViewModel.cs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Flow.Launcher/ViewModel/ResultViewModel.cs b/Flow.Launcher/ViewModel/ResultViewModel.cs index c8664dc36f4..3eba63b2232 100644 --- a/Flow.Launcher/ViewModel/ResultViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultViewModel.cs @@ -68,17 +68,20 @@ public ResultViewModel(Result result, Settings settings) OnPropertyChanged(nameof(Image)); }); - if (Result.Glyph.FontFamily.Contains('/')) + if (Result.Glyph is { FontFamily: not null } glyph) { - var fontPath = Result.Glyph.FontFamily; - Glyph = Path.IsPathRooted(fontPath) ? Result.Glyph : Result.Glyph with + if (glyph.FontFamily.Contains('/')) { - FontFamily = Path.Combine(Result.PluginDirectory, fontPath) - }; - } - else - { - Glyph = Result.Glyph; + var fontPath = Result.Glyph.FontFamily; + Glyph = Path.IsPathRooted(fontPath) ? Result.Glyph : Result.Glyph with + { + FontFamily = Path.Combine(Result.PluginDirectory, fontPath) + }; + } + else + { + Glyph = glyph; + } } } From 0f66baf64dd7a5466aa66cc099387d30678b2137 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Mon, 9 Aug 2021 20:06:18 +1000 Subject: [PATCH 5/6] add comment for system font loading --- Flow.Launcher/ViewModel/ResultViewModel.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher/ViewModel/ResultViewModel.cs b/Flow.Launcher/ViewModel/ResultViewModel.cs index 3eba63b2232..a73e3847d8e 100644 --- a/Flow.Launcher/ViewModel/ResultViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultViewModel.cs @@ -70,6 +70,7 @@ public ResultViewModel(Result result, Settings settings) if (Result.Glyph is { FontFamily: not null } glyph) { + // Checks if it's a system installed font, which does not require path to be provided. if (glyph.FontFamily.Contains('/')) { var fontPath = Result.Glyph.FontFamily; @@ -155,4 +156,4 @@ public override string ToString() return Result.ToString(); } } -} \ No newline at end of file +} From 317ce59ee769df71bbc7a6d6f87f62b04d56afb7 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Tue, 10 Aug 2021 20:24:27 +1000 Subject: [PATCH 6/6] add comment for system font loading --- Flow.Launcher/ViewModel/ResultViewModel.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher/ViewModel/ResultViewModel.cs b/Flow.Launcher/ViewModel/ResultViewModel.cs index 176943e4cd7..328dbcba5f6 100644 --- a/Flow.Launcher/ViewModel/ResultViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultViewModel.cs @@ -20,6 +20,7 @@ public ResultViewModel(Result result, Settings settings) if (Result.Glyph is { FontFamily: not null } glyph) { + // Checks if it's a system installed font, which does not require path to be provided. if (glyph.FontFamily.EndsWith(".ttf") || glyph.FontFamily.EndsWith(".otf")) { var fontPath = Result.Glyph.FontFamily; @@ -127,4 +128,4 @@ public override string ToString() return Result.ToString(); } } -} \ No newline at end of file +}