mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
feat(core/path): add PathResolver::home_dir on Android (#11455)
ref: https://github.com/tauri-apps/tauri/issues/10478#issuecomment-2383754176
This commit is contained in:
5
.changes/android-home-dir.md
Normal file
5
.changes/android-home-dir.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": "patch:feat"
|
||||
---
|
||||
|
||||
Add `PathResolver::home_dir()` method on Android.
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"))]
|
||||
@@ -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,
|
||||
@@ -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",
|
||||
@@ -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",
|
||||
@@ -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,
|
||||
@@ -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,
|
||||
@@ -302,6 +299,7 @@ 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"))]
|
||||
@@ -309,8 +307,6 @@ fn resolve_path<R: Runtime>(
|
||||
#[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(),
|
||||
|
||||
Reference in New Issue
Block a user