diff --git a/app/config.h b/app/config.h index 34bdbd8..d8c2076 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 14 +#define QBREAK_VERSION_SUFFIX 15 // How often UI is updated - interval in seconds #define INTERVAL_UPDATE_UI (15) diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index b2e90bd..9a66fff 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -218,7 +218,8 @@ void MainWindow::showMe() // qDebug() << "Screen not found!"; #if defined(DEBUG) - showMaximized(); + showFullScreen(); + //showMaximized(); #else showFullScreen(); #endif @@ -292,6 +293,21 @@ QString state2str(AppState state) return QString(); } +static void dispatchToMainThread(std::function callback) +{ + // any thread + QTimer* timer = new QTimer(); + timer->moveToThread(qApp->thread()); + timer->setSingleShot(true); + QObject::connect(timer, &QTimer::timeout, [=]() + { + // main thread + callback(); + timer->deleteLater(); + }); + QMetaObject::invokeMethod(timer, "start", Qt::QueuedConnection, Q_ARG(int, 0)); +} + void MainWindow::shiftTo(AppState newState) { if (newState == mState) @@ -324,7 +340,12 @@ void MainWindow::shiftTo(AppState newState) } mState = newState; - onUpdateUI(); + + // Run deferred in main UI thread + dispatchToMainThread([this](){ + onUpdateUI(); + }); + } void MainWindow::onUpdateUI() @@ -382,6 +403,8 @@ void MainWindow::onUpdateUI() tr("There are %1 minutes left until the next break.") .arg(msec2min(remaining_milliseconds))); } + else + qDebug() << "No tray icon available."; break; }