mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add LoadImageAsync api function
This commit is contained in:
parent
a3c18a6e3b
commit
5165ce8f2a
3 changed files with 28 additions and 6 deletions
|
|
@ -277,7 +277,7 @@ namespace Flow.Launcher.Infrastructure.Image
|
|||
return ImageCache.TryGetValue(path, loadFullImage, out image);
|
||||
}
|
||||
|
||||
public static async ValueTask<ImageSource> LoadAsync(string path, bool loadFullImage = false)
|
||||
public static async ValueTask<ImageSource> LoadAsync(string path, bool loadFullImage = false, bool cacheImage = true)
|
||||
{
|
||||
var imageResult = await LoadInternalAsync(path, loadFullImage);
|
||||
|
||||
|
|
@ -293,16 +293,18 @@ namespace Flow.Launcher.Infrastructure.Image
|
|||
// image already exists
|
||||
img = ImageCache[key, loadFullImage] ?? img;
|
||||
}
|
||||
else
|
||||
else if (cacheImage)
|
||||
{
|
||||
// new guid
|
||||
|
||||
// save guid key
|
||||
GuidToKey[hash] = path;
|
||||
}
|
||||
}
|
||||
|
||||
// update cache
|
||||
ImageCache[path, loadFullImage] = img;
|
||||
if (cacheImage)
|
||||
{
|
||||
// update cache
|
||||
ImageCache[path, loadFullImage] = img;
|
||||
}
|
||||
}
|
||||
|
||||
return img;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using System.Runtime.CompilerServices;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Flow.Launcher.Plugin
|
||||
{
|
||||
|
|
@ -344,5 +345,20 @@ namespace Flow.Launcher.Plugin
|
|||
/// Stop the loading bar in main window
|
||||
/// </summary>
|
||||
public void StopLoadingBar();
|
||||
|
||||
/// <summary>
|
||||
/// Load image from path. Support local, remote and data:image url.
|
||||
/// If image path is missing, it will retun a missing icon.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the image.</param>
|
||||
/// <param name="loadFullImage">
|
||||
/// Load full image or not.
|
||||
/// </param>
|
||||
/// <param name="cacheImage">
|
||||
/// Cache the image or not. Cached image will be stored in FL cache.
|
||||
/// If the image is just used one time, it's better to set this to false.
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
ValueTask<ImageSource> LoadImageAsync(string path, bool loadFullImage = false, bool cacheImage = true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ using System.Runtime.CompilerServices;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Squirrel;
|
||||
using Flow.Launcher.Core;
|
||||
|
|
@ -342,6 +343,9 @@ namespace Flow.Launcher
|
|||
|
||||
public Task ShowProgressBoxAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action cancelProgress = null) => ProgressBoxEx.ShowAsync(caption, reportProgressAsync, cancelProgress);
|
||||
|
||||
public ValueTask<ImageSource> LoadImageAsync(string path, bool loadFullImage = false, bool cacheImage = true) =>
|
||||
ImageLoader.LoadAsync(path, loadFullImage, cacheImage);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
|
|
|||
Loading…
Reference in a new issue