mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Support badge icon loading
This commit is contained in:
parent
ec99a365b9
commit
2eda64aa7a
2 changed files with 44 additions and 4 deletions
|
|
@ -145,7 +145,7 @@
|
|||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Bottom"
|
||||
RenderOptions.BitmapScalingMode="Fant"
|
||||
Source="{Binding Image, TargetNullValue={x:Null}}"
|
||||
Source="{Binding BadgeImage, TargetNullValue={x:Null}}"
|
||||
Visibility="{Binding ShowBadge}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
|
|
|||
|
|
@ -125,13 +125,21 @@ namespace Flow.Launcher.ViewModel
|
|||
|
||||
public Visibility ShowBadge
|
||||
{
|
||||
get => Settings.ShowBadges ? Visibility.Visible : Visibility.Collapsed;
|
||||
get
|
||||
{
|
||||
if (Settings.ShowBadges && BadgeIconAvailable)
|
||||
return Visibility.Visible;
|
||||
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
private bool GlyphAvailable => Glyph is not null;
|
||||
|
||||
private bool ImgIconAvailable => !string.IsNullOrEmpty(Result.IcoPath) || Result.Icon is not null;
|
||||
|
||||
private bool BadgeIconAvailable => !string.IsNullOrEmpty(Result.BadgeIcoPath) || Result.BadgeIcon is not null;
|
||||
|
||||
private bool PreviewImageAvailable => !string.IsNullOrEmpty(Result.Preview.PreviewImagePath) || Result.Preview.PreviewDelegate != null;
|
||||
|
||||
public string OpenResultModifiers => Settings.OpenResultModifiers;
|
||||
|
|
@ -145,9 +153,11 @@ namespace Flow.Launcher.ViewModel
|
|||
: Result.SubTitleToolTip;
|
||||
|
||||
private volatile bool _imageLoaded;
|
||||
private volatile bool _badgeImageLoaded;
|
||||
private volatile bool _previewImageLoaded;
|
||||
|
||||
private ImageSource _image = ImageLoader.LoadingImage;
|
||||
private ImageSource _badgeImage = ImageLoader.LoadingImage;
|
||||
private ImageSource _previewImage = ImageLoader.LoadingImage;
|
||||
|
||||
public ImageSource Image
|
||||
|
|
@ -165,6 +175,21 @@ namespace Flow.Launcher.ViewModel
|
|||
private set => _image = value;
|
||||
}
|
||||
|
||||
public ImageSource BadgeImage
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_badgeImageLoaded)
|
||||
{
|
||||
_badgeImageLoaded = true;
|
||||
_ = LoadBadgeImageAsync();
|
||||
}
|
||||
|
||||
return _badgeImage;
|
||||
}
|
||||
private set => _badgeImage = value;
|
||||
}
|
||||
|
||||
public ImageSource PreviewImage
|
||||
{
|
||||
get
|
||||
|
|
@ -210,7 +235,7 @@ namespace Flow.Launcher.ViewModel
|
|||
{
|
||||
var imagePath = Result.IcoPath;
|
||||
var iconDelegate = Result.Icon;
|
||||
if (ImageLoader.TryGetValue(imagePath, false, out ImageSource img))
|
||||
if (ImageLoader.TryGetValue(imagePath, false, out var img))
|
||||
{
|
||||
_image = img;
|
||||
}
|
||||
|
|
@ -221,11 +246,26 @@ namespace Flow.Launcher.ViewModel
|
|||
}
|
||||
}
|
||||
|
||||
private async Task LoadBadgeImageAsync()
|
||||
{
|
||||
var badgeImagePath = Result.BadgeIcoPath;
|
||||
var badgeIconDelegate = Result.BadgeIcon;
|
||||
if (ImageLoader.TryGetValue(badgeImagePath, false, out var img))
|
||||
{
|
||||
_badgeImage = img;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We need to modify the property not field here to trigger the OnPropertyChanged event
|
||||
BadgeImage = await LoadImageInternalAsync(badgeImagePath, badgeIconDelegate, false).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadPreviewImageAsync()
|
||||
{
|
||||
var imagePath = Result.Preview.PreviewImagePath ?? Result.IcoPath;
|
||||
var iconDelegate = Result.Preview.PreviewDelegate ?? Result.Icon;
|
||||
if (ImageLoader.TryGetValue(imagePath, true, out ImageSource img))
|
||||
if (ImageLoader.TryGetValue(imagePath, true, out var img))
|
||||
{
|
||||
_previewImage = img;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue