use super::*;
#[must_use]
pub fn detect_current_platform() -> PlatformKind {
#[cfg(target_arch = "wasm32")]
{
PlatformKind::Web
}
#[cfg(target_env = "ohos")]
{
PlatformKind::HarmonyOs
}
#[cfg(target_os = "android")]
{
PlatformKind::Android
}
#[cfg(target_os = "ios")]
{
ios_detect_platform_kind()
}
#[cfg(target_os = "macos")]
{
PlatformKind::MacOs
}
#[cfg(target_os = "windows")]
{
PlatformKind::Windows
}
#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
{
PlatformKind::Linux
}
#[cfg(not(any(target_arch = "wasm32", unix, windows)))]
{
PlatformKind::Headless
}
}
#[must_use]
pub fn create_native_platform() -> Box<dyn PlatformBackend> {
#[cfg(target_arch = "wasm32")]
{
Box::new(WebPlatform::default())
}
#[cfg(target_env = "ohos")]
{
Box::new(HarmonyPlatform::default())
}
#[cfg(target_os = "android")]
{
Box::new(AndroidPlatform::default())
}
#[cfg(target_os = "ios")]
{
Box::new(IosPlatform::default())
}
#[cfg(target_os = "macos")]
{
Box::new(MacOsPlatform::default())
}
#[cfg(target_os = "windows")]
{
Box::new(WindowsPlatform::default())
}
#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
{
Box::new(LinuxPlatform::default())
}
#[cfg(not(any(target_arch = "wasm32", unix, windows)))]
{
Box::new(HeadlessPlatform::default())
}
}
#[must_use]
pub fn create_platform_for_kind(kind: PlatformKind) -> Box<dyn PlatformBackend> {
match kind {
PlatformKind::Terminal => Box::new(TerminalPlatform::with_mode(
TerminalHostMode::InteractiveTui,
)),
PlatformKind::TerminalCli => {
Box::new(TerminalPlatform::with_mode(TerminalHostMode::StaticCli))
}
PlatformKind::Wearable => Box::new(WearablePlatform::default()),
PlatformKind::HarmonyOs => Box::new(HarmonyPlatform::default()),
PlatformKind::MiniApp => Box::new(MiniAppPlatform::default()),
PlatformKind::QuickApp => Box::new(QuickAppPlatform::default()),
PlatformKind::Headless => Box::new(HeadlessPlatform::default()),
other => {
if other == detect_current_platform() {
create_native_platform()
} else {
Box::new(HeadlessPlatform::emulating(
other,
1.0,
SafeAreaInsets::default(),
))
}
}
}
}