mirror of
https://github.com/szymon-jozef/libnotify-rs.git
synced 2026-10-27 19:20:43 +01:00
feat: add libnotify context
This commit is contained in:
40
src/context.rs
Normal file
40
src/context.rs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
use crate::functions::{init, is_initted, set_app_icon, set_app_name, uninit};
|
||||||
|
|
||||||
|
pub struct LibnotifyContext {}
|
||||||
|
|
||||||
|
static IS_CONTEXT_CREATED: std::sync::atomic::AtomicBool =
|
||||||
|
std::sync::atomic::AtomicBool::new(false);
|
||||||
|
|
||||||
|
impl LibnotifyContext {
|
||||||
|
pub fn new(app_name: &str) -> Result<LibnotifyContext, Box<dyn std::error::Error>> {
|
||||||
|
if IS_CONTEXT_CREATED.swap(true, std::sync::atomic::Ordering::SeqCst) {
|
||||||
|
return Err("You can create only one context at a time".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
if !is_initted() {
|
||||||
|
init(app_name)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Self {})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_new_name(&self, app_name: &str) -> Result<(), std::ffi::NulError> {
|
||||||
|
set_app_name(app_name)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_app_icon(&self, app_icon: &str) -> Result<(), std::ffi::NulError> {
|
||||||
|
set_app_icon(app_icon)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for LibnotifyContext {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
if is_initted() {
|
||||||
|
uninit();
|
||||||
|
|
||||||
|
IS_CONTEXT_CREATED.store(false, std::sync::atomic::Ordering::SeqCst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
|
pub mod context;
|
||||||
pub mod functions;
|
pub mod functions;
|
||||||
mod libnotify;
|
mod libnotify;
|
||||||
pub mod notification;
|
pub mod notification;
|
||||||
|
|||||||
Reference in New Issue
Block a user