diff --git a/applets/timer/package/contents/ui/TimerView.qml b/applets/timer/package/contents/ui/TimerView.qml --- a/applets/timer/package/contents/ui/TimerView.qml +++ b/applets/timer/package/contents/ui/TimerView.qml @@ -51,21 +51,21 @@ Timer { id: t; - interval: 1000; + interval: 20; onTriggered: { - if (root.seconds != 0) { - root.seconds--; + var ts = new Date().getTime(); + if (root.seconds > 0) { + root.seconds = root.initialSeconds - Math.floor((ts-root.startedAt)/1000); } - if (root.seconds == 0) { - root.running = false; + if (root.seconds <= 0) { + resetTimer(); if (showNotification) { root.createNotification(); } if (runCommand) { TimerPlasmoid.Timer.runCommand(command); } - saveTimer(); } } repeat: true; diff --git a/applets/timer/package/contents/ui/main.qml b/applets/timer/package/contents/ui/main.qml --- a/applets/timer/package/contents/ui/main.qml +++ b/applets/timer/package/contents/ui/main.qml @@ -35,6 +35,12 @@ property bool running: (plasmoid.configuration.running > 0) ? true : false; property bool suspended: false; + // timestamp from when the user clicked 'start timer'; in ms + property var startedAt: 0; + // value of 'seconds' when the user clicked 'start timer' + property int initialSeconds: 0; + + property string notificationText: plasmoid.configuration.notificationText; Plasmoid.toolTipMainText: { @@ -100,6 +106,8 @@ (sec % 60) % 10; } function startTimer() { + startedAt = new Date().getTime(); + initialSeconds = seconds; running = true; suspended = false; opacityNeedsReset() @@ -109,13 +117,17 @@ function stopTimer() { running = false; suspended = true; + startedAt = 0; + initialSeconds = 0; saveTimer(); } function resetTimer() { running = false; suspended = false; seconds = 0; + startedAt = 0; + initialSeconds = 0; opacityNeedsReset() saveTimer(); }