-
-
Notifications
You must be signed in to change notification settings - Fork 455
Allow plugins to use web URL's for icon paths #1351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
taooceros
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I don't think that's needed since it is creating a url.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to make the streamsource collectable
| image.StreamSource = buffer; | ||
| image.EndInit(); | ||
| image.StreamSource = null; | ||
| image.Freeze(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
| private static ImageResult GetThumbnailResult(ref string path, bool loadFullImage = false) | |
| { | |
| ImageSource image; | |
| ImageType type = ImageType.Error; | |
| if (Directory.Exists(path)) | |
| { | |
| /* Directories can also have thumbnails instead of shell icons. | |
| * Generating thumbnails for a bunch of folder results while scrolling | |
| * could have a big impact on performance and Flow.Launcher responsibility. | |
| * - Solution: just load the icon | |
| */ | |
| type = ImageType.Folder; | |
| image = GetThumbnail(path, ThumbnailOptions.IconOnly); | |
| } | |
| else if (File.Exists(path)) | |
| { | |
| var extension = Path.GetExtension(path).ToLower(); | |
| if (ImageExtensions.Contains(extension)) | |
| { |
(GetThumbnailResult is called by LoadInternalAsync)
We just need to determine that it is not a URI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
| get { return _icoPath; } | ||
| set | ||
| { | ||
| if (!string.IsNullOrEmpty(PluginDirectory) && !Path.IsPathRooted(value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
…low.Launcher into handle-icon-urls
|
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.