config: don't spawn useless extra thread
This commit is contained in:
parent
8322bbc051
commit
3e1c4df585
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -789,7 +789,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "sway-flash-indicator"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
dependencies = [
|
||||
"directories",
|
||||
"futures-util",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "sway-flash-indicator"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Maintainer: Alex Janka <alex@alexjanka.com>
|
||||
|
||||
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')
|
||||
|
|
|
@ -49,7 +49,10 @@ impl ConfigHandle {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn parse_config() -> Res<()> {
|
||||
#[allow(dead_code)]
|
||||
pub struct WatchHandle(notify_debouncer_mini::Debouncer<notify::INotifyWatcher>);
|
||||
|
||||
pub async fn parse_config() -> Res<WatchHandle> {
|
||||
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<Config> {
|
||||
|
|
|
@ -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?;
|
||||
|
|
Loading…
Reference in a new issue