Skip to content

Commit ca271b1

Browse files
committed
notmuch: update the count whenever the database is updated
Specifically, this re-runs the count command whenever the databased lock is released. This event is triggered whenever the database is closed after it was opened for writing, but NOT when it was opened for reading.
1 parent 2d797c5 commit ca271b1

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# i3status-rust 0.35.0 [unreleased]
2+
3+
### Breaking Changes
4+
5+
- The `interval` option has been removed from the `notmuch` block in favor of watching the notmuch database for changes.
6+
17
# i3status-rust 0.34.0
28

39
### New Blocks and Features

src/blocks/notmuch.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,16 @@
4343
//! # Icons Used
4444
//! - `mail`
4545
46+
use std::path::Path;
47+
48+
use inotify::{Inotify, WatchMask};
49+
4650
use super::prelude::*;
4751

4852
#[derive(Deserialize, Debug, SmartDefault)]
4953
#[serde(deny_unknown_fields, default)]
5054
pub struct Config {
5155
pub format: FormatConfig,
52-
#[default(10.into())]
53-
pub interval: Seconds,
5456
#[default("~/.mail".into())]
5557
pub maildir: ShellString,
5658
pub query: String,
@@ -68,7 +70,21 @@ pub async fn run(config: &Config, api: &CommonApi) -> Result<()> {
6870
let format = config.format.with_default(" $icon $count ")?;
6971

7072
let db = config.maildir.expand()?;
71-
let mut timer = config.interval.timer();
73+
let notify = Inotify::init().error("Failed to start inotify")?;
74+
75+
for lockpath in ["xapian/flintlock", ".notmuch/xapian/flintlock"] {
76+
let fname = Path::new(&*db).join(lockpath);
77+
if fname.exists() {
78+
notify
79+
.watches()
80+
.add(fname, WatchMask::CLOSE_WRITE)
81+
.error("failed to add inotify watch")?;
82+
}
83+
}
84+
85+
let mut updates = notify
86+
.into_event_stream([0; 1024])
87+
.error("Failed to create event stream")?;
7288

7389
loop {
7490
// TODO: spawn_blocking?
@@ -96,7 +112,7 @@ pub async fn run(config: &Config, api: &CommonApi) -> Result<()> {
96112
api.set_widget(widget)?;
97113

98114
tokio::select! {
99-
_ = timer.tick() => (),
115+
_ = updates.next_debounced() => (),
100116
_ = api.wait_for_update_request() => (),
101117
}
102118
}

0 commit comments

Comments
 (0)