[Timer applet] Fix double speed countdown & commands run multiple times

Summary:
Both the compact and the fullpresentation variants of the applet had
an instance of a timer, and both were connected to the central "running"
flag. So if both variants had been created, there were 2 timers triggering
the decreasing of the seconds, and also firing off the command once done.

Moving the countdown timer (and at the same time also a timer for
delayed saving of the state, which had the same issue) to the central root
item fixes this.

BUG: 381173
FIXED-IN: 5.12.6

Test Plan:
Applet still works as before on panel and background pane, now does proper
countdown in both cases.

Reviewers: #plasma, davidedmundson

Reviewed By: #plasma, davidedmundson

Subscribers: davidedmundson, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D13065
parent 9249acf2
......@@ -23,7 +23,6 @@ import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.kquickcontrolsaddons 2.0 as QtExtra
import org.kde.plasma.private.timer 0.1 as TimerPlasmoid
Item {
id: main
......@@ -33,13 +32,6 @@ Item {
// display seconds in addition to hours and minutes (default: enabled)
property bool showSeconds: plasmoid.configuration.showSeconds;
// show notification on timer completion (default: enabled)
property bool showNotification: plasmoid.configuration.showNotification;
// run custom command on timer completion (default: disabled)
property bool runCommand: plasmoid.configuration.runCommand;
property string command: plasmoid.configuration.command;
property real digits: (showSeconds) ? 7 : 4.5;
property int digitH: ((height / 2) * digits < width ? height : ((width - (digits - 1)) / digits) * 2);
property int digitW: digitH / 2;
......@@ -49,35 +41,6 @@ Item {
imagePath: "widgets/timer"
}
Timer {
id: t;
interval: 1000;
onTriggered: {
if (root.seconds != 0) {
root.seconds--;
}
if (root.seconds == 0) {
root.running = false;
if (showNotification) {
root.createNotification();
}
if (runCommand) {
TimerPlasmoid.Timer.runCommand(command);
}
saveTimer();
}
}
repeat: true;
running: root.running;
}
Timer {
id: delayedSaveTimer;
interval: 3000;
onTriggered: saveTimer();
}
Column {
anchors.centerIn: parent;
Text {
......@@ -177,18 +140,12 @@ Item {
}
}
function digitChanged() {
delayedSaveTimer.stop();
delayedSaveTimer.start();
}
function resetOpacity() {
timerDigits.opacity = 1.0;
}
Component.onCompleted: {
root.opacityNeedsReset.connect(resetOpacity);
root.digitHasChanged.connect(digitChanged);
}
}
......@@ -22,6 +22,7 @@ import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.kquickcontrolsaddons 2.0 as QtExtra
import org.kde.plasma.private.timer 0.1 as TimerPlasmoid
Item {
id: root;
......@@ -29,6 +30,12 @@ Item {
property int seconds : restoreToSeconds(plasmoid.configuration.running, plasmoid.configuration.savedAt, plasmoid.configuration.seconds);
// show notification on timer completion (default: enabled)
property bool showNotification: plasmoid.configuration.showNotification;
// run custom command on timer completion (default: disabled)
property bool runCommand: plasmoid.configuration.runCommand;
property string command: plasmoid.configuration.command;
// show title (can be customized in the settings dialog, default: disabled)
property bool showTitle: plasmoid.configuration.showTitle;
property string title: plasmoid.configuration.title;
......@@ -65,6 +72,40 @@ Item {
connectedSources: "org.freedesktop.Notifications"
}
Timer {
id: t;
interval: 1000;
onTriggered: {
if (root.seconds != 0) {
root.seconds--;
}
if (root.seconds == 0) {
root.running = false;
if (showNotification) {
root.createNotification();
}
if (runCommand) {
TimerPlasmoid.Timer.runCommand(command);
}
saveTimer();
}
}
repeat: true;
running: root.running;
}
Timer {
id: delayedSaveTimer;
interval: 3000;
onTriggered: saveTimer();
}
function onDigitHasChanged() {
delayedSaveTimer.stop();
delayedSaveTimer.start();
}
function createNotification() {
var service = notificationSource.serviceForSource("notification");
var operation = service.operationDescription("createNotification");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment