diff options
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | desktop/src/App.css | 2 | ||||
| -rw-r--r-- | desktop/src/components/PixelTimer.tsx | 2 | ||||
| -rw-r--r-- | desktop/src/hooks/useTimer.ts | 10 | ||||
| -rw-r--r-- | desktop/src/lib/sounds.ts | 87 |
5 files changed, 101 insertions, 3 deletions
@@ -2,11 +2,12 @@ # pomoru -A minimalist Pomodoro TUI with a task list, written in Rust. +A minimalist Pomodoro TUI (& GUI) with a task list, written in Rust.    +   diff --git a/desktop/src/App.css b/desktop/src/App.css index fc05349..aa84ce2 100644 --- a/desktop/src/App.css +++ b/desktop/src/App.css @@ -340,7 +340,7 @@ .ascii-art-timer { font-family: "JetBrains Mono", "Courier New", monospace; - font-size: 10px; + font-size: 14px; line-height: 1.1; letter-spacing: -0.05em; font-weight: 700; diff --git a/desktop/src/components/PixelTimer.tsx b/desktop/src/components/PixelTimer.tsx index 5ad2904..010bd62 100644 --- a/desktop/src/components/PixelTimer.tsx +++ b/desktop/src/components/PixelTimer.tsx @@ -129,7 +129,7 @@ export default function PixelTimer({ timer, onSetDuration }: PixelTimerProps) { if (e.key === "Enter" || e.key === " ") handleStartEdit(); }} > - <div style={{ display: "flex", gap: "12px", alignItems: "center" }}> + <div style={{ display: "flex", gap: "20px", alignItems: "center" }}> {timeStr.split("").map((char, index) => ( <AnimatedDigit key={index} char={char} mode={timer.mode} /> ))} diff --git a/desktop/src/hooks/useTimer.ts b/desktop/src/hooks/useTimer.ts index 408a6b0..06fa720 100644 --- a/desktop/src/hooks/useTimer.ts +++ b/desktop/src/hooks/useTimer.ts @@ -1,5 +1,6 @@ import { useState, useEffect, useRef, useCallback } from "react"; import { commands, type TimerState, type TickResult } from "../lib/commands"; +import { playWorkDoneSound, playBreakDoneSound } from "../lib/sounds"; export function useTimer() { const [timer, setTimer] = useState<TimerState | null>(null); @@ -15,6 +16,15 @@ export function useTimer() { if (timer?.is_running) { intervalRef.current = setInterval(async () => { const result: TickResult = await commands.tick(); + + if (result.event) { + if (result.timer.mode === "work") { + playBreakDoneSound(); // Break finished, wake up for work + } else { + playWorkDoneSound(); // Work finished, relax for break + } + } + setTimer(result.timer); }, 1000); } else { diff --git a/desktop/src/lib/sounds.ts b/desktop/src/lib/sounds.ts new file mode 100644 index 0000000..99ef7d5 --- /dev/null +++ b/desktop/src/lib/sounds.ts @@ -0,0 +1,87 @@ +let audioCtx: AudioContext | null = null; + +function getAudioContext() { + if (!audioCtx) { + audioCtx = new (window.AudioContext || (window as any).webkitAudioContext)(); + } + return audioCtx; +} + +export function playWorkDoneSound() { + const ctx = getAudioContext(); + if (ctx.state === "suspended") ctx.resume(); + + const now = ctx.currentTime; + + // Relaxing, dreamy Cmaj9 chord (C4, E4, G4, B4, D5) + // Strummed slowly like a soft kalimba or meditation bowl + const notes = [261.63, 329.63, 392.00, 493.88, 587.33]; + notes.forEach((freq, i) => { + playTone(ctx, freq, now + i * 0.06, 4.0); + }); +} + +export function playBreakDoneSound() { + const ctx = getAudioContext(); + if (ctx.state === "suspended") ctx.resume(); + + const now = ctx.currentTime; + + // Bright, uplifting Fmaj9 chord (F4, A4, C5, E5, G5) + const notes = [349.23, 440.00, 523.25, 659.25, 783.99]; + notes.forEach((freq, i) => { + playTone(ctx, freq, now + i * 0.06, 4.0); + }); +} + +function playTone(ctx: AudioContext, frequency: number, startTime: number, duration: number) { + // 1. Fundamental body (warm sine) + const osc1 = ctx.createOscillator(); + const gain1 = ctx.createGain(); + osc1.type = "sine"; + osc1.frequency.setValueAtTime(frequency, startTime); + + gain1.gain.setValueAtTime(0, startTime); + // Soft attack, long decay (Volume drastically reduced to support chords without clipping) + gain1.gain.linearRampToValueAtTime(0.08, startTime + 0.05); + gain1.gain.exponentialRampToValueAtTime(0.001, startTime + duration); + + osc1.connect(gain1); + gain1.connect(ctx.destination); + + osc1.start(startTime); + osc1.stop(startTime + duration); + + // 2. Kalimba metallic overtone (inharmonic triangle) + const osc2 = ctx.createOscillator(); + const gain2 = ctx.createGain(); + osc2.type = "triangle"; + osc2.frequency.setValueAtTime(frequency * 3.14, startTime); + + gain2.gain.setValueAtTime(0, startTime); + // Fast attack, short decay for the woody "tink" + gain2.gain.linearRampToValueAtTime(0.02, startTime + 0.01); + gain2.gain.exponentialRampToValueAtTime(0.001, startTime + 0.3); + + osc2.connect(gain2); + gain2.connect(ctx.destination); + + osc2.start(startTime); + osc2.stop(startTime + 0.3); + + // 3. Thumb pluck transient (high frequency click) + const osc3 = ctx.createOscillator(); + const gain3 = ctx.createGain(); + osc3.type = "sine"; + osc3.frequency.setValueAtTime(frequency * 6.5, startTime); + + gain3.gain.setValueAtTime(0, startTime); + gain3.gain.linearRampToValueAtTime(0.01, startTime + 0.002); + gain3.gain.exponentialRampToValueAtTime(0.001, startTime + 0.05); + + osc3.connect(gain3); + gain3.connect(ctx.destination); + + osc3.start(startTime); + osc3.stop(startTime + 0.05); +} |