1+ use crate :: Webview ;
12use futures:: future:: BoxFuture ;
2- use webview_official:: WebviewMut ;
33
44mod runner;
55
6- type InvokeHandler =
7- dyn Fn ( WebviewMut , String ) -> BoxFuture < ' static , Result < ( ) , String > > + Send + Sync ;
8- type Setup = dyn Fn ( WebviewMut , String ) -> BoxFuture < ' static , ( ) > + Send + Sync ;
6+ type InvokeHandler < W > = dyn Fn ( W , String ) -> BoxFuture < ' static , Result < ( ) , String > > + Send + Sync ;
7+ type Setup < W > = dyn Fn ( W , String ) -> BoxFuture < ' static , ( ) > + Send + Sync ;
98
109/// The application runner.
11- pub struct App {
10+ pub struct App < W : Webview > {
1211 /// The JS message handler.
13- invoke_handler : Option < Box < InvokeHandler > > ,
12+ invoke_handler : Option < Box < InvokeHandler < W > > > ,
1413 /// The setup callback, invoked when the webview is ready.
15- setup : Option < Box < Setup > > ,
14+ setup : Option < Box < Setup < W > > > ,
1615 /// The HTML of the splashscreen to render.
1716 splashscreen_html : Option < String > ,
1817}
1918
20- impl App {
19+ impl < W : Webview + ' static > App < W > {
2120 /// Runs the app until it finishes.
2221 pub fn run ( self ) {
2322 runner:: run ( self ) . expect ( "Failed to build webview" ) ;
@@ -28,7 +27,7 @@ impl App {
2827 /// The message is considered consumed if the handler exists and returns an Ok Result.
2928 pub ( crate ) async fn run_invoke_handler (
3029 & self ,
31- webview : & mut WebviewMut ,
30+ webview : & mut W ,
3231 arg : & str ,
3332 ) -> Result < bool , String > {
3433 if let Some ( ref invoke_handler) = self . invoke_handler {
@@ -40,7 +39,7 @@ impl App {
4039 }
4140
4241 /// Runs the setup callback if defined.
43- pub ( crate ) async fn run_setup ( & self , webview : & mut WebviewMut , source : String ) {
42+ pub ( crate ) async fn run_setup ( & self , webview : & mut W , source : String ) {
4443 if let Some ( ref setup) = self . setup {
4544 let fut = setup ( webview. clone ( ) , source) ;
4645 fut. await ;
@@ -55,16 +54,16 @@ impl App {
5554
5655/// The App builder.
5756#[ derive( Default ) ]
58- pub struct AppBuilder {
57+ pub struct AppBuilder < W : Webview > {
5958 /// The JS message handler.
60- invoke_handler : Option < Box < InvokeHandler > > ,
59+ invoke_handler : Option < Box < InvokeHandler < W > > > ,
6160 /// The setup callback, invoked when the webview is ready.
62- setup : Option < Box < Setup > > ,
61+ setup : Option < Box < Setup < W > > > ,
6362 /// The HTML of the splashscreen to render.
6463 splashscreen_html : Option < String > ,
6564}
6665
67- impl AppBuilder {
66+ impl < W : Webview + ' static > AppBuilder < W > {
6867 /// Creates a new App builder.
6968 pub fn new ( ) -> Self {
7069 Self {
@@ -77,7 +76,7 @@ impl AppBuilder {
7776 /// Defines the JS message handler callback.
7877 pub fn invoke_handler <
7978 T : futures:: Future < Output = Result < ( ) , String > > + Send + Sync + ' static ,
80- F : Fn ( WebviewMut , String ) -> T + Send + Sync + ' static ,
79+ F : Fn ( W , String ) -> T + Send + Sync + ' static ,
8180 > (
8281 mut self ,
8382 invoke_handler : F ,
@@ -91,7 +90,7 @@ impl AppBuilder {
9190 /// Defines the setup callback.
9291 pub fn setup <
9392 T : futures:: Future < Output = ( ) > + Send + Sync + ' static ,
94- F : Fn ( WebviewMut , String ) -> T + Send + Sync + ' static ,
93+ F : Fn ( W , String ) -> T + Send + Sync + ' static ,
9594 > (
9695 mut self ,
9796 setup : F ,
@@ -109,13 +108,16 @@ impl AppBuilder {
109108 }
110109
111110 /// Adds a plugin to the runtime.
112- pub fn plugin ( self , plugin : impl crate :: plugin:: Plugin + Send + Sync + Sync + ' static ) -> Self {
113- crate :: async_runtime:: block_on ( crate :: plugin:: register ( plugin) ) ;
111+ pub fn plugin (
112+ self ,
113+ plugin : impl crate :: plugin:: Plugin < W > + Send + Sync + Sync + ' static ,
114+ ) -> Self {
115+ crate :: async_runtime:: block_on ( crate :: plugin:: register ( W :: plugin_store ( ) , plugin) ) ;
114116 self
115117 }
116118
117119 /// Builds the App.
118- pub fn build ( self ) -> App {
120+ pub fn build ( self ) -> App < W > {
119121 App {
120122 invoke_handler : self . invoke_handler ,
121123 setup : self . setup ,
0 commit comments