make pomodoro timer persistent

This commit is contained in:
end-4
2025-08-09 12:54:37 +07:00
parent 91dae8ad85
commit 9bc4ff16a7
3 changed files with 14 additions and 8 deletions
@@ -255,7 +255,6 @@ Singleton {
property string dateFormat: "ddd, dd/MM"
property JsonObject pomodoro: JsonObject {
property string alertSound: ""
property bool autoRun: false
property int breakTime: 300
property int cycle: 4
property int focus: 1500
@@ -44,6 +44,13 @@ Singleton {
property bool allowNsfw: false
property string provider: "yandere"
}
property JsonObject timer: JsonObject {
property JsonObject pomodoro: JsonObject {
property bool running: false
property int start: 0
}
}
}
}
}
+7 -7
View File
@@ -20,12 +20,12 @@ Singleton {
property int longBreakCycle: Config.options.time.pomodoro.cycle
property string alertSound: Config.options.time.pomodoro.alertSound
property bool isPomodoroRunning: Config.options.time.pomodoro.autoRun
property bool isPomodoroRunning: Persistent.states.timer.pomodoro.running
property bool isBreak: false
property bool isPomodoroReset: !isPomodoroRunning
property int timeLeft: focusTime
property int getPomodoroSecondsLeft: focusTime
property int pomodoroStartTime: getCurrentTimeInSeconds() // The time pomodoro was last Resumed
property int pomodoroStartTime: Persistent.states.timer.pomodoro.start
property int pomodoroCycle: 1
property bool isStopwatchRunning: false
@@ -36,9 +36,9 @@ Singleton {
// Start and Stop button
function togglePomodoro() {
isPomodoroReset = false
isPomodoroRunning = !isPomodoroRunning
Persistent.states.timer.pomodoro.running = !isPomodoroRunning
if (isPomodoroRunning) { // Pressed Start button
pomodoroStartTime = getCurrentTimeInSeconds()
Persistent.states.timer.pomodoro.start = getCurrentTimeInSeconds()
} else { // Pressed Stop button
timeLeft -= (getCurrentTimeInSeconds() - pomodoroStartTime)
}
@@ -46,11 +46,11 @@ Singleton {
// Reset button
function pomodoroReset() {
isPomodoroRunning = false
Persistent.states.timer.pomodoro.running = false
isBreak = false
isPomodoroReset = true
timeLeft = focusTime
pomodoroStartTime = getCurrentTimeInSeconds()
Persistent.states.timer.pomodoro.start = getCurrentTimeInSeconds()
pomodoroCycle = 1
refreshPomodoro()
}
@@ -58,7 +58,7 @@ Singleton {
function refreshPomodoro() {
if (getCurrentTimeInSeconds() >= pomodoroStartTime + timeLeft) {
isBreak = !isBreak
pomodoroStartTime += timeLeft
Persistent.states.timer.pomodoro.start += timeLeft
timeLeft = isBreak ? breakTime : focusTime
let notificationTitle, notificationMessage