Repository: servo/servo
File: ports/servoshell/egl/app.rs (Rust)

Code before:

pub(crate) struct AppInitOptions {
    pub host: Box<dyn HostTrait>,
    pub event_loop_waker: Box<dyn EventLoopWaker>,
    pub viewport_rect: Rect<i32, DevicePixel>,
    pub hidpi_scale_factor: f32,
    pub rendering_context: Rc<WindowRenderingContext>,
    pub refresh_driver: Rc<VsyncRefreshDriver>,
    pub initial_url: Option<String>,
    pub opts: Opts,
    pub preferences: Preferences,
    pub servoshell_preferences: ServoShellPreferences,
    #[cfg(feature = "webxr")]
    pub xr_discovery: Option<servo::webxr::Discovery>,
}

pub struct App {
    state: Rc<RunningAppState>,
    platform_window: Rc<EmbeddedPlatformWindow>,
}

#[allow(unused)]
impl App {
    pub(super) fn new(init: AppInitOptions) -> Rc<Self> {
        #[cfg(feature = "gamepad")]
        let gamepad_provider = Rc::new(ServoshellGamepadProvider::new());

        let servo_builder = ServoBuilder::default()
            .opts(init.opts)
            .preferences(init.preferences)
            .event_loop_waker(init.event_loop_waker.clone());

        #[cfg(feature = "gamepad")]
        let servo_builder = servo_builder.gamepad_provider(gamepad_provider.clone());

        #[cfg(feature = "webxr")]
        let servo_builder = servo_builder
            .webxr_registry(Box::new(XrDiscoveryWebXrRegistry::new(init.xr_discovery)));
        let servo = servo_builder.build();

        let initial_url = init.initial_url.and_then(|string| Url::parse(&string).ok());
        let initial_url = initial_url
            .or_else(|| Url::parse(&init.servoshell_preferences.homepage).ok())
            .or_else(|| Url::parse("about:blank").ok())
            .expect("Failed to parse initial URL");

        let user_content_manager = Rc::new(UserContentManager::new(&servo));
        let state = Rc::new(RunningAppState::new(
            servo,
            init.servoshell_preferences,
            init.event_loop_waker,

Review comment (suggestion):
I think you can avoid this as there is no gamepad support for EGL as of yet. You can just remove the dummy `ServoshellGamepadProvider` for EGL as well.

Code after:
            .push(new_start_frame_callback);
    }
}

pub(crate) struct AppInitOptions {
    pub host: Rc<dyn HostTrait>,
    pub event_loop_waker: Box<dyn EventLoopWaker>,
    pub initial_url: Option<String>,
    pub opts: Opts,
    pub preferences: Preferences,
    pub servoshell_preferences: ServoShellPreferences,
    #[cfg(feature = "webxr")]
    pub xr_discovery: Option<servo::webxr::Discovery>,
}

pub struct App {
    state: Rc<RunningAppState>,
    // TODO: multi-window support, like desktop version.
    // This is just an intermediate state, to split refactoring into
    // multiple PRs.
    host: Rc<dyn HostTrait>,
    initial_url: Url,
}

#[expect(unused)]
impl App {
    pub(super) fn new(init: AppInitOptions) -> Rc<Self> {
        let mut servo_builder = ServoBuilder::default()
            .opts(init.opts)
            .preferences(init.preferences.clone())
            .event_loop_waker(init.event_loop_waker.clone());
        #[cfg(feature = "webxr")]
        let servo_builder = servo_builder
            .webxr_registry(Box::new(XrDiscoveryWebXrRegistry::new(init.xr_discovery)));
        let servo = servo_builder.build();

        let initial_url = init.initial_url.and_then(|string| Url::parse(&string).ok());
        let initial_url = initial_url
            .or_else(|| Url::parse(&init.servoshell_preferences.homepage).ok())
            .or_else(|| Url::parse("about:blank").ok())
            .expect("Failed to parse initial URL");

        let user_content_manager = Rc::new(UserContentManager::new(&servo));
        let state = Rc::new(RunningAppState::new(
            servo,
            init.servoshell_preferences,
            init.event_loop_waker,
            user_content_manager,
            init.preferences,
        ));