Fix race condition when toggling transcription via SIGUSR2 (#560)
* Fix race condition when toggling transcription via SIGUSR2 The toggle state was being set to false immediately when stop was called, but the actual transcription runs asynchronously. If another signal arrived before transcription completed, a new recording could start while the old transcription was still running, causing the old text to paste unexpectedly. Now the toggle state stays true until the async transcription task completes. * remove import --------- Co-authored-by: CJ Pais <cj@cjpais.com>
This commit is contained in:
parent
3bd2ad841d
commit
ae9c33e0c7
2 changed files with 9 additions and 1 deletions
|
|
@ -8,6 +8,7 @@ use crate::settings::{get_settings, AppSettings, APPLE_INTELLIGENCE_PROVIDER_ID}
|
|||
use crate::shortcut;
|
||||
use crate::tray::{change_tray_icon, TrayIconState};
|
||||
use crate::utils::{self, show_recording_overlay, show_transcribing_overlay};
|
||||
use crate::ManagedToggleState;
|
||||
use ferrous_opencc::{config::BuiltinConfig, OpenCC};
|
||||
use log::{debug, error};
|
||||
use once_cell::sync::Lazy;
|
||||
|
|
@ -408,6 +409,11 @@ impl ShortcutAction for TranscribeAction {
|
|||
utils::hide_recording_overlay(&ah);
|
||||
change_tray_icon(&ah, TrayIconState::Idle);
|
||||
}
|
||||
|
||||
// Clear toggle state now that transcription is complete
|
||||
if let Ok(mut states) = ah.state::<ManagedToggleState>().lock() {
|
||||
states.active_toggles.insert(binding_id, false);
|
||||
}
|
||||
});
|
||||
|
||||
debug!(
|
||||
|
|
|
|||
|
|
@ -47,7 +47,9 @@ pub fn setup_signal_handler(app_handle: AppHandle, mut signals: Signals) {
|
|||
.or_insert(false);
|
||||
|
||||
should_start = !*is_currently_active;
|
||||
*is_currently_active = should_start;
|
||||
if should_start {
|
||||
*is_currently_active = true;
|
||||
}
|
||||
} // Lock released here
|
||||
|
||||
// Now call the action without holding the lock
|
||||
|
|
|
|||
Loading…
Reference in a new issue