use tauri::{
plugin::{Builder, TauriPlugin},
Runtime,
};
#[cfg(target_os = "android")]
use tauri::Manager;
pub use models::*;
#[cfg(target_os = "android")]
mod mobile;
#[cfg(target_os = "android")]
use mobile::NativeCamera;
mod models;
mod error;
pub use error::{Error, Result};
#[cfg(target_os = "android")]
mod commands {
use super::*;
#[tauri::command]
pub(crate) async fn take_picture<R: Runtime>(
app: tauri::AppHandle<R>,
_window: tauri::Window<R>,
) -> Result<CaptureResult> {
let camera = app.state::<NativeCamera<R>>();
camera.take_picture()
}
}
#[cfg(target_os = "android")]
pub trait NativeCameraExt<R: Runtime> {
fn native_camera(&self) -> &NativeCamera<R>;
}
#[cfg(target_os = "android")]
impl<R: Runtime, T: Manager<R>> crate::NativeCameraExt<R> for T {
fn native_camera(&self) -> &NativeCamera<R> {
self.state::<NativeCamera<R>>().inner()
}
}
pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("native-camera")
.setup(|_app, _api| {
#[cfg(target_os = "android")]
{
let handle = _api.register_android_plugin("in.kushaldas.plugin.nativecamera", "NativeCameraPlugin")?;
_app.manage(NativeCamera::new(handle));
}
Ok(())
})
.invoke_handler(tauri::generate_handler![
#[cfg(target_os = "android")]
commands::take_picture
])
.build()
}