Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support deleting plugin settings when uninstalling plugins #3219

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

Jack251970
Copy link
Contributor

@Jack251970 Jack251970 commented Feb 1, 2025

Allow user to delete plugin settings (under %APPDATA%\FlowLauncher\Settings\Plugins{Plugin_AssemblyName}) when uninstalling plugins.

image

Test

  • MessageBoxEx behaviour when deleting plugin: Every time you uninstall the plugin, it will create one dialog for that.

  • Delete settings behaviour for dotnet (I guess C# and F# should be the same, so I just test for C#), python, nodejs plugins: When uninstalling all types of plugins, if you don not let FL keep the plugin settings, the plugin settings files will be deleted.

Copy link

gitstream-cm bot commented Feb 1, 2025

🥷 Code experts: jjw24

Jack251970 has most 👩‍💻 activity in the files.
jjw24, VictoriousRaptor have most 🧠 knowledge in the files.

See details

Flow.Launcher.Core/Plugin/PluginManager.cs

Activity based on git-commit:

Jack251970
FEB
JAN
DEC
NOV 1 additions & 1 deletions
OCT
SEP

Knowledge based on git-blame:
VictoriousRaptor: 27%
jjw24: 4%

Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs

Activity based on git-commit:

Jack251970
FEB
JAN
DEC
NOV
OCT
SEP

Knowledge based on git-blame:
jjw24: 28%

Flow.Launcher/PublicAPIInstance.cs

Activity based on git-commit:

Jack251970
FEB
JAN 18 additions & 21 deletions
DEC 25 additions & 32 deletions
NOV 16 additions & 0 deletions
OCT
SEP

Knowledge based on git-blame:
jjw24: 9%
VictoriousRaptor: 1%

Plugins/Flow.Launcher.Plugin.PluginsManager/Languages/en.xaml

Activity based on git-commit:

Jack251970
FEB
JAN
DEC
NOV
OCT
SEP

Knowledge based on git-blame:
jjw24: 35%
VictoriousRaptor: 23%

Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs

Activity based on git-commit:

Jack251970
FEB
JAN
DEC
NOV 28 additions & 28 deletions
OCT
SEP

Knowledge based on git-blame:
jjw24: 16%
VictoriousRaptor: 11%

To learn more about /:\ gitStream - Visit our Docs

This comment has been minimized.

Copy link
Contributor

coderabbitai bot commented Feb 1, 2025

📝 Walkthrough

Walkthrough

The changes update the plugin management system by enhancing the uninstallation and update logic. The PluginManager now uses two additional parameters in its UninstallPlugin method to separately control removal from settings and deletion of the plugin settings directory. Meanwhile, the PluginsManager class now prompts users regarding retaining settings using two new UI strings. Additionally, the PluginJsonStorage class is improved with a new AssemblyName field and directory deletion support, and a new PublicAPIInstance method removes plugin settings based on assembly name.

Changes

File(s) Change Summary
Flow.Launcher.Core/Plugin/PluginManager.cs
Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs
Plugins/Flow.Launcher.Plugin.PluginsManager/Languages/en.xaml
Updated UninstallPlugin method signature and logic to accept separate flags for removing from settings and deleting plugin settings; Uninstall method in PluginsManager now prompts user with new UI text resources from en.xaml and passes the new parameters accordingly.
Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs Added a public readonly AssemblyName field and a new DeleteDirectory method; updated directory path construction to use AssemblyName for accuracy.
Flow.Launcher/PublicAPIInstance.cs Introduced a new RemovePluginSettings method that iterates through plugin storages, removes the matching entry by assembly name, and returns the removed value or null.
Flow.Launcher.Core/Plugin/JsonRPCPluginBase.cs Added a new method DeletePluginSettingsDirectory for managing settings directory cleanup; refactored SettingPath to derive from a new SettingDirectory property.

Suggested labels

enhancement, Explorer Plugin

Suggested reviewers

  • jjw24
  • taooceros

Poem

I’m a hopping rabbit, quick and bright,
Coding through plugins in the soft moonlight.
With prompts that ask if settings should stay,
And clean-up functions that clear the way.
My whiskers twitch at changes so neat –
Celebrating code with a joyful beat! 🐇
Hoppin’ on, the changes feel just right!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
Flow.Launcher.Core/Plugin/PluginManager.cs (1)

546-556: Consider adding error handling for directory operations.

The directory deletion operation could fail due to various reasons (e.g., file locks, permissions). Consider adding try-catch blocks to handle potential exceptions gracefully.

 if (removePluginSettings)
 {
     var assemblyLoader = new PluginAssemblyLoader(plugin.ExecuteFilePath);
     var assembly = assemblyLoader.LoadAssemblyAndDependencies();
     var assemblyName = assembly.GetName().Name;
     var directoryPath = Path.Combine(DataLocation.DataDirectory(), JsonStorage<object>.DirectoryName, Constant.Plugins, assemblyName);
     if (Directory.Exists(directoryPath))
     {
+        try
+        {
             Directory.Delete(directoryPath, true);
+        }
+        catch (Exception ex)
+        {
+            Log.Exception(nameof(PluginManager), $"Failed to delete plugin settings directory for {plugin.Name}", ex);
+        }
     }
 }
Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs (1)

685-689: LGTM! Consider adding documentation to clarify parameters.

The implementation looks good and aligns with the PR objectives. The user prompt is clear and consistent with the codebase's style.

Consider adding a comment to explain the difference between removeSettings and removePluginSettings parameters:

 private void Uninstall(PluginMetadata plugin)
 {
     try
     {
+        // removeSettings: Remove plugin's system settings
+        // removePluginSettings: Remove plugin's user settings from %APPDATA%\FlowLauncher\Settings\Plugins\{Plugin_AssemblyName}
         var removePluginSettings = Context.API.ShowMsgBox(
             Context.API.GetTranslation("plugin_pluginsmanager_keep_plugin_settings_subtitle"),
             Context.API.GetTranslation("plugin_pluginsmanager_keep_plugin_settings_title"),
             button: MessageBoxButton.YesNo) == MessageBoxResult.No;
         PluginManager.UninstallPlugin(plugin, removeSettings: true, removePluginSettings: removePluginSettings);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6cf7674 and e320ca1.

📒 Files selected for processing (5)
  • Flow.Launcher.Core/Plugin/PluginManager.cs (5 hunks)
  • Plugins/Flow.Launcher.Plugin.PluginsManager/Languages/en.xaml (2 hunks)
  • Plugins/Flow.Launcher.Plugin.PluginsManager/Languages/zh-cn.xaml (2 hunks)
  • Plugins/Flow.Launcher.Plugin.PluginsManager/Languages/zh-tw.xaml (2 hunks)
  • Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: gitStream.cm
🔇 Additional comments (5)
Flow.Launcher.Core/Plugin/PluginManager.cs (2)

458-460: LGTM! Method signature updated to support plugin settings deletion.

The new removePluginSettings parameter with a default value of false maintains backward compatibility while adding support for plugin settings deletion.


443-443: LGTM! UpdatePlugin method updated to maintain settings.

The UpdatePlugin method correctly passes false for both removeSettings and removePluginSettings to preserve settings during updates.

Plugins/Flow.Launcher.Plugin.PluginsManager/Languages/en.xaml (1)

18-19: LGTM! Clear and consistent English localization strings.

The strings are well-written and clearly communicate the purpose to users.

Plugins/Flow.Launcher.Plugin.PluginsManager/Languages/zh-cn.xaml (1)

16-17: LGTM! Clear and consistent Simplified Chinese localization strings.

The translations maintain the same meaning as the English strings while being natural in Chinese.

Plugins/Flow.Launcher.Plugin.PluginsManager/Languages/zh-tw.xaml (1)

16-17: LGTM! Clear and consistent Traditional Chinese localization strings.

The translations are accurate and maintain consistency with other language versions.

@jjw24
Copy link
Member

jjw24 commented Feb 4, 2025

Hey @Jack251970, are you in flow's Discord?

@Jack251970
Copy link
Contributor Author

Hey @Jack251970, are you in flow's Discord?

Yes?

@jjw24
Copy link
Member

jjw24 commented Feb 4, 2025

Can you message me in Discord - jjw24

@Jack251970
Copy link
Contributor Author

Can you message me in Discord - jjw24

Already sent.

Copy link
Member

@jjw24 jjw24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the behaviour like when I choose that option in PluginsManagee to not restart automatically and uninstall multiple plugins? Will I get many prompts?

@@ -13,6 +13,8 @@
<system:String x:Key="plugin_pluginsmanager_installing_plugin">Installing Plugin</system:String>
<system:String x:Key="plugin_pluginsmanager_install_from_web">下載並安裝 {0}</system:String>
<system:String x:Key="plugin_pluginsmanager_uninstall_title">解除安裝擴充功能</system:String>
<system:String x:Key="plugin_pluginsmanager_keep_plugin_settings_title">保留插件設置</system:String>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, language files other than English need to be added by Crowdin. This may exist until next Crowdin PR update, which will revert this to English or new translation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean, I need to revert all changes in non-English languages files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or I need to add the strings as the same string as English to other non-English files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seem that the former is the right choice🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have used the former way as I check the previous commits.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@Jack251970
Copy link
Contributor Author

What's the behaviour like when I choose that option in PluginsManagee to not restart automatically and uninstall multiple plugins? Will I get many prompts?

@jjw24 private void Uninstall(PluginMetadata plugin) is called regardless of whether FL should restart automatically, so the actions remains the same.

And every time you uninstall one plugin, you will get one prompts for this. So uninstall multiple plugins will get many prompts.

This comment has been minimized.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs (2)

685-689: LGTM! The implementation aligns well with the PR objectives.

The changes effectively implement the feature to optionally delete plugin settings during uninstallation:

  1. Clear user prompt asking whether to keep plugin settings
  2. Proper handling of the user's choice when calling UninstallPlugin

However, consider the following enhancement:

The message box text could be more explicit about the consequences of the choice. Here's a suggested improvement:

-                    Context.API.GetTranslation("plugin_pluginsmanager_keep_plugin_settings_subtitle"),
+                    Context.API.GetTranslation("plugin_pluginsmanager_keep_plugin_settings_subtitle") + 
+                    Environment.NewLine + 
+                    Context.API.GetTranslation("These settings will be permanently deleted if you choose No."),

681-697: Consider enhancing the bulk uninstallation experience.

When uninstalling multiple plugins without auto-restart, users will see multiple prompts (one for settings and one for confirmation per plugin). Consider adding a bulk operation option that allows users to apply the same settings choice to all plugins being uninstalled.

Here's a suggested approach:

         private void Uninstall(PluginMetadata plugin)
         {
+            // Use a static field to remember the user's choice during bulk operations
+            private static bool? _bulkUninstallKeepSettings = null;
             try
             {
-                var removePluginSettings = Context.API.ShowMsgBox(
-                    Context.API.GetTranslation("plugin_pluginsmanager_keep_plugin_settings_subtitle"),
-                    Context.API.GetTranslation("plugin_pluginsmanager_keep_plugin_settings_title"),
-                    button: MessageBoxButton.YesNo) == MessageBoxResult.No;
+                var removePluginSettings = true;
+                if (_bulkUninstallKeepSettings == null)
+                {
+                    var result = Context.API.ShowMsgBox(
+                        Context.API.GetTranslation("plugin_pluginsmanager_keep_plugin_settings_subtitle") +
+                        Environment.NewLine +
+                        "Apply this choice to all plugins being uninstalled?",
+                        Context.API.GetTranslation("plugin_pluginsmanager_keep_plugin_settings_title"),
+                        button: MessageBoxButton.YesNoCancel);
+                    
+                    if (result == MessageBoxResult.Cancel)
+                        return;
+                        
+                    removePluginSettings = result == MessageBoxResult.No;
+                    _bulkUninstallKeepSettings = removePluginSettings;
+                }
+                else
+                {
+                    removePluginSettings = _bulkUninstallKeepSettings.Value;
+                }
                 PluginManager.UninstallPlugin(plugin, removePluginFromSettings: true, removePluginSettings: removePluginSettings);
             }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7598a6a and 1f1b319.

📒 Files selected for processing (2)
  • Flow.Launcher.Core/Plugin/PluginManager.cs (4 hunks)
  • Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Flow.Launcher.Core/Plugin/PluginManager.cs
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm

This comment has been minimized.

@Jack251970 Jack251970 requested a review from jjw24 February 8, 2025 10:00

This comment has been minimized.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1f1b319 and f0e74a2.

📒 Files selected for processing (3)
  • Flow.Launcher.Core/Plugin/PluginManager.cs (3 hunks)
  • Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs (2 hunks)
  • Flow.Launcher/PublicAPIInstance.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Flow.Launcher.Core/Plugin/PluginManager.cs
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
🔇 Additional comments (2)
Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs (1)

8-9: LGTM! Good use of readonly field.

The AssemblyName field is correctly marked as readonly to prevent modifications after initialization.

Flow.Launcher/PublicAPIInstance.cs (1)

192-207: Verify the impact on plugin settings removal.

The implementation removes plugin settings from memory but doesn't delete the settings directory. Consider calling DeleteDirectory after removing the settings.

Run this script to check if any plugin settings directories remain after uninstallation:

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Description: Check for orphaned plugin settings directories.

# Search for references to plugin settings deletion
rg -A 5 "RemovePluginSettings|DeleteDirectory"

# Search for plugin uninstallation code
ast-grep --pattern $'UninstallPlugin($$$) {
  $$$
}'

Length of output: 2213


Plugin settings directory deletion is correctly chained.

The RemovePluginSettings method only removes the in‑memory plugin settings. The PluginManager in Flow.Launcher.Core/Plugin/PluginManager.cs subsequently retrieves the returned plugin storage object and, if not null, calls its DeleteDirectory method (defined in Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs) to delete the settings directory.

  • Flow.Launcher/PublicAPIInstance.cs: RemovePluginSettings only removes the in‑memory entry.
  • Flow.Launcher.Core/Plugin/PluginManager.cs: After invoking RemovePluginSettings, it calls DeleteDirectory on the plugin storage if one exists.
  • Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs: DeleteDirectory deletes the settings directory.

No changes are needed as the chain of deletion is already implemented.

This comment has been minimized.

Copy link

github-actions bot commented Feb 9, 2025

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors Count
❌ forbidden-pattern 22
⚠️ ignored-expect-variant 1
⚠️ non-alpha-in-dictionary 19

See ❌ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
Flow.Launcher.Core/Plugin/JsonRPCPluginBase.cs (1)

165-171: Consider adding error handling for directory deletion.

While the directory existence check is good, the deletion operation could fail due to file locks or permissions.

Apply this diff to add error handling:

 public void DeletePluginSettingsDirectory()
 {
     if (Directory.Exists(SettingDirectory))
     {
-        Directory.Delete(SettingDirectory, true);
+        try
+        {
+            Directory.Delete(SettingDirectory, true);
+        }
+        catch (Exception e)
+        {
+            Log.Exception($"|JsonRPCPluginBase.DeletePluginSettingsDirectory|Failed to delete settings directory for {Context.CurrentPluginMetadata.Name}", e);
+        }
     }
 }
Flow.Launcher.Core/Plugin/PluginManager.cs (1)

547-589: Consider extracting plugin settings removal logic into separate methods.

The plugin settings removal logic is quite complex and could benefit from being split into separate methods for .NET and JSON RPC plugins.

Apply this diff to improve code organization:

+private static void RemoveDotNetPluginSettings(PluginMetadata plugin)
+{
+    var assemblyLoader = new PluginAssemblyLoader(plugin.ExecuteFilePath);
+    var assembly = assemblyLoader.LoadAssemblyAndDependencies();
+    var assemblyName = assembly.GetName().Name;
+
+    // if user want to remove the plugin settings, we cannot call save method for the plugin json storage instance of this plugin
+    // so we need to remove it from the api instance
+    var method = API.GetType().GetMethod("RemovePluginSettings");
+    var pluginJsonStorage = method?.Invoke(API, new object[] { assemblyName });
+
+    // if there exists a json storage for current plugin, we need to delete the directory path
+    if (pluginJsonStorage != null)
+    {
+        var deleteMethod = pluginJsonStorage.GetType().GetMethod("DeleteDirectory");
+        try
+        {
+            deleteMethod?.Invoke(pluginJsonStorage, null);
+        }
+        catch (Exception e)
+        {
+            Log.Exception($"|PluginManager.UninstallPlugin|Failed to delete plugin json folder for {plugin.Name}", e);
+        }
+    }
+}
+
+private static void RemoveJsonRpcPluginSettings(PluginMetadata plugin)
+{
+    var pluginPair = AllPlugins.FirstOrDefault(p => p.Metadata.ID == plugin.ID);
+    if (pluginPair != null && pluginPair.Plugin is JsonRPCPlugin jsonRpcPlugin)
+    {
+        try
+        {
+            jsonRpcPlugin.DeletePluginSettingsDirectory();
+        }
+        catch (Exception e)
+        {
+            Log.Exception($"|PluginManager.UninstallPlugin|Failed to delete plugin json folder for {plugin.Name}", e);
+        }
+    }
+}
+
 internal static void UninstallPlugin(PluginMetadata plugin, bool removePluginFromSettings, bool removePluginSettings, bool checkModified)
 {
     if (checkModified && PluginModified(plugin.ID))
     {
         throw new ArgumentException($"Plugin {plugin.Name} has been modified");
     }
 
     if (removePluginSettings)
     {
-        if (AllowedLanguage.IsDotNet(plugin.Language))  // for the plugin in .NET, we can use assembly loader
-        {
-            var assemblyLoader = new PluginAssemblyLoader(plugin.ExecuteFilePath);
-            var assembly = assemblyLoader.LoadAssemblyAndDependencies();
-            var assemblyName = assembly.GetName().Name;
-
-            // if user want to remove the plugin settings, we cannot call save method for the plugin json storage instance of this plugin
-            // so we need to remove it from the api instance
-            var method = API.GetType().GetMethod("RemovePluginSettings");
-            var pluginJsonStorage = method?.Invoke(API, new object[] { assemblyName });
-
-            // if there exists a json storage for current plugin, we need to delete the directory path
-            if (pluginJsonStorage != null)
-            {
-                var deleteMethod = pluginJsonStorage.GetType().GetMethod("DeleteDirectory");
-                try
-                {
-                    deleteMethod?.Invoke(pluginJsonStorage, null);
-                }
-                catch (Exception e)
-                {
-                    Log.Exception($"|PluginManager.UninstallPlugin|Failed to delete plugin json folder for {plugin.Name}", e);
-                }
-            }
-        }
-        else  // the plugin with json prc interface
-        {
-            var pluginPair = AllPlugins.FirstOrDefault(p => p.Metadata.ID == plugin.ID);
-            if (pluginPair != null && pluginPair.Plugin is JsonRPCPlugin jsonRpcPlugin)
-            {
-                try
-                {
-                    jsonRpcPlugin.DeletePluginSettingsDirectory();
-                }
-                catch (Exception e)
-                {
-                    Log.Exception($"|PluginManager.UninstallPlugin|Failed to delete plugin json folder for {plugin.Name}", e);
-                }
-            }
-        }
+        if (AllowedLanguage.IsDotNet(plugin.Language))
+            RemoveDotNetPluginSettings(plugin);
+        else
+            RemoveJsonRpcPluginSettings(plugin);
     }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 37837e7 and 54a0f3d.

📒 Files selected for processing (2)
  • Flow.Launcher.Core/Plugin/JsonRPCPluginBase.cs (2 hunks)
  • Flow.Launcher.Core/Plugin/PluginManager.cs (3 hunks)
🔇 Additional comments (6)
Flow.Launcher.Core/Plugin/JsonRPCPluginBase.cs (2)

47-48: LGTM!

The SettingDirectory property correctly combines the plugin settings directory path with the plugin name.


50-50: LGTM!

Good refactoring to reuse the SettingDirectory property for constructing the settings file path.

Flow.Launcher.Core/Plugin/PluginManager.cs (4)

442-442: LGTM!

The method call correctly uses the new parameters, ensuring plugin settings are preserved during updates.


457-459: LGTM!

The parameter renaming improves clarity by distinguishing between removing the plugin from settings and removing the plugin's settings directory.


524-532: LGTM!

Good addition of error handling for temp folder deletion with proper logging.


591-595: LGTM!

The plugin removal logic is correctly guarded by the removePluginFromSettings parameter.

@Jack251970 Jack251970 changed the title Add support for deleting plugin settings when uninstalling plugins Support deleting plugin settings when uninstalling plugins Feb 9, 2025
@Jack251970 Jack251970 added the enhancement New feature or request label Feb 9, 2025
@Jack251970
Copy link
Contributor Author

Jack251970 commented Feb 19, 2025

@taooceros Regarding the reflection issue you mentioned, I’m planning to improve the FL plugin settings path mangement in the future. And these reflection codes will be removed.

@taooceros
Copy link
Member

@taooceros Regarding the reflection issue you mentioned, I’m planning to improve the FL plugin settings in the future. And these reflection codes will be removed.

I see. This seems pretty ambitious. Looking forward to it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 min review enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants