Skip to content

Commit 126153b

Browse files
committed
Improve plugin settings directory clean & Support plugin cache directory clean
1 parent 3efe550 commit 126153b

File tree

3 files changed

+28
-38
lines changed

3 files changed

+28
-38
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -546,50 +546,41 @@ internal static void UninstallPlugin(PluginMetadata plugin, bool removePluginFro
546546

547547
if (removePluginSettings)
548548
{
549-
if (AllowedLanguage.IsDotNet(plugin.Language)) // for the plugin in .NET, we can use assembly loader
549+
// For dotnet plugins, we need to remove their PluginJsonStorage instance
550+
if (AllowedLanguage.IsDotNet(plugin.Language))
550551
{
551-
// if user want to remove the plugin settings, we cannot call save method for the plugin json storage instance of this plugin
552-
// so we need to remove it from the api instance
553552
var method = API.GetType().GetMethod("RemovePluginSettings");
554-
var pluginJsonStorage = method?.Invoke(API, new object[] { plugin.AssemblyName });
553+
method?.Invoke(API, new object[] { plugin.AssemblyName });
554+
}
555555

556-
// if there exists a json storage for current plugin, we need to delete the directory path
557-
if (pluginJsonStorage != null)
558-
{
559-
var deleteMethod = pluginJsonStorage.GetType().GetMethod("DeleteDirectory");
560-
try
561-
{
562-
deleteMethod?.Invoke(pluginJsonStorage, null);
563-
}
564-
catch (Exception e)
565-
{
566-
Log.Exception($"|PluginManager.UninstallPlugin|Failed to delete plugin json folder for {plugin.Name}", e);
567-
API.ShowMsg(API.GetTranslation("failedToRemovePluginSettingsTitle"),
568-
string.Format(API.GetTranslation("failedToRemovePluginSettingsMessage"), plugin.Name));
569-
}
570-
}
556+
try
557+
{
558+
var pluginSettingsDirectory = plugin.PluginSettingsDirectoryPath;
559+
if (Directory.Exists(pluginSettingsDirectory))
560+
Directory.Delete(pluginSettingsDirectory, true);
571561
}
572-
else // the plugin with json prc interface
562+
catch (Exception e)
573563
{
574-
var pluginPair = AllPlugins.FirstOrDefault(p => p.Metadata.ID == plugin.ID);
575-
if (pluginPair != null && pluginPair.Plugin is JsonRPCPlugin jsonRpcPlugin)
576-
{
577-
try
578-
{
579-
jsonRpcPlugin.DeletePluginSettingsDirectory();
580-
}
581-
catch (Exception e)
582-
{
583-
Log.Exception($"|PluginManager.UninstallPlugin|Failed to delete plugin json folder for {plugin.Name}", e);
584-
API.ShowMsg(API.GetTranslation("failedToRemovePluginSettingsTitle"),
585-
string.Format(API.GetTranslation("failedToRemovePluginSettingsMessage"), plugin.Name));
586-
}
587-
}
564+
Log.Exception($"|PluginManager.UninstallPlugin|Failed to delete plugin settings folder for {plugin.Name}", e);
565+
API.ShowMsg(API.GetTranslation("failedToRemovePluginSettingsTitle"),
566+
string.Format(API.GetTranslation("failedToRemovePluginSettingsMessage"), plugin.Name));
588567
}
589568
}
590569

591570
if (removePluginFromSettings)
592571
{
572+
try
573+
{
574+
var pluginCacheDirectory = plugin.PluginCacheDirectoryPath;
575+
if (Directory.Exists(pluginCacheDirectory))
576+
Directory.Delete(pluginCacheDirectory, true);
577+
}
578+
catch (Exception e)
579+
{
580+
Log.Exception($"|PluginManager.UninstallPlugin|Failed to delete plugin cache folder for {plugin.Name}", e);
581+
API.ShowMsg(API.GetTranslation("failedToRemovePluginCacheTitle"),
582+
string.Format(API.GetTranslation("failedToRemovePluginCacheMessage"), plugin.Name));
583+
}
593584
Settings.Plugins.Remove(plugin.ID);
594585
AllPlugins.RemoveAll(p => p.Metadata.ID == plugin.ID);
595586
}

Flow.Launcher/Languages/en.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@
131131
<system:String x:Key="plugin_uninstall">Uninstall</system:String>
132132
<system:String x:Key="failedToRemovePluginSettingsTitle">Fail to remove plugin settings</system:String>
133133
<system:String x:Key="failedToRemovePluginSettingsMessage">Plugins: {0} - Fail to remove plugin settings files, please remove them manually</system:String>
134+
<system:String x:Key="failedToRemovePluginCacheTitle">Fail to remove plugin cache</system:String>
135+
<system:String x:Key="failedToRemovePluginCacheMessage">Plugins: {0} - Fail to remove plugin cache files, please remove them manually</system:String>
134136

135137
<!-- Setting Plugin Store -->
136138
<system:String x:Key="pluginStore">Plugin Store</system:String>

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public void LogException(string className, string message, Exception e,
189189

190190
private readonly ConcurrentDictionary<Type, object> _pluginJsonStorages = new();
191191

192-
public object RemovePluginSettings(string assemblyName)
192+
public void RemovePluginSettings(string assemblyName)
193193
{
194194
foreach (var keyValuePair in _pluginJsonStorages)
195195
{
@@ -199,11 +199,8 @@ public object RemovePluginSettings(string assemblyName)
199199
if (name == assemblyName)
200200
{
201201
_pluginJsonStorages.Remove(key, out var pluginJsonStorage);
202-
return pluginJsonStorage;
203202
}
204203
}
205-
206-
return null;
207204
}
208205

209206
/// <summary>

0 commit comments

Comments
 (0)