use serde::de::DeserializeOwned;
use tauri::{
plugin::{PluginApi, PluginHandle},
AppHandle, Runtime,
};
use crate::models::*;
#[cfg(target_os = "ios")]
tauri::ios_plugin_binding!(init_plugin_healthkit);
pub fn init<R: Runtime, C: DeserializeOwned>(
_app: &AppHandle<R>,
api: PluginApi<R, C>,
) -> crate::Result<Healthkit<R>> {
#[cfg(target_os = "android")]
let handle = api.register_android_plugin("life.thephage.healthkit", "HealthConnectPlugin")?;
#[cfg(target_os = "ios")]
let handle = api.register_ios_plugin(init_plugin_healthkit)?;
Ok(Healthkit(handle))
}
pub struct Healthkit<R: Runtime>(PluginHandle<R>);
impl<R: Runtime> Healthkit<R> {
pub fn get_status(&self) -> crate::Result<StatusResponse> {
self.0
.run_mobile_plugin("getHealthStatus", ())
.map_err(Into::into)
}
pub fn check_permissions(&self) -> crate::Result<PermissionsResponse> {
self.0
.run_mobile_plugin("checkPermissions", ())
.map_err(Into::into)
}
pub fn request_permissions(
&self,
payload: PermissionsRequest,
) -> crate::Result<PermissionsResponse> {
self.0
.run_mobile_plugin("requestPermissions", payload)
.map_err(Into::into)
}
pub fn open_settings(&self) -> crate::Result<()> {
self.0
.run_mobile_plugin::<()>("openSettings", ())
.map_err(Into::into)
}
pub fn open_play_store(&self) -> crate::Result<()> {
self.0
.run_mobile_plugin::<()>("openPlayStore", ())
.map_err(Into::into)
}
pub fn get_step(
&self,
payload: StepDataRequest,
) -> crate::Result<StepResponse> {
self.0
.run_mobile_plugin("getStep", payload)
.map_err(Into::into)
}
pub fn get_sleep(&self, payload: SleepDataRequest) -> crate::Result<SleepResponse> {
self.0
.run_mobile_plugin("getSleep", payload)
.map_err(Into::into)
}
pub fn get_weight(&self, payload: WeightDataRequest) -> crate::Result<WeightResponse> {
self.0
.run_mobile_plugin("getWeight", payload)
.map_err(Into::into)
}
}