Stop announcing the same email twice

Both notification paths feed one channel, which is how a single arrival
came to be announced twice: Gmail names the sender, then the unread count
says "1 new" behind it seconds later.

A count is now skipped when the app has spoken for itself in the last
twenty seconds - generous, because a count is only noticed on a
four-second tick, well after the app raised its own. Settings can also
turn count notifications off outright, for hearing only what an app says
in its own words, at the cost of the tools that never say anything.

`npm run ship` now updates only /Applications. The Desktop installer
moved behind `--dmg`, for when a build is going to someone else.
This commit is contained in:
2026-09-02 09:36:57 +02:00
parent c989fef6fe
commit aa19da48de
10 changed files with 121 additions and 21 deletions
+33 -1
View File
@@ -159,6 +159,16 @@ fn handle_sentinel(
let body = params.get("b").cloned().unwrap_or_default();
let app_name = params.get("a").cloned().unwrap_or_default();
let notification_id = params.get("id").cloned().unwrap_or_default();
// Noted so a count does not repeat, seconds later and worse,
// what the app has just said properly.
handle
.state::<crate::commands::AppState>()
.last_spoke
.lock()
.unwrap()
.insert(from.clone(), std::time::Instant::now());
notify(&handle, &from, &app_name, &title, &body, notification_id);
}
@@ -245,7 +255,10 @@ fn handle_sentinel(
};
let _ = handle.emit("unread-changed", crate::commands::unread_list(&state));
if total > previous && showing.as_deref() != Some(from.as_str()) {
if total > previous
&& showing.as_deref() != Some(from.as_str())
&& count_may_speak(&handle, &from)
{
let name = state
.cfg()
.app(&from)
@@ -299,6 +312,25 @@ fn handle_sentinel(
});
}
/// Whether an unread count should raise a notification of its own.
///
/// Two things can suppress it. The setting, for someone who would rather hear
/// only what an app says in its own words. And an app having just said it:
/// Gmail raises a proper notification naming the sender, and the count arriving
/// behind it saying "1 new" is the same news told worse. The window is generous
/// because a count is noticed on a four-second tick, well after the app spoke.
fn count_may_speak(handle: &AppHandle, app_id: &str) -> bool {
let state = handle.state::<crate::commands::AppState>();
if !state.cfg().settings.count_notifications {
return false;
}
let spoke = state.last_spoke.lock().unwrap().get(app_id).copied();
match spoke {
Some(at) => at.elapsed() > std::time::Duration::from_secs(20),
None => true,
}
}
/// Raises a macOS notification and waits, on its own thread, to see it clicked.
///
/// Not the notification plugin: that has no way to report a click, and a