diff --git a/Cargo.lock b/Cargo.lock index 234c5f3..f229e28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -789,7 +789,7 @@ dependencies = [ [[package]] name = "sway-flash-indicator" -version = "0.4.0" +version = "0.4.1" dependencies = [ "directories", "futures-util", diff --git a/Cargo.toml b/Cargo.toml index 67c5f99..c793850 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sway-flash-indicator" -version = "0.4.0" +version = "0.4.1" edition = "2021" [dependencies] diff --git a/packaging/PKGBUILD b/packaging/PKGBUILD index ed52251..155673b 100644 --- a/packaging/PKGBUILD +++ b/packaging/PKGBUILD @@ -1,7 +1,7 @@ # Maintainer: Alex Janka pkgname=sway-flash-indicator -pkgver=0.4.0 +pkgver=0.4.1 pkgrel=1 pkgdesc="flashes sway indicator border rather than always showing it" arch=('x86_64' 'aarch64') diff --git a/src/config.rs b/src/config.rs index 6a20379..d221d6a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -49,7 +49,10 @@ impl ConfigHandle { } } -pub async fn parse_config() -> Res<()> { +#[allow(dead_code)] +pub struct WatchHandle(notify_debouncer_mini::Debouncer); + +pub async fn parse_config() -> Res { let dirs = directories::ProjectDirs::from("com", "alexjanka", "sway-flash-indicator") .ok_or(Error::NoMatchingConfig)?; @@ -72,36 +75,32 @@ pub async fn parse_config() -> Res<()> { c }; let path = config_path.clone(); - tokio::task::spawn(async move { - let mut debouncer = notify_debouncer_mini::new_debouncer( - std::time::Duration::from_secs(1), - move |res: notify_debouncer_mini::DebounceEventResult| match res { - Ok(events) => events.iter().for_each(|e| { - if e.kind == notify_debouncer_mini::DebouncedEventKind::Any { - if let Some(config) = read_config(&path) { - CONFIG.set_blocking(config); - } else { - log::error!("failed to parse config"); - } - } - }), - Err(e) => println!("Error {:?}", e), - }, - ) - .unwrap(); - debouncer - .watcher() - .watch(&config_path, notify::RecursiveMode::Recursive) - .unwrap(); - loop { - tokio::time::sleep(std::time::Duration::from_secs(10)).await; - } - }); + let mut debouncer = notify_debouncer_mini::new_debouncer( + std::time::Duration::from_secs(1), + move |res: notify_debouncer_mini::DebounceEventResult| match res { + Ok(events) => events.iter().for_each(|e| { + if e.kind == notify_debouncer_mini::DebouncedEventKind::Any { + if let Some(config) = read_config(&path) { + CONFIG.set_blocking(config); + } else { + log::error!("failed to parse config"); + } + } + }), + Err(e) => println!("Error {:?}", e), + }, + ) + .unwrap(); + + debouncer + .watcher() + .watch(&config_path, notify::RecursiveMode::Recursive) + .unwrap(); crate::CONFIG.set(config).await; - Ok(()) + Ok(WatchHandle(debouncer)) } fn read_config(path: &std::path::PathBuf) -> Option { diff --git a/src/main.rs b/src/main.rs index fe56fe3..c61cf96 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ async fn main() -> Res<()> { } pretty_env_logger::init(); - config::parse_config().await?; + let _watch_handle = config::parse_config().await?; let mut event_connection = swayipc_async::Connection::new().await?; let mut autosplit_connection = swayipc_async::Connection::new().await?;