Files
jellytau/src-tauri/src/commands/sessions.rs
T
dtourolle 3fbf6afdbc Background-audio handoff for video + repository/player refactor
Hand video playback off to a native audio-only stream when the app is
backgrounded or locked, with no on-device video decode (UR-040). Adds
player_enter/exit_background_audio commands, an audio-only stream URL
for video items across the repository layer, and the frontend handoff
state machine wired into VideoPlayer. Includes accompanying
repository/offline/player refactoring and regenerates the traceability
matrix.
2026-07-22 21:52:07 +02:00

103 lines
3.0 KiB
Rust

//! TRACES: UR-010 | JA-021 | DR-037
use crate::jellyfin::client::SessionInfo;
use crate::session_poller::{PollingHint, SessionPollerManager};
use std::sync::Arc;
use tauri::State;
/// Tauri state wrapper for SessionPollerManager
pub struct SessionPollerWrapper(pub Arc<SessionPollerManager>);
/// Set polling frequency hint based on UI state
#[tauri::command]
#[specta::specta]
pub fn sessions_set_polling_hint(
poller: State<'_, SessionPollerWrapper>,
hint: String,
) -> Result<(), String> {
let parsed_hint = match hint.as_str() {
"cast_active" => PollingHint::CastActive,
"cast_discovery" => PollingHint::CastDiscovery,
"normal" => PollingHint::Normal,
_ => return Err(format!("Invalid polling hint: {}", hint)),
};
poller.0.set_polling_hint(parsed_hint);
Ok(())
}
/// Manually trigger a session poll (for refresh button)
#[tauri::command]
#[specta::specta]
pub async fn sessions_poll_now(
poller: State<'_, SessionPollerWrapper>,
) -> Result<Vec<SessionInfo>, String> {
poller.0.poll_now().await
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_polling_hint_parsing() {
// Test valid hints
assert_eq!(
match "cast_active" {
"cast_active" => Some(PollingHint::CastActive),
"cast_discovery" => Some(PollingHint::CastDiscovery),
"normal" => Some(PollingHint::Normal),
_ => None,
},
Some(PollingHint::CastActive)
);
assert_eq!(
match "cast_discovery" {
"cast_active" => Some(PollingHint::CastActive),
"cast_discovery" => Some(PollingHint::CastDiscovery),
"normal" => Some(PollingHint::Normal),
_ => None,
},
Some(PollingHint::CastDiscovery)
);
assert_eq!(
match "normal" {
"cast_active" => Some(PollingHint::CastActive),
"cast_discovery" => Some(PollingHint::CastDiscovery),
"normal" => Some(PollingHint::Normal),
_ => None,
},
Some(PollingHint::Normal)
);
}
#[test]
fn test_invalid_polling_hint() {
// Test invalid hint
let result = match "invalid" {
"cast_active" => Ok(PollingHint::CastActive),
"cast_discovery" => Ok(PollingHint::CastDiscovery),
"normal" => Ok(PollingHint::Normal),
_ => Err("Invalid polling hint"),
};
assert!(result.is_err());
}
#[test]
fn test_session_poller_wrapper_structure() {
// Test that wrapper type structure is correct
assert_eq!(std::mem::size_of::<SessionPollerWrapper>() > 0, true);
}
#[test]
fn test_polling_hints_exist() {
// Verify polling hint variants exist
let _ = PollingHint::CastActive;
let _ = PollingHint::CastDiscovery;
let _ = PollingHint::Normal;
}
}