Skip to content

Commit 2b538d9

Browse files
committed
Merge branch 'dev' into filewatcher
2 parents 0842091 + 150ce09 commit 2b538d9

File tree

126 files changed

+349
-279
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+349
-279
lines changed

Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using Flow.Launcher.Infrastructure.Logger;
33
using System;
44
using System.Collections.Generic;
5+
using System.Net;
6+
using System.Net.Http;
57
using System.Text.Json;
68
using System.Threading;
79
using System.Threading.Tasks;
@@ -10,43 +12,43 @@ namespace Flow.Launcher.Core.ExternalPlugins
1012
{
1113
public static class PluginsManifest
1214
{
13-
static PluginsManifest()
14-
{
15-
UpdateTask = UpdateManifestAsync();
16-
}
17-
18-
public static List<UserPlugin> UserPlugins { get; private set; } = new List<UserPlugin>();
19-
20-
public static Task UpdateTask { get; private set; }
15+
private const string manifestFileUrl = "https://cdn.jsdelivr.net/gh/Flow-Launcher/Flow.Launcher.PluginsManifest@plugin_api_v2/plugins.json";
2116

2217
private static readonly SemaphoreSlim manifestUpdateLock = new(1);
2318

24-
public static Task UpdateManifestAsync()
25-
{
26-
if (manifestUpdateLock.CurrentCount == 0)
27-
{
28-
return UpdateTask;
29-
}
19+
private static string latestEtag = "";
3020

31-
return UpdateTask = DownloadManifestAsync();
32-
}
21+
public static List<UserPlugin> UserPlugins { get; private set; } = new List<UserPlugin>();
3322

34-
private static async Task DownloadManifestAsync()
23+
public static async Task UpdateManifestAsync(CancellationToken token = default)
3524
{
3625
try
3726
{
38-
await manifestUpdateLock.WaitAsync().ConfigureAwait(false);
27+
await manifestUpdateLock.WaitAsync(token).ConfigureAwait(false);
28+
29+
var request = new HttpRequestMessage(HttpMethod.Get, manifestFileUrl);
30+
request.Headers.Add("If-None-Match", latestEtag);
31+
32+
var response = await Http.SendAsync(request, token).ConfigureAwait(false);
3933

40-
await using var jsonStream = await Http.GetStreamAsync("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/plugin_api_v2/plugins.json")
41-
.ConfigureAwait(false);
34+
if (response.StatusCode == HttpStatusCode.OK)
35+
{
36+
Log.Info($"|PluginsManifest.{nameof(UpdateManifestAsync)}|Fetched plugins from manifest repo");
4237

43-
UserPlugins = await JsonSerializer.DeserializeAsync<List<UserPlugin>>(jsonStream).ConfigureAwait(false);
38+
var json = await response.Content.ReadAsStreamAsync(token).ConfigureAwait(false);
39+
40+
UserPlugins = await JsonSerializer.DeserializeAsync<List<UserPlugin>>(json, cancellationToken: token).ConfigureAwait(false);
41+
42+
latestEtag = response.Headers.ETag.Tag;
43+
}
44+
else if (response.StatusCode != HttpStatusCode.NotModified)
45+
{
46+
Log.Warn($"|PluginsManifest.{nameof(UpdateManifestAsync)}|Http response for manifest file was {response.StatusCode}");
47+
}
4448
}
4549
catch (Exception e)
4650
{
47-
Log.Exception("|PluginManagement.GetManifest|Encountered error trying to download plugins manifest", e);
48-
49-
UserPlugins = new List<UserPlugin>();
51+
Log.Exception($"|PluginsManifest.{nameof(UpdateManifestAsync)}|Http request failed", e);
5052
}
5153
finally
5254
{

Flow.Launcher.Infrastructure/Http/Http.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,13 @@ public static async Task<Stream> GetStreamAsync([NotNull] string url, Cancellati
153153
var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, token);
154154
return await response.Content.ReadAsStreamAsync();
155155
}
156+
157+
/// <summary>
158+
/// Asynchrously send an HTTP request.
159+
/// </summary>
160+
public static async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken token = default)
161+
{
162+
return await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, token);
163+
}
156164
}
157165
}

Flow.Launcher.Plugin/Result.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ public class Result
2929
/// </summary>
3030
public string ActionKeywordAssigned { get; set; }
3131

32+
/// <summary>
33+
/// This holds the text which can be provided by plugin to be copied to the
34+
/// user's clipboard when Ctrl + C is pressed on a result. If the text is a file/directory path
35+
/// flow will copy the actual file/folder instead of just the path text.
36+
/// </summary>
37+
public string CopyText { get; set; } = string.Empty;
38+
3239
/// <summary>
3340
/// This holds the text which can be provided by plugin to help Flow autocomplete text
3441
/// for user on the plugin result. If autocomplete action for example is tab, pressing tab will have

Flow.Launcher/App.xaml.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ private void RegisterDispatcherUnhandledException()
153153
DispatcherUnhandledException += ErrorReporting.DispatcherUnhandledException;
154154
}
155155

156-
157156
/// <summary>
158157
/// let exception throw as normal is better for Debug
159158
/// </summary>
@@ -179,4 +178,4 @@ public void OnSecondAppStarted()
179178
Current.MainWindow.Show();
180179
}
181180
}
182-
}
181+
}

Flow.Launcher/Flow.Launcher.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
8989
</PackageReference>
9090
<PackageReference Include="InputSimulator" Version="1.0.4" />
91+
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.2" />
9192
<PackageReference Include="ModernWpfUI" Version="0.9.4" />
9293
<PackageReference Include="NHotkey.Wpf" Version="2.1.0" />
9394
<PackageReference Include="NuGet.CommandLine" Version="5.4.0">

Flow.Launcher/Images/Browser.png

1.8 KB

Flow.Launcher/Images/EXE.png

1.37 KB

Flow.Launcher/Images/Link.png

2.39 KB

Flow.Launcher/Images/New Message.png

372 Bytes
-40.7 KB

0 commit comments

Comments
 (0)