chore: init
This commit is contained in:
41
src/mobile.rs
Normal file
41
src/mobile.rs
Normal file
@ -0,0 +1,41 @@
|
||||
use serde::de::DeserializeOwned;
|
||||
use tauri::{
|
||||
plugin::{PluginApi, PluginHandle},
|
||||
AppHandle, Runtime,
|
||||
};
|
||||
|
||||
use crate::models::*;
|
||||
|
||||
#[cfg(target_os = "ios")]
|
||||
tauri::ios_plugin_binding!(init_plugin_duck);
|
||||
|
||||
// initializes the Kotlin or Swift plugin classes
|
||||
pub fn init<R: Runtime, C: DeserializeOwned>(
|
||||
_app: &AppHandle<R>,
|
||||
api: PluginApi<R, C>,
|
||||
) -> crate::Result<Duck<R>> {
|
||||
#[cfg(target_os = "android")]
|
||||
let handle = api.register_android_plugin("de.cfp.duck", "DuckPlugin")?;
|
||||
#[cfg(target_os = "ios")]
|
||||
let handle = api.register_ios_plugin(init_plugin_duck)?;
|
||||
Ok(Duck(handle))
|
||||
}
|
||||
|
||||
/// Access to the duck APIs.
|
||||
pub struct Duck<R: Runtime>(PluginHandle<R>);
|
||||
|
||||
impl<R: Runtime> Duck<R> {
|
||||
pub fn duck(&self) -> crate::Result<DuckResponse> {
|
||||
self
|
||||
.0
|
||||
.run_mobile_plugin("duck")
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
pub fn unduck(&self) -> crate::Result<DuckResponse> {
|
||||
self
|
||||
.0
|
||||
.run_mobile_plugin("unduck")
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user