feat: add "Unload Model" in tray (#731)
* feat: add "Unload Model" in tray * gray out "unload model" when model not loaded --------- Co-authored-by: CJ Pais <cj@cjpais.com>
This commit is contained in:
parent
14db1791d5
commit
ea4b270f85
18 changed files with 45 additions and 2 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
©_last_transcript_i,
|
||||
&unload_model_i,
|
||||
&separator(),
|
||||
&settings_i,
|
||||
&check_updates_i,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
"settings": "...الإعدادات",
|
||||
"checkUpdates": "...التحقق من وجود تحديثات",
|
||||
"copyLastTranscript": "نسخ آخر نص تم تفريغه",
|
||||
"unloadModel": "تفريغ النموذج",
|
||||
"quit": "إنهاء",
|
||||
"cancel": "إلغاء"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
"settings": "Nastavení...",
|
||||
"checkUpdates": "Zkontrolovat aktualizace...",
|
||||
"copyLastTranscript": "Zkopírovat poslední přepis",
|
||||
"unloadModel": "Uvolnit model",
|
||||
"quit": "Ukončit",
|
||||
"cancel": "Zrušit"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
"settings": "Einstellungen...",
|
||||
"checkUpdates": "Nach Updates suchen...",
|
||||
"copyLastTranscript": "Letzte Transkription kopieren",
|
||||
"unloadModel": "Modell entladen",
|
||||
"quit": "Beenden",
|
||||
"cancel": "Abbrechen"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
"settings": "Settings...",
|
||||
"checkUpdates": "Check for Updates...",
|
||||
"copyLastTranscript": "Copy Last Transcript",
|
||||
"unloadModel": "Unload Model",
|
||||
"quit": "Quit",
|
||||
"cancel": "Cancel"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
"settings": "Configuración...",
|
||||
"checkUpdates": "Buscar actualizaciones...",
|
||||
"copyLastTranscript": "Copiar la última transcripción",
|
||||
"unloadModel": "Descargar modelo",
|
||||
"quit": "Salir",
|
||||
"cancel": "Cancelar"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
"settings": "Impostazioni...",
|
||||
"checkUpdates": "Verifica aggiornamenti...",
|
||||
"copyLastTranscript": "Copia l'ultima trascrizione",
|
||||
"unloadModel": "Scarica modello",
|
||||
"quit": "Esci",
|
||||
"cancel": "Annulla"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
"settings": "設定...",
|
||||
"checkUpdates": "アップデートを確認...",
|
||||
"copyLastTranscript": "最新の文字起こしをコピー",
|
||||
"unloadModel": "モデルをアンロード",
|
||||
"quit": "終了",
|
||||
"cancel": "キャンセル"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
"settings": "설정...",
|
||||
"checkUpdates": "업데이트 확인...",
|
||||
"copyLastTranscript": "마지막 녹음 내용 복사",
|
||||
"unloadModel": "모델 언로드",
|
||||
"quit": "종료",
|
||||
"cancel": "취소"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
"settings": "Ustawienia...",
|
||||
"checkUpdates": "Sprawdź aktualizacje...",
|
||||
"copyLastTranscript": "Kopiuj ostatnią transkrypcję",
|
||||
"unloadModel": "Zwolnij model",
|
||||
"quit": "Zamknij",
|
||||
"cancel": "Anuluj"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
"settings": "Configurações...",
|
||||
"checkUpdates": "Verificar Atualizações...",
|
||||
"copyLastTranscript": "Copiar última transcrição",
|
||||
"unloadModel": "Descarregar modelo",
|
||||
"quit": "Sair",
|
||||
"cancel": "Cancelar"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
"settings": "Настройки...",
|
||||
"checkUpdates": "Проверить обновления...",
|
||||
"copyLastTranscript": "Скопировать последнюю транскрипцию",
|
||||
"unloadModel": "Выгрузить модель",
|
||||
"quit": "Выход",
|
||||
"cancel": "Отмена"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
"settings": "Ayarlar...",
|
||||
"checkUpdates": "Güncellemeleri Kontrol Et...",
|
||||
"copyLastTranscript": "Son transkripti kopyala",
|
||||
"unloadModel": "Modeli boşalt",
|
||||
"quit": "Çıkış",
|
||||
"cancel": "İptal"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
"settings": "Налаштування...",
|
||||
"checkUpdates": "Перевірити оновлення...",
|
||||
"copyLastTranscript": "Скопіювати останню транскрипцію",
|
||||
"unloadModel": "Вивантажити модель",
|
||||
"quit": "Вийти",
|
||||
"cancel": "Скасувати"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
"settings": "设置...",
|
||||
"checkUpdates": "检查更新...",
|
||||
"copyLastTranscript": "复制最新转录",
|
||||
"unloadModel": "卸载模型",
|
||||
"quit": "退出",
|
||||
"cancel": "取消"
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue