@@ -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 } ;
@@ -139,7 +139,7 @@ fn set_csp<R: Runtime>(
139139 let default_src = csp
140140 . entry ( "default-src" . into ( ) )
141141 . or_insert_with ( Default :: default) ;
142- default_src. push ( format_real_schema ( schema) ) ;
142+ default_src. push ( crate :: pattern :: format_real_schema ( schema) ) ;
143143 }
144144
145145 Csp :: DirectiveMap ( csp) . to_string ( )
@@ -231,7 +231,7 @@ pub struct InnerWindowManager<R: Runtime> {
231231 /// The script that initializes the invoke system.
232232 invoke_initialization_script : String ,
233233 /// Application pattern.
234- pattern : Pattern ,
234+ pub ( crate ) pattern : Pattern ,
235235}
236236
237237impl < R : Runtime > fmt:: Debug for InnerWindowManager < R > {
@@ -367,9 +367,12 @@ impl<R: Runtime> WindowManager<R> {
367367 /// Get the base URL to use for webview requests.
368368 ///
369369 /// In dev mode, this will be based on the `devPath` configuration value.
370- fn get_url ( & self ) -> Cow < ' _ , Url > {
370+ pub ( crate ) fn get_url ( & self ) -> Cow < ' _ , Url > {
371371 match self . base_path ( ) {
372372 AppUrl :: Url ( WindowUrl :: External ( url) ) => Cow :: Borrowed ( url) ,
373+ #[ cfg( windows) ]
374+ _ => Cow :: Owned ( Url :: parse ( "https://tauri.localhost" ) . unwrap ( ) ) ,
375+ #[ cfg( not( windows) ) ]
373376 _ => Cow :: Owned ( Url :: parse ( "tauri://localhost" ) . unwrap ( ) ) ,
374377 }
375378 }
@@ -477,7 +480,7 @@ impl<R: Runtime> WindowManager<R> {
477480 } ) ;
478481 }
479482
480- let window_url = Url :: parse ( & pending. url ) . unwrap ( ) ;
483+ let window_url = pending. current_url . lock ( ) . unwrap ( ) . clone ( ) ;
481484 let window_origin =
482485 if cfg ! ( windows) && window_url. scheme ( ) != "http" && window_url. scheme ( ) != "https" {
483486 format ! ( "https://{}.localhost" , window_url. scheme( ) )
@@ -1072,7 +1075,16 @@ mod test {
10721075 ) ;
10731076
10741077 #[ cfg( custom_protocol) ]
1075- assert_eq ! ( manager. get_url( ) . to_string( ) , "tauri://localhost" ) ;
1078+ {
1079+ assert_eq ! (
1080+ manager. get_url( ) . to_string( ) ,
1081+ if cfg!( windows) {
1082+ "https://tauri.localhost/"
1083+ } else {
1084+ "tauri://localhost"
1085+ }
1086+ ) ;
1087+ }
10761088
10771089 #[ cfg( dev) ]
10781090 assert_eq ! ( manager. get_url( ) . to_string( ) , "http://localhost:4000/" ) ;
@@ -1123,27 +1135,21 @@ impl<R: Runtime> WindowManager<R> {
11231135 return Err ( crate :: Error :: WindowLabelAlreadyExists ( pending. label ) ) ;
11241136 }
11251137 #[ allow( unused_mut) ] // mut url only for the data-url parsing
1126- let ( is_local , mut url) = match & pending. webview_attributes . url {
1138+ let mut url = match & pending. webview_attributes . url {
11271139 WindowUrl :: App ( path) => {
11281140 let url = self . get_url ( ) ;
1129- (
1130- true ,
1131- // ignore "index.html" just to simplify the url
1132- if path. to_str ( ) != Some ( "index.html" ) {
1133- url
1134- . join ( & path. to_string_lossy ( ) )
1135- . map_err ( crate :: Error :: InvalidUrl )
1136- // this will never fail
1137- . unwrap ( )
1138- } else {
1139- url. into_owned ( )
1140- } ,
1141- )
1142- }
1143- WindowUrl :: External ( url) => {
1144- let config_url = self . get_url ( ) ;
1145- ( config_url. make_relative ( url) . is_some ( ) , url. clone ( ) )
1141+ // ignore "index.html" just to simplify the url
1142+ if path. to_str ( ) != Some ( "index.html" ) {
1143+ url
1144+ . join ( & * path. to_string_lossy ( ) )
1145+ . map_err ( crate :: Error :: InvalidUrl )
1146+ // this will never fail
1147+ . unwrap ( )
1148+ } else {
1149+ url. into_owned ( )
1150+ }
11461151 }
1152+ WindowUrl :: External ( url) => url. clone ( ) ,
11471153 _ => unimplemented ! ( ) ,
11481154 } ;
11491155
@@ -1170,7 +1176,7 @@ impl<R: Runtime> WindowManager<R> {
11701176 }
11711177 }
11721178
1173- pending. url = url. to_string ( ) ;
1179+ * pending. current_url . lock ( ) . unwrap ( ) = url;
11741180
11751181 if !pending. window_builder . has_icon ( ) {
11761182 if let Some ( default_window_icon) = self . inner . default_window_icon . clone ( ) {
@@ -1186,17 +1192,15 @@ impl<R: Runtime> WindowManager<R> {
11861192 }
11871193 }
11881194
1189- if is_local {
1190- let label = pending. label . clone ( ) ;
1191- pending = self . prepare_pending_window (
1192- pending,
1193- & label,
1194- window_labels,
1195- app_handle. clone ( ) ,
1196- web_resource_request_handler,
1197- ) ?;
1198- pending. ipc_handler = Some ( self . prepare_ipc_handler ( app_handle) ) ;
1199- }
1195+ let label = pending. label . clone ( ) ;
1196+ pending = self . prepare_pending_window (
1197+ pending,
1198+ & label,
1199+ window_labels,
1200+ app_handle. clone ( ) ,
1201+ web_resource_request_handler,
1202+ ) ?;
1203+ pending. ipc_handler = Some ( self . prepare_ipc_handler ( app_handle) ) ;
12001204
12011205 // in `Windows`, we need to force a data_directory
12021206 // but we do respect user-specification
@@ -1221,6 +1225,17 @@ impl<R: Runtime> WindowManager<R> {
12211225 }
12221226 }
12231227
1228+ let current_url_ = pending. current_url . clone ( ) ;
1229+ let navigation_handler = pending. navigation_handler . take ( ) ;
1230+ pending. navigation_handler = Some ( Box :: new ( move |url| {
1231+ * current_url_. lock ( ) . unwrap ( ) = url. clone ( ) ;
1232+ if let Some ( handler) = & navigation_handler {
1233+ handler ( url)
1234+ } else {
1235+ true
1236+ }
1237+ } ) ) ;
1238+
12241239 Ok ( pending)
12251240 }
12261241
0 commit comments