Merge pull request #3668 from Flow-Launcher/derive_class_save

Fix Derive Class Save Method Calling Issue
This commit is contained in:
Jack Ye 2025-06-09 16:27:19 +08:00 committed by GitHub
commit ba28621b84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 16 additions and 12 deletions

View file

@ -12,7 +12,7 @@ using Flow.Launcher.Plugin;
namespace Flow.Launcher.Core.Plugin
{
public class JsonRPCPluginSettings
public class JsonRPCPluginSettings : ISavable
{
public required JsonRpcConfigurationModel? Configuration { get; init; }

View file

@ -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<T> : JsonStorage<T> where T : new()
// Expose ISaveable interface in derived class to make sure we are calling the new version of Save method
public class FlowLauncherJsonStorage<T> : JsonStorage<T>, ISavable where T : new()
{
private static readonly string ClassName = "FlowLauncherJsonStorage";

View file

@ -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<T> : BinaryStorage<T> where T : new()
// Expose ISaveable interface in derived class to make sure we are calling the new version of Save method
public class PluginBinaryStorage<T> : BinaryStorage<T>, ISavable where T : new()
{
private static readonly string ClassName = "PluginBinaryStorage";

View file

@ -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<T> : JsonStorage<T> where T : new()
// Expose ISaveable interface in derived class to make sure we are calling the new version of Save method
public class PluginJsonStorage<T> : JsonStorage<T>, ISavable where T : new()
{
// Use assembly name to check which plugin is using this storage
public readonly string AssemblyName;

View file

@ -287,7 +287,7 @@ namespace Flow.Launcher
public void LogException(string className, string message, Exception e, [CallerMemberName] string methodName = "") =>
Log.Exception(className, message, e, methodName);
private readonly ConcurrentDictionary<Type, object> _pluginJsonStorages = new();
private readonly ConcurrentDictionary<Type, ISavable> _pluginJsonStorages = new();
public void RemovePluginSettings(string assemblyName)
{
@ -305,10 +305,9 @@ namespace Flow.Launcher
public void SavePluginSettings()
{
foreach (var value in _pluginJsonStorages.Values)
foreach (var savable in _pluginJsonStorages.Values)
{
var savable = value as ISavable;
savable?.Save();
savable.Save();
}
}
@ -507,7 +506,7 @@ namespace Flow.Launcher
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)
{
@ -524,10 +523,9 @@ namespace Flow.Launcher
public void SavePluginCaches()
{
foreach (var value in _pluginBinaryStorages.Values)
foreach (var savable in _pluginBinaryStorages.Values)
{
var savable = value as ISavable;
savable?.Save();
savable.Save();
}
}