mirror of
https://github.com/servo/servo.git
synced 2025-09-30 00:29:14 +01:00
api: Flatten and simplify Servo preferences (#34966)
Flatten and simplify Servo's preferences code. In addition, have both preferences and options passed in as arguments to `Servo::new()` and make sure not to use the globally set preferences in `servoshell` (as much as possible now). Instead of a complex procedural macro to generate preferences, just expose a very simple derive macro that adds string based getters and setters. - All command-line parsing is moved to servoshell. - There is no longer the concept of a missing preference. - Preferences no longer have to be part of the resources bundle because they now have reasonable default values. - servoshell specific preferences are no longer part of the preferences exposed by the Servo API. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
c4c85affb5
commit
0e616e0c5d
316 changed files with 2088 additions and 3235 deletions
|
@ -2,16 +2,12 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::{env, panic, process};
|
||||
|
||||
use getopts::Options;
|
||||
use log::error;
|
||||
use servo::config::opts::{self, ArgumentParsingResult};
|
||||
use servo::servo_config::pref;
|
||||
use std::{env, panic};
|
||||
|
||||
use crate::desktop::app::App;
|
||||
use crate::desktop::events_loop::EventsLoop;
|
||||
use crate::panic_hook;
|
||||
use crate::prefs::{parse_command_line_arguments, ArgumentParsingResult};
|
||||
|
||||
pub fn main() {
|
||||
crate::crash_handler::install();
|
||||
|
@ -19,98 +15,23 @@ pub fn main() {
|
|||
crate::init_crypto();
|
||||
crate::resources::init();
|
||||
|
||||
// Parse the command line options and store them globally
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let mut opts = Options::new();
|
||||
opts.optflag(
|
||||
"",
|
||||
"clean-shutdown",
|
||||
"Do not shutdown until all threads have finished (macos only)",
|
||||
);
|
||||
opts.optflag("b", "no-native-titlebar", "Do not use native titlebar");
|
||||
opts.optopt("", "device-pixel-ratio", "Device pixels per px", "");
|
||||
opts.optopt(
|
||||
"u",
|
||||
"user-agent",
|
||||
"Set custom user agent string (or ios / android / desktop for platform default)",
|
||||
"NCSA Mosaic/1.0 (X11;SunOS 4.1.4 sun4m)",
|
||||
);
|
||||
opts.optmulti(
|
||||
"",
|
||||
"pref",
|
||||
"A preference to set to enable",
|
||||
"dom.bluetooth.enabled",
|
||||
);
|
||||
opts.optmulti(
|
||||
"",
|
||||
"pref",
|
||||
"A preference to set to disable",
|
||||
"dom.webgpu.enabled=false",
|
||||
);
|
||||
opts.optmulti(
|
||||
"",
|
||||
"prefs-file",
|
||||
"Load in additional prefs from a file.",
|
||||
"--prefs-file /path/to/prefs.json",
|
||||
);
|
||||
|
||||
let opts_matches;
|
||||
let content_process_token;
|
||||
|
||||
match opts::from_cmdline_args(opts, &args) {
|
||||
ArgumentParsingResult::ContentProcess(matches, token) => {
|
||||
opts_matches = matches;
|
||||
content_process_token = Some(token);
|
||||
},
|
||||
ArgumentParsingResult::ChromeProcess(matches) => {
|
||||
opts_matches = matches;
|
||||
content_process_token = None;
|
||||
},
|
||||
};
|
||||
|
||||
crate::prefs::register_user_prefs(&opts_matches);
|
||||
|
||||
// TODO: once log-panics is released, can this be replaced by
|
||||
// log_panics::init()?
|
||||
panic::set_hook(Box::new(panic_hook::panic_hook));
|
||||
|
||||
if let Some(token) = content_process_token {
|
||||
return servo::run_content_process(token);
|
||||
}
|
||||
|
||||
if opts::get().is_printing_version {
|
||||
println!("{}", crate::servo_version());
|
||||
process::exit(0);
|
||||
}
|
||||
|
||||
let clean_shutdown = opts_matches.opt_present("clean-shutdown");
|
||||
let do_not_use_native_titlebar =
|
||||
opts_matches.opt_present("no-native-titlebar") || !(pref!(shell.native_titlebar.enabled));
|
||||
let device_pixel_ratio_override = opts_matches.opt_str("device-pixel-ratio").map(|dppx_str| {
|
||||
dppx_str.parse().unwrap_or_else(|err| {
|
||||
error!("Error parsing option: --device-pixel-ratio ({})", err);
|
||||
process::exit(1);
|
||||
})
|
||||
});
|
||||
|
||||
let user_agent = opts_matches.opt_str("u");
|
||||
|
||||
let url_opt = if !opts_matches.free.is_empty() {
|
||||
Some(&opts_matches.free[0][..])
|
||||
} else {
|
||||
None
|
||||
let args = env::args().collect();
|
||||
let (opts, preferences, servoshell_preferences) = match parse_command_line_arguments(args) {
|
||||
ArgumentParsingResult::ContentProcess(token) => return servo::run_content_process(token),
|
||||
ArgumentParsingResult::ChromeProcess(opts, preferences, servoshell_preferences) => {
|
||||
(opts, preferences, servoshell_preferences)
|
||||
},
|
||||
};
|
||||
|
||||
let event_loop = EventsLoop::new(opts::get().headless, opts::get().output_file.is_some())
|
||||
let clean_shutdown = servoshell_preferences.clean_shutdown;
|
||||
let event_loop = EventsLoop::new(opts.headless, opts.output_file.is_some())
|
||||
.expect("Failed to create events loop");
|
||||
|
||||
let mut app = App::new(
|
||||
&event_loop,
|
||||
user_agent,
|
||||
url_opt.map(|s| s.to_string()),
|
||||
do_not_use_native_titlebar,
|
||||
device_pixel_ratio_override,
|
||||
);
|
||||
let mut app = App::new(opts, preferences, servoshell_preferences, &event_loop);
|
||||
|
||||
event_loop.run_app(&mut app);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue