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
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 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, removeSettings: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 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

{
UninstallPlugin(plugin, removeSettings, true);
UninstallPlugin(plugin, removeSettings, removePluginSettings, true);
}

#endregion
Expand Down Expand Up @@ -529,7 +530,7 @@ 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 removeSettings, bool removePluginSettings, bool checkModified)
{
if (checkModified && PluginModified(plugin.ID))
{
Expand All @@ -542,6 +543,18 @@ internal static void UninstallPlugin(PluginMetadata plugin, bool removeSettings,
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 @@ -13,6 +13,8 @@
<system:String x:Key="plugin_pluginsmanager_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>
<system:String x:Key="plugin_pluginsmanager_keep_plugin_settings_subtitle">你希望保留插件设置以便于下次使用吗?</system:String>
<system:String x:Key="plugin_pluginsmanager_install_success_restart">插件安装成功。正在重新启动 Flow Launcher,请稍候...</system:String>
<system:String x:Key="plugin_pluginsmanager_install_errormetadatafile">安装失败:无法从新插件中找到plugin.json元数据文件</system:String>
<system:String x:Key="plugin_pluginsmanager_install_error_duplicate">错误:具有相同或更高版本的 {0} 的插件已经存在。</system:String>
Expand All @@ -35,13 +37,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 @@ -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.

<system:String x:Key="plugin_pluginsmanager_keep_plugin_settings_subtitle">你希望保留插件設置以便於下次使用嗎?</system:String>
<system:String x:Key="plugin_pluginsmanager_install_success_restart">外掛安裝成功。正在重啟 Flow,請稍後...</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 @@ -35,13 +37,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, removeSettings: true, removePluginSettings: removePluginSettings);
}
catch (ArgumentException e)
{
Expand Down
Loading