Skip to content

Commit b43b971

Browse files
committed
fix(hotkey): prevent simulation triggering when binding an already-bound hotkey
1 parent 5d547c7 commit b43b971

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

src/utils/hotkey.rs

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -102,28 +102,33 @@ pub fn start_global_hotkey_listener(
102102
// Handle hotkey state
103103
let mut prev_state = previous_state.lock().unwrap();
104104
if is_hotkey_pressed && !*prev_state {
105-
let now = Instant::now();
106-
let mut last_toggle_time = last_toggle.lock().unwrap();
107-
108-
if last_toggle_time.map_or(true, |last|
109-
now.duration_since(last).as_millis() > HOTKEY_TOGGLE_DELAY_MS as u128) {
110-
let mut is_running = running.lock().unwrap();
111-
*is_running = !*is_running;
112-
113-
if *is_running {
114-
log::info!("Hotkey pressed, starting simulation");
115-
initialize_simulation(&app_data, &selected_keys, &modifier_mode);
116-
start_simulation(
117-
Arc::clone(&running),
118-
Arc::clone(&interval_ms),
119-
Arc::clone(&selected_keys),
120-
Arc::clone(&modifier_mode),
121-
);
122-
} else {
123-
log::info!("Hotkey pressed, stopping simulation");
105+
// Prevent triggering simulation if binding global hotkey is active.
106+
if app_data.lock().unwrap().capturing_global_hotkey {
107+
*prev_state = is_hotkey_pressed;
108+
} else {
109+
let now = Instant::now();
110+
let mut last_toggle_time = last_toggle.lock().unwrap();
111+
112+
if last_toggle_time.map_or(true, |last|
113+
now.duration_since(last).as_millis() > HOTKEY_TOGGLE_DELAY_MS as u128) {
114+
let mut is_running = running.lock().unwrap();
115+
*is_running = !*is_running;
116+
117+
if *is_running {
118+
log::info!("Hotkey pressed, starting simulation");
119+
initialize_simulation(&app_data, &selected_keys, &modifier_mode);
120+
start_simulation(
121+
Arc::clone(&running),
122+
Arc::clone(&interval_ms),
123+
Arc::clone(&selected_keys),
124+
Arc::clone(&modifier_mode),
125+
);
126+
} else {
127+
log::info!("Hotkey pressed, stopping simulation");
128+
}
129+
130+
*last_toggle_time = Some(now);
124131
}
125-
126-
*last_toggle_time = Some(now);
127132
}
128133
}
129134

0 commit comments

Comments
 (0)