diff --git a/docs/usage/guides/plugin.md b/docs/usage/guides/plugin.md index f25429213..52c82c458 100644 --- a/docs/usage/guides/plugin.md +++ b/docs/usage/guides/plugin.md @@ -10,7 +10,6 @@ Tauri will soon offer Plugin starter kits so the process of writing a Plugin cra For now it's recommended to follow the [official Tauri plugins](#official-tauri-plugins). -The Tauri Plugin system was introduced in [tauri v0.8.0](https://docs.rs/tauri/0.8.0/tauri/). Plugins allow you to hook into the Tauri application lifecycle and introduce new commands. ## Writing a Plugin @@ -18,10 +17,10 @@ Plugins allow you to hook into the Tauri application lifecycle and introduce new To write a plugin you just need to implement the `tauri::plugin::Plugin` trait: ```rust -use tauri::{plugin::{Plugin, Result as PluginResult}, PageLoadPayload, Params, Window, InvokeMessage}; +use tauri::{plugin::{Plugin, Result as PluginResult}, PageLoadPayload, Params, Window, Invoke, App}; -struct MyAwesomePlugin { - invoke_handler: Box) + Send + Sync>, +struct MyAwesomePlugin { + invoke_handler: Box) + Send + Sync>, // plugin state, configuration fields } @@ -35,7 +34,7 @@ fn initialize() {} // this will be accessible with `invoke('plugin:awesome|do_something')`. fn do_something() {} -impl MyAwesomePlugin { +impl MyAwesomePlugin

{ // you can add configuration fields here, // see https://doc.rust-lang.org/1.0.0/style/ownership/builders.html pub fn new() -> Self { @@ -45,7 +44,7 @@ impl MyAwesomePlugin { } } -impl Plugin for MyAwesomePlugin { +impl Plugin

for MyAwesomePlugin

{ /// The plugin name. Must be defined and used on the `invoke` calls. fn name(&self) -> &'static str { "awesome" @@ -60,18 +59,18 @@ impl Plugin for MyAwesomePlugin { } /// initialize plugin with the config provided on `tauri.conf.json > plugins > $yourPluginName` or the default value. - fn initialize(&self, config: serde_json::Value) -> PluginResult<()> { + fn initialize(&mut self, app: &App

, config: serde_json::Value) -> PluginResult<()> { Ok(()) } /// Callback invoked when the Window is created. - fn created(&self, window: Window) {} + fn created(&mut self, window: Window

) {} /// Callback invoked when the webview performs a navigation. - fn on_page_load(&self, window: Window, payload: PageLoadPayload) {} + fn on_page_load(&mut self, window: Window

, payload: PageLoadPayload) {} /// Extend the invoke handler. - fn extend_api(&mut self, message: InvokeMessage) { + fn extend_api(&mut self, message: Invoke

) { (self.invoke_handler)(message) } }