@@ -303,6 +303,17 @@ impl<R: Runtime> WindowManager<R> {
303303 registered_scheme_protocols. push ( "tauri" . into ( ) ) ;
304304 }
305305 if !registered_scheme_protocols. contains ( & "asset" . into ( ) ) {
306+ let window_url = Url :: parse ( & pending. url ) . unwrap ( ) ;
307+ let window_origin = format ! (
308+ "{}://{}{}" ,
309+ window_url. scheme( ) ,
310+ window_url. host( ) . unwrap( ) ,
311+ if let Some ( port) = window_url. port( ) {
312+ format!( ":{}" , port)
313+ } else {
314+ "" . into( )
315+ }
316+ ) ;
306317 pending. register_uri_scheme_protocol ( "asset" , move |request| {
307318 #[ cfg( target_os = "windows" ) ]
308319 let path = request. uri ( ) . replace ( "asset://localhost/" , "" ) ;
@@ -313,11 +324,13 @@ impl<R: Runtime> WindowManager<R> {
313324 . to_string ( ) ;
314325 let path_for_data = path. clone ( ) ;
315326
327+ let mut response =
328+ HttpResponseBuilder :: new ( ) . header ( "Access-Control-Allow-Origin" , & window_origin) ;
329+
316330 // handle 206 (partial range) http request
317331 if let Some ( range) = request. headers ( ) . get ( "range" ) . cloned ( ) {
318332 let mut status_code = 200 ;
319333 let path_for_data = path_for_data. clone ( ) ;
320- let mut response = HttpResponseBuilder :: new ( ) ;
321334 let ( headers, status_code, data) = crate :: async_runtime:: safe_block_on ( async move {
322335 let mut headers = HashMap :: new ( ) ;
323336 let mut buf = Vec :: new ( ) ;
@@ -371,10 +384,14 @@ impl<R: Runtime> WindowManager<R> {
371384 }
372385 }
373386
374- let data =
375- crate :: async_runtime:: safe_block_on ( async move { tokio:: fs:: read ( path_for_data) . await } ) ?;
376- let mime_type = MimeType :: parse ( & data, & path) ;
377- HttpResponseBuilder :: new ( ) . mimetype ( & mime_type) . body ( data)
387+ if let Ok ( data) =
388+ crate :: async_runtime:: safe_block_on ( async move { tokio:: fs:: read ( path_for_data) . await } )
389+ {
390+ let mime_type = MimeType :: parse ( & data, & path) ;
391+ response. mimetype ( & mime_type) . body ( data)
392+ } else {
393+ response. status ( 404 ) . body ( Vec :: new ( ) )
394+ }
378395 } ) ;
379396 }
380397
@@ -634,6 +651,8 @@ impl<R: Runtime> WindowManager<R> {
634651 _ => unimplemented ! ( ) ,
635652 } ;
636653
654+ pending. url = url;
655+
637656 if is_local {
638657 let label = pending. label . clone ( ) ;
639658 pending = self . prepare_pending_window ( pending, & label, pending_labels, app_handle. clone ( ) ) ?;
@@ -644,8 +663,6 @@ impl<R: Runtime> WindowManager<R> {
644663 pending. file_drop_handler = Some ( self . prepare_file_drop ( app_handle) ) ;
645664 }
646665
647- pending. url = url;
648-
649666 // in `Windows`, we need to force a data_directory
650667 // but we do respect user-specification
651668 #[ cfg( target_os = "windows" ) ]
0 commit comments