Skip to content

Commit 2eda64a

Browse files
committed
Support badge icon loading
1 parent ec99a36 commit 2eda64a

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

Flow.Launcher/ResultListBox.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
HorizontalAlignment="Right"
146146
VerticalAlignment="Bottom"
147147
RenderOptions.BitmapScalingMode="Fant"
148-
Source="{Binding Image, TargetNullValue={x:Null}}"
148+
Source="{Binding BadgeImage, TargetNullValue={x:Null}}"
149149
Visibility="{Binding ShowBadge}" />
150150
</Grid>
151151
</Border>

Flow.Launcher/ViewModel/ResultViewModel.cs

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,21 @@ public Visibility ShowGlyph
125125

126126
public Visibility ShowBadge
127127
{
128-
get => Settings.ShowBadges ? Visibility.Visible : Visibility.Collapsed;
128+
get
129+
{
130+
if (Settings.ShowBadges && BadgeIconAvailable)
131+
return Visibility.Visible;
132+
133+
return Visibility.Collapsed;
134+
}
129135
}
130136

131137
private bool GlyphAvailable => Glyph is not null;
132138

133139
private bool ImgIconAvailable => !string.IsNullOrEmpty(Result.IcoPath) || Result.Icon is not null;
134140

141+
private bool BadgeIconAvailable => !string.IsNullOrEmpty(Result.BadgeIcoPath) || Result.BadgeIcon is not null;
142+
135143
private bool PreviewImageAvailable => !string.IsNullOrEmpty(Result.Preview.PreviewImagePath) || Result.Preview.PreviewDelegate != null;
136144

137145
public string OpenResultModifiers => Settings.OpenResultModifiers;
@@ -145,9 +153,11 @@ public Visibility ShowBadge
145153
: Result.SubTitleToolTip;
146154

147155
private volatile bool _imageLoaded;
156+
private volatile bool _badgeImageLoaded;
148157
private volatile bool _previewImageLoaded;
149158

150159
private ImageSource _image = ImageLoader.LoadingImage;
160+
private ImageSource _badgeImage = ImageLoader.LoadingImage;
151161
private ImageSource _previewImage = ImageLoader.LoadingImage;
152162

153163
public ImageSource Image
@@ -165,6 +175,21 @@ public ImageSource Image
165175
private set => _image = value;
166176
}
167177

178+
public ImageSource BadgeImage
179+
{
180+
get
181+
{
182+
if (!_badgeImageLoaded)
183+
{
184+
_badgeImageLoaded = true;
185+
_ = LoadBadgeImageAsync();
186+
}
187+
188+
return _badgeImage;
189+
}
190+
private set => _badgeImage = value;
191+
}
192+
168193
public ImageSource PreviewImage
169194
{
170195
get
@@ -210,7 +235,7 @@ private async Task LoadImageAsync()
210235
{
211236
var imagePath = Result.IcoPath;
212237
var iconDelegate = Result.Icon;
213-
if (ImageLoader.TryGetValue(imagePath, false, out ImageSource img))
238+
if (ImageLoader.TryGetValue(imagePath, false, out var img))
214239
{
215240
_image = img;
216241
}
@@ -221,11 +246,26 @@ private async Task LoadImageAsync()
221246
}
222247
}
223248

249+
private async Task LoadBadgeImageAsync()
250+
{
251+
var badgeImagePath = Result.BadgeIcoPath;
252+
var badgeIconDelegate = Result.BadgeIcon;
253+
if (ImageLoader.TryGetValue(badgeImagePath, false, out var img))
254+
{
255+
_badgeImage = img;
256+
}
257+
else
258+
{
259+
// We need to modify the property not field here to trigger the OnPropertyChanged event
260+
BadgeImage = await LoadImageInternalAsync(badgeImagePath, badgeIconDelegate, false).ConfigureAwait(false);
261+
}
262+
}
263+
224264
private async Task LoadPreviewImageAsync()
225265
{
226266
var imagePath = Result.Preview.PreviewImagePath ?? Result.IcoPath;
227267
var iconDelegate = Result.Preview.PreviewDelegate ?? Result.Icon;
228-
if (ImageLoader.TryGetValue(imagePath, true, out ImageSource img))
268+
if (ImageLoader.TryGetValue(imagePath, true, out var img))
229269
{
230270
_previewImage = img;
231271
}

0 commit comments

Comments
 (0)