Procházet zdrojové kódy

feat(api): add `resolveResource` API to the path module (#4234)

Lucas Fernandes Nogueira před 3 roky
rodič
revize
7bba8db83e

+ 5 - 0
.changes/resolve-resource-api.md

@@ -0,0 +1,5 @@
+---
+"api": patch
+---
+
+Added the `resolveResource` API to the path module.

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 0
core/tauri/scripts/bundle.js


+ 21 - 1
tooling/api/src/path.ts

@@ -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
  */
@@ -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.
  *
@@ -559,6 +578,7 @@ export {
   pictureDir,
   publicDir,
   resourceDir,
+  resolveResource,
   runtimeDir,
   templateDir,
   videoDir,

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů