66using Flow . Launcher . Infrastructure . Logger ;
77using Flow . Launcher . Infrastructure . UserSettings ;
88using Flow . Launcher . Plugin ;
9+ using System . IO ;
910
1011namespace Flow . Launcher . ViewModel
1112{
@@ -16,24 +17,49 @@ public ResultViewModel(Result result, Settings settings)
1617 if ( result != null )
1718 {
1819 Result = result ;
20+
21+ if ( Result . Glyph is { FontFamily : not null } glyph )
22+ {
23+ // Checks if it's a system installed font, which does not require path to be provided.
24+ if ( glyph . FontFamily . EndsWith ( ".ttf" ) || glyph . FontFamily . EndsWith ( ".otf" ) )
25+ {
26+ var fontPath = Result . Glyph . FontFamily ;
27+ Glyph = Path . IsPathRooted ( fontPath )
28+ ? Result . Glyph
29+ : Result . Glyph with
30+ {
31+ FontFamily = Path . Combine ( Result . PluginDirectory , fontPath )
32+ } ;
33+ }
34+ else
35+ {
36+ Glyph = glyph ;
37+ }
38+ }
1939 }
2040
2141 Settings = settings ;
2242 }
2343
24- public Settings Settings { get ; private set ; }
44+ private Settings Settings { get ; }
45+
46+ public Visibility ShowOpenResultHotkey =>
47+ Settings . ShowOpenResultHotkey ? Visibility . Visible : Visibility . Hidden ;
2548
26- public Visibility ShowOpenResultHotkey => Settings . ShowOpenResultHotkey ? Visibility . Visible : Visibility . Hidden ;
49+ public Visibility ShowIcon => Result . IcoPath != null || Result . Icon is not null || Glyph == null
50+ ? Visibility . Visible
51+ : Visibility . Hidden ;
2752
53+ public Visibility ShowGlyph => Glyph is not null ? Visibility . Visible : Visibility . Hidden ;
2854 public string OpenResultModifiers => Settings . OpenResultModifiers ;
2955
3056 public string ShowTitleToolTip => string . IsNullOrEmpty ( Result . TitleToolTip )
31- ? Result . Title
32- : Result . TitleToolTip ;
57+ ? Result . Title
58+ : Result . TitleToolTip ;
3359
3460 public string ShowSubTitleToolTip => string . IsNullOrEmpty ( Result . SubTitleToolTip )
35- ? Result . SubTitle
36- : Result . SubTitleToolTip ;
61+ ? Result . SubTitle
62+ : Result . SubTitleToolTip ;
3763
3864 private volatile bool ImageLoaded ;
3965
@@ -48,10 +74,14 @@ public ImageSource Image
4874 ImageLoaded = true ;
4975 _ = LoadImageAsync ( ) ;
5076 }
77+
5178 return image ;
5279 }
5380 private set => image = value ;
5481 }
82+
83+ public GlyphInfo Glyph { get ; set ; }
84+
5585 private async ValueTask LoadImageAsync ( )
5686 {
5787 var imagePath = Result . IcoPath ;
@@ -64,7 +94,9 @@ private async ValueTask LoadImageAsync()
6494 }
6595 catch ( Exception e )
6696 {
67- Log . Exception ( $ "|ResultViewModel.Image|IcoPath is empty and exception when calling Icon() for result <{ Result . Title } > of plugin <{ Result . PluginDirectory } >", e ) ;
97+ Log . Exception (
98+ $ "|ResultViewModel.Image|IcoPath is empty and exception when calling Icon() for result <{ Result . Title } > of plugin <{ Result . PluginDirectory } >",
99+ e ) ;
68100 }
69101 }
70102
@@ -74,7 +106,7 @@ private async ValueTask LoadImageAsync()
74106 image = ImageLoader . Load ( imagePath ) ;
75107 return ;
76108 }
77-
109+
78110 // We need to modify the property not field here to trigger the OnPropertyChanged event
79111 Image = await Task . Run ( ( ) => ImageLoader . Load ( imagePath ) ) . ConfigureAwait ( false ) ;
80112 }
0 commit comments