Skip to content

Commit 92634e6

Browse files
Merge branch 'dev' into AddSponsorButton
2 parents 17bc59d + 5bc6acf commit 92634e6

File tree

13 files changed

+194
-117
lines changed

13 files changed

+194
-117
lines changed

Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ public static async Task UpdateManifestAsync(CancellationToken token = default)
2929
var request = new HttpRequestMessage(HttpMethod.Get, manifestFileUrl);
3030
request.Headers.Add("If-None-Match", latestEtag);
3131

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

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

38-
var json = await response.Content.ReadAsStreamAsync(token).ConfigureAwait(false);
38+
await using var json = await response.Content.ReadAsStreamAsync(token).ConfigureAwait(false);
3939

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

@@ -56,4 +56,4 @@ public static async Task UpdateManifestAsync(CancellationToken token = default)
5656
}
5757
}
5858
}
59-
}
59+
}

Flow.Launcher.Core/Updater.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public async Task UpdateAppAsync(IPublicAPI api, bool silentUpdate = true)
7979
await updateManager.CreateUninstallerRegistryEntry().ConfigureAwait(false);
8080
}
8181

82-
var newVersionTips = NewVersinoTips(newReleaseVersion.ToString());
82+
var newVersionTips = NewVersionTips(newReleaseVersion.ToString());
8383

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

@@ -137,10 +137,10 @@ private async Task<UpdateManager> GitHubUpdateManagerAsync(string repository)
137137
return manager;
138138
}
139139

140-
public string NewVersinoTips(string version)
140+
public string NewVersionTips(string version)
141141
{
142-
var translater = InternationalizationManager.Instance;
143-
var tips = string.Format(translater.GetTranslation("newVersionTips"), version);
142+
var translator = InternationalizationManager.Instance;
143+
var tips = string.Format(translator.GetTranslation("newVersionTips"), version);
144144

145145
return tips;
146146
}

Flow.Launcher.Infrastructure/Http/Http.cs

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static void UpdateProxy(ProxyProperty property)
6868
var userName when string.IsNullOrEmpty(userName) =>
6969
(new Uri($"http://{Proxy.Server}:{Proxy.Port}"), null),
7070
_ => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"),
71-
new NetworkCredential(Proxy.UserName, Proxy.Password))
71+
new NetworkCredential(Proxy.UserName, Proxy.Password))
7272
},
7373
_ => (null, null)
7474
},
@@ -79,7 +79,7 @@ var userName when string.IsNullOrEmpty(userName) =>
7979
_ => throw new ArgumentOutOfRangeException()
8080
};
8181
}
82-
catch(UriFormatException e)
82+
catch (UriFormatException e)
8383
{
8484
API.ShowMsg("Please try again", "Unable to parse Http Proxy");
8585
Log.Exception("Flow.Launcher.Infrastructure.Http", "Unable to parse Uri", e);
@@ -94,7 +94,7 @@ public static async Task DownloadAsync([NotNull] string url, [NotNull] string fi
9494
if (response.StatusCode == HttpStatusCode.OK)
9595
{
9696
await using var fileStream = new FileStream(filePath, FileMode.CreateNew);
97-
await response.Content.CopyToAsync(fileStream);
97+
await response.Content.CopyToAsync(fileStream, token);
9898
}
9999
else
100100
{
@@ -117,7 +117,7 @@ public static async Task DownloadAsync([NotNull] string url, [NotNull] string fi
117117
public static Task<string> GetAsync([NotNull] string url, CancellationToken token = default)
118118
{
119119
Log.Debug($"|Http.Get|Url <{url}>");
120-
return GetAsync(new Uri(url.Replace("#", "%23")), token);
120+
return GetAsync(new Uri(url), token);
121121
}
122122

123123
/// <summary>
@@ -130,36 +130,57 @@ public static async Task<string> GetAsync([NotNull] Uri url, CancellationToken t
130130
{
131131
Log.Debug($"|Http.Get|Url <{url}>");
132132
using var response = await client.GetAsync(url, token);
133-
var content = await response.Content.ReadAsStringAsync();
134-
if (response.StatusCode == HttpStatusCode.OK)
135-
{
136-
return content;
137-
}
138-
else
133+
var content = await response.Content.ReadAsStringAsync(token);
134+
if (response.StatusCode != HttpStatusCode.OK)
139135
{
140136
throw new HttpRequestException(
141137
$"Error code <{response.StatusCode}> with content <{content}> returned from <{url}>");
142138
}
139+
140+
return content;
143141
}
144142

145143
/// <summary>
146-
/// Asynchrously get the result as stream from url.
144+
/// Send a GET request to the specified Uri with an HTTP completion option and a cancellation token as an asynchronous operation.
145+
/// </summary>
146+
/// <param name="url">The Uri the request is sent to.</param>
147+
/// <param name="completionOption">An HTTP completion option value that indicates when the operation should be considered completed.</param>
148+
/// <param name="token">A cancellation token that can be used by other objects or threads to receive notice of cancellation</param>
149+
/// <returns></returns>
150+
public static Task<Stream> GetStreamAsync([NotNull] string url,
151+
CancellationToken token = default) => GetStreamAsync(new Uri(url), token);
152+
153+
154+
/// <summary>
155+
/// Send a GET request to the specified Uri with an HTTP completion option and a cancellation token as an asynchronous operation.
147156
/// </summary>
148157
/// <param name="url"></param>
158+
/// <param name="token"></param>
149159
/// <returns></returns>
150-
public static async Task<Stream> GetStreamAsync([NotNull] string url, CancellationToken token = default)
160+
public static async Task<Stream> GetStreamAsync([NotNull] Uri url,
161+
CancellationToken token = default)
162+
{
163+
Log.Debug($"|Http.Get|Url <{url}>");
164+
return await client.GetStreamAsync(url, token);
165+
}
166+
167+
public static async Task<HttpResponseMessage> GetResponseAsync(string url, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead,
168+
CancellationToken token = default)
169+
=> await GetResponseAsync(new Uri(url), completionOption, token);
170+
171+
public static async Task<HttpResponseMessage> GetResponseAsync([NotNull] Uri url, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead,
172+
CancellationToken token = default)
151173
{
152174
Log.Debug($"|Http.Get|Url <{url}>");
153-
var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, token);
154-
return await response.Content.ReadAsStreamAsync();
175+
return await client.GetAsync(url, completionOption, token);
155176
}
156177

157178
/// <summary>
158179
/// Asynchrously send an HTTP request.
159180
/// </summary>
160-
public static async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken token = default)
181+
public static async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken token = default)
161182
{
162-
return await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, token);
183+
return await client.SendAsync(request, completionOption, token);
163184
}
164185
}
165186
}

