Skip to content

Commit ce50d98

Browse files
Jack251970jjw24
authored andcommitted
Merge pull request #3668 from Flow-Launcher/derive_class_save
Fix Derive Class Save Method Calling Issue
1 parent 705f4d4 commit ce50d98

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace Flow.Launcher.Core.Plugin
1414
{
15-
public class JsonRPCPluginSettings
15+
public class JsonRPCPluginSettings : ISavable
1616
{
1717
public required JsonRpcConfigurationModel? Configuration { get; init; }
1818

Flow.Launcher.Infrastructure/Storage/FlowLauncherJsonStorage.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
using System.Threading.Tasks;
33
using Flow.Launcher.Infrastructure.Logger;
44
using Flow.Launcher.Infrastructure.UserSettings;
5+
using Flow.Launcher.Plugin;
56
using Flow.Launcher.Plugin.SharedCommands;
67

78
namespace Flow.Launcher.Infrastructure.Storage
89
{
9-
public class FlowLauncherJsonStorage<T> : JsonStorage<T> where T : new()
10+
// Expose ISaveable interface in derived class to make sure we are calling the new version of Save method
11+
public class FlowLauncherJsonStorage<T> : JsonStorage<T>, ISavable where T : new()
1012
{
1113
private static readonly string ClassName = "FlowLauncherJsonStorage";
1214

Flow.Launcher.Infrastructure/Storage/PluginBinaryStorage.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using System.IO;
22
using System.Threading.Tasks;
33
using Flow.Launcher.Infrastructure.Logger;
4+
using Flow.Launcher.Plugin;
45
using Flow.Launcher.Plugin.SharedCommands;
56

67
namespace Flow.Launcher.Infrastructure.Storage
78
{
8-
public class PluginBinaryStorage<T> : BinaryStorage<T> where T : new()
9+
// Expose ISaveable interface in derived class to make sure we are calling the new version of Save method
10+
public class PluginBinaryStorage<T> : BinaryStorage<T>, ISavable where T : new()
911
{
1012
private static readonly string ClassName = "PluginBinaryStorage";
1113

Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
using System.Threading.Tasks;
33
using Flow.Launcher.Infrastructure.Logger;
44
using Flow.Launcher.Infrastructure.UserSettings;
5+
using Flow.Launcher.Plugin;
56
using Flow.Launcher.Plugin.SharedCommands;
67

78
namespace Flow.Launcher.Infrastructure.Storage
89
{
9-
public class PluginJsonStorage<T> : JsonStorage<T> where T : new()
10+
// Expose ISaveable interface in derived class to make sure we are calling the new version of Save method
11+
public class PluginJsonStorage<T> : JsonStorage<T>, ISavable where T : new()
1012
{
1113
// Use assembly name to check which plugin is using this storage
1214
public readonly string AssemblyName;

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public void LogError(string className, string message, [CallerMemberName] string
276276
public void LogException(string className, string message, Exception e, [CallerMemberName] string methodName = "") =>
277277
Log.Exception(className, message, e, methodName);
278278

279-
private readonly ConcurrentDictionary<Type, object> _pluginJsonStorages = new();
279+
private readonly ConcurrentDictionary<Type, ISavable> _pluginJsonStorages = new();
280280

281281
public void RemovePluginSettings(string assemblyName)
282282
{
@@ -294,10 +294,9 @@ public void RemovePluginSettings(string assemblyName)
294294

295295
public void SavePluginSettings()
296296
{
297-
foreach (var value in _pluginJsonStorages.Values)
297+
foreach (var savable in _pluginJsonStorages.Values)
298298
{
299-
var savable = value as ISavable;
300-
savable?.Save();
299+
savable.Save();
301300
}
302301
}
303302

@@ -496,7 +495,7 @@ public Task ShowProgressBoxAsync(string caption, Func<Action<double>, Task> repo
496495
public bool SetCurrentTheme(ThemeData theme) =>
497496
Theme.ChangeTheme(theme.FileNameWithoutExtension);
498497

499-
private readonly ConcurrentDictionary<(string, string, Type), object> _pluginBinaryStorages = new();
498+
private readonly ConcurrentDictionary<(string, string, Type), ISavable> _pluginBinaryStorages = new();
500499

501500
public void RemovePluginCaches(string cacheDirectory)
502501
{
@@ -513,10 +512,9 @@ public void RemovePluginCaches(string cacheDirectory)
513512

514513
public void SavePluginCaches()
515514
{
516-
foreach (var value in _pluginBinaryStorages.Values)
515+
foreach (var savable in _pluginBinaryStorages.Values)
517516
{
518-
var savable = value as ISavable;
519-
savable?.Save();
517+
savable.Save();
520518
}
521519
}
522520

0 commit comments

Comments
 (0)