@@ -22,7 +22,7 @@ use crate::{
2222 scope:: FsScope ,
2323 sealed:: { ManagerBase , RuntimeOrDispatch } ,
2424 utils:: config:: Config ,
25- utils:: { assets:: Assets , Env } ,
25+ utils:: { assets:: Assets , resources :: resource_relpath , Env } ,
2626 Context , EventLoopMessage , Invoke , InvokeError , InvokeResponse , Manager , Runtime , Scopes ,
2727 StateManager , Theme , Window ,
2828} ;
@@ -39,7 +39,7 @@ use tauri_utils::PackageInfo;
3939
4040use std:: {
4141 collections:: HashMap ,
42- path:: PathBuf ,
42+ path:: { Path , PathBuf } ,
4343 sync:: { mpsc:: Sender , Arc , Weak } ,
4444} ;
4545
@@ -255,6 +255,41 @@ impl PathResolver {
255255 crate :: api:: path:: resource_dir ( & self . package_info , & self . env )
256256 }
257257
258+ /// Resolves the path of the given resource.
259+ /// Note that the path must be the same as provided in `tauri.conf.json`.
260+ ///
261+ /// This function is helpful when your resource path includes a root dir (`/`) or parent component (`..`),
262+ /// because Tauri replaces them with a parent folder, so simply using [`Self::resource_dir`] and joining the path
263+ /// won't work.
264+ ///
265+ /// # Examples
266+ ///
267+ /// `tauri.conf.json`:
268+ /// ```json
269+ /// {
270+ /// "tauri": {
271+ /// "bundle": {
272+ /// "resources": ["../assets/*"]
273+ /// }
274+ /// }
275+ /// }
276+ /// ```
277+ ///
278+ /// ```no_run
279+ /// tauri::Builder::default()
280+ /// .setup(|app| {
281+ /// let resource_path = app.path_resolver()
282+ /// .resolve_resource("../assets/logo.svg")
283+ /// .expect("failed to resolve resource dir");
284+ /// Ok(())
285+ /// });
286+ /// ```
287+ pub fn resolve_resource < P : AsRef < Path > > ( & self , path : P ) -> Option < PathBuf > {
288+ self
289+ . resource_dir ( )
290+ . map ( |dir| dir. join ( resource_relpath ( path. as_ref ( ) ) ) )
291+ }
292+
258293 /// Returns the path to the suggested directory for your app config files.
259294 pub fn app_dir ( & self ) -> Option < PathBuf > {
260295 crate :: api:: path:: app_dir ( & self . config )
0 commit comments