forked from Shinonome/dots-hyprland
pomodoro: remove unused notificationTitle var, format
This commit is contained in:
@@ -35,15 +35,16 @@ Singleton {
|
|||||||
|
|
||||||
// General
|
// General
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
if (!isStopwatchRunning) stopwatchReset()
|
if (!isStopwatchRunning)
|
||||||
|
stopwatchReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCurrentTimeInSeconds() { // Pomodoro uses Seconds
|
function getCurrentTimeInSeconds() { // Pomodoro uses Seconds
|
||||||
return Math.floor(Date.now() / 1000)
|
return Math.floor(Date.now() / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCurrentTimeIn10ms() { // Stopwatch uses 10ms
|
function getCurrentTimeIn10ms() { // Stopwatch uses 10ms
|
||||||
return Math.floor(Date.now() / 10)
|
return Math.floor(Date.now() / 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pomodoro
|
// Pomodoro
|
||||||
@@ -51,32 +52,31 @@ Singleton {
|
|||||||
// Work <-> break ?
|
// Work <-> break ?
|
||||||
if (getCurrentTimeInSeconds() >= Persistent.states.timer.pomodoro.start + pomodoroLapDuration) {
|
if (getCurrentTimeInSeconds() >= Persistent.states.timer.pomodoro.start + pomodoroLapDuration) {
|
||||||
// Reset counts
|
// Reset counts
|
||||||
const currentTimeInSeconds = getCurrentTimeInSeconds()
|
const currentTimeInSeconds = getCurrentTimeInSeconds();
|
||||||
Persistent.states.timer.pomodoro.isBreak = !Persistent.states.timer.pomodoro.isBreak
|
Persistent.states.timer.pomodoro.isBreak = !Persistent.states.timer.pomodoro.isBreak;
|
||||||
Persistent.states.timer.pomodoro.isLongBreak = Persistent.states.timer.pomodoro.isBreak && (pomodoroCycle + 1 == cyclesBeforeLongBreak)
|
Persistent.states.timer.pomodoro.isLongBreak = Persistent.states.timer.pomodoro.isBreak && (pomodoroCycle + 1 == cyclesBeforeLongBreak);
|
||||||
Persistent.states.timer.pomodoro.start = currentTimeInSeconds
|
Persistent.states.timer.pomodoro.start = currentTimeInSeconds;
|
||||||
|
|
||||||
// Send notification
|
// Send notification
|
||||||
let notificationTitle, notificationMessage
|
let notificationMessage;
|
||||||
if (Persistent.states.timer.pomodoro.isBreak && pomodoroCycle % cyclesBeforeLongBreak === 0) { // isPomodoroLongBreak
|
if (Persistent.states.timer.pomodoro.isLongBreak) {
|
||||||
notificationMessage = Translation.tr(`Relax for %1 minutes`).arg(Math.floor(longBreakTime / 60))
|
notificationMessage = Translation.tr(`Relax for %1 minutes`).arg(Math.floor(longBreakTime / 60));
|
||||||
} else if (Persistent.states.timer.pomodoro.isBreak) {
|
} else if (Persistent.states.timer.pomodoro.isBreak) {
|
||||||
notificationMessage = Translation.tr(`Relax for %1 minutes`).arg(Math.floor(breakTime / 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(focusTime / 60))
|
notificationMessage = Translation.tr(`Focus for %1 minutes`).arg(Math.floor(focusTime / 60));
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
if (alertSound)
|
||||||
Quickshell.execDetached(["ffplay", "-nodisp", "-autoexit", alertSound])
|
Quickshell.execDetached(["ffplay", "-nodisp", "-autoexit", alertSound]);
|
||||||
}
|
|
||||||
|
|
||||||
if (!isBreak) {
|
if (!isBreak) {
|
||||||
Persistent.states.timer.pomodoro.cycle = (Persistent.states.timer.pomodoro.cycle + 1) % root.cyclesBeforeLongBreak;
|
Persistent.states.timer.pomodoro.cycle = (Persistent.states.timer.pomodoro.cycle + 1) % root.cyclesBeforeLongBreak;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pomodoroSecondsLeft = pomodoroLapDuration - (getCurrentTimeInSeconds() - Persistent.states.timer.pomodoro.start)
|
pomodoroSecondsLeft = pomodoroLapDuration - (getCurrentTimeInSeconds() - Persistent.states.timer.pomodoro.start);
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
@@ -88,23 +88,24 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function togglePomodoro() {
|
function togglePomodoro() {
|
||||||
Persistent.states.timer.pomodoro.running = !isPomodoroRunning
|
Persistent.states.timer.pomodoro.running = !isPomodoroRunning;
|
||||||
if (Persistent.states.timer.pomodoro.running) { // Start/Resume
|
if (Persistent.states.timer.pomodoro.running) {
|
||||||
Persistent.states.timer.pomodoro.start = getCurrentTimeInSeconds() + pomodoroSecondsLeft - pomodoroLapDuration
|
// Start/Resume
|
||||||
|
Persistent.states.timer.pomodoro.start = getCurrentTimeInSeconds() + pomodoroSecondsLeft - pomodoroLapDuration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetPomodoro() {
|
function resetPomodoro() {
|
||||||
Persistent.states.timer.pomodoro.running = false
|
Persistent.states.timer.pomodoro.running = false;
|
||||||
Persistent.states.timer.pomodoro.isBreak = false
|
Persistent.states.timer.pomodoro.isBreak = false;
|
||||||
Persistent.states.timer.pomodoro.start = getCurrentTimeInSeconds()
|
Persistent.states.timer.pomodoro.start = getCurrentTimeInSeconds();
|
||||||
Persistent.states.timer.pomodoro.cycle = 0
|
Persistent.states.timer.pomodoro.cycle = 0;
|
||||||
refreshPomodoro()
|
refreshPomodoro();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stopwatch
|
// Stopwatch
|
||||||
function refreshStopwatch() { // Stopwatch stores time in 10ms
|
function refreshStopwatch() { // Stopwatch stores time in 10ms
|
||||||
stopwatchTime = getCurrentTimeIn10ms() - stopwatchStart
|
stopwatchTime = getCurrentTimeIn10ms() - stopwatchStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
@@ -117,28 +118,28 @@ Singleton {
|
|||||||
|
|
||||||
function toggleStopwatch() {
|
function toggleStopwatch() {
|
||||||
if (root.isStopwatchRunning)
|
if (root.isStopwatchRunning)
|
||||||
stopwatchPause()
|
stopwatchPause();
|
||||||
else
|
else
|
||||||
stopwatchResume()
|
stopwatchResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopwatchPause() {
|
function stopwatchPause() {
|
||||||
Persistent.states.timer.stopwatch.running = false
|
Persistent.states.timer.stopwatch.running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopwatchResume() {
|
function stopwatchResume() {
|
||||||
Persistent.states.timer.stopwatch.running = true
|
Persistent.states.timer.stopwatch.running = true;
|
||||||
Persistent.states.timer.stopwatch.start = getCurrentTimeIn10ms() - stopwatchTime
|
Persistent.states.timer.stopwatch.start = getCurrentTimeIn10ms() - stopwatchTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopwatchReset() {
|
function stopwatchReset() {
|
||||||
Persistent.states.timer.stopwatch.running = false
|
Persistent.states.timer.stopwatch.running = false;
|
||||||
stopwatchTime = 0
|
stopwatchTime = 0;
|
||||||
Persistent.states.timer.stopwatch.start = getCurrentTimeIn10ms()
|
Persistent.states.timer.stopwatch.start = getCurrentTimeIn10ms();
|
||||||
Persistent.states.timer.stopwatch.laps = []
|
Persistent.states.timer.stopwatch.laps = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopwatchRecordLap() {
|
function stopwatchRecordLap() {
|
||||||
Persistent.states.timer.stopwatch.laps.push(stopwatchTime)
|
Persistent.states.timer.stopwatch.laps.push(stopwatchTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user