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

Add support for deleting plugin settings when uninstalling plugins #3219

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

Conversation

Jack251970
Copy link
Contributor

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

image

Copy link

gitstream-cm bot commented Feb 1, 2025

🥷 Code experts: jjw24, VictoriousRaptor

Jack251970, Yusyuriv have 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 Yusyuriv
FEB
JAN
DEC
NOV 1 additions & 1 deletions
OCT
SEP

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

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

Activity based on git-commit:

Jack251970 Yusyuriv
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 Yusyuriv
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 pull request introduces enhancements to the plugin management system in Flow Launcher, focusing on providing more granular control over plugin settings during uninstallation. The UninstallPlugin method has been updated to include two new parameters, removePluginFromSettings and removePluginSettings, allowing users to choose whether to retain plugin-specific settings when uninstalling. This modification is complemented by updates to the PluginsManager class and localization files in English, Simplified Chinese, and Traditional Chinese.

Changes

File Change Summary
Flow.Launcher.Core/Plugin/PluginManager.cs Updated UninstallPlugin method signature to include removePluginFromSettings and removePluginSettings parameters; modified UpdatePlugin method to pass these parameters.
Plugins/Flow.Launcher.Plugin.PluginsManager/Languages/en.xaml Added new localization strings for plugin settings retention prompt.
Plugins/Flow.Launcher.Plugin.PluginsManager/Languages/zh-cn.xaml Added new localization strings for plugin operations without restart.
Plugins/Flow.Launcher.Plugin.PluginsManager/Languages/zh-tw.xaml Added new localization strings for plugin operations without restart.
Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs Modified Uninstall method to include user prompt for keeping plugin settings.

Suggested labels

enhancement, Explorer Plugin

Suggested reviewers

  • jjw24

Poem

🐰 A rabbit's tale of plugin might,
Settings dance in soft delight,
Uninstall with care, choose your way,
Keep or clear, it's your display!
Flow Launcher's magic, clean and bright! 🔧

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

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.

@@ -454,9 +455,9 @@ public static void InstallPlugin(UserPlugin plugin, string zipFilePath)
/// <summary>
/// Uninstall a plugin.
/// </summary>
public static void UninstallPlugin(PluginMetadata plugin, bool removeSettings = true)
public static void UninstallPlugin(PluginMetadata plugin, bool removeSettings = true, bool removePluginSettings = false)
Copy link
Contributor

Choose a reason for hiding this comment

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

I kinda forget what is removeSettings for. Is it possible to use this arg rather than adding a new one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps not. This arg is for remove plugin in FL settings file (settings.json as I remember).

More details here:

if (removeSettings)
{
    Settings.Plugins.Remove(plugin.ID);
    AllPlugins.RemoveAll(p => p.Metadata.ID == plugin.ID);
}

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))
    {
        Directory.Delete(directoryPath, true);
    }
}

Copy link
Contributor

Choose a reason for hiding this comment

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

OK nvm. it just removes data in PluginManager rather than on disk. perhaps we can rename it to avoid confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well, np

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

Copy link

github-actions bot commented Feb 8, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants