-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial effort to use IPC calls to control verso (#207)
* Initial effort to use IPC calls to control verso * Move functions to a struct * Change simple example to main.rs * Rename to `ipc_channel` * Rename and give the thread a name
- Loading branch information
1 parent
decf3b3
commit 3843d4e
Showing
10 changed files
with
138 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,27 @@ | ||
use std::{path::Path, process::Command}; | ||
use versoview_messages::ControllerMessage; | ||
|
||
use ipc_channel::ipc::{IpcOneShotServer, IpcSender}; | ||
|
||
pub struct VersoviewController(IpcSender<ControllerMessage>); | ||
|
||
impl VersoviewController { | ||
/// Create a new verso instance and get the controller to it | ||
pub fn new(verso_path: impl AsRef<Path>, initial_url: url::Url) -> Self { | ||
let path = verso_path.as_ref(); | ||
let (server, server_name) = | ||
IpcOneShotServer::<IpcSender<ControllerMessage>>::new().unwrap(); | ||
Command::new(path) | ||
.arg(format!("--ipc-channel={server_name}")) | ||
.arg(format!("--url={initial_url}")) | ||
.spawn() | ||
.unwrap(); | ||
let (_, sender) = server.accept().unwrap(); | ||
Self(sender) | ||
} | ||
|
||
/// Navigate to url | ||
pub fn navigate(&self, url: url::Url) -> Result<(), Box<ipc_channel::ErrorKind>> { | ||
self.0.send(ControllerMessage::NavigateTo(url)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use std::{env::current_exe, thread::sleep, time::Duration}; | ||
|
||
fn main() { | ||
let versoview_path = current_exe().unwrap().parent().unwrap().join("versoview"); | ||
let controller = verso::VersoviewController::new( | ||
versoview_path, | ||
url::Url::parse("https://example.com").unwrap(), | ||
); | ||
sleep(Duration::from_secs(10)); | ||
dbg!(controller | ||
.navigate(url::Url::parse("https://docs.rs").unwrap()) | ||
.unwrap()); | ||
loop { | ||
sleep(Duration::MAX); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
#[non_exhaustive] | ||
pub enum ControllerMessage { | ||
NavigateTo(url::Url), | ||
} |