@@ -6,7 +6,6 @@ use crate::{
66 api:: {
77 assets:: Assets ,
88 config:: { AppUrl , Config , WindowUrl } ,
9- path:: { resolve_path, BaseDirectory } ,
109 PackageInfo ,
1110 } ,
1211 app:: { AppHandle , GlobalWindowEvent , GlobalWindowEventListener } ,
@@ -24,6 +23,9 @@ use crate::{
2423 App , Context , Invoke , StateManager , Window ,
2524} ;
2625
26+ #[ cfg( target_os = "windows" ) ]
27+ use crate :: api:: path:: { resolve_path, BaseDirectory } ;
28+
2729#[ cfg( feature = "menu" ) ]
2830use crate :: app:: { GlobalMenuEventListener , WindowMenuEvent } ;
2931
@@ -286,19 +288,6 @@ impl<R: Runtime> WindowManager<R> {
286288 } ) ;
287289 }
288290
289- let local_app_data = resolve_path (
290- & self . inner . config ,
291- & self . inner . package_info ,
292- & self . inner . config . tauri . bundle . identifier ,
293- Some ( BaseDirectory :: LocalData ) ,
294- ) ;
295- if let Ok ( user_data_dir) = local_app_data {
296- // Make sure the directory exist without panic
297- if create_dir_all ( & user_data_dir) . is_ok ( ) {
298- webview_attributes = webview_attributes. data_directory ( user_data_dir) ;
299- }
300- }
301-
302291 pending. webview_attributes = webview_attributes;
303292
304293 Ok ( pending)
@@ -591,8 +580,31 @@ impl<R: Runtime> WindowManager<R> {
591580 if pending. webview_attributes . file_drop_handler_enabled {
592581 pending. file_drop_handler = Some ( self . prepare_file_drop ( app_handle) ) ;
593582 }
583+
594584 pending. url = url;
595585
586+ // in `Windows`, we need to force a data_directory
587+ // but we do respect user-specification
588+ #[ cfg( target_os = "windows" ) ]
589+ if pending. webview_attributes . data_directory . is_none ( ) {
590+ let local_app_data = resolve_path (
591+ & self . inner . config ,
592+ & self . inner . package_info ,
593+ & self . inner . config . tauri . bundle . identifier ,
594+ Some ( BaseDirectory :: LocalData ) ,
595+ ) ;
596+ if let Ok ( user_data_dir) = local_app_data {
597+ pending. webview_attributes . data_directory = Some ( user_data_dir) ;
598+ }
599+ }
600+
601+ // make sure the directory is created and available to prevent a panic
602+ if let Some ( user_data_dir) = & pending. webview_attributes . data_directory {
603+ if !user_data_dir. exists ( ) {
604+ create_dir_all ( user_data_dir) ?;
605+ }
606+ }
607+
596608 Ok ( pending)
597609 }
598610
0 commit comments