Skip to content

Support deleting plugin settings when uninstalling plugins #3219

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

Merged
merged 10 commits into from
Feb 23, 2025
Merged
23 changes: 18 additions & 5 deletions Flow.Launcher.Core/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Flow.Launcher.Plugin.SharedCommands;
using System.Text.Json;
using Flow.Launcher.Core.Resource;
using Flow.Launcher.Infrastructure.Storage;

namespace Flow.Launcher.Core.Plugin
{
Expand Down Expand Up @@ -439,7 +440,7 @@ public static bool PluginModified(string uuid)
public static void UpdatePlugin(PluginMetadata existingVersion, UserPlugin newVersion, string zipFilePath)
{
InstallPlugin(newVersion, zipFilePath, checkModified:false);
UninstallPlugin(existingVersion, removeSettings:false, checkModified:false);
UninstallPlugin(existingVersion, removePluginFromSettings:false, removePluginSettings:false, checkModified: false);
_modifiedPlugins.Add(existingVersion.ID);
}

Expand All @@ -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 removePluginFromSettings = true, bool removePluginSettings = false)
{
UninstallPlugin(plugin, removeSettings, true);
UninstallPlugin(plugin, removePluginFromSettings, removePluginSettings, true);
}

#endregion
Expand Down Expand Up @@ -529,19 +530,31 @@ internal static void InstallPlugin(UserPlugin plugin, string zipFilePath, bool c
}
}

internal static void UninstallPlugin(PluginMetadata plugin, bool removeSettings, bool checkModified)
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 (removeSettings)
if (removePluginFromSettings)
{
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);
}
}

// Marked for deletion. Will be deleted on next start up
using var _ = File.CreateText(Path.Combine(plugin.PluginDirectory, "NeedDelete.txt"));

Expand Down
6 changes: 4 additions & 2 deletions Plugins/Flow.Launcher.Plugin.PluginsManager/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<system:String x:Key="plugin_pluginsmanager_installing_plugin">Installing Plugin</system:String>
<system:String x:Key="plugin_pluginsmanager_install_from_web">Download and install {0}</system:String>
<system:String x:Key="plugin_pluginsmanager_uninstall_title">Plugin Uninstall</system:String>
<system:String x:Key="plugin_pluginsmanager_keep_plugin_settings_title">Keep plugin settings</system:String>
<system:String x:Key="plugin_pluginsmanager_keep_plugin_settings_subtitle">Do you want to keep the settings of the plugin for the next usage?</system:String>
<system:String x:Key="plugin_pluginsmanager_install_success_restart">Plugin {0} successfully installed. Restarting Flow, please wait...</system:String>
<system:String x:Key="plugin_pluginsmanager_install_errormetadatafile">Unable to find the plugin.json metadata file from the extracted zip file.</system:String>
<system:String x:Key="plugin_pluginsmanager_install_error_duplicate">Error: A plugin which has the same or greater version with {0} already exists.</system:String>
Expand All @@ -37,13 +39,13 @@
<system:String x:Key="plugin_pluginsmanager_update_success_restart">Plugin {0} successfully updated. Restarting Flow, please wait...</system:String>
<system:String x:Key="plugin_pluginsmanager_install_unknown_source_warning_title">Installing from an unknown source</system:String>
<system:String x:Key="plugin_pluginsmanager_install_unknown_source_warning">You are installing this plugin from an unknown source and it may contain potential risks!{0}{0}Please ensure you understand where this plugin is from and that it is safe.{0}{0}Would you like to continue still?{0}{0}(You can switch off this warning via settings)</system:String>

<system:String x:Key="plugin_pluginsmanager_install_success_no_restart">Plugin {0} successfully installed. Please restart Flow.</system:String>
<system:String x:Key="plugin_pluginsmanager_uninstall_success_no_restart">Plugin {0} successfully uninstalled. Please restart Flow.</system:String>
<system:String x:Key="plugin_pluginsmanager_update_success_no_restart">Plugin {0} successfully updated. Please restart Flow.</system:String>
<system:String x:Key="plugin_pluginsmanager_update_all_success_no_restart">{0} plugins successfully updated. Please restart Flow.</system:String>
<system:String x:Key="plugin_pluginsmanager_plugin_modified_error">Plugin {0} has already been modified. Please restart Flow before making any further changes.</system:String>

