mirror of
https://github.com/tauri-apps/tauri.git
synced 2025-01-01 23:42:33 +03:00
Fix outdated Plugin page (#2178)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
parent
8157a68af1
commit
324275c00a
@ -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).
|
||||
</Alert>
|
||||
|
||||
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<M: Params> {
|
||||
invoke_handler: Box<dyn Fn(InvokeMessage<M>) + Send + Sync>,
|
||||
struct MyAwesomePlugin<P: Params> {
|
||||
invoke_handler: Box<dyn Fn(Invoke<P>) + 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<P: Params> MyAwesomePlugin<P> {
|
||||
// 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<M: Params> Plugin<M> for MyAwesomePlugin<M> {
|
||||
impl<P: Params> Plugin<P> for MyAwesomePlugin<P> {
|
||||
/// The plugin name. Must be defined and used on the `invoke` calls.
|
||||
fn name(&self) -> &'static str {
|
||||
"awesome"
|
||||
@ -60,18 +59,18 @@ impl<M: Params> Plugin<M> for MyAwesomePlugin<M> {
|
||||
}
|
||||
|
||||
/// 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<P>, config: serde_json::Value) -> PluginResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Callback invoked when the Window is created.
|
||||
fn created(&self, window: Window<M>) {}
|
||||
fn created(&mut self, window: Window<P>) {}
|
||||
|
||||
/// Callback invoked when the webview performs a navigation.
|
||||
fn on_page_load(&self, window: Window<M>, payload: PageLoadPayload) {}
|
||||
fn on_page_load(&mut self, window: Window<P>, payload: PageLoadPayload) {}
|
||||
|
||||
/// Extend the invoke handler.
|
||||
fn extend_api(&mut self, message: InvokeMessage<M>) {
|
||||
fn extend_api(&mut self, message: Invoke<P>) {
|
||||
(self.invoke_handler)(message)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user