Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,15 @@ fn initialize_core_logic(app_handle: &AppHandle) {
Err(e) => log::error!("Failed to unload model via tray: {}", e),
}
}
"transcribe" => {
utils::send_transcription_input(app, "transcribe", "tray");
}
"stop" => {
utils::send_transcription_input(app, "transcribe", "tray");
}
"cancel" => {
use crate::utils::cancel_current_operation;

// Use centralized cancellation that handles all operations
cancel_current_operation(app);
utils::cancel_current_operation(app);
}
"quit" => {
app.exit(0);
Expand Down Expand Up @@ -481,9 +485,9 @@ pub fn run(cli_args: CliArgs) {
builder
.plugin(tauri_plugin_single_instance::init(|app, args, _cwd| {
if args.iter().any(|a| a == "--toggle-transcription") {
signal_handle::send_transcription_input(app, "transcribe", "CLI");
utils::send_transcription_input(app, "transcribe", "CLI");
} else if args.iter().any(|a| a == "--toggle-post-process") {
signal_handle::send_transcription_input(app, "transcribe_with_post_process", "CLI");
utils::send_transcription_input(app, "transcribe_with_post_process", "CLI");
} else if args.iter().any(|a| a == "--cancel") {
crate::utils::cancel_current_operation(app);
} else {
Expand Down
15 changes: 2 additions & 13 deletions src-tauri/src/signal_handle.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::TranscriptionCoordinator;
use crate::utils::send_transcription_input;
#[cfg(unix)]
use log::debug;
use log::warn;
use tauri::{AppHandle, Manager};
use tauri::AppHandle;

#[cfg(unix)]
use signal_hook::consts::{SIGUSR1, SIGUSR2};
Expand All @@ -11,16 +10,6 @@ use signal_hook::iterator::Signals;
#[cfg(unix)]
use std::thread;

/// Send a transcription input to the coordinator.
/// Used by signal handlers, CLI flags, and any other external trigger.
pub fn send_transcription_input(app: &AppHandle, binding_id: &str, source: &str) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to utils as it is used not only by signals but also by CLI and now tray menu.

if let Some(c) = app.try_state::<TranscriptionCoordinator>() {
c.send_input(binding_id, source, true, false);
} else {
warn!("TranscriptionCoordinator not initialized");
}
}

#[cfg(unix)]
pub fn setup_signal_handler(app_handle: AppHandle, mut signals: Signals) {
debug!("Signal handlers registered (SIGUSR1, SIGUSR2)");
Expand Down
44 changes: 27 additions & 17 deletions src-tauri/src/tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,16 @@ pub fn update_tray_menu(app: &AppHandle, state: &TrayIconState, locale: Option<&

let menu = match state {
TrayIconState::Recording | TrayIconState::Transcribing => {
let stop_i = MenuItem::with_id(app, "stop", &strings.stop, true, None::<&str>)
.expect("failed to create stop item");
let cancel_i = MenuItem::with_id(app, "cancel", &strings.cancel, true, None::<&str>)
.expect("failed to create cancel item");
Menu::with_items(
app,
&[
&version_i,
&separator(),
&stop_i,
&cancel_i,
&separator(),
&copy_last_transcript_i,
Expand All @@ -190,23 +193,30 @@ pub fn update_tray_menu(app: &AppHandle, state: &TrayIconState, locale: Option<&
)
.expect("failed to create menu")
}
TrayIconState::Idle => Menu::with_items(
app,
&[
&version_i,
&separator(),
&copy_last_transcript_i,
&separator(),
&model_submenu,
&unload_model_i,
&separator(),
&settings_i,
&check_updates_i,
&separator(),
&quit_i,
],
)
.expect("failed to create menu"),
TrayIconState::Idle => {
let transcribe_i =
MenuItem::with_id(app, "transcribe", &strings.transcribe, true, None::<&str>)
.expect("failed to create transcribe item");
Menu::with_items(
app,
&[
&version_i,
&separator(),
&transcribe_i,
&separator(),
&copy_last_transcript_i,
&separator(),
&model_submenu,
&unload_model_i,
&separator(),
&settings_i,
&check_updates_i,
&separator(),
&quit_i,
],
)
.expect("failed to create menu")
}
};

let tray = app.state::<TrayIcon>();
Expand Down
12 changes: 11 additions & 1 deletion src-tauri/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::managers::audio::AudioRecordingManager;
use crate::managers::transcription::TranscriptionManager;
use crate::shortcut;
use crate::TranscriptionCoordinator;
use log::info;
use log::{info, warn};
use std::sync::Arc;
use tauri::{AppHandle, Manager};

Expand All @@ -12,6 +12,16 @@ pub use crate::clipboard::*;
pub use crate::overlay::*;
pub use crate::tray::*;

/// Send a transcription input to the coordinator.
/// Used by signal handlers, CLI flags, tray menu, and any other external trigger.
pub fn send_transcription_input(app: &AppHandle, binding_id: &str, source: &str) {
if let Some(c) = app.try_state::<TranscriptionCoordinator>() {
c.send_input(binding_id, source, true, false);
} else {
warn!("TranscriptionCoordinator not initialized");
}
}

/// 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) {
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/ar/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"unloadModel": "تفريغ النموذج",
"model": "النموذج",
"quit": "إنهاء",
"cancel": "إلغاء"
"cancel": "إلغاء",
"transcribe": "نسخ صوتي",
"stop": "إيقاف"
},
"sidebar": {
"general": "عام",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/bg/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"unloadModel": "Разтоварване на модела",
"model": "Модел",
"quit": "Изход",
"cancel": "Отказ"
"cancel": "Отказ",
"transcribe": "Транскрипция",
"stop": "Спри"
},
"sidebar": {
"general": "Общи",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/cs/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"unloadModel": "Uvolnit model",
"model": "Model",
"quit": "Ukončit",
"cancel": "Zrušit"
"cancel": "Zrušit",
"transcribe": "Přepsat",
"stop": "Zastavit"
},
"sidebar": {
"general": "Obecné",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/de/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"unloadModel": "Modell entladen",
"model": "Modell",
"quit": "Beenden",
"cancel": "Abbrechen"
"cancel": "Abbrechen",
"transcribe": "Transkribieren",
"stop": "Stopp"
},
"sidebar": {
"general": "Allgemein",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"unloadModel": "Unload Model",
"model": "Model",
"quit": "Quit",
"cancel": "Cancel"
"cancel": "Cancel",
"transcribe": "Transcribe",
"stop": "Stop"
},
"sidebar": {
"general": "General",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"unloadModel": "Descargar modelo",
"model": "Modelo",
"quit": "Salir",
"cancel": "Cancelar"
"cancel": "Cancelar",
"transcribe": "Transcribir",
"stop": "Detener"
},
"sidebar": {
"general": "General",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"unloadModel": "Décharger le modèle",
"model": "Modèle",
"quit": "Quitter",
"cancel": "Annuler"
"cancel": "Annuler",
"transcribe": "Transcrire",
"stop": "Arrêter"
},
"sidebar": {
"general": "Général",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/it/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"unloadModel": "Rilascia modello",
"model": "Modello",
"quit": "Esci",
"cancel": "Annulla"
"cancel": "Annulla",
"transcribe": "Trascrivi",
"stop": "Ferma"
},
"sidebar": {
"general": "Generale",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/ja/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"unloadModel": "モデルをアンロード",
"model": "モデル",
"quit": "終了",
"cancel": "キャンセル"
"cancel": "キャンセル",
"transcribe": "文字起こし",
"stop": "停止"
},
"sidebar": {
"general": "一般",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/ko/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"unloadModel": "모델 언로드",
"model": "모델",
"quit": "종료",
"cancel": "취소"
"cancel": "취소",
"transcribe": "받아쓰기",
"stop": "중지"
},
"sidebar": {
"general": "일반",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/pl/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"unloadModel": "Zwolnij model",
"model": "Model",
"quit": "Zamknij",
"cancel": "Anuluj"
"cancel": "Anuluj",
"transcribe": "Transkrybuj",
"stop": "Zatrzymaj"
},
"sidebar": {
"general": "Ogólne",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/pt/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"unloadModel": "Descarregar modelo",
"model": "Modelo",
"quit": "Sair",
"cancel": "Cancelar"
"cancel": "Cancelar",
"transcribe": "Transcrever",
"stop": "Parar"
},
"sidebar": {
"general": "Geral",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/ru/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"unloadModel": "Выгрузить модель",
"model": "Модель",
"quit": "Выход",
"cancel": "Отмена"
"cancel": "Отмена",
"transcribe": "Транскрибировать",
"stop": "Остановить"
},
"sidebar": {
"general": "Общие",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/sv/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"unloadModel": "Avlasta modell",
"model": "Modell",
"quit": "Avsluta",
"cancel": "Avbryt"
"cancel": "Avbryt",
"transcribe": "Transkribera",
"stop": "Stoppa"
},
"sidebar": {
"general": "Allmänt",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/tr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"unloadModel": "Modeli boşalt",
"model": "Model",
"quit": "Çıkış",
"cancel": "İptal"
"cancel": "İptal",
"transcribe": "Transkribe et",
"stop": "Durdur"
},
"sidebar": {
"general": "Genel",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/uk/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"unloadModel": "Вивантажити модель",
"model": "Модель",
"quit": "Вийти",
"cancel": "Скасувати"
"cancel": "Скасувати",
"transcribe": "Транскрибувати",
"stop": "Зупинити"
},
"sidebar": {
"general": "Загальні",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/vi/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"unloadModel": "Dỡ mô hình",
"model": "Mô hình",
"quit": "Thoát",
"cancel": "Hủy"
"cancel": "Hủy",
"transcribe": "Phiên âm",
"stop": "Dừng"
},
"sidebar": {
"general": "Chung",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/zh-TW/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"unloadModel": "卸載模型",
"model": "模型",
"quit": "結束",
"cancel": "取消"
"cancel": "取消",
"transcribe": "轉錄",
"stop": "停止"
},
"sidebar": {
"general": "一般",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"unloadModel": "卸载模型",
"model": "模型",
"quit": "退出",
"cancel": "取消"
"cancel": "取消",
"transcribe": "转录",
"stop": "停止"
},
"sidebar": {
"general": "通用",
Expand Down
Loading