Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
ffbd8fd
Add logic for IcoPath's that are web URL's
Garulf Aug 30, 2022
03e319e
Remove whitespace
Garulf Aug 30, 2022
fda155a
DOn't prepend pluginpath if IcoPath is a web URL
Garulf Aug 30, 2022
b5c2125
Merge branch 'dev' into handle-icon-urls
Garulf Aug 30, 2022
d62d710
Use URI class to detect web URL
Garulf Sep 21, 2022
301882d
Switch from WebClient to HTTP
Garulf Sep 21, 2022
5c33b0d
Only convert relative paths if its a valid path
Garulf Oct 7, 2022
b7900b2
// Only convert relative paths if its a valid path
Garulf Oct 7, 2022
57d63cf
Add logic for IcoPath's that are web URL's
Garulf Aug 30, 2022
ed107cc
Remove whitespace
Garulf Aug 30, 2022
7f1b9d0
DOn't prepend pluginpath if IcoPath is a web URL
Garulf Aug 30, 2022
416c44f
Use URI class to detect web URL
Garulf Sep 21, 2022
ec1a061
Switch from WebClient to HTTP
Garulf Sep 21, 2022
ebd6f17
Only convert relative paths if its a valid path
Garulf Oct 7, 2022
eb3f723
// Only convert relative paths if its a valid path
Garulf Oct 7, 2022
ef575bb
Adjust Http Code
taooceros Oct 13, 2022
3708489
Adjust Google Code a bit due to http change
taooceros Oct 13, 2022
191c6af
Adjust Bing Code a bit due to http change
taooceros Oct 13, 2022
957c4e2
Adjust Http Design to avoid memory leak
taooceros Oct 13, 2022
eb5e33a
Make ImageLoader Async
taooceros Oct 13, 2022
c39a727
Revert back some unnecessary change
taooceros Oct 13, 2022
99fd8d1
Dispose Stream (though it maybe already disposed by disposed the resp…
taooceros Oct 27, 2022
2507d1a
remove testing code
taooceros Oct 30, 2022
ba0aee1
resize bitmapimage when not loading full image
taooceros Oct 30, 2022
cae0b7b
Merge branch 'handle-icon-urls' of https://github.com/Flow-Launcher/F…
Garulf Oct 30, 2022
e9bf62e
Revert "Merge branch 'handle-icon-urls' of https://github.com/Flow-La…
taooceros Oct 30, 2022
0fd127a
Refactor code
taooceros Oct 30, 2022
cf9dd4a
Respect loadFullImage Option in ImageCache.cs
taooceros Oct 30, 2022
ffa40b0
Respect loadFullImage Option in ImageCache.cs
taooceros Oct 30, 2022
ff2ebc8
Merge branch 'dev' into handle-icon-urls
taooceros Oct 30, 2022
e86a2f1
slightly refactor
taooceros Oct 30, 2022
28256a7
Merge remote-tracking branch 'origin/handle-icon-urls' into handle-ic…
taooceros Oct 30, 2022
101593a
edit signature for CacheContainImage
taooceros Oct 31, 2022
169857b
Merge remote-tracking branch 'origin/dev' into handle-icon-urls
taooceros Nov 11, 2022
26668b4
Merge branch 'dev' into handle-icon-urls
Garulf Nov 17, 2022
ce52919
Merge branch 'dev' into handle-icon-urls
Garulf Nov 17, 2022
414e55c
Merge branch 'dev' into handle-icon-urls
onesounds Nov 18, 2022
622b130
Merge branch 'handle-icon-urls' of https://github.com/Flow-Launcher/F…
Garulf Nov 18, 2022
e5948a7
Merge branch 'dev' into handle-icon-urls
jjw24 Nov 22, 2022
67443fd
Merge branch 'handle-icon-urls' of https://github.com/Flow-Launcher/F…
Garulf Nov 23, 2022
3665bd9
Wrap non async part in task
Garulf Nov 23, 2022
83ec809
remove PluginDirectory, ImageLoader path checking, update IcoPath logic
jjw24 Nov 24, 2022
303d3b9
remove task.run outside
taooceros Nov 24, 2022
fb3a23f
remove unnecessary local variable
taooceros Nov 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public static async Task UpdateManifestAsync(CancellationToken token = default)
var request = new HttpRequestMessage(HttpMethod.Get, manifestFileUrl);
request.Headers.Add("If-None-Match", latestEtag);

var response = await Http.SendAsync(request, token).ConfigureAwait(false);
using var response = await Http.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, token).ConfigureAwait(false);

