Skip to content

Commit 4df7413

Browse files
committed
Merge remote-tracking branch 'origin/dev' into ChangeMissingIcon
2 parents 06859ef + f636891 commit 4df7413

File tree

219 files changed

+49918
-2846
lines changed

Some content is hidden

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

219 files changed

+49918
-2846
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 async static 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.Core/Plugin/ExecutablePlugin.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Diagnostics;
1+
using System.Diagnostics;
32
using System.IO;
43
using System.Threading;
54
using System.Threading.Tasks;
@@ -22,18 +21,23 @@ public ExecutablePlugin(string filename)
2221
RedirectStandardOutput = true,
2322
RedirectStandardError = true
2423
};
24+
25+
// required initialisation for below request calls
26+
_startInfo.ArgumentList.Add(string.Empty);
2527
}
2628

2729
protected override Task<Stream> RequestAsync(JsonRPCRequestModel request, CancellationToken token = default)
2830
{
29-
_startInfo.Arguments = $"\"{request}\"";
31+
// since this is not static, request strings will build up in ArgumentList if index is not specified
32+
_startInfo.ArgumentList[0] = request.ToString();
3033
return ExecuteAsync(_startInfo, token);
3134
}
3235

3336
protected override string Request(JsonRPCRequestModel rpcRequest, CancellationToken token = default)
3437
{
35-
_startInfo.Arguments = $"\"{rpcRequest}\"";
38+
// since this is not static, request strings will build up in ArgumentList if index is not specified
39+
_startInfo.ArgumentList[0] = rpcRequest.ToString();
3640
return Execute(_startInfo);
3741
}
3842
}
39-
}
43+
}

Flow.Launcher.Core/Plugin/JsonPRCModel.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,19 @@ public class JsonRPCQueryResponseModel : JsonRPCResponseModel
4343
[JsonPropertyName("result")]
4444
public new List<JsonRPCResult> Result { get; set; }
4545

46+
public Dictionary<string, object> SettingsChange { get; set; }
47+
4648
public string DebugMessage { get; set; }
4749
}
48-
50+
4951
public class JsonRPCRequestModel
5052
{
5153
public string Method { get; set; }
5254

5355
public object[] Parameters { get; set; }
5456

57+
public Dictionary<string, object> Settings { get; set; }
58+
5559
private static readonly JsonSerializerOptions options = new()
5660
{
5761
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
@@ -86,5 +90,7 @@ public class JsonRPCClientRequestModel : JsonRPCRequestModel
8690
public class JsonRPCResult : Result
8791
{
8892
public JsonRPCClientRequestModel JsonRPCAction { get; set; }
93+
94+
public Dictionary<string, object> SettingsChange { get; set; }
8995
}
9096
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.Collections.Generic;
2+
3+
namespace Flow.Launcher.Core.Plugin
4+
{
5+
public class JsonRpcConfigurationModel
6+
{
7+
public List<SettingField> Body { get; set; }
8+
public void Deconstruct(out List<SettingField> Body)
9+
{
10+
Body = this.Body;
11+
}
12+
}
13+
14+
public class SettingField
15+
{
16+
public string Type { get; set; }
17+
public FieldAttributes Attributes { get; set; }
18+
public void Deconstruct(out string Type, out FieldAttributes attributes)
19+
{
20+
Type = this.Type;
21+
attributes = this.Attributes;
22+
}
23+
}
24+
public class FieldAttributes
25+
{
26+
public string Name { get; set; }
27+
public string Label { get; set; }
28+
public string Description { get; set; }
29+
public bool Validation { get; set; }
30+
public List<string> Options { get; set; }
31+
public string DefaultValue { get; set; }
32+
public char passwordChar { get; set; }
33+
public void Deconstruct(out string Name, out string Label, out string Description, out bool Validation, out List<string> Options, out string DefaultValue)
34+
{
35+
Name = this.Name;
36+
Label = this.Label;
37+
Description = this.Description;
38+
Validation = this.Validation;
39+
Options = this.Options;
40+
DefaultValue = this.DefaultValue;
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)