diff --git a/Cargo.toml b/Cargo.toml index 69caff8..7ed5d9d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,8 +3,6 @@ name = "libnotify-rs" version = "0.1.0" edition = "2024" -[dependencies] - [build-dependencies] pkg-config = "0.3.34" bindgen = "0.73.2" diff --git a/src/functions.rs b/src/functions.rs index d70f3e3..f8992ec 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -5,25 +5,26 @@ include!(concat!(env!("OUT_DIR"), "/bindings.rs")); /// Starting from 0.8, if the provided app_name is NULL, libnotify will try to figure it out from the running application. Before it was not allowed, and was causing libnotify not to be initialized. /// /// # Returns -/// True if successful, false if libnotify fails to initialize, error if string contains \0 -pub fn init<'a, T>(app_name: T) -> Result> +/// TRUE if successful, or FALSE on error +pub fn init<'a, T>(app_name: T) -> bool where T: Into>, { - let app_name = app_name + match app_name .into() .map(|app_name| std::ffi::CString::new(app_name)) - .transpose()?; + .transpose() + { + Ok(app_name) => unsafe { + notify_init( + app_name + .as_ref() + .map_or(std::ptr::null(), |app_name| app_name.as_ptr()), + ) != 0 + }, - let result = unsafe { - notify_init( - app_name - .as_ref() - .map_or(std::ptr::null(), |app_name| app_name.as_ptr()), - ) != 0 - }; - - Ok(result) + Err(_) => return false, + } } /// Uninitializes libnotify. @@ -33,3 +34,22 @@ pub fn uninit() { notify_uninit(); } } + +/// Gets whether or not libnotify is initialized. +pub fn is_initted() -> bool { + unsafe { notify_is_initted() != 0 } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_initializing() { + assert!(!is_initted()); + assert!(init("Morbius")); + assert!(is_initted()); + uninit(); + assert!(!is_initted()); + } +}