Where to get/how to generate config instance (to use with tauri::api::path::app_data_dir)? #6583
-
I'm new to Tauri so this is probably a very obvious question, but I'm trying to get started by creating a file in the |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
The idea is to get it from an instance of |
Beta Was this translation helpful? Give feedback.
-
Here's the proper way to get all the paths relevant to your app: You have to use 2 different sources to get all the paths: fn main() {
tauri::Builder::default()
.setup(setup_handler)
.invoke_handler(tauri::generate_handler![])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
fn setup_handler(app: &mut tauri::App) -> Result<(), Box<dyn std::error::Error + 'static>> {
let app_handle = app.handle();
println!("{}", app_handle.path_resolver().resource_dir().unwrap_or(std::path::PathBuf::new()).to_string_lossy());
println!("{}", app_handle.path_resolver().app_config_dir().unwrap_or(std::path::PathBuf::new()).to_string_lossy());
println!("{}", app_handle.path_resolver().app_data_dir().unwrap_or(std::path::PathBuf::new()).to_string_lossy());
println!("{}", app_handle.path_resolver().app_local_data_dir().unwrap_or(std::path::PathBuf::new()).to_string_lossy());
println!("{}", app_handle.path_resolver().app_cache_dir().unwrap_or(std::path::PathBuf::new()).to_string_lossy());
println!("{}", app_handle.path_resolver().app_log_dir().unwrap_or(std::path::PathBuf::new()).to_string_lossy());
println!("{}", tauri::api::path::data_dir().unwrap_or(std::path::PathBuf::new()).to_string_lossy());
println!("{}", tauri::api::path::local_data_dir().unwrap_or(std::path::PathBuf::new()).to_string_lossy());
println!("{}", tauri::api::path::cache_dir().unwrap_or(std::path::PathBuf::new()).to_string_lossy());
println!("{}", tauri::api::path::config_dir().unwrap_or(std::path::PathBuf::new()).to_string_lossy());
println!("{}", tauri::api::path::executable_dir().unwrap_or(std::path::PathBuf::new()).to_string_lossy());
println!("{}", tauri::api::path::public_dir().unwrap_or(std::path::PathBuf::new()).to_string_lossy());
println!("{}", tauri::api::path::runtime_dir().unwrap_or(std::path::PathBuf::new()).to_string_lossy());
println!("{}", tauri::api::path::template_dir().unwrap_or(std::path::PathBuf::new()).to_string_lossy());
println!("{}", tauri::api::path::font_dir().unwrap_or(std::path::PathBuf::new()).to_string_lossy());
println!("{}", tauri::api::path::home_dir().unwrap_or(std::path::PathBuf::new()).to_string_lossy());
println!("{}", tauri::api::path::audio_dir().unwrap_or(std::path::PathBuf::new()).to_string_lossy());
println!("{}", tauri::api::path::desktop_dir().unwrap_or(std::path::PathBuf::new()).to_string_lossy());
println!("{}", tauri::api::path::document_dir().unwrap_or(std::path::PathBuf::new()).to_string_lossy());
println!("{}", tauri::api::path::download_dir().unwrap_or(std::path::PathBuf::new()).to_string_lossy());
println!("{}", tauri::api::path::picture_dir().unwrap_or(std::path::PathBuf::new()).to_string_lossy());
} |
Beta Was this translation helpful? Give feedback.
-
this works for me pub fn run() {
tauri::Builder::default()
.setup(|app| {
let path = app.path().data_dir();
println!("----{:?}-----", path.unwrap());
Ok(())
})
.plugin(tauri_plugin_fs::init())
.plugin(tauri_plugin_shell::init())
.invoke_handler(tauri::generate_handler![
greet,
commands::commands::my_custom_command,
commands::commands::my_custom_command_2
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
} |
Beta Was this translation helpful? Give feedback.
The idea is to get it from an instance of
App
orAppHandle
which you can get in thesetup
hook and commands for example.And if you have an app instance there's a helper function to make it a bit more streamlined (without the config stuff):
app.path_resolver().app_data_dir()