Skip to content

Commit 9ee123b

Browse files
authored
Merge pull request #3932 from Flow-Launcher/add_plugin_min_flow_version
Allow setting of minimum app version plugin requirement
2 parents ca01d15 + 8392a02 commit 9ee123b

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading.Tasks;
55
using CommunityToolkit.Mvvm.DependencyInjection;
66
using Flow.Launcher.Plugin;
7+
using Flow.Launcher.Infrastructure;
78

89
namespace Flow.Launcher.Core.ExternalPlugins
910
{
@@ -39,13 +40,23 @@ public static async Task<bool> UpdateManifestAsync(bool usePrimaryUrlOnly = fals
3940
var results = await mainPluginStore.FetchAsync(token, usePrimaryUrlOnly).ConfigureAwait(false);
4041

4142
// If the results are empty, we shouldn't update the manifest because the results are invalid.
42-
if (results.Count != 0)
43-
{
44-
UserPlugins = results;
45-
lastFetchedAt = DateTime.Now;
43+
if (results.Count == 0)
44+
return false;
45+
46+
lastFetchedAt = DateTime.Now;
4647

47-
return true;
48+
var updatedPluginResults = new List<UserPlugin>();
49+
var appVersion = SemanticVersioning.Version.Parse(Constant.Version);
50+
51+
for (int i = 0; i < results.Count; i++)
52+
{
53+
if (IsMinimumAppVersionSatisfied(results[i], appVersion))
54+
updatedPluginResults.Add(results[i]);
4855
}
56+
57+
UserPlugins = updatedPluginResults;
58+
59+
return true;
4960
}
5061
}
5162
catch (Exception e)
@@ -59,5 +70,16 @@ public static async Task<bool> UpdateManifestAsync(bool usePrimaryUrlOnly = fals
5970

6071
return false;
6172
}
73+
74+
private static bool IsMinimumAppVersionSatisfied(UserPlugin plugin, SemanticVersioning.Version appVersion)
75+
{
76+
if (string.IsNullOrEmpty(plugin.MinimumAppVersion) || appVersion >= SemanticVersioning.Version.Parse(plugin.MinimumAppVersion))
77+
return true;
78+
79+
API.LogDebug(ClassName, $"Plugin {plugin.Name} requires minimum Flow Launcher version {plugin.MinimumAppVersion}, "
80+
+ $"but current version is {Constant.Version}. Plugin excluded from manifest.");
81+
82+
return false;
83+
}
6284
}
6385
}

Flow.Launcher.Plugin/UserPlugin.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,10 @@ public record UserPlugin
7676
/// Indicates whether the plugin is installed from a local path
7777
/// </summary>
7878
public bool IsFromLocalInstallPath => !string.IsNullOrEmpty(LocalInstallPath);
79+
80+
/// <summary>
81+
/// The minimum Flow Launcher version required for this plugin. Default is "".
82+
/// </summary>
83+
public string MinimumAppVersion { get; set; } = string.Empty;
7984
}
8085
}

0 commit comments

Comments
 (0)