Move browser code to core crate

This commit is contained in:
John Doty 2022-12-17 08:48:57 -08:00
parent 9cf0089e48
commit d6c9ae8d71
5 changed files with 32 additions and 15 deletions

View file

@ -8,6 +8,8 @@ use tokio::sync::mpsc;
use users;
use xdg;
pub async fn browse_url_impl(_url: &String) {}
pub async fn handle_browser_open_impl(
messages: mpsc::Sender<Message>,
) -> Result<()> {

View file

@ -3,16 +3,20 @@ use anyhow::Result;
use tokio::sync::mpsc;
#[cfg(target_family = "unix")]
mod browser_unix;
mod browse_unix;
#[cfg(target_family = "unix")]
use browser_unix::handle_browser_open_impl;
use browse_unix::{browse_url_impl, handle_browser_open_impl};
#[inline]
pub async fn browse_url(url: &String) {
browse_url_impl(url).await
}
#[cfg(not(target_family = "unix"))]
async fn handle_browser_open_impl(
messages: mpsc::Sender<Message>,
) -> Result<()> {
std::future::pending().await
pub async fn browse_url_impl(url: &String) {
print!("Opening a browser is not supported on this platform\n");
std::process::exit(1);
}
#[inline]
@ -21,3 +25,10 @@ pub async fn handle_browser_open(
) -> Result<()> {
handle_browser_open_impl(messages).await
}
#[cfg(not(target_family = "unix"))]
async fn handle_browser_open_impl(
messages: mpsc::Sender<Message>,
) -> Result<()> {
std::future::pending().await
}

View file

@ -1,6 +1,8 @@
mod browse;
mod client;
mod message;
mod server;
pub use browse::browse_url;
pub use client::run_client;
pub use server::run_server;

View file

@ -3,15 +3,17 @@
#[tokio::main]
async fn main() {
let args: Vec<String> = std::env::args().collect();
if args.len() != 2 {
eprintln!("Usage: fwd <server>");
std::process::exit(1);
}
let remote = &args[1];
if remote == "--server" {
if args.len() == 2 && &args[1] == "--server" {
fwd::run_server().await;
} else if args.len() == 3 && args[1] == "browse" {
fwd::browse_url(&args[2]).await;
} else {
fwd::run_client(remote).await;
if args.len() < 2 {
eprintln!("Usage: fwd <server>");
std::process::exit(1);
}
fwd::run_client(&args[1]).await;
}
}

View file

@ -1,10 +1,10 @@
use crate::browse::handle_browser_open;
use crate::message::{Message, MessageReader, MessageWriter};
use anyhow::Result;
use log::{error, warn};
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt, BufReader, BufWriter};
use tokio::sync::mpsc;
mod browser;
mod refresh;
// We drive writes through an mpsc queue, because we not only handle requests
@ -82,7 +82,7 @@ async fn server_main<
tokio::select! {
_ = write_driver(&mut receiver, &mut writer) => Ok(()),
r = server_loop(&mut reader, &mut sender) => r,
r = browser::handle_browser_open(browse_sender) => r,
r = handle_browser_open(browse_sender) => r,
}
}