Unggahan awal

This commit is contained in:
2026-04-14 18:36:14 +07:00
parent 240227ce02
commit 9db8123021
43 changed files with 713 additions and 2 deletions
+13
View File
@@ -0,0 +1,13 @@
use tauri::{AppHandle, command, Runtime};
use crate::models::*;
use crate::Result;
use crate::BluclasExt;
#[command]
pub(crate) async fn ping<R: Runtime>(
app: AppHandle<R>,
payload: PingRequest,
) -> Result<PingResponse> {
app.bluclas().ping(payload)
}
+22
View File
@@ -0,0 +1,22 @@
use serde::de::DeserializeOwned;
use tauri::{plugin::PluginApi, AppHandle, Runtime};
use crate::models::*;
pub fn init<R: Runtime, C: DeserializeOwned>(
app: &AppHandle<R>,
_api: PluginApi<R, C>,
) -> crate::Result<Bluclas<R>> {
Ok(Bluclas(app.clone()))
}
/// Access to the bluclas APIs.
pub struct Bluclas<R: Runtime>(AppHandle<R>);
impl<R: Runtime> Bluclas<R> {
pub fn ping(&self, payload: PingRequest) -> crate::Result<PingResponse> {
Ok(PingResponse {
value: payload.value,
})
}
}
+21
View File
@@ -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())
}
}
+48
View File
@@ -0,0 +1,48 @@
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::Bluclas;
#[cfg(mobile)]
use mobile::Bluclas;
/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the bluclas APIs.
pub trait BluclasExt<R: Runtime> {
fn bluclas(&self) -> &Bluclas<R>;
}
impl<R: Runtime, T: Manager<R>> crate::BluclasExt<R> for T {
fn bluclas(&self) -> &Bluclas<R> {
self.state::<Bluclas<R>>().inner()
}
}
/// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("bluclas")
.invoke_handler(tauri::generate_handler![commands::ping])
.setup(|app, api| {
#[cfg(mobile)]
let bluclas = mobile::init(app, api)?;
#[cfg(desktop)]
let bluclas = desktop::init(app, api)?;
app.manage(bluclas);
Ok(())
})
.build()
}
+34
View File
@@ -0,0 +1,34 @@
use serde::de::DeserializeOwned;
use tauri::{
plugin::{PluginApi, PluginHandle},
AppHandle, Runtime,
};
use crate::models::*;
#[cfg(target_os = "ios")]
tauri::ios_plugin_binding!(init_plugin_bluclas);
// initializes the Kotlin or Swift plugin classes
pub fn init<R: Runtime, C: DeserializeOwned>(
_app: &AppHandle<R>,
api: PluginApi<R, C>,
) -> crate::Result<Bluclas<R>> {
#[cfg(target_os = "android")]
let handle = api.register_android_plugin("", "ExamplePlugin")?;
#[cfg(target_os = "ios")]
let handle = api.register_ios_plugin(init_plugin_bluclas)?;
Ok(Bluclas(handle))
}
/// Access to the bluclas APIs.
pub struct Bluclas<R: Runtime>(PluginHandle<R>);
impl<R: Runtime> Bluclas<R> {
pub fn ping(&self, payload: PingRequest) -> crate::Result<PingResponse> {
self
.0
.run_mobile_plugin("ping", payload)
.map_err(Into::into)
}
}
+13
View File
@@ -0,0 +1,13 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PingRequest {
pub value: Option<String>,
}
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PingResponse {
pub value: Option<String>,
}