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
This commit is contained in:
Jonathan White 2020-06-02 22:57:12 -04:00
parent f129768f07
commit e039006667
3 changed files with 13 additions and 3 deletions

View file

@ -489,7 +489,11 @@ MainWindow::MainWindow()
connect(UpdateChecker::instance(), connect(UpdateChecker::instance(),
SIGNAL(updateCheckFinished(bool, QString, bool)), SIGNAL(updateCheckFinished(bool, QString, bool)),
SLOT(hasUpdateAvailable(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 #else
m_ui->actionCheckForUpdates->setVisible(false); m_ui->actionCheckForUpdates->setVisible(false);
#endif #endif
@ -892,7 +896,7 @@ void MainWindow::showAboutDialog()
aboutDialog->open(); aboutDialog->open();
} }
void MainWindow::showUpdateCheckStartup() void MainWindow::performUpdateCheck()
{ {
#ifdef WITH_XC_UPDATECHECK #ifdef WITH_XC_UPDATECHECK
if (!config()->get(Config::UpdateCheckMessageShown).toBool()) { if (!config()->get(Config::UpdateCheckMessageShown).toBool()) {

View file

@ -92,7 +92,7 @@ private slots:
void updateToolbarSeparatorVisibility(); void updateToolbarSeparatorVisibility();
void updateWindowTitle(); void updateWindowTitle();
void showAboutDialog(); void showAboutDialog();
void showUpdateCheckStartup(); void performUpdateCheck();
void showUpdateCheckDialog(); void showUpdateCheckDialog();
void focusWindowChanged(QWindow* focusWindow); void focusWindowChanged(QWindow* focusWindow);
void hasUpdateAvailable(bool hasUpdate, const QString& version, bool isManuallyRequested); void hasUpdateAvailable(bool hasUpdate, const QString& version, bool isManuallyRequested);
@ -175,6 +175,7 @@ private:
bool m_showToolbarSeparator = false; bool m_showToolbarSeparator = false;
qint64 m_lastFocusOutTime = 0; qint64 m_lastFocusOutTime = 0;
qint64 m_lastShowTime = 0; qint64 m_lastShowTime = 0;
QTimer m_updateCheckTimer;
QTimer m_trayIconTriggerTimer; QTimer m_trayIconTriggerTimer;
QSystemTrayIcon::ActivationReason m_trayIconTriggerReason; QSystemTrayIcon::ActivationReason m_trayIconTriggerReason;
}; };

View file

@ -42,6 +42,11 @@ UpdateChecker::~UpdateChecker()
void UpdateChecker::checkForUpdates(bool manuallyRequested) 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(); auto nextCheck = config()->get(Config::GUI_CheckForUpdatesNextCheck).toULongLong();
m_isManuallyRequested = manuallyRequested; m_isManuallyRequested = manuallyRequested;