diff --git a/verso/src/lib.rs b/verso/src/lib.rs index 6ab21f86..c8b522e5 100644 --- a/verso/src/lib.rs +++ b/verso/src/lib.rs @@ -3,23 +3,49 @@ use versoview_messages::ControllerMessage; use ipc_channel::ipc::{IpcOneShotServer, IpcSender}; +#[derive(Debug, Default)] +pub struct VersoviewSettings { + pub with_panel: bool, +} + pub struct VersoviewController(IpcSender); impl VersoviewController { - /// Create a new verso instance and get the controller to it - pub fn new(verso_path: impl AsRef, initial_url: url::Url) -> Self { + /// Create a new verso instance with settings and get the controller to it + fn create( + verso_path: impl AsRef, + initial_url: url::Url, + settings: VersoviewSettings, + ) -> Self { let path = verso_path.as_ref(); let (server, server_name) = IpcOneShotServer::>::new().unwrap(); - Command::new(path) + let mut command = Command::new(path); + command .arg(format!("--ipc-channel={server_name}")) - .arg(format!("--url={initial_url}")) - .spawn() - .unwrap(); + .arg(format!("--url={initial_url}")); + if !settings.with_panel { + command.arg("--no-panel"); + } + command.spawn().unwrap(); let (_, sender) = server.accept().unwrap(); Self(sender) } + /// Create a new verso instance with default settings and get the controller to it + pub fn new(verso_path: impl AsRef, initial_url: url::Url) -> Self { + Self::create(verso_path, initial_url, VersoviewSettings::default()) + } + + /// Create a new verso instance with custom settings and get the controller to it + pub fn new_with_settings( + verso_path: impl AsRef, + initial_url: url::Url, + settings: VersoviewSettings, + ) -> Self { + Self::create(verso_path, initial_url, settings) + } + /// Navigate to url pub fn navigate(&self, url: url::Url) -> Result<(), Box> { self.0.send(ControllerMessage::NavigateTo(url)) diff --git a/verso/src/main.rs b/verso/src/main.rs index 188191d5..4e7627b4 100644 --- a/verso/src/main.rs +++ b/verso/src/main.rs @@ -1,10 +1,16 @@ use std::{env::current_exe, thread::sleep, time::Duration}; +use verso::VersoviewSettings; + fn main() { let versoview_path = current_exe().unwrap().parent().unwrap().join("versoview"); - let controller = verso::VersoviewController::new( + let controller = verso::VersoviewController::new_with_settings( versoview_path, url::Url::parse("https://example.com").unwrap(), + VersoviewSettings { + with_panel: true, + ..Default::default() + }, ); sleep(Duration::from_secs(10)); dbg!(controller