diff --git a/Cargo.lock b/Cargo.lock index 16a9188..7e4d97b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1473,6 +1473,7 @@ dependencies = [ "gtk4-layer-shell", "redb", "serde", + "waycast-config", "waycast-core", "waycast-plugins", ] diff --git a/waycast-config/src/lib.rs b/waycast-config/src/lib.rs index 1a24ebb..dbd01db 100644 --- a/waycast-config/src/lib.rs +++ b/waycast-config/src/lib.rs @@ -14,6 +14,38 @@ pub fn project_dirs() -> Option { ProjectDirs::from("dev.thegrind", "The Grind", "waycast") } +pub fn config_dir() -> Option { + if let Some(dirs) = project_dirs() { + return Some(dirs.config_dir().to_path_buf()); + } + + None +} + +pub fn cache_dir() -> Option { + if let Some(dirs) = project_dirs() { + return Some(dirs.cache_dir().to_path_buf()); + } + + None +} + +pub fn data_dir() -> Option { + if let Some(dirs) = project_dirs() { + return Some(dirs.data_dir().to_path_buf()); + } + + None +} + +pub fn config_path>(file: P) -> Option { + if let Some(p) = config_dir() { + return Some(p.join(file)); + } + + None +} + pub fn config_file() -> &'static Config { CONFIG_SINGLETON.get_or_init(|| init()) } @@ -23,9 +55,16 @@ pub fn get(key: &str) -> Result { } fn init() -> Config { - Config::builder() - .add_source(config::File::with_name("waycast.toml")) - .add_source(config::Environment::with_prefix("WAYCAST")) - .build() - .unwrap() + let mut cfg = Config::builder(); + + cfg = cfg.add_source(config::File::with_name("waycast.toml").required(false)); // Local file for dev + + // Production version in ~/.config + if let Some(path) = config_path("waycast.toml") { + cfg = cfg.add_source(config::File::with_name(&path.to_string_lossy()).required(false)); + } + + cfg = cfg.add_source(config::Environment::with_prefix("WAYCAST")); + + cfg.build().unwrap() } diff --git a/waycast-gtk/Cargo.toml b/waycast-gtk/Cargo.toml index 9e4cc3d..726e8af 100644 --- a/waycast-gtk/Cargo.toml +++ b/waycast-gtk/Cargo.toml @@ -10,6 +10,7 @@ path = "src/main.rs" [dependencies] waycast-core = { path = "../waycast-core" } waycast-plugins = { path = "../waycast-plugins" } +waycast-config = { path = "../waycast-config" } gio = "0.21.1" glib = "0.21.1" gtk = { version = "0.10.0", package = "gtk4" } diff --git a/waycast-gtk/src/main.rs b/waycast-gtk/src/main.rs index 4afb404..b5fa06b 100644 --- a/waycast-gtk/src/main.rs +++ b/waycast-gtk/src/main.rs @@ -27,10 +27,11 @@ fn main() { eprintln!("Warning: Could not apply default styles: {}", e); } - // Optionally apply user CSS overrides - // if let Err(_) = ui.apply_css("waycast.css") { - // // Silently ignore if user hasn't provided custom CSS - // } + if let Some(path) = waycast_config::config_path("waycast.css") { + if let Err(_) = ui.apply_css(path) { + println!("No user css found"); + } + } ui.show(); });