diff --git a/src/browse/browse_unix.rs b/src/browse/browse_unix.rs index 9975b48..5a92b88 100644 --- a/src/browse/browse_unix.rs +++ b/src/browse/browse_unix.rs @@ -1,4 +1,4 @@ -use crate::message::{Message, MessageReader}; +use crate::message::{Message, MessageReader, MessageWriter}; use anyhow::{bail, Context, Result}; use log::warn; use std::os::unix::fs::DirBuilderExt; @@ -8,7 +8,18 @@ use tokio::sync::mpsc; use users; use xdg; -pub async fn browse_url_impl(_url: &String) {} +pub async fn browse_url_impl(url: &String) -> Result<()> { + let path = socket_path().context("Error getting socket path")?; + let stream = UnixStream::connect(&path).await.context( + "Error connecting to socket (is fwd actually connected here?)", + )?; + let mut writer = MessageWriter::new(stream); + writer + .write(Message::Browse(url.clone())) + .await + .context("Error sending browse message")?; + Ok(()) +} pub async fn handle_browser_open_impl( messages: mpsc::Sender, diff --git a/src/browse/mod.rs b/src/browse/mod.rs index d8a17d2..c1e264c 100644 --- a/src/browse/mod.rs +++ b/src/browse/mod.rs @@ -10,13 +10,15 @@ use browse_unix::{browse_url_impl, handle_browser_open_impl}; #[inline] pub async fn browse_url(url: &String) { - browse_url_impl(url).await + if let Err(e) = browse_url_impl(url).await { + eprintln!("{}", e); + std::process::exit(1); + } } #[cfg(not(target_family = "unix"))] -pub async fn browse_url_impl(url: &String) { - print!("Opening a browser is not supported on this platform\n"); - std::process::exit(1); +pub async fn browse_url_impl(url: &String) -> Result<()> { + anyhow!("Opening a browser is not supported on this platform") } #[inline]