diff --git a/komorebi-bar/src/komorebi.rs b/komorebi-bar/src/komorebi.rs index a16db58c1..4c60e05a3 100644 --- a/komorebi-bar/src/komorebi.rs +++ b/komorebi-bar/src/komorebi.rs @@ -83,14 +83,6 @@ impl From<&KomorebiConfig> for Komorebi { if let Some(configuration_switcher) = &value.configuration_switcher { let mut configuration_switcher = configuration_switcher.clone(); for (_, location) in configuration_switcher.configurations.iter_mut() { - if let Ok(expanded) = std::env::var("KOMOREBI_CONFIG_HOME") { - *location = location.replace("$Env:KOMOREBI_CONFIG_HOME", &expanded); - } - - if let Ok(expanded) = std::env::var("USERPROFILE") { - *location = location.replace("$Env:USERPROFILE", &expanded); - } - *location = dunce::simplified(&PathBuf::from(location.clone())) .to_string_lossy() .to_string(); diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index 8bc09cef6..1ca3633a5 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -934,7 +934,34 @@ impl StaticConfig { pub fn read(path: &PathBuf) -> Result { let content = std::fs::read_to_string(path)?; - let value: Self = serde_json::from_str(&content)?; + let mut value: Self = serde_json::from_str(&content)?; + + if let Some(path) = &mut value.app_specific_configuration_path { + *path = resolve_home_path(&*path)?; + } + + if let Some(monitors) = &mut value.monitors { + for m in monitors { + for w in &mut m.workspaces { + if let Some(path) = &mut w.custom_layout { + *path = resolve_home_path(&*path)?; + } + + if let Some(map) = &mut w.custom_layout_rules { + for path in map.values_mut() { + *path = resolve_home_path(&*path)?; + } + } + } + } + } + + if let Some(bar_configurations) = &mut value.bar_configurations { + for path in bar_configurations { + *path = resolve_home_path(&*path)?; + } + } + Ok(value) } @@ -944,8 +971,7 @@ impl StaticConfig { incoming: Receiver, unix_listener: Option, ) -> Result { - let content = std::fs::read_to_string(path)?; - let mut value: Self = serde_json::from_str(&content)?; + let mut value = Self::read(path)?; value.apply_globals()?; let listener = match unix_listener { @@ -1024,8 +1050,7 @@ impl StaticConfig { } pub fn postload(path: &PathBuf, wm: &Arc>) -> Result<()> { - let content = std::fs::read_to_string(path)?; - let value: Self = serde_json::from_str(&content)?; + let value = Self::read(path)?; let mut wm = wm.lock(); if let Some(monitors) = value.monitors { @@ -1092,8 +1117,7 @@ impl StaticConfig { } pub fn reload(path: &PathBuf, wm: &mut WindowManager) -> Result<()> { - let content = std::fs::read_to_string(path)?; - let mut value: Self = serde_json::from_str(&content)?; + let mut value = Self::read(path)?; value.apply_globals()?; diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 139ad10f6..248cf6b83 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -1517,26 +1517,15 @@ fn main() -> Result<()> { println!("Found komorebi.json; this file can be passed to the start command with the --config flag\n"); - if let Ok(config) = &parsed_config { - if let Some(asc_path) = config.get("app_specific_configuration_path") { - let mut normalized_asc_path = asc_path - .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_asc_path = normalized_asc_path - .replace("$Env:KOMOREBI_CONFIG_HOME", &komorebi_config_home) - .replace('"', "") - .replace('\\', "/"); + if let Ok(config) = StaticConfig::read(&static_config) { + match config.app_specific_configuration_path { + None => { + println!("Application specific configuration file path has not been set. Try running 'komorebic fetch-asc'\n"); } - - if !Path::exists(Path::new(&normalized_asc_path)) { - println!("Application specific configuration file path '{normalized_asc_path}' does not exist. Try running 'komorebic fetch-asc'\n"); + Some(path) => { + if !Path::exists(Path::new(&path)) { + println!("Application specific configuration file path '{}' does not exist. Try running 'komorebic fetch-asc'\n", path.display()); + } } } } @@ -2042,26 +2031,8 @@ if (!(Get-Process whkd -ErrorAction SilentlyContinue)) 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); + .replace("CONFIGFILE", &config_file_path.to_string_lossy()); match powershell_script::run(&script) { Ok(_) => {