use std::{cell::RefCell, rc::Rc};
pub trait AppInfo {
fn version_name(&self) -> Option<String>;
fn build_version(&self) -> Option<String>;
}
pub type AppInfoRef = Rc<dyn AppInfo>;
struct DefaultAppInfo;
impl AppInfo for DefaultAppInfo {
fn version_name(&self) -> Option<String> {
None
}
fn build_version(&self) -> Option<String> {
None
}
}
thread_local! {
static PLATFORM_APP_INFO: RefCell<Option<AppInfoRef>> = const { RefCell::new(None) };
}
pub fn set_platform_app_info(info: AppInfoRef) {
PLATFORM_APP_INFO.with(|cell| *cell.borrow_mut() = Some(info));
}
pub fn clear_platform_app_info() {
PLATFORM_APP_INFO.with(|cell| *cell.borrow_mut() = None);
}
pub fn app_info() -> AppInfoRef {
PLATFORM_APP_INFO
.with(|cell| cell.borrow().clone())
.unwrap_or_else(|| Rc::new(DefaultAppInfo))
}
pub fn version_name() -> Option<String> {
app_info().version_name()
}
pub fn build_version() -> Option<String> {
app_info().build_version()
}
#[cfg(test)]
#[path = "tests/app_info_tests.rs"]
mod tests;