|
46 | 46 | from qgis.core import Qgis, QgsApplication, QgsNetworkAccessManager, QgsSettings, QgsNetworkRequestParameters
|
47 | 47 | from qgis.gui import QgsMessageBar, QgsPasswordLineEdit, QgsHelp
|
48 | 48 | from qgis.utils import (iface, startPlugin, unloadPlugin, loadPlugin, OverrideCursor,
|
49 |
| - reloadPlugin, updateAvailablePlugins, plugins_metadata_parser) |
| 49 | + reloadPlugin, updateAvailablePlugins, plugins_metadata_parser, isPluginLoaded) |
50 | 50 | from .installer_data import (repositories, plugins, officialRepo,
|
51 | 51 | settingsGroup, reposGroup, removeDir)
|
52 | 52 | from .qgsplugininstallerinstallingdialog import QgsPluginInstallerInstallingDialog
|
@@ -315,13 +315,21 @@ def installPlugin(self, key, quiet=False, stable=True):
|
315 | 315 | if QMessageBox.warning(iface.mainWindow(), self.tr("QGIS Python Plugin Installer"), self.tr("Are you sure you want to downgrade the plugin to the latest available version? The installed one is newer!"), QMessageBox.Yes, QMessageBox.No) == QMessageBox.No:
|
316 | 316 | return
|
317 | 317 |
|
| 318 | + # if plugin is active, unload it before update, see https://github.com/qgis/QGIS/issues/54968 |
| 319 | + pluginWasLoaded = isPluginLoaded(plugin["id"]) |
| 320 | + if pluginWasLoaded: |
| 321 | + unloadPlugin(plugin["id"]) |
| 322 | + |
318 | 323 | dlg = QgsPluginInstallerInstallingDialog(iface.mainWindow(), plugin, stable=stable)
|
319 | 324 | dlg.exec_()
|
320 | 325 |
|
321 | 326 | plugin_path = qgis.utils.home_plugin_path + "/" + key
|
322 | 327 | if dlg.result():
|
323 | 328 | error = True
|
324 | 329 | infoString = (self.tr("Plugin installation failed"), dlg.result())
|
| 330 | + # download failed or aborted. If plugin was active before the update, let's try to load it back |
| 331 | + if pluginWasLoaded and loadPlugin(plugin["id"]): |
| 332 | + startPlugin(plugin["id"]) |
325 | 333 | elif not QDir(plugin_path).exists():
|
326 | 334 | error = True
|
327 | 335 | infoString = (
|
@@ -612,6 +620,10 @@ def installFromZipFile(self, filePath):
|
612 | 620 |
|
613 | 621 | pluginDirectory = QDir.cleanPath(os.path.join(pluginsDirectory, pluginName))
|
614 | 622 |
|
| 623 | + # if plugin is active, unload it before update, see https://github.com/qgis/QGIS/issues/54968 |
| 624 | + if isPluginLoaded(pluginName): |
| 625 | + unloadPlugin(pluginName) |
| 626 | + |
615 | 627 | # If the target directory already exists as a link,
|
616 | 628 | # remove the link without resolving
|
617 | 629 | QFile(pluginDirectory).remove()
|
|
0 commit comments