From 260035ca3cd2d0c9a414bab27da54679772062ac Mon Sep 17 00:00:00 2001 From: Victor Azevedo <34415964+victrme@users.noreply.github.com> Date: Fri, 9 Jan 2026 07:27:38 +0100 Subject: [PATCH 1/9] Add UI, update, types for pomodoro alarms --- src/scripts/defaults.ts | 2 ++ src/scripts/features/pomodoro.ts | 53 ++++++++++++++++++++------------ src/scripts/settings.ts | 9 ++++++ src/settings.html | 29 +++++++++++++++++ src/types/sync.ts | 2 ++ 5 files changed, 75 insertions(+), 20 deletions(-) diff --git a/src/scripts/defaults.ts b/src/scripts/defaults.ts index b7432b95b..e97c07189 100644 --- a/src/scripts/defaults.ts +++ b/src/scripts/defaults.ts @@ -203,6 +203,8 @@ export const SYNC_DEFAULT: Sync = { }, focus: false, sound: true, + volume: 0.6, + alarm: 'default', history: [], }, font: { diff --git a/src/scripts/features/pomodoro.ts b/src/scripts/features/pomodoro.ts index e2ce450dc..e72596f4f 100644 --- a/src/scripts/features/pomodoro.ts +++ b/src/scripts/features/pomodoro.ts @@ -15,8 +15,10 @@ type PomodoroUpdate = { mode?: PomodoroMode pause?: number focus?: boolean - timeFor?: Partial> sound?: boolean + volume?: number + alarm?: string + timeFor?: Partial> history?: { endedAt: string; duration?: number } } @@ -27,8 +29,6 @@ type PomodoroHistoryEntry = { let currentPomodoroData: Pomodoro -const alarmSound = new Audio('src/assets/sounds/clock-alarm-classic.mp3') - const pomodoroContainer = document.getElementById('pomodoro_container') as HTMLDivElement const pomodoroStart = document.getElementById('pmdr_start') as HTMLButtonElement const pomodoroPause = document.getElementById('pmdr_pause') as HTMLButtonElement @@ -466,12 +466,15 @@ export function togglePomodoroFocus(focus: boolean) { } function ringTheAlarm() { + const alarmSound = new Audio('src/assets/sounds/clock-alarm-classic.mp3') + // only triggers on the last active tab const lastTab = localStorage.getItem('lastActiveTab') const willRingAndSave = lastTab === TAB_ID if (willRingAndSave) { if (currentPomodoroData.sound) { + alarmSound.volume = 0.6 alarmSound.play() } @@ -522,42 +525,52 @@ function setPomodoroInfo(history: PomodoroHistoryEntry[]) { ;(document.getElementById('poms-month') as HTMLSpanElement).textContent = pomsMonth.toString() } -async function updatePomodoro({ on, sound, end, mode, pause, focus, timeFor, history }: PomodoroUpdate) { +async function updatePomodoro(update: PomodoroUpdate) { const data = await storage.sync.get(['pomodoro']) - if (on !== undefined) { - data.pomodoro.on = on + if (update.on !== undefined) { + data.pomodoro.on = update.on } - if (sound !== undefined) { - data.pomodoro.sound = sound + if (update.sound !== undefined) { + data.pomodoro.sound = update.sound } - if (end !== undefined) { - data.pomodoro.end = end + if (update.alarm) { + console.log(update.alarm) } - if (mode) { - data.pomodoro.mode = mode + if (update.volume) { + console.log(update.volume) } - if (pause !== undefined) { - data.pomodoro.pause = pause + if (update.end !== undefined) { + data.pomodoro.end = update.end } - if (focus !== undefined) { - data.pomodoro.focus = focus + if (update.mode) { + data.pomodoro.mode = update.mode } - if (history !== undefined) { + if (update.pause !== undefined) { + data.pomodoro.pause = update.pause + } + + if (update.focus !== undefined) { + data.pomodoro.focus = update.focus + } + + if (update.history !== undefined) { data.pomodoro.history.push({ - endedAt: history.endedAt, + endedAt: update.history.endedAt, duration: data.pomodoro.timeFor['pomodoro'], }) } // the time defined by the user for each mode (pomodoro, break...) - if (timeFor) { + if (update.timeFor) { + const {timeFor} = update + for (const mode of Object.keys(timeFor) as PomodoroMode[]) { const value = timeFor[mode] @@ -574,7 +587,7 @@ async function updatePomodoro({ on, sound, end, mode, pause, focus, timeFor, his // known flaw: sessions are only up to date on the ringing tab setPomodoroInfo(data.pomodoro.history) - if (timeFor) { + if (update.timeFor) { resetTimer() } } diff --git a/src/scripts/settings.ts b/src/scripts/settings.ts index 6309ec9b7..19e9e6b98 100644 --- a/src/scripts/settings.ts +++ b/src/scripts/settings.ts @@ -886,6 +886,14 @@ function initOptionsEvents() { pomodoro(undefined, { sound: target.checked }) }) + paramId('i_pmdr_alarms').addEventListener('change', function () { + pomodoro(undefined, { alarm: this.value }) + }) + + paramId('i_pmdr_volume').addEventListener('input', function () { + pomodoro(undefined, { volume: Number(this.value) }) + }) + paramId('i_pmdr_pomodoro').addEventListener('input', function () { pomodoro(undefined, { timeFor: { pomodoro: Number(this.value) } }) }) @@ -898,6 +906,7 @@ function initOptionsEvents() { pomodoro(undefined, { timeFor: { longbreak: Number(this.value) } }) }) + // paramId('i_pmdr_pomodoro').addEventListener('change', () => { // paramId('i_pmdr_pomodoro').blur() // }) diff --git a/src/settings.html b/src/settings.html index 28e2b67df..709ffadd4 100644 --- a/src/settings.html +++ b/src/settings.html @@ -1681,6 +1681,35 @@

Pomodoro timer