From 9bc4ff16a7b3aa502776658fc403deecdc531c9e Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sat, 9 Aug 2025 12:54:37 +0700 Subject: [PATCH] make pomodoro timer persistent --- .config/quickshell/ii/modules/common/Config.qml | 1 - .../quickshell/ii/modules/common/Persistent.qml | 7 +++++++ .config/quickshell/ii/services/Pomodoro.qml | 14 +++++++------- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.config/quickshell/ii/modules/common/Config.qml b/.config/quickshell/ii/modules/common/Config.qml index 73930f938..9580c3bc0 100644 --- a/.config/quickshell/ii/modules/common/Config.qml +++ b/.config/quickshell/ii/modules/common/Config.qml @@ -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 diff --git a/.config/quickshell/ii/modules/common/Persistent.qml b/.config/quickshell/ii/modules/common/Persistent.qml index abd062d73..a650dc0bb 100644 --- a/.config/quickshell/ii/modules/common/Persistent.qml +++ b/.config/quickshell/ii/modules/common/Persistent.qml @@ -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 + } + } } } } diff --git a/.config/quickshell/ii/services/Pomodoro.qml b/.config/quickshell/ii/services/Pomodoro.qml index 9b7b68da4..073280d65 100644 --- a/.config/quickshell/ii/services/Pomodoro.qml +++ b/.config/quickshell/ii/services/Pomodoro.qml @@ -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