#[cfg(not(coverage))]
fn refresh_eye_feed_controls(
    widgets: &super::ui_components::LauncherWidgets,
    state: &LauncherState,
) {
    for monitor_id in 0..2 {
        super::ui_components::sync_feed_source_combo(
            &widgets.display_panes[monitor_id].feed_source_combo,
            state.feed_source_options(monitor_id),
            state.feed_source_preset(monitor_id),
        );
        if state.feed_source_preset(monitor_id) != FeedSourcePreset::Off {
            let choice = state
                .display_capture_size_choice(monitor_id)
                .unwrap_or_else(|| state.capture_size_choice(monitor_id));
            if state.feed_source_preset(monitor_id) == FeedSourcePreset::ThisEye {
                super::ui_components::sync_capture_resolution_combo(
                    &widgets.display_panes[monitor_id].capture_resolution_combo,
                    state.capture_size_options(),
                    state.capture_size_preset(monitor_id),
                );
            } else {
                super::ui_components::sync_capture_resolution_locked(
                    &widgets.display_panes[monitor_id].capture_resolution_combo,
                    state.capture_size_options(),
                    choice.preset,
                );
            }
        } else {
            super::ui_components::sync_capture_resolution_disabled(
                &widgets.display_panes[monitor_id].capture_resolution_combo,
            );
        }
        super::ui_components::sync_breakout_size_combo(
            &widgets.display_panes[monitor_id].breakout_combo,
            state.breakout_size_options(monitor_id),
            state.breakout_size_preset(monitor_id),
        );
        refresh_preview_frame_ratio(widgets, monitor_id, state);
    }
}

#[cfg(not(coverage))]
fn refresh_preview_frame_ratio(
    widgets: &super::ui_components::LauncherWidgets,
    monitor_id: usize,
    state: &LauncherState,
) {
    let capture = state
        .display_capture_size_choice(monitor_id)
        .unwrap_or_else(|| state.capture_size_choice(monitor_id));
    widgets.display_panes[monitor_id]
        .preview_frame
        .set_ratio(capture.preset.display_aspect_ratio());
}

#[cfg(not(coverage))]
fn eye_caps_changed(state: &LauncherState, caps: &crate::handshake::PeerCaps) -> bool {
    let next_width = caps.eye_width.unwrap_or(state.preview_source.width);
    let next_height = caps.eye_height.unwrap_or(state.preview_source.height);
    let next_fps = caps.eye_fps.unwrap_or(state.preview_source.fps);
    state.preview_source.width != next_width
        || state.preview_source.height != next_height
        || state.preview_source.fps != next_fps
}

#[cfg(not(coverage))]
fn record_diagnostics_sample(
    widgets: &super::ui_components::LauncherWidgets,
    state: &LauncherState,
    preview: Option<&super::preview::LauncherPreview>,
    uplink: Option<&crate::uplink_telemetry::UplinkTelemetrySnapshot>,
    network: NetworkSnapshot,
    client_process_cpu_pct: f32,
) {
    let left_metrics = preview
        .and_then(|preview| {
            (state.feed_source_preset(0) != FeedSourcePreset::Off).then_some(
                preview.snapshot_metrics(
                    0,
                    match state.display_surface(0) {
                        DisplaySurface::Preview => super::preview::PreviewSurface::Inline,
                        DisplaySurface::Window => super::preview::PreviewSurface::Window,
                    },
                ),
            )
        })
        .flatten()
        .unwrap_or_default();
    let right_metrics = preview
        .and_then(|preview| {
            (state.feed_source_preset(1) != FeedSourcePreset::Off).then_some(
                preview.snapshot_metrics(
                    1,
                    match state.display_surface(1) {
                        DisplaySurface::Preview => super::preview::PreviewSurface::Inline,
                        DisplaySurface::Window => super::preview::PreviewSurface::Window,
                    },
                ),
            )
        })
        .flatten()
        .unwrap_or_default();

    widgets
        .diagnostics_log
        .borrow_mut()
        .record(PerformanceSample {
            rtt_ms: network.rtt_ms,
            probe_spread_ms: network.probe_spread_ms,
            input_latency_ms: network.rtt_ms * 0.5,
            probe_loss_pct: network.probe_loss_pct,
            client_process_cpu_pct,
            server_process_cpu_pct: left_metrics
                .server_process_cpu_pct
                .max(right_metrics.server_process_cpu_pct),
            video_loss_pct: left_metrics
                .packet_loss_pct
                .max(right_metrics.packet_loss_pct),
            left_receive_fps: left_metrics.receive_fps,
            left_present_fps: left_metrics.present_fps,
            left_server_fps: left_metrics.server_fps,
            left_stream_spread_ms: left_metrics.stream_spread_ms,
            left_packet_gap_peak_ms: left_metrics.packet_gap_peak_ms,
            left_present_gap_peak_ms: left_metrics.present_gap_peak_ms,
            left_queue_depth: left_metrics.queue_depth,
            left_queue_peak: left_metrics.queue_depth_peak,
            left_server_source_gap_peak_ms: left_metrics.server_source_gap_peak_ms,
            left_server_send_gap_peak_ms: left_metrics.server_send_gap_peak_ms,
            left_server_queue_peak: left_metrics.server_queue_peak,
            left_server_encoder_label: left_metrics.server_encoder_label.clone(),
            left_decoder_label: left_metrics.decoder_label.clone(),
            left_stream_caps_label: left_metrics.stream_caps_label.clone(),
            left_decoded_caps_label: left_metrics.decoded_caps_label.clone(),
            left_rendered_caps_label: left_metrics.rendered_caps_label.clone(),
            right_receive_fps: right_metrics.receive_fps,
            right_present_fps: right_metrics.present_fps,
            right_server_fps: right_metrics.server_fps,
            right_stream_spread_ms: right_metrics.stream_spread_ms,
            right_packet_gap_peak_ms: right_metrics.packet_gap_peak_ms,
            right_present_gap_peak_ms: right_metrics.present_gap_peak_ms,
            right_queue_depth: right_metrics.queue_depth,
            right_queue_peak: right_metrics.queue_depth_peak,
            right_server_source_gap_peak_ms: right_metrics.server_source_gap_peak_ms,
            right_server_send_gap_peak_ms: right_metrics.server_send_gap_peak_ms,
            right_server_queue_peak: right_metrics.server_queue_peak,
            right_server_encoder_label: right_metrics.server_encoder_label.clone(),
            right_decoder_label: right_metrics.decoder_label.clone(),
            right_stream_caps_label: right_metrics.stream_caps_label.clone(),
            right_decoded_caps_label: right_metrics.decoded_caps_label.clone(),
            right_rendered_caps_label: right_metrics.rendered_caps_label.clone(),
            upstream_camera: uplink.map(|snapshot| snapshot.camera.clone()).unwrap_or_default(),
            upstream_microphone: uplink
                .map(|snapshot| snapshot.microphone.clone())
                .unwrap_or_default(),
            upstream_mode: uplink
                .map(|snapshot| snapshot.upstream_mode.clone())
                .filter(|mode| !mode.trim().is_empty())
                .unwrap_or_else(|| "unknown".to_string()),
            dropped_frames: left_metrics
                .dropped_frames
                .saturating_add(right_metrics.dropped_frames),
            queue_depth: left_metrics.queue_depth.max(right_metrics.queue_depth),
        });
}
