use crate::managers::audio::AudioRecordingManager; use crate::managers::transcription::TranscriptionManager; use crate::shortcut; use crate::ManagedToggleState; use log::{info, warn}; use std::sync::Arc; use tauri::{AppHandle, Manager}; // Re-export all utility modules for easy access // pub use crate::audio_feedback::*; pub use crate::clipboard::*; pub use crate::overlay::*; pub use crate::tray::*; /// Centralized cancellation function that can be called from anywhere in the app. /// Handles cancelling both recording and transcription operations and updates UI state. pub fn cancel_current_operation(app: &AppHandle) { info!("Initiating operation cancellation..."); // Unregister the cancel shortcut asynchronously shortcut::unregister_cancel_shortcut(app); // First, reset all shortcut toggle states. // This is critical for non-push-to-talk mode where shortcuts toggle on/off let toggle_state_manager = app.state::(); if let Ok(mut states) = toggle_state_manager.lock() { states.active_toggles.values_mut().for_each(|v| *v = false); } else { warn!("Failed to lock toggle state manager during cancellation"); } // Cancel any ongoing recording let audio_manager = app.state::>(); audio_manager.cancel_recording(); // Update tray icon and hide overlay change_tray_icon(app, crate::tray::TrayIconState::Idle); hide_recording_overlay(app); // Unload model if immediate unload is enabled let tm = app.state::>(); tm.maybe_unload_immediately("cancellation"); info!("Operation cancellation completed - returned to idle state"); } /// Check if using the Wayland display server protocol #[cfg(target_os = "linux")] pub fn is_wayland() -> bool { std::env::var("WAYLAND_DISPLAY").is_ok() || std::env::var("XDG_SESSION_TYPE") .map(|v| v.to_lowercase() == "wayland") .unwrap_or(false) } /// Check if running on KDE Plasma desktop environment #[cfg(target_os = "linux")] pub fn is_kde_plasma() -> bool { std::env::var("XDG_CURRENT_DESKTOP") .map(|v| v.to_uppercase().contains("KDE")) .unwrap_or(false) || std::env::var("KDE_SESSION_VERSION").is_ok() } /// Check if running on KDE Plasma with Wayland #[cfg(target_os = "linux")] pub fn is_kde_wayland() -> bool { is_wayland() && is_kde_plasma() }