Skip to content

Commit ba28621

Browse files
authored
Merge pull request #3668 from Flow-Launcher/derive_class_save
Fix Derive Class Save Method Calling Issue
2 parents 680c6cc + 754533f commit ba28621

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
@@ -287,7 +287,7 @@ public void LogError(string className, string message, [CallerMemberName] string
287287
public void LogException(string className, string message, Exception e, [CallerMemberName] string methodName = "") =>
288288
Log.Exception(className, message, e, methodName);
289289

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

292292
public void RemovePluginSettings(string assemblyName)
293293
{
@@ -305,10 +305,9 @@ public void RemovePluginSettings(string assemblyName)
305305

306306
public void SavePluginSettings()
307307
{
308-
foreach (var value in _pluginJsonStorages.Values)
308+
foreach (var savable in _pluginJsonStorages.Values)
309309
{
310-
var savable = value as ISavable;
311-
savable?.Save();
310+
savable.Save();
312311
}
313312
}
314313

@@ -507,7 +506,7 @@ public Task ShowProgressBoxAsync(string caption, Func<Action<double>, Task> repo
507506
public bool SetCurrentTheme(ThemeData theme) =>
508507
Theme.ChangeTheme(theme.FileNameWithoutExtension);
509508

510-
private readonly ConcurrentDictionary<(string, string, Type), object> _pluginBinaryStorages = new();
509+
private readonly ConcurrentDictionary<(string, string, Type), ISavable> _pluginBinaryStorages = new();
511510

512511
public void RemovePluginCaches(string cacheDirectory)
513512
{
@@ -524,10 +523,9 @@ public void RemovePluginCaches(string cacheDirectory)
524523

525524
public void SavePluginCaches()
526525
{
527-
foreach (var value in _pluginBinaryStorages.Values)
526+
foreach (var savable in _pluginBinaryStorages.Values)
528527
{
529-
var savable = value as ISavable;
530-
savable?.Save();
528+
savable.Save();
531529
}
532530
}
533531

0 commit comments

Comments
 (0)