fix(core): Force data_directory on Windows (#2288)

This commit is contained in:
david 2021-07-23 07:29:22 -07:00 committed by GitHub
parent d832d575d9
commit 70a1941468
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 14 deletions

View File

@ -0,0 +1,5 @@
---
"tauri": patch
---
Force data directory even on non-local window.

View File

@ -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)
}