feat #14740: settings, keyring, tray and manual recording
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
//! Tray icon with "Öffnen", "Aufnahme manuell starten" and "Beenden".
|
||||
|
||||
use std::thread;
|
||||
|
||||
use tauri::menu::{Menu, MenuItem, PredefinedMenuItem};
|
||||
use tauri::tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent};
|
||||
use tauri::{AppHandle, Manager};
|
||||
|
||||
use crate::commands;
|
||||
use crate::state::AppState;
|
||||
|
||||
const OPEN: &str = "open";
|
||||
const RECORD: &str = "record";
|
||||
const QUIT: &str = "quit";
|
||||
|
||||
pub fn create(app: &AppHandle) -> tauri::Result<()> {
|
||||
let menu = Menu::with_items(
|
||||
app,
|
||||
&[
|
||||
&MenuItem::with_id(app, OPEN, "Öffnen", true, None::<&str>)?,
|
||||
&MenuItem::with_id(app, RECORD, "Aufnahme manuell starten", true, None::<&str>)?,
|
||||
&PredefinedMenuItem::separator(app)?,
|
||||
&MenuItem::with_id(app, QUIT, "Beenden", true, None::<&str>)?,
|
||||
],
|
||||
)?;
|
||||
|
||||
let mut builder = TrayIconBuilder::with_id("main")
|
||||
.tooltip("Gesprächsrekorder")
|
||||
.menu(&menu)
|
||||
.show_menu_on_left_click(false)
|
||||
.on_menu_event(|app, event| match event.id().as_ref() {
|
||||
OPEN => {
|
||||
commands::show_main(app);
|
||||
commands::show_recorder_if_recording(app);
|
||||
}
|
||||
RECORD => {
|
||||
// Opening the audio devices can take a moment; keep the
|
||||
// event loop free.
|
||||
let app = app.clone();
|
||||
thread::spawn(move || {
|
||||
if let Err(e) = commands::start_manual(&app) {
|
||||
log::error!("manual recording from tray failed: {e}");
|
||||
}
|
||||
});
|
||||
}
|
||||
QUIT => quit(app),
|
||||
_ => {}
|
||||
})
|
||||
.on_tray_icon_event(|tray, event| {
|
||||
if let TrayIconEvent::Click {
|
||||
button: MouseButton::Left,
|
||||
button_state: MouseButtonState::Up,
|
||||
..
|
||||
} = event
|
||||
{
|
||||
commands::show_main(tray.app_handle());
|
||||
}
|
||||
});
|
||||
if let Some(icon) = app.default_window_icon() {
|
||||
builder = builder.icon(icon.clone());
|
||||
}
|
||||
builder.build(app)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Finalizes a running recording, then exits.
|
||||
fn quit(app: &AppHandle) {
|
||||
let app = app.clone();
|
||||
thread::spawn(move || {
|
||||
if let Err(e) = app.state::<AppState>().stop_recording() {
|
||||
log::error!("stopping the recording on quit failed: {e}");
|
||||
}
|
||||
app.exit(0);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user