if (response.StatusCode == HttpStatusCode.OK)
{
Log.Info($"|PluginsManifest.{nameof(UpdateManifestAsync)}|Fetched plugins from manifest repo");

var json = await response.Content.ReadAsStreamAsync(token).ConfigureAwait(false);
await using var json = await response.Content.ReadAsStreamAsync(token).ConfigureAwait(false);

UserPlugins = await JsonSerializer.DeserializeAsync<List<UserPlugin>>(json, cancellationToken: token).ConfigureAwait(false);

Expand All @@ -56,4 +56,4 @@ public static async Task UpdateManifestAsync(CancellationToken token = default)
}
}
}
}
}
8 changes: 4 additions & 4 deletions Flow.Launcher.Core/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public async Task UpdateAppAsync(IPublicAPI api, bool silentUpdate = true)
await updateManager.CreateUninstallerRegistryEntry().ConfigureAwait(false);
}

var newVersionTips = NewVersinoTips(newReleaseVersion.ToString());
var newVersionTips = NewVersionTips(newReleaseVersion.ToString());

Log.Info($"|Updater.UpdateApp|Update success:{newVersionTips}");

Expand Down Expand Up @@ -137,10 +137,10 @@ private async Task<UpdateManager> GitHubUpdateManagerAsync(string repository)
return manager;
}

