diff --git a/AGENTS.md b/AGENTS.md index 5a2247f..4d45211 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -281,6 +281,11 @@ git push origin release/v git-api pr create --title "release: Version " --body "..." ``` +## Git Rules + +- **NEVER `--amend` unless you verify HEAD is your commit first** — always run `git log --oneline -1` before amending to confirm you're amending the right commit. +- **When a commit fails (hooks modified files), just commit again normally** — do NOT use `--amend`, or you'll amend the parent commit. Simply stage the changes and `git commit -m "..."` again. + ### Note on Protected Branches The `master` branch is protected. Releases must go through a PR. After merge, tagging and GitHub release are automated. diff --git a/src/timer.rs b/src/timer.rs index 3aff99c..f25ebfa 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -103,6 +103,31 @@ where } } +fn play_beep() -> Result<()> { + for _ in 0..BEEP_REPETITIONS { + sleep(stdDuration::from_millis(SOUND_START_DELAY)); + if beep(BEEP_FREQ, stdDuration::from_millis(BEEP_DURATION)).is_err() { + sleep(stdDuration::from_millis(BEEP_DURATION)); + } + + let remaining_delay = BEEP_DELAY.saturating_sub(SOUND_START_DELAY); + if remaining_delay > 0 { + sleep(stdDuration::from_millis(remaining_delay)); + } + } + Ok(()) +} + +fn play_sound() -> Result<()> { + let sound = Sound::new()?; + + for _ in 0..BEEP_REPETITIONS { + sound.play()?; + sleep(stdDuration::from_millis(BEEP_DELAY)); + } + Ok(()) +} + pub fn countdown(w: &mut W, end: OffsetDateTime, opts: &Opts) -> Result<()> where W: io::Write, @@ -123,23 +148,9 @@ where } if !opts.silence { - match Sound::new() { - Ok(sound) => { - for _ in 0..BEEP_REPETITIONS { - sleep(stdDuration::from_millis(SOUND_START_DELAY)); - if beep(BEEP_FREQ, stdDuration::from_millis(BEEP_DURATION)).is_err() - { - sleep(stdDuration::from_millis(BEEP_DURATION)); - } - - if sound.play().is_err() { - break; - } - sleep(stdDuration::from_millis(BEEP_DELAY)); - } - } - Err(e) => return Err(e), - } + let sound_handle = std::thread::spawn(|| play_sound().unwrap()); + play_beep()?; + sound_handle.join().map_err(|_| "Sound thread panicked")?; } return Ok(()); }