mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Refactor code
This commit is contained in:
parent
e9bf62ed08
commit
0fd127ab98
1 changed files with 22 additions and 21 deletions
|
|
@ -117,27 +117,7 @@ namespace Flow.Launcher.Infrastructure.Image
|
|||
if (Uri.TryCreate(path, UriKind.RelativeOrAbsolute, out var uriResult)
|
||||
&& (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps))
|
||||
{
|
||||
// Download image from url
|
||||
await using var resp = await GetStreamAsync(uriResult);
|
||||
if (resp == null)
|
||||
{
|
||||
return new ImageResult(ImageCache[Constant.MissingImgIcon], ImageType.Error);
|
||||
}
|
||||
await using var buffer = new MemoryStream();
|
||||
await resp.CopyToAsync(buffer);
|
||||
buffer.Seek(0, SeekOrigin.Begin);
|
||||
var image = new BitmapImage();
|
||||
image.BeginInit();
|
||||
image.CacheOption = BitmapCacheOption.OnLoad;
|
||||
if (!loadFullImage)
|
||||
{
|
||||
image.DecodePixelHeight = SmallIconSize;
|
||||
image.DecodePixelWidth = SmallIconSize;
|
||||
}
|
||||
image.StreamSource = buffer;
|
||||
image.EndInit();
|
||||
image.StreamSource = null;
|
||||
image.Freeze();
|
||||
var image = await LoadRemoteImageAsync(loadFullImage, uriResult);
|
||||
ImageCache[path] = image;
|
||||
return new ImageResult(image, ImageType.ImageFile);
|
||||
}
|
||||
|
|
@ -175,6 +155,27 @@ namespace Flow.Launcher.Infrastructure.Image
|
|||
|
||||
return imageResult;
|
||||
}
|
||||
private static async Task<BitmapImage> LoadRemoteImageAsync(bool loadFullImage, Uri uriResult)
|
||||
{
|
||||
// Download image from url
|
||||
await using var resp = await GetStreamAsync(uriResult);
|
||||
await using var buffer = new MemoryStream();
|
||||
await resp.CopyToAsync(buffer);
|
||||
buffer.Seek(0, SeekOrigin.Begin);
|
||||
var image = new BitmapImage();
|
||||
image.BeginInit();
|
||||
image.CacheOption = BitmapCacheOption.OnLoad;
|
||||
if (!loadFullImage)
|
||||
{
|
||||
image.DecodePixelHeight = SmallIconSize;
|
||||
image.DecodePixelWidth = SmallIconSize;
|
||||
}
|
||||
image.StreamSource = buffer;
|
||||
image.EndInit();
|
||||
image.StreamSource = null;
|
||||
image.Freeze();
|
||||
return image;
|
||||
}
|
||||
|
||||
private static ImageResult GetThumbnailResult(ref string path, bool loadFullImage = false)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue