Skip to content

Commit

Permalink
Merge pull request #2197 from Flow-Launcher/dev
Browse files Browse the repository at this point in the history
Release 1.16.0 | Plugin 4.1.0
  • Loading branch information
jjw24 committed Jul 10, 2023
2 parents 1c356d0 + 6020cd9 commit 45e1f39
Show file tree
Hide file tree
Showing 231 changed files with 8,181 additions and 1,130 deletions.
8 changes: 8 additions & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ WCA_ACCENT_POLICY
HGlobal
dopusrt
firefox
Firefox
msedge
svgc
ime
Expand All @@ -95,3 +96,10 @@ keyevent
KListener
requery
vkcode
čeština
Polski
Srpski
Português
Português (Brasil)
Italiano
Slovenský
3 changes: 1 addition & 2 deletions .github/workflows/winget.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: Publish to Winget

on:
release:
types: [released]
workflow_dispatch:

jobs:
publish:
Expand Down
4 changes: 0 additions & 4 deletions Deploy/local_build.ps1

This file was deleted.

5 changes: 5 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
</PropertyGroup>
</Project>
57 changes: 57 additions & 0 deletions Flow.Launcher.Core/ExternalPlugins/CommunityPluginSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Flow.Launcher.Infrastructure.Http;
using Flow.Launcher.Infrastructure.Logger;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading;
using System.Threading.Tasks;

