Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ futures = "0.3.0"
ashpd = "0.6.0"
async-channel = "2.1.0"
relm4-macros = { version = "0.6.2", features = [], default-features = false }
rodio = "0.14"
6 changes: 3 additions & 3 deletions build-aux/com.ranfdev.Notify.Devel.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"id": "com.ranfdev.Notify.Devel",
"runtime": "org.gnome.Platform",
"runtime-version": "master",
"sdk": "org.gnome.Sdk",
"runtime": "org.freedesktop.Platform",
"runtime-version": "23.08",
"sdk": "org.freedesktop.Sdk",
"sdk-extensions": [
"org.freedesktop.Sdk.Extension.rust-stable",
"org.freedesktop.Sdk.Extension.llvm16"
Expand Down
24 changes: 24 additions & 0 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use std::path::Path;
use std::path::PathBuf;
use std::pin::Pin;
use std::rc::Rc;
use std::io::Cursor;

use rodio::{Decoder, OutputStream, Sink};
use adw::prelude::*;
use adw::subclass::prelude::*;
use capnp_rpc::{rpc_twoparty_capnp, twoparty, RpcSystem};
Expand Down Expand Up @@ -288,6 +290,9 @@ impl NotifyApplication {
}

app.send_notification(None, &gio_notif);
if let Err(e) = play_sound() {
eprintln!("Error playing sound: {}", e);
}
}
});
struct Proxies {
Expand Down Expand Up @@ -357,6 +362,25 @@ impl NotifyApplication {
}
}

fn play_sound() -> Result<(), Box<dyn std::error::Error>> {
// Initialize the audio output stream
let (_stream, stream_handle) = OutputStream::try_default()?;

// Create a new sink (a way to control audio playback)
let sink = Sink::try_new(&stream_handle)?;

// Use the sound file bundled at compile time
let sound_data = include_bytes!("./notification.wav");
let cursor = Cursor::new(sound_data);
let source = Decoder::new(cursor)?;

// Play the sound
sink.append(source);
sink.sleep_until_end();

Ok(())
}

impl Default for NotifyApplication {
fn default() -> Self {
glib::Object::builder()
Expand Down
Binary file added src/notification.wav
Binary file not shown.