From fad4cbf0190193500febd4b77ba9c1ca845144fc Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 15 Apr 2022 12:22:18 -0700 Subject: [PATCH] fix(ahk): quote app ids in generated code Previously, generated AHK did not surround with quotes inputs which could contain spaces such as application titles. This commit ensures that in any generated AHK code where an application id is passed to a komorebic.exe command as input, that input will always be quoted. This fixes bugs related to float rules, manage rules and other application identification commands not being properly executed via komorebic called from the generated AHK files when the app id contained a space. --- komorebi-core/src/config_generation.rs | 18 ++++++++++++------ komorebic.lib.sample.ahk | 14 +++++++------- komorebic/src/main.rs | 5 ++++- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/komorebi-core/src/config_generation.rs b/komorebi-core/src/config_generation.rs index 2fd97dc3..e7cec879 100644 --- a/komorebi-core/src/config_generation.rs +++ b/komorebi-core/src/config_generation.rs @@ -27,24 +27,30 @@ impl ApplicationOptions { match self { ApplicationOptions::ObjectNameChange => { format!( - "komorebic.exe identify-object-name-change-application {} {}", + "komorebic.exe identify-object-name-change-application {} \"{}\"", kind, id ) } ApplicationOptions::Layered => { - format!("komorebic.exe identify-layered-application {} {}", kind, id) + format!( + "komorebic.exe identify-layered-application {} \"{}\"", + kind, id + ) } ApplicationOptions::BorderOverflow => { format!( - "komorebic.exe identify-border-overflow-application {} {}", + "komorebic.exe identify-border-overflow-application {} \"{}\"", kind, id ) } ApplicationOptions::TrayAndMultiWindow => { - format!("komorebic.exe identify-tray-application {} {}", kind, id) + format!( + "komorebic.exe identify-tray-application {} \"{}\"", + kind, id + ) } ApplicationOptions::Force => { - format!("komorebic.exe manage-rule {} {}", kind, id) + format!("komorebic.exe manage-rule {} \"{}\"", kind, id) } } ) @@ -145,7 +151,7 @@ impl ApplicationConfigurationGenerator { if let Some(float_identifiers) = app.float_identifiers { for float in float_identifiers { let float_rule = format!( - "Run, komorebic.exe float-rule {} {}, , Hide", + "Run, komorebic.exe float-rule {} \"{}\", , Hide", float.kind, float.id ); diff --git a/komorebic.lib.sample.ahk b/komorebic.lib.sample.ahk index 8b498bbd..d62d43f0 100644 --- a/komorebic.lib.sample.ahk +++ b/komorebic.lib.sample.ahk @@ -257,31 +257,31 @@ WindowHidingBehaviour(hiding_behaviour) { } FloatRule(identifier, id) { - Run, komorebic.exe float-rule %identifier% %id%, , Hide + Run, komorebic.exe float-rule %identifier% "%id%", , Hide } ManageRule(identifier, id) { - Run, komorebic.exe manage-rule %identifier% %id%, , Hide + Run, komorebic.exe manage-rule %identifier% "%id%", , Hide } WorkspaceRule(identifier, id, monitor, workspace) { - Run, komorebic.exe workspace-rule %identifier% %id% %monitor% %workspace%, , Hide + Run, komorebic.exe workspace-rule %identifier% "%id%" %monitor% %workspace%, , Hide } IdentifyObjectNameChangeApplication(identifier, id) { - Run, komorebic.exe identify-object-name-change-application %identifier% %id%, , Hide + Run, komorebic.exe identify-object-name-change-application %identifier% "%id%", , Hide } IdentifyTrayApplication(identifier, id) { - Run, komorebic.exe identify-tray-application %identifier% %id%, , Hide + Run, komorebic.exe identify-tray-application %identifier% "%id%", , Hide } IdentifyLayeredApplication(identifier, id) { - Run, komorebic.exe identify-layered-application %identifier% %id%, , Hide + Run, komorebic.exe identify-layered-application %identifier% "%id%", , Hide } IdentifyBorderOverflowApplication(identifier, id) { - Run, komorebic.exe identify-border-overflow-application %identifier% %id%, , Hide + Run, komorebic.exe identify-border-overflow-application %identifier% "%id%", , Hide } FocusFollowsMouse(boolean_state, implementation) { diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 5361626c..a0ec0ef8 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -692,7 +692,10 @@ fn main() -> Result<()> { .truncate(true) .open(library.clone())?; - file.write_all(SubCommand::generate_ahk_library().as_bytes())?; + let output: String = SubCommand::generate_ahk_library(); + let fixed_output = output.replace("%id%", "\"%id%\""); + + file.write_all(fixed_output.as_bytes())?; println!( "\nAHK helper library for komorebic written to {}",