{
    let left_pane = left_pane;
    let right_pane = right_pane;
    if let Some(preview) = preview.as_ref() {
        *left_pane.preview_binding.borrow_mut() =
            if state.feed_source_preset(0) == FeedSourcePreset::Off {
                None
            } else {
                preview.install_on_picture(
                    0,
                    PreviewSurface::Inline,
                    &left_pane.picture,
                    &left_pane.stream_status,
                )
            };
        *right_pane.preview_binding.borrow_mut() =
            if state.feed_source_preset(1) == FeedSourcePreset::Off {
                None
            } else {
                preview.install_on_picture(
                    1,
                    PreviewSurface::Inline,
                    &right_pane.picture,
                    &right_pane.stream_status,
                )
            };
    } else {
        left_pane.stream_status.set_text("Preview unavailable");
        left_pane.preview_placeholder.set_visible(true);
        right_pane.stream_status.set_text("Preview unavailable");
        right_pane.preview_placeholder.set_visible(true);
    }
    sync_feed_source_combo(
        &left_pane.feed_source_combo,
        state.feed_source_options(0),
        state.feed_source_preset(0),
    );
    sync_feed_source_combo(
        &right_pane.feed_source_combo,
        state.feed_source_options(1),
        state.feed_source_preset(1),
    );
    if state.feed_source_preset(0) != FeedSourcePreset::Off {
        let choice = state
            .display_capture_size_choice(0)
            .unwrap_or_else(|| state.capture_size_choice(0));
        if state.feed_source_preset(0) == FeedSourcePreset::ThisEye {
            sync_capture_resolution_combo(
                &left_pane.capture_resolution_combo,
                state.capture_size_options(),
                state.capture_size_preset(0),
            );
        } else {
            sync_capture_resolution_locked(
                &left_pane.capture_resolution_combo,
                state.capture_size_options(),
                choice.preset,
            );
        }
    } else {
        sync_capture_resolution_disabled(&left_pane.capture_resolution_combo);
    }
    if state.feed_source_preset(1) != FeedSourcePreset::Off {
        let choice = state
            .display_capture_size_choice(1)
            .unwrap_or_else(|| state.capture_size_choice(1));
        if state.feed_source_preset(1) == FeedSourcePreset::ThisEye {
            sync_capture_resolution_combo(
                &right_pane.capture_resolution_combo,
                state.capture_size_options(),
                state.capture_size_preset(1),
            );
        } else {
            sync_capture_resolution_locked(
                &right_pane.capture_resolution_combo,
                state.capture_size_options(),
                choice.preset,
            );
        }
    } else {
        sync_capture_resolution_disabled(&right_pane.capture_resolution_combo);
    }
    sync_breakout_size_combo(
        &left_pane.breakout_combo,
        state.breakout_size_options(0),
        state.breakout_size_preset(0),
    );
    sync_breakout_size_combo(
        &right_pane.breakout_combo,
        state.breakout_size_options(1),
        state.breakout_size_preset(1),
    );
    let diagnostics_popout_label = Rc::new(RefCell::new(None));
    let diagnostics_popout_scroll = Rc::new(RefCell::new(None));

    let widgets = LauncherWidgets {
        status_label: status_label.clone(),
        diagnostics_log: diagnostics_log.clone(),
        diagnostics_label: diagnostics_label.clone(),
        diagnostics_scroll: diagnostics_scroll.clone(),
        diagnostics_popout_label: diagnostics_popout_label.clone(),
        diagnostics_popout_scroll: diagnostics_popout_scroll.clone(),
        diagnostics_rendered_text: Rc::new(RefCell::new(String::new())),
        session_log_buffer: session_log_buffer.clone(),
        session_log_view: session_log_view.clone(),
        summary: SummaryWidgets {
            relay_light,
            relay_value,
            routing_light,
            routing_value,
            gpio_light,
            gpio_value,
            left_eye_light,
            left_eye_value,
            right_eye_light,
            right_eye_value,
            usb_light,
            usb_value,
            uac_light,
            uac_value,
            uvc_light,
            uvc_value,
            upstream_lag_light,
            upstream_lag_value,
            shortcut_value,
        },
        power_detail,
        audio_check_detail,
        audio_check_meter,
        display_panes: [left_pane.clone(), right_pane.clone()],
        server_entry: server_entry.clone(),
        start_button: start_button.clone(),
        certs_button: certs_button.clone(),
        camera_combo: camera_combo.clone(),
        camera_quality_combo: camera_quality_combo.clone(),
        microphone_combo: microphone_combo.clone(),
        speaker_combo: speaker_combo.clone(),
        keyboard_combo: keyboard_combo.clone(),
        mouse_combo: mouse_combo.clone(),
        camera_channel_toggle: camera_channel_toggle.clone(),
        microphone_channel_toggle: microphone_channel_toggle.clone(),
        noise_suppression_toggle: noise_suppression_toggle.clone(),
        audio_channel_toggle: audio_channel_toggle.clone(),
        power_auto_button: power_auto_button.clone(),
        power_on_button: power_on_button.clone(),
        power_off_button: power_off_button.clone(),
        audio_gain_scale: audio_gain_scale.clone(),
        audio_gain_value: audio_gain_value.clone(),
        mic_gain_scale: mic_gain_scale.clone(),
        mic_gain_value: mic_gain_value.clone(),
        input_toggle_button: input_toggle_button.clone(),
        clipboard_button: clipboard_button.clone(),
        wake_combo: wake_combo.clone(),
        usb_recover_button: usb_recover_button.clone(),
        uac_recover_button: uac_recover_button.clone(),
        uvc_recover_button: uvc_recover_button.clone(),
        calibration_default_button: calibration_default_button.clone(),
        calibration_factory_button: calibration_factory_button.clone(),
        calibration_blind_button: calibration_blind_button.clone(),
        calibration_minus_button: calibration_minus_button.clone(),
        calibration_plus_button: calibration_plus_button.clone(),
        calibration_rig_button: calibration_rig_button.clone(),
        device_refresh_button: device_refresh_button.clone(),
        swap_key_button: swap_key_button.clone(),
        camera_test_button: camera_test_button.clone(),
        camera_preview_stack: camera_preview_stack.clone(),
        webcam_transport_combo: webcam_transport_combo.clone(),
        webcam_transport_syncing: Rc::new(Cell::new(false)),
        upstream_audio_transport_combo: upstream_audio_transport_combo.clone(),
        upstream_audio_transport_syncing: Rc::new(Cell::new(false)),
        camera_mirror_button: camera_mirror_button.clone(),
        camera_mirror_revealer: camera_mirror_revealer.clone(),
        microphone_test_button: microphone_test_button.clone(),
        microphone_replay_button: microphone_replay_button.clone(),
        speaker_test_button: speaker_test_button.clone(),
        diagnostics_copy_button: diagnostics_copy_button.clone(),
        diagnostics_popout_button: diagnostics_popout_button.clone(),
        console_copy_button: console_copy_button.clone(),
        console_popout_button: console_popout_button.clone(),
        console_level_combo: console_level_combo.clone(),
        session_log_level: session_log_level.clone(),
    };
    let popouts = Rc::new(RefCell::new([None, None]));
    let diagnostics_popout = Rc::new(RefCell::new(None));
    let log_popout = Rc::new(RefCell::new(None));

    super::ui_runtime::refresh_diagnostics_report(&widgets, state, false);

    window.set_child(Some(&root));

    LauncherView {
        window,
        server_entry,
        camera_combo,
        camera_quality_combo,
        microphone_combo,
        speaker_combo,
        keyboard_combo,
        mouse_combo,
        device_stage: DeviceStageWidgets {
            devices_panel,
            preview_panel,
            camera_preview_stack,
            camera_preview_frame,
            camera_preview,
            webcam_transport_combo,
            upstream_audio_transport_combo,
            camera_mirror_button,
            camera_status,
        },
        widgets,
        preview,
        popouts,
        diagnostics_popout,
        log_popout,
    }
}
