diff --git a/src/cli/mod.rs b/src/cli/mod.rs index a92690d..f797e4a 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -1,9 +1,9 @@ -use clap::Parser; use crate::Result; +use clap::Parser; -mod start; mod daemon; mod run; +mod start; #[derive(Debug, clap::Parser)] struct Cli { diff --git a/src/cli/run.rs b/src/cli/run.rs index ab84d65..f5bdd31 100644 --- a/src/cli/run.rs +++ b/src/cli/run.rs @@ -1,7 +1,7 @@ use crate::{env, Result}; use eyre::bail; -use interprocess::local_socket::{GenericFilePath, ToFsName}; use interprocess::local_socket::traits::tokio::Stream; +use interprocess::local_socket::{GenericFilePath, ToFsName}; use tokio::io::{AsyncBufReadExt, AsyncWriteExt}; use tokio::try_join; @@ -25,8 +25,10 @@ impl Run { } dbg!(&self); - let conn = - interprocess::local_socket::tokio::Stream::connect(env::IPC_SOCK_PATH.clone().to_fs_name::()?).await?; + let conn = interprocess::local_socket::tokio::Stream::connect( + env::IPC_SOCK_PATH.clone().to_fs_name::()?, + ) + .await?; let (recv, mut send) = conn.split(); let mut read = tokio::io::BufReader::new(recv); let mut buffer = String::with_capacity(1024); diff --git a/src/ipc/client.rs b/src/ipc/client.rs index e69de29..8b13789 100644 --- a/src/ipc/client.rs +++ b/src/ipc/client.rs @@ -0,0 +1 @@ + diff --git a/src/ipc/mod.rs b/src/ipc/mod.rs index 6fc0725..d212451 100644 --- a/src/ipc/mod.rs +++ b/src/ipc/mod.rs @@ -1,2 +1,2 @@ pub(crate) mod client; -pub(crate) mod server; \ No newline at end of file +pub(crate) mod server; diff --git a/src/ipc/server.rs b/src/ipc/server.rs index 955e995..a34ac29 100644 --- a/src/ipc/server.rs +++ b/src/ipc/server.rs @@ -1,7 +1,7 @@ +use crate::{env, Result}; +use interprocess::local_socket::{GenericFilePath, ListenerOptions, Name, ToFsName}; use std::path::Path; use tokio::fs; -use interprocess::local_socket::{GenericFilePath, ListenerOptions, Name, ToFsName}; -use crate::{env, Result}; pub async fn listen() -> Result { let _ = fs::remove_file(&*env::IPC_SOCK_PATH).await; @@ -13,4 +13,4 @@ pub async fn listen() -> Result { fn fs_name(path: &Path) -> Result { let fs_name = path.clone().to_fs_name::()?; Ok(fs_name) -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index 14b4089..5954616 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,13 +4,13 @@ extern crate log; mod cli; mod daemon; mod env; +mod ipc; mod logger; -mod state_file; mod pitchfork_toml; mod procs; +mod state_file; mod supervisor; mod ui; -mod ipc; pub use eyre::Result; diff --git a/src/state_file.rs b/src/state_file.rs index 993783c..aaf3f64 100644 --- a/src/state_file.rs +++ b/src/state_file.rs @@ -1,7 +1,7 @@ +use crate::Result; use std::collections::BTreeMap; use std::fmt::Debug; use std::path::{Path, PathBuf}; -use crate::Result; #[derive(Debug, serde::Serialize, serde::Deserialize)] pub struct StateFile { diff --git a/src/supervisor.rs b/src/supervisor.rs index 912001c..f46853c 100644 --- a/src/supervisor.rs +++ b/src/supervisor.rs @@ -30,7 +30,10 @@ enum Event { impl Supervisor { pub fn new(pid_file: StateFile) -> Self { - Self { state_file: pid_file, last_run: time::Instant::now() } + Self { + state_file: pid_file, + last_run: time::Instant::now(), + } } pub async fn start(mut self) -> Result<()> { @@ -39,7 +42,13 @@ impl Supervisor { let listener = ipc::server::listen().await?; - self.state_file.daemons.insert("pitchfork".to_string(), StateFileDaemon { pid, status: StateFileDaemonStatus::Running }); + self.state_file.daemons.insert( + "pitchfork".to_string(), + StateFileDaemon { + pid, + status: StateFileDaemonStatus::Running, + }, + ); self.state_file.write()?; let (tx, mut rx) = channel(1); @@ -65,14 +74,14 @@ impl Supervisor { continue; } }; - + let mut recv = BufReader::new(&conn); let mut send = &conn; let mut buffer = String::with_capacity(1024); let send = send.write_all(b"Hello, world!\n"); let recv = recv.read_line(&mut buffer); try_join!(send, recv)?; - + println!("Received: {}", buffer.trim()); } } @@ -167,22 +176,27 @@ impl Supervisor { fn file_watch(&self, tx: Sender) -> Result> { let h = tokio::runtime::Handle::current(); - let mut debouncer = new_debouncer(Duration::from_secs(2), move |res: DebounceEventResult| { - let tx = tx.clone(); - h.spawn(async move { - if let Ok(ev) = res { - let paths = ev.into_iter().map(|e| e.path).collect(); - tx.send(Event::FileChange(paths)).await.unwrap(); - } - }); - })?; + let mut debouncer = + new_debouncer(Duration::from_secs(2), move |res: DebounceEventResult| { + let tx = tx.clone(); + h.spawn(async move { + if let Ok(ev) = res { + let paths = ev.into_iter().map(|e| e.path).collect(); + tx.send(Event::FileChange(paths)).await.unwrap(); + } + }); + })?; - debouncer.watcher().watch(&env::BIN_PATH, RecursiveMode::NonRecursive)?; - debouncer.watcher().watch(&self.state_file.path, RecursiveMode::NonRecursive)?; + debouncer + .watcher() + .watch(&env::BIN_PATH, RecursiveMode::NonRecursive)?; + debouncer + .watcher() + .watch(&self.state_file.path, RecursiveMode::NonRecursive)?; Ok(debouncer) } - + fn interval_watch(&self, tx: Sender) -> Result<()> { let tx = tx.clone(); tokio::spawn(async move {