feat(cli): add support for starting/stopping masir

This commit adds support to the start and stop commands for starting and
stopping masir.
This commit is contained in:
LGUG2Z
2024-12-07 11:08:39 -08:00
parent 280ca0ffcd
commit 440d78e8f4
2 changed files with 49 additions and 1 deletions

View File

@@ -268,7 +268,7 @@ pub struct StaticConfig {
/// Determine what happens when commands are sent while an unmanaged window is in the foreground (default: Op)
#[serde(skip_serializing_if = "Option::is_none")]
pub unmanaged_window_operation_behaviour: Option<OperationBehaviour>,
/// END OF LIFE FEATURE: Determine focus follows mouse implementation (default: None)
/// END OF LIFE FEATURE: Use https://github.com/LGUG2Z/masir instead
#[serde(skip_serializing_if = "Option::is_none")]
pub focus_follows_mouse: Option<FocusFollowsMouseImplementation>,
/// Enable or disable mouse follows focus (default: true)

View File

@@ -779,6 +779,9 @@ struct Start {
/// Start komorebi-bar in a background process
#[clap(long)]
bar: bool,
/// Start masir in a background process for focus-follows-mouse
#[clap(long)]
masir: bool,
}
#[derive(Parser)]
@@ -792,6 +795,9 @@ struct Stop {
/// Stop komorebi-bar if it is running as a background process
#[clap(long)]
bar: bool,
/// Stop masir if it is running as a background process
#[clap(long)]
masir: bool,
}
#[derive(Parser)]
@@ -888,6 +894,9 @@ struct EnableAutostart {
/// Enable autostart of komorebi-bar
#[clap(long)]
bar: bool,
/// Enable autostart of masir
#[clap(long)]
masir: bool,
}
#[derive(Parser)]
@@ -1507,6 +1516,10 @@ fn main() -> Result<()> {
arguments.push_str(" --ahk");
}
if args.bar {
arguments.push_str(" --masir");
}
Command::new("powershell")
.arg("-c")
.arg("$WshShell = New-Object -comObject WScript.Shell; $Shortcut = $WshShell.CreateShortcut($env:SHORTCUT_PATH); $Shortcut.TargetPath = $env:TARGET_PATH; $Shortcut.Arguments = $env:TARGET_ARGS; $Shortcut.Save()")
@@ -1927,6 +1940,10 @@ fn main() -> Result<()> {
bail!("could not find whkd, please make sure it is installed before using the --whkd flag");
}
if arg.masir && which("masir").is_err() {
bail!("could not find masir, please make sure it is installed before using the --masir flag");
}
if arg.ahk && which(&ahk).is_err() {
bail!("could not find autohotkey, please make sure it is installed before using the --ahk flag");
}
@@ -2130,6 +2147,23 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
}
}
if arg.masir {
let script = r"
if (!(Get-Process masir -ErrorAction SilentlyContinue))
{
Start-Process masir -WindowStyle hidden
}
";
match powershell_script::run(script) {
Ok(_) => {
println!("{script}");
}
Err(error) => {
println!("Error: {error}");
}
}
}
println!("\nThank you for using komorebi!\n");
println!("# Sponsorship");
println!("* Become a sponsor https://github.com/sponsors/LGUG2Z - $5/month makes a big difference");
@@ -2198,6 +2232,20 @@ Stop-Process -Name:komorebi-bar -ErrorAction SilentlyContinue
}
}
if arg.masir {
let script = r"
Stop-Process -Name:masir -ErrorAction SilentlyContinue
";
match powershell_script::run(script) {
Ok(_) => {
println!("{script}");
}
Err(error) => {
println!("Error: {error}");
}
}
}
if arg.ahk {
let script = r#"
if (Get-Command Get-CimInstance -ErrorAction SilentlyContinue) {