use lingxia_platform::ScreenInfo;
use lingxia_platform::traits::device::Device;
use lingxia_platform::traits::location::Location;
use lingxia_platform::traits::wifi::Wifi;
use serde::Serialize;
#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct DeviceInfo {
pub brand: String,
pub model: String,
pub market_name: String,
pub os_name: String,
pub os_version: String,
}
impl From<lingxia_platform::DeviceInfo> for DeviceInfo {
fn from(info: lingxia_platform::DeviceInfo) -> Self {
Self {
brand: info.brand,
model: info.model,
market_name: info.market_name,
os_name: info.os_name,
os_version: info.os_version,
}
}
}
#[derive(Debug, Clone, Copy, Serialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct SystemSettings {
pub wifi_enabled: bool,
pub location_enabled: bool,
}
pub fn info() -> crate::Result<DeviceInfo> {
Ok(crate::runtime::platform()?.device_info().into())
}
pub fn screen() -> crate::Result<ScreenInfo> {
Ok(crate::runtime::platform()?.screen_info())
}
pub fn vibrate(long: bool) -> crate::Result<()> {
crate::runtime::platform()?
.vibrate(long)
.map_err(Into::into)
}
pub fn make_phone_call(number: &str) -> crate::Result<()> {
crate::runtime::platform()?
.make_phone_call(number)
.map_err(Into::into)
}
pub fn system_settings() -> crate::Result<SystemSettings> {
let runtime = crate::runtime::platform()?;
let wifi_enabled = runtime.is_wifi_enabled().map_err(crate::Error::from)?;
let location_enabled = runtime.is_location_enabled().map_err(crate::Error::from)?;
Ok(SystemSettings {
wifi_enabled,
location_enabled,
})
}