Archived
Unggahan awal
This commit is contained in:
1 parent
7915065d1c
commit
8c96423e9b
19 files changed
+686
No files matched your search
@@ -0,0 +1,9 @@
|
||||
use tauri::{AppHandle, Runtime, command};
|
||||
|
||||
use crate::AuthExt;
|
||||
use crate::Result;
|
||||
|
||||
#[command]
|
||||
pub(crate) async fn autentikasi<R: Runtime>(app: AppHandle<R>) -> Result<Vec<()>> {
|
||||
return app.auth().autentikasi();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
use serde::de::DeserializeOwned;
|
||||
use tauri::{AppHandle, Runtime, plugin::PluginApi};
|
||||
|
||||
pub fn init<R: Runtime, C: DeserializeOwned>(
|
||||
app: &AppHandle<R>,
|
||||
_api: PluginApi<R, C>,
|
||||
) -> crate::Result<Auth<R>> {
|
||||
Ok(Auth(app.clone()))
|
||||
}
|
||||
|
||||
/// Access to the auth APIs.
|
||||
pub struct Auth<R: Runtime>(AppHandle<R>);
|
||||
|
||||
impl<R: Runtime> Auth<R> {
|
||||
pub fn autentikasi(&self) -> crate::Result<Vec<()>> {
|
||||
return Ok(vec![]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
use serde::{ser::Serializer, Serialize};
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
#[error(transparent)]
|
||||
Io(#[from] std::io::Error),
|
||||
#[cfg(mobile)]
|
||||
#[error(transparent)]
|
||||
PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
|
||||
}
|
||||
|
||||
impl Serialize for Error {
|
||||
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str(self.to_string().as_ref())
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
use tauri::{
|
||||
Manager, Runtime,
|
||||
plugin::{Builder, TauriPlugin},
|
||||
};
|
||||
|
||||
#[cfg(desktop)]
|
||||
mod desktop;
|
||||
#[cfg(mobile)]
|
||||
mod mobile;
|
||||
|
||||
mod commands;
|
||||
mod error;
|
||||
mod models;
|
||||
|
||||
pub use error::{Error, Result};
|
||||
|
||||
#[cfg(desktop)]
|
||||
use desktop::Auth;
|
||||
#[cfg(mobile)]
|
||||
use mobile::Auth;
|
||||
|
||||
/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the auth APIs.
|
||||
pub trait AuthExt<R: Runtime> {
|
||||
fn auth(&self) -> &Auth<R>;
|
||||
}
|
||||
|
||||
impl<R: Runtime, T: Manager<R>> crate::AuthExt<R> for T {
|
||||
fn auth(&self) -> &Auth<R> {
|
||||
self.state::<Auth<R>>().inner()
|
||||
}
|
||||
}
|
||||
|
||||
/// Initializes the plugin.
|
||||
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
Builder::new("auth")
|
||||
.invoke_handler(tauri::generate_handler![commands::autentikasi])
|
||||
.setup(|app, api| {
|
||||
#[cfg(mobile)]
|
||||
let auth = mobile::init(app, api)?;
|
||||
#[cfg(desktop)]
|
||||
let auth = desktop::init(app, api)?;
|
||||
app.manage(auth);
|
||||
Ok(())
|
||||
})
|
||||
.build()
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
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("", "ExamplePlugin")?;
|
||||
#[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 autentikasi(&self) -> crate::Result<Vec<()>> {
|
||||
return self.0.run_mobile_plugin("autentikasi").map_err(Into::into);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Reference in new issue
Block a user