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        ArgumentParsingResult::Exit => {
28            std::process::exit(0);
29        },
30        ArgumentParsingResult::ErrorParsing => {
31            std::process::exit(1);
32        },
33    };
34
35    crate::init_tracing(servoshell_preferences.tracing_filter.as_deref());
36
37    let clean_shutdown = servoshell_preferences.clean_shutdown;
38    let event_loop =
39        EventsLoop::new(servoshell_preferences.headless).expect("Failed to create events loop");
40
41    {
42        let mut app = App::new(opts, preferences, servoshell_preferences, &event_loop);
43        event_loop.run_app(&mut app);
44    }
45
46    crate::platform::deinit(clean_shutdown)
47}