use serde::de::DeserializeOwned;
use tauri::{plugin::PluginApi, AppHandle, Runtime};
use crate::models::*;
pub fn init<R: Runtime, C: DeserializeOwned>(
app: &AppHandle<R>,
_api: PluginApi<R, C>,
) -> crate::Result<Intent<R>> {
Ok(Intent(app.clone()))
}
pub struct Intent<R: Runtime>(AppHandle<R>);
impl<R: Runtime> Intent<R> {
pub async fn open_intent(
&self,
payload: OpenIntentRequest,
) -> crate::Result<OpenIntentResponse> {
match payload.action.as_str() {
"android.intent.action.VIEW" => {
if let Some(data) = payload.data {
#[cfg(desktop)]
{
if let Err(e) = opener::open(&data) {
return Ok(OpenIntentResponse {
success: false,
error: Some(format!("Failed to open URL: {}", e)),
});
}
}
Ok(OpenIntentResponse {
success: true,
error: None,
})
} else {
Ok(OpenIntentResponse {
success: false,
error: Some("No data provided for VIEW intent".to_string()),
})
}
}
"android.intent.action.CALL" => {
Ok(OpenIntentResponse {
success: false,
error: Some("Phone calls are not supported on desktop".to_string()),
})
}
_ => Ok(OpenIntentResponse {
success: false,
error: Some(format!("Unsupported intent action: {}", payload.action)),
}),
}
}
}