Skip to content

Commit

Permalink
feat(core/path): add PathResolver::home_dir on Android (#11455)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Oct 24, 2024
1 parent 516c7d9 commit 8036c78
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changes/android-home-dir.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": "patch:feat"
---

Add `PathResolver::home_dir()` method on Android.
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@ class PathPlugin(private val activity: Activity): Plugin(activity) {
fun getCacheDir(invoke: Invoke) {
resolvePath(invoke, activity.cacheDir.absolutePath)
}

@Command
fun getHomeDir(invoke: Invoke) {
resolvePath(invoke, Environment.getExternalStorageDirectory().absolutePath)
}
}
11 changes: 11 additions & 0 deletions crates/tauri/src/path/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,15 @@ impl<R: Runtime> PathResolver<R> {
pub fn temp_dir(&self) -> Result<PathBuf> {
Ok(std::env::temp_dir())
}

/// Returns the path to the user's home directory.
///
/// ## Platform-specific
///
/// - **Linux:** Resolves to `$HOME`.
/// - **macOS:** Resolves to `$HOME`.
/// - **Windows:** Resolves to `{FOLDERID_Profile}`.
pub fn home_dir(&self) -> Result<PathBuf> {
self.call_resolve("getHomeDir")
}
}
14 changes: 5 additions & 9 deletions crates/tauri/src/path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ pub enum BaseDirectory {
/// Resolves to [`BaseDirectory::Home`]`/Library/Logs/{bundle_identifier}` on macOS
/// and [`BaseDirectory::Config`]`/{bundle_identifier}/logs` on linux and Windows.
AppLog,
/// The Home directory.
Home,

/// The Desktop directory.
#[cfg(not(target_os = "android"))]
Expand All @@ -132,9 +134,6 @@ pub enum BaseDirectory {
/// The Font directory.
#[cfg(not(target_os = "android"))]
Font,
/// The Home directory.
#[cfg(not(target_os = "android"))]
Home,
/// The Runtime directory.
#[cfg(not(target_os = "android"))]
Runtime,
Expand Down Expand Up @@ -164,6 +163,7 @@ impl BaseDirectory {
Self::AppLocalData => "$APPLOCALDATA",
Self::AppCache => "$APPCACHE",
Self::AppLog => "$APPLOG",
Self::Home => "$HOME",

#[cfg(not(target_os = "android"))]
Self::Desktop => "$DESKTOP",
Expand All @@ -172,8 +172,6 @@ impl BaseDirectory {
#[cfg(not(target_os = "android"))]
Self::Font => "$FONT",
#[cfg(not(target_os = "android"))]
Self::Home => "$HOME",
#[cfg(not(target_os = "android"))]
Self::Runtime => "$RUNTIME",
#[cfg(not(target_os = "android"))]
Self::Template => "$TEMPLATE",
Expand Down Expand Up @@ -201,6 +199,7 @@ impl BaseDirectory {
"$APPLOCALDATA" => Self::AppLocalData,
"$APPCACHE" => Self::AppCache,
"$APPLOG" => Self::AppLog,
"$HOME" => Self::Home,

#[cfg(not(target_os = "android"))]
"$DESKTOP" => Self::Desktop,
Expand All @@ -209,8 +208,6 @@ impl BaseDirectory {
#[cfg(not(target_os = "android"))]
"$FONT" => Self::Font,
#[cfg(not(target_os = "android"))]
"$HOME" => Self::Home,
#[cfg(not(target_os = "android"))]
"$RUNTIME" => Self::Runtime,
#[cfg(not(target_os = "android"))]
"$TEMPLATE" => Self::Template,
Expand Down Expand Up @@ -302,15 +299,14 @@ fn resolve_path<R: Runtime>(
BaseDirectory::AppLocalData => resolver.app_local_data_dir(),
BaseDirectory::AppCache => resolver.app_cache_dir(),
BaseDirectory::AppLog => resolver.app_log_dir(),
BaseDirectory::Home => resolver.home_dir(),
#[cfg(not(target_os = "android"))]
BaseDirectory::Desktop => resolver.desktop_dir(),
#[cfg(not(target_os = "android"))]
BaseDirectory::Executable => resolver.executable_dir(),
#[cfg(not(target_os = "android"))]
BaseDirectory::Font => resolver.font_dir(),
#[cfg(not(target_os = "android"))]
BaseDirectory::Home => resolver.home_dir(),
#[cfg(not(target_os = "android"))]
BaseDirectory::Runtime => resolver.runtime_dir(),
#[cfg(not(target_os = "android"))]
BaseDirectory::Template => resolver.template_dir(),
Expand Down

0 comments on commit 8036c78

Please sign in to comment.