Skip to content

Commit

Permalink
Use settings for future expansions
Browse files Browse the repository at this point in the history
  • Loading branch information
Legend-Master committed Jan 22, 2025
1 parent f72a9ef commit 0d3c219
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
29 changes: 21 additions & 8 deletions verso/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,47 @@ use versoview_messages::ControllerMessage;

use ipc_channel::ipc::{IpcOneShotServer, IpcSender};

#[derive(Debug, Default)]
pub struct VersoviewSettings {
pub with_panel: bool,
}

pub struct VersoviewController(IpcSender<ControllerMessage>);

impl VersoviewController {
/// Create a new verso instance and get the controller to it
fn create(verso_path: impl AsRef<Path>, initial_url: url::Url, with_panel: bool) -> Self {
/// Create a new verso instance with settings and get the controller to it
fn create(
verso_path: impl AsRef<Path>,
initial_url: url::Url,
settings: VersoviewSettings,
) -> Self {
let path = verso_path.as_ref();
let (server, server_name) =
IpcOneShotServer::<IpcSender<ControllerMessage>>::new().unwrap();
let mut command = Command::new(path);
command
.arg(format!("--ipc-channel={server_name}"))
.arg(format!("--url={initial_url}"));
if !with_panel {
if !settings.with_panel {
command.arg("--no-panel");
}
command.spawn().unwrap();
let (_, sender) = server.accept().unwrap();
Self(sender)
}

/// Create a new verso instance and get the controller to it
/// Create a new verso instance with default settings and get the controller to it
pub fn new(verso_path: impl AsRef<Path>, initial_url: url::Url) -> Self {
Self::create(verso_path, initial_url, false)
Self::create(verso_path, initial_url, VersoviewSettings::default())
}

/// Create a new verso instance with the default panel and get the controller to it
pub fn new_with_panel(verso_path: impl AsRef<Path>, initial_url: url::Url) -> Self {
Self::create(verso_path, initial_url, true)
/// Create a new verso instance with custom settings and get the controller to it
pub fn new_with_settings(
verso_path: impl AsRef<Path>,
initial_url: url::Url,
settings: VersoviewSettings,
) -> Self {
Self::create(verso_path, initial_url, settings)
}

/// Navigate to url
Expand Down
8 changes: 7 additions & 1 deletion verso/src/main.rs
Original file line number Diff line number Diff line change
@@ -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_with_panel(
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
Expand Down

0 comments on commit 0d3c219

Please sign in to comment.