Archived
39 lines
1.0 KiB
Rust
39 lines
1.0 KiB
Rust
use serde::de::DeserializeOwned;
|
|
use tauri::{
|
|
AppHandle, Runtime,
|
|
plugin::{PluginApi, PluginHandle},
|
|
};
|
|
|
|
use crate::models::*;
|
|
|
|
#[cfg(target_os = "ios")]
|
|
tauri::ios_plugin_binding!(init_plugin_auth);
|
|
|
|
// initializes the Kotlin or Swift plugin classes
|
|
pub fn init<R: Runtime, C: DeserializeOwned>(
|
|
_app: &AppHandle<R>,
|
|
api: PluginApi<R, C>,
|
|
) -> crate::Result<Auth<R>> {
|
|
#[cfg(target_os = "android")]
|
|
let handle = api.register_android_plugin("com.plugin.auth", "AuthPlugin")?;
|
|
#[cfg(target_os = "ios")]
|
|
let handle = api.register_ios_plugin(init_plugin_auth)?;
|
|
Ok(Auth(handle))
|
|
}
|
|
|
|
/// Access to the auth APIs.
|
|
pub struct Auth<R: Runtime>(PluginHandle<R>);
|
|
|
|
impl<R: Runtime> Auth<R> {
|
|
pub fn masuk(&self, muatan: SAuthMuatanMasuk) -> crate::Result<()> {
|
|
return self
|
|
.0
|
|
.run_mobile_plugin("masuk", muatan)
|
|
.map_err(Into::into);
|
|
}
|
|
|
|
pub fn keluar(&self) -> crate::Result<()> {
|
|
return self.0.run_mobile_plugin("keluar", ()).map_err(Into::into);
|
|
}
|
|
}
|