Skip to content

Commit 7bba8db

Browse files
authored
feat(api): add resolveResource API to the path module (#4234)
1 parent 3f998ca commit 7bba8db

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

.changes/resolve-resource-api.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"api": patch
3+
---
4+
5+
Added the `resolveResource` API to the path module.

core/tauri/scripts/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/api/src/path.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ async function publicDir(): Promise<string> {
331331
}
332332

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

350+
/**
351+
* Resolve the path to a resource file.
352+
*
353+
* @param resourcePath The path to the resource.
354+
* Must follow the same syntax as defined in `tauri.conf.json > tauri > bundle > resources`, i.e. keeping subfolders and parent dir components (`../`).
355+
* @returns The full path to the resource.
356+
*/
357+
async function resolveResource(resourcePath: string): Promise<string> {
358+
return invokeTauriCommand<string>({
359+
__tauriModule: 'Path',
360+
message: {
361+
cmd: 'resolvePath',
362+
path: resourcePath,
363+
directory: BaseDirectory.Resource
364+
}
365+
})
366+
}
367+
349368
/**
350369
* Returns the path to the user's runtime directory.
351370
*
@@ -559,6 +578,7 @@ export {
559578
pictureDir,
560579
publicDir,
561580
resourceDir,
581+
resolveResource,
562582
runtimeDir,
563583
templateDir,
564584
videoDir,

0 commit comments

Comments
 (0)