Skip to content

Commit 0976f61

Browse files
committed
chain, log if dirs::data_local_dir fails
1 parent b2e8ab7 commit 0976f61

File tree

5 files changed

+29
-21
lines changed

5 files changed

+29
-21
lines changed

crates/tauri-cli/config.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@
574574
"type": "boolean"
575575
},
576576
"dataDirectory": {
577-
"description": "Set a custom path for the webview's data directory (localStorage, cache, etc.) **relative to [`appDataDir()`]**.\n\n To set absolute paths, use [`WebviewWindowBuilder::data_directory`](https://docs.rs/tauri/2/tauri/webview/struct.WebviewWindowBuilder.html#method.data_directory)\n\n #### Platform-specific:\n\n - **Windows**: WebViews with different values for settings like `additionalBrowserArgs`, `browserExtensionsEnabled` or `scrollBarStyle` must have different data directories.\n - **macOS / iOS**: Unsupported, use `dataStoreIdentifier` instead.\n - **Android**: Unsupported.",
577+
"description": "Set a custom path for the webview's data directory (localStorage, cache, etc.) **relative to [`appDataDir()`]/${label}**.\n\n To set absolute paths, use [`WebviewWindowBuilder::data_directory`](https://docs.rs/tauri/2/tauri/webview/struct.WebviewWindowBuilder.html#method.data_directory)\n\n #### Platform-specific:\n\n - **Windows**: WebViews with different values for settings like `additionalBrowserArgs`, `browserExtensionsEnabled` or `scrollBarStyle` must have different data directories.\n - **macOS / iOS**: Unsupported, use `dataStoreIdentifier` instead.\n - **Android**: Unsupported.",
578578
"type": [
579579
"string",
580580
"null"

crates/tauri-schema-generator/schemas/config.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@
574574
"type": "boolean"
575575
},
576576
"dataDirectory": {
577-
"description": "Set a custom path for the webview's data directory (localStorage, cache, etc.) **relative to [`appDataDir()`]**.\n\n To set absolute paths, use [`WebviewWindowBuilder::data_directory`](https://docs.rs/tauri/2/tauri/webview/struct.WebviewWindowBuilder.html#method.data_directory)\n\n #### Platform-specific:\n\n - **Windows**: WebViews with different values for settings like `additionalBrowserArgs`, `browserExtensionsEnabled` or `scrollBarStyle` must have different data directories.\n - **macOS / iOS**: Unsupported, use `dataStoreIdentifier` instead.\n - **Android**: Unsupported.",
577+
"description": "Set a custom path for the webview's data directory (localStorage, cache, etc.) **relative to [`appDataDir()`]/${label}**.\n\n To set absolute paths, use [`WebviewWindowBuilder::data_directory`](https://docs.rs/tauri/2/tauri/webview/struct.WebviewWindowBuilder.html#method.data_directory)\n\n #### Platform-specific:\n\n - **Windows**: WebViews with different values for settings like `additionalBrowserArgs`, `browserExtensionsEnabled` or `scrollBarStyle` must have different data directories.\n - **macOS / iOS**: Unsupported, use `dataStoreIdentifier` instead.\n - **Android**: Unsupported.",
578578
"type": [
579579
"string",
580580
"null"

crates/tauri-utils/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1853,7 +1853,7 @@ pub struct WindowConfig {
18531853
)]
18541854
pub disable_input_accessory_view: bool,
18551855
///
1856-
/// Set a custom path for the webview's data directory (localStorage, cache, etc.) **relative to [`appDataDir()`]**.
1856+
/// Set a custom path for the webview's data directory (localStorage, cache, etc.) **relative to [`appDataDir()`]/${label}**.
18571857
///
18581858
/// To set absolute paths, use [`WebviewWindowBuilder::data_directory`](https://docs.rs/tauri/2/tauri/webview/struct.WebviewWindowBuilder.html#method.data_directory)
18591859
///

crates/tauri/src/webview/mod.rs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -391,30 +391,38 @@ async fn create_window(app: tauri::AppHandle) {
391391
let mut config = config.to_owned();
392392

393393
if let Some(data_directory) = &config.data_directory {
394-
if let Some(mut local_dir) = dirs::data_local_dir() {
395-
local_dir.push(&config.label);
396-
397-
match SafePathBuf::new(data_directory.clone()) {
398-
Ok(data_directory) => {
399-
if data_directory.as_ref().is_relative() {
400-
config.data_directory =
401-
Some(local_dir.join(&config.label).join(data_directory.as_ref()));
394+
let resolve_data_dir_res = dirs::data_local_dir()
395+
.or({
396+
#[cfg(feature = "tracing")]
397+
tracing::error!("failed to resolve data directory");
398+
None
399+
})
400+
.and_then(|local_dir| {
401+
SafePathBuf::new(data_directory.clone())
402+
.inspect_err(|_err| {
403+
#[cfg(feature = "tracing")]
404+
tracing::error!(
405+
"data_directory `{}` is not a safe path, ignoring config. Validation error was: {_err}",
406+
data_directory.display()
407+
);
408+
})
409+
.map(|p| (local_dir, p))
410+
.ok()
411+
})
412+
.and_then(|(local_dir, data_directory)| {
413+
if data_directory.as_ref().is_relative() {
414+
Some(local_dir.join(&config.label).join(data_directory.as_ref()))
402415
} else {
403416
#[cfg(feature = "tracing")]
404417
tracing::error!(
405418
"data_directory `{}` is not a relative path, ignoring config.",
406419
data_directory.display()
407420
);
421+
None
408422
}
409-
}
410-
Err(_err) => {
411-
#[cfg(feature = "tracing")]
412-
tracing::error!(
413-
"data_directory `{}` is not a safe path, ignoring config. Validation error was: {_err}",
414-
data_directory.display()
415-
);
416-
}
417-
}
423+
});
424+
if let Some(resolved_data_directory) = resolve_data_dir_res {
425+
config.data_directory = Some(resolved_data_directory);
418426
}
419427
}
420428

packages/api/src/webview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ interface WebviewOptions {
855855
*/
856856
disableInputAccessoryView?: boolean
857857
/**
858-
* Set a custom path for the webview's data directory (localStorage, cache, etc.) **relative to [`appDataDir()`]**.
858+
* Set a custom path for the webview's data directory (localStorage, cache, etc.) **relative to [`appDataDir()`]/${label}**.
859859
* For security reasons, paths outside of that location can only be configured on the Rust side.
860860
*
861861
* #### Platform-specific:

0 commit comments

Comments
 (0)