public string NewVersinoTips(string version)
public string NewVersionTips(string version)
{
var translater = InternationalizationManager.Instance;
var tips = string.Format(translater.GetTranslation("newVersionTips"), version);
var translator = InternationalizationManager.Instance;
var tips = string.Format(translator.GetTranslation("newVersionTips"), version);

return tips;
}
Expand Down
53 changes: 37 additions & 16 deletions Flow.Launcher.Infrastructure/Http/Http.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static void UpdateProxy(ProxyProperty property)
var userName when string.IsNullOrEmpty(userName) =>
(new Uri($"http://{Proxy.Server}:{Proxy.Port}"), null),
_ => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"),
new NetworkCredential(Proxy.UserName, Proxy.Password))
new NetworkCredential(Proxy.UserName, Proxy.Password))
},
_ => (null, null)
},
Expand All @@ -79,7 +79,7 @@ var userName when string.IsNullOrEmpty(userName) =>
_ => throw new ArgumentOutOfRangeException()
};
}
catch(UriFormatException e)
catch (UriFormatException e)
{
API.ShowMsg("Please try again", "Unable to parse Http Proxy");
Log.Exception("Flow.Launcher.Infrastructure.Http", "Unable to parse Uri", e);
Expand All @@ -94,7 +94,7 @@ public static async Task DownloadAsync([NotNull] string url, [NotNull] string fi
if (response.StatusCode == HttpStatusCode.OK)
{
await using var fileStream = new FileStream(filePath, FileMode.CreateNew);
await response.Content.CopyToAsync(fileStream);
await response.Content.CopyToAsync(fileStream, token);
}
else
{
Expand All @@ -117,7 +117,7 @@ public static async Task DownloadAsync([NotNull] string url, [NotNull] string fi
public static Task<string> GetAsync([NotNull] string url, CancellationToken token = default)
{
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?

}

/// <summary>
Expand All @@ -130,36 +130,57 @@ public static async Task<string> GetAsync([NotNull] Uri url, CancellationToken t
{
Log.Debug($"|Http.Get|Url <{url}>");
using var response = await client.GetAsync(url, token);
var content = await response.Content.ReadAsStringAsync();
if (response.StatusCode == HttpStatusCode.OK)
{
return content;
}
else
var content = await response.Content.ReadAsStringAsync(token);
if (response.StatusCode != HttpStatusCode.OK)
{
throw new HttpRequestException(
$"Error code <{response.StatusCode}> with content <{content}> returned from <{url}>");
}

return content;
}

/// <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

/// Send a GET request to the specified Uri with an HTTP completion option and a cancellation token as an asynchronous operation.
/// </summary>
/// <param name="url">The Uri the request is sent to.</param>
/// <param name="completionOption">An HTTP completion option value that indicates when the operation should be considered completed.</param>
/// <param name="token">A cancellation token that can be used by other objects or threads to receive notice of cancellation</param>
/// <returns></returns>
public static Task<Stream> GetStreamAsync([NotNull] string url,
CancellationToken token = default) => GetStreamAsync(new Uri(url), token);


/// <summary>
/// Send a GET request to the specified Uri with an HTTP completion option and a cancellation token as an asynchronous operation.
/// </summary>
/// <param name="url"></param>
/// <param name="token"></param>
/// <returns></returns>
public static async Task<Stream> GetStreamAsync([NotNull] string url, CancellationToken token = default)
public static async Task<Stream> GetStreamAsync([NotNull] Uri url,
CancellationToken token = default)
{
Log.Debug($"|Http.Get|Url <{url}>");
return await client.GetStreamAsync(url, token);
}

public static async Task<HttpResponseMessage> GetResponseAsync(string url, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead,
CancellationToken token = default)
=> await GetResponseAsync(new Uri(url), completionOption, token);

public static async Task<HttpResponseMessage> GetResponseAsync([NotNull] Uri url, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead,
CancellationToken token = default)
{
Log.Debug($"|Http.Get|Url <{url}>");
var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, token);
return await response.Content.ReadAsStreamAsync();
return await client.GetAsync(url, completionOption, token);
}

/// <summary>
/// Asynchrously send an HTTP request.
/// </summary>
public static async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken token = default)
public static async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken token = default)
{
return await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, token);
return await client.SendAsync(request, completionOption, token);
}
}
}
36 changes: 18 additions & 18 deletions Flow.Launcher.Infrastructure/Image/ImageCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,41 @@ public ImageUsage(int usage, ImageSource image)
public class ImageCache
{
private const int MaxCached = 50;
public ConcurrentDictionary<string, ImageUsage> Data { get; private set; } = new ConcurrentDictionary<string, ImageUsage>();
public ConcurrentDictionary<(string, bool), ImageUsage> Data { get; } = new();
private const int permissibleFactor = 2;
private SemaphoreSlim semaphore = new(1, 1);

public void Initialization(Dictionary<string, int> usage)
public void Initialization(Dictionary<(string, bool), int> usage)
{
foreach (var key in usage.Keys)
{
Data[key] = new ImageUsage(usage[key], null);
}
}

public ImageSource this[string path]
public ImageSource this[string path, bool isFullImage = false]
{
get
{
if (Data.TryGetValue(path, out var value))
if (!Data.TryGetValue((path, isFullImage), out var value))
{
value.usage++;
return value.imageSource;
return null;
}
value.usage++;
return value.imageSource;

return null;
}
set
{
Data.AddOrUpdate(
path,
new ImageUsage(0, value),
(k, v) =>
{
v.imageSource = value;
v.usage++;
return v;
}
(path, isFullImage),
new ImageUsage(0, value),
(k, v) =>
{
v.imageSource = value;
v.usage++;
return v;
}
);

SliceExtra();
Expand All @@ -82,9 +82,9 @@ async void SliceExtra()
}
}

public bool ContainsKey(string key)
public bool ContainsKey(string key, bool isFullImage)
{
return key is not null && Data.ContainsKey(key) && Data[key].imageSource != null;
return key is not null && Data.ContainsKey((key, isFullImage)) && Data[(key, isFullImage)].imageSource != null;
}

public int CacheSize()
Expand All @@ -100,4 +100,4 @@ public int UniqueImagesInCache()
return Data.Values.Select(x => x.imageSource).Distinct().Count();
}
}
}
}
Loading