Skip to content

Commit

Permalink
Check for updates every 7 days while running
Browse files Browse the repository at this point in the history
* 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 keepassxreboot#3706
  • Loading branch information
droidmonkey committed Jun 4, 2020
1 parent f129768 commit e039006
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()) {
Expand Down
3 changes: 2 additions & 1 deletion src/gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -175,6 +175,7 @@ private slots:
bool m_showToolbarSeparator = false;
qint64 m_lastFocusOutTime = 0;
qint64 m_lastShowTime = 0;
QTimer m_updateCheckTimer;
QTimer m_trayIconTriggerTimer;
QSystemTrayIcon::ActivationReason m_trayIconTriggerReason;
};
Expand Down
5 changes: 5 additions & 0 deletions src/updatecheck/UpdateChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit e039006

Please sign in to comment.