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
This commit is contained in:
LGUG2Z
2023-12-02 13:27:45 -08:00
parent ca9eccf247
commit 8980e3b16e

View File

@@ -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 {