mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-06-06 13:53:54 +02:00
update camera android project
This commit is contained in:
+11
-11
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2022 Tauri Programme within The Commons Conservancy
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
@@ -8,17 +8,17 @@ pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
#[error(transparent)]
|
||||
Io(#[from] std::io::Error),
|
||||
#[error(transparent)]
|
||||
PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
|
||||
#[error(transparent)]
|
||||
Io(#[from] std::io::Error),
|
||||
#[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())
|
||||
}
|
||||
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str(self.to_string().as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
+22
-23
@@ -1,12 +1,12 @@
|
||||
// Copyright 2019-2022 Tauri Programme within The Commons Conservancy
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#![cfg(mobile)]
|
||||
|
||||
use tauri::{
|
||||
plugin::{Builder, PluginHandle, TauriPlugin},
|
||||
Manager, Runtime,
|
||||
plugin::{Builder, PluginHandle, TauriPlugin},
|
||||
Manager, Runtime,
|
||||
};
|
||||
|
||||
pub use models::*;
|
||||
@@ -24,35 +24,34 @@ tauri::ios_plugin_binding!(init_plugin_camera);
|
||||
pub struct Camera<R: Runtime>(PluginHandle<R>);
|
||||
|
||||
impl<R: Runtime> Camera<R> {
|
||||
pub fn get_photo(&self, options: ImageOptions) -> Result<Image> {
|
||||
self
|
||||
.0
|
||||
.run_mobile_plugin("getPhoto", options)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
pub fn get_photo(&self, options: ImageOptions) -> Result<Image> {
|
||||
self.0
|
||||
.run_mobile_plugin("getPhoto", options)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the camera APIs.
|
||||
pub trait CameraExt<R: Runtime> {
|
||||
fn camera(&self) -> &Camera<R>;
|
||||
fn camera(&self) -> &Camera<R>;
|
||||
}
|
||||
|
||||
impl<R: Runtime, T: Manager<R>> CameraExt<R> for T {
|
||||
fn camera(&self) -> &Camera<R> {
|
||||
self.state::<Camera<R>>().inner()
|
||||
}
|
||||
fn camera(&self) -> &Camera<R> {
|
||||
self.state::<Camera<R>>().inner()
|
||||
}
|
||||
}
|
||||
|
||||
/// Initializes the plugin.
|
||||
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
Builder::new("camera")
|
||||
.setup(|app, api| {
|
||||
#[cfg(target_os = "android")]
|
||||
let handle = api.register_android_plugin(PLUGIN_IDENTIFIER, "CameraPlugin")?;
|
||||
#[cfg(target_os = "ios")]
|
||||
let handle = api.register_ios_plugin(init_plugin_camera)?;
|
||||
app.manage(Camera(handle));
|
||||
Ok(())
|
||||
})
|
||||
.build()
|
||||
Builder::new("camera")
|
||||
.setup(|app, api| {
|
||||
#[cfg(target_os = "android")]
|
||||
let handle = api.register_android_plugin(PLUGIN_IDENTIFIER, "CameraPlugin")?;
|
||||
#[cfg(target_os = "ios")]
|
||||
let handle = api.register_ios_plugin(init_plugin_camera)?;
|
||||
app.manage(Camera(handle));
|
||||
Ok(())
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2022 Tauri Programme within The Commons Conservancy
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
|
||||
Reference in New Issue
Block a user