forked from Shinonome/dots-hyprland
Minor tweaks and better variables names
Signed-off-by: Nyx <189459385+nyx-4@users.noreply.github.com>
This commit is contained in:
@@ -254,11 +254,12 @@ Singleton {
|
|||||||
property string format: "hh:mm"
|
property string format: "hh:mm"
|
||||||
property string dateFormat: "ddd, dd/MM"
|
property string dateFormat: "ddd, dd/MM"
|
||||||
property JsonObject pomodoro: JsonObject {
|
property JsonObject pomodoro: JsonObject {
|
||||||
|
property string alertSound: ""
|
||||||
|
property bool autoRun: false
|
||||||
property int breakTime: 300
|
property int breakTime: 300
|
||||||
property int cycle: 4
|
property int cycle: 4
|
||||||
property int focus: 1500
|
property int focus: 1500
|
||||||
property int longBreak: 1200
|
property int longBreak: 1200
|
||||||
property bool running: false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ Item {
|
|||||||
property int lapsListItemSpacing: 5
|
property int lapsListItemSpacing: 5
|
||||||
|
|
||||||
|
|
||||||
// These are keybinds, make sure to change them.
|
// These are keybinds for stopwatch and pomodoro
|
||||||
Keys.onPressed: (event) => {
|
Keys.onPressed: (event) => {
|
||||||
if ((event.key === Qt.Key_PageDown || event.key === Qt.Key_PageUp) && event.modifiers === Qt.NoModifier) {
|
if ((event.key === Qt.Key_PageDown || event.key === Qt.Key_PageUp) && event.modifiers === Qt.NoModifier) {
|
||||||
if (event.key === Qt.Key_PageDown) {
|
if (event.key === Qt.Key_PageDown) {
|
||||||
@@ -30,15 +30,15 @@ Item {
|
|||||||
currentTab = Math.max(currentTab - 1, 0)
|
currentTab = Math.max(currentTab - 1, 0)
|
||||||
}
|
}
|
||||||
event.accepted = true
|
event.accepted = true
|
||||||
} else if (event.key === Qt.Key_Space && !showDialog) {
|
} else if (event.key === Qt.Key_Space || event.key === Qt.Key_S) {
|
||||||
// Toggle start/stop with Space key
|
// Toggle start/stop with Space or S key
|
||||||
if (currentTab === 0) {
|
if (currentTab === 0) {
|
||||||
Pomodoro.togglePomodoro()
|
Pomodoro.togglePomodoro()
|
||||||
} else {
|
} else {
|
||||||
Pomodoro.toggleStopwatch()
|
Pomodoro.toggleStopwatch()
|
||||||
}
|
}
|
||||||
event.accepted = true
|
event.accepted = true
|
||||||
} else if (event.key === Qt.Key_R && !showDialog) {
|
} else if (event.key === Qt.Key_R) {
|
||||||
// Reset with R key
|
// Reset with R key
|
||||||
if (currentTab === 0) {
|
if (currentTab === 0) {
|
||||||
Pomodoro.pomodoroReset()
|
Pomodoro.pomodoroReset()
|
||||||
@@ -46,18 +46,18 @@ Item {
|
|||||||
Pomodoro.stopwatchReset()
|
Pomodoro.stopwatchReset()
|
||||||
}
|
}
|
||||||
event.accepted = true
|
event.accepted = true
|
||||||
} else if (event.key === Qt.Key_Escape && showDialog) {
|
} else if (event.key === Qt.Key_L) {
|
||||||
showDialog = false
|
// record Stopwatch lap with L key, regardless of current Tab
|
||||||
event.accepted = true
|
Pomodoro.recordLaps()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: pomodoroTimer
|
id: pomodoroTimer
|
||||||
interval: 200
|
interval: 200
|
||||||
running: Config.options.time.pomodoro.running
|
running: Pomodoro.isPomodoroRunning
|
||||||
repeat: true
|
repeat: true
|
||||||
onTriggered: Pomodoro.tickSecond()
|
onTriggered: Pomodoro.refreshPomodoro()
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
@@ -65,7 +65,7 @@ Item {
|
|||||||
interval: 10
|
interval: 10
|
||||||
running: Pomodoro.isStopwatchRunning
|
running: Pomodoro.isStopwatchRunning
|
||||||
repeat: true
|
repeat: true
|
||||||
onTriggered: Pomodoro.tick10ms()
|
onTriggered: Pomodoro.refreshStopwatch()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ Item {
|
|||||||
Rectangle {
|
Rectangle {
|
||||||
id: indicator
|
id: indicator
|
||||||
property int tabCount: root.tabButtonList.length
|
property int tabCount: root.tabButtonList.length
|
||||||
property real fullTabSize: root.width / tabCount
|
property real fullTabSize: root.width / tabCount;
|
||||||
property real targetWidth: tabBar.contentItem.children[0].children[tabBar.currentIndex].tabContentWidth
|
property real targetWidth: tabBar.contentItem.children[0].children[tabBar.currentIndex].tabContentWidth
|
||||||
|
|
||||||
implicitWidth: targetWidth
|
implicitWidth: targetWidth
|
||||||
@@ -176,7 +176,7 @@ Item {
|
|||||||
lineWidth: 7
|
lineWidth: 7
|
||||||
gapAngle: Math.PI / 14
|
gapAngle: Math.PI / 14
|
||||||
value: {
|
value: {
|
||||||
let pomodoroTotalTime = Pomodoro.isPomodoroBreak ? Pomodoro.pomodoroBreakTime : Pomodoro.pomodoroFocusTime
|
let pomodoroTotalTime = Pomodoro.isBreak ? Pomodoro.breakTime : Pomodoro.focusTime
|
||||||
return Pomodoro.getPomodoroSecondsLeft / pomodoroTotalTime
|
return Pomodoro.getPomodoroSecondsLeft / pomodoroTotalTime
|
||||||
}
|
}
|
||||||
size: 125
|
size: 125
|
||||||
@@ -200,7 +200,7 @@ Item {
|
|||||||
}
|
}
|
||||||
StyledText {
|
StyledText {
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
text: Pomodoro.isPomodoroBreak ? Translation.tr("Break") : Translation.tr("Focus")
|
text: Pomodoro.isBreak ? Translation.tr("Break") : Translation.tr("Focus")
|
||||||
font.pixelSize: Appearance.font.pixelSize.normal
|
font.pixelSize: Appearance.font.pixelSize.normal
|
||||||
color: Appearance.m3colors.m3onSurface
|
color: Appearance.m3colors.m3onSurface
|
||||||
}
|
}
|
||||||
@@ -273,6 +273,10 @@ Item {
|
|||||||
value: Config.options.time.pomodoro.focus / 60
|
value: Config.options.time.pomodoro.focus / 60
|
||||||
onValueChanged: {
|
onValueChanged: {
|
||||||
Config.options.time.pomodoro.focus = value * 60
|
Config.options.time.pomodoro.focus = value * 60
|
||||||
|
if (Pomodoro.isPomodoroReset) { // Special case for Pomodoro in Reset state
|
||||||
|
Pomodoro.getPomodoroSecondsLeft = Pomodoro.focusTime
|
||||||
|
Pomodoro.timeLeft = Pomodoro.focusTime
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,7 +339,9 @@ Item {
|
|||||||
|
|
||||||
// Stopwatch Tab
|
// Stopwatch Tab
|
||||||
Item {
|
Item {
|
||||||
|
id: stopwatchTab
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
Layout.fillHeight: true
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
@@ -346,6 +352,7 @@ Item {
|
|||||||
spacing: 40
|
spacing: 40
|
||||||
// The Stopwatch circle
|
// The Stopwatch circle
|
||||||
CircularProgress {
|
CircularProgress {
|
||||||
|
id: stopwatchClock
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
lineWidth: 7
|
lineWidth: 7
|
||||||
gapAngle: Math.PI / 18
|
gapAngle: Math.PI / 18
|
||||||
@@ -413,7 +420,7 @@ Item {
|
|||||||
Layout.preferredHeight: 35
|
Layout.preferredHeight: 35
|
||||||
Layout.preferredWidth: 90
|
Layout.preferredWidth: 90
|
||||||
font.pixelSize: Appearance.font.pixelSize.larger
|
font.pixelSize: Appearance.font.pixelSize.larger
|
||||||
onClicked: Pomodoro.stopwatchReset()
|
onClicked: Pomodoro.stopwatchResetOrLaps()
|
||||||
colBackground: Appearance.m3colors.m3onError
|
colBackground: Appearance.m3colors.m3onError
|
||||||
colBackgroundHover: Appearance.m3colors.m3onError
|
colBackgroundHover: Appearance.m3colors.m3onError
|
||||||
}
|
}
|
||||||
@@ -423,9 +430,10 @@ Item {
|
|||||||
StyledListView {
|
StyledListView {
|
||||||
id: lapsList
|
id: lapsList
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.preferredHeight: contentHeight
|
Layout.preferredHeight: stopwatchTab.height - stopwatchClock.height - 20
|
||||||
spacing: lapsListItemSpacing
|
spacing: lapsListItemSpacing
|
||||||
clip: true
|
clip: true
|
||||||
|
popin: true
|
||||||
model: Pomodoro.stopwatchLaps
|
model: Pomodoro.stopwatchLaps
|
||||||
|
|
||||||
delegate: Rectangle {
|
delegate: Rectangle {
|
||||||
@@ -446,11 +454,8 @@ Item {
|
|||||||
font.pixelSize: Appearance.font.pixelSize.normal
|
font.pixelSize: Appearance.font.pixelSize.normal
|
||||||
|
|
||||||
text: {
|
text: {
|
||||||
let lapIndex = index + 1
|
|
||||||
let lapTime = modelData
|
let lapTime = modelData
|
||||||
// if (index > 0) {
|
|
||||||
// lapTime = modelData - Pomodoro.stopwatchLaps[index - 1]
|
|
||||||
// }
|
|
||||||
let _10ms = (Math.floor(lapTime) % 100).toString().padStart(2, '0')
|
let _10ms = (Math.floor(lapTime) % 100).toString().padStart(2, '0')
|
||||||
let totalSeconds = Math.floor(lapTime) / 100
|
let totalSeconds = Math.floor(lapTime) / 100
|
||||||
let minutes = Math.floor(totalSeconds / 60).toString().padStart(2, '0')
|
let minutes = Math.floor(totalSeconds / 60).toString().padStart(2, '0')
|
||||||
@@ -472,9 +477,8 @@ Item {
|
|||||||
color: Appearance.colors.colPrimary
|
color: Appearance.colors.colPrimary
|
||||||
|
|
||||||
text: {
|
text: {
|
||||||
let lapTime = modelData
|
|
||||||
if (index != Pomodoro.stopwatchLaps.length - 1) { // except first lap
|
if (index != Pomodoro.stopwatchLaps.length - 1) { // except first lap
|
||||||
lapTime = modelData - Pomodoro.stopwatchLaps[index + 1]
|
let lapTime = modelData - Pomodoro.stopwatchLaps[index + 1]
|
||||||
let _10ms = (Math.floor(lapTime) % 100).toString().padStart(2, '0')
|
let _10ms = (Math.floor(lapTime) % 100).toString().padStart(2, '0')
|
||||||
let totalSeconds = Math.floor(lapTime) / 100
|
let totalSeconds = Math.floor(lapTime) / 100
|
||||||
let minutes = Math.floor(totalSeconds / 60).toString().padStart(2, '0')
|
let minutes = Math.floor(totalSeconds / 60).toString().padStart(2, '0')
|
||||||
|
|||||||
@@ -14,64 +14,72 @@ import QtQuick
|
|||||||
Singleton {
|
Singleton {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property int pomodoroFocusTime: Config.options.time.pomodoro.focus
|
property int focusTime: Config.options.time.pomodoro.focus
|
||||||
property int pomodoroBreakTime: Config.options.time.pomodoro.breakTime
|
property int breakTime: Config.options.time.pomodoro.breakTime
|
||||||
property int pomodoroLongBreakTime: Config.options.time.pomodoro.longBreak
|
property int longBreakTime: Config.options.time.pomodoro.longBreak
|
||||||
property int pomodoroLongBreakCycle: Config.options.time.pomodoro.cycle
|
property int longBreakCycle: Config.options.time.pomodoro.cycle
|
||||||
property bool isPomodoroRunning: Config.options.time.pomodoro.running
|
property string alertSound: Config.options.time.pomodoro.alertSound
|
||||||
|
|
||||||
property int pomodoroTimeLeft: pomodoroFocusTime
|
property bool isPomodoroRunning: Config.options.time.pomodoro.autoRun
|
||||||
property int getPomodoroSecondsLeft: pomodoroFocusTime
|
property bool isBreak: false
|
||||||
property int pomodoroTimeStarted: getCurrentTimeInSeconds() // The time pomodoro was last Resumed
|
property bool isPomodoroReset: !isPomodoroRunning
|
||||||
property bool isPomodoroBreak: false
|
property int timeLeft: focusTime
|
||||||
|
property int getPomodoroSecondsLeft: focusTime
|
||||||
|
property int pomodoroStartTime: getCurrentTimeInSeconds() // The time pomodoro was last Resumed
|
||||||
property int pomodoroCycle: 1
|
property int pomodoroCycle: 1
|
||||||
|
|
||||||
property int stopwatchTime: 0
|
|
||||||
property bool isStopwatchRunning: false
|
property bool isStopwatchRunning: false
|
||||||
property int stopwatchStartTime: 0
|
property int stopwatchTime: 0
|
||||||
|
property int stopwatchStart: 0
|
||||||
property var stopwatchLaps: []
|
property var stopwatchLaps: []
|
||||||
|
|
||||||
// Start and Stop button
|
// Start and Stop button
|
||||||
function togglePomodoro() {
|
function togglePomodoro() {
|
||||||
Config.options.time.pomodoro.running = !isPomodoroRunning
|
isPomodoroReset = false
|
||||||
|
isPomodoroRunning = !isPomodoroRunning
|
||||||
if (isPomodoroRunning) { // Pressed Start button
|
if (isPomodoroRunning) { // Pressed Start button
|
||||||
pomodoroTimeStarted = getCurrentTimeInSeconds()
|
pomodoroStartTime = getCurrentTimeInSeconds()
|
||||||
} else { // Pressed Stop button
|
} else { // Pressed Stop button
|
||||||
pomodoroTimeLeft -= (getCurrentTimeInSeconds() - pomodoroTimeStarted)
|
timeLeft -= (getCurrentTimeInSeconds() - pomodoroStartTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset button
|
// Reset button
|
||||||
function pomodoroReset() {
|
function pomodoroReset() {
|
||||||
pomodoroTimeLeft = pomodoroFocusTime
|
isPomodoroRunning = false
|
||||||
getPomodoroSecondsLeft = pomodoroFocusTime
|
isBreak = false
|
||||||
isPomodoroBreak = false
|
isPomodoroReset = true
|
||||||
Config.options.time.pomodoro.running = false
|
timeLeft = focusTime
|
||||||
|
pomodoroStartTime = getCurrentTimeInSeconds()
|
||||||
pomodoroCycle = 1
|
pomodoroCycle = 1
|
||||||
|
refreshPomodoro()
|
||||||
}
|
}
|
||||||
|
|
||||||
function tickSecond() {
|
function refreshPomodoro() {
|
||||||
if (getCurrentTimeInSeconds() >= pomodoroTimeStarted + pomodoroTimeLeft) {
|
if (getCurrentTimeInSeconds() >= pomodoroStartTime + timeLeft) {
|
||||||
isPomodoroBreak = !isPomodoroBreak
|
isBreak = !isBreak
|
||||||
pomodoroTimeStarted += pomodoroTimeLeft
|
pomodoroStartTime += timeLeft
|
||||||
pomodoroTimeLeft = isPomodoroBreak ? pomodoroBreakTime : pomodoroFocusTime
|
timeLeft = isBreak ? breakTime : focusTime
|
||||||
|
|
||||||
let notificationTitle, notificationMessage
|
let notificationTitle, notificationMessage
|
||||||
|
|
||||||
if (isPomodoroBreak && pomodoroCycle % pomodoroLongBreakCycle === 0) { // isPomodoroLongBreak
|
if (isBreak && pomodoroCycle % longBreakCycle === 0) { // isPomodoroLongBreak
|
||||||
notificationMessage = Translation.tr(`Relax for %1 minutes`).arg(Math.floor(pomodoroLongBreakTime / 60))
|
notificationMessage = Translation.tr(`Relax for %1 minutes`).arg(Math.floor(longBreakTime / 60))
|
||||||
} else if (isPomodoroBreak) {
|
} else if (isBreak) {
|
||||||
notificationMessage = Translation.tr(`Relax for %1 minutes`).arg(Math.floor(pomodoroBreakTime / 60))
|
notificationMessage = Translation.tr(`Relax for %1 minutes`).arg(Math.floor(breakTime / 60))
|
||||||
} else {
|
} else {
|
||||||
notificationMessage = Translation.tr(`Focus for %1 minutes`).arg(Math.floor(pomodoroFocusTime / 60))
|
notificationMessage = Translation.tr(`Focus for %1 minutes`).arg(Math.floor(focusTime / 60))
|
||||||
pomodoroCycle += 1
|
pomodoroCycle += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
Quickshell.execDetached(["notify-send", "Pomodoro", notificationMessage, "-a", "Shell"])
|
Quickshell.execDetached(["notify-send", "Pomodoro", notificationMessage, "-a", "Shell"])
|
||||||
|
if (alertSound) { // Play sound only if alertSound is explicitly specified
|
||||||
|
Quickshell.execDetached(["bash", "-c", `ffplay -nodisp -autoexit ${alertSound}`])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A nice abstraction for resume logic by updating the TimeStarted
|
// A nice abstraction for resume logic by updating the TimeStarted
|
||||||
getPomodoroSecondsLeft = (pomodoroTimeStarted + pomodoroTimeLeft) - getCurrentTimeInSeconds()
|
getPomodoroSecondsLeft = (pomodoroStartTime + timeLeft) - getCurrentTimeInSeconds()
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCurrentTimeInSeconds() { // Pomodoro uses Seconds
|
function getCurrentTimeInSeconds() { // Pomodoro uses Seconds
|
||||||
@@ -82,8 +90,8 @@ Singleton {
|
|||||||
return Math.floor(Date.now() / 10)
|
return Math.floor(Date.now() / 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
function tick10ms() { // stopwatch stores time in 10ms
|
function refreshStopwatch() { // stopwatch stores time in 10ms
|
||||||
stopwatchTime = getCurrentTimeIn10ms() - stopwatchStartTime
|
stopwatchTime = getCurrentTimeIn10ms() - stopwatchStart
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stopwatch functions
|
// Stopwatch functions
|
||||||
@@ -91,20 +99,28 @@ Singleton {
|
|||||||
isStopwatchRunning = !isStopwatchRunning
|
isStopwatchRunning = !isStopwatchRunning
|
||||||
if (isStopwatchRunning) {
|
if (isStopwatchRunning) {
|
||||||
// Resume from paused time by adjusting start time
|
// Resume from paused time by adjusting start time
|
||||||
stopwatchStartTime = getCurrentTimeIn10ms() - stopwatchTime
|
stopwatchStart = getCurrentTimeIn10ms() - stopwatchTime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopwatchResetOrLaps() {
|
||||||
|
if (isStopwatchRunning) { // Clicked on Lap
|
||||||
|
recordLaps()
|
||||||
|
} else { // Clicked on Reset
|
||||||
|
stopwatchReset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopwatchReset() {
|
function stopwatchReset() {
|
||||||
if (isStopwatchRunning) { // Clicked on Lap
|
isStopwatchRunning = false
|
||||||
|
stopwatchTime = 0
|
||||||
|
stopwatchStart = 0
|
||||||
|
stopwatchLaps = []
|
||||||
|
}
|
||||||
|
|
||||||
|
function recordLaps() {
|
||||||
stopwatchLaps.unshift(stopwatchTime) // Last lap goes first on list
|
stopwatchLaps.unshift(stopwatchTime) // Last lap goes first on list
|
||||||
// Reassign to trigger onListChanged, idk copied from Todo.qml
|
// Reassign to trigger onListChanged, idk copied from Todo.qml
|
||||||
root.stopwatchLaps = stopwatchLaps.slice(0)
|
root.stopwatchLaps = stopwatchLaps.slice(0)
|
||||||
} else { // Clicked on Reset
|
|
||||||
isStopwatchRunning = false
|
|
||||||
stopwatchTime = 0
|
|
||||||
stopwatchStartTime = 0
|
|
||||||
stopwatchLaps = []
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user