mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
bind to task instead of the complex loading scheme
This commit is contained in:
parent
dc4e1c4b75
commit
0f3cb5da8d
2 changed files with 20 additions and 50 deletions
|
|
@ -83,7 +83,7 @@
|
|||
Margin="0,0,0,0"
|
||||
HorizontalAlignment="Center"
|
||||
IsHitTestVisible="False"
|
||||
Source="{Binding Image, TargetNullValue={x:Null}}"
|
||||
Source="{Binding Image^, FallbackValue={Binding DefaultImage}, TargetNullValue={x:Null}}"
|
||||
Stretch="Uniform"
|
||||
IsVisible="{Binding ShowIcon}">
|
||||
</Image>
|
||||
|
|
|
|||
|
|
@ -58,12 +58,16 @@ namespace Flow.Launcher.ViewModel
|
|||
Glyph = glyph;
|
||||
}
|
||||
}
|
||||
|
||||
LoadImage();
|
||||
}
|
||||
|
||||
private Settings Settings { get; }
|
||||
|
||||
public bool ShowOpenResultHotkey => Settings.ShowOpenResultHotkey;
|
||||
|
||||
public Bitmap DefaultImage => ImageLoader.LoadingImage;
|
||||
|
||||
public bool ShowDefaultPreview => Result.PreviewPanel != null;
|
||||
|
||||
public bool ShowCustomizedPreview => Result.PreviewPanel != null;
|
||||
|
|
@ -144,32 +148,9 @@ namespace Flow.Launcher.ViewModel
|
|||
? Result.SubTitle
|
||||
: Result.SubTitleToolTip;
|
||||
|
||||
private volatile bool ImageLoaded;
|
||||
private volatile bool PreviewImageLoaded;
|
||||
public Task<Bitmap> Image { get; set; }
|
||||
|
||||
private Bitmap image = default; //ImageLoader.LoadingImage;
|
||||
private Bitmap previewImage = default; //ImageLoader.LoadingImage;
|
||||
|
||||
public Bitmap Image
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!ImageLoaded)
|
||||
{
|
||||
ImageLoaded = true;
|
||||
_ = LoadImageAsync();
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
private set => image = value;
|
||||
}
|
||||
|
||||
public Bitmap PreviewImage
|
||||
{
|
||||
get => previewImage;
|
||||
private set => previewImage = value;
|
||||
}
|
||||
public Task<Bitmap> PreviewImage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines if to use the full width of the preview panel
|
||||
|
|
@ -199,48 +180,37 @@ namespace Flow.Launcher.ViewModel
|
|||
return default; // await ImageLoader.LoadAsync(imagePath, loadFullImage).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task LoadImageAsync()
|
||||
private void LoadImage()
|
||||
{
|
||||
var imagePath = Result.IcoPath;
|
||||
var iconDelegate = Result.Icon;
|
||||
if (ImageLoader.TryGetValue(imagePath, false, out var img))
|
||||
{
|
||||
image = img;
|
||||
Image = Task.FromResult(img);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We need to modify the property not field here to trigger the OnPropertyChanged event
|
||||
Image = await LoadImageInternalAsync(imagePath, iconDelegate, 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 var img))
|
||||
{
|
||||
previewImage = img;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We need to modify the property not field here to trigger the OnPropertyChanged event
|
||||
PreviewImage = await LoadImageInternalAsync(imagePath, iconDelegate, true).ConfigureAwait(false);
|
||||
Image = LoadImageInternalAsync(imagePath, iconDelegate, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadPreviewImage()
|
||||
{
|
||||
if (ShowDefaultPreview)
|
||||
var imagePath = Result.Preview.PreviewImagePath ?? Result.IcoPath;
|
||||
var iconDelegate = Result.Preview.PreviewDelegate ?? Result.Icon;
|
||||
if (ImageLoader.TryGetValue(imagePath, true, out var img))
|
||||
{
|
||||
if (!PreviewImageLoaded && ShowPreviewImage)
|
||||
{
|
||||
PreviewImageLoaded = true;
|
||||
_ = LoadPreviewImageAsync();
|
||||
}
|
||||
PreviewImage = Task.FromResult(img);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We need to modify the property not field here to trigger the OnPropertyChanged event
|
||||
PreviewImage = LoadImageInternalAsync(imagePath, iconDelegate, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Result Result { get; }
|
||||
|
||||
public int ResultProgress
|
||||
|
|
|
|||
Loading…
Reference in a new issue