tauri-plugin-healthkit 0.1.3

A Tauri plugin for accessing HealthKit (iOS) and Health Connect (Android)
use tauri::{command, AppHandle, Runtime};

use crate::models::*;
use crate::HealthkitExt;
use crate::Result;

// ============================================================================
// Status & Permissions
// ============================================================================

#[command]
pub(crate) async fn get_status<R: Runtime>(app: AppHandle<R>) -> Result<StatusResponse> {
    app.healthkit().get_status()
}

#[command]
pub(crate) async fn check_permissions<R: Runtime>(
    app: AppHandle<R>,
) -> Result<PermissionsResponse> {
    app.healthkit().check_permissions()
}

#[command]
pub(crate) async fn request_permissions<R: Runtime>(
    app: AppHandle<R>,
    payload: PermissionsRequest,
) -> Result<PermissionsResponse> {
    app.healthkit().request_permissions(payload)
}

// ============================================================================
// Settings & Store
// ============================================================================

#[command]
pub(crate) async fn open_settings<R: Runtime>(app: AppHandle<R>) -> Result<()> {
    app.healthkit().open_settings()
}

#[command]
pub(crate) async fn open_play_store<R: Runtime>(app: AppHandle<R>) -> Result<()> {
    app.healthkit().open_play_store()
}

// ============================================================================
// Step Count Data
// ============================================================================

#[command]
pub(crate) async fn get_step<R: Runtime>(
    app: AppHandle<R>,
    payload: StepDataRequest,
) -> Result<StepResponse> {
    app.healthkit().get_step(payload)
}

// ============================================================================
// Sleep Data
// ============================================================================

/// Get sleep data within time range
#[command]
pub(crate) async fn get_sleep<R: Runtime>(
    app: AppHandle<R>,
    payload: SleepDataRequest,
) -> Result<SleepResponse> {
    app.healthkit().get_sleep(payload)
}

// ============================================================================
// Weight Data
// ============================================================================

/// Get weight data within time range
#[command]
pub(crate) async fn get_weight<R: Runtime>(
    app: AppHandle<R>,
    payload: WeightDataRequest,
) -> Result<WeightResponse> {
    app.healthkit().get_weight(payload)
}