diff --git a/Cargo.lock b/Cargo.lock index 4783055f..c91ba607 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -874,6 +874,7 @@ dependencies = [ "dunce", "fs-tail", "heck 0.5.0", + "komorebi-client", "komorebi-core", "lazy_static", "miette", diff --git a/komorebi-client/src/lib.rs b/komorebi-client/src/lib.rs index 621753db..27fb227a 100644 --- a/komorebi-client/src/lib.rs +++ b/komorebi-client/src/lib.rs @@ -16,6 +16,7 @@ pub use komorebi::NotificationEvent; pub use komorebi::RuleDebug; pub use komorebi::StackbarConfig; pub use komorebi::State; +pub use komorebi::StaticConfig; pub use komorebi::TabsConfig; pub use komorebi_core::ActiveWindowBorderStyle; pub use komorebi_core::Arrangement; diff --git a/komorebic/Cargo.toml b/komorebic/Cargo.toml index 3296956b..7ae99ab9 100644 --- a/komorebic/Cargo.toml +++ b/komorebic/Cargo.toml @@ -13,6 +13,7 @@ edition = "2021" [dependencies] derive-ahk = { path = "../derive-ahk" } komorebi-core = { path = "../komorebi-core" } +komorebi-client = { path = "../komorebi-client" } clap = { version = "4", features = ["derive", "wrap_help"] } color-eyre = { workspace = true } diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 934b9c33..95abb834 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -1391,6 +1391,11 @@ fn main() -> Result<()> { } } + // Check that this file adheres to the schema static config schema as the last step, + // so that more basic errors above can be shown to the error before schema-specific + // errors + let _ = serde_json::from_str::(&config_source)?; + if config_whkd.exists() { println!("Found {}; key bindings will be loaded from here when whkd is started, and you can start it automatically using the --whkd flag\n", config_whkd.to_string_lossy()); } else { @@ -1775,7 +1780,7 @@ fn main() -> Result<()> { }; let mut flags = vec![]; - if let Some(config) = arg.config { + if let Some(config) = &arg.config { let path = resolve_home_path(config)?; if !path.is_file() { bail!("could not find file: {}", path.display()); @@ -1810,9 +1815,10 @@ fn main() -> Result<()> { ) }; + let mut attempts = 0; let mut running = false; - while !running { + while !running && attempts <= 2 { match powershell_script::run(&script) { Ok(_) => { println!("{script}"); @@ -1833,9 +1839,27 @@ fn main() -> Result<()> { running = true; } else { println!("komorebi.exe did not start... Trying again"); + attempts += 1; } } + if !running { + println!("\nRunning komorebi.exe directly for detailed error output\n"); + if let Some(config) = arg.config { + let path = resolve_home_path(config)?; + if let Ok(output) = Command::new("komorebi.exe") + .arg(format!("'--config=\"{}\"'", path.display())) + .output() + { + println!("{}", String::from_utf8(output.stderr)?); + } + } else if let Ok(output) = Command::new("komorebi.exe").output() { + println!("{}", String::from_utf8(output.stderr)?); + } + + return Ok(()); + } + if arg.whkd { let script = r" if (!(Get-Process whkd -ErrorAction SilentlyContinue))