update
This commit is contained in:
@@ -14,6 +14,8 @@ use thiserror::Error;
|
||||
|
||||
#[path = "ely_servo_sidecar/args.rs"]
|
||||
mod args;
|
||||
#[path = "ely_servo_sidecar/live.rs"]
|
||||
mod live;
|
||||
#[path = "ely_servo_sidecar/report.rs"]
|
||||
mod report;
|
||||
|
||||
@@ -28,6 +30,7 @@ const INPUT_SETTLE_TIMEOUT: Duration = Duration::from_millis(700);
|
||||
|
||||
fn main() -> Result<(), SidecarError> {
|
||||
match args::parse_env_command()? {
|
||||
SidecarCommand::Live(args) => live::run_live(args).map_err(SidecarError::Live),
|
||||
SidecarCommand::Snapshot(args) => run_snapshot(args),
|
||||
}
|
||||
}
|
||||
@@ -43,6 +46,9 @@ enum SidecarError {
|
||||
#[error(transparent)]
|
||||
Host(#[from] ServoHostError),
|
||||
|
||||
#[error(transparent)]
|
||||
Live(#[from] live::LiveSidecarError),
|
||||
|
||||
#[error(transparent)]
|
||||
Io(#[from] std::io::Error),
|
||||
|
||||
|
||||
@@ -8,9 +8,14 @@ use serde::Deserialize;
|
||||
use thiserror::Error;
|
||||
|
||||
pub(super) enum SidecarCommand {
|
||||
Live(LiveArgs),
|
||||
Snapshot(SnapshotArgs),
|
||||
}
|
||||
|
||||
pub(super) struct LiveArgs {
|
||||
pub(super) profile_data_dir: PathBuf,
|
||||
}
|
||||
|
||||
pub(super) struct SnapshotArgs {
|
||||
pub(super) url: UrlText,
|
||||
pub(super) profile_id: ProfileId,
|
||||
@@ -109,11 +114,34 @@ fn parse_command(
|
||||
let command = args.next().ok_or(SidecarArgsError::MissingCommand)?;
|
||||
|
||||
match command.as_str() {
|
||||
"live" => parse_live_args(args).map(SidecarCommand::Live),
|
||||
"snapshot" => parse_snapshot_args(args).map(SidecarCommand::Snapshot),
|
||||
_ => Err(SidecarArgsError::UnknownCommand { value: command }),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_live_args(args: impl IntoIterator<Item = String>) -> Result<LiveArgs, SidecarArgsError> {
|
||||
let mut args = args.into_iter();
|
||||
let mut profile_data_dir = None;
|
||||
|
||||
while let Some(name) = args.next() {
|
||||
match name.as_str() {
|
||||
"--profile-data-dir" => {
|
||||
profile_data_dir = Some(parse_path(
|
||||
"--profile-data-dir",
|
||||
next_argument(&mut args, "--profile-data-dir")?,
|
||||
)?)
|
||||
}
|
||||
_ => return Err(SidecarArgsError::UnknownArgument { value: name }),
|
||||
}
|
||||
}
|
||||
|
||||
Ok(LiveArgs {
|
||||
profile_data_dir: profile_data_dir
|
||||
.ok_or(SidecarArgsError::MissingRequiredArgument { name: "--profile-data-dir" })?,
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_snapshot_args(
|
||||
args: impl IntoIterator<Item = String>,
|
||||
) -> Result<SnapshotArgs, SidecarArgsError> {
|
||||
@@ -344,9 +372,8 @@ mod tests {
|
||||
fn parses_snapshot_profile_identity() -> Result<(), SidecarArgsError> {
|
||||
let profile_id = ProfileId::new();
|
||||
let profile_data_dir = env::temp_dir().join(profile_id.as_str());
|
||||
let command = parse_snapshot_command(&profile_id, profile_data_dir.clone())?;
|
||||
let args = parse_snapshot_command(&profile_id, profile_data_dir.clone())?;
|
||||
|
||||
let SidecarCommand::Snapshot(args) = command;
|
||||
assert_eq!(args.profile_id, profile_id);
|
||||
assert_eq!(args.profile_data_dir, profile_data_dir);
|
||||
assert_eq!(args.page_zoom_percent, DEFAULT_ZOOM_PERCENT);
|
||||
@@ -393,7 +420,7 @@ mod tests {
|
||||
.to_string(),
|
||||
);
|
||||
|
||||
let SidecarCommand::Snapshot(args) = parse_command(command)?;
|
||||
let args = snapshot_args(parse_command(command)?);
|
||||
assert_eq!(args.site_permissions.len(), 1);
|
||||
let permission = &args.site_permissions[0];
|
||||
assert_eq!(permission.origin.as_str(), "https://example.com");
|
||||
@@ -410,7 +437,7 @@ mod tests {
|
||||
command.push("--page-zoom-percent".to_string());
|
||||
command.push("125".to_string());
|
||||
|
||||
let SidecarCommand::Snapshot(args) = parse_command(command)?;
|
||||
let args = snapshot_args(parse_command(command)?);
|
||||
assert_eq!(args.page_zoom_percent, 125);
|
||||
Ok(())
|
||||
}
|
||||
@@ -432,8 +459,15 @@ mod tests {
|
||||
fn parse_snapshot_command(
|
||||
profile_id: &ProfileId,
|
||||
profile_data_dir: PathBuf,
|
||||
) -> Result<SidecarCommand, SidecarArgsError> {
|
||||
parse_command(snapshot_command_args(profile_id, profile_data_dir))
|
||||
) -> Result<super::SnapshotArgs, SidecarArgsError> {
|
||||
Ok(snapshot_args(parse_command(snapshot_command_args(profile_id, profile_data_dir))?))
|
||||
}
|
||||
|
||||
fn snapshot_args(command: SidecarCommand) -> super::SnapshotArgs {
|
||||
match command {
|
||||
SidecarCommand::Snapshot(args) => args,
|
||||
SidecarCommand::Live(_) => unreachable!("expected snapshot command"),
|
||||
}
|
||||
}
|
||||
|
||||
fn snapshot_command_args(profile_id: &ProfileId, profile_data_dir: PathBuf) -> Vec<String> {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::{cell::Cell, cell::RefCell, rc::Rc};
|
||||
|
||||
use ely_domain::{ProfileId, TabId, WebViewId};
|
||||
use servo::{LoadStatus, WebView, WebViewDelegate};
|
||||
use servo::{LoadStatus, RenderingContext, WebView, WebViewDelegate};
|
||||
use url::Url;
|
||||
|
||||
use crate::{
|
||||
@@ -12,6 +12,7 @@ use crate::{
|
||||
pub(super) struct HostWebView {
|
||||
pub(super) tab_id: TabId,
|
||||
pub(super) profile_id: ProfileId,
|
||||
pub(super) rendering_context: Rc<dyn RenderingContext>,
|
||||
pub(super) webview: WebView,
|
||||
pub(super) delegate: Rc<HostWebViewDelegate>,
|
||||
pub(super) requested_url: Option<String>,
|
||||
|
||||
Reference in New Issue
Block a user