From e039006667a432b9b1c23a4522704b0d8d9ca93f Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Tue, 2 Jun 2020 22:57:12 -0400 Subject: [PATCH] Check for updates every 7 days while running * Check every hour to see if another update check should be performed. Nothing actually happens unless 7 days has elapsed since the last update check. * Fixes #3706 --- src/gui/MainWindow.cpp | 8 ++++++-- src/gui/MainWindow.h | 3 ++- src/updatecheck/UpdateChecker.cpp | 5 +++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index ca4898d80..3f85390f8 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -489,7 +489,11 @@ MainWindow::MainWindow() connect(UpdateChecker::instance(), SIGNAL(updateCheckFinished(bool, QString, bool)), SLOT(hasUpdateAvailable(bool, QString, bool))); - QTimer::singleShot(500, this, SLOT(showUpdateCheckStartup())); + // Setup an update check every hour (checked only occur every 7 days) + connect(&m_updateCheckTimer, &QTimer::timeout, this, &MainWindow::performUpdateCheck); + m_updateCheckTimer.start(3.6e6); + // Perform the startup update check after 500 ms + QTimer::singleShot(500, this, SLOT(performUpdateCheck())); #else m_ui->actionCheckForUpdates->setVisible(false); #endif @@ -892,7 +896,7 @@ void MainWindow::showAboutDialog() aboutDialog->open(); } -void MainWindow::showUpdateCheckStartup() +void MainWindow::performUpdateCheck() { #ifdef WITH_XC_UPDATECHECK if (!config()->get(Config::UpdateCheckMessageShown).toBool()) { diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index 9adc5f0cb..230e6256e 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -92,7 +92,7 @@ private slots: void updateToolbarSeparatorVisibility(); void updateWindowTitle(); void showAboutDialog(); - void showUpdateCheckStartup(); + void performUpdateCheck(); void showUpdateCheckDialog(); void focusWindowChanged(QWindow* focusWindow); void hasUpdateAvailable(bool hasUpdate, const QString& version, bool isManuallyRequested); @@ -175,6 +175,7 @@ private: bool m_showToolbarSeparator = false; qint64 m_lastFocusOutTime = 0; qint64 m_lastShowTime = 0; + QTimer m_updateCheckTimer; QTimer m_trayIconTriggerTimer; QSystemTrayIcon::ActivationReason m_trayIconTriggerReason; }; diff --git a/src/updatecheck/UpdateChecker.cpp b/src/updatecheck/UpdateChecker.cpp index 48a8c98c7..3d3387585 100644 --- a/src/updatecheck/UpdateChecker.cpp +++ b/src/updatecheck/UpdateChecker.cpp @@ -42,6 +42,11 @@ UpdateChecker::~UpdateChecker() void UpdateChecker::checkForUpdates(bool manuallyRequested) { + // Skip update if we are already performing one + if (m_reply) { + return; + } + auto nextCheck = config()->get(Config::GUI_CheckForUpdatesNextCheck).toULongLong(); m_isManuallyRequested = manuallyRequested;