diff --git a/Cargo.lock b/Cargo.lock index c3ad814075..0019c81c33 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -664,6 +664,7 @@ dependencies = [ "candle-nn", "candle-transformers", "cudarc", + "directories 6.0.0", "dirs 6.0.0", "filesys", "futures 0.3.29", @@ -3184,6 +3185,15 @@ dependencies = [ "dirs-sys 0.4.1", ] +[[package]] +name = "directories" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16f5094c54661b38d03bd7e50df373292118db60b585c08a411c6d840017fe7d" +dependencies = [ + "dirs-sys 0.5.0", +] + [[package]] name = "dirs" version = "5.0.1" @@ -7571,7 +7581,7 @@ dependencies = [ "base16ct", "base64 0.22.1", "chrono", - "directories", + "directories 5.0.1", "flate2", "lazy_static", "log", diff --git a/crates/desktop/src-tauri/.taurignore b/crates/desktop/src-tauri/.taurignore new file mode 100644 index 0000000000..ad17b2ca1c --- /dev/null +++ b/crates/desktop/src-tauri/.taurignore @@ -0,0 +1,4 @@ +# Don't restart the dev server on Rust changes +crates/ +Cargo.toml +Cargo.lock \ No newline at end of file diff --git a/crates/desktop/src-tauri/Cargo.toml b/crates/desktop/src-tauri/Cargo.toml index a4596a4d39..662e91e79c 100644 --- a/crates/desktop/src-tauri/Cargo.toml +++ b/crates/desktop/src-tauri/Cargo.toml @@ -35,6 +35,7 @@ candle-core = { path = "../../vendor/candle/candle-core", features = ["cuda"] } candle-nn = { path = "../../vendor/candle/candle-nn", features = ["cuda"] } candle-transformers = { path = "../../vendor/candle/candle-transformers", features = ["cuda"] } dirs = "6.0.0" +directories = "6.0.0" futures = "0.3" hf-hub = "0.3.2" image = "0.25.5" diff --git a/crates/desktop/src-tauri/src/state/app_config.rs b/crates/desktop/src-tauri/src/state/app_config.rs index c8ac8de251..929579e28b 100644 --- a/crates/desktop/src-tauri/src/state/app_config.rs +++ b/crates/desktop/src-tauri/src/state/app_config.rs @@ -15,8 +15,6 @@ const DEFAULT_SD_IMAGE_HEIGHT: usize = 1024; const DEFAULT_SD_NUMERIC_DATATYPE: DType = DType::F32; const SD_VERSION: StableDiffusionVersion = StableDiffusionVersion::V1_5; -const DEFAULT_DATA_DIR_UNIX : &str = "~/artcraft"; - /// A central place to configure app-wide details. pub struct AppConfig { /// We only support one device type currently, and we can't multiplex @@ -78,24 +76,21 @@ impl AppConfig { let os_platform = OsPlatform::get(); - let default_data_path = match os_platform { + let default_data_root = match os_platform { OsPlatform::Linux => yaml_configs.linux_default_data_path.as_deref(), OsPlatform::MacOs => yaml_configs.mac_default_data_path.as_deref(), OsPlatform::Windows => yaml_configs.windows_default_data_path.as_deref(), }; - let data_root_path = match default_data_path { - Some(default_data_path) => default_data_path.to_string(), - None => match os_platform { - OsPlatform::Linux | OsPlatform::MacOs => DEFAULT_DATA_DIR_UNIX.to_string(), - OsPlatform::Windows => ".".to_string(), - } + println!("Possible user-defined data root: {:?}", default_data_root); + + let app_data_root = match default_data_root { + None => AppDataRoot::create_default()?, + Some(path) => AppDataRoot::create_existing(path)?, }; - - println!("Using data root: {}", data_root_path); + + println!("App data root: {:?}", app_data_root.path()); - let app_data_root = AppDataRoot::create_existing(data_root_path)?; - Ok(Self { device, dtype: DEFAULT_SD_NUMERIC_DATATYPE, diff --git a/crates/desktop/src-tauri/src/state/app_dir.rs b/crates/desktop/src-tauri/src/state/app_dir.rs index 000c59c6a4..3885ae5862 100644 --- a/crates/desktop/src-tauri/src/state/app_dir.rs +++ b/crates/desktop/src-tauri/src/state/app_dir.rs @@ -1,10 +1,12 @@ use crate::ml::model_type::ModelType; use crate::state::expanduser::expanduser; use crate::state::os_platform::OsPlatform; +use anyhow::anyhow; +use directories::UserDirs; use std::path::{Path, PathBuf}; use tempdir::TempDir; use tempfile::{Builder, NamedTempFile}; - +const DEFAULT_DATA_DIR : &str = "artcraft"; const ASSETS_SUBDIRECTORY : &str = "assets"; const WEIGHTS_SUBDIRECTORY : &str = "weights"; @@ -35,6 +37,11 @@ pub struct TemporaryDir { } impl AppDataRoot { + pub fn create_default() -> anyhow::Result { + let directory = get_default_data_dir()?; + Self::create_existing(directory) + } + pub fn create_existing>(dir: P) -> anyhow::Result { let mut dir = dir.as_ref().to_path_buf(); @@ -169,3 +176,11 @@ impl TemporaryDir { Ok(tempfile) } } + +// eg. /home/bob/artcraft, /Users/bob/artcraft, or C:\Users\Alice\artcraft +fn get_default_data_dir() -> anyhow::Result { + Ok(UserDirs::new() + .ok_or_else(|| anyhow!("could not determine user home directory"))? + .home_dir() + .join(DEFAULT_DATA_DIR)) +}