From 8980e3b16e0a1dead82c10d07c2f163e1ef36947 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 2 Dec 2023 13:27:45 -0800 Subject: [PATCH] feat(config): make static config flag optional This commit makes the --config flag on komorebi.exe optional, and updates the configuration loading logic to try to find a komorebi.json file in the HOME_DIR, which is either $Env:KOMOREBI_CONFIG_HOME or $Env:PROFILE. This unlocks the way for Amr's PR to make the --config flag optional on the enable-autostart command. re #596 --- komorebi/src/main.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/komorebi/src/main.rs b/komorebi/src/main.rs index c67a3456..d96aa107 100644 --- a/komorebi/src/main.rs +++ b/komorebi/src/main.rs @@ -509,7 +509,18 @@ fn main() -> Result<()> { Hidden::create("komorebi-hidden")?; - let wm = if let Some(config) = &opts.config { + let static_config = if let Some(config) = opts.config { + Option::from(config) + } else { + let komorebi_json = HOME_DIR.join("komorebi.json"); + if komorebi_json.is_file() { + Option::from(komorebi_json) + } else { + None + } + }; + + let wm = if let Some(config) = &static_config { tracing::info!( "creating window manager from static configuration file: {}", config.display() @@ -526,7 +537,8 @@ fn main() -> Result<()> { }; wm.lock().init()?; - if let Some(config) = &opts.config { + + if let Some(config) = &static_config { StaticConfig::postload(config, &wm)?; } @@ -540,7 +552,7 @@ fn main() -> Result<()> { listen_for_commands_tcp(wm.clone(), port); } - if opts.config.is_none() { + if static_config.is_none() { std::thread::spawn(|| load_configuration().expect("could not load configuration")); if opts.await_configuration {