From f87d4d520be4f242c3733186953b8a2558f132df Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sun, 19 Feb 2023 07:39:46 -0800 Subject: [PATCH] refactor(ahk): merge ahk v1/v2 exe env vars --- README.md | 7 ++--- komorebi/src/main.rs | 49 ++++++++-------------------------- komorebi/src/window_manager.rs | 13 +++------ 3 files changed, 17 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index 7cc6cddd..b1a6d1f1 100644 --- a/README.md +++ b/README.md @@ -274,11 +274,8 @@ scoop install autohotkey1.1 If you install AutoHotKey using a different method, the name of the executable file may differ from the name given by `scoop`, and thus what is expected by default in `komorebi`. -You may override the executables that `komorebi` looks for to launch and reload `komorebi.ahk` configuration files using -by setting one of the following two environment variables depending on which version of AutoHotKey you wish to use: - -- `$Env:KOMOREBI_AHK_V1_EXE` -- `$Env:KOMOREBI_AHK_V2_EXE` +You may override the executable that `komorebi` looks for to launch and reload `komorebi.ahk` configuration files by +setting the `$Env:KOMOREBI_AHK_EXE` environment variable. Please keep in mind that even when setting a custom executable name using these environment variables, the executables are still required to be in your `Path`. diff --git a/komorebi/src/main.rs b/komorebi/src/main.rs index 788ac3e8..ad63469b 100644 --- a/komorebi/src/main.rs +++ b/komorebi/src/main.rs @@ -129,29 +129,17 @@ lazy_static! { }) }; static ref DATA_DIR: PathBuf = dirs::data_local_dir().expect("there is no local data directory").join("komorebi"); - static ref AHK_V1_EXE: String = { - let mut ahk_v1: String = String::from("autohotkey.exe"); + static ref AHK_EXE: String = { + let mut ahk: String = String::from("autohotkey.exe"); - if let Ok(komorebi_ahk_v1_exe) = std::env::var("KOMOREBI_AHK_V1_EXE") { - if which(&komorebi_ahk_v1_exe).is_ok() { - ahk_v1 = komorebi_ahk_v1_exe; + if let Ok(komorebi_ahk_exe) = std::env::var("KOMOREBI_AHK_EXE") { + if which(&komorebi_ahk_exe).is_ok() { + ahk = komorebi_ahk_exe; } } - ahk_v1 + ahk }; - static ref AHK_V2_EXE: String = { - let mut ahk_v2: String = String::from("AutoHotkey64.exe"); - - if let Ok(komorebi_ahk_v2_exe) = std::env::var("KOMOREBI_AHK_V2_EXE") { - if which(&komorebi_ahk_v2_exe).is_ok() { - ahk_v2 = komorebi_ahk_v2_exe; - } - } - - ahk_v2 - }; - static ref WINDOWS_11: bool = { matches!( os_info::get().version(), @@ -251,11 +239,8 @@ pub fn load_configuration() -> Result<()> { let mut config_pwsh = home.clone(); config_pwsh.push("komorebi.ps1"); - let mut config_v1 = home.clone(); - config_v1.push("komorebi.ahk"); - - let mut config_v2 = home; - config_v2.push("komorebi.ahk2"); + let mut config_ahk = home.clone(); + config_ahk.push("komorebi.ahk"); if config_pwsh.exists() { let powershell_exe = if which("pwsh.exe").is_ok() { @@ -275,29 +260,17 @@ pub fn load_configuration() -> Result<()> { Command::new(powershell_exe) .arg(config_pwsh.as_os_str()) .output()?; - } else if config_v1.exists() && which(&*AHK_V1_EXE).is_ok() { + } else if config_ahk.exists() && which(&*AHK_EXE).is_ok() { tracing::info!( "loading configuration file: {}", - config_v1 + config_ahk .as_os_str() .to_str() .ok_or_else(|| anyhow!("cannot convert path to string"))? ); Command::new("autohotkey.exe") - .arg(config_v1.as_os_str()) - .output()?; - } else if config_v2.exists() && which(&*AHK_V2_EXE).is_ok() { - tracing::info!( - "loading configuration file: {}", - config_v2 - .as_os_str() - .to_str() - .ok_or_else(|| anyhow!("cannot convert path to string"))? - ); - - Command::new("AutoHotkey64.exe") - .arg(config_v2.as_os_str()) + .arg(config_ahk.as_os_str()) .output()?; } diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 79021d0d..89755bb3 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -233,18 +233,13 @@ impl WindowManager { let mut config_pwsh = home.clone(); config_pwsh.push("komorebi.ps1"); - let mut config_v1 = home.clone(); - config_v1.push("komorebi.ahk"); - - let mut config_v2 = home; - config_v2.push("komorebi.ahk2"); + let mut config_ahk = home.clone(); + config_ahk.push("komorebi.ahk"); if config_pwsh.exists() { self.configure_watcher(enable, config_pwsh)?; - } else if config_v1.exists() { - self.configure_watcher(enable, config_v1)?; - } else if config_v2.exists() { - self.configure_watcher(enable, config_v2)?; + } else if config_ahk.exists() { + self.configure_watcher(enable, config_ahk)?; } Ok(())