Skip to content

Commit

Permalink
feat(api): add resolveResource API to the path module (#4234)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed May 29, 2022
1 parent 3f998ca commit 7bba8db
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changes/resolve-resource-api.md
@@ -0,0 +1,5 @@
---
"api": patch
---

Added the `resolveResource` API to the path module.
2 changes: 1 addition & 1 deletion core/tauri/scripts/bundle.js

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion tooling/api/src/path.ts
Expand Up @@ -331,7 +331,8 @@ async function publicDir(): Promise<string> {
}

/**
* Returns the path to the user's resource directory.
* Returns the path to the application's resource directory.
* To resolve a resource path, see the [[resolveResource | `resolveResource API`]].
*
* @returns
*/
Expand All @@ -346,6 +347,24 @@ async function resourceDir(): Promise<string> {
})
}

/**
* Resolve the path to a resource file.
*
* @param resourcePath The path to the resource.
* Must follow the same syntax as defined in `tauri.conf.json > tauri > bundle > resources`, i.e. keeping subfolders and parent dir components (`../`).
* @returns The full path to the resource.
*/
async function resolveResource(resourcePath: string): Promise<string> {
return invokeTauriCommand<string>({
__tauriModule: 'Path',
message: {
cmd: 'resolvePath',
path: resourcePath,
directory: BaseDirectory.Resource
}
})
}

/**
* Returns the path to the user's runtime directory.
*
Expand Down Expand Up @@ -559,6 +578,7 @@ export {
pictureDir,
publicDir,
resourceDir,
resolveResource,
runtimeDir,
templateDir,
videoDir,
Expand Down

0 comments on commit 7bba8db

Please sign in to comment.