pub trait Plugin<R: Runtime>: Send {
// Required method
fn name(&self) -> &'static str;
// Provided methods
fn initialize(
&mut self,
app: &AppHandle<R>,
config: JsonValue,
) -> Result<(), Box<dyn Error>> { ... }
fn initialization_script(&self) -> Option<String> { ... }
fn initialization_script_2(&self) -> Option<InitializationScript> { ... }
fn window_created(&mut self, window: Window<R>) { ... }
fn webview_created(&mut self, webview: Webview<R>) { ... }
fn on_navigation(&mut self, webview: &Webview<R>, url: &Url) -> bool { ... }
fn on_page_load(
&mut self,
webview: &Webview<R>,
payload: &PageLoadPayload<'_>,
) { ... }
fn on_event(&mut self, app: &AppHandle<R>, event: &RunEvent) { ... }
fn extend_api(&mut self, invoke: Invoke<R>) -> bool { ... }
}Expand description
The plugin interface.
Required Methods§
Provided Methods§
Sourcefn initialize(
&mut self,
app: &AppHandle<R>,
config: JsonValue,
) -> Result<(), Box<dyn Error>>
fn initialize( &mut self, app: &AppHandle<R>, config: JsonValue, ) -> Result<(), Box<dyn Error>>
Initializes the plugin.
Sourcefn initialization_script(&self) -> Option<String>
fn initialization_script(&self) -> Option<String>
Add the provided JavaScript to a list of scripts that should be run after the global object has been created, but before the HTML document has been parsed and before any other script included by the HTML document is run.
The script is wrapped into its own context with (function () { /* your script here */ })();,
so global variables must be assigned to window instead of implicitly declared.
This is executed only on the main frame.
If you only want to run it in all frames, use Plugin::initialization_script_2 to set that to false.
§Platform-specific
- Windows: scripts are always added to subframes.
- Android: When addDocumentStartJavaScript is not supported, we prepend initialization scripts to each HTML head (implementation only supported on custom protocol URLs). For remote URLs, we use onPageStarted which is not guaranteed to run before other scripts.
Sourcefn initialization_script_2(&self) -> Option<InitializationScript>
fn initialization_script_2(&self) -> Option<InitializationScript>
Same as Plugin::initialization_script but returns an InitializationScript instead
We plan to replace Plugin::initialization_script with this signature in v3
Sourcefn window_created(&mut self, window: Window<R>)
fn window_created(&mut self, window: Window<R>)
Callback invoked when the window is created.
Sourcefn webview_created(&mut self, webview: Webview<R>)
fn webview_created(&mut self, webview: Webview<R>)
Callback invoked when the webview is created.
Callback invoked when webview tries to navigate to the given Url. Returning falses cancels navigation.
Sourcefn on_page_load(&mut self, webview: &Webview<R>, payload: &PageLoadPayload<'_>)
fn on_page_load(&mut self, webview: &Webview<R>, payload: &PageLoadPayload<'_>)
Callback invoked when the webview performs a navigation to a page.
Sourcefn on_event(&mut self, app: &AppHandle<R>, event: &RunEvent)
fn on_event(&mut self, app: &AppHandle<R>, event: &RunEvent)
Callback invoked when the event loop receives a new event.
Sourcefn extend_api(&mut self, invoke: Invoke<R>) -> bool
fn extend_api(&mut self, invoke: Invoke<R>) -> bool
Extend commands to crate::Builder::invoke_handler.