pub fn resolve_path<P: AsRef<Path>>(
config: &Config,
package_info: &PackageInfo,
env: &Env,
path: P,
dir: Option<BaseDirectory>
) -> Result<PathBuf>
Expand description
Resolves the path with the optional base directory.
This is a low level API. If the application has been built, prefer the path resolver API.
Examples
Before initializing the application
use tauri::{api::path::{BaseDirectory, resolve_path}, Env};
// on an actual app, remove the string argument
let context = tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json");
let path = resolve_path(
context.config(),
context.package_info(),
&Env::default(),
"db/tauri.sqlite",
Some(BaseDirectory::App))
.expect("failed to resolve path");
assert_eq!(path.to_str().unwrap(), "/home/${whoami}/.config/com.tauri.app/db/tauri.sqlite");
tauri::Builder::default().run(context).expect("error while running tauri application");
With an initialized app
use tauri::{api::path::{BaseDirectory, resolve_path}, Manager};
tauri::Builder::default()
.setup(|app| {
let path = resolve_path(
&app.config(),
app.package_info(),
&app.env(),
"path/to/something",
Some(BaseDirectory::Config)
)?;
assert_eq!(path.to_str().unwrap(), "/home/${whoami}/.config/path/to/something");
Ok(())
});