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
|
## Permission Table
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
[default]
|
[default]
|
||||||
description = "Default permissions for the plugin"
|
description = "Default permissions for the plugin"
|
||||||
permissions = ["saveToken"]
|
permissions = ["allow-save-token"]
|
||||||
|
@ -305,6 +305,12 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"const": "deny-saveToken",
|
"const": "deny-saveToken",
|
||||||
"markdownDescription": "Denies the saveToken command without any pre-configured scope."
|
"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::models::*;
|
||||||
use crate::Result;
|
|
||||||
use crate::IosSharedTokenExt;
|
use crate::IosSharedTokenExt;
|
||||||
|
use crate::Result;
|
||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
pub(crate) async fn ping<R: Runtime>(
|
pub(crate) async fn save_token<R: Runtime>(
|
||||||
app: AppHandle<R>,
|
app: AppHandle<R>,
|
||||||
payload: PingRequest,
|
payload: SaveTokenRequest,
|
||||||
) -> Result<PingResponse> {
|
) -> Result<SaveTokenResponse> {
|
||||||
app.ios_shared_token().ping(payload)
|
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::{
|
use tauri::{
|
||||||
plugin::{Builder, TauriPlugin},
|
plugin::{Builder, TauriPlugin},
|
||||||
Manager, Runtime,
|
Manager, Runtime,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use models::*;
|
pub use models::*;
|
||||||
|
|
||||||
#[cfg(desktop)]
|
|
||||||
mod desktop;
|
|
||||||
#[cfg(mobile)]
|
|
||||||
mod mobile;
|
mod mobile;
|
||||||
|
|
||||||
mod commands;
|
mod commands;
|
||||||
@ -16,33 +13,27 @@ mod models;
|
|||||||
|
|
||||||
pub use error::{Error, Result};
|
pub use error::{Error, Result};
|
||||||
|
|
||||||
#[cfg(desktop)]
|
|
||||||
use desktop::IosSharedToken;
|
|
||||||
#[cfg(mobile)]
|
|
||||||
use mobile::IosSharedToken;
|
use mobile::IosSharedToken;
|
||||||
|
|
||||||
/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the ios-shared-token APIs.
|
/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the ios-shared-token APIs.
|
||||||
pub trait IosSharedTokenExt<R: Runtime> {
|
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 {
|
impl<R: Runtime, T: Manager<R>> crate::IosSharedTokenExt<R> for T {
|
||||||
fn ios_shared_token(&self) -> &IosSharedToken<R> {
|
fn ios_shared_token(&self) -> &IosSharedToken<R> {
|
||||||
self.state::<IosSharedToken<R>>().inner()
|
self.state::<IosSharedToken<R>>().inner()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initializes the plugin.
|
/// Initializes the plugin.
|
||||||
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||||
Builder::new("ios-shared-token")
|
Builder::new("ios-shared-token")
|
||||||
.invoke_handler(tauri::generate_handler![commands::ping])
|
.invoke_handler(tauri::generate_handler![commands::save_token])
|
||||||
.setup(|app, api| {
|
.setup(|app, api| {
|
||||||
#[cfg(mobile)]
|
let ios_shared_token = mobile::init(app, api)?;
|
||||||
let ios_shared_token = mobile::init(app, api)?;
|
app.manage(ios_shared_token);
|
||||||
#[cfg(desktop)]
|
Ok(())
|
||||||
let ios_shared_token = desktop::init(app, api)?;
|
})
|
||||||
app.manage(ios_shared_token);
|
.build()
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
.build()
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use tauri::{
|
use tauri::{
|
||||||
plugin::{PluginApi, PluginHandle},
|
plugin::{PluginApi, PluginHandle},
|
||||||
AppHandle, Runtime,
|
AppHandle, Runtime,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::models::*;
|
use crate::models::*;
|
||||||
@ -11,24 +11,20 @@ tauri::ios_plugin_binding!(init_plugin_ios_shared_token);
|
|||||||
|
|
||||||
// initializes the Kotlin or Swift plugin classes
|
// initializes the Kotlin or Swift plugin classes
|
||||||
pub fn init<R: Runtime, C: DeserializeOwned>(
|
pub fn init<R: Runtime, C: DeserializeOwned>(
|
||||||
_app: &AppHandle<R>,
|
_app: &AppHandle<R>,
|
||||||
api: PluginApi<R, C>,
|
api: PluginApi<R, C>,
|
||||||
) -> crate::Result<IosSharedToken<R>> {
|
) -> crate::Result<IosSharedToken<R>> {
|
||||||
#[cfg(target_os = "android")]
|
let handle = api.register_ios_plugin(init_plugin_ios_shared_token)?;
|
||||||
let handle = api.register_android_plugin("", "ExamplePlugin")?;
|
Ok(IosSharedToken(handle))
|
||||||
#[cfg(target_os = "ios")]
|
|
||||||
let handle = api.register_ios_plugin(init_plugin_ios_shared_token)?;
|
|
||||||
Ok(IosSharedToken(handle))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Access to the ios-shared-token APIs.
|
/// Access to the ios-shared-token APIs.
|
||||||
pub struct IosSharedToken<R: Runtime>(PluginHandle<R>);
|
pub struct IosSharedToken<R: Runtime>(PluginHandle<R>);
|
||||||
|
|
||||||
impl<R: Runtime> IosSharedToken<R> {
|
impl<R: Runtime> IosSharedToken<R> {
|
||||||
pub fn ping(&self, payload: PingRequest) -> crate::Result<PingResponse> {
|
pub fn save_token(&self, payload: SaveTokenRequest) -> crate::Result<SaveTokenResponse> {
|
||||||
self
|
self.0
|
||||||
.0
|
.run_mobule_plugin("saveToken", payload)
|
||||||
.run_mobile_plugin("ping", payload)
|
.map_err(Into::into)
|
||||||
.map_err(Into::into)
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,10 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct PingRequest {
|
pub struct SaveTokenRequest {
|
||||||
pub value: Option<String>,
|
pub token: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
|
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct PingResponse {
|
pub struct SaveTokenResponse {}
|
||||||
pub value: Option<String>,
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user