Skip to content

Commit

Permalink
feat(core): use bundle identifier on user data path (#1580)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Apr 22, 2021
1 parent 5909c1e commit 5f033db
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 44 deletions.
5 changes: 5 additions & 0 deletions .changes/user-data-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Set LocalStorage and IndexedDB files path on Linux to `$HOME/.local/${bundleIdentifier}`.
5 changes: 5 additions & 0 deletions .changes/windows-user-data-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Use bundle identifier instead of `Tauri` for user data path on Windows.
28 changes: 0 additions & 28 deletions core/tauri/src/runtime/flavors/wry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ use std::{
sync::{Arc, Mutex},
};

#[cfg(target_os = "windows")]
use crate::api::path::{resolve_path, BaseDirectory};
#[cfg(target_os = "windows")]
use std::fs::create_dir_all;

/// Wrapper around a [`wry::Icon`] that can be created from an [`Icon`].
pub struct WryIcon(wry::Icon);

Expand Down Expand Up @@ -92,29 +87,6 @@ impl Attributes for WryAttributes {
webview = webview.y(y);
}

// If we are on windows use App Data Local as user_data
// to prevent any bundled application to failed.

// Should fix:
// https://github.com/tauri-apps/tauri/issues/1365

#[cfg(target_os = "windows")]
{
//todo(lemarier): we should replace with AppName from the context
// will be available when updater will merge

// https://docs.rs/dirs-next/2.0.0/dirs_next/fn.data_local_dir.html

let local_app_data = resolve_path("Tauri", Some(BaseDirectory::LocalData));

if let Ok(user_data_dir) = local_app_data {
// Make sure the directory exist without panic
if let Ok(()) = create_dir_all(&user_data_dir) {
webview = webview.user_data_path(Some(user_data_dir));
}
}
}

webview
}

Expand Down
23 changes: 9 additions & 14 deletions core/tauri/src/runtime/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
api::{
assets::Assets,
config::{Config, WindowUrl},
path::{resolve_path, BaseDirectory},
PackageInfo,
},
event::{Event, EventHandler, Listeners},
Expand All @@ -27,6 +28,7 @@ use std::{
borrow::Cow,
collections::{HashMap, HashSet},
convert::TryInto,
fs::create_dir_all,
sync::{Arc, Mutex, MutexGuard},
};
use uuid::Uuid;
Expand Down Expand Up @@ -188,21 +190,14 @@ impl<P: Params> WindowManager<P> {
attributes = attributes.custom_protocol("tauri", self.prepare_custom_protocol().handler);
}

// If we are on windows use App Data Local as webview temp dir
// to prevent any bundled application to failed.
// Fix: https://github.com/tauri-apps/tauri/issues/1365
#[cfg(windows)]
{
// Should return a path similar to C:\Users\<User>\AppData\Local\<AppName>
let local_app_data = crate::api::path::resolve_path(
self.inner.package_info.name,
Some(crate::api::path::BaseDirectory::LocalData),
);
let local_app_data = resolve_path(
&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 let Ok(user_data_dir) = local_app_data {
if let Ok(()) = std::fs::create_dir_all(&user_data_dir) {
attributes = attributes.user_data_path(Some(user_data_dir));
}
if create_dir_all(&user_data_dir).is_ok() {
attributes = attributes.user_data_path(Some(user_data_dir));
}
}

Expand Down
3 changes: 1 addition & 2 deletions core/tauri/src/runtime/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

//! A layer between raw [`Runtime`] webview windows and Tauri.

use crate::api::config::WindowConfig;
use crate::{
api::config::WindowUrl,
api::config::{WindowConfig, WindowUrl},
event::{Event, EventHandler},
hooks::{InvokeMessage, InvokePayload, PageLoadPayload},
runtime::{
Expand Down

0 comments on commit 5f033db

Please sign in to comment.