Skip to content

Commit 3185bda

Browse files
committed
Use IRemovable interface instead of reflection
1 parent 6e5c7ad commit 3185bda

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Flow.Launcher.Infrastructure.UserSettings;
1414
using Flow.Launcher.Plugin;
1515
using Flow.Launcher.Plugin.SharedCommands;
16+
using IRemovable = Flow.Launcher.Core.Storage.IRemovable;
1617
using ISavable = Flow.Launcher.Plugin.ISavable;
1718

1819
namespace Flow.Launcher.Core.Plugin
@@ -588,12 +589,10 @@ internal static async Task UninstallPluginAsync(PluginMetadata plugin, bool remo
588589
if (removePluginSettings)
589590
{
590591
// For dotnet plugins, we need to remove their PluginJsonStorage and PluginBinaryStorage instances
591-
if (AllowedLanguage.IsDotNet(plugin.Language))
592+
if (AllowedLanguage.IsDotNet(plugin.Language) && API is IRemovable removable)
592593
{
593-
var method = API.GetType().GetMethod("RemovePluginSettings");
594-
method?.Invoke(API, new object[] { plugin.AssemblyName });
595-
var method1 = API.GetType().GetMethod("RemovePluginCache");
596-
method1?.Invoke(API, new object[] { plugin.PluginCacheDirectoryPath });
594+
removable.RemovePluginSettings(plugin.AssemblyName);
595+
removable.RemovePluginCaches(plugin.PluginCacheDirectoryPath);
597596
}
598597

599598
try
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace Flow.Launcher.Core.Storage;
2+
3+
/// <summary>
4+
/// Remove storage instances from <see cref="Launcher.Plugin.IPublicAPI"> instance
5+
/// </summary>
6+
public interface IRemovable
7+
{
8+
/// <summary>
9+
/// Remove all <see cref="Infrastructure.Storage.PluginJsonStorage{T}"> instances of one plugin
10+
/// </summary>
11+
/// <param name="assemblyName"></param>
12+
public void RemovePluginSettings(string assemblyName);
13+
14+
/// <summary>
15+
/// Remove all <see cref="Infrastructure.Storage.PluginBinaryStorage{T}"> instances of one plugin
16+
/// </summary>
17+
/// <param name="cacheDirectory"></param>
18+
public void RemovePluginCaches(string cacheDirectory);
19+
}

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
using Squirrel;
1515
using Flow.Launcher.Core;
1616
using Flow.Launcher.Core.Plugin;
17+
using Flow.Launcher.Core.Resource;
18+
using Flow.Launcher.Core.Storage;
1719
using Flow.Launcher.Helper;
1820
using Flow.Launcher.Infrastructure;
1921
using Flow.Launcher.Infrastructure.Http;
@@ -27,11 +29,10 @@
2729
using Flow.Launcher.Plugin.SharedCommands;
2830
using Flow.Launcher.ViewModel;
2931
using JetBrains.Annotations;
30-
using Flow.Launcher.Core.Resource;
3132

3233
namespace Flow.Launcher
3334
{
34-
public class PublicAPIInstance : IPublicAPI
35+
public class PublicAPIInstance : IPublicAPI, IRemovable
3536
{
3637
private readonly Settings _settings;
3738
private readonly Internationalization _translater;
@@ -348,7 +349,7 @@ public MessageBoxResult ShowMsgBox(string messageBoxText, string caption = "", M
348349

349350
private readonly ConcurrentDictionary<(string, string, Type), object> _pluginBinaryStorages = new();
350351

351-
public void RemovePluginCache(string cacheDirectory)
352+
public void RemovePluginCaches(string cacheDirectory)
352353
{
353354
foreach (var keyValuePair in _pluginBinaryStorages)
354355
{

0 commit comments

Comments
 (0)