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

Code before:
        self.windows.insert(window.id(), window);

        let (_, window) = self.windows.iter().next().unwrap();

        let mut user_content_manager = UserContentManager::new();
        for script in load_userscripts(self.servoshell_preferences.userscripts_directory.as_deref())
            .expect("Loading userscripts failed")
        {
            user_content_manager.add_script(script);
        }

        let mut protocol_registry = ProtocolRegistry::default();
        let _ = protocol_registry.register(
            "urlinfo",
            protocols::urlinfo::UrlInfoProtocolHander::default(),
        );
        let _ =
            protocol_registry.register("servo", protocols::servo::ServoProtocolHandler::default());
        let _ = protocol_registry.register(
            "resource",
            protocols::resource::ResourceProtocolHandler::default(),
        );
        let _ = protocol_registry.register_page_content_handler(
            "mailto".to_owned(),
            "https://mail.proton.me/inbox/#mailto=%s".to_owned(),
        );

        let servo_builder = ServoBuilder::default()
            .opts(self.opts.clone())
            .preferences(self.preferences.clone())
            .user_content_manager(user_content_manager)
            .protocol_registry(protocol_registry)
            .event_loop_waker(self.waker.clone());

        #[cfg(feature = "webxr")]
        let servo_builder =
            servo_builder.webxr_registry(super::webxr::XrDiscoveryWebXrRegistry::new_boxed(
                window.clone(),
                event_loop,
                &self.preferences,
            ));

        let servo = servo_builder.build();
        servo.setup_logging();

        // Initialize WebDriver server here before `servo` is moved.
        let webdriver_receiver = self.servoshell_preferences.webdriver_port.map(|port| {
            let (embedder_sender, embedder_receiver) = unbounded();
            webdriver_server::start_server(port, embedder_sender, self.waker.clone());
            embedder_receiver
        });

Review comment (suggestion):
I'm not sure automatically registering a protocol handler to the Proton Mail service a good default for servoshell, which is the public-facing build of Servo.

Code after:

        let servo = servo_builder.build();
        servo.setup_logging();

        let running_state = Rc::new(RunningAppState::new(
            servo,
            self.servoshell_preferences.clone(),
            self.waker.clone(),
        ));
        running_state.create_window(platform_window, self.initial_url.as_url().clone());

        self.state = AppState::Running(running_state);
    }

    fn create_platform_window(
        &self,
        url: ServoUrl,
        active_event_loop: Option<&ActiveEventLoop>,
    ) -> Rc<dyn PlatformWindow> {
        assert_eq!(
            self.servoshell_preferences.headless,
            active_event_loop.is_none()
        );

        let Some(active_event_loop) = active_event_loop else {
            return headless_window::Window::new(&self.servoshell_preferences);
        };

        headed_window::Window::new(
            &self.servoshell_preferences,
            active_event_loop,
            self.event_loop_proxy
                .clone()
                .expect("Should always have event loop proxy in headed mode."),
            url,
        )
    }

    pub fn pump_servo_event_loop(&mut self) -> bool {
        let AppState::Running(state) = &self.state else {
            return false;
        };

        if !state.spin_event_loop() {
            self.state = AppState::ShuttingDown;
            return false;
        }
        true
    }
}