diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index c920f84ee..8bc09cef6 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -341,6 +341,10 @@ pub struct StaticConfig { /// How long to wait when compensating for slow applications, in milliseconds (default: 20) #[serde(skip_serializing_if = "Option::is_none")] pub slow_application_compensation_time: Option, + /// Komorebi status bar configuration files for multiple instances on different monitors + #[serde(skip_serializing_if = "Option::is_none")] + // this option is a little special because it is only consumed by komorebic + pub bar_configurations: Option>, } #[derive(Debug, Serialize, Deserialize, JsonSchema)] @@ -556,6 +560,7 @@ impl From<&WindowManager> for StaticConfig { SLOW_APPLICATION_COMPENSATION_TIME.load(Ordering::SeqCst), ), slow_application_identifiers: Option::from(SLOW_APPLICATION_IDENTIFIERS.lock().clone()), + bar_configurations: None, } } } diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index b914944ae..139ad10f6 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -2025,19 +2025,68 @@ if (!(Get-Process whkd -ErrorAction SilentlyContinue)) } } + let static_config = arg.config.clone().map_or_else( + || { + let komorebi_json = HOME_DIR.join("komorebi.json"); + if komorebi_json.is_file() { + Option::from(komorebi_json) + } else { + None + } + }, + Option::from, + ); + if arg.bar { - let script = r" + if let Some(config) = &static_config { + let mut config = StaticConfig::read(config)?; + if let Some(display_bar_configurations) = &mut config.bar_configurations { + for config_file_path in &mut *display_bar_configurations { + let mut normalized = config_file_path + .to_string_lossy() + .to_string() + .replace( + "$Env:USERPROFILE", + &dirs::home_dir().unwrap().to_string_lossy(), + ) + .replace('"', "") + .replace('\\', "/"); + + if let Ok(komorebi_config_home) = std::env::var("KOMOREBI_CONFIG_HOME") + { + normalized = normalized + .replace("$Env:KOMOREBI_CONFIG_HOME", &komorebi_config_home) + .replace('"', "") + .replace('\\', "/"); + } + + let script = r"Start-Process 'komorebi-bar' '--config CONFIGFILE' -WindowStyle hidden" + .replace("CONFIGFILE", &normalized); + + match powershell_script::run(&script) { + Ok(_) => { + println!("{script}"); + } + Err(error) => { + println!("Error: {error}"); + } + } + } + } else { + let script = r" if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue)) { Start-Process komorebi-bar -WindowStyle hidden } "; - match powershell_script::run(script) { - Ok(_) => { - println!("{script}"); - } - Err(error) => { - println!("Error: {error}"); + match powershell_script::run(script) { + Ok(_) => { + println!("{script}"); + } + Err(error) => { + println!("Error: {error}"); + } + } } } } @@ -2050,18 +2099,6 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue)) println!("* Join the Discord https://discord.gg/mGkn66PHkx - Chat, ask questions, share your desktops"); println!("* Read the docs https://lgug2z.github.io/komorebi - Quickly search through all komorebic commands"); - let static_config = arg.config.clone().map_or_else( - || { - let komorebi_json = HOME_DIR.join("komorebi.json"); - if komorebi_json.is_file() { - Option::from(komorebi_json) - } else { - None - } - }, - Option::from, - ); - let bar_config = arg.config.map_or_else( || { let bar_json = HOME_DIR.join("komorebi.bar.json"); @@ -2074,7 +2111,7 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue)) Option::from, ); - if let Some(config) = static_config { + if let Some(config) = &static_config { let path = resolve_home_path(config)?; let raw = std::fs::read_to_string(path)?; StaticConfig::aliases(&raw);