Config notification/toast sound (#179)
* try adding config to load different sound looks like include_bytes!() doesn't take a variable parameter, so will need a different solution lol. * no errors in loading, but toast.rs now has a lifetime issue * hey, config toast sound works now! the sound is loaded in AppState now, since Toast are created in several different places at different times, and i don't want to load the sound every time a toast is made. also put back the original sound since i accidentally commited my custom one. * clean up * change custom toast sound leak to happen on load rather than every play * move toast sound loading into a function so it can be reused in the future, for example if we want to load arbitrary keypress sounds or other [u8] data. * remove label from try_load_bytes, return early when failing
This commit is contained in:
@@ -18,7 +18,6 @@ use crate::{
|
||||
const FONT_SIZE: isize = 16;
|
||||
const PADDING: (f32, f32) = (25., 7.);
|
||||
const PIXELS_TO_METERS: f32 = 1. / 2000.;
|
||||
const TOAST_AUDIO_WAV: &[u8] = include_bytes!("../res/557297.wav");
|
||||
static TOAST_NAME: Lazy<Arc<str>> = Lazy::new(|| "toast".into());
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
@@ -78,6 +77,9 @@ impl Toast {
|
||||
let destroy_at = instant.add(std::time::Duration::from_secs_f32(self.timeout));
|
||||
|
||||
let has_sound = self.sound && app.session.config.notifications_sound_enabled;
|
||||
if has_sound {
|
||||
app.audio.play(app.toast_sound);
|
||||
}
|
||||
|
||||
// drop any toast that was created before us.
|
||||
// (DropOverlay only drops overlays that were
|
||||
@@ -109,9 +111,6 @@ impl Toast {
|
||||
instant,
|
||||
);
|
||||
|
||||
if has_sound {
|
||||
app.audio.play(TOAST_AUDIO_WAV);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user