Flow.Launcher.Infrastructure/Image/ImageCache.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,41 +25,41 @@ public ImageUsage(int usage, ImageSource image)
2525
public class ImageCache
2626
{
2727
private const int MaxCached = 50;
28-
public ConcurrentDictionary<string, ImageUsage> Data { get; private set; } = new ConcurrentDictionary<string, ImageUsage>();
28+
public ConcurrentDictionary<(string, bool), ImageUsage> Data { get; } = new();
2929
private const int permissibleFactor = 2;
3030
private SemaphoreSlim semaphore = new(1, 1);
3131

32-
public void Initialization(Dictionary<string, int> usage)
32+
public void Initialization(Dictionary<(string, bool), int> usage)
3333
{
3434
foreach (var key in usage.Keys)
3535
{
3636
Data[key] = new ImageUsage(usage[key], null);
3737
}
3838
}
3939

40-
public ImageSource this[string path]
40+
public ImageSource this[string path, bool isFullImage = false]
4141
{
4242
get
4343
{
44-
if (Data.TryGetValue(path, out var value))
44+
if (!Data.TryGetValue((path, isFullImage), out var value))
4545
{
46-
value.usage++;
47-
return value.imageSource;
46+
return null;
4847
}
48+
value.usage++;
49+
return value.imageSource;
4950

50-
return null;
5151
}
5252
set
5353
{
5454
Data.AddOrUpdate(
55-
path,
56-
new ImageUsage(0, value),
57-
(k, v) =>
58-
{
59-
v.imageSource = value;
60-
v.usage++;
61-
return v;
62-
}
55+
(path, isFullImage),
56+
new ImageUsage(0, value),
57+
(k, v) =>
58+
{
59+
v.imageSource = value;
60+
v.usage++;
61+
return v;
62+
}
6363
);
6464

6565
SliceExtra();
@@ -82,9 +82,9 @@ async void SliceExtra()
8282
}
8383
}
8484

85-
public bool ContainsKey(string key)
85+
public bool ContainsKey(string key, bool isFullImage)
8686
{
87-
return key is not null && Data.ContainsKey(key) && Data[key].imageSource != null;
87+
return key is not null && Data.ContainsKey((key, isFullImage)) && Data[(key, isFullImage)].imageSource != null;
8888
}
8989

9090
public int CacheSize()
@@ -100,4 +100,4 @@ public int UniqueImagesInCache()
100100
return Data.Values.Select(x => x.imageSource).Distinct().Count();
101101
}
102102
}
103-
}
103+
}

0 commit comments

Comments
 (0)