Skip to content

Commit 6c0de24

Browse files
wesbillmanPinky
andcommitted
fix(desktop): honor disabled PTT shortcut in handler
Gate incoming global shortcut events on the same PTT shortcut settings predicate used for registration. If unregistering fails after the user disables the shortcut, any still-delivered OS events are ignored instead of toggling push-to-talk. Co-authored-by: Pinky <44b8e82baa6e0e254e0208d68f335c283c94e7b78dd1fa10d5a49d3f13dd0435@sprout-oss.stage.blox.sqprod.co> Signed-off-by: Wes <[email protected]>
1 parent 5db27eb commit 6c0de24

2 files changed

Lines changed: 8 additions & 14 deletions

File tree

‎desktop/src-tauri/src/lib.rs‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -431,19 +431,9 @@ pub fn run() {
431431
None => return,
432432
};
433433

434-
// Only act if a huddle is active and mode is PTT.
435-
let (is_ptt_mode, is_active) = match state.huddle_state.lock() {
436-
Ok(hs) => (
437-
hs.voice_input_mode == huddle::VoiceInputMode::PushToTalk,
438-
matches!(
439-
hs.phase,
440-
huddle::HuddlePhase::Connected | huddle::HuddlePhase::Active
441-
),
442-
),
443-
Err(_) => return,
444-
};
445-
446-
if !is_ptt_mode || !is_active {
434+
// This is a defensive runtime gate: if unregistering fails after the user
435+
// disables the shortcut, the OS may still deliver events to this handler.
436+
if !ptt_shortcut::should_handle_shortcut_event(&state) {
447437
return;
448438
}
449439

‎desktop/src-tauri/src/ptt_shortcut.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn set_ptt_inactive(app: &AppHandle, state: &AppState) {
136136
let _ = app.emit("ptt-state", false);
137137
}
138138

139-
fn should_register(state: &AppState) -> bool {
139+
pub(crate) fn should_handle_shortcut_event(state: &AppState) -> bool {
140140
if !state.ptt_shortcut.enabled.load(Ordering::Acquire) {
141141
return false;
142142
}
@@ -147,6 +147,10 @@ fn should_register(state: &AppState) -> bool {
147147
&& matches!(hs.phase, HuddlePhase::Connected | HuddlePhase::Active)
148148
}
149149

150+
fn should_register(state: &AppState) -> bool {
151+
should_handle_shortcut_event(state)
152+
}
153+
150154
pub fn refresh_registration(app: &AppHandle, state: &AppState) {
151155
let should_be_registered = should_register(state);
152156
let is_registered = state.ptt_shortcut.registered.load(Ordering::Acquire);

0 commit comments

Comments
 (0)