remove PluginDirectory, ImageLoader path checking, update IcoPath logic

This commit is contained in:
Jeremy Wu 2022-11-24 17:31:00 +11:00
parent 3665bd9efc
commit 83ec8099a7
2 changed files with 14 additions and 23 deletions

View file

@ -113,10 +113,12 @@ namespace Flow.Launcher.Infrastructure.Image
{ {
return new ImageResult(DefaultImage, ImageType.Error); return new ImageResult(DefaultImage, ImageType.Error);
} }
if (ImageCache.ContainsKey(path, loadFullImage)) if (ImageCache.ContainsKey(path, loadFullImage))
{ {
return new ImageResult(ImageCache[path, loadFullImage], ImageType.Cache); return new ImageResult(ImageCache[path, loadFullImage], ImageType.Cache);
} }
if (Uri.TryCreate(path, UriKind.RelativeOrAbsolute, out var uriResult) if (Uri.TryCreate(path, UriKind.RelativeOrAbsolute, out var uriResult)
&& (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps)) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps))
{ {
@ -131,11 +133,6 @@ namespace Flow.Launcher.Infrastructure.Image
return new ImageResult(imageSource, ImageType.Data); return new ImageResult(imageSource, ImageType.Data);
} }
if (!Path.IsPathRooted(path))
{
path = Path.Combine(Constant.ProgramDirectory, "Images", Path.GetFileName(path));
}
imageResult = await Task.Run(() => GetThumbnailResult(ref path, loadFullImage)); imageResult = await Task.Run(() => GetThumbnailResult(ref path, loadFullImage));
} }
catch (System.Exception e) catch (System.Exception e)

View file

@ -60,15 +60,14 @@ namespace Flow.Launcher.Plugin
get { return _icoPath; } get { return _icoPath; }
set set
{ {
if (!string.IsNullOrEmpty(PluginDirectory) && !Path.IsPathRooted(value)) // As a standard this property will handle prepping and converting to absolute local path for icon image processing
if (!string.IsNullOrEmpty(value)
&& !string.IsNullOrEmpty(PluginDirectory)
&& !Path.IsPathRooted(value)
&& !value.StartsWith("http://", StringComparison.OrdinalIgnoreCase)
&& !value.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
{ {
string absPath = Path.Combine(value, IcoPath); _icoPath = Path.Combine(PluginDirectory, value);
// Only convert relative paths if its a valid path
if (File.Exists(absPath))
{
_icoPath = Path.Combine(value, IcoPath);
}
} }
else else
{ {
@ -146,16 +145,11 @@ namespace Flow.Launcher.Plugin
set set
{ {
_pluginDirectory = value; _pluginDirectory = value;
if (!string.IsNullOrEmpty(IcoPath) && !Path.IsPathRooted(IcoPath))
{ // When the Result object is returned from the query call, PluginDirectory is not provided until
string absPath = Path.Combine(value, IcoPath); // UpdatePluginMetadata call is made at PluginManager.cs L196. Once the PluginDirectory becomes available
// Only convert relative paths if its a valid path // we need to update (only if not Uri path) the IcoPath with the full absolute path so the image can be loaded.
if (File.Exists(absPath)) IcoPath = _icoPath;
{
IcoPath = absPath;
}
}
} }
} }