pomodoro: add cycle indicator, make long break work, fix reset button

This commit is contained in:
end-4
2025-08-09 22:06:05 +07:00
parent 4ca15a1fc3
commit 9e1b55a749
3 changed files with 65 additions and 32 deletions
@@ -11,18 +11,35 @@ Singleton {
property string fileName: "states.json"
property string filePath: `${root.fileDir}/${root.fileName}`
Timer {
id: fileReloadTimer
interval: 100
repeat: false
onTriggered: {
persistentStatesFileView.reload()
}
}
Timer {
id: fileWriteTimer
interval: 100
repeat: false
onTriggered: {
persistentStatesFileView.writeAdapter()
}
}
FileView {
id: persistentStatesFileView
path: root.filePath
watchChanges: true
onFileChanged: reload()
onAdapterUpdated: {
writeAdapter()
}
onFileChanged: fileReloadTimer.restart()
onAdapterUpdated: fileWriteTimer.restart()
onLoadFailed: error => {
console.log("Failed to load persistent states file:", error);
if (error == FileViewError.FileNotFound) {
writeAdapter();
fileWriteTimer.restart();
}
}
@@ -50,6 +67,7 @@ Singleton {
property bool running: false
property int start: 0
property bool isBreak: false
property bool isLongBreak: false
property int cycle: 0
}
property JsonObject stopwatch: JsonObject {
@@ -23,14 +23,10 @@ Item {
CircularProgress {
Layout.alignment: Qt.AlignHCenter
lineWidth: 8
gapAngle: Math.PI / 14
value: {
let pomodoroTotalTime = Pomodoro.isBreak ? Pomodoro.breakTime : Pomodoro.focusTime;
return Pomodoro.pomodoroSecondsLeft / pomodoroTotalTime;
return Pomodoro.pomodoroSecondsLeft / Pomodoro.pomodoroLapDuration;
}
size: 200
primaryColor: Appearance.m3colors.m3onSecondaryContainer
secondaryColor: Appearance.colors.colSecondaryContainer
enableAnimation: true
ColumnLayout {
@@ -49,11 +45,30 @@ Item {
}
StyledText {
Layout.alignment: Qt.AlignHCenter
text: Pomodoro.isBreak ? Translation.tr("Break") : Translation.tr("Focus")
text: Pomodoro.isLongBreak ? Translation.tr("Long break") : Pomodoro.isBreak ? Translation.tr("Break") : Translation.tr("Focus")
font.pixelSize: Appearance.font.pixelSize.normal
color: Appearance.colors.colSubtext
}
}
Rectangle {
radius: Appearance.rounding.full
color: Appearance.colors.colLayer2
anchors {
right: parent.right
bottom: parent.bottom
}
implicitWidth: 36
implicitHeight: implicitWidth
StyledText {
id: cycleText
anchors.centerIn: parent
color: Appearance.colors.colOnLayer2
text: Pomodoro.pomodoroCycle + 1
}
}
}
// The Start/Stop and Reset buttons
@@ -81,7 +96,7 @@ Item {
implicitWidth: 90
onClicked: Pomodoro.resetPomodoro()
enabled: (Pomodoro.pomodoroSecondsLeft < (Pomodoro.isBreak ? Pomodoro.breakTime : Pomodoro.focusTime))
enabled: (Pomodoro.pomodoroSecondsLeft < Pomodoro.pomodoroLapDuration) || Pomodoro.pomodoroCycle > 0 || Pomodoro.isBreak
font.pixelSize: Appearance.font.pixelSize.larger
colBackground: Appearance.colors.colErrorContainer