@@ -42,6 +42,7 @@ use std::{
42
42
sync:: { Arc , Mutex , MutexGuard } ,
43
43
} ;
44
44
use tauri_macros:: default_runtime;
45
+ use url:: Url ;
45
46
use uuid:: Uuid ;
46
47
47
48
const WINDOW_RESIZED_EVENT : & str = "tauri://resize" ;
@@ -180,20 +181,27 @@ impl<R: Runtime> WindowManager<R> {
180
181
self . inner . menu_ids . clone ( )
181
182
}
182
183
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
+
184
193
#[ 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
190
196
}
191
197
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 ( ) ) ,
197
205
}
198
206
}
199
207
@@ -505,10 +513,10 @@ mod test {
505
513
) ;
506
514
507
515
#[ cfg( custom_protocol) ]
508
- assert_eq ! ( manager. get_url( ) , "tauri://localhost" ) ;
516
+ assert_eq ! ( manager. get_url( ) . to_string ( ) , "tauri://localhost" ) ;
509
517
510
518
#[ cfg( dev) ]
511
- assert_eq ! ( manager. get_url( ) , "http://localhost:4000/" ) ;
519
+ assert_eq ! ( manager. get_url( ) . to_string ( ) , "http://localhost:4000/" ) ;
512
520
}
513
521
}
514
522
@@ -561,13 +569,16 @@ impl<R: Runtime> WindowManager<R> {
561
569
true ,
562
570
// ignore "index.html" just to simplify the url
563
571
if path. to_str ( ) != Some ( "index.html" ) {
564
- format ! ( "{}/{}" , url, path. to_string_lossy( ) )
565
- } else {
566
572
url
573
+ . join ( & * path. to_string_lossy ( ) )
574
+ . map_err ( crate :: Error :: InvalidUrl ) ?
575
+ . to_string ( )
576
+ } else {
577
+ url. to_string ( )
567
578
} ,
568
579
)
569
580
}
570
- WindowUrl :: External ( url) => ( url. as_str ( ) . starts_with ( "tauri://" ) , url. to_string ( ) ) ,
581
+ WindowUrl :: External ( url) => ( url. scheme ( ) == "tauri" , url. to_string ( ) ) ,
571
582
_ => unimplemented ! ( ) ,
572
583
} ;
573
584
0 commit comments