@@ -42,6 +42,7 @@ use std::{
4242 sync:: { Arc , Mutex , MutexGuard } ,
4343} ;
4444use tauri_macros:: default_runtime;
45+ use url:: Url ;
4546use uuid:: Uuid ;
4647
4748const WINDOW_RESIZED_EVENT : & str = "tauri://resize" ;
@@ -180,20 +181,27 @@ impl<R: Runtime> WindowManager<R> {
180181 self . inner . menu_ids . clone ( )
181182 }
182183
183- // setup content for dev-server
184+ /// Get the base path to serve data from.
185+ ///
186+ /// * In dev mode, this will be based on the `devPath` configuration value.
187+ /// * Otherwise, this will be based on the `distDir` configuration value.
188+ #[ cfg( custom_protocol) ]
189+ fn base_path ( & self ) -> & AppUrl {
190+ & self . inner . config . build . dist_dir
191+ }
192+
184193 #[ cfg( dev) ]
185- fn get_url ( & self ) -> String {
186- match & self . inner . config . build . dev_path {
187- AppUrl :: Url ( WindowUrl :: External ( url) ) => url. to_string ( ) ,
188- _ => "tauri://localhost" . into ( ) ,
189- }
194+ fn base_path ( & self ) -> & AppUrl {
195+ & self . inner . config . build . dev_path
190196 }
191197
192- #[ cfg( custom_protocol) ]
193- fn get_url ( & self ) -> String {
194- match & self . inner . config . build . dist_dir {
195- AppUrl :: Url ( WindowUrl :: External ( url) ) => url. to_string ( ) ,
196- _ => "tauri://localhost" . into ( ) ,
198+ /// Get the base URL to use for webview requests.
199+ ///
200+ /// In dev mode, this will be based on the `devPath` configuration value.
201+ fn get_url ( & self ) -> Cow < ' _ , Url > {
202+ match self . base_path ( ) {
203+ AppUrl :: Url ( WindowUrl :: External ( url) ) => Cow :: Borrowed ( url) ,
204+ _ => Cow :: Owned ( Url :: parse ( "tauri://localhost" ) . unwrap ( ) ) ,
197205 }
198206 }
199207
@@ -505,10 +513,10 @@ mod test {
505513 ) ;
506514
507515 #[ cfg( custom_protocol) ]
508- assert_eq ! ( manager. get_url( ) , "tauri://localhost" ) ;
516+ assert_eq ! ( manager. get_url( ) . to_string ( ) , "tauri://localhost" ) ;
509517
510518 #[ cfg( dev) ]
511- assert_eq ! ( manager. get_url( ) , "http://localhost:4000/" ) ;
519+ assert_eq ! ( manager. get_url( ) . to_string ( ) , "http://localhost:4000/" ) ;
512520 }
513521}
514522
@@ -561,13 +569,16 @@ impl<R: Runtime> WindowManager<R> {
561569 true ,
562570 // ignore "index.html" just to simplify the url
563571 if path. to_str ( ) != Some ( "index.html" ) {
564- format ! ( "{}/{}" , url, path. to_string_lossy( ) )
565- } else {
566572 url
573+ . join ( & * path. to_string_lossy ( ) )
574+ . map_err ( crate :: Error :: InvalidUrl ) ?
575+ . to_string ( )
576+ } else {
577+ url. to_string ( )
567578 } ,
568579 )
569580 }
570- WindowUrl :: External ( url) => ( url. as_str ( ) . starts_with ( "tauri://" ) , url. to_string ( ) ) ,
581+ WindowUrl :: External ( url) => ( url. scheme ( ) == "tauri" , url. to_string ( ) ) ,
571582 _ => unimplemented ! ( ) ,
572583 } ;
573584
0 commit comments