From d0ebda2fb2576544fecb99c5dd1375231ff6514b Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Wed, 7 Oct 2026 18:25:02 +0200 Subject: fix(mail): recount unread when the notmuch database commits Accounts counted only at shell start and when the mail page opened, so the drawer tile drifted behind the inbox for the rest of the session: it read 14 while notmuch and the waybar pill both said 16. The waybar pill never drifted because waybar-mail.sh watches the database; the drawer had no watcher. Accounts now runs its own inotifywait -m on the xapian directory (the directory, because Xapian replaces files on commit) and refreshes 300ms after a commit burst settles. The watcher respawns after 5s if it exits, since a dead one reproduces the drift with no visible error. This is the prerequisite for removing waybar: the drawer becomes the only place the unread count is shown. Co-Authored-By: Claude Opus 5.5 --- desktop/modules/mail/Accounts.qml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'desktop/modules/mail/Accounts.qml') diff --git a/desktop/modules/mail/Accounts.qml b/desktop/modules/mail/Accounts.qml index 0ae6886..c2bc9d8 100644 --- a/desktop/modules/mail/Accounts.qml +++ b/desktop/modules/mail/Accounts.qml @@ -184,6 +184,28 @@ Singleton { accounts = next; } + // Recount whenever the notmuch database commits. Without this the counts + // were read only at shell start and when the mail page opened, so the + // tile drifted behind the real inbox for the rest of the session. + // + // The directory is watched, not a file: Xapian replaces its files on + // commit, which kills a watch held on any one of them. notmuch is asked + // for its own database path, so a moved database needs no edit here. + Process { + id: watcher + running: true + command: ["sh", "-c", + 'exec inotifywait -m -q -e close_write,moved_to --format x "$(notmuch config get database.path)/xapian"'] + // One commit touches several files; the timer turns that burst into + // one refresh. + stdout: SplitParser { onRead: debounce.restart() } + // A dead watcher is the original bug again, silently. Come back. + onExited: respawn.start() + } + + Timer { id: debounce; interval: 300; onTriggered: root.refresh() } + Timer { id: respawn; interval: 5000; onTriggered: watcher.running = true } + // Launching qtmaildir. It takes no arguments, so there is nothing to tell // it about the account or thread clicked. Process { id: openProc; command: [`${Quickshell.env("HOME")}/bin/qtmaildir`] } -- cgit v1.2.3