| 1 | use serde::de::DeserializeOwned; |
| 2 | use tauri::{ |
| 3 | plugin::{PluginApi, PluginHandle}, |
| 4 | AppHandle, Runtime, |
| 5 | }; |
| 6 | |
| 7 | use crate::models::*; |
| 8 | |
| 9 | #[cfg(target_os = "ios")] |
| 10 | tauri::ios_plugin_binding!(init_plugin_android_tv_check); |
| 11 | #[cfg(target_os = "android")] |
| 12 | const PLUGIN_IDENTIFIER: &str = "com.plugin.androidTvCheck"; |
| 13 | |
| 14 | // initializes the Kotlin or Swift plugin classes |
| 15 | pub fn init<R: Runtime, C: DeserializeOwned>( |
| 16 | _app: &AppHandle<R>, |
| 17 | api: PluginApi<R, C>, |
| 18 | ) -> crate::Result<AndroidTvCheck<R>> { |
| 19 | #[cfg(target_os = "android")] |
| 20 | let handle = api.register_android_plugin(PLUGIN_IDENTIFIER, "AndroidTvCheckPlugin")?; |
| 21 | #[cfg(target_os = "ios")] |
| 22 | let handle = api.register_ios_plugin(init_plugin_android_tv_check)?; |
| 23 | Ok(AndroidTvCheck(handle)) |
| 24 | } |
| 25 | |
| 26 | /// Access to the android-tv-check APIs. |
| 27 | pub struct AndroidTvCheck<R: Runtime>(PluginHandle<R>); |
| 28 | |
| 29 | impl<R: Runtime> AndroidTvCheck<R> { |
| 30 | pub fn check(&self) -> crate::Result<CheckResponse> { |
| 31 | match self.0.run_mobile_plugin("check", ()) { |
| 32 | Ok(res) => { |
| 33 | println!("Check response: {:?}", res); |
| 34 | Ok(res) |
| 35 | } |
| 36 | Err(err) => Err(err.into()), |
| 37 | } |
| 38 | } |
| 39 | } |