servoshell/desktop/
cli.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use std::{env, panic};
6
7use crate::desktop::app::App;
8use crate::desktop::events_loop::EventsLoop;
9use crate::panic_hook;
10use crate::prefs::{ArgumentParsingResult, parse_command_line_arguments};
11
12pub fn main() {
13    crate::crash_handler::install();
14    crate::init_crypto();
15    crate::resources::init();
16
17    // TODO: once log-panics is released, can this be replaced by
18    // log_panics::init()?
19    panic::set_hook(Box::new(panic_hook::panic_hook));
20
21    let args = env::args().collect();
22    let (opts, preferences, servoshell_preferences) = match parse_command_line_arguments(args) {
23        ArgumentParsingResult::ContentProcess(token) => return servo::run_content_process(token),
24        ArgumentParsingResult::ChromeProcess(opts, preferences, servoshell_preferences) => {
25            (opts, preferences, servoshell_preferences)
26        },
27    };
28
29    crate::init_tracing(servoshell_preferences.tracing_filter.as_deref());
30
31    let clean_shutdown = servoshell_preferences.clean_shutdown;
32    let has_output_file = servoshell_preferences.output_image_path.is_some();
33    let event_loop = EventsLoop::new(servoshell_preferences.headless, has_output_file)
34        .expect("Failed to create events loop");
35
36    {
37        let mut app = App::new(opts, preferences, servoshell_preferences, &event_loop);
38        event_loop.run_app(&mut app);
39    }
40
41    crate::platform::deinit(clean_shutdown)
42}