mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-28 12:27:16 +03:00
fix(core): Force data_directory on Windows (#2288)
This commit is contained in:
parent
d832d575d9
commit
70a1941468
5
.changes/tauri-data-directory.md
Normal file
5
.changes/tauri-data-directory.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": patch
|
||||
---
|
||||
|
||||
Force data directory even on non-local window.
|
@ -6,7 +6,6 @@ use crate::{
|
||||
api::{
|
||||
assets::Assets,
|
||||
config::{AppUrl, Config, WindowUrl},
|
||||
path::{resolve_path, BaseDirectory},
|
||||
PackageInfo,
|
||||
},
|
||||
app::{AppHandle, GlobalWindowEvent, GlobalWindowEventListener},
|
||||
@ -24,6 +23,9 @@ use crate::{
|
||||
App, Context, Invoke, StateManager, Window,
|
||||
};
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
use crate::api::path::{resolve_path, BaseDirectory};
|
||||
|
||||
#[cfg(feature = "menu")]
|
||||
use crate::app::{GlobalMenuEventListener, WindowMenuEvent};
|
||||
|
||||
@ -286,19 +288,6 @@ impl<R: Runtime> WindowManager<R> {
|
||||
});
|
||||
}
|
||||
|
||||
let local_app_data = resolve_path(
|
||||
&self.inner.config,
|
||||
&self.inner.package_info,
|
||||
&self.inner.config.tauri.bundle.identifier,
|
||||
Some(BaseDirectory::LocalData),
|
||||
);
|
||||
if let Ok(user_data_dir) = local_app_data {
|
||||
// Make sure the directory exist without panic
|
||||
if create_dir_all(&user_data_dir).is_ok() {
|
||||
webview_attributes = webview_attributes.data_directory(user_data_dir);
|
||||
}
|
||||
}
|
||||
|
||||
pending.webview_attributes = webview_attributes;
|
||||
|
||||
Ok(pending)
|
||||
@ -591,8 +580,31 @@ impl<R: Runtime> WindowManager<R> {
|
||||
if pending.webview_attributes.file_drop_handler_enabled {
|
||||
pending.file_drop_handler = Some(self.prepare_file_drop(app_handle));
|
||||
}
|
||||
|
||||
pending.url = url;
|
||||
|
||||
// in `Windows`, we need to force a data_directory
|
||||
// but we do respect user-specification
|
||||
#[cfg(target_os = "windows")]
|
||||
if pending.webview_attributes.data_directory.is_none() {
|
||||
let local_app_data = resolve_path(
|
||||
&self.inner.config,
|
||||
&self.inner.package_info,
|
||||
&self.inner.config.tauri.bundle.identifier,
|
||||
Some(BaseDirectory::LocalData),
|
||||
);
|
||||
if let Ok(user_data_dir) = local_app_data {
|
||||
pending.webview_attributes.data_directory = Some(user_data_dir);
|
||||
}
|
||||
}
|
||||
|
||||
// make sure the directory is created and available to prevent a panic
|
||||
if let Some(user_data_dir) = &pending.webview_attributes.data_directory {
|
||||
if !user_data_dir.exists() {
|
||||
create_dir_all(user_data_dir)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(pending)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user