`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
//! Server-reachability / connectivity commands.
|
|
//!
|
|
//! TRACES: UR-043 | IR-027 | DR-055
|
|
|
|
use crate::connectivity::{ConnectivityMonitor, ConnectivityStatus};
|
|
use std::sync::Arc;
|
|
use tauri::State;
|
|
|
|
/// Wrapper for ConnectivityMonitor managed state
|
|
pub struct ConnectivityMonitorWrapper(pub Arc<tokio::sync::Mutex<ConnectivityMonitor>>);
|
|
|
|
/// Check if the server is currently reachable
|
|
#[tauri::command]
|
|
#[specta::specta]
|
|
pub async fn connectivity_check_server(
|
|
state: State<'_, ConnectivityMonitorWrapper>,
|
|
) -> Result<bool, String> {
|
|
let monitor = state.0.lock().await;
|
|
Ok(monitor.check_reachability().await)
|
|
}
|
|
|
|
/// Set the server URL and trigger an immediate check
|
|
#[tauri::command]
|
|
#[specta::specta]
|
|
pub async fn connectivity_set_server_url(
|
|
url: String,
|
|
state: State<'_, ConnectivityMonitorWrapper>,
|
|
) -> Result<(), String> {
|
|
let monitor = state.0.lock().await;
|
|
monitor.set_server_url(url).await;
|
|
Ok(())
|
|
}
|
|
|
|
/// Get the current connectivity status
|
|
#[tauri::command]
|
|
#[specta::specta]
|
|
pub async fn connectivity_get_status(
|
|
state: State<'_, ConnectivityMonitorWrapper>,
|
|
) -> Result<ConnectivityStatus, String> {
|
|
let monitor = state.0.lock().await;
|
|
Ok(monitor.get_status().await)
|
|
}
|
|
|
|
/// Start monitoring connectivity with adaptive polling
|
|
#[tauri::command]
|
|
#[specta::specta]
|
|
pub async fn connectivity_start_monitoring(
|
|
state: State<'_, ConnectivityMonitorWrapper>,
|
|
) -> Result<(), String> {
|
|
let monitor = state.0.lock().await;
|
|
monitor.start_monitoring().await;
|
|
Ok(())
|
|
}
|
|
|
|
/// Stop monitoring connectivity
|
|
#[tauri::command]
|
|
#[specta::specta]
|
|
pub async fn connectivity_stop_monitoring(
|
|
state: State<'_, ConnectivityMonitorWrapper>,
|
|
) -> Result<(), String> {
|
|
let monitor = state.0.lock().await;
|
|
monitor.stop_monitoring();
|
|
Ok(())
|
|
}
|
|
|
|
/// Mark the server as reachable (called after successful API calls)
|
|
#[tauri::command]
|
|
#[specta::specta]
|
|
pub async fn connectivity_mark_reachable(
|
|
state: State<'_, ConnectivityMonitorWrapper>,
|
|
) -> Result<(), String> {
|
|
let monitor = state.0.lock().await;
|
|
monitor.mark_reachable().await;
|
|
Ok(())
|
|
}
|
|
|
|
/// Mark the server as unreachable (called after failed API calls)
|
|
#[tauri::command]
|
|
#[specta::specta]
|
|
pub async fn connectivity_mark_unreachable(
|
|
error: Option<String>,
|
|
state: State<'_, ConnectivityMonitorWrapper>,
|
|
) -> Result<(), String> {
|
|
let monitor = state.0.lock().await;
|
|
monitor.mark_unreachable(error).await;
|
|
Ok(())
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_connectivity_monitor_wrapper_structure() {
|
|
// Test that wrapper can be created and holds Arc
|
|
// We can't instantiate ConnectivityMonitor directly in tests
|
|
// due to its dependencies, so we just test the wrapper type structure
|
|
|
|
// This verifies the wrapper type exists and can hold Arc<Mutex>
|
|
assert!(std::mem::size_of::<ConnectivityMonitorWrapper>() > 0);
|
|
}
|
|
}
|