T-032: Tray-Icon (Anzeigen/Beenden), Autostart-Plugin, Einstellungs-Panel (Zahnrad in der Leiste)

This commit is contained in:
2026-11-06 20:38:40 +01:00
parent 06ac4ebd11
commit e7fe398f39
7 changed files with 222 additions and 8 deletions

127
src-tauri/Cargo.lock generated
View File

@ -207,6 +207,20 @@ version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
[[package]]
name = "auto-launch"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17918dba7ecf78b9a14507ec9f984e7977d13fad87dc86d61038980a45d128cf"
dependencies = [
"dirs 6.0.0",
"os_info",
"smappservice-rs",
"thiserror 2.0.21",
"windows-registry",
"windows-result",
]
[[package]]
name = "autocfg"
version = "1.5.1"
@ -454,6 +468,12 @@ version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
[[package]]
name = "cfg_aliases"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527"
[[package]]
name = "chrono"
version = "0.4.45"
@ -723,6 +743,15 @@ dependencies = [
"crypto-common",
]
[[package]]
name = "dirs"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e"
dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs"
version = "7.0.0"
@ -1434,6 +1463,7 @@ dependencies = [
"serde_json",
"tauri",
"tauri-build",
"tauri-plugin-autostart",
"tauri-plugin-opener",
]
@ -2124,6 +2154,18 @@ version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086"
[[package]]
name = "nix"
version = "0.31.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf20d2fde8ff38632c426f1165ed7436270b44f199fc55284c38276f9db47c3d"
dependencies = [
"bitflags 2.13.2",
"cfg-if",
"cfg_aliases",
"libc",
]
[[package]]
name = "num-conv"
version = "0.2.2"
@ -2285,6 +2327,7 @@ checksum = "e3e0adef53c21f888deb4fa59fc59f7eb17404926ee8a6f59f5df0fd7f9f3272"
dependencies = [
"bitflags 2.13.2",
"block2",
"libc",
"objc2",
"objc2-core-foundation",
]
@ -2312,6 +2355,30 @@ dependencies = [
"objc2-foundation",
]
[[package]]
name = "objc2-security"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "709fe137109bd1e8b5a99390f77a7d8b2961dafc1a1c5db8f2e60329ad6d895a"
dependencies = [
"bitflags 2.13.2",
"objc2",
"objc2-core-foundation",
]
[[package]]
name = "objc2-service-management"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b213642d6959cc6023ceb1217aa595eaaf09b8094ce95127c103cab611fe65e8"
dependencies = [
"block2",
"objc2",
"objc2-core-foundation",
"objc2-foundation",
"objc2-security",
]
[[package]]
name = "objc2-ui-kit"
version = "0.3.2"
@ -2390,6 +2457,21 @@ dependencies = [
"pin-project-lite",
]
[[package]]
name = "os_info"
version = "3.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cf20a545b305cf1da722b236b5155c9bb35f1d5ceb28c048bd96ca842f41b5b"
dependencies = [
"android_system_properties",
"log",
"nix",
"objc2",
"objc2-foundation",
"objc2-ui-kit",
"windows-sys 0.61.2",
]
[[package]]
name = "pango"
version = "0.18.3"
@ -3141,6 +3223,18 @@ version = "1.16.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0d5d4b1981b8bbbb7aed204cae5726d683d5d6ac7e74ec54122ea28f315e7c8"
[[package]]
name = "smappservice-rs"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52703b97a53101cf5d4580e0737aaa634ce1fdcfc123c16b2a9658e358013488"
dependencies = [
"objc2",
"objc2-foundation",
"objc2-service-management",
"thiserror 2.0.21",
]
[[package]]
name = "socket2"
version = "0.6.5"
@ -3383,7 +3477,7 @@ dependencies = [
"anyhow",
"bytes",
"cookie",
"dirs",
"dirs 7.0.0",
"dunce",
"embed_plist",
"getrandom 0.3.4",
@ -3434,7 +3528,7 @@ checksum = "adddb0e648752aaac5da9c3c3c6a68e1e87cab55e3b757b18a9441ef8c3ac614"
dependencies = [
"anyhow",
"cargo_toml",
"dirs",
"dirs 7.0.0",
"glob",
"heck 0.5.0",
"json-patch",
@ -3506,6 +3600,20 @@ dependencies = [
"walkdir",
]
[[package]]
name = "tauri-plugin-autostart"
version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bce56ceb0a99b8ab5eebc977ba9ffc62391b862648cb9ab76fc8bc7231b8f7e2"
dependencies = [
"auto-launch",
"serde",
"serde_json",
"tauri",
"tauri-plugin",
"thiserror 2.0.21",
]
[[package]]
name = "tauri-plugin-opener"
version = "2.7.2"
@ -3954,7 +4062,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2b9c52859a94554803ccd4a24b98f74148ebc73b90676d783f3490b1bff9d72"
dependencies = [
"crossbeam-channel",
"dirs",
"dirs 7.0.0",
"libappindicator",
"muda",
"objc2",
@ -4436,6 +4544,17 @@ dependencies = [
"windows-link",
]
[[package]]
name = "windows-registry"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720"
dependencies = [
"windows-link",
"windows-result",
"windows-strings",
]
[[package]]
name = "windows-result"
version = "0.4.1"
@ -4597,7 +4716,7 @@ dependencies = [
"block2",
"cookie",
"crossbeam-channel",
"dirs",
"dirs 7.0.0",
"dom_query",
"dpi",
"dunce",

View File

@ -18,7 +18,8 @@ crate-type = ["staticlib", "cdylib", "rlib"]
tauri-build = { version = "2", features = [] }
[dependencies]
tauri = { version = "2", features = ["protocol-asset"] }
tauri = { version = "2", features = ["protocol-asset", "tray-icon"] }
tauri-plugin-autostart = "2"
tauri-plugin-opener = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"

View File

@ -8,6 +8,9 @@ use download::{DownloadMgr, SharedDownloadMgr};
use player::{MpvPlayer, Player, PlayerState, SharedPlayer};
use tauri::Manager;
use tauri::menu::{Menu, MenuItem};
use tauri::tray::TrayIconBuilder;
use tauri_plugin_autostart::ManagerExt;
#[tauri::command]
fn auth_status(client: tauri::State<CliAudibleClient>) -> Result<AuthStatus, String> {
@ -202,6 +205,23 @@ async fn bookmark_set_note(
.map_err(|e| format!("Hintergrundthread fehlgeschlagen: {e}"))?
}
#[tauri::command]
async fn autostart_enabled(app: tauri::AppHandle) -> Result<bool, String> {
app.autolaunch()
.is_enabled()
.map_err(|e| format!("Autostart: {e}"))
}
#[tauri::command]
async fn autostart_set(app: tauri::AppHandle, on: bool) -> Result<(), String> {
let al = app.autolaunch();
if on {
al.enable().map_err(|e| format!("Autostart aktivieren: {e}"))
} else {
al.disable().map_err(|e| format!("Autostart deaktivieren: {e}"))
}
}
#[tauri::command]
async fn player_snapshot(pl: tauri::State<'_, SharedPlayer>) -> Result<PlayerState, String> {
let p = pl.inner().clone();
@ -214,6 +234,10 @@ async fn player_snapshot(pl: tauri::State<'_, SharedPlayer>) -> Result<PlayerSta
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_autostart::init(
tauri_plugin_autostart::MacosLauncher::LaunchAgent,
None,
))
.manage(CliAudibleClient::new())
.manage(DownloadMgr::new())
.manage(MpvPlayer::new())
@ -223,14 +247,32 @@ pub fn run() {
let p = app.state::<SharedPlayer>().inner().clone();
p.attach(app.handle().clone());
player::spawn_mpris(p.clone());
// Tray-Icon (T-032)
let show = MenuItem::with_id(app, "show", "Hörwerk anzeigen", true, None::<&str>)?;
let quit = MenuItem::with_id(app, "quit", "Beenden", true, None::<&str>)?;
let menu = Menu::with_items(app, &[&show, &quit])?;
TrayIconBuilder::with_id("hoerwerk-tray")
.icon(app.default_window_icon().unwrap().clone())
.tooltip("Hörwerk")
.menu(&menu)
.menu_on_left_click(false)
.on_menu_event(|app, ev| match ev.id().as_ref() {
"show" => {
if let Some(w) = app.get_webview_window("main") {
let _ = w.show();
let _ = w.set_focus();
}
}
"quit" => app.exit(0),
_ => {}
})
.build(app)?;
// Letztes Buch pausiert fortsetzen (T-024), sobald mpv bereit ist
std::thread::Builder::new()
.name("hoerwerk-resume".into())
.spawn(move || {
std::thread::sleep(std::time::Duration::from_millis(1200));
if let Ok(_st) = p.resume_last() {
// Events gehen live; UI sieht die Leiste über Snapshot
}
let _ = p.resume_last();
})
.expect("resume thread");
Ok(())
@ -252,6 +294,8 @@ pub fn run() {
player_set_speed,
player_stop,
player_snapshot,
autostart_enabled,
autostart_set,
bookmark_list,
bookmark_add,
bookmark_remove,

View File

@ -29,6 +29,8 @@
bmAdd,
bmRemove,
bmSetNote,
autostartEnabled,
autostartSet,
type Bm,
type Book,
type DlItem,
@ -123,6 +125,23 @@
playerSetPosition(bookmarks[idx]?.time ?? 0)
}
// Einstellungen (T-032)
let settingsOpen = $state(false)
let autostart = $state(false)
function openSettings(): void {
settingsOpen = !settingsOpen
if (settingsOpen) {
autostartEnabled().then((on) => (autostart = on)).catch(() => (autostart = false))
}
}
function setAutostart(on: boolean): void {
autostartSet(on)
.then(() => (autostart = on))
.catch((e) => (error = String(e)))
}
function setSleep(sel: string): void {
if (sleepTimer) {
clearInterval(sleepTimer)
@ -649,6 +668,7 @@
/>
<button class="ghost iconbtn" title="Lesezeichen (Panel)" onclick={() => openBookmarks()}><Icon name="flag" size={14} /></button>
<button class="ghost iconbtn" title="Bookmark an aktueller Stelle" onclick={() => bookmarkAddHere()}><Icon name="pencil" size={14} /></button>
<button class="ghost iconbtn" title="Einstellungen" onclick={() => openSettings()}><Icon name="gear" size={14} /></button>
<button class="ghost" title="Schließen" onclick={() => playerStop()}><Icon name="x" /></button>
<span class="sleepwrap">
<Icon name="moon" size={13} />
@ -696,6 +716,26 @@
<button class="ghost" title="Panel schließen" onclick={() => (bmOpen = false)}><Icon name="x" size={12} /></button>
</div>
{/if}
{#if settingsOpen}
<div class="bmpanel settings">
<label class="setrow">
<input
type="checkbox"
checked={autostart}
onchange={(e) => setAutostart(e.currentTarget.checked)}
/>
<span>Beim Systemstart starten</span>
</label>
<p class="muted small" style="margin:0">
Daten: <code>~/.local/share/hoerwerk/</code> · Downloads:
<code>~/.cache/hoerwerk/</code>
</p>
<p class="muted small" style="margin:0">
Tray-Icon im Systemmenü (Anzeigen/Beenden). Media-Tasten über MPRIS.
</p>
<button class="ghost" title="Schließen" onclick={() => (settingsOpen = false)}><Icon name="x" size={12} /></button>
</div>
{/if}
{/if}
</main>
{/if}

View File

@ -437,3 +437,9 @@ code {
font-size: 0.85rem;
padding: 0.25rem 0.5rem;
}
.settings .setrow {
display: flex;
align-items: center;
gap: 0.5rem;
}

View File

@ -19,6 +19,8 @@
'<path d="m4 6 6 6-6 6"/><path d="m13 6 6 6-6 6"/>',
check: '<path d="M4 12l5 5L20 6"/>',
flag: '<path d="M6 21V4h11l-2.5 4L17 12H6"/>',
gear:
'<circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 1 1-4 0v-.09a1.65 1.65 0 0 0-1-1.51 1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 1 1 0-4h.09a1.65 1.65 0 0 0 1.51-1 1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 1 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 1 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/>',
pencil:
'<path d="M4 20h4L20 8l-4-4L4 16v4z"/><path d="M13.5 6.5l4 4"/>',
x: '<path d="M5 5l14 14"/><path d="M19 5 5 19"/>',

View File

@ -76,6 +76,8 @@ export const bmRemove = (asin: string, index: number) =>
invoke<Bm[]>('bookmark_remove', { asin, index })
export const bmSetNote = (asin: string, index: number, note: string) =>
invoke<Bm[]>('bookmark_set_note', { asin, index, note })
export const autostartEnabled = () => invoke<boolean>('autostart_enabled')
export const autostartSet = (on: boolean) => invoke<void>('autostart_set', { on })
export function fmtClock(sec: number): string {
const t = Math.max(0, Math.floor(sec))
const h = Math.floor(t / 3600)