mirror of
https://github.com/readest/readest.git
synced 2026-04-29 12:00:49 +00:00
* auth: add safari-auth plugin for iOS OAuth * fix: temporarily disable email auth provider for iOS
48 lines
1.1 KiB
Rust
48 lines
1.1 KiB
Rust
use tauri::{
|
|
plugin::{Builder, TauriPlugin},
|
|
Manager, Runtime,
|
|
};
|
|
|
|
pub use models::*;
|
|
|
|
#[cfg(desktop)]
|
|
mod desktop;
|
|
#[cfg(mobile)]
|
|
mod mobile;
|
|
|
|
mod commands;
|
|
mod error;
|
|
mod models;
|
|
|
|
pub use error::{Error, Result};
|
|
|
|
#[cfg(desktop)]
|
|
use desktop::SafariAuth;
|
|
#[cfg(mobile)]
|
|
use mobile::SafariAuth;
|
|
|
|
/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the safari-auth APIs.
|
|
pub trait SafariAuthExt<R: Runtime> {
|
|
fn safari_auth(&self) -> &SafariAuth<R>;
|
|
}
|
|
|
|
impl<R: Runtime, T: Manager<R>> crate::SafariAuthExt<R> for T {
|
|
fn safari_auth(&self) -> &SafariAuth<R> {
|
|
self.state::<SafariAuth<R>>().inner()
|
|
}
|
|
}
|
|
|
|
/// Initializes the plugin.
|
|
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
|
Builder::new("safari-auth")
|
|
.invoke_handler(tauri::generate_handler![commands::auth_with_safari])
|
|
.setup(|app, api| {
|
|
#[cfg(mobile)]
|
|
let safari_auth = mobile::init(app, api)?;
|
|
#[cfg(desktop)]
|
|
let safari_auth = desktop::init(app, api)?;
|
|
app.manage(safari_auth);
|
|
Ok(())
|
|
})
|
|
.build()
|
|
}
|