2025-04-04 07:56:18 +00:00
|
|
|
|
using System;
|
2021-10-10 21:46:54 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2025-04-04 07:56:18 +00:00
|
|
|
|
using Flow.Launcher.Plugin;
|
2026-02-27 10:30:29 +00:00
|
|
|
|
using Flow.Launcher.Core.Plugin;
|
2021-10-10 21:46:54 +00:00
|
|
|
|
|
|
|
|
|
|
namespace Flow.Launcher.Core.ExternalPlugins
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class PluginsManifest
|
|
|
|
|
|
{
|
2025-04-13 09:59:39 +00:00
|
|
|
|
private static readonly string ClassName = nameof(PluginsManifest);
|
|
|
|
|
|
|
2023-07-04 20:44:35 +00:00
|
|
|
|
private static readonly CommunityPluginStore mainPluginStore =
|
2025-09-03 11:02:07 +00:00
|
|
|
|
new("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/main/plugins.json",
|
|
|
|
|
|
"https://fastly.jsdelivr.net/gh/Flow-Launcher/Flow.Launcher.PluginsManifest@main/plugins.json",
|
|
|
|
|
|
"https://gcore.jsdelivr.net/gh/Flow-Launcher/Flow.Launcher.PluginsManifest@main/plugins.json",
|
|
|
|
|
|
"https://cdn.jsdelivr.net/gh/Flow-Launcher/Flow.Launcher.PluginsManifest@main/plugins.json");
|
2021-10-10 21:46:54 +00:00
|
|
|
|
|
|
|
|
|
|
private static readonly SemaphoreSlim manifestUpdateLock = new(1);
|
|
|
|
|
|
|
2023-07-05 13:54:50 +00:00
|
|
|
|
private static DateTime lastFetchedAt = DateTime.MinValue;
|
2025-04-04 07:56:18 +00:00
|
|
|
|
private static readonly TimeSpan fetchTimeout = TimeSpan.FromMinutes(2);
|
2021-10-10 21:46:54 +00:00
|
|
|
|
|
2023-07-04 20:44:35 +00:00
|
|
|
|
public static List<UserPlugin> UserPlugins { get; private set; }
|
2021-10-10 21:46:54 +00:00
|
|
|
|
|
2025-04-04 07:56:18 +00:00
|
|
|
|
public static async Task<bool> UpdateManifestAsync(bool usePrimaryUrlOnly = false, CancellationToken token = default)
|
2021-10-10 21:46:54 +00:00
|
|
|
|
{
|
2025-11-07 07:30:07 +00:00
|
|
|
|
bool lockAcquired = false;
|
2021-10-10 21:46:54 +00:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2022-01-11 04:12:10 +00:00
|
|
|
|
await manifestUpdateLock.WaitAsync(token).ConfigureAwait(false);
|
2025-11-07 07:30:07 +00:00
|
|
|
|
lockAcquired = true;
|
2021-10-10 21:46:54 +00:00
|
|
|
|
|
2025-02-10 03:54:09 +00:00
|
|
|
|
if (UserPlugins == null || usePrimaryUrlOnly || DateTime.Now.Subtract(lastFetchedAt) >= fetchTimeout)
|
2022-01-11 04:00:14 +00:00
|
|
|
|
{
|
2023-07-05 14:01:12 +00:00
|
|
|
|
var results = await mainPluginStore.FetchAsync(token, usePrimaryUrlOnly).ConfigureAwait(false);
|
2022-01-11 04:00:14 +00:00
|
|
|
|
|
2025-02-10 03:54:09 +00:00
|
|
|
|
// If the results are empty, we shouldn't update the manifest because the results are invalid.
|
2025-09-02 12:11:08 +00:00
|
|
|
|
if (results.Count == 0)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
2025-09-02 12:46:37 +00:00
|
|
|
|
var updatedPluginResults = new List<UserPlugin>();
|
2025-09-02 12:11:08 +00:00
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < results.Count; i++)
|
|
|
|
|
|
{
|
2026-02-27 10:30:29 +00:00
|
|
|
|
if (PluginManager.IsMinimumAppVersionSatisfied(results[i].Name, results[i].MinimumAppVersion))
|
2025-09-02 12:46:37 +00:00
|
|
|
|
updatedPluginResults.Add(results[i]);
|
2025-02-10 03:54:09 +00:00
|
|
|
|
}
|
2025-09-02 12:11:08 +00:00
|
|
|
|
|
2025-09-02 12:46:37 +00:00
|
|
|
|
UserPlugins = updatedPluginResults;
|
2025-09-02 12:11:08 +00:00
|
|
|
|
|
2025-09-04 11:49:16 +00:00
|
|
|
|
lastFetchedAt = DateTime.Now;
|
|
|
|
|
|
|
2025-09-02 12:11:08 +00:00
|
|
|
|
return true;
|
2022-01-11 04:00:14 +00:00
|
|
|
|
}
|
2021-10-10 21:46:54 +00:00
|
|
|
|
}
|
2025-11-06 12:47:54 +00:00
|
|
|
|
catch (OperationCanceledException)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Ignored
|
|
|
|
|
|
}
|
2021-10-10 21:46:54 +00:00
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
2025-09-23 09:40:54 +00:00
|
|
|
|
PublicApi.Instance.LogException(ClassName, "Http request failed", e);
|
2021-10-10 21:46:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
2025-11-07 07:30:07 +00:00
|
|
|
|
// Only release the lock if it was acquired
|
|
|
|
|
|
if (lockAcquired) manifestUpdateLock.Release();
|
2021-10-10 21:46:54 +00:00
|
|
|
|
}
|
2025-02-10 04:01:21 +00:00
|
|
|
|
|
|
|
|
|
|
return false;
|
2021-10-10 21:46:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-10-30 19:23:04 +00:00
|
|
|
|
}
|