@@ -116,7 +116,7 @@ pub fn launch(root: Component) {
116116/// ```
117117pub fn launch_cfg (
118118 root : Component ,
119- config_builder : impl for < ' a , ' b > FnOnce ( & ' b mut DesktopConfig < ' a > ) -> & ' b mut DesktopConfig < ' a > ,
119+ config_builder : impl FnOnce ( & mut DesktopConfig ) -> & mut DesktopConfig ,
120120) {
121121 launch_with_props ( root, ( ) , config_builder)
122122}
@@ -147,7 +147,7 @@ pub fn launch_cfg(
147147pub fn launch_with_props < P : ' static + Send > (
148148 root : Component < P > ,
149149 props : P ,
150- builder : impl for < ' a , ' b > FnOnce ( & ' b mut DesktopConfig < ' a > ) -> & ' b mut DesktopConfig < ' a > ,
150+ builder : impl FnOnce ( & mut DesktopConfig ) -> & mut DesktopConfig ,
151151) {
152152 let mut cfg = DesktopConfig :: new ( ) ;
153153 builder ( & mut cfg) ;
@@ -170,9 +170,11 @@ pub fn launch_with_props<P: 'static + Send>(
170170 let ( is_ready, sender) = ( desktop. is_ready . clone ( ) , desktop. sender . clone ( ) ) ;
171171
172172 let proxy = proxy. clone ( ) ;
173- let webview = WebViewBuilder :: new ( window)
173+ let file_handler = cfg. file_drop_handler . take ( ) ;
174+
175+ let mut webview = WebViewBuilder :: new ( window)
174176 . unwrap ( )
175- . with_url ( "wry ://index.html/" )
177+ . with_url ( "dioxus ://index.html/" )
176178 . unwrap ( )
177179 . with_rpc_handler ( move |_window : & Window , req : RpcRequest | {
178180 match req. method . as_str ( ) {
@@ -189,26 +191,37 @@ pub fn launch_with_props<P: 'static + Send>(
189191 }
190192 None
191193 } )
192- . with_custom_protocol ( "wry " . into ( ) , move |request| {
193- // Any content that that uses the `wry ://` scheme will be shuttled through this handler as a "special case"
194+ . with_custom_protocol ( "dioxus " . into ( ) , move |request| {
195+ // Any content that that uses the `dioxus ://` scheme will be shuttled through this handler as a "special case"
194196 // For now, we only serve two pieces of content which get included as bytes into the final binary.
195- let path = request. uri ( ) . replace ( "wry://" , "" ) ;
196- let ( data, meta) = match path. as_str ( ) {
197- "index.html" | "index.html/" | "/index.html" => {
198- ( include_bytes ! ( "./index.html" ) . to_vec ( ) , "text/html" )
199- }
200- "index.html/index.js" => {
201- ( include_bytes ! ( "./index.js" ) . to_vec ( ) , "text/javascript" )
202- }
203- _ => ( include_bytes ! ( "./index.html" ) . to_vec ( ) , "text/html" ) ,
204- } ;
205-
206- wry:: http:: ResponseBuilder :: new ( ) . mimetype ( meta) . body ( data)
197+ let path = request. uri ( ) . replace ( "dioxus://" , "" ) ;
198+
199+ if path. trim_end_matches ( '/' ) == "index.html" {
200+ wry:: http:: ResponseBuilder :: new ( )
201+ . mimetype ( "text/html" )
202+ . body ( include_bytes ! ( "./index.html" ) . to_vec ( ) )
203+ } else if path. trim_end_matches ( '/' ) == "index.html/index.js" {
204+ wry:: http:: ResponseBuilder :: new ( )
205+ . mimetype ( "text/javascript" )
206+ . body ( include_bytes ! ( "./index.js" ) . to_vec ( ) )
207+ } else {
208+ wry:: http:: ResponseBuilder :: new ( )
209+ . status ( wry:: http:: status:: StatusCode :: NOT_FOUND )
210+ . body ( format ! ( "Not found: {}" , path) . as_bytes ( ) . to_vec ( ) )
211+ }
207212 } )
208- . build ( )
209- . unwrap ( ) ;
213+ . with_file_drop_handler ( move |window, evet| {
214+ if let Some ( handler) = file_handler. as_ref ( ) {
215+ return handler ( window, evet) ;
216+ }
217+ false
218+ } ) ;
219+
220+ for ( name, handler) in cfg. protocos . drain ( ..) {
221+ webview = webview. with_custom_protocol ( name, handler)
222+ }
210223
211- desktop. webviews . insert ( window_id, webview) ;
224+ desktop. webviews . insert ( window_id, webview. build ( ) . unwrap ( ) ) ;
212225 }
213226
214227 Event :: WindowEvent {
0 commit comments