wip(ios): correct command and permissions

This commit is contained in:
2025-05-01 18:40:30 +01:00
parent 9f3a2a473a
commit 7e9b33f625
8 changed files with 48 additions and 72 deletions

View File

@ -1,3 +1,10 @@
## Default Permission
Default permissions for the plugin
#### This default permission set includes the following:
- `saveToken`
## Permission Table

View File

@ -1,3 +1,3 @@
[default]
description = "Default permissions for the plugin"
permissions = ["saveToken"]
permissions = ["allow-save-token"]

View File

@ -305,6 +305,12 @@
"type": "string",
"const": "deny-saveToken",
"markdownDescription": "Denies the saveToken command without any pre-configured scope."
},
{
"description": "Default permissions for the plugin\n#### This default permission set includes:\n\n- `saveToken`",
"type": "string",
"const": "default",
"markdownDescription": "Default permissions for the plugin\n#### This default permission set includes:\n\n- `saveToken`"
}
]
}

View File

@ -1,13 +1,13 @@
use tauri::{AppHandle, command, Runtime};
use tauri::{command, AppHandle, Runtime};
use crate::models::*;
use crate::Result;
use crate::IosSharedTokenExt;
use crate::Result;
#[command]
pub(crate) async fn ping<R: Runtime>(
pub(crate) async fn save_token<R: Runtime>(
app: AppHandle<R>,
payload: PingRequest,
) -> Result<PingResponse> {
app.ios_shared_token().ping(payload)
payload: SaveTokenRequest,
) -> Result<SaveTokenResponse> {
app.ios_shared_token().save_token(payload)
}

View File

@ -1,22 +0,0 @@
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<IosSharedToken<R>> {
Ok(IosSharedToken(app.clone()))
}
/// Access to the ios-shared-token APIs.
pub struct IosSharedToken<R: Runtime>(AppHandle<R>);
impl<R: Runtime> IosSharedToken<R> {
pub fn ping(&self, payload: PingRequest) -> crate::Result<PingResponse> {
Ok(PingResponse {
value: payload.value,
})
}
}

View File

@ -5,9 +5,6 @@ use tauri::{
pub use models::*;
#[cfg(desktop)]
mod desktop;
#[cfg(mobile)]
mod mobile;
mod commands;
@ -16,9 +13,6 @@ mod models;
pub use error::{Error, Result};
#[cfg(desktop)]
use desktop::IosSharedToken;
#[cfg(mobile)]
use mobile::IosSharedToken;
/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the ios-shared-token APIs.
@ -35,12 +29,9 @@ impl<R: Runtime, T: Manager<R>> crate::IosSharedTokenExt<R> for T {
/// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("ios-shared-token")
.invoke_handler(tauri::generate_handler![commands::ping])
.invoke_handler(tauri::generate_handler![commands::save_token])
.setup(|app, api| {
#[cfg(mobile)]
let ios_shared_token = mobile::init(app, api)?;
#[cfg(desktop)]
let ios_shared_token = desktop::init(app, api)?;
app.manage(ios_shared_token);
Ok(())
})

View File

@ -14,9 +14,6 @@ pub fn init<R: Runtime, C: DeserializeOwned>(
_app: &AppHandle<R>,
api: PluginApi<R, C>,
) -> crate::Result<IosSharedToken<R>> {
#[cfg(target_os = "android")]
let handle = api.register_android_plugin("", "ExamplePlugin")?;
#[cfg(target_os = "ios")]
let handle = api.register_ios_plugin(init_plugin_ios_shared_token)?;
Ok(IosSharedToken(handle))
}
@ -25,10 +22,9 @@ pub fn init<R: Runtime, C: DeserializeOwned>(
pub struct IosSharedToken<R: Runtime>(PluginHandle<R>);
impl<R: Runtime> IosSharedToken<R> {
pub fn ping(&self, payload: PingRequest) -> crate::Result<PingResponse> {
self
.0
.run_mobile_plugin("ping", payload)
pub fn save_token(&self, payload: SaveTokenRequest) -> crate::Result<SaveTokenResponse> {
self.0
.run_mobule_plugin("saveToken", payload)
.map_err(Into::into)
}
}

View File

@ -2,12 +2,10 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PingRequest {
pub value: Option<String>,
pub struct SaveTokenRequest {
pub token: String,
}
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PingResponse {
pub value: Option<String>,
}
pub struct SaveTokenResponse {}