Allow plugins to use web URL's for icon paths#1351
Conversation
taooceros
left a comment
There was a problem hiding this comment.
Nice change, but requires a bit (maybe quite a bit🤣) modification to make it perfect.
5baace7 to
eb5e33a
Compare
|
I will adjust the code a bit before marking ready. |
|
@Garulf or @taooceros please resolve conflict |
| { | ||
| Log.Debug($"|Http.Get|Url <{url}>"); | ||
| return GetAsync(new Uri(url.Replace("#", "%23")), token); | ||
| return GetAsync(new Uri(url), token); |
There was a problem hiding this comment.
yeah I don't think that's needed since it is creating a url.
There was a problem hiding this comment.
what do you mean? the old code is also creating a url too no?
|
Please update PR description on what tests have been done. |
| } | ||
|
|
||
| /// <summary> | ||
| /// Asynchrously get the result as stream from url. |
There was a problem hiding this comment.
I revised some of the Http design to align with the HttpClient design. Their design is much better
| { | ||
| Load(x.Key); | ||
| }); | ||
| await LoadAsync(imageUsage.Key); |
There was a problem hiding this comment.
Due to the ImageLoader change to async (not always async so ValueTask). I wonder whether we should use Task to wrap the nonasync part so we can always just await it.
| image.CacheOption = BitmapCacheOption.OnLoad; | ||
| image.StreamSource = buffer; | ||
| image.EndInit(); | ||
| image.StreamSource = null; |
There was a problem hiding this comment.
to make the streamsource collectable
| image.StreamSource = buffer; | ||
| image.EndInit(); | ||
| image.StreamSource = null; | ||
| image.Freeze(); |
There was a problem hiding this comment.
Freeze is needed because the BitmapImage is not created in the ui thread.
| { | ||
| Log.Debug($"|Http.Get|Url <{url}>"); | ||
| return GetAsync(new Uri(url.Replace("#", "%23")), token); | ||
| return GetAsync(new Uri(url), token); |
There was a problem hiding this comment.
yeah I don't think that's needed since it is creating a url.
Flow.Launcher.Plugin/Result.cs
Outdated
| _icoPath = Path.Combine(value, IcoPath); | ||
| string absPath = Path.Combine(value, IcoPath); | ||
| // Only convert relative paths if its a valid path | ||
| if (File.Exists(absPath)) |
There was a problem hiding this comment.
Is there another way to check this path without using File.Exists? Doesn't seem necessary to use it here.
There was a problem hiding this comment.
This way allows us to improve how Flow auto appends the plugins path to icon paths that are relative and still accept URI such as http, https, ftp, etc. instead of checking every URI under the sun to see if it's valid let's just detect if that file even exists and leave it alone if it doesn't.
Edit: original code just tacked on the plugins path to any string it didn't detect a root file path on.
There was a problem hiding this comment.
I mean this is an unnecessary call because we already checking that the path exists or not at
Flow.Launcher/Flow.Launcher.Infrastructure/Image/ImageLoader.cs
Lines 183 to 202 in e5948a7
(GetThumbnailResult is called by LoadInternalAsync)
We just need to determine that it is not a URI.
There was a problem hiding this comment.
We're not really concerned with if the path exists or not. What we're really concerned with is the path really a relative path or not.
The built-in method for detecting relative paths isnt very smart.
There was a problem hiding this comment.
The built-in method for detecting relative paths isnt very smart
Agree, using Uri class is not working for our cases. Just doing a simple check for http and https seems more effective to determine that it is Url, then consider everything else as local absolute/relative path.
@Garulf @taooceros I reworked IcoPath, PluginDirectory and ImageLoader 83ec809, let me know if ok.
Flow.Launcher.Plugin/Result.cs
Outdated
| @@ -62,7 +62,13 @@ public string IcoPath | |||
| { | |||
| if (!string.IsNullOrEmpty(PluginDirectory) && !Path.IsPathRooted(value)) | |||
There was a problem hiding this comment.
@taooceros & @Garulf not related to this PR but I am trying to figure out why we need to check PluginDirectory is not an empty string? I cant seem to hit this condition.
|
I remove the await Task.Run outside. However, it sometimes makes the debugger stop when fetching image fails (which throws an error that is caught outside). I wonder whether we should make the method more robust by using return code🤔 |
This PR allows Flow Launcher to accept remote URL's provided in the
IcoPathfield.This greatly speeds up results.