6
6
using Flow . Launcher . Infrastructure . Logger ;
7
7
using Flow . Launcher . Infrastructure . UserSettings ;
8
8
using Flow . Launcher . Plugin ;
9
+ using System . IO ;
9
10
10
11
namespace Flow . Launcher . ViewModel
11
12
{
@@ -16,24 +17,49 @@ public ResultViewModel(Result result, Settings settings)
16
17
if ( result != null )
17
18
{
18
19
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
+ }
19
39
}
20
40
21
41
Settings = settings ;
22
42
}
23
43
24
- public Settings Settings { get ; private set ; }
44
+ private Settings Settings { get ; }
45
+
46
+ public Visibility ShowOpenResultHotkey =>
47
+ Settings . ShowOpenResultHotkey ? Visibility . Visible : Visibility . Hidden ;
25
48
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 ;
27
52
53
+ public Visibility ShowGlyph => Glyph is not null ? Visibility . Visible : Visibility . Hidden ;
28
54
public string OpenResultModifiers => Settings . OpenResultModifiers ;
29
55
30
56
public string ShowTitleToolTip => string . IsNullOrEmpty ( Result . TitleToolTip )
31
- ? Result . Title
32
- : Result . TitleToolTip ;
57
+ ? Result . Title
58
+ : Result . TitleToolTip ;
33
59
34
60
public string ShowSubTitleToolTip => string . IsNullOrEmpty ( Result . SubTitleToolTip )
35
- ? Result . SubTitle
36
- : Result . SubTitleToolTip ;
61
+ ? Result . SubTitle
62
+ : Result . SubTitleToolTip ;
37
63
38
64
private volatile bool ImageLoaded ;
39
65
@@ -48,10 +74,14 @@ public ImageSource Image
48
74
ImageLoaded = true ;
49
75
_ = LoadImageAsync ( ) ;
50
76
}
77
+
51
78
return image ;
52
79
}
53
80
private set => image = value ;
54
81
}
82
+
83
+ public GlyphInfo Glyph { get ; set ; }
84
+
55
85
private async ValueTask LoadImageAsync ( )
56
86
{
57
87
var imagePath = Result . IcoPath ;
@@ -64,7 +94,9 @@ private async ValueTask LoadImageAsync()
64
94
}
65
95
catch ( Exception e )
66
96
{
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 ) ;
68
100
}
69
101
}
70
102
@@ -74,7 +106,7 @@ private async ValueTask LoadImageAsync()
74
106
image = ImageLoader . Load ( imagePath ) ;
75
107
return ;
76
108
}
77
-
109
+
78
110
// We need to modify the property not field here to trigger the OnPropertyChanged event
79
111
Image = await Task . Run ( ( ) => ImageLoader . Load ( imagePath ) ) . ConfigureAwait ( false ) ;
80
112
}
0 commit comments