Skip to content

Commit

Permalink
feat(core): add plugin register API on the Manager trait (#2340)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Aug 2, 2021
1 parent 2eed5b5 commit 5b7be81
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/dynamic-plugin.md
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Allow registering a plugin on structs that implements the `Manager` trait (`App`, `AppHandle`, `Window`) using the trait's `plugin` method.
11 changes: 11 additions & 0 deletions core/tauri/src/lib.rs
Expand Up @@ -315,6 +315,17 @@ pub trait Manager<R: Runtime>: sealed::ManagerBase<R> {
{
self.manager().inner.state.get()
}

/// Adds a plugin to the runtime.
fn plugin<P: plugin::Plugin<R> + 'static>(&self, plugin: P) {
self
.manager()
.inner
.plugins
.lock()
.unwrap()
.register(plugin);
}
}

/// Prevent implementation details from leaking out of the [`Manager`] trait.
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/manager.rs
Expand Up @@ -60,7 +60,7 @@ const MENU_EVENT: &str = "tauri://menu";
#[default_runtime(crate::Wry, wry)]
pub struct InnerWindowManager<R: Runtime> {
windows: Mutex<HashMap<String, Window<R>>>,
plugins: Mutex<PluginStore<R>>,
pub(crate) plugins: Mutex<PluginStore<R>>,
listeners: Listeners,
pub(crate) state: Arc<StateManager>,

Expand Down

0 comments on commit 5b7be81

Please sign in to comment.