{
// you can add configuration fields here,
// see https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
pub fn new() -> Self {
Self {
invoke_handler: Box::new(tauri::generate_handler![initialize, do_something]),
}
}
}
impl for MyAwesomePlugin {
/// The plugin name. Must be defined and used on the `invoke` calls.
fn name(&self) -> &'static str {
"awesome"
}
/// The JS script to evaluate on initialization.
/// Useful when your plugin is accessible through `window`
/// or needs to perform a JS task on app initialization
/// e.g. "window.awesomePlugin = { ... the plugin interface }"
fn initialization_script(&self) -> Option , config: serde_json::Value) -> PluginResult<()> {
Ok(())
}
/// Callback invoked when the Window is created.
fn created(&mut self, window: Window ) {}
/// Callback invoked when the webview performs a navigation.
fn on_page_load(&mut self, window: Window , payload: PageLoadPayload) {}
/// Extend the invoke handler.
fn extend_api(&mut self, message: Invoke ) {
(self.invoke_handler)(message)
}
}
```
Note that each function on the `Plugin` trait is optional, except the `name` function.
## Using a plugin
To use a plugin, just pass an instance of the `MyAwesomePlugin` struct to the App's `plugin` method:
```rust
fn main() {
let awesome_plugin = MyAwesomePlugin::new();
tauri::Builder::default()
.plugin(awesome_plugin)
.run(tauri::generate_context!())
.expect("failed to run app");
}
```
## Official Tauri Plugins
- [Stronghold (WIP)](https://github.com/tauri-apps/tauri-plugin-stronghold)
- [Authenticator (WIP)](https://github.com/tauri-apps/tauri-plugin-authenticator)
- [Logging (WIP)](https://github.com/tauri-apps/tauri-plugin-log)
- [SQL (WIP)](https://github.com/tauri-apps/tauri-plugin-sql)