diff --git a/.changes/cli-plugin-template-updates.md b/.changes/cli-plugin-template-updates.md
new file mode 100644
index 000000000000..de98339e137e
--- /dev/null
+++ b/.changes/cli-plugin-template-updates.md
@@ -0,0 +1,6 @@
+---
+"tauri-cli": "patch:enhance"
+"@tauri-apps/cli": "patch:enhance"
+---
+
+Enhance the plugin template to include `permissions/default.toml` and default capabilities file for the example application.
diff --git a/tooling/cli/src/plugin/init.rs b/tooling/cli/src/plugin/init.rs
index 236041ed79ed..f5dd40b45929 100644
--- a/tooling/cli/src/plugin/init.rs
+++ b/tooling/cli/src/plugin/init.rs
@@ -239,9 +239,17 @@ pub fn command(mut options: Options) -> Result<()> {
.with_context(|| "failed to render plugin Android template")?;
}
- std::fs::create_dir(template_target_path.join("permissions"))
+ let permissions_dir = template_target_path.join("permissions");
+ std::fs::create_dir(&permissions_dir)
.with_context(|| "failed to create `permissions` directory")?;
+ let default_permissions = r#"[default]
+description = "Default permissions for the plugin"
+permissions = ["allow-ping"]
+"#;
+ std::fs::write(permissions_dir.join("default.toml"), default_permissions)
+ .with_context(|| "failed to write `permissions/default.toml`")?;
+
Ok(())
}
diff --git a/tooling/cli/templates/plugin/__example-api/tauri-app/src-tauri/capabilities/default.json b/tooling/cli/templates/plugin/__example-api/tauri-app/src-tauri/capabilities/default.json
new file mode 100644
index 000000000000..bc594466d734
--- /dev/null
+++ b/tooling/cli/templates/plugin/__example-api/tauri-app/src-tauri/capabilities/default.json
@@ -0,0 +1,18 @@
+{
+ "$schema": "../gen/schemas/desktop-schema.json",
+ "identifier": "default",
+ "description": "enables the default permissions",
+ "windows": ["main"],
+ "permissions": [
+ "path:default",
+ "event:default",
+ "window:default",
+ "webview:default",
+ "app:default",
+ "resources:default",
+ "image:default",
+ "menu:default",
+ "tray:default",
+ "{{ plugin_name }}:default"
+ ]
+}
diff --git a/tooling/cli/templates/plugin/__example-api/tauri-app/src/App.svelte b/tooling/cli/templates/plugin/__example-api/tauri-app/src/App.svelte
index 7c05b27167b8..df696ffbf783 100644
--- a/tooling/cli/templates/plugin/__example-api/tauri-app/src/App.svelte
+++ b/tooling/cli/templates/plugin/__example-api/tauri-app/src/App.svelte
@@ -1,15 +1,15 @@
@@ -37,7 +37,7 @@
-
+
{@html response}
diff --git a/tooling/cli/templates/plugin/__example-basic/vanilla/src-tauri/capabilities/default.json b/tooling/cli/templates/plugin/__example-basic/vanilla/src-tauri/capabilities/default.json
new file mode 100644
index 000000000000..bc594466d734
--- /dev/null
+++ b/tooling/cli/templates/plugin/__example-basic/vanilla/src-tauri/capabilities/default.json
@@ -0,0 +1,18 @@
+{
+ "$schema": "../gen/schemas/desktop-schema.json",
+ "identifier": "default",
+ "description": "enables the default permissions",
+ "windows": ["main"],
+ "permissions": [
+ "path:default",
+ "event:default",
+ "window:default",
+ "webview:default",
+ "app:default",
+ "resources:default",
+ "image:default",
+ "menu:default",
+ "tray:default",
+ "{{ plugin_name }}:default"
+ ]
+}
diff --git a/tooling/cli/templates/plugin/build.rs b/tooling/cli/templates/plugin/build.rs
index a10892a6dc78..e0ff2ccce229 100644
--- a/tooling/cli/templates/plugin/build.rs
+++ b/tooling/cli/templates/plugin/build.rs
@@ -1,4 +1,4 @@
-const COMMANDS: &[&str] = &["ping", "execute"];
+const COMMANDS: &[&str] = &["ping"];
fn main() {
tauri_plugin::Builder::new(COMMANDS)
diff --git a/tooling/cli/templates/plugin/guest-js/index.ts b/tooling/cli/templates/plugin/guest-js/index.ts
index 6697605d5f67..cbbafe2ed8de 100644
--- a/tooling/cli/templates/plugin/guest-js/index.ts
+++ b/tooling/cli/templates/plugin/guest-js/index.ts
@@ -3,6 +3,10 @@
{{/if}}
import { invoke } from '@tauri-apps/api/core'
-export async function execute() {
- await invoke('plugin:{{ plugin_name }}|execute')
+export async function ping(value: string): Promise {
+ return await invoke<{value?: string}>('plugin:{{ plugin_name }}|ping', {
+ payload: {
+ value,
+ },
+ }).then((r) => (r.value ? r.value : null));
}
diff --git a/tooling/cli/templates/plugin/src/commands.rs b/tooling/cli/templates/plugin/src/commands.rs
index c1272703a9c7..80c544642ad7 100644
--- a/tooling/cli/templates/plugin/src/commands.rs
+++ b/tooling/cli/templates/plugin/src/commands.rs
@@ -1,16 +1,16 @@
{{#if license_header}}
{{ license_header }}
{{/if}}
-use tauri::{AppHandle, command, Runtime, State, Window};
+use tauri::{AppHandle, command, Runtime};
-use crate::{MyState, Result};
+use crate::models::*;
+use crate::Result;
+use crate::{{ plugin_name_pascal_case }}Ext;
#[command]
-pub(crate) async fn execute(
- _app: AppHandle,
- _window: Window,
- state: State<'_, MyState>,
-) -> Result {
- state.0.lock().unwrap().insert("key".into(), "value".into());
- Ok("success".to_string())
+pub(crate) async fn ping(
+ app: AppHandle,
+ payload: PingRequest,
+) -> Result {
+ app.{{ plugin_name_snake_case }}().ping(payload)
}
diff --git a/tooling/cli/templates/plugin/src/lib.rs b/tooling/cli/templates/plugin/src/lib.rs
index 07bfd6770603..874b99f67f10 100644
--- a/tooling/cli/templates/plugin/src/lib.rs
+++ b/tooling/cli/templates/plugin/src/lib.rs
@@ -6,8 +6,6 @@ use tauri::{
Manager, Runtime,
};
-use std::{collections::HashMap, sync::Mutex};
-
pub use models::*;
#[cfg(desktop)]
@@ -26,9 +24,6 @@ use desktop::{{ plugin_name_pascal_case }};
#[cfg(mobile)]
use mobile::{{ plugin_name_pascal_case }};
-#[derive(Default)]
-struct MyState(Mutex>);
-
/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the {{ plugin_name }} APIs.
pub trait {{ plugin_name_pascal_case }}Ext {
fn {{ plugin_name_snake_case }}(&self) -> &{{ plugin_name_pascal_case }};
@@ -43,16 +38,13 @@ impl> crate::{{ plugin_name_pascal_case }}Ext for T
/// Initializes the plugin.
pub fn init() -> TauriPlugin {
Builder::new("{{ plugin_name }}")
- .invoke_handler(tauri::generate_handler![commands::execute])
+ .invoke_handler(tauri::generate_handler![commands::ping])
.setup(|app, api| {
#[cfg(mobile)]
let {{ plugin_name_snake_case }} = mobile::init(app, api)?;
#[cfg(desktop)]
let {{ plugin_name_snake_case }} = desktop::init(app, api)?;
app.manage({{ plugin_name_snake_case }});
-
- // manage state so it is accessible by the commands
- app.manage(MyState::default());
Ok(())
})
.build()
diff --git a/tooling/cli/templates/plugin/src/models.rs b/tooling/cli/templates/plugin/src/models.rs
index 04f81da9c36e..914fb2388828 100644
--- a/tooling/cli/templates/plugin/src/models.rs
+++ b/tooling/cli/templates/plugin/src/models.rs
@@ -3,13 +3,13 @@
{{/if}}
use serde::{Deserialize, Serialize};
-#[derive(Debug, Serialize)]
+#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PingRequest {
pub value: Option,
}
-#[derive(Debug, Clone, Default, Deserialize)]
+#[derive(Debug, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PingResponse {
pub value: Option,