- Add #[specta::specta] to all 201 #[tauri::command] functions. - Derive specta::Type on all IPC DTOs (repository/types, settings, player/storage/ download command DTOs, player enums, jellyfin SessionInfo/NowPlayingItem/PlayState, ThumbnailCacheStats, DownloadInfo, CacheConfig, etc.). - Replace tauri::generate_handler! with a tauri_specta::Builder + collect_commands! in lib.rs (exports bindings.ts in debug builds). Two contract changes required by specta constraints (frontend migration follows): - specta caps command arity at 10 args: download_item_and_start / download_item / download_video now take a single request struct (params bundled, body unchanged via destructuring). - specta can't parse split serde rename_all: SessionInfo/NowPlayingItem/PlayState switched to rename_all = "PascalCase" (Jellyfin deserialization preserved; these now serialize PascalCase to the frontend). cargo check --lib is clean (0 errors). Frontend migration to bindings.ts is the next step.
103 lines
3.0 KiB
Rust
103 lines
3.0 KiB
Rust
//! TRACES: UR-010 | JA-021 | DR-037
|
|
|
|
use std::sync::Arc;
|
|
use tauri::State;
|
|
use crate::session_poller::{PollingHint, SessionPollerManager};
|
|
use crate::jellyfin::client::SessionInfo;
|
|
|
|
/// 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;
|
|
}
|
|
}
|