@@ -484,10 +484,16 @@ impl<R: Runtime> AppHandle<R> {
484484 /// Ok(())
485485 /// });
486486 /// ```
487- #[ cfg_attr( feature = "tracing" , tracing:: instrument( name = "app::plugin::register" , skip( plugin) , fields( name = plugin. name( ) ) ) ) ]
488487 pub fn plugin < P : Plugin < R > + ' static > ( & self , plugin : P ) -> crate :: Result < ( ) > {
489- let mut plugin = Box :: new ( plugin) as Box < dyn Plugin < R > > ;
488+ self . plugin_boxed ( Box :: new ( plugin) )
489+ }
490490
491+ /// Adds a Tauri application plugin.
492+ ///
493+ /// This method is similar to [`Self::plugin`],
494+ /// but accepts a boxed trait object instead of a generic type.
495+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( name = "app::plugin::register" , skip( plugin) , fields( name = plugin. name( ) ) ) ) ]
496+ pub fn plugin_boxed ( & self , mut plugin : Box < dyn Plugin < R > > ) -> crate :: Result < ( ) > {
491497 let mut store = self . manager ( ) . plugins . lock ( ) . unwrap ( ) ;
492498 store. initialize ( & mut plugin, self , & self . config ( ) . plugins ) ?;
493499 store. register ( plugin) ;
@@ -1683,8 +1689,17 @@ tauri::Builder::default()
16831689 /// .plugin(plugin::init());
16841690 /// ```
16851691 #[ must_use]
1686- pub fn plugin < P : Plugin < R > + ' static > ( mut self , plugin : P ) -> Self {
1687- self . plugins . register ( Box :: new ( plugin) ) ;
1692+ pub fn plugin < P : Plugin < R > + ' static > ( self , plugin : P ) -> Self {
1693+ self . plugin_boxed ( Box :: new ( plugin) )
1694+ }
1695+
1696+ /// Adds a Tauri application plugin.
1697+ ///
1698+ /// This method is similar to [`Self::plugin`],
1699+ /// but accepts a boxed trait object instead of a generic type.
1700+ #[ must_use]
1701+ pub fn plugin_boxed ( mut self , plugin : Box < dyn Plugin < R > > ) -> Self {
1702+ self . plugins . register ( plugin) ;
16881703 self
16891704 }
16901705
0 commit comments