Skip to main content

jellytau_lib/commands/player/
session.rs

1//! Media session state commands.
2//!
3//! TRACES: UR-005 | DR-009
4//!
5//! Read and dismiss the current media session (the Now Playing surface backing
6//! lockscreen/notification controls).
7
8use tauri::State;
9
10use super::{MediaSessionManagerWrapper, PlayerStateWrapper};
11use crate::player::PlayerStatusEvent;
12
13/// Get the current media session state
14#[tauri::command]
15#[specta::specta]
16pub async fn player_get_session(
17    session: State<'_, MediaSessionManagerWrapper>,
18) -> Result<crate::player::session::MediaSessionType, String> {
19    let manager = session.0.lock().map_err(|e| e.to_string())?;
20    Ok(manager.current().clone())
21}
22
23/// Dismiss the current media session (returns to Idle)
24#[tauri::command]
25#[specta::specta]
26pub async fn player_dismiss_session(
27    session: State<'_, MediaSessionManagerWrapper>,
28    player: State<'_, PlayerStateWrapper>,
29) -> Result<(), String> {
30    log::info!("[Session] Dismissing current media session");
31
32    // Dismiss the session
33    {
34        let mut manager = session.0.lock().map_err(|e| e.to_string())?;
35        manager.dismiss();
36    }
37
38    // Emit session changed event
39    if let Some(emitter) = player.0.lock().await.event_emitter() {
40        let manager = session.0.lock().map_err(|e| e.to_string())?;
41        emitter.emit(PlayerStatusEvent::SessionChanged {
42            session: manager.current().clone(),
43        });
44    }
45
46    Ok(())
47}