diff --git a/src/functions.rs b/src/functions.rs new file mode 100644 index 0000000..3c0f2f3 --- /dev/null +++ b/src/functions.rs @@ -0,0 +1,27 @@ +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); + +/// Initialized libnotify. This must be called before any other functions. +/// +/// 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> +where + T: Into>, +{ + let app_name = app_name + .into() + .map(|app_name| std::ffi::CString::new(app_name)) + .transpose()?; + + let result = unsafe { + notify_init( + app_name + .as_ref() + .map_or(std::ptr::null(), |app_name| app_name.as_ptr()), + ) != 0 + }; + + Ok(result) +}