use serde_json::Value;
use tishlang_core::Value as TishValue;
mod android;
mod apple;
mod lin;
mod ms;
#[allow(unused_imports)]
pub use android::AndroidPlatformHost;
#[allow(unused_imports)]
pub use apple::ApplePlatformHost;
#[allow(unused_imports)]
pub use lin::LinPlatformHost;
#[allow(unused_imports)]
pub use ms::MsPlatformHost;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PlatformId {
Apple,
Ms,
Lin,
Android,
DesktopTauri,
}
pub trait PlatformHost: Send + Sync {
fn id(&self) -> PlatformId;
fn name(&self) -> &'static str;
fn supports_native_surface(&self) -> bool;
fn attach_native(&self, _root: &TishValue, _options: &Value) -> Result<Value, String> {
Err("native attach unsupported on this platform".into())
}
}
pub fn current_host() -> Box<dyn PlatformHost> {
#[cfg(all(feature = "platform-apple", target_os = "macos"))]
{
return Box::new(ApplePlatformHost);
}
#[cfg(all(feature = "platform-ms", target_os = "windows"))]
{
return Box::new(MsPlatformHost);
}
#[cfg(all(feature = "platform-lin", target_os = "linux"))]
{
return Box::new(LinPlatformHost);
}
#[cfg(all(feature = "platform-ms", not(target_os = "windows"), not(all(feature = "platform-apple", target_os = "macos"))))]
{
return Box::new(MsPlatformHost);
}
#[cfg(all(feature = "platform-lin", not(target_os = "linux"), not(feature = "platform-ms"), not(all(feature = "platform-apple", target_os = "macos"))))]
{
return Box::new(LinPlatformHost);
}
#[cfg(all(feature = "platform-android", target_os = "android"))]
{
return Box::new(AndroidPlatformHost);
}
#[cfg(all(
feature = "platform-android",
not(target_os = "android"),
not(feature = "platform-ms"),
not(feature = "platform-lin"),
not(all(feature = "platform-apple", target_os = "macos"))
))]
{
return Box::new(AndroidPlatformHost);
}
Box::new(DesktopOnlyHost)
}
struct DesktopOnlyHost;
impl PlatformHost for DesktopOnlyHost {
fn id(&self) -> PlatformId {
PlatformId::DesktopTauri
}
fn name(&self) -> &'static str {
"desktop-tauri"
}
fn supports_native_surface(&self) -> bool {
false
}
}