mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-23 00:02:38 -05:00
Make plugin watchdog considering timestamp of last run. Fixes #59370
This commit is contained in:
parent
5acffdaeda
commit
e1de76d763
@ -29,7 +29,7 @@ import zipfile
|
||||
from functools import partial
|
||||
|
||||
from qgis.PyQt import sip
|
||||
from qgis.PyQt.QtCore import Qt, QObject, QDir, QUrl, QFileInfo, QFile
|
||||
from qgis.PyQt.QtCore import Qt, QObject, QDateTime, QDir, QUrl, QFileInfo, QFile
|
||||
from qgis.PyQt.QtWidgets import (
|
||||
QApplication,
|
||||
QDialog,
|
||||
@ -118,7 +118,8 @@ class QgsPluginInstaller(QObject):
|
||||
self.uninstallPlugin(key, quiet=True)
|
||||
updateAvailablePlugins()
|
||||
if plugin_is_active:
|
||||
settings.setValue("/PythonPlugins/watchDog/" + key, True)
|
||||
settings.setValue("/PythonPlugins/watchDog/" + key,
|
||||
QDateTime.currentDateTime().toSecsSinceEpoch())
|
||||
loadPlugin(key)
|
||||
startPlugin(key)
|
||||
settings.remove("/PythonPlugins/watchDog/" + key)
|
||||
|
@ -505,10 +505,23 @@ void QgsPluginRegistry::restoreSessionPlugins( const QString &pluginDirString )
|
||||
const QString myFullPath = pluginDirString + '/' + myPluginDir[i];
|
||||
if ( checkCppPlugin( myFullPath ) )
|
||||
{
|
||||
// check if the plugin was active on last session
|
||||
// check if there is a watchdog timestamp left after last session
|
||||
|
||||
bool pluginCrashedPreviously = false;
|
||||
const QString baseName = QFileInfo( myFullPath ).baseName();
|
||||
if ( mySettings.value( QStringLiteral( "Plugins/watchDog/%1" ).arg( baseName ) ).isValid() )
|
||||
const QVariant lastRun = mySettings.value( QStringLiteral( "Plugins/watchDog/%1" ).arg( baseName ) );
|
||||
if ( lastRun.isValid() )
|
||||
{
|
||||
const int delta = QDateTime::currentDateTime().toSecsSinceEpoch() - lastRun.toInt();
|
||||
if ( delta > 5 )
|
||||
{
|
||||
// The timestamp is left unremoved and is older than 5 seconds, so it doesn't come
|
||||
// from a parallelly running instance.
|
||||
pluginCrashedPreviously = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( pluginCrashedPreviously )
|
||||
{
|
||||
QToolButton *btnEnablePlugin = new QToolButton();
|
||||
btnEnablePlugin ->setText( QObject::tr( "Enable Plugin" ) );
|
||||
@ -548,7 +561,8 @@ void QgsPluginRegistry::restoreSessionPlugins( const QString &pluginDirString )
|
||||
}
|
||||
if ( mySettings.value( "/Plugins/" + baseName ).toBool() )
|
||||
{
|
||||
mySettings.setValue( QStringLiteral( "Plugins/watchDog/%1" ).arg( baseName ), true );
|
||||
mySettings.setValue( QStringLiteral( "Plugins/watchDog/%1" ).arg( baseName ),
|
||||
QDateTime::currentDateTime().toSecsSinceEpoch() );
|
||||
loadCppPlugin( myFullPath );
|
||||
mySettings.remove( QStringLiteral( "/Plugins/watchDog/%1" ).arg( baseName ) );
|
||||
}
|
||||
@ -597,8 +611,20 @@ void QgsPluginRegistry::restoreSessionPlugins( const QString &pluginDirString )
|
||||
}
|
||||
// end - temporary fix for issue #5879, more below
|
||||
|
||||
bool pluginCrashedPreviously = false;
|
||||
const QVariant lastRun = mySettings.value( QStringLiteral( "/PythonPlugins/watchDog/%1" ).arg( packageName ) );
|
||||
if ( lastRun.isValid() )
|
||||
{
|
||||
const int delta = QDateTime::currentDateTime().toSecsSinceEpoch() - lastRun.toInt();
|
||||
if ( delta > 5 )
|
||||
{
|
||||
// The timestamp is left unremoved and is older than 5 seconds, so it doesn't come
|
||||
// from a parallelly running instance.
|
||||
pluginCrashedPreviously = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( mySettings.value( "/PythonPlugins/watchDog/" + packageName ).isValid() )
|
||||
if ( pluginCrashedPreviously )
|
||||
{
|
||||
QToolButton *btnEnablePlugin = new QToolButton();
|
||||
btnEnablePlugin->setText( QObject::tr( "Enable Plugin" ) );
|
||||
@ -645,7 +671,8 @@ void QgsPluginRegistry::restoreSessionPlugins( const QString &pluginDirString )
|
||||
// check if the plugin was active on last session
|
||||
if ( mySettings.value( "/PythonPlugins/" + packageName ).toBool() )
|
||||
{
|
||||
mySettings.setValue( "/PythonPlugins/watchDog/" + packageName, true );
|
||||
mySettings.setValue( "/PythonPlugins/watchDog/" + packageName,
|
||||
QDateTime::currentDateTime().toSecsSinceEpoch() );
|
||||
if ( checkPythonPlugin( packageName ) )
|
||||
{
|
||||
loadPythonPlugin( packageName );
|
||||
|
Loading…
x
Reference in New Issue
Block a user