Skip to content

armgit / Handy

Public Imported from GitHub
0

A free, open source, and extensible speech-to-text application that works completely offline.

feat: add "Unload Model" in tray (#731)

Alex Pantechovskisea4b270f85eb
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index c45adf9f..fb3920b7 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -34,8 +34,7 @@ use std::sync::{Arc, Mutex};
use tauri::image::Image;
use tauri::tray::TrayIconBuilder;
-use tauri::Emitter;
-use tauri::{AppHandle, Manager};
+use tauri::{AppHandle, Emitter, Listener, Manager};
use tauri_plugin_autostart::{MacosLauncher, ManagerExt};
use tauri_plugin_log::{Builder as LogBuilder, RotationStrategy, Target, TargetKind};
@@ -185,6 +184,17 @@ fn initialize_core_logic(app_handle: &AppHandle) {
"copy_last_transcript" => {
tray::copy_last_transcript(app);
}
+ "unload_model" => {
+ let transcription_manager = app.state::<Arc<TranscriptionManager>>();
+ if !transcription_manager.is_model_loaded() {
+ log::warn!("No model is currently loaded.");
+ return;
+ }
+ match transcription_manager.unload_model() {
+ Ok(()) => log::info!("Model unloaded via tray."),
+ Err(e) => log::error!("Failed to unload model via tray: {}", e),
+ }
+ }
"cancel" => {
use crate::utils::cancel_current_operation;
@@ -203,6 +213,12 @@ fn initialize_core_logic(app_handle: &AppHandle) {
// Initialize tray menu with idle state
utils::update_tray_menu(app_handle, &utils::TrayIconState::Idle, None);
+ // Refresh tray menu when model state changes
+ let app_handle_for_listener = app_handle.clone();
+ app_handle.listen("model-state-changed", move |_| {
+ tray::update_tray_menu(&app_handle_for_listener, &tray::TrayIconState::Idle, None);
+ });
+
// Get the autostart manager and configure based on user setting
let autostart_manager = app_handle.autolaunch();
let settings = settings::get_settings(&app_handle);
diff --git a/src-tauri/src/tray.rs b/src-tauri/src/tray.rs
index 3cdffb72..e5beaa06 100644
--- a/src-tauri/src/tray.rs
+++ b/src-tauri/src/tray.rs
@@ -1,4 +1,5 @@
use crate::managers::history::{HistoryEntry, HistoryManager};
+use crate::managers::transcription::TranscriptionManager;
use crate::settings;
use crate::tray_i18n::get_tray_translations;
use log::{error, info, warn};
@@ -123,6 +124,15 @@ pub fn update_tray_menu(app: &AppHandle, state: &TrayIconState, locale: Option<&
None::<&str>,
)
.expect("failed to create copy last transcript item");
+ let model_loaded = app.state::<Arc<TranscriptionManager>>().is_model_loaded();
+ let unload_model_i = MenuItem::with_id(
+ app,
+ "unload_model",
+ &strings.unload_model,
+ model_loaded,
+ None::<&str>,
+ )
+ .expect("failed to create unload model item");
let quit_i = MenuItem::with_id(app, "quit", &strings.quit, true, quit_accelerator)
.expect("failed to create quit item");
let separator = || PredefinedMenuItem::separator(app).expect("failed to create separator");
@@ -154,6 +164,7 @@ pub fn update_tray_menu(app: &AppHandle, state: &TrayIconState, locale: Option<&
&version_i,
&separator(),
&copy_last_transcript_i,
+ &unload_model_i,
&separator(),
&settings_i,
&check_updates_i,
diff --git a/src/i18n/locales/ar/translation.json b/src/i18n/locales/ar/translation.json
index 7a4e59bb..a83ba642 100644
--- a/src/i18n/locales/ar/translation.json
+++ b/src/i18n/locales/ar/translation.json
@@ -3,6 +3,7 @@
"settings": "...الإعدادات",
"checkUpdates": "...التحقق من وجود تحديثات",
"copyLastTranscript": "نسخ آخر نص تم تفريغه",
+ "unloadModel": "تفريغ النموذج",
"quit": "إنهاء",
"cancel": "إلغاء"
},
diff --git a/src/i18n/locales/cs/translation.json b/src/i18n/locales/cs/translation.json
index 5bd50b04..e4a67cc4 100644
--- a/src/i18n/locales/cs/translation.json
+++ b/src/i18n/locales/cs/translation.json
@@ -3,6 +3,7 @@
"settings": "Nastavení...",
"checkUpdates": "Zkontrolovat aktualizace...",
"copyLastTranscript": "Zkopírovat poslední přepis",
+ "unloadModel": "Uvolnit model",
"quit": "Ukončit",
"cancel": "Zrušit"
},
diff --git a/src/i18n/locales/de/translation.json b/src/i18n/locales/de/translation.json
index 9a6b676b..31ae54c3 100644
--- a/src/i18n/locales/de/translation.json
+++ b/src/i18n/locales/de/translation.json
@@ -3,6 +3,7 @@
"settings": "Einstellungen...",
"checkUpdates": "Nach Updates suchen...",
"copyLastTranscript": "Letzte Transkription kopieren",
+ "unloadModel": "Modell entladen",
"quit": "Beenden",
"cancel": "Abbrechen"
},
diff --git a/src/i18n/locales/en/translation.json b/src/i18n/locales/en/translation.json
index c6c28411..714e2bf2 100644
--- a/src/i18n/locales/en/translation.json
+++ b/src/i18n/locales/en/translation.json
@@ -3,6 +3,7 @@
"settings": "Settings...",
"checkUpdates": "Check for Updates...",
"copyLastTranscript": "Copy Last Transcript",
+ "unloadModel": "Unload Model",
"quit": "Quit",
"cancel": "Cancel"
},
diff --git a/src/i18n/locales/es/translation.json b/src/i18n/locales/es/translation.json
index 617d63c0..93cc64ee 100644
--- a/src/i18n/locales/es/translation.json
+++ b/src/i18n/locales/es/translation.json
@@ -3,6 +3,7 @@
"settings": "Configuración...",
"checkUpdates": "Buscar actualizaciones...",
"copyLastTranscript": "Copiar la última transcripción",
+ "unloadModel": "Descargar modelo",
"quit": "Salir",
"cancel": "Cancelar"
},
diff --git a/src/i18n/locales/fr/translation.json b/src/i18n/locales/fr/translation.json
index 47f0b0ee..b2099f1c 100644
--- a/src/i18n/locales/fr/translation.json
+++ b/src/i18n/locales/fr/translation.json
@@ -3,6 +3,7 @@
"settings": "Paramètres...",
"checkUpdates": "Rechercher des mises à jour...",
"copyLastTranscript": "Copier la dernière transcription",
+ "unloadModel": "Décharger le modèle",
"quit": "Quitter",
"cancel": "Annuler"
},
diff --git a/src/i18n/locales/it/translation.json b/src/i18n/locales/it/translation.json
index cac1cbfa..2116f5f2 100644
--- a/src/i18n/locales/it/translation.json
+++ b/src/i18n/locales/it/translation.json
@@ -3,6 +3,7 @@
"settings": "Impostazioni...",
"checkUpdates": "Verifica aggiornamenti...",
"copyLastTranscript": "Copia l'ultima trascrizione",
+ "unloadModel": "Scarica modello",
"quit": "Esci",
"cancel": "Annulla"
},
diff --git a/src/i18n/locales/ja/translation.json b/src/i18n/locales/ja/translation.json
index bdf30a83..6af229d8 100644
--- a/src/i18n/locales/ja/translation.json
+++ b/src/i18n/locales/ja/translation.json
@@ -3,6 +3,7 @@
"settings": "設定...",
"checkUpdates": "アップデートを確認...",
"copyLastTranscript": "最新の文字起こしをコピー",
+ "unloadModel": "モデルをアンロード",
"quit": "終了",
"cancel": "キャンセル"
},
diff --git a/src/i18n/locales/ko/translation.json b/src/i18n/locales/ko/translation.json
index 38603f48..9712fbf5 100644
--- a/src/i18n/locales/ko/translation.json
+++ b/src/i18n/locales/ko/translation.json
@@ -3,6 +3,7 @@
"settings": "설정...",
"checkUpdates": "업데이트 확인...",
"copyLastTranscript": "마지막 녹음 내용 복사",
+ "unloadModel": "모델 언로드",
"quit": "종료",
"cancel": "취소"
},
diff --git a/src/i18n/locales/pl/translation.json b/src/i18n/locales/pl/translation.json
index 6a51452f..5244ab33 100644
--- a/src/i18n/locales/pl/translation.json
+++ b/src/i18n/locales/pl/translation.json
@@ -3,6 +3,7 @@
"settings": "Ustawienia...",
"checkUpdates": "Sprawdź aktualizacje...",
"copyLastTranscript": "Kopiuj ostatnią transkrypcję",
+ "unloadModel": "Zwolnij model",
"quit": "Zamknij",
"cancel": "Anuluj"
},
diff --git a/src/i18n/locales/pt/translation.json b/src/i18n/locales/pt/translation.json
index db2cf943..df9f3e4b 100644
--- a/src/i18n/locales/pt/translation.json
+++ b/src/i18n/locales/pt/translation.json
@@ -3,6 +3,7 @@
"settings": "Configurações...",
"checkUpdates": "Verificar Atualizações...",
"copyLastTranscript": "Copiar última transcrição",
+ "unloadModel": "Descarregar modelo",
"quit": "Sair",
"cancel": "Cancelar"
},
diff --git a/src/i18n/locales/ru/translation.json b/src/i18n/locales/ru/translation.json
index 98645d81..518b744e 100644
--- a/src/i18n/locales/ru/translation.json
+++ b/src/i18n/locales/ru/translation.json
@@ -3,6 +3,7 @@
"settings": "Настройки...",
"checkUpdates": "Проверить обновления...",
"copyLastTranscript": "Скопировать последнюю транскрипцию",
+ "unloadModel": "Выгрузить модель",
"quit": "Выход",
"cancel": "Отмена"
},
diff --git a/src/i18n/locales/tr/translation.json b/src/i18n/locales/tr/translation.json
index 0271aa3e..3c8a02c5 100644
--- a/src/i18n/locales/tr/translation.json
+++ b/src/i18n/locales/tr/translation.json
@@ -3,6 +3,7 @@
"settings": "Ayarlar...",
"checkUpdates": "Güncellemeleri Kontrol Et...",
"copyLastTranscript": "Son transkripti kopyala",
+ "unloadModel": "Modeli boşalt",
"quit": "Çıkış",
"cancel": "İptal"
},
diff --git a/src/i18n/locales/uk/translation.json b/src/i18n/locales/uk/translation.json
index 25c58748..db9b81aa 100644
--- a/src/i18n/locales/uk/translation.json
+++ b/src/i18n/locales/uk/translation.json
@@ -3,6 +3,7 @@
"settings": "Налаштування...",
"checkUpdates": "Перевірити оновлення...",
"copyLastTranscript": "Скопіювати останню транскрипцію",
+ "unloadModel": "Вивантажити модель",
"quit": "Вийти",
"cancel": "Скасувати"
},
diff --git a/src/i18n/locales/vi/translation.json b/src/i18n/locales/vi/translation.json
index 076f31d1..da530f44 100644
--- a/src/i18n/locales/vi/translation.json
+++ b/src/i18n/locales/vi/translation.json
@@ -3,6 +3,7 @@
"settings": "Cài đặt...",
"checkUpdates": "Kiểm tra cập nhật...",
"copyLastTranscript": "Sao chép bản chép lời mới nhất",
+ "unloadModel": "Dỡ mô hình",
"quit": "Thoát",
"cancel": "Hủy"
},
diff --git a/src/i18n/locales/zh/translation.json b/src/i18n/locales/zh/translation.json
index 627957a1..4f240f64 100644
--- a/src/i18n/locales/zh/translation.json
+++ b/src/i18n/locales/zh/translation.json
@@ -3,6 +3,7 @@
"settings": "设置...",
"checkUpdates": "检查更新...",
"copyLastTranscript": "复制最新转录",
+ "unloadModel": "卸载模型",
"quit": "退出",
"cancel": "取消"
},