From 24b470cfc68be6f02ad24b94a5d88b050e21a984 Mon Sep 17 00:00:00 2001 From: Dmytro Bogovych Date: Sun, 29 May 2022 16:59:56 +0300 Subject: [PATCH] - version 0.1.5 - fix random notifications --- app/config.h | 2 +- app/mainwindow.cpp | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/config.h b/app/config.h index 9d8207c..a5db9b3 100644 --- a/app/config.h +++ b/app/config.h @@ -4,7 +4,7 @@ // App version #define QBREAK_VERSION_MAJOR 0 #define QBREAK_VERSION_MINOR 1 -#define QBREAK_VERSION_SUFFIX 4 +#define QBREAK_VERSION_SUFFIX 5 // How often UI is updated - interval in seconds #define INTERVAL_UPDATE_UI (60) diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index e3c8a63..867265c 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -273,10 +273,16 @@ void MainWindow::onUpdateUI() { // Start idle mode. Save idle start time mIdleStart = std::chrono::steady_clock::now() - std::chrono::milliseconds(idle_milliseconds); - mIdleRemaining = mTimer->remainingTime() + idle_milliseconds; + if (mTimer->isActive()) + { + // Save how much time was remaininig when idle was detected + add idle length + // Later timer will restart with this interval time + mIdleRemaining = mTimer->remainingTime() + idle_milliseconds; - // Stop counting - mTimer->stop(); + // Stop counting + mTimer->stop(); + mNotifyTimer->stop(); + } } else { @@ -290,9 +296,8 @@ void MainWindow::onUpdateUI() { // Idle interval ended mIdleStart.reset(); - mTimer->setInterval(mIdleRemaining); - mTimer->setSingleShot(true); - mTimer->start(); + mTimer->start(mIdleRemaining); + mNotifyTimer->start(std::max(1, mIdleRemaining - 30 * 1000)); } else { @@ -334,7 +339,11 @@ void MainWindow::onLongBreakStart() { // qDebug() << "Long break starts for " << secondsToText(mAppConfig.longbreak_postpone_interval); + mTimer->stop(); + mNotifyTimer->stop(); + // Reset idle counter + mLastIdleMilliseconds = 0; ui->mPostponeButton->setText(tr("Postpone for ") + secondsToText(mAppConfig.longbreak_postpone_interval)); @@ -429,6 +438,9 @@ void MainWindow::onProgress() void MainWindow::onNextBreak() { + mIdleRemaining = 0; + mIdleStart.reset(); + mTimer->stop(); mNotifyTimer->stop();