Skip to content

Conversation

@Garulf
Copy link
Member

@Garulf Garulf commented Aug 30, 2022

This PR allows Flow Launcher to accept remote URL's provided in the IcoPath field.

This greatly speeds up results.

Copy link
Member

@taooceros taooceros left a 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.

@jjw24 jjw24 marked this pull request as draft September 27, 2022 11:11
@taooceros
Copy link
Member

@jjw24 jjw24 added enhancement New feature or request review in progress Indicates that a review is in progress for this PR labels Nov 14, 2022
@jjw24 jjw24 added this to the 1.10.0 milestone Nov 14, 2022
@jjw24
Copy link
Member

jjw24 commented Nov 14, 2022

@Garulf or @taooceros please resolve conflict

@jjw24 jjw24 requested a review from taooceros November 14, 2022 09:59
{
Log.Debug($"|Http.Get|Url <{url}>");
return GetAsync(new Uri(url.Replace("#", "%23")), token);
return GetAsync(new Uri(url), token);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change intended?

Copy link
Member

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.

Copy link
Member

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?

@jjw24
Copy link
Member

jjw24 commented Nov 22, 2022

Please update PR description on what tests have been done.

}

/// <summary>
/// Asynchrously get the result as stream from url.
Copy link
Member

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);
Copy link
Member

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;
Copy link
Member

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();
Copy link
Member

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);
Copy link
Member

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.

_icoPath = Path.Combine(value, IcoPath);
string absPath = Path.Combine(value, IcoPath);
// Only convert relative paths if its a valid path
if (File.Exists(absPath))
Copy link
Member

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.

Copy link
Member Author

@Garulf Garulf Nov 22, 2022

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.

Copy link
Member

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

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.

Copy link
Member Author

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.

Copy link
Member

@jjw24 jjw24 Nov 24, 2022

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.

get { return _icoPath; }
set
{
if (!string.IsNullOrEmpty(PluginDirectory) && !Path.IsPathRooted(value))
Copy link
Member

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.

@taooceros
Copy link
Member

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🤔

@jjw24 jjw24 enabled auto-merge November 25, 2022 02:50
@jjw24 jjw24 merged commit 5bc6acf into dev Nov 25, 2022
@jjw24 jjw24 deleted the handle-icon-urls branch November 25, 2022 02:50
@jjw24 jjw24 removed the review in progress Indicates that a review is in progress for this PR label Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants