diff --git a/src/cthulhu/plugin_system_manager.py b/src/cthulhu/plugin_system_manager.py index 0516e3b..31d74c7 100644 --- a/src/cthulhu/plugin_system_manager.py +++ b/src/cthulhu/plugin_system_manager.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 + #!/usr/bin/env python3 # # Copyright (c) 2024 Stormux # Copyright (c) 2010-2012 The Orca Team @@ -489,7 +489,7 @@ class PluginSystemManager: """ return pluginInfo.is_builtin() -def isPluginHidden(self, pluginInfo): + def isPluginHidden(self, pluginInfo): """Check if a plugin is hidden. Args: @@ -555,7 +555,7 @@ def isPluginHidden(self, pluginInfo): """ return pluginInfo.get_description() - def getPlugingetHelpUri(self, pluginInfo): + def getPluginHelpUri(self, pluginInfo): """Get the plugin help URI. Args: @@ -997,6 +997,40 @@ def isPluginHidden(self, pluginInfo): return pluginFileExists + def uninstallPlugin(self, pluginInfo): + """Uninstall a plugin. + + Args: + pluginInfo: The plugin information. + + Returns: + True if the plugin was uninstalled successfully, False otherwise. + """ + if self.isPluginBuildIn(pluginInfo): + return False + + # Do we want to allow removing system plugins? + if self.getPluginType(pluginInfo) == PluginType.SYSTEM: + return False + + pluginFolder = pluginInfo.get_data_dir() + if not pluginFolder.endswith('/'): + pluginFolder += '/' + + if not os.path.isdir(pluginFolder): + return False + + if self.isPluginActive(pluginInfo): + self.setPluginActive(pluginInfo, False) + # TODO: Update active plugins in settings + + self.callPackageTriggers(pluginFolder, 'onPreUninstall') + + try: + shutil.rmtree(pluginFolder, ignore_errors=True) + except Exception as e: + print(e) + def uninstallPlugin(self, pluginInfo): """Uninstall a plugin.