From baef9ddacd119e5fdce544b8f5ee476482732408 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 6 Jun 2025 18:37:17 +0800 Subject: [PATCH 1/3] Expose ISaveable interface in derived class to make sure we are calling the new version of Save method --- .../Storage/FlowLauncherJsonStorage.cs | 4 +++- Flow.Launcher.Infrastructure/Storage/PluginBinaryStorage.cs | 4 +++- Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher.Infrastructure/Storage/FlowLauncherJsonStorage.cs b/Flow.Launcher.Infrastructure/Storage/FlowLauncherJsonStorage.cs index 158e0cdf58c..857490badd2 100644 --- a/Flow.Launcher.Infrastructure/Storage/FlowLauncherJsonStorage.cs +++ b/Flow.Launcher.Infrastructure/Storage/FlowLauncherJsonStorage.cs @@ -2,11 +2,13 @@ using System.Threading.Tasks; using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Infrastructure.UserSettings; +using Flow.Launcher.Plugin; using Flow.Launcher.Plugin.SharedCommands; namespace Flow.Launcher.Infrastructure.Storage { - public class FlowLauncherJsonStorage : JsonStorage where T : new() + // Expose ISaveable interface in derived class to make sure we are calling the new version of Save method + public class FlowLauncherJsonStorage : JsonStorage, ISavable where T : new() { private static readonly string ClassName = "FlowLauncherJsonStorage"; diff --git a/Flow.Launcher.Infrastructure/Storage/PluginBinaryStorage.cs b/Flow.Launcher.Infrastructure/Storage/PluginBinaryStorage.cs index 01da96d6259..0e0906e7328 100644 --- a/Flow.Launcher.Infrastructure/Storage/PluginBinaryStorage.cs +++ b/Flow.Launcher.Infrastructure/Storage/PluginBinaryStorage.cs @@ -1,11 +1,13 @@ using System.IO; using System.Threading.Tasks; using Flow.Launcher.Infrastructure.Logger; +using Flow.Launcher.Plugin; using Flow.Launcher.Plugin.SharedCommands; namespace Flow.Launcher.Infrastructure.Storage { - public class PluginBinaryStorage : BinaryStorage where T : new() + // Expose ISaveable interface in derived class to make sure we are calling the new version of Save method + public class PluginBinaryStorage : BinaryStorage, ISavable where T : new() { private static readonly string ClassName = "PluginBinaryStorage"; diff --git a/Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs b/Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs index 14715294958..d5908307129 100644 --- a/Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs +++ b/Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs @@ -2,11 +2,13 @@ using System.Threading.Tasks; using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Infrastructure.UserSettings; +using Flow.Launcher.Plugin; using Flow.Launcher.Plugin.SharedCommands; namespace Flow.Launcher.Infrastructure.Storage { - public class PluginJsonStorage : JsonStorage where T : new() + // Expose ISaveable interface in derived class to make sure we are calling the new version of Save method + public class PluginJsonStorage : JsonStorage, ISavable where T : new() { // Use assembly name to check which plugin is using this storage public readonly string AssemblyName; From 062cd2ad1dc8dd8327a6a2cebdbd58e478c362d9 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 6 Jun 2025 18:38:05 +0800 Subject: [PATCH 2/3] Use ISavable instead of object --- Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs | 2 +- Flow.Launcher/PublicAPIInstance.cs | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs b/Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs index 003e72a5d86..435d97ab712 100644 --- a/Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs +++ b/Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs @@ -12,7 +12,7 @@ namespace Flow.Launcher.Core.Plugin { - public class JsonRPCPluginSettings + public class JsonRPCPluginSettings : ISavable { public required JsonRpcConfigurationModel? Configuration { get; init; } diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 80d5de53d84..06e17baf02f 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -276,7 +276,7 @@ public void LogError(string className, string message, [CallerMemberName] string public void LogException(string className, string message, Exception e, [CallerMemberName] string methodName = "") => Log.Exception(className, message, e, methodName); - private readonly ConcurrentDictionary _pluginJsonStorages = new(); + private readonly ConcurrentDictionary _pluginJsonStorages = new(); public void RemovePluginSettings(string assemblyName) { @@ -294,9 +294,8 @@ public void RemovePluginSettings(string assemblyName) public void SavePluginSettings() { - foreach (var value in _pluginJsonStorages.Values) + foreach (var savable in _pluginJsonStorages.Values) { - var savable = value as ISavable; savable?.Save(); } } @@ -496,7 +495,7 @@ public Task ShowProgressBoxAsync(string caption, Func, Task> repo public bool SetCurrentTheme(ThemeData theme) => Theme.ChangeTheme(theme.FileNameWithoutExtension); - private readonly ConcurrentDictionary<(string, string, Type), object> _pluginBinaryStorages = new(); + private readonly ConcurrentDictionary<(string, string, Type), ISavable> _pluginBinaryStorages = new(); public void RemovePluginCaches(string cacheDirectory) { @@ -513,9 +512,8 @@ public void RemovePluginCaches(string cacheDirectory) public void SavePluginCaches() { - foreach (var value in _pluginBinaryStorages.Values) + foreach (var savable in _pluginBinaryStorages.Values) { - var savable = value as ISavable; savable?.Save(); } } From 754533f78b4419d4c8c2ad5c62354c9c826ca66c Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sun, 8 Jun 2025 14:28:37 +0800 Subject: [PATCH 3/3] Remove null check --- Flow.Launcher/PublicAPIInstance.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 06e17baf02f..17d0a875251 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -296,7 +296,7 @@ public void SavePluginSettings() { foreach (var savable in _pluginJsonStorages.Values) { - savable?.Save(); + savable.Save(); } } @@ -514,7 +514,7 @@ public void SavePluginCaches() { foreach (var savable in _pluginBinaryStorages.Values) { - savable?.Save(); + savable.Save(); } }