wip(ios): correct command and permissions
This commit is contained in:
@ -1,3 +1,10 @@
|
||||
## Default Permission
|
||||
|
||||
Default permissions for the plugin
|
||||
|
||||
#### This default permission set includes the following:
|
||||
|
||||
- `saveToken`
|
||||
|
||||
## Permission Table
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
[default]
|
||||
description = "Default permissions for the plugin"
|
||||
permissions = ["saveToken"]
|
||||
permissions = ["allow-save-token"]
|
||||
|
@ -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`"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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,
|
||||
})
|
||||
}
|
||||
}
|
@ -1,13 +1,10 @@
|
||||
use tauri::{
|
||||
plugin::{Builder, TauriPlugin},
|
||||
Manager, Runtime,
|
||||
plugin::{Builder, TauriPlugin},
|
||||
Manager, Runtime,
|
||||
};
|
||||
|
||||
pub use models::*;
|
||||
|
||||
#[cfg(desktop)]
|
||||
mod desktop;
|
||||
#[cfg(mobile)]
|
||||
mod mobile;
|
||||
|
||||
mod commands;
|
||||
@ -16,33 +13,27 @@ 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.
|
||||
pub trait IosSharedTokenExt<R: Runtime> {
|
||||
fn ios_shared_token(&self) -> &IosSharedToken<R>;
|
||||
fn ios_shared_token(&self) -> &IosSharedToken<R>;
|
||||
}
|
||||
|
||||
impl<R: Runtime, T: Manager<R>> crate::IosSharedTokenExt<R> for T {
|
||||
fn ios_shared_token(&self) -> &IosSharedToken<R> {
|
||||
self.state::<IosSharedToken<R>>().inner()
|
||||
}
|
||||
fn ios_shared_token(&self) -> &IosSharedToken<R> {
|
||||
self.state::<IosSharedToken<R>>().inner()
|
||||
}
|
||||
}
|
||||
|
||||
/// Initializes the plugin.
|
||||
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
Builder::new("ios-shared-token")
|
||||
.invoke_handler(tauri::generate_handler![commands::ping])
|
||||
.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(())
|
||||
})
|
||||
.build()
|
||||
Builder::new("ios-shared-token")
|
||||
.invoke_handler(tauri::generate_handler![commands::save_token])
|
||||
.setup(|app, api| {
|
||||
let ios_shared_token = mobile::init(app, api)?;
|
||||
app.manage(ios_shared_token);
|
||||
Ok(())
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use serde::de::DeserializeOwned;
|
||||
use tauri::{
|
||||
plugin::{PluginApi, PluginHandle},
|
||||
AppHandle, Runtime,
|
||||
plugin::{PluginApi, PluginHandle},
|
||||
AppHandle, Runtime,
|
||||
};
|
||||
|
||||
use crate::models::*;
|
||||
@ -11,24 +11,20 @@ tauri::ios_plugin_binding!(init_plugin_ios_shared_token);
|
||||
|
||||
// initializes the Kotlin or Swift plugin classes
|
||||
pub fn init<R: Runtime, C: DeserializeOwned>(
|
||||
_app: &AppHandle<R>,
|
||||
api: PluginApi<R, C>,
|
||||
_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))
|
||||
let handle = api.register_ios_plugin(init_plugin_ios_shared_token)?;
|
||||
Ok(IosSharedToken(handle))
|
||||
}
|
||||
|
||||
/// Access to the ios-shared-token APIs.
|
||||
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)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
pub fn save_token(&self, payload: SaveTokenRequest) -> crate::Result<SaveTokenResponse> {
|
||||
self.0
|
||||
.run_mobule_plugin("saveToken", payload)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
@ -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 {}
|
||||
|
Reference in New Issue
Block a user