Skip to content

Commit

Permalink
Allow changing user agent through cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Legend-Master committed Nov 18, 2024
1 parent c638e3b commit 7e642ef
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use euclid::{vec2, Point2D, Scale, Size2D, Transform3D, Vector2D};
use gleam::gl;
use ipc_channel::ipc::{self, IpcSharedMemory};
use log::{debug, error, trace, warn};
use profile_traits::time::{self as profile_time, profile, ProfilerCategory};
use profile_traits::time::{self as profile_time, ProfilerCategory};
use profile_traits::{mem, time, time_profile};
use script_traits::CompositorEvent::{MouseButtonEvent, MouseMoveEvent, TouchEvent, WheelEvent};
use script_traits::{
Expand Down
15 changes: 13 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub struct CliArgs {
/// Path to resource directory. If None, Verso will try to get default directory. And if that
/// still doesn't exist, all resource configuration will set to default values.
pub resource_dir: Option<PathBuf>,
/// Override the user agent
pub user_agent: Option<String>,
}

/// Configuration of Verso instance.
Expand Down Expand Up @@ -91,6 +93,13 @@ fn parse_cli_args() -> Result<CliArgs, getopts::Fail> {
"out.html",
);

opts.optopt(
"",
"user-agent",
"Override the user agent",
"'VersoView/1.0'",
);

opts.optopt(
"w",
"width",
Expand Down Expand Up @@ -159,6 +168,8 @@ fn parse_cli_args() -> Result<CliArgs, getopts::Fail> {
None
};

let user_agent = matches.opt_str("user-agent");

let mut window_attributes = winit::window::Window::default_attributes();

let width = matches.opt_get::<u32>("width").unwrap_or_else(|e| {
Expand Down Expand Up @@ -216,12 +227,12 @@ fn parse_cli_args() -> Result<CliArgs, getopts::Fail> {
window_attributes,
devtools_port,
profiler_settings,
user_agent,
})
}

impl Config {
/// Create a new configuration for creating Verso instance. It must provide the path of
/// resources directory.
/// Create a new configuration for creating Verso instance.
pub fn new() -> Self {
let mut opts = default_opts();
let args = parse_cli_args().unwrap_or_default();
Expand Down
7 changes: 6 additions & 1 deletion src/verso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ impl Verso {
let initial_url = config.args.url.clone();
let with_panel = !config.args.no_panel;
let window_settings = config.args.window_attributes.clone();
let user_agent: Cow<'static, str> = config
.args
.user_agent
.clone()
.unwrap_or_else(|| default_user_agent_string().to_string())
.into();

config.init();
// Reserving a namespace to create TopLevelBrowsingContextId.
Expand Down Expand Up @@ -275,7 +281,6 @@ impl Verso {
BluetoothThreadFactory::new(embedder_sender.clone());

// Create resource thread pool
let user_agent: Cow<'static, str> = default_user_agent_string().into();
let (public_resource_threads, private_resource_threads) =
resource_thread::new_resource_threads(
user_agent.clone(),
Expand Down

0 comments on commit 7e642ef

Please sign in to comment.