Skip to content

Commit 5f033db

Browse files
authored
feat(core): use bundle identifier on user data path (#1580)
1 parent 5909c1e commit 5f033db

File tree

5 files changed

+20
-44
lines changed

5 files changed

+20
-44
lines changed

.changes/user-data-path.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Set LocalStorage and IndexedDB files path on Linux to `$HOME/.local/${bundleIdentifier}`.

.changes/windows-user-data-path.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Use bundle identifier instead of `Tauri` for user data path on Windows.

core/tauri/src/runtime/flavors/wry.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ use std::{
2222
sync::{Arc, Mutex},
2323
};
2424

25-
#[cfg(target_os = "windows")]
26-
use crate::api::path::{resolve_path, BaseDirectory};
27-
#[cfg(target_os = "windows")]
28-
use std::fs::create_dir_all;
29-
3025
/// Wrapper around a [`wry::Icon`] that can be created from an [`Icon`].
3126
pub struct WryIcon(wry::Icon);
3227

@@ -92,29 +87,6 @@ impl Attributes for WryAttributes {
9287
webview = webview.y(y);
9388
}
9489

95-
// If we are on windows use App Data Local as user_data
96-
// to prevent any bundled application to failed.
97-
98-
// Should fix:
99-
// https://github.com/tauri-apps/tauri/issues/1365
100-
101-
#[cfg(target_os = "windows")]
102-
{
103-
//todo(lemarier): we should replace with AppName from the context
104-
// will be available when updater will merge
105-
106-
// https://docs.rs/dirs-next/2.0.0/dirs_next/fn.data_local_dir.html
107-
108-
let local_app_data = resolve_path("Tauri", Some(BaseDirectory::LocalData));
109-
110-
if let Ok(user_data_dir) = local_app_data {
111-
// Make sure the directory exist without panic
112-
if let Ok(()) = create_dir_all(&user_data_dir) {
113-
webview = webview.user_data_path(Some(user_data_dir));
114-
}
115-
}
116-
}
117-
11890
webview
11991
}
12092

core/tauri/src/runtime/manager.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::{
66
api::{
77
assets::Assets,
88
config::{Config, WindowUrl},
9+
path::{resolve_path, BaseDirectory},
910
PackageInfo,
1011
},
1112
event::{Event, EventHandler, Listeners},
@@ -27,6 +28,7 @@ use std::{
2728
borrow::Cow,
2829
collections::{HashMap, HashSet},
2930
convert::TryInto,
31+
fs::create_dir_all,
3032
sync::{Arc, Mutex, MutexGuard},
3133
};
3234
use uuid::Uuid;
@@ -188,21 +190,14 @@ impl<P: Params> WindowManager<P> {
188190
attributes = attributes.custom_protocol("tauri", self.prepare_custom_protocol().handler);
189191
}
190192

191-
// If we are on windows use App Data Local as webview temp dir
192-
// to prevent any bundled application to failed.
193-
// Fix: https://github.com/tauri-apps/tauri/issues/1365
194-
#[cfg(windows)]
195-
{
196-
// Should return a path similar to C:\Users\<User>\AppData\Local\<AppName>
197-
let local_app_data = crate::api::path::resolve_path(
198-
self.inner.package_info.name,
199-
Some(crate::api::path::BaseDirectory::LocalData),
200-
);
193+
let local_app_data = resolve_path(
194+
&self.inner.config.tauri.bundle.identifier,
195+
Some(BaseDirectory::LocalData),
196+
);
197+
if let Ok(user_data_dir) = local_app_data {
201198
// Make sure the directory exist without panic
202-
if let Ok(user_data_dir) = local_app_data {
203-
if let Ok(()) = std::fs::create_dir_all(&user_data_dir) {
204-
attributes = attributes.user_data_path(Some(user_data_dir));
205-
}
199+
if create_dir_all(&user_data_dir).is_ok() {
200+
attributes = attributes.user_data_path(Some(user_data_dir));
206201
}
207202
}
208203

core/tauri/src/runtime/window.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
//! A layer between raw [`Runtime`] webview windows and Tauri.
66
7-
use crate::api::config::WindowConfig;
87
use crate::{
9-
api::config::WindowUrl,
8+
api::config::{WindowConfig, WindowUrl},
109
event::{Event, EventHandler},
1110
hooks::{InvokeMessage, InvokePayload, PageLoadPayload},
1211
runtime::{

0 commit comments

Comments
 (0)