Skip to content

Commit 5b7be81

Browse files
authored
feat(core): add plugin register API on the Manager trait (#2340)
1 parent 2eed5b5 commit 5b7be81

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

.changes/dynamic-plugin.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Allow registering a plugin on structs that implements the `Manager` trait (`App`, `AppHandle`, `Window`) using the trait's `plugin` method.

core/tauri/src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,17 @@ pub trait Manager<R: Runtime>: sealed::ManagerBase<R> {
315315
{
316316
self.manager().inner.state.get()
317317
}
318+
319+
/// Adds a plugin to the runtime.
320+
fn plugin<P: plugin::Plugin<R> + 'static>(&self, plugin: P) {
321+
self
322+
.manager()
323+
.inner
324+
.plugins
325+
.lock()
326+
.unwrap()
327+
.register(plugin);
328+
}
318329
}
319330

320331
/// Prevent implementation details from leaking out of the [`Manager`] trait.

core/tauri/src/manager.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const MENU_EVENT: &str = "tauri://menu";
6060
#[default_runtime(crate::Wry, wry)]
6161
pub struct InnerWindowManager<R: Runtime> {
6262
windows: Mutex<HashMap<String, Window<R>>>,
63-
plugins: Mutex<PluginStore<R>>,
63+
pub(crate) plugins: Mutex<PluginStore<R>>,
6464
listeners: Listeners,
6565
pub(crate) state: Arc<StateManager>,
6666

0 commit comments

Comments
 (0)