Skip to content

Commit 18b5299

Browse files
docs: where does resource dir resolve to (#13640)
* docs: where does resource dir resolve to * Add note about potential change
1 parent eb3f024 commit 18b5299

File tree

3 files changed

+46
-14
lines changed

3 files changed

+46
-14
lines changed

crates/tauri-utils/src/platform.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -252,20 +252,19 @@ fn is_cargo_output_directory(path: &std::path::Path) -> bool {
252252

253253
/// Computes the resource directory of the current environment.
254254
///
255-
/// On Windows, it's the path to the executable.
255+
/// ## Platform-specific
256256
///
257-
/// On Linux, when running in an AppImage the `APPDIR` variable will be set to
258-
/// the mounted location of the app, and the resource dir will be
259-
/// `${APPDIR}/usr/lib/${exe_name}`. If not running in an AppImage, the path is
260-
/// `/usr/lib/${exe_name}`. When running the app from
261-
/// `src-tauri/target/(debug|release)/`, the path is
262-
/// `${exe_dir}/../lib/${exe_name}`.
263-
///
264-
/// On MacOS, it's `${exe_dir}../Resources` (inside .app).
265-
///
266-
/// On iOS, it's `${exe_dir}/assets`.
267-
///
268-
/// Android uses a special URI prefix that is resolved by the Tauri file system plugin `asset://localhost/`
257+
/// - **Windows:** Resolves to the directory that contains the main executable.
258+
/// - **Linux:** When running in an AppImage, the `APPDIR` variable will be set to
259+
/// the mounted location of the app, and the resource dir will be `${APPDIR}/usr/lib/${exe_name}`.
260+
/// If not running in an AppImage, the path is `/usr/lib/${exe_name}`.
261+
/// When running the app from `src-tauri/target/(debug|release)/`, the path is `${exe_dir}/../lib/${exe_name}`.
262+
/// - **macOS:** Resolves to `${exe_dir}/../Resources` (inside .app).
263+
/// - **iOS:** Resolves to `${exe_dir}/assets`.
264+
/// - **Android:** Currently the resources are stored in the APK as assets so it's not a normal file system path,
265+
/// we return a special URI prefix `asset://localhost/` here that can be used with the [file system plugin](https://tauri.app/plugin/file-system/),
266+
/// with that, you can read the files through [`FsExt::fs`](https://docs.rs/tauri-plugin-fs/latest/tauri_plugin_fs/trait.FsExt.html#tymethod.fs)
267+
/// like this: `app.fs().read_to_string(app.path().resource_dir().unwrap().join("resource"));`
269268
pub fn resource_dir(package_info: &PackageInfo, env: &Env) -> crate::Result<PathBuf> {
270269
#[cfg(target_os = "android")]
271270
return resource_dir_android(package_info, env);

crates/tauri/src/path/desktop.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,23 @@ impl<R: Runtime> PathResolver<R> {
209209
}
210210

211211
/// Returns the path to the resource directory of this app.
212+
///
213+
/// ## Platform-specific
214+
///
215+
/// Although we provide the exact path where this function resolves to,
216+
/// this is not a contract and things might change in the future
217+
///
218+
/// - **Windows:** Resolves to the directory that contains the main executable.
219+
/// - **Linux:** When running in an AppImage, the `APPDIR` variable will be set to
220+
/// the mounted location of the app, and the resource dir will be `${APPDIR}/usr/lib/${exe_name}`.
221+
/// If not running in an AppImage, the path is `/usr/lib/${exe_name}`.
222+
/// When running the app from `src-tauri/target/(debug|release)/`, the path is `${exe_dir}/../lib/${exe_name}`.
223+
/// - **macOS:** Resolves to `${exe_dir}/../Resources` (inside .app).
224+
/// - **iOS:** Resolves to `${exe_dir}/assets`.
225+
/// - **Android:** Currently the resources are stored in the APK as assets so it's not a normal file system path,
226+
/// we return a special URI prefix `asset://localhost/` here that can be used with the [file system plugin](https://tauri.app/plugin/file-system/),
227+
/// with that, you can read the files through [`FsExt::fs`](https://docs.rs/tauri-plugin-fs/latest/tauri_plugin_fs/trait.FsExt.html#tymethod.fs)
228+
/// like this: `app.fs().read_to_string(app.path().resource_dir().unwrap().join("resource"));`
212229
pub fn resource_dir(&self) -> Result<PathBuf> {
213230
crate::utils::platform::resource_dir(self.0.package_info(), &self.0.env())
214231
.map_err(|_| Error::UnknownPath)

packages/api/src/path.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,23 @@ async function publicDir(): Promise<string> {
467467

468468
/**
469469
* Returns the path to the application's resource directory.
470-
* To resolve a resource path, see the [[resolveResource | `resolveResource API`]].
470+
* To resolve a resource path, see {@linkcode resolveResource}.
471+
*
472+
* ## Platform-specific
473+
*
474+
* Although we provide the exact path where this function resolves to,
475+
* this is not a contract and things might change in the future
476+
*
477+
* - **Windows:** Resolves to the directory that contains the main executable.
478+
* - **Linux:** When running in an AppImage, the `APPDIR` variable will be set to
479+
* the mounted location of the app, and the resource dir will be `${APPDIR}/usr/lib/${exe_name}`.
480+
* If not running in an AppImage, the path is `/usr/lib/${exe_name}`.
481+
* When running the app from `src-tauri/target/(debug|release)/`, the path is `${exe_dir}/../lib/${exe_name}`.
482+
* - **macOS:** Resolves to `${exe_dir}/../Resources` (inside .app).
483+
* - **iOS:** Resolves to `${exe_dir}/assets`.
484+
* - **Android:** Currently the resources are stored in the APK as assets so it's not a normal file system path,
485+
* we return a special URI prefix `asset://localhost/` here that can be used with the [file system plugin](https://tauri.app/plugin/file-system/),
486+
*
471487
* @example
472488
* ```typescript
473489
* import { resourceDir } from '@tauri-apps/api/path';

0 commit comments

Comments
 (0)