mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-07-10 07:02:44 +02:00
refactor(ahk): merge ahk v1/v2 exe env vars
This commit is contained in:
@@ -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
|
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`.
|
`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
|
You may override the executable that `komorebi` looks for to launch and reload `komorebi.ahk` configuration files by
|
||||||
by setting one of the following two environment variables depending on which version of AutoHotKey you wish to use:
|
setting the `$Env:KOMOREBI_AHK_EXE` environment variable.
|
||||||
|
|
||||||
- `$Env:KOMOREBI_AHK_V1_EXE`
|
|
||||||
- `$Env:KOMOREBI_AHK_V2_EXE`
|
|
||||||
|
|
||||||
Please keep in mind that even when setting a custom executable name using these environment variables, the executables
|
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`.
|
are still required to be in your `Path`.
|
||||||
|
|||||||
+11
-38
@@ -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 DATA_DIR: PathBuf = dirs::data_local_dir().expect("there is no local data directory").join("komorebi");
|
||||||
static ref AHK_V1_EXE: String = {
|
static ref AHK_EXE: String = {
|
||||||
let mut ahk_v1: String = String::from("autohotkey.exe");
|
let mut ahk: String = String::from("autohotkey.exe");
|
||||||
|
|
||||||
if let Ok(komorebi_ahk_v1_exe) = std::env::var("KOMOREBI_AHK_V1_EXE") {
|
if let Ok(komorebi_ahk_exe) = std::env::var("KOMOREBI_AHK_EXE") {
|
||||||
if which(&komorebi_ahk_v1_exe).is_ok() {
|
if which(&komorebi_ahk_exe).is_ok() {
|
||||||
ahk_v1 = komorebi_ahk_v1_exe;
|
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 = {
|
static ref WINDOWS_11: bool = {
|
||||||
matches!(
|
matches!(
|
||||||
os_info::get().version(),
|
os_info::get().version(),
|
||||||
@@ -251,11 +239,8 @@ pub fn load_configuration() -> Result<()> {
|
|||||||
let mut config_pwsh = home.clone();
|
let mut config_pwsh = home.clone();
|
||||||
config_pwsh.push("komorebi.ps1");
|
config_pwsh.push("komorebi.ps1");
|
||||||
|
|
||||||
let mut config_v1 = home.clone();
|
let mut config_ahk = home.clone();
|
||||||
config_v1.push("komorebi.ahk");
|
config_ahk.push("komorebi.ahk");
|
||||||
|
|
||||||
let mut config_v2 = home;
|
|
||||||
config_v2.push("komorebi.ahk2");
|
|
||||||
|
|
||||||
if config_pwsh.exists() {
|
if config_pwsh.exists() {
|
||||||
let powershell_exe = if which("pwsh.exe").is_ok() {
|
let powershell_exe = if which("pwsh.exe").is_ok() {
|
||||||
@@ -275,29 +260,17 @@ pub fn load_configuration() -> Result<()> {
|
|||||||
Command::new(powershell_exe)
|
Command::new(powershell_exe)
|
||||||
.arg(config_pwsh.as_os_str())
|
.arg(config_pwsh.as_os_str())
|
||||||
.output()?;
|
.output()?;
|
||||||
} else if config_v1.exists() && which(&*AHK_V1_EXE).is_ok() {
|
} else if config_ahk.exists() && which(&*AHK_EXE).is_ok() {
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
"loading configuration file: {}",
|
"loading configuration file: {}",
|
||||||
config_v1
|
config_ahk
|
||||||
.as_os_str()
|
.as_os_str()
|
||||||
.to_str()
|
.to_str()
|
||||||
.ok_or_else(|| anyhow!("cannot convert path to string"))?
|
.ok_or_else(|| anyhow!("cannot convert path to string"))?
|
||||||
);
|
);
|
||||||
|
|
||||||
Command::new("autohotkey.exe")
|
Command::new("autohotkey.exe")
|
||||||
.arg(config_v1.as_os_str())
|
.arg(config_ahk.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())
|
|
||||||
.output()?;
|
.output()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -233,18 +233,13 @@ impl WindowManager {
|
|||||||
let mut config_pwsh = home.clone();
|
let mut config_pwsh = home.clone();
|
||||||
config_pwsh.push("komorebi.ps1");
|
config_pwsh.push("komorebi.ps1");
|
||||||
|
|
||||||
let mut config_v1 = home.clone();
|
let mut config_ahk = home.clone();
|
||||||
config_v1.push("komorebi.ahk");
|
config_ahk.push("komorebi.ahk");
|
||||||
|
|
||||||
let mut config_v2 = home;
|
|
||||||
config_v2.push("komorebi.ahk2");
|
|
||||||
|
|
||||||
if config_pwsh.exists() {
|
if config_pwsh.exists() {
|
||||||
self.configure_watcher(enable, config_pwsh)?;
|
self.configure_watcher(enable, config_pwsh)?;
|
||||||
} else if config_v1.exists() {
|
} else if config_ahk.exists() {
|
||||||
self.configure_watcher(enable, config_v1)?;
|
self.configure_watcher(enable, config_ahk)?;
|
||||||
} else if config_v2.exists() {
|
|
||||||
self.configure_watcher(enable, config_v2)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user