Browse Source

feat(core): use bundle identifier on user data path (#1580)

Lucas Fernandes Nogueira 4 years ago
parent
commit
5f033db41c

+ 5 - 0
.changes/user-data-path.md

@@ -0,0 +1,5 @@
+---
+"tauri": patch
+---
+
+Set LocalStorage and IndexedDB files path on Linux to `$HOME/.local/${bundleIdentifier}`.

+ 5 - 0
.changes/windows-user-data-path.md

@@ -0,0 +1,5 @@
+---
+"tauri": patch
+---
+
+Use bundle identifier instead of `Tauri` for user data path on Windows.

+ 0 - 28
core/tauri/src/runtime/flavors/wry.rs

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

+ 9 - 14
core/tauri/src/runtime/manager.rs

@@ -6,6 +6,7 @@ use crate::{
   api::{
     assets::Assets,
     config::{Config, WindowUrl},
+    path::{resolve_path, BaseDirectory},
     PackageInfo,
   },
   event::{Event, EventHandler, Listeners},
@@ -27,6 +28,7 @@ use std::{
   borrow::Cow,
   collections::{HashMap, HashSet},
   convert::TryInto,
+  fs::create_dir_all,
   sync::{Arc, Mutex, MutexGuard},
 };
 use uuid::Uuid;
@@ -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));
       }
     }
 

+ 1 - 2
core/tauri/src/runtime/window.rs

@@ -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::{