Skip to main content

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::event_loop::ServoShellEventLoop;
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
16    // TODO: once log-panics is released, can this be replaced by
17    // log_panics::init()?
18    panic::set_hook(Box::new(panic_hook::panic_hook));
19
20    // Skip the first argument, which is the binary name.
21    let args: Vec<String> = env::args().skip(1).collect();
22    let (opts, preferences, servoshell_preferences) = match parse_command_line_arguments(&*args) {
23        #[cfg(not(feature = "multiprocess"))]
24        ArgumentParsingResult::ContentProcess(_) => {
25            log::error!("IPC not enabled, cannot use contentprocesses");
26            return;
27        },
28        #[cfg(feature = "multiprocess")]
29        ArgumentParsingResult::ContentProcess(token) => {
30            return servo::run_content_process(token);
31        },
32        ArgumentParsingResult::ChromeProcess(opts, preferences, servoshell_preferences) => {
33            (opts, preferences, servoshell_preferences)
34        },
35        ArgumentParsingResult::Exit => {
36            std::process::exit(0);
37        },
38        ArgumentParsingResult::ErrorParsing => {
39            std::process::exit(1);
40        },
41    };
42
43    crate::init_tracing(servoshell_preferences.tracing_filter.as_deref());
44
45    let clean_shutdown = servoshell_preferences.clean_shutdown;
46    let event_loop = match servoshell_preferences.headless {
47        true => ServoShellEventLoop::headless(),
48        false => ServoShellEventLoop::headed(),
49    };
50
51    {
52        let mut app = App::new(opts, preferences, servoshell_preferences, &event_loop);
53        event_loop.run_app(&mut app);
54    }
55
56    crate::platform::deinit(clean_shutdown)
57}