From 96605f72a7453cc1bd538f59529e2195ae2f9786 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sun, 6 Oct 2024 16:30:06 -0700 Subject: [PATCH] feat(config): add bar configurations opt This commit adds a "bar_configurations" option to the static config file which takes an array of PathBufs. If this option is defined and the --bar flag is passed to the "komorebic start" command, komorebic will attempt to launch multiple instances of komorebi-bar.exe with the --config flag pointing to the PathBufs given. This configuration option is only consumed by komorebic, not by the window manager directly, so it could also be used by other status bar projects to read configuration file locations from. There is no requirement for the PathBufs to point specifically to komorebi bar configuration files if the --bar flag is not being used with "komorebic start". --- komorebi/src/static_config.rs | 5 ++ komorebic/src/main.rs | 89 +++++++++++++++++++++++++---------- 2 files changed, 68 insertions(+), 26 deletions(-) diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index c920f84e..8bc09cef 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 b914944a..139ad10f 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -2025,31 +2025,6 @@ if (!(Get-Process whkd -ErrorAction SilentlyContinue)) } } - if arg.bar { - 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}"); - } - } - } - - println!("\nThank you for using komorebi!\n"); - println!("* Become a sponsor https://github.com/sponsors/LGUG2Z - Even $1/month makes a big difference"); - println!( - "* Subscribe to https://youtube.com/@LGUG2Z - Live dev videos and feature previews" - ); - 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"); @@ -2062,6 +2037,68 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue)) Option::from, ); + if arg.bar { + 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}"); + } + } + } + } + } + + println!("\nThank you for using komorebi!\n"); + println!("* Become a sponsor https://github.com/sponsors/LGUG2Z - Even $1/month makes a big difference"); + println!( + "* Subscribe to https://youtube.com/@LGUG2Z - Live dev videos and feature previews" + ); + 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 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);