From 0ec2ad9124a1b6cc2a37948c8aab2af5accbef31 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Sun, 20 Jun 2021 22:17:54 +1000 Subject: [PATCH] add skeleton handling upgrade incompatible plugins --- Flow.Launcher.Core/Plugin/PluginManager.cs | 3 ++ Flow.Launcher.Core/Plugin/PluginUpgrader.cs | 41 +++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 Flow.Launcher.Core/Plugin/PluginUpgrader.cs diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index 8d2c6df2426..e4c26a8883b 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -79,6 +79,9 @@ static PluginManager() /// public static void LoadPlugins(PluginsSettings settings) { + if (PluginUpgrader.ForceUpgradeRequired(settings)) + PluginUpgrader.ForceUpgrade(settings); + _metadatas = PluginConfig.Parse(Directories); Settings = settings; Settings.UpdatePluginSettings(_metadatas); diff --git a/Flow.Launcher.Core/Plugin/PluginUpgrader.cs b/Flow.Launcher.Core/Plugin/PluginUpgrader.cs new file mode 100644 index 00000000000..6d90b7ec7ba --- /dev/null +++ b/Flow.Launcher.Core/Plugin/PluginUpgrader.cs @@ -0,0 +1,41 @@ +using Flow.Launcher.Infrastructure.UserSettings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Flow.Launcher.Core.Plugin +{ + public static class PluginUpgrader + { + /// + /// Indicates these plugins need to have version greater than currently recorded + /// + private static readonly Dictionary PluginsUpgradeRequiredVersion = new() + { + { "D2D2C23B084D411DB66FE0C79D6C2A6E", new PluginVersion { ForceUpgradeRequiredVersion = "1.4.9" } } + }; + + internal static void ForceUpgrade(PluginsSettings settings) + { + // if new version is added for PluginVersion.NewVersionDownloadUrl=> remove older plugin, download & extract + // if PluginVersion.NewVersionDownloadUrl does not contain new version url, disable plugin and prompt to notify user + } + + internal static bool ForceUpgradeRequired(PluginsSettings settings) + { + return + settings.Plugins + .Any(t1 => PluginsUpgradeRequiredVersion + .Any(x => x.Key == t1.Key && x.Value.ForceUpgradeRequiredVersion == t1.Value.Version)); + } + } + + internal class PluginVersion + { + internal string ForceUpgradeRequiredVersion; + + internal string NewVersionDownloadUrl = string.Empty; + } +}