Skip to content

Commit 6e36e3e

Browse files
alexbruynyalldawson
authored andcommitted
unload active plugin before updating or reinstalling it (fix #54968)
1 parent 60affab commit 6e36e3e

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

python/pyplugin_installer/installer.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
from qgis.core import Qgis, QgsApplication, QgsNetworkAccessManager, QgsSettings, QgsNetworkRequestParameters
4747
from qgis.gui import QgsMessageBar, QgsPasswordLineEdit, QgsHelp
4848
from qgis.utils import (iface, startPlugin, unloadPlugin, loadPlugin, OverrideCursor,
49-
reloadPlugin, updateAvailablePlugins, plugins_metadata_parser)
49+
reloadPlugin, updateAvailablePlugins, plugins_metadata_parser, isPluginLoaded)
5050
from .installer_data import (repositories, plugins, officialRepo,
5151
settingsGroup, reposGroup, removeDir)
5252
from .qgsplugininstallerinstallingdialog import QgsPluginInstallerInstallingDialog
@@ -315,13 +315,21 @@ def installPlugin(self, key, quiet=False, stable=True):
315315
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:
316316
return
317317

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+
318323
dlg = QgsPluginInstallerInstallingDialog(iface.mainWindow(), plugin, stable=stable)
319324
dlg.exec_()
320325

321326
plugin_path = qgis.utils.home_plugin_path + "/" + key
322327
if dlg.result():
323328
error = True
324329
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"])
325333
elif not QDir(plugin_path).exists():
326334
error = True
327335
infoString = (
@@ -612,6 +620,10 @@ def installFromZipFile(self, filePath):
612620

613621
pluginDirectory = QDir.cleanPath(os.path.join(pluginsDirectory, pluginName))
614622

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+
615627
# If the target directory already exists as a link,
616628
# remove the link without resolving
617629
QFile(pluginDirectory).remove()

0 commit comments

Comments
 (0)