namespace Flow.Launcher.Core.ExternalPlugins
{
public record CommunityPluginSource(string ManifestFileUrl)
{
private string latestEtag = "";

private List<UserPlugin> plugins = new();

/// <summary>
/// Fetch and deserialize the contents of a plugins.json file found at <see cref="ManifestFileUrl"/>.
/// We use conditional http requests to keep repeat requests fast.
/// </summary>
/// <remarks>
/// This method will only return plugin details when the underlying http request is successful (200 or 304).
/// In any other case, an exception is raised
/// </remarks>
public async Task<List<UserPlugin>> FetchAsync(CancellationToken token)
{
Log.Info(nameof(CommunityPluginSource), $"Loading plugins from {ManifestFileUrl}");

var request = new HttpRequestMessage(HttpMethod.Get, ManifestFileUrl);

request.Headers.Add("If-None-Match", latestEtag);

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

if (response.StatusCode == HttpStatusCode.OK)
{
this.plugins = await response.Content.ReadFromJsonAsync<List<UserPlugin>>(cancellationToken: token).ConfigureAwait(false);
this.latestEtag = response.Headers.ETag.Tag;

Log.Info(nameof(CommunityPluginSource), $"Loaded {this.plugins.Count} plugins from {ManifestFileUrl}");
return this.plugins;
}
else if (response.StatusCode == HttpStatusCode.NotModified)
{
Log.Info(nameof(CommunityPluginSource), $"Resource {ManifestFileUrl} has not been modified.");
return this.plugins;
}
else
{
Log.Warn(nameof(CommunityPluginSource), $"Failed to load resource {ManifestFileUrl} with response {response.StatusCode}");
throw new Exception($"Failed to load resource {ManifestFileUrl} with response {response.StatusCode}");
}
}
}
}
54 changes: 54 additions & 0 deletions Flow.Launcher.Core/ExternalPlugins/CommunityPluginStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace Flow.Launcher.Core.ExternalPlugins
{
/// <summary>
/// Describes a store of community-made plugins.
/// The provided URLs should point to a json file, whose content
/// is deserializable as a <see cref="UserPlugin"/> array.
/// </summary>
/// <param name="primaryUrl">Primary URL to the manifest json file.</param>
/// <param name="secondaryUrls">Secondary URLs to access the <paramref name="primaryUrl"/>, for example CDN links</param>
public record CommunityPluginStore(string primaryUrl, params string[] secondaryUrls)
{
private readonly List<CommunityPluginSource> pluginSources =
secondaryUrls
.Append(primaryUrl)
.Select(url => new CommunityPluginSource(url))
.ToList();

public async Task<List<UserPlugin>> FetchAsync(CancellationToken token, bool onlyFromPrimaryUrl = false)
{
// we create a new cancellation token source linked to the given token.
// Once any of the http requests completes successfully, we call cancel
// to stop the rest of the running http requests.
var cts = CancellationTokenSource.CreateLinkedTokenSource(token);

var tasks = onlyFromPrimaryUrl
? new() { pluginSources.Last().FetchAsync(cts.Token) }
: pluginSources.Select(pluginSource => pluginSource.FetchAsync(cts.Token)).ToList();

var pluginResults = new List<UserPlugin>();

// keep going until all tasks have completed
while (tasks.Any())
{
var completedTask = await Task.WhenAny(tasks);
if (completedTask.IsCompletedSuccessfully)
{
// one of the requests completed successfully; keep its results
// and cancel the remaining http requests.
pluginResults = await completedTask;
cts.Cancel();
}
tasks.Remove(completedTask);
}

// all tasks have finished
return pluginResults;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,6 @@ internal IEnumerable<PluginPair> Setup()
if (!PluginMetadataList.Any(o => o.Language.Equals(Language, StringComparison.OrdinalIgnoreCase)))
return new List<PluginPair>();

// TODO: Remove. This is backwards compatibility for 1.10.0 release- changed PythonEmbeded to Environments/Python
if (Language.Equals(AllowedLanguage.Python, StringComparison.OrdinalIgnoreCase))
{
FilesFolders.RemoveFolderIfExists(Path.Combine(DataLocation.DataDirectory(), "PythonEmbeddable"));

if (!string.IsNullOrEmpty(PluginSettings.PythonDirectory) && PluginSettings.PythonDirectory.StartsWith(Path.Combine(DataLocation.DataDirectory(), "PythonEmbeddable")))
{
InstallEnvironment();
PluginSettings.PythonDirectory = string.Empty;
}
}

if (!string.IsNullOrEmpty(PluginsSettingsFilePath) && FilesFolders.FileExists(PluginsSettingsFilePath))
{
// Ensure latest only if user is using Flow's environment setup.
Expand Down
39 changes: 14 additions & 25 deletions Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs
Original file line number Diff line number Diff line change
@@ -1,49 +1,38 @@
using Flow.Launcher.Infrastructure.Http;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Infrastructure.Logger;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;

namespace Flow.Launcher.Core.ExternalPlugins
{
public static class PluginsManifest
{
private const string manifestFileUrl = "https://cdn.jsdelivr.net/gh/Flow-Launcher/Flow.Launcher.PluginsManifest@plugin_api_v2/plugins.json";
private static readonly CommunityPluginStore mainPluginStore =
new("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/plugin_api_v2/plugins.json",
"https://fastly.jsdelivr.net/gh/Flow-Launcher/Flow.Launcher.PluginsManifest@plugin_api_v2/plugins.json",
"https://gcore.jsdelivr.net/gh/Flow-Launcher/Flow.Launcher.PluginsManifest@plugin_api_v2/plugins.json",
"https://cdn.jsdelivr.net/gh/Flow-Launcher/Flow.Launcher.PluginsManifest@plugin_api_v2/plugins.json");

private static readonly SemaphoreSlim manifestUpdateLock = new(1);

private static string latestEtag = "";
private static DateTime lastFetchedAt = DateTime.MinValue;
private static TimeSpan fetchTimeout = TimeSpan.FromMinutes(2);

public static List<UserPlugin> UserPlugins { get; private set; } = new List<UserPlugin>();
public static List<UserPlugin> UserPlugins { get; private set; }

public static async Task UpdateManifestAsync(CancellationToken token = default)
public static async Task UpdateManifestAsync(CancellationToken token = default, bool usePrimaryUrlOnly = false)
{
try
{
await manifestUpdateLock.WaitAsync(token).ConfigureAwait(false);

var request = new HttpRequestMessage(HttpMethod.Get, manifestFileUrl);
request.Headers.Add("If-None-Match", latestEtag);

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

if (response.StatusCode == HttpStatusCode.OK)
if (UserPlugins == null || usePrimaryUrlOnly || DateTime.Now.Subtract(lastFetchedAt) >= fetchTimeout)
{
Log.Info($"|PluginsManifest.{nameof(UpdateManifestAsync)}|Fetched plugins from manifest repo");

await using var json = await response.Content.ReadAsStreamAsync(token).ConfigureAwait(false);
var results = await mainPluginStore.FetchAsync(token, usePrimaryUrlOnly).ConfigureAwait(false);

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

latestEtag = response.Headers.ETag.Tag;
}
else if (response.StatusCode != HttpStatusCode.NotModified)
{
Log.Warn($"|PluginsManifest.{nameof(UpdateManifestAsync)}|Http response for manifest file was {response.StatusCode}");
UserPlugins = results;
lastFetchedAt = DateTime.Now;
}
}
catch (Exception e)
Expand Down
6 changes: 3 additions & 3 deletions Flow.Launcher.Core/Flow.Launcher.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
Expand Down Expand Up @@ -54,8 +54,8 @@

<ItemGroup>
<PackageReference Include="Droplex" Version="1.6.0" />
<PackageReference Include="FSharp.Core" Version="7.0.0" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="2.3.1" />
<PackageReference Include="FSharp.Core" Version="7.0.300" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="2.3.2" />
<PackageReference Include="squirrel.windows" Version="1.5.2" NoWarn="NU1701" />
</ItemGroup>

Expand Down
1 change: 0 additions & 1 deletion Flow.Launcher.Core/Plugin/ExecutablePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Flow.Launcher.Plugin;

namespace Flow.Launcher.Core.Plugin
{
Expand Down
2 changes: 0 additions & 2 deletions Flow.Launcher.Core/Plugin/JsonPRCModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
*
*/

using Flow.Launcher.Core.Resource;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using Flow.Launcher.Plugin;
using System.Text.Json;
Expand Down
3 changes: 0 additions & 3 deletions Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
using TextBox = System.Windows.Controls.TextBox;
using UserControl = System.Windows.Controls.UserControl;
using System.Windows.Documents;
using static System.Windows.Forms.LinkLabel;
using Droplex;
using System.Windows.Forms;

namespace Flow.Launcher.Core.Plugin
{
Expand Down
6 changes: 1 addition & 5 deletions Flow.Launcher.Core/Plugin/NodePlugin.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Flow.Launcher.Plugin;
Expand Down
5 changes: 1 addition & 4 deletions Flow.Launcher.Core/Plugin/PluginAssemblyLoader.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using Flow.Launcher.Infrastructure;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System;
using System.IO;
using System.Linq;
using System.Reflection;
Expand Down
2 changes: 2 additions & 0 deletions Flow.Launcher.Core/Plugin/PluginsLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using System.Threading.Tasks;
using System.Windows.Forms;
using Flow.Launcher.Core.ExternalPlugins.Environments;
#pragma warning disable IDE0005
using Flow.Launcher.Infrastructure.Logger;
#pragma warning restore IDE0005
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
Expand Down
3 changes: 1 addition & 2 deletions Flow.Launcher.Core/Plugin/PythonPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
Expand Down
13 changes: 8 additions & 5 deletions Flow.Launcher.Core/Plugin/QueryBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Flow.Launcher.Plugin;

namespace Flow.Launcher.Core.Plugin
Expand Down Expand Up @@ -34,9 +33,13 @@ public static Query Build(string text, Dictionary<string, PluginPair> nonGlobalP
searchTerms = terms;
}

var query = new Query(rawQuery, search,terms, searchTerms, actionKeyword);

return query;
return new Query ()
{
Search = search,
RawQuery = rawQuery,
SearchTerms = searchTerms,
ActionKeyword = actionKeyword
};
}
}
}
6 changes: 5 additions & 1 deletion Flow.Launcher.Core/Resource/AvailableLanguages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ internal static class AvailableLanguages
public static Language Norwegian_Bokmal = new Language("nb-NO", "Norsk Bokmål");
public static Language Slovak = new Language("sk", "Slovenský");
public static Language Turkish = new Language("tr", "Türkçe");
public static Language Czech = new Language("cs", "čeština");
public static Language Arabic = new Language("ar", "اللغة العربية");

public static List<Language> GetAvailableLanguages()
{
Expand All @@ -50,7 +52,9 @@ public static List<Language> GetAvailableLanguages()
Italian,
Norwegian_Bokmal,
Slovak,
Turkish
Turkish,
Czech,
Arabic
};
return languages;
}
Expand Down
Loading

0 comments on commit 45e1f39

Please sign in to comment.