use rosace_state::GlobalAtom;
use rosace_trace::event::AtomId;
const PLATFORM_ATOM_ID: AtomId = AtomId(0xFFFD);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Platform {
MacOs,
Windows,
Linux,
Ios,
Android,
Web,
}
impl Platform {
pub fn detect() -> Self {
#[cfg(target_arch = "wasm32")]
return Platform::Web;
#[cfg(target_os = "macos")]
return Platform::MacOs;
#[cfg(target_os = "windows")]
return Platform::Windows;
#[cfg(target_os = "linux")]
return Platform::Linux;
#[cfg(target_os = "ios")]
return Platform::Ios;
#[cfg(target_os = "android")]
return Platform::Android;
#[allow(unreachable_code)]
Platform::Linux
}
pub fn is_desktop(&self) -> bool {
matches!(self, Platform::MacOs | Platform::Windows | Platform::Linux)
}
pub fn is_mobile(&self) -> bool {
matches!(self, Platform::Ios | Platform::Android)
}
}
static CURRENT_PLATFORM: GlobalAtom<Platform> = GlobalAtom::new(PLATFORM_ATOM_ID, Platform::detect);
pub fn use_platform() -> Platform {
CURRENT_PLATFORM.get()
}
pub fn set_platform(p: Platform) {
CURRENT_PLATFORM.set(p);
}