mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-04-23 17:18:40 +02:00
refactor(wm): standardize config env var handling
This commit ensures that whenever komorebi.json is read and deserialized into StaticConfig via StaticConfig::read, all known paths where $Env:KOMOREBI_CONFIG_HOME and $Env:USERPROFILE are accepted will be run through the resolve_home_path helper fn.
This commit is contained in:
@@ -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(_) => {
|
||||
|
||||
Reference in New Issue
Block a user