<!-- Plugin Infos -->
<system:String x:Key="plugin_pluginsmanager_plugin_name">Plugins Manager</system:String>
<system:String x:Key="plugin_pluginsmanager_plugin_description">Management of installing, uninstalling or updating Flow Launcher plugins</system:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
<system:String x:Key="plugin_pluginsmanager_update_success_restart">插件{0}更新成功。正在重新启动 Flow Launcher,请稍候...</system:String>
<system:String x:Key="plugin_pluginsmanager_install_unknown_source_warning_title">从未知源安装</system:String>
<system:String x:Key="plugin_pluginsmanager_install_unknown_source_warning">您正在从未知源安装此插件,它可能包含潜在风险!{0}{0}请确保您了解来源以及安全性。{0}{0}您想要继续吗?{0}{0}(您可以通过设置关闭此警告)</system:String>

<system:String x:Key="plugin_pluginsmanager_install_success_no_restart">成功安装插件{0}。请重新启动 Flow Launcher。</system:String>
<system:String x:Key="plugin_pluginsmanager_uninstall_success_no_restart">成功卸载插件{0}。请重新启动 Flow Launcher。</system:String>
<system:String x:Key="plugin_pluginsmanager_update_success_no_restart">成功更新插件{0}。请重新启动 Flow Launcher。</system:String>
<system:String x:Key="plugin_pluginsmanager_update_all_success_no_restart">插件 {0} 更新成功。请重新启动 Flow Launcher。</system:String>
<system:String x:Key="plugin_pluginsmanager_plugin_modified_error">插件 {0} 已被修改。请在进行任何进一步更改之前重新启动Flow。</system:String>

<!-- Plugin Infos -->
<system:String x:Key="plugin_pluginsmanager_plugin_name">插件管理</system:String>
<system:String x:Key="plugin_pluginsmanager_plugin_description">安装,卸载或更新 Flow Launcher 插件</system:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
<system:String x:Key="plugin_pluginsmanager_update_success_restart">Plugin {0} successfully updated. Restarting Flow, please wait...</system:String>
<system:String x:Key="plugin_pluginsmanager_install_unknown_source_warning_title">Installing from an unknown source</system:String>
<system:String x:Key="plugin_pluginsmanager_install_unknown_source_warning">You are installing this plugin from an unknown source and it may contain potential risks!{0}{0}Please ensure you understand where this plugin is from and that it is safe.{0}{0}Would you like to continue still?{0}{0}(You can switch off this warning via settings)</system:String>

<system:String x:Key="plugin_pluginsmanager_install_success_no_restart">Plugin {0} successfully installed. Please restart Flow.</system:String>
<system:String x:Key="plugin_pluginsmanager_uninstall_success_no_restart">Plugin {0} successfully uninstalled. Please restart Flow.</system:String>
<system:String x:Key="plugin_pluginsmanager_update_success_no_restart">Plugin {0} successfully updated. Please restart Flow.</system:String>
<system:String x:Key="plugin_pluginsmanager_update_all_success_no_restart">{0} plugins successfully updated. Please restart Flow.</system:String>
<system:String x:Key="plugin_pluginsmanager_plugin_modified_error">Plugin {0} has already been modified. Please restart Flow before making any further changes.</system:String>

<!-- Plugin Infos -->
<system:String x:Key="plugin_pluginsmanager_plugin_name">擴充功能管理</system:String>
<system:String x:Key="plugin_pluginsmanager_plugin_description">Management of installing, uninstalling or updating Flow Launcher plugins</system:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,11 @@ private void Uninstall(PluginMetadata plugin)
{
try
{
PluginManager.UninstallPlugin(plugin, removeSettings: true);
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, removePluginFromSettings: true, removePluginSettings: removePluginSettings);
}
catch (ArgumentException e)
{
Expand Down
Loading