Skip to main content

init

Function init 

Source
pub fn init<R: Runtime>() -> TauriPlugin<R>
Expand description

Initialise the plugin which will take care of polyfilling WebMIDI into any Tauri webview.

ยงUsage

Using this plugin is very simple. Just add it to your Tauri builder:

 tauri::Builder::default()
       .plugin(tauri_plugin_midi::init()) // <- This bit here
       // .... rest of your builder

Then give permissions to the plugin by adding the midi:default permissions to your application.

This can be done by modifying the capabilities/default.json file:

{
  "$schema": "../gen/schemas/desktop-schema.json",
  "identifier": "default",
  "description": "Capability for the main window",
  "windows": ["main"],
  "permissions": ["core:default", "midi:default"] // <- add `midi:default` into here
}

and now you can use the regular WebMIDI API from within your webview.

The polyfill is injected into every frame (not just the main frame) so that it can be used from within iframes. Tauri itself only injects __TAURI_INTERNALS__ and the IPC bridge into the main frame (and, on Windows, into subframes too), so in a same-origin subframe on macOS/Linux the polyfill bridges its IPC calls to the top frame over postMessage. See issue #7.