feat(ahk): autoload config on start

When AutoHotKey is detected, and %USERPROFILE%\komorebi.ahk exists,
komorebi.exe will now try to run the ahk script after starting the
command listener.

For this to work smoothly, it is important to set the #SingleInstance
directive to Force in komorebi.ahk, which will ensure that duplicates of
the script are not run, and a new version of the script is loaded
without displaying a GUI confirmation prompt.

resolve #3
This commit is contained in:
LGUG2Z
2021-08-14 07:53:37 -07:00
parent 55b62c2bc9
commit 91ddb2c22b
5 changed files with 31 additions and 1 deletions

12
Cargo.lock generated
View File

@@ -363,6 +363,7 @@ dependencies = [
"tracing-appender",
"tracing-subscriber",
"uds_windows",
"which",
]
[[package]]
@@ -1060,6 +1061,17 @@ version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "which"
version = "4.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea187a8ef279bc014ec368c27a920da2024d2a711109bfbe3440585d5cf27ad9"
dependencies = [
"either",
"lazy_static",
"libc",
]
[[package]]
name = "winapi"
version = "0.3.9"

View File

@@ -84,6 +84,9 @@ by `komorebic`.
You can similarly stop the process by running `komorebic stop`.
If you have AutoHotKey installed and a `komorebi.ahk` file in your home directory (run `$Env:UserProfile` at a
PowerShell prompt to find your home directory), `komorebi` will automatically try to load it when starting.
## Configuration
As previously mentioned, this project does not handle anything related to keybindings and shortcuts directly. I

View File

@@ -1,3 +1,5 @@
#SingleInstance Force
; Enable focus follows mouse
Run, komorebic.exe focus-follows-mouse enable

View File

@@ -28,3 +28,4 @@ tracing = "0.1"
tracing-appender = "0.1"
tracing-subscriber = "0.2"
uds_windows = "1"
which = "4"

View File

@@ -1,6 +1,7 @@
#![warn(clippy::all, clippy::nursery, clippy::pedantic)]
#![allow(clippy::missing_errors_doc)]
use std::process::Command;
use std::sync::Arc;
use std::sync::Mutex;
@@ -13,6 +14,7 @@ use sysinfo::SystemExt;
use tracing_appender::non_blocking::WorkerGuard;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::EnvFilter;
use which::which;
use crate::process_command::listen_for_commands;
use crate::process_event::listen_for_events;
@@ -115,6 +117,16 @@ fn main() -> Result<()> {
listen_for_commands(wm.clone());
listen_for_events(wm.clone());
let home = dirs::home_dir().context("there is no home directory")?;
let mut config = home;
config.push("komorebi.ahk");
if config.exists() && which("autohotkey.exe").is_ok() {
Command::new("autohotkey.exe")
.arg(config.as_os_str())
.output()?;
}
let (ctrlc_sender, ctrlc_receiver) = crossbeam_channel::bounded(1);
ctrlc::set_handler(move || {
ctrlc_sender