use std::sync::atomic::AtomicBool;
use once_cell::sync::OnceCell;
#[cfg(target_os = "android")]
pub mod android;
mod error;
mod handler;
#[cfg(any(test, feature = "mock"))]
pub mod mock;
pub mod models;
pub use error::{Error, Result};
pub use handler::Handler;
pub use handler::{OnDisconnectHandler, SubscriptionHandler};
pub use models::{Timeouts, TimeoutsMs};
pub static ALLOW_IBEACONS: AtomicBool = AtomicBool::new(false);
static HANDLER: OnceCell<Handler> = OnceCell::new();
pub async fn init() -> Result<&'static Handler> {
if let Some(handler) = HANDLER.get() {
return Ok(handler);
}
let handler = Handler::new().await?;
let _ = HANDLER.set(handler);
get_handler()
}
pub fn get_handler() -> Result<&'static Handler> {
let handler = HANDLER.get().ok_or(Error::HandlerNotInitialized)?;
Ok(handler)
}
#[allow(unused)]
pub async fn check_permissions(ask_if_denied: bool) -> Result<bool> {
#[cfg(target_os = "android")]
return android::check_permissions(ask_if_denied).await;
#[cfg(not(target_os = "android"))]
return Ok(true);
}