3fa4d102df
The cancel key was consumed by rdev::grab at all times, not just during recording/transcribing. This made the Escape key unusable system-wide while Mouth was running. Now the cancel key only gets swallowed when Mouth is actively recording or transcribing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
42 lines
1.2 KiB
Rust
42 lines
1.2 KiB
Rust
use std::sync::atomic::{AtomicBool, Ordering};
|
|
use std::sync::RwLock;
|
|
use std::time::Instant;
|
|
|
|
/// Thread-safe shared state accessible by the coordinator, IPC listener, and tray icon.
|
|
pub struct SharedState {
|
|
pub state: RwLock<String>,
|
|
/// True when recording or transcribing — the hotkey listener uses this to
|
|
/// decide whether to swallow the cancel key.
|
|
pub is_active: AtomicBool,
|
|
pub model: String,
|
|
pub accelerator: String,
|
|
pub started_at: Instant,
|
|
}
|
|
|
|
impl SharedState {
|
|
pub fn new(model: String, accelerator: String) -> Self {
|
|
Self {
|
|
state: RwLock::new("idle".to_string()),
|
|
is_active: AtomicBool::new(false),
|
|
model,
|
|
accelerator,
|
|
started_at: Instant::now(),
|
|
}
|
|
}
|
|
|
|
pub fn set_state(&self, state: &str) {
|
|
if let Ok(mut s) = self.state.write() {
|
|
*s = state.to_string();
|
|
}
|
|
self.is_active.store(state != "idle", Ordering::Release);
|
|
}
|
|
|
|
pub fn get_state(&self) -> String {
|
|
self.state.read().map(|s| s.clone()).unwrap_or_else(|_| "unknown".to_string())
|
|
}
|
|
|
|
pub fn uptime_secs(&self) -> u64 {
|
|
self.started_at.elapsed().as_secs()
|
|
}
|
|
}
|