Make early network accesses more reliable when using WLAN

The automatic update check is performed early during the application
start. It turns out that, when using a Wifi connection, the Qt
networking code is not ready yet at this point which leads to an
"Network inaccessible" error. This commit delays the automatic update
check until the network configuration is loaded completely.

See issue #1595.
This commit is contained in:
Martin Kleusberg
2019-02-15 12:27:55 +01:00
parent 1bfb97fb65
commit abac190e76
3 changed files with 15 additions and 9 deletions

View File

@@ -518,15 +518,6 @@ void MainWindow::init()
// Load all settings
reloadSettings();
#ifdef CHECKNEWVERSION
// Check for a new version if automatic update check aren't disabled in the settings dialog
if(Settings::getValue("checkversion", "enabled").toBool())
{
m_remoteDb->fetch("https://download.sqlitebrowser.org/currentrelease",
RemoteDatabase::RequestTypeNewVersionCheck);
}
#endif
#ifndef ENABLE_SQLCIPHER
// Only show encryption menu action when SQLCipher support is enabled
ui->actionEncryption->setVisible(false);

View File

@@ -1,5 +1,6 @@
#include <QApplication>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkConfigurationManager>
#include <QMessageBox>
#include <QtNetwork/QNetworkReply>
#include <QFile>
@@ -21,9 +22,21 @@
RemoteDatabase::RemoteDatabase() :
m_manager(new QNetworkAccessManager),
m_configurationManager(new QNetworkConfigurationManager),
m_progress(nullptr),
m_dbLocal(nullptr)
{
// Update network configurations
connect(m_configurationManager, &QNetworkConfigurationManager::updateCompleted, [this]() {
m_manager->setConfiguration(m_configurationManager->defaultConfiguration());
#ifdef CHECKNEWVERSION
// Check for a new version if automatic update check aren't disabled in the settings dialog
if(Settings::getValue("checkversion", "enabled").toBool())
fetch("https://download.sqlitebrowser.org/currentrelease", RemoteDatabase::RequestTypeNewVersionCheck);
#endif
});
// Set up SSL configuration
m_sslConfiguration = QSslConfiguration::defaultConfiguration();
m_sslConfiguration.setPeerVerifyMode(QSslSocket::VerifyPeer);

View File

@@ -5,6 +5,7 @@
#include <QtNetwork/QSslConfiguration>
class QNetworkAccessManager;
class QNetworkConfigurationManager;
class QString;
class QNetworkReply;
class QSslError;
@@ -88,6 +89,7 @@ private:
void clearAccessCache(const QString& clientCert);
QNetworkAccessManager* m_manager;
QNetworkConfigurationManager* m_configurationManager;
QProgressDialog* m_progress;
QSslConfiguration m_sslConfiguration;
QMap<QString, QSslCertificate> m_clientCertFiles;