Basic support for opening a browser maybe
This commit is contained in:
parent
d6c9ae8d71
commit
1a5228c380
2 changed files with 19 additions and 6 deletions
|
|
@ -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<Message>,
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue