@@ -25,10 +25,9 @@ use tauri_utils::{
2525 html:: { SCRIPT_NONCE_TOKEN , STYLE_NONCE_TOKEN } ,
2626} ;
2727
28- use crate :: hooks:: IpcJavascript ;
2928#[ cfg( feature = "isolation" ) ]
3029use crate :: hooks:: IsolationJavascript ;
31- use crate :: pattern:: { format_real_schema , PatternJavascript } ;
30+ use crate :: pattern:: PatternJavascript ;
3231use crate :: {
3332 app:: { AppHandle , GlobalWindowEvent , GlobalWindowEventListener } ,
3433 event:: { assert_event_name_is_valid, Event , EventHandler , Listeners } ,
@@ -54,6 +53,7 @@ use crate::{
5453 app:: { GlobalMenuEventListener , WindowMenuEvent } ,
5554 window:: WebResourceRequestHandler ,
5655} ;
56+ use crate :: { hooks:: IpcJavascript , pattern:: format_real_schema} ;
5757
5858#[ cfg( any( target_os = "linux" , target_os = "windows" ) ) ]
5959use crate :: api:: path:: { resolve_path, BaseDirectory } ;
@@ -136,7 +136,7 @@ fn set_csp<R: Runtime>(
136136 let default_src = csp
137137 . entry ( "default-src" . into ( ) )
138138 . or_insert_with ( Default :: default) ;
139- default_src. push ( format_real_schema ( schema) ) ;
139+ default_src. push ( crate :: pattern :: format_real_schema ( schema) ) ;
140140 }
141141
142142 Csp :: DirectiveMap ( csp) . to_string ( )
@@ -225,7 +225,7 @@ pub struct InnerWindowManager<R: Runtime> {
225225 /// The script that initializes the invoke system.
226226 invoke_initialization_script : String ,
227227 /// Application pattern.
228- pattern : Pattern ,
228+ pub ( crate ) pattern : Pattern ,
229229}
230230
231231impl < R : Runtime > fmt:: Debug for InnerWindowManager < R > {
@@ -357,9 +357,12 @@ impl<R: Runtime> WindowManager<R> {
357357 /// Get the base URL to use for webview requests.
358358 ///
359359 /// In dev mode, this will be based on the `devPath` configuration value.
360- fn get_url ( & self ) -> Cow < ' _ , Url > {
360+ pub ( crate ) fn get_url ( & self ) -> Cow < ' _ , Url > {
361361 match self . base_path ( ) {
362362 AppUrl :: Url ( WindowUrl :: External ( url) ) => Cow :: Borrowed ( url) ,
363+ #[ cfg( windows) ]
364+ _ => Cow :: Owned ( Url :: parse ( "https://tauri.localhost" ) . unwrap ( ) ) ,
365+ #[ cfg( not( windows) ) ]
363366 _ => Cow :: Owned ( Url :: parse ( "tauri://localhost" ) . unwrap ( ) ) ,
364367 }
365368 }
@@ -467,7 +470,7 @@ impl<R: Runtime> WindowManager<R> {
467470 } ) ;
468471 }
469472
470- let window_url = Url :: parse ( & pending. url ) . unwrap ( ) ;
473+ let window_url = pending. current_url . lock ( ) . unwrap ( ) . clone ( ) ;
471474 let window_origin =
472475 if cfg ! ( windows) && window_url. scheme ( ) != "http" && window_url. scheme ( ) != "https" {
473476 format ! ( "https://{}.localhost" , window_url. scheme( ) )
@@ -1001,7 +1004,16 @@ mod test {
10011004 ) ;
10021005
10031006 #[ cfg( custom_protocol) ]
1004- assert_eq ! ( manager. get_url( ) . to_string( ) , "tauri://localhost" ) ;
1007+ {
1008+ assert_eq ! (
1009+ manager. get_url( ) . to_string( ) ,
1010+ if cfg!( windows) {
1011+ "https://tauri.localhost/"
1012+ } else {
1013+ "tauri://localhost"
1014+ }
1015+ ) ;
1016+ }
10051017
10061018 #[ cfg( dev) ]
10071019 assert_eq ! ( manager. get_url( ) . to_string( ) , "http://localhost:4000/" ) ;
@@ -1052,27 +1064,21 @@ impl<R: Runtime> WindowManager<R> {
10521064 return Err ( crate :: Error :: WindowLabelAlreadyExists ( pending. label ) ) ;
10531065 }
10541066 #[ allow( unused_mut) ] // mut url only for the data-url parsing
1055- let ( is_local , mut url) = match & pending. webview_attributes . url {
1067+ let mut url = match & pending. webview_attributes . url {
10561068 WindowUrl :: App ( path) => {
10571069 let url = self . get_url ( ) ;
1058- (
1059- true ,
1060- // ignore "index.html" just to simplify the url
1061- if path. to_str ( ) != Some ( "index.html" ) {
1062- url
1063- . join ( & * path. to_string_lossy ( ) )
1064- . map_err ( crate :: Error :: InvalidUrl )
1065- // this will never fail
1066- . unwrap ( )
1067- } else {
1068- url. into_owned ( )
1069- } ,
1070- )
1071- }
1072- WindowUrl :: External ( url) => {
1073- let config_url = self . get_url ( ) ;
1074- ( config_url. make_relative ( url) . is_some ( ) , url. clone ( ) )
1070+ // ignore "index.html" just to simplify the url
1071+ if path. to_str ( ) != Some ( "index.html" ) {
1072+ url
1073+ . join ( & * path. to_string_lossy ( ) )
1074+ . map_err ( crate :: Error :: InvalidUrl )
1075+ // this will never fail
1076+ . unwrap ( )
1077+ } else {
1078+ url. into_owned ( )
1079+ }
10751080 }
1081+ WindowUrl :: External ( url) => url. clone ( ) ,
10761082 _ => unimplemented ! ( ) ,
10771083 } ;
10781084
@@ -1099,7 +1105,7 @@ impl<R: Runtime> WindowManager<R> {
10991105 }
11001106 }
11011107
1102- pending. url = url. to_string ( ) ;
1108+ * pending. current_url . lock ( ) . unwrap ( ) = url;
11031109
11041110 if !pending. window_builder . has_icon ( ) {
11051111 if let Some ( default_window_icon) = self . inner . default_window_icon . clone ( ) {
@@ -1115,17 +1121,15 @@ impl<R: Runtime> WindowManager<R> {
11151121 }
11161122 }
11171123
1118- if is_local {
1119- let label = pending. label . clone ( ) ;
1120- pending = self . prepare_pending_window (
1121- pending,
1122- & label,
1123- window_labels,
1124- app_handle. clone ( ) ,
1125- web_resource_request_handler,
1126- ) ?;
1127- pending. ipc_handler = Some ( self . prepare_ipc_handler ( app_handle) ) ;
1128- }
1124+ let label = pending. label . clone ( ) ;
1125+ pending = self . prepare_pending_window (
1126+ pending,
1127+ & label,
1128+ window_labels,
1129+ app_handle. clone ( ) ,
1130+ web_resource_request_handler,
1131+ ) ?;
1132+ pending. ipc_handler = Some ( self . prepare_ipc_handler ( app_handle) ) ;
11291133
11301134 // in `Windows`, we need to force a data_directory
11311135 // but we do respect user-specification
@@ -1150,6 +1154,17 @@ impl<R: Runtime> WindowManager<R> {
11501154 }
11511155 }
11521156
1157+ let current_url_ = pending. current_url . clone ( ) ;
1158+ let navigation_handler = pending. navigation_handler . take ( ) ;
1159+ pending. navigation_handler = Some ( Box :: new ( move |url| {
1160+ * current_url_. lock ( ) . unwrap ( ) = url. clone ( ) ;
1161+ if let Some ( handler) = & navigation_handler {
1162+ handler ( url)
1163+ } else {
1164+ true
1165+ }
1166+ } ) ) ;
1167+
11531168 Ok ( pending)
11541169 }
11551170
0 commit comments