mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Use IRemovable interface instead of reflection
This commit is contained in:
parent
6e5c7ad190
commit
3185bda824
3 changed files with 27 additions and 8 deletions
|
|
@ -13,6 +13,7 @@ using Flow.Launcher.Infrastructure.Logger;
|
|||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.Plugin;
|
||||
using Flow.Launcher.Plugin.SharedCommands;
|
||||
using IRemovable = Flow.Launcher.Core.Storage.IRemovable;
|
||||
using ISavable = Flow.Launcher.Plugin.ISavable;
|
||||
|
||||
namespace Flow.Launcher.Core.Plugin
|
||||
|
|
@ -588,12 +589,10 @@ namespace Flow.Launcher.Core.Plugin
|
|||
if (removePluginSettings)
|
||||
{
|
||||
// For dotnet plugins, we need to remove their PluginJsonStorage and PluginBinaryStorage instances
|
||||
if (AllowedLanguage.IsDotNet(plugin.Language))
|
||||
if (AllowedLanguage.IsDotNet(plugin.Language) && API is IRemovable removable)
|
||||
{
|
||||
var method = API.GetType().GetMethod("RemovePluginSettings");
|
||||
method?.Invoke(API, new object[] { plugin.AssemblyName });
|
||||
var method1 = API.GetType().GetMethod("RemovePluginCache");
|
||||
method1?.Invoke(API, new object[] { plugin.PluginCacheDirectoryPath });
|
||||
removable.RemovePluginSettings(plugin.AssemblyName);
|
||||
removable.RemovePluginCaches(plugin.PluginCacheDirectoryPath);
|
||||
}
|
||||
|
||||
try
|
||||
|
|
|
|||
19
Flow.Launcher.Core/Storage/IRemovable.cs
Normal file
19
Flow.Launcher.Core/Storage/IRemovable.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
namespace Flow.Launcher.Core.Storage;
|
||||
|
||||
/// <summary>
|
||||
/// Remove storage instances from <see cref="Launcher.Plugin.IPublicAPI"> instance
|
||||
/// </summary>
|
||||
public interface IRemovable
|
||||
{
|
||||
/// <summary>
|
||||
/// Remove all <see cref="Infrastructure.Storage.PluginJsonStorage{T}"> instances of one plugin
|
||||
/// </summary>
|
||||
/// <param name="assemblyName"></param>
|
||||
public void RemovePluginSettings(string assemblyName);
|
||||
|
||||
/// <summary>
|
||||
/// Remove all <see cref="Infrastructure.Storage.PluginBinaryStorage{T}"> instances of one plugin
|
||||
/// </summary>
|
||||
/// <param name="cacheDirectory"></param>
|
||||
public void RemovePluginCaches(string cacheDirectory);
|
||||
}
|
||||
|
|
@ -14,6 +14,8 @@ using CommunityToolkit.Mvvm.DependencyInjection;
|
|||
using Squirrel;
|
||||
using Flow.Launcher.Core;
|
||||
using Flow.Launcher.Core.Plugin;
|
||||
using Flow.Launcher.Core.Resource;
|
||||
using Flow.Launcher.Core.Storage;
|
||||
using Flow.Launcher.Helper;
|
||||
using Flow.Launcher.Infrastructure;
|
||||
using Flow.Launcher.Infrastructure.Http;
|
||||
|
|
@ -27,11 +29,10 @@ using Flow.Launcher.Plugin.SharedModels;
|
|||
using Flow.Launcher.Plugin.SharedCommands;
|
||||
using Flow.Launcher.ViewModel;
|
||||
using JetBrains.Annotations;
|
||||
using Flow.Launcher.Core.Resource;
|
||||
|
||||
namespace Flow.Launcher
|
||||
{
|
||||
public class PublicAPIInstance : IPublicAPI
|
||||
public class PublicAPIInstance : IPublicAPI, IRemovable
|
||||
{
|
||||
private readonly Settings _settings;
|
||||
private readonly Internationalization _translater;
|
||||
|
|
@ -348,7 +349,7 @@ namespace Flow.Launcher
|
|||
|
||||
private readonly ConcurrentDictionary<(string, string, Type), object> _pluginBinaryStorages = new();
|
||||
|
||||
public void RemovePluginCache(string cacheDirectory)
|
||||
public void RemovePluginCaches(string cacheDirectory)
|
||||
{
|
||||
foreach (var keyValuePair in _pluginBinaryStorages)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue