Skip to content

Commit 8036c78

Browse files
authored
feat(core/path): add PathResolver::home_dir on Android (#11455)
ref: #10478 (comment)
1 parent 516c7d9 commit 8036c78

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

.changes/android-home-dir.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": "patch:feat"
3+
---
4+
5+
Add `PathResolver::home_dir()` method on Android.

crates/tauri/mobile/android/src/main/java/app/tauri/PathPlugin.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,9 @@ class PathPlugin(private val activity: Activity): Plugin(activity) {
7676
fun getCacheDir(invoke: Invoke) {
7777
resolvePath(invoke, activity.cacheDir.absolutePath)
7878
}
79+
80+
@Command
81+
fun getHomeDir(invoke: Invoke) {
82+
resolvePath(invoke, Environment.getExternalStorageDirectory().absolutePath)
83+
}
7984
}

crates/tauri/src/path/android.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,15 @@ impl<R: Runtime> PathResolver<R> {
117117
pub fn temp_dir(&self) -> Result<PathBuf> {
118118
Ok(std::env::temp_dir())
119119
}
120+
121+
/// Returns the path to the user's home directory.
122+
///
123+
/// ## Platform-specific
124+
///
125+
/// - **Linux:** Resolves to `$HOME`.
126+
/// - **macOS:** Resolves to `$HOME`.
127+
/// - **Windows:** Resolves to `{FOLDERID_Profile}`.
128+
pub fn home_dir(&self) -> Result<PathBuf> {
129+
self.call_resolve("getHomeDir")
130+
}
120131
}

crates/tauri/src/path/mod.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ pub enum BaseDirectory {
122122
/// Resolves to [`BaseDirectory::Home`]`/Library/Logs/{bundle_identifier}` on macOS
123123
/// and [`BaseDirectory::Config`]`/{bundle_identifier}/logs` on linux and Windows.
124124
AppLog,
125+
/// The Home directory.
126+
Home,
125127

126128
/// The Desktop directory.
127129
#[cfg(not(target_os = "android"))]
@@ -132,9 +134,6 @@ pub enum BaseDirectory {
132134
/// The Font directory.
133135
#[cfg(not(target_os = "android"))]
134136
Font,
135-
/// The Home directory.
136-
#[cfg(not(target_os = "android"))]
137-
Home,
138137
/// The Runtime directory.
139138
#[cfg(not(target_os = "android"))]
140139
Runtime,
@@ -164,6 +163,7 @@ impl BaseDirectory {
164163
Self::AppLocalData => "$APPLOCALDATA",
165164
Self::AppCache => "$APPCACHE",
166165
Self::AppLog => "$APPLOG",
166+
Self::Home => "$HOME",
167167

168168
#[cfg(not(target_os = "android"))]
169169
Self::Desktop => "$DESKTOP",
@@ -172,8 +172,6 @@ impl BaseDirectory {
172172
#[cfg(not(target_os = "android"))]
173173
Self::Font => "$FONT",
174174
#[cfg(not(target_os = "android"))]
175-
Self::Home => "$HOME",
176-
#[cfg(not(target_os = "android"))]
177175
Self::Runtime => "$RUNTIME",
178176
#[cfg(not(target_os = "android"))]
179177
Self::Template => "$TEMPLATE",
@@ -201,6 +199,7 @@ impl BaseDirectory {
201199
"$APPLOCALDATA" => Self::AppLocalData,
202200
"$APPCACHE" => Self::AppCache,
203201
"$APPLOG" => Self::AppLog,
202+
"$HOME" => Self::Home,
204203

205204
#[cfg(not(target_os = "android"))]
206205
"$DESKTOP" => Self::Desktop,
@@ -209,8 +208,6 @@ impl BaseDirectory {
209208
#[cfg(not(target_os = "android"))]
210209
"$FONT" => Self::Font,
211210
#[cfg(not(target_os = "android"))]
212-
"$HOME" => Self::Home,
213-
#[cfg(not(target_os = "android"))]
214211
"$RUNTIME" => Self::Runtime,
215212
#[cfg(not(target_os = "android"))]
216213
"$TEMPLATE" => Self::Template,
@@ -302,15 +299,14 @@ fn resolve_path<R: Runtime>(
302299
BaseDirectory::AppLocalData => resolver.app_local_data_dir(),
303300
BaseDirectory::AppCache => resolver.app_cache_dir(),
304301
BaseDirectory::AppLog => resolver.app_log_dir(),
302+
BaseDirectory::Home => resolver.home_dir(),
305303
#[cfg(not(target_os = "android"))]
306304
BaseDirectory::Desktop => resolver.desktop_dir(),
307305
#[cfg(not(target_os = "android"))]
308306
BaseDirectory::Executable => resolver.executable_dir(),
309307
#[cfg(not(target_os = "android"))]
310308
BaseDirectory::Font => resolver.font_dir(),
311309
#[cfg(not(target_os = "android"))]
312-
BaseDirectory::Home => resolver.home_dir(),
313-
#[cfg(not(target_os = "android"))]
314310
BaseDirectory::Runtime => resolver.runtime_dir(),
315311
#[cfg(not(target_os = "android"))]
316312
BaseDirectory::Template => resolver.template_dir(),

0 commit comments

Comments
 (0)