DioxusLabs / DioxusLabs/dioxus
Cross Platform Path Provider
- Dominant language
- Rust
- Stars
- 39.1k
- Forks
- 1.9k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 4
Description
From discussion in: https://github.com/DioxusLabs/dioxus/issues/3850
## Feature Request
To unify the path handling in dioxus across platforms, dioxus should provide a "path provider" that serves the common paths on each platform.
Platform Directory Comparison Example Chart
Directory | Android | iOS | Linux | macOS | Windows
-- | -- | -- | -- | -- | --
Temporary | /data/data/com.example.app/cache/temp/ | /tmp/ | /tmp/ | /private/tmp/ or /tmp/ | C:\Users\Username\AppData\Local\Temp\
Application Support (internal app data) | /data/data/com.example.app/files/ | /var/mobile/Containers/Data/Application/{UUID}/Library/Application Support/ | ~/.config/appname/ | ~/Library/Application Support/AppName/ | C:\Users\Username\AppData\Roaming\AppName\
Application Documents (user data that can be explorable) | /storage/sdcard0/Android/data/com.example.app/files/Documents/ | /var/mobile/Containers/Data/Application/{UUID}/Documents/ | ~/Documents/appname/ | ~/Documents/AppName/ | C:\Users\Username\Documents\AppName\
Application Cache | /data/data/com.example.app/cache/ | /var/mobile/Containers/Data/Application/{UUID}/Library/Caches/ | ~/.cache/appname/ | ~/Library/Caches/AppName/ | C:\Users\Username\AppData\Local\AppName\Cache\
Downloads | /storage/sdcard0/Download/ | /var/mobile/Containers/Data/Application/{UUID}/Documents/Downloads/ **Note**: This is a convention | ~/Downloads/ | ~/Downloads/ | C:\Users\Username\Downloads\
**Note:** For native IOS and Android apps, they rely on on internal api's and discourage using raw path conventions as these may change between versions and hardware/virtualization. So instead of raw path conventions we should use ffi.
**Note:** For Linux XDG environment variables that can override the default paths, we should check these (if not using `dirs-rs`).
**Note:** While a `Downloads` api is mentioned above, we should probably discourage using this for writing, since this will not work on web and instead provided a separate cross platform download api that will prompt on the appropriate platforms that need this.
Prior Art:
- https://github.com/flutter/packages/tree/main/packages/path_provider/path_provider (flutter/dart bindings to platform specific code)
- https://codeberg.org/dirs/dirs-rs (low level system paths for windows, linux, macos. Formerly https://github.com/dirs-dev/dirs-rs )
- https://codeberg.org/dirs/directories-rs (high level applications paths for windows, linux, macos. Formerly https://github.com/dirs-dev/directories-rs )
- https://github.com/project-robius/robius-directories (fork of directories-rs with android support)
- https://github.com/DioxusLabs/dioxus/discussions/3475 (Android paths on dioxus)
**Implementation**
We should create a cross platform path provider interface e.g. `dioxus::directories::app_data()` which returns a `Result`
`dirs-rs` already does the heavy lifting for us on linux, windows, and macos. We could just wrap these api's for these platforms.
For IOS, we should use ffi to interact with the `FileManager` api. For android with should use ffi to interact with the `context` class. For web should use IndexedDB and always return an `Err` for the `Downloads` directory.
**Considerations**
- Should we provide "Home Directory" api? If so, how will these default on other platforms?
Contributor guide
No contributing guide indexed for this repository
Research direction
No source file or test is named. Start with the proposed dioxus::directories::app_data() interface, then read the linked discussion and the cited dirs-rs, directories-rs, robius-directories, and Flutter path_provider prior art. Done would require a settled cross-platform API and the platform-specific behavior described for desktop, mobile, and web.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- desktop, mobile, operating-systems, web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100