A free, open source, and extensible speech-to-text application that works completely offline.
Merge branch 'main' into cancel-actions-in-menu
CJ Paisa7c5b199fb42
diff --cc src-tauri/src/lib.rsindex 39879f76,11e4d7ee..eb8e6fe9--- a/src-tauri/src/lib.rs+++ b/src-tauri/src/lib.rs@@@ -57,40 -115,17 +79,22 @@@ pub fn run()"resources/tray_idle.png",tauri::path::BaseDirectory::Resource,)?)?)- .menu(&menu).show_menu_on_left_click(true)+ .icon_as_template(true).on_menu_event(|app, event| match event.id.as_ref() {"settings" => {- if let Some(settings_window) = app.get_webview_window("main") {- // First, ensure the window is visible- if let Err(e) = settings_window.show() {- eprintln!("Failed to show window: {}", e);- }- // Then, bring it to the front and give it focus- if let Err(e) = settings_window.set_focus() {- eprintln!("Failed to focus window: {}", e);- }- // Optional: On macOS, ensure the app becomes active if it was an accessory- #[cfg(target_os = "macos")]- {- if let Err(e) =- app.set_activation_policy(tauri::ActivationPolicy::Regular)- {- eprintln!("Failed to set activation policy to Regular: {}", e);- }- }- } else {- eprintln!("Main window not found");- }+ show_main_window(app);}"check_updates" => {+ show_main_window(app);let _ = app.emit("check-for-updates", ());}+ "cancel" => {+ use crate::utils::cancel_current_operation;++ // Use centralized cancellation that handles all operations+ cancel_current_operation(app);+ }"quit" => {app.exit(0);}@@@ -148,8 -180,8 +152,9 @@@shortcut::change_ptt_setting,shortcut::change_audio_feedback_setting,shortcut::change_translate_to_english_setting,+ shortcut::change_selected_language_setting,trigger_update_check,+ commands::cancel_operation,commands::models::get_available_models,commands::models::get_model_info,commands::models::download_model,diff --cc src-tauri/src/utils.rsindex 3e6e0a8c,54bf605f..400b2712--- a/src-tauri/src/utils.rs+++ b/src-tauri/src/utils.rs@@@ -95,120 -93,7 +95,121 @@@ pub fn change_tray_icon(app: &AppHandle).expect("failed to set icon"),));++ // Update menu based on state+ update_tray_menu(app, &icon);+}++/// 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) {+ use crate::actions::ACTION_MAP;+ use crate::managers::audio::AudioRecordingManager;+ use crate::ManagedToggleState;+ use std::sync::Arc;++ println!("Initiating operation cancellation...");++ // First, reset all shortcut toggle states and call stop actions+ // This is critical for non-push-to-talk mode where shortcuts toggle on/off+ let toggle_state_manager = app.state::<ManagedToggleState>();+ if let Ok(mut states) = toggle_state_manager.lock() {+ // For each currently active toggle, call its stop action and reset state+ let active_bindings: Vec<String> = states+ .active_toggles+ .iter()+ .filter(|(_, &is_active)| is_active)+ .map(|(binding_id, _)| binding_id.clone())+ .collect();++ for binding_id in active_bindings {+ println!("Stopping active action for binding: {}", binding_id);++ // Call the action's stop method to ensure proper cleanup+ if let Some(action) = ACTION_MAP.get(&binding_id) {+ action.stop(app, &binding_id, "cancelled");+ }++ // Reset the toggle state+ if let Some(is_active) = states.active_toggles.get_mut(&binding_id) {+ *is_active = false;+ }+ }+ } else {+ eprintln!("Warning: Failed to lock toggle state manager during cancellation");+ }++ // Cancel any ongoing recording+ let audio_manager = app.state::<Arc<AudioRecordingManager>>();+ audio_manager.cancel_recording();++ // Update tray icon and menu to idle state+ change_tray_icon(app, TrayIconState::Idle);++ println!("Operation cancellation completed - returned to idle state");+}++pub fn update_tray_menu(app: &AppHandle, state: &TrayIconState) {+ // Platform-specific accelerators+ #[cfg(target_os = "macos")]+ let (settings_accelerator, quit_accelerator) = (Some("Cmd+,"), Some("Cmd+Q"));+ #[cfg(not(target_os = "macos"))]+ let (settings_accelerator, quit_accelerator) = (Some("Ctrl+,"), Some("Ctrl+Q"));++ // Create common menu items+ let version_label = format!("Handy v{}", env!("CARGO_PKG_VERSION"));+ let version_i = MenuItem::with_id(app, "version", &version_label, false, None::<&str>)+ .expect("failed to create version item");+ let settings_i = MenuItem::with_id(app, "settings", "Settings...", true, settings_accelerator)+ .expect("failed to create settings item");+ let check_updates_i = MenuItem::with_id(+ app,+ "check_updates",+ "Check for Updates...",+ true,+ None::<&str>,+ )+ .expect("failed to create check updates item");+ let quit_i = MenuItem::with_id(app, "quit", "Quit", true, quit_accelerator)+ .expect("failed to create quit item");+ let separator = || PredefinedMenuItem::separator(app).expect("failed to create separator");++ let menu = match state {+ TrayIconState::Recording | TrayIconState::Transcribing => {+ let cancel_i = MenuItem::with_id(app, "cancel", "Cancel", true, None::<&str>)+ .expect("failed to create cancel item");+ Menu::with_items(+ app,+ &[+ &version_i,+ &separator(),+ &cancel_i,+ &separator(),+ &settings_i,+ &check_updates_i,+ &separator(),+ &quit_i,+ ],+ )+ .expect("failed to create menu")+ }+ TrayIconState::Idle => Menu::with_items(+ app,+ &[+ &version_i,+ &separator(),+ &settings_i,+ &check_updates_i,+ &separator(),+ &quit_i,+ ],+ )+ .expect("failed to create menu"),+ };++ let tray = app.state::<TrayIcon>();+ let _ = tray.set_menu(Some(menu));+ let _ = tray.set_icon_as_template(true);}/// Plays an audio resource from the resources directory.