From ce67e527722cadd4ed7341a3e5d433beb62887f6 Mon Sep 17 00:00:00 2001 From: YummyOreo Date: Sun, 12 May 2024 21:35:34 -0500 Subject: feat(daemon): add support for daemon on windows (#2014) * fix: gracefully exit on windows * feat(daemon): tcp support for windows * feat(daemon): add tcp port configuration * fix: logging and fix compiler error * docs: add build dependency to the readme fix(docs): move a line up * fix: missing field error * docs: adds the daemon section to the default config * fix: clippy and fmt * feat: Update README.md Co-authored-by: Ellie Huxtable * refactor: changes tcp port and other stuff as per request * fix(config): update default tcp port in example config * fix: complier error on unix * refactor: make the cfg stuff look better --------- Co-authored-by: Ellie Huxtable --- crates/atuin-daemon/src/client.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'crates/atuin-daemon/src/client.rs') diff --git a/crates/atuin-daemon/src/client.rs b/crates/atuin-daemon/src/client.rs index a832f9a9..f3fecdbc 100644 --- a/crates/atuin-daemon/src/client.rs +++ b/crates/atuin-daemon/src/client.rs @@ -1,8 +1,12 @@ use eyre::{eyre, Result}; -use tokio::net::UnixStream; +#[cfg(windows)] +use tokio::net::TcpStream; use tonic::transport::{Channel, Endpoint, Uri}; use tower::service_fn; +#[cfg(unix)] +use tokio::net::UnixStream; + use atuin_client::history::History; use crate::history::{ @@ -15,6 +19,7 @@ pub struct HistoryClient { // Wrap the grpc client impl HistoryClient { + #[cfg(unix)] pub async fn new(path: String) -> Result { let channel = Endpoint::try_from("http://atuin_local_daemon:0")? .connect_with_connector(service_fn(move |_: Uri| { @@ -30,6 +35,21 @@ impl HistoryClient { Ok(HistoryClient { client }) } + #[cfg(not(unix))] + pub async fn new(port: u64) -> Result { + let channel = Endpoint::try_from("http://atuin_local_daemon:0")? + .connect_with_connector(service_fn(move |_: Uri| { + let url = format!("127.0.0.1:{}", port); + TcpStream::connect(url) + })) + .await + .map_err(|_| eyre!("failed to connect to local atuin daemon. Is it running?"))?; + + let client = HistoryServiceClient::new(channel); + + Ok(HistoryClient { client }) + } + pub async fn start_history(&mut self, h: History) -> Result { let req = StartHistoryRequest { command: h.command, -- cgit v1.3.1