fix: make sure we don't start playing around sound if one is already playing
This commit is contained in:
+13
-5
@@ -1,5 +1,6 @@
|
||||
use std::sync::mpsc;
|
||||
use std::thread;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{LazyLock, mpsc};
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||
@@ -12,14 +13,21 @@ const NOTE_2_DURATION_SECS: f32 = 0.25;
|
||||
const TOTAL_CHIME_DURATION_SECS: f32 = NOTE_1_DURATION_SECS + NOTE_2_DURATION_SECS;
|
||||
const CHIME_VOLUME_GAIN: f32 = 0.25;
|
||||
|
||||
static SOUND_BUSY: LazyLock<AtomicBool> = LazyLock::new(|| AtomicBool::new(false));
|
||||
|
||||
pub fn play_notification_sound() {
|
||||
thread::spawn(move || {
|
||||
// term bell fallback
|
||||
if SOUND_BUSY.swap(true, Ordering::AcqRel) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::thread::spawn(move || {
|
||||
// term bell fall back
|
||||
print!("\x07");
|
||||
|
||||
let _ = std::io::Write::flush(&mut std::io::stdout());
|
||||
|
||||
let _ = play_audio_chime();
|
||||
|
||||
SOUND_BUSY.store(false, Ordering::Release);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user