{
            {
                let state = Rc::clone(&state);
                let catalog = Rc::clone(&catalog);
                let widgets = widgets.clone();
                let child_proc = Rc::clone(&child_proc);
                let tests = Rc::clone(&tests);
                let camera_quality_syncing = Rc::clone(&camera_quality_syncing);
                let camera_combo = camera_combo.clone();
                let camera_quality_combo = camera_quality_combo.clone();
                let camera_combo_read = camera_combo.clone();
                camera_combo.connect_changed(move |_| {
                    let selected = selected_combo_value(&camera_combo_read);
                    let preview_was_running =
                        tests.borrow_mut().is_running(DeviceTestKind::Camera);
                    {
                        let catalog = catalog.borrow();
                        let mut state = state.borrow_mut();
                        state.select_camera(selected.clone());
                        camera_quality_syncing.set(true);
                        sync_camera_quality_selection(&camera_quality_combo, &mut state, &catalog);
                        camera_quality_syncing.set(false);
                    }
                    let quality = state.borrow().camera_quality;
                    if let Err(err) = tests.borrow_mut().set_camera_selection(selected.as_deref()) {
                        widgets
                            .status_label
                            .set_text(&format!("Camera preview update failed: {err}"));
                    } else if let Err(err) = tests.borrow_mut().set_camera_quality(quality) {
                        widgets
                            .status_label
                            .set_text(&format!("Camera quality update failed: {err}"));
                    } else if child_proc.borrow().is_some() {
                        apply_live_media_device_change(
                            &state.borrow(),
                            &widgets,
                            &child_proc,
                            "Camera",
                        );
                    } else if preview_was_running {
                        widgets.status_label.set_text(&format!(
                            "Local camera preview switched to {}{}.",
                            selected.as_deref().unwrap_or("no camera"),
                            quality
                                .map(|mode| format!(" at {}", mode.short_label()))
                                .unwrap_or_default()
                        ));
                    }
                    refresh_launcher_ui(&widgets, &state.borrow(), child_proc.borrow().is_some());
                    refresh_test_buttons(&widgets, &mut tests.borrow_mut());
                });
            }

            {
                let state = Rc::clone(&state);
                let widgets = widgets.clone();
                let child_proc = Rc::clone(&child_proc);
                let transport_combo = widgets.webcam_transport_combo.clone();
                let transport_combo_read = transport_combo.clone();
                transport_combo.connect_changed(move |_| {
                    if widgets.webcam_transport_syncing.get() {
                        return;
                    }
                    let selected = transport_combo_read
                        .active_id()
                        .as_deref()
                        .and_then(WebcamTransport::from_id)
                        .unwrap_or_default();
                    let Ok(mut state_mut) = state.try_borrow_mut() else {
                        return;
                    };
                    state_mut.select_webcam_transport(selected);
                    drop(state_mut);
                    let relay_live = child_proc.borrow().is_some();
                    if relay_live {
                        if let Ok(state_ref) = state.try_borrow() {
                            apply_live_media_device_change(
                                &state_ref,
                                &widgets,
                                &child_proc,
                                "Webcam transport",
                            );
                        }
                    } else {
                        widgets.status_label.set_text(&format!(
                            "Webcam transport set to {} for the next relay launch.",
                            selected.label()
                        ));
                    }
                    if let Ok(state_ref) = state.try_borrow() {
                        refresh_launcher_ui(&widgets, &state_ref, relay_live);
                    }
                });
            }

            {
                let state = Rc::clone(&state);
                let widgets = widgets.clone();
                let child_proc = Rc::clone(&child_proc);
                let audio_combo = widgets.upstream_audio_transport_combo.clone();
                let audio_combo_read = audio_combo.clone();
                audio_combo.connect_changed(move |_| {
                    if widgets.upstream_audio_transport_syncing.get() {
                        return;
                    }
                    let selected = audio_combo_read
                        .active_id()
                        .as_deref()
                        .and_then(UpstreamAudioTransport::from_id)
                        .unwrap_or_default();
                    let Ok(mut state_mut) = state.try_borrow_mut() else {
                        return;
                    };
                    state_mut.select_upstream_audio_transport(selected);
                    drop(state_mut);
                    let relay_live = child_proc.borrow().is_some();
                    if relay_live {
                        if let Ok(state_ref) = state.try_borrow() {
                            apply_live_media_device_change(
                                &state_ref,
                                &widgets,
                                &child_proc,
                                "Microphone transport",
                            );
                        }
                    } else {
                        widgets.status_label.set_text(&format!(
                            "Upstream microphone transport set to {} for the next relay launch.",
                            selected.label()
                        ));
                    }
                    if let Ok(state_ref) = state.try_borrow() {
                        refresh_launcher_ui(&widgets, &state_ref, relay_live);
                    }
                });
            }

            {
                let state = Rc::clone(&state);
                let widgets = widgets.clone();
                let child_proc = Rc::clone(&child_proc);
                let tests = Rc::clone(&tests);
                let camera_quality_syncing = Rc::clone(&camera_quality_syncing);
                let camera_quality_combo = camera_quality_combo.clone();
                let camera_quality_combo_read = camera_quality_combo.clone();
                camera_quality_combo.connect_changed(move |_| {
                    if camera_quality_syncing.get() {
                        return;
                    }
                    let selected = selected_camera_quality(&camera_quality_combo_read);
                    let preview_was_running =
                        tests.borrow_mut().is_running(DeviceTestKind::Camera);
                    let Ok(mut state_mut) = state.try_borrow_mut() else {
                        return;
                    };
                    state_mut.select_camera_quality(selected);
                    drop(state_mut);
                    if let Err(err) = tests.borrow_mut().set_camera_quality(selected) {
                        widgets
                            .status_label
                            .set_text(&format!("Camera quality update failed: {err}"));
                    } else if child_proc.borrow().is_some() {
                        apply_live_media_device_change(
                            &state.borrow(),
                            &widgets,
                            &child_proc,
                            "Camera quality",
                        );
                    } else if preview_was_running {
                        widgets.status_label.set_text(&format!(
                            "Local camera preview switched to {}.",
                            selected
                                .map(CameraMode::short_label)
                                .unwrap_or_else(|| "default quality".to_string())
                        ));
                    }
                    refresh_launcher_ui(&widgets, &state.borrow(), child_proc.borrow().is_some());
                    refresh_test_buttons(&widgets, &mut tests.borrow_mut());
                });
            }

            {
                let state = Rc::clone(&state);
                let widgets = widgets.clone();
                let child_proc = Rc::clone(&child_proc);
                let keyboard_combo = keyboard_combo.clone();
                let keyboard_combo_read = keyboard_combo.clone();
                keyboard_combo.connect_changed(move |_| {
                    let selected = selected_combo_value(&keyboard_combo_read);
                    state.borrow_mut().select_keyboard(selected.clone());
                    let message = match selected.as_deref() {
                        Some(path) => {
                            format!("The next relay launch will listen only to keyboard {path}.")
                        }
                        None => "The next relay launch will listen to all keyboards.".to_string(),
                    };
                    widgets.status_label.set_text(&message);
                    refresh_launcher_ui(&widgets, &state.borrow(), child_proc.borrow().is_some());
                });
            }

            {
                let state = Rc::clone(&state);
                let widgets = widgets.clone();
                let child_proc = Rc::clone(&child_proc);
                let mouse_combo = mouse_combo.clone();
                let mouse_combo_read = mouse_combo.clone();
                mouse_combo.connect_changed(move |_| {
                    let selected = selected_combo_value(&mouse_combo_read);
                    state.borrow_mut().select_mouse(selected.clone());
                    let message = match selected.as_deref() {
                        Some(path) => {
                            format!("The next relay launch will listen only to pointer {path}.")
                        }
                        None => {
                            "The next relay launch will listen to all pointer devices."
                                .to_string()
                        }
                    };
                    widgets.status_label.set_text(&message);
                    refresh_launcher_ui(&widgets, &state.borrow(), child_proc.borrow().is_some());
                });
            }

            if let Some(preview) = preview.as_ref() {
                preview.set_session_active(false);
            }
            request_capture_power_refresh(
                power_tx.clone(),
                selected_server_addr(&server_entry, server_addr.as_ref()),
                Duration::ZERO,
            );
            caps_request_in_flight.set(true);
            request_handshake_caps(
                caps_tx.clone(),
                selected_server_addr(&server_entry, server_addr.as_ref()),
                Duration::ZERO,
            );

            {
                let state = Rc::clone(&state);
                let child_proc = Rc::clone(&child_proc);
                let widgets = widgets.clone();
                let server_entry = server_entry.clone();
                let server_entry_read = server_entry.clone();
                let server_addr_fallback = Rc::clone(&server_addr);
                let preview = preview.clone();
                let power_tx = power_tx.clone();
                let caps_tx = caps_tx.clone();
                let caps_request_in_flight = Rc::clone(&caps_request_in_flight);
                server_entry.connect_changed(move |_| {
                    let server_addr =
                        selected_server_addr(&server_entry_read, server_addr_fallback.as_ref());
                    {
                        let mut state = state.borrow_mut();
                        state.set_server_available(false);
                        state.set_server_version(None);
                        state.set_server_media_caps(None, None, None, None);
                        state.set_capture_power(CapturePowerStatus::default());
                    }
                    if let Some(preview) = preview.as_ref() {
                        preview.set_server_addr(server_addr.clone());
                    }
                    refresh_launcher_ui(&widgets, &state.borrow(), child_proc.borrow().is_some());
                    request_capture_power_refresh(
                        power_tx.clone(),
                        server_addr.clone(),
                        Duration::from_millis(150),
                    );
                    caps_request_in_flight.set(true);
                    request_handshake_caps(caps_tx.clone(), server_addr, Duration::from_millis(150));
                });
            }
}
