mirror of
https://github.com/szymon-jozef/libnotify-rs.git
synced 2026-10-27 19:20:43 +01:00
fix: change show method to return libnotify error
This commit is contained in:
@@ -273,19 +273,19 @@ impl<'a> Notification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Tells the notification server to display the notification on the screen
|
/// Tells the notification server to display the notification on the screen
|
||||||
pub fn show(&self) -> Result<(), Box<dyn std::error::Error>> {
|
pub fn show(&self) -> Result<(), LibnotifyError> {
|
||||||
let mut gerror = std::ptr::null_mut() as *mut GError;
|
let mut gerror = std::ptr::null_mut() as *mut GError;
|
||||||
|
|
||||||
if unsafe { notify_notification_show(self.inner, &mut gerror) } == 0 {
|
if unsafe { notify_notification_show(self.inner, &mut gerror) } == 0 {
|
||||||
if gerror.is_null() {
|
if gerror.is_null() {
|
||||||
return Err("Unknown error".into());
|
return Err(LibnotifyError::AllocationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
let err_msg = unsafe { *gerror }.message;
|
let err_msg = unsafe { *gerror }.message;
|
||||||
|
|
||||||
if err_msg.is_null() {
|
if err_msg.is_null() {
|
||||||
unsafe { g_error_free(gerror) };
|
unsafe { g_error_free(gerror) };
|
||||||
return Err("Unknown error".into());
|
return Err(LibnotifyError::AllocationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
let err_msg_str = unsafe { std::ffi::CStr::from_ptr(err_msg) }
|
let err_msg_str = unsafe { std::ffi::CStr::from_ptr(err_msg) }
|
||||||
@@ -293,7 +293,7 @@ impl<'a> Notification {
|
|||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
unsafe { g_error_free(gerror) };
|
unsafe { g_error_free(gerror) };
|
||||||
return Err(err_msg_str.into());
|
return Err(LibnotifyError::GerrorError(err_msg_str));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user