{
            {
                let state = Rc::clone(&state);
                let catalog_state = Rc::clone(&catalog);
                let widgets = widgets.clone();
                let widgets_handle = widgets.clone();
                let child_proc = Rc::clone(&child_proc);
                let tests = Rc::clone(&tests);
                let camera_combo = camera_combo.clone();
                let camera_quality_combo = camera_quality_combo.clone();
                let microphone_combo = microphone_combo.clone();
                let speaker_combo = speaker_combo.clone();
                let keyboard_combo = keyboard_combo.clone();
                let mouse_combo = mouse_combo.clone();
                let camera_quality_syncing = Rc::clone(&camera_quality_syncing);
                widgets.device_refresh_button.connect_clicked(move |_| {
                    let fresh_catalog = DeviceCatalog::discover();
                    let (
                        selected_camera,
                        selected_microphone,
                        selected_speaker,
                        selected_keyboard,
                        selected_mouse,
                    ) = {
                        let state = state.borrow();
                        (
                            retained_stage_selection(
                                state.devices.camera.as_deref(),
                                &fresh_catalog.cameras,
                            ),
                            retained_stage_selection(
                                state.devices.microphone.as_deref(),
                                &fresh_catalog.microphones,
                            ),
                            retained_stage_selection(
                                state.devices.speaker.as_deref(),
                                &fresh_catalog.speakers,
                            ),
                            retained_input_selection(
                                state.devices.keyboard.as_deref(),
                                &fresh_catalog.keyboards,
                            ),
                            retained_input_selection(
                                state.devices.mouse.as_deref(),
                                &fresh_catalog.mice,
                            ),
                        )
                    };
                    {
                        let mut state = state.borrow_mut();
                        state.select_camera(selected_camera);
                        camera_quality_syncing.set(true);
                        sync_camera_quality_selection(
                            &camera_quality_combo,
                            &mut state,
                            &fresh_catalog,
                        );
                        camera_quality_syncing.set(false);
                        state.select_microphone(selected_microphone);
                        state.select_speaker(selected_speaker);
                        state.select_keyboard(selected_keyboard);
                        state.select_mouse(selected_mouse);
                    }
                    *catalog_state.borrow_mut() = fresh_catalog.clone();
                    let state_snapshot = state.borrow().clone();
                    sync_stage_device_combo(
                        &camera_combo,
                        &fresh_catalog.cameras,
                        state_snapshot.devices.camera.as_deref(),
                    );
                    sync_stage_device_combo(
                        &microphone_combo,
                        &fresh_catalog.microphones,
                        state_snapshot.devices.microphone.as_deref(),
                    );
                    sync_stage_device_combo(
                        &speaker_combo,
                        &fresh_catalog.speakers,
                        state_snapshot.devices.speaker.as_deref(),
                    );
                    sync_input_device_combo(
                        &keyboard_combo,
                        &fresh_catalog.keyboards,
                        state_snapshot.devices.keyboard.as_deref(),
                        "all keyboards",
                    );
                    sync_input_device_combo(
                        &mouse_combo,
                        &fresh_catalog.mice,
                        state_snapshot.devices.mouse.as_deref(),
                        "all mice",
                    );
                    if let Err(err) = tests
                        .borrow_mut()
                        .set_camera_selection(state_snapshot.devices.camera.as_deref())
                    {
                        widgets_handle
                            .status_label
                            .set_text(&format!("Device refresh succeeded, but the webcam test could not switch cleanly: {err}"));
                    } else if let Err(err) =
                        tests.borrow_mut().set_camera_quality(state_snapshot.camera_quality)
                    {
                        widgets_handle.status_label.set_text(&format!(
                            "Device refresh succeeded, but the webcam quality test could not switch cleanly: {err}"
                        ));
                    } else {
                        let message = if usb_audio_kernel_support_missing() {
                            "Device staging refreshed. USB audio devices may still stay invisible until the host boots a kernel with snd_usb_audio available; reconnect the relay if you want the live session to use a new webcam, mic, or speaker."
                        } else {
                            "Device staging refreshed. Newly attached devices are ready for local tests; all-keyboard/all-mouse relay sessions will pick up new input devices automatically."
                        };
                        widgets_handle.status_label.set_text(message);
                    }
                    refresh_launcher_ui(
                        &widgets_handle,
                        &state.borrow(),
                        child_proc.borrow().is_some(),
                    );
                    refresh_test_buttons(&widgets_handle, &mut tests.borrow_mut());
                });
            }
}
