- better idle handling

This commit is contained in:
Dmytro Bogovych 2022-06-17 22:01:54 +03:00
parent eed9e13e91
commit f1ca3ed0ed
7 changed files with 8 additions and 10 deletions

View File

@ -1,3 +0,0 @@
URL for used image:
https://thenounproject.com/icon/coffee-break-537907/

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="1200pt" height="1200pt" version="1.1" viewBox="0 0 1200 1200" xmlns="http://www.w3.org/2000/svg">
<path d="m228 72c-9.332 0-14.488 4.707-18.375 9.375-5.1367 6.5391-7.332 15.398-4.125 23.25 18.855 47.793 10.898 59.164 0.375 85.5s-22.758 65.922-0.375 129.75c3.3164 12.883 18.977 20.988 31.5 16.5s19.121-20.566 13.5-32.625c-19.188-54.711-10.637-70.312-0.375-96s23.09-63.176 0.375-120.75c-3.4375-9.0625-12.848-14.941-22.5-15zm324 0c-9.332 0-14.488 4.707-18.375 9.375-5.1367 6.5391-7.332 15.398-4.125 23.25 18.855 47.793 10.898 59.164 0.375 85.5s-22.758 65.922-0.375 129.75c3.3164 12.883 18.977 20.988 31.5 16.5s19.121-20.566 13.5-32.625c-19.188-54.711-10.637-70.312-0.375-96s23.09-63.176 0.375-120.75c-3.4375-9.0625-12.848-14.941-22.5-15zm324 0c-9.332 0-14.488 4.707-18.375 9.375-5.1367 6.5391-7.332 15.398-4.125 23.25 18.855 47.793 10.898 59.164 0.375 85.5s-22.758 65.922-0.375 129.75c3.3164 12.883 18.977 20.988 31.5 16.5s19.121-20.566 13.5-32.625c-19.188-54.711-10.637-70.312-0.375-96s23.09-63.176 0.375-120.75c-3.4375-9.0625-12.848-14.941-22.5-15zm-782.25 360c-11.797 1.1133-21.801 12.148-21.75 24 0 304.82 77.43 453.77 174.75 624h-126.75c-13.297 0-24 10.703-24 24s10.703 24 24 24h864c13.297 0 24-10.703 24-24s-10.703-24-24-24h-126.75c25.375-44.387 49.617-87.379 71.25-132h115.5c46.531 0 84-37.469 84-84v-264c0-46.531-37.465-84-84-84h-13.125c0.69922-19.352 1.125-39.258 1.125-60 0-12.566-11.434-24-24-24h-912c-0.75-0.035156-1.5-0.035156-2.25 0zm27 48h862.5c-4.168 292.51-80.758 424.66-181.5 600h-499.5c-100.74-175.34-177.33-307.49-181.5-600zm907.5 84h15.75c24.383 0 36 11.621 36 36v264c0 24.383-11.617 36-36 36h-93.75c39.703-92.473 68.336-195.91 78-336z"/>
</svg>

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

View File

@ -273,7 +273,8 @@ void MainWindow::onUpdateUI()
{ {
// Idle could start before timer start // Idle could start before timer start
// Check and shrink the found idle interval if needed // Check and shrink the found idle interval if needed
auto proposed_idle_start = std::chrono::steady_clock::now() - std::chrono::milliseconds(idle_milliseconds); auto current_time = std::chrono::steady_clock::now();
auto proposed_idle_start = current_time - std::chrono::milliseconds(idle_milliseconds);
auto timer_start = std::chrono::steady_clock::now() - (std::chrono::milliseconds(mTimer->interval() - mTimer->remainingTime())); auto timer_start = std::chrono::steady_clock::now() - (std::chrono::milliseconds(mTimer->interval() - mTimer->remainingTime()));
mIdleStart = std::max(timer_start, proposed_idle_start); mIdleStart = std::max(timer_start, proposed_idle_start);
@ -281,6 +282,9 @@ void MainWindow::onUpdateUI()
// mIdleStart = std::chrono::steady_clock::now() - std::chrono::milliseconds(idle_milliseconds); // mIdleStart = std::chrono::steady_clock::now() - std::chrono::milliseconds(idle_milliseconds);
if (mTimer->isActive()) if (mTimer->isActive())
{ {
// Correct duration of idle
idle_milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(current_time - mIdleStart.value()).count();
// Save how much time was remaininig when idle was detected + add idle length // Save how much time was remaininig when idle was detected + add idle length
// Later timer will restart with this interval time // Later timer will restart with this interval time
mIdleRemaining = mTimer->remainingTime() + idle_milliseconds; mIdleRemaining = mTimer->remainingTime() + idle_milliseconds;
@ -288,6 +292,9 @@ void MainWindow::onUpdateUI()
// Stop counting // Stop counting
mTimer->stop(); mTimer->stop();
mNotifyTimer->stop(); mNotifyTimer->stop();
// Update "Remaining ..." label
mTrayIcon->setToolTip(tr("There are %1 minutes left until the next break.").arg(msec2min(mIdleRemaining)));
} }
} }
else else

View File

@ -1,7 +1,5 @@
<RCC> <RCC>
<qresource prefix="/"> <qresource prefix="/">
<file>assets/images/app_icon_dark.png</file>
<file>assets/images/app_icon_light.png</file>
<file>assets/misc/qbreak.desktop</file> <file>assets/misc/qbreak.desktop</file>
<file>assets/images/coffee_cup/icon_16x16.png</file> <file>assets/images/coffee_cup/icon_16x16.png</file>
<file>assets/images/coffee_cup/icon_24x24.png</file> <file>assets/images/coffee_cup/icon_24x24.png</file>