@@ -6,7 +6,6 @@ use crate::{
6
6
api:: {
7
7
assets:: Assets ,
8
8
config:: { AppUrl , Config , WindowUrl } ,
9
- path:: { resolve_path, BaseDirectory } ,
10
9
PackageInfo ,
11
10
} ,
12
11
app:: { AppHandle , GlobalWindowEvent , GlobalWindowEventListener } ,
@@ -24,6 +23,9 @@ use crate::{
24
23
App , Context , Invoke , StateManager , Window ,
25
24
} ;
26
25
26
+ #[ cfg( target_os = "windows" ) ]
27
+ use crate :: api:: path:: { resolve_path, BaseDirectory } ;
28
+
27
29
#[ cfg( feature = "menu" ) ]
28
30
use crate :: app:: { GlobalMenuEventListener , WindowMenuEvent } ;
29
31
@@ -286,19 +288,6 @@ impl<R: Runtime> WindowManager<R> {
286
288
} ) ;
287
289
}
288
290
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
-
302
291
pending. webview_attributes = webview_attributes;
303
292
304
293
Ok ( pending)
@@ -591,8 +580,31 @@ impl<R: Runtime> WindowManager<R> {
591
580
if pending. webview_attributes . file_drop_handler_enabled {
592
581
pending. file_drop_handler = Some ( self . prepare_file_drop ( app_handle) ) ;
593
582
}
583
+
594
584
pending. url = url;
595
585
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
+
596
608
Ok ( pending)
597
609
}
598
610
0 commit comments