`cargo clippy --all-targets` went from 51 warnings (23 in the lib) to zero. Most were mechanical — needless borrows, `assert_eq!` against a bool literal, `vec!` where an array does, `or_insert_with(Vec::new)`, a loop index used only to index — and were applied with `clippy --fix`, then reviewed line by line. That review caught one auto-fix that was *not* semantically neutral: dropping the redundant `use hostname;` left its `#[cfg(target_os = "linux")]` orphaned directly above `SERVICE_NAME`, which would have silently cfg'd the constant out of every non-Linux build. Removed the stray attribute with the import. Where a lint asked for a risky change rather than a better one, it is suppressed with a comment saying why: - `too_many_arguments` on five `#[tauri::command]` handlers and `ThumbnailCache::save_thumbnail` — most of the arity is `State<'_, _>` injection, and a parameter struct would change the IPC contract and the generated TypeScript for no readability gain. - `large_enum_variant` on `PlayerStatusEvent` and `AutoplayDecision` — both are serde + specta wire types emitted a handful of times a second, never bulk allocated; boxing would have to stay invisible to the generated bindings while every match arm gained a deref. - `await_holding_lock` on the `hybrid`/`offline` test modules — the guard is a test-only serialisation lock for the process-global `INCLUDE_CATALOG_BROWSE` flag, and the await it spans *is* the critical section. Each `#[tokio::test]` gets its own single-threaded runtime, so this is not the production deadlock class the lint targets; restructuring would reintroduce the flag race. Real fixes elsewhere: `JellyfinItem::to_media_item` takes `self` by value, so it is now `into_media_item`; the five-tuple episode row in the download commands has a named `EpisodeRow` alias; the mpv `PropertyChange` arm matches `name: "pause"` instead of guarding on it. Also converted the last 27 raw `.lock().unwrap()` call sites to `lock_safe()`, completing the `MutexSafe`/`RwLockSafe` convention. All of them turned out to be in test modules — production code was already clean — so this is consistency rather than a fix. The two raw locks in `utils/lock.rs` stay raw on purpose: those tests deliberately poison a mutex to prove the helpers recover from it. Pure refactoring: all 698 tests still pass.
103 lines
2.9 KiB
Rust
103 lines
2.9 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!(std::mem::size_of::<SessionPollerWrapper>() > 0);
|
|
}
|
|
|
|
#[test]
|
|
fn test_polling_hints_exist() {
|
|
// Verify polling hint variants exist
|
|
let _ = PollingHint::CastActive;
|
|
let _ = PollingHint::CastDiscovery;
|
|
let _ = PollingHint::Normal;
|
|
}
|
|
}
|