More config progress
This commit is contained in:
parent
075746472f
commit
85326e435c
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1473,6 +1473,7 @@ dependencies = [
|
|||||||
"gtk4-layer-shell",
|
"gtk4-layer-shell",
|
||||||
"redb",
|
"redb",
|
||||||
"serde",
|
"serde",
|
||||||
|
"waycast-config",
|
||||||
"waycast-core",
|
"waycast-core",
|
||||||
"waycast-plugins",
|
"waycast-plugins",
|
||||||
]
|
]
|
||||||
|
@ -14,6 +14,38 @@ pub fn project_dirs() -> Option<ProjectDirs> {
|
|||||||
ProjectDirs::from("dev.thegrind", "The Grind", "waycast")
|
ProjectDirs::from("dev.thegrind", "The Grind", "waycast")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn config_dir() -> Option<PathBuf> {
|
||||||
|
if let Some(dirs) = project_dirs() {
|
||||||
|
return Some(dirs.config_dir().to_path_buf());
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn cache_dir() -> Option<PathBuf> {
|
||||||
|
if let Some(dirs) = project_dirs() {
|
||||||
|
return Some(dirs.cache_dir().to_path_buf());
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn data_dir() -> Option<PathBuf> {
|
||||||
|
if let Some(dirs) = project_dirs() {
|
||||||
|
return Some(dirs.data_dir().to_path_buf());
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn config_path<P: AsRef<Path>>(file: P) -> Option<PathBuf> {
|
||||||
|
if let Some(p) = config_dir() {
|
||||||
|
return Some(p.join(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
pub fn config_file() -> &'static Config {
|
pub fn config_file() -> &'static Config {
|
||||||
CONFIG_SINGLETON.get_or_init(|| init())
|
CONFIG_SINGLETON.get_or_init(|| init())
|
||||||
}
|
}
|
||||||
@ -23,9 +55,16 @@ pub fn get<T: DeserializeOwned>(key: &str) -> Result<T, config::ConfigError> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn init() -> Config {
|
fn init() -> Config {
|
||||||
Config::builder()
|
let mut cfg = Config::builder();
|
||||||
.add_source(config::File::with_name("waycast.toml"))
|
|
||||||
.add_source(config::Environment::with_prefix("WAYCAST"))
|
cfg = cfg.add_source(config::File::with_name("waycast.toml").required(false)); // Local file for dev
|
||||||
.build()
|
|
||||||
.unwrap()
|
// 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()
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ path = "src/main.rs"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
waycast-core = { path = "../waycast-core" }
|
waycast-core = { path = "../waycast-core" }
|
||||||
waycast-plugins = { path = "../waycast-plugins" }
|
waycast-plugins = { path = "../waycast-plugins" }
|
||||||
|
waycast-config = { path = "../waycast-config" }
|
||||||
gio = "0.21.1"
|
gio = "0.21.1"
|
||||||
glib = "0.21.1"
|
glib = "0.21.1"
|
||||||
gtk = { version = "0.10.0", package = "gtk4" }
|
gtk = { version = "0.10.0", package = "gtk4" }
|
||||||
|
@ -27,10 +27,11 @@ fn main() {
|
|||||||
eprintln!("Warning: Could not apply default styles: {}", e);
|
eprintln!("Warning: Could not apply default styles: {}", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optionally apply user CSS overrides
|
if let Some(path) = waycast_config::config_path("waycast.css") {
|
||||||
// if let Err(_) = ui.apply_css("waycast.css") {
|
if let Err(_) = ui.apply_css(path) {
|
||||||
// // Silently ignore if user hasn't provided custom CSS
|
println!("No user css found");
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ui.show();
|
ui.show();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user