Tray-Icon mit Menü (Zeigen/Minimieren/Beenden)

- Tray-Icon zeigt App im System-Tray
- Kontextmenü: Fenster zeigen, Minimieren, Beenden
- Klick auf Tray-Icon zeigt Fenster
- Capabilities für Window-Operationen ergänzt
- Icon-Konfiguration in tauri.conf.json

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Eddy 2026-04-14 11:57:15 +02:00
parent 4ba14a53e1
commit 3c6da3b3d5
3 changed files with 66 additions and 2 deletions

View file

@ -5,6 +5,12 @@
"windows": ["main"],
"permissions": [
"core:default",
"core:window:allow-show",
"core:window:allow-hide",
"core:window:allow-set-focus",
"core:window:allow-close",
"core:menu:default",
"core:tray:default",
"shell:allow-open",
"shell:allow-execute",
"shell:allow-spawn",

View file

@ -2,7 +2,11 @@
// Hauptmodul für die Rust-Seite der App
use std::sync::{Arc, Mutex};
use tauri::Manager;
use tauri::{
Manager,
menu::{Menu, MenuItem},
tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent},
};
mod audit;
mod claude;
@ -97,6 +101,57 @@ pub fn run() {
println!("🧠 Initialisiere Gedächtnis-System...");
});
// Tray-Icon einrichten
let show_item = MenuItem::with_id(app, "show", "Fenster zeigen", true, None::<&str>)?;
let hide_item = MenuItem::with_id(app, "hide", "Minimieren", true, None::<&str>)?;
let quit_item = MenuItem::with_id(app, "quit", "Beenden", true, None::<&str>)?;
let tray_menu = Menu::with_items(app, &[&show_item, &hide_item, &quit_item])?;
// App-Icon für Tray verwenden
let icon = app.default_window_icon()
.cloned()
.expect("Kein App-Icon konfiguriert");
let tray_icon = TrayIconBuilder::new()
.icon(icon)
.menu(&tray_menu)
.show_menu_on_left_click(false)
.tooltip("Claude Desktop")
.on_menu_event(|app, event| {
match event.id.as_ref() {
"show" => {
if let Some(window) = app.get_webview_window("main") {
let _ = window.show();
let _ = window.set_focus();
}
}
"hide" => {
if let Some(window) = app.get_webview_window("main") {
let _ = window.hide();
}
}
"quit" => {
app.exit(0);
}
_ => {}
}
})
.on_tray_icon_event(|tray, event| {
// Doppelklick auf Tray-Icon zeigt das Fenster
if let TrayIconEvent::Click { button: MouseButton::Left, button_state: MouseButtonState::Up, .. } = event {
if let Some(window) = tray.app_handle().get_webview_window("main") {
let _ = window.show();
let _ = window.set_focus();
}
}
})
.build(app)?;
// Tray-Icon Handle speichern (optional für späteren Zugriff)
app.manage(tray_icon);
println!("🔲 Tray-Icon eingerichtet");
Ok(())
})
.run(tauri::generate_context!())

View file

@ -31,7 +31,10 @@
},
"bundle": {
"active": true,
"targets": ["appimage", "deb"]
"targets": ["appimage", "deb"],
"icon": [
"icons/icon.png"
]
},
"plugins": {
"shell": {