Skip to content

Commit

Permalink
Add a CLI arg for launching without control panel (#215)
Browse files Browse the repository at this point in the history
* Add cli arg for launching without control panel

* Rename with_panel to no_panel
  • Loading branch information
Legend-Master authored Nov 6, 2024
1 parent 4d56a12 commit ec65e25
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
10 changes: 9 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub struct CliArgs {
pub url: Option<url::Url>,
/// The IPC channel name used to communicate with the webview controller.
pub ipc_channel: Option<String>,
/// Should launch without control panel
pub no_panel: bool,
}

/// Configuration of Verso instance.
Expand All @@ -41,6 +43,7 @@ fn parse_cli_args() -> Result<CliArgs, getopts::Fail> {
"IPC channel name to communicate and control verso",
"",
);
opts.optflag("", "no-panel", "Launch Verso without control panel");

let matches: getopts::Matches = opts.parse(&args[1..])?;
let url = matches
Expand All @@ -58,8 +61,13 @@ fn parse_cli_args() -> Result<CliArgs, getopts::Fail> {
}
});
let ipc_channel = matches.opt_str("ipc-channel");
let no_panel = matches.opt_present("no-panel");

Ok(CliArgs { url, ipc_channel })
Ok(CliArgs {
url,
ipc_channel,
no_panel,
})
}

impl Config {
Expand Down
7 changes: 6 additions & 1 deletion src/verso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl Verso {
// Initialize configurations and Verso window
let protocols = config.create_protocols();
let initial_url = config.args.url.clone();
let with_panel = !config.args.no_panel;

config.init();
// Reserving a namespace to create TopLevelBrowsingContextId.
Expand Down Expand Up @@ -389,7 +390,11 @@ impl Verso {
opts.debug.convert_mouse_to_touch,
);

window.create_panel(&constellation_sender, initial_url);
if with_panel {
window.create_panel(&constellation_sender, initial_url);
} else if let Some(initial_url) = initial_url {
window.create_webview(&constellation_sender, initial_url.into());
}

let mut windows = HashMap::new();
windows.insert(window.id(), (window, webrender_document));
Expand Down
15 changes: 1 addition & 14 deletions src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,7 @@ impl Window {
self.window.request_redraw();
send_to_constellation(sender, ConstellationMsg::FocusWebView(panel_id));

let demo_id = WebViewId::new();
let size = self.size();
let rect = DeviceIntRect::from_size(size);
let mut webview = WebView::new(demo_id, rect);
webview.set_size(self.get_content_size(rect));
self.webview = Some(webview);
send_to_constellation(
sender,
ConstellationMsg::NewWebView(
self.panel.as_ref().unwrap().initial_url.clone(),
demo_id,
),
);
log::debug!("Verso Window {:?} adds webview {}", self.id(), demo_id);
self.create_webview(sender, self.panel.as_ref().unwrap().initial_url.clone());
}
EmbedderMsg::AllowNavigationRequest(id, _url) => {
// The panel shouldn't navigate to other pages.
Expand Down
21 changes: 20 additions & 1 deletion src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl Window {
self.panel = Some(Panel {
webview: WebView::new(panel_id, DeviceIntRect::from_size(size)),
initial_url: if let Some(initial_url) = initial_url {
servo_url::ServoUrl::from_url(initial_url)
ServoUrl::from_url(initial_url)
} else {
ServoUrl::parse("https://example.com").unwrap()
},
Expand All @@ -171,6 +171,25 @@ impl Window {
);
}

/// Create a new webview and send the constellation message to load the initial URL
pub fn create_webview(
&mut self,
constellation_sender: &Sender<ConstellationMsg>,
initial_url: ServoUrl,
) {
let webview_id = WebViewId::new();
let size = self.size();
let rect = DeviceIntRect::from_size(size);
let mut webview = WebView::new(webview_id, rect);
webview.set_size(self.get_content_size(rect));
self.webview.replace(webview);
send_to_constellation(
constellation_sender,
ConstellationMsg::NewWebView(initial_url, webview_id),
);
log::debug!("Verso Window {:?} adds webview {}", self.id(), webview_id);
}

/// Handle Winit window event and return a boolean to indicate if the compositor should repaint immediately.
pub fn handle_winit_window_event(
&mut self,
Expand Down

0 comments on commit ec65e25

Please sign in to comment.