tauri_plugin_matrix_svelte/utils/
fs.rs

1use std::path::PathBuf;
2
3use tauri::{AppHandle, Manager, Runtime};
4
5pub fn get_app_dir_or_create_it<R: Runtime>(app_handle: &AppHandle<R>) -> anyhow::Result<PathBuf> {
6    let app_data_dir = app_handle.path().app_data_dir()?;
7
8    match std::fs::create_dir(&app_data_dir) {
9        Ok(_) => println!("Directory created"),
10        Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => {
11            // Do nothing if the directory already exists
12            println!("App data directory already exists.")
13        }
14        Err(e) => {
15            // Handle other errors
16            eprintln!("Error creating directory: {}", e);
17        }
18    }
19    Ok(app_data_dir)
20}