Skip to content

feat(notifications): respect system Do Not Disturb for WhatsApp's mes… - #1001

Merged
rafatosta merged 2 commits into
rafatosta:mainfrom
the-beper:feat/respect-do-not-disturb
Nov 11, 2026
Merged

rafatosta merged 2 commits into
rafatosta:mainfrom
the-beper:feat/respect-do-not-disturb

Conversation

@the-beper

Copy link
Copy Markdown
Contributor

AI disclosure

This PR has been assisted by Claude Code.

Summary

Silence WhatsApp Web's message tone while the desktop Do Not Disturb mode is on. New setting Respect Do Not Disturb (Notifications page, notification/respect_dnd, default on).

Fixes the tone still playing under DND: #896 (KDE Plasma), #624 (GNOME). Related: #864, #816.

Problem

The message tone is played by the WhatsApp Web page (<audio>), not by the notification server. Existing controls do not cover it:

Changes

DND detection (features/notifications/do_not_disturb_monitor.py, QtDBus only, no new dependency). DoNotDisturbMonitor.active is true when any available source reports DND, and changed(bool) fires on transitions.

Source Read Updates DND when
org.freedesktop.Notifications (KDE Plasma, any server implementing it) Properties.Get(..., "Inhibited") PropertiesChanged Inhibited == true
XDG portal (GNOME) Settings.Read("org.gnome.desktop.notifications", "show-banners") SettingChanged show-banners == false
  • Calls use QDBusMessage.createMethodCall with a 1 s block timeout: no introspection, no long stall on the GUI thread.
  • NameOwnerChanged for org.freedesktop.Notifications: owner gone resets the inhibition (no stuck-silent state if plasmashell restarts); new owner re-reads.
  • A failed subscription logs a warning. A missing source is ignored.
  • Inert on Windows and macOS.
  • Works in the Flatpak sandbox: --talk-name=org.freedesktop.Notifications is already granted and the portal is always reachable.

Tone suppression (features/browser/web/scripts/notification_sound_guard.js). Wraps HTMLMediaElement.prototype.play and returns a resolved Promise without playing when suppression is active and the element matches all of:

  • tagName === "AUDIO"
  • not attached to the DOM (!isConnected)
  • !loop
  • currentSrc/src starts with https://static.whatsapp.net/

Voice notes (blob: sources), videos (attached <video>) and the looping call ringtone do not match. Anything unrecognised plays normally (fails open). The matcher was derived from play() calls logged on a live session (see Testing).

Registered per profile at DocumentCreation, MainWorld, main frame only. The initial state is prefixed to the script source (window.__zapzapNotificationSoundInitial), and the script is re-registered on every state change, so a reload or a new document never starts unmuted. The live document is updated with runJavaScript.

State ownership. MainWindowController computes respect_dnd and monitor.active (runtime only, not persisted) and fans it out via BrowserController.set_notification_sound_suppressed → WebView → PageController, following the existing set_audio_muted path. Accounts created later inherit the current state. system/audio_muted and notification/sound are untouched and independent.

Setting. NotificationSettings.respect_dnd plus a notification_settings_events.respect_dnd_changed signal (same pattern as download_settings_events) so toggling applies immediately. The switch sits outside the group that depends on "Desktop notifications", because the page plays the tone even with desktop notifications disabled.

Translations. Two new msgids added to zapzap.pot and all .po files (msgmerge, minimal diff). Translated for it, pt_BR and tr; their .mo files are rebuilt. Other catalogs keep empty msgstr and fall back to English.

Docs. docs/testing.md: test inventory entries and a manual DND validation checklist.

Testing

Run in the official Flatpak environment.

  • unittest discover -s tests -q: 781 tests. 8 failures/errors, none related to this change: dictionary manager/options UI, zh-CN catalog, macOS packaging script, account context menu. Checked on the author's working tree, not on a clean upstream main.
  • check_unused_code.py --packages-only, test_documentation_structure.py, compileall, git diff --check: pass.
  • New test_do_not_disturb_monitor.py: transitions emit once, unrelated interfaces/keys ignored, nested-variant and error replies, server owner loss/return, no-op off Linux.
  • New test_notification_sound_guard.py: script in a real QWebEnginePage (message tone silenced; looping ringtone, blob: audio, attached <video> and attached <audio> pass; initial state; suppression lifted again) and per-account fan-out through MainWindowController.
  • Extended test_notifications_settings_ui.py: switch persists and stays enabled when desktop notifications are off.
  • Manual, KDE Plasma (Wayland) with a Flatpak build: no tone for an incoming message with DND on; video and voice-note playback still audible. The play() log used to derive the matcher came from the same session.
  • Inhibited verified to exist on Plasma (busctl), and the monitor's read verified inside the sandbox.

Not verified

  • GNOME: whether the portal exposes org.gnome.desktop.notifications at all. If not, the GNOME source is simply unavailable.
  • The matcher depends on how WhatsApp Web plays the tone today. It also matches any other non-looping, detached static.whatsapp.net audio, which may include the sent-message sound (not checked).
  • The stubbed play() fires no ended/pause event; whether WhatsApp Web waits for one was not checked.
  • Popup windows (e.g. calls) are not affected by the guard.

@the-beper
the-beper force-pushed the feat/respect-do-not-disturb branch from 4ec2aae to 0a5d90d Compare November 11, 2026 18:14
the-beper and others added 2 commits November 11, 2026 19:28
…sage tone

Add DoNotDisturbMonitor (QtDBus), which reads the notification server's
Inhibited property (KDE Plasma) and the portal show-banners setting (GNOME,
not verified on a real session) and follows their changes, including a
notification server that disappears or restarts.

While Do Not Disturb is on and the new "Respect Do Not Disturb" setting
(default on) is enabled, an injected script makes play() a no-op for
WhatsApp Web's message tone only: a detached, non-looping <audio> served by
static.whatsapp.net. Calls, voice notes and videos are unaffected. The state
is baked into the script source so reloads start with the right value. The
tone comes from the page, so neither the desktop notification hints nor the
global mute covered this case (#896, #624).

Add the two new strings to the catalogs with Italian and Brazilian
Portuguese translations; the Turkish one needs a native review.

Tests:
- flatpak_python -m unittest discover -s tests -q: 781 tests, 8 failures that
  also fail without this change (dictionary UI, zh-CN catalog, macOS packaging
  script, account context menu)
- flatpak_python tests/check_unused_code.py --packages-only
- flatpak_python tests/test_documentation_structure.py -v
- Manual on KDE Plasma (Flatpak build): no tone for a message with Do Not
  Disturb on; video and voice playback still audible. Live DND toggling, calls
  and GNOME were not tested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refresh the POT template and every catalog after the rebase onto main so
source references match the moved code. The merge surfaced the new
single-process alert strings in the Turkish catalog as fuzzy or empty
entries, which the Turkish guard test rejects; fill them with best-effort
Turkish translations pending native review, as with the Do Not Disturb
strings.

Tests:
- flatpak_python -m unittest discover -s tests -q
- flatpak_python tests/check_unused_code.py --packages-only
- flatpak_python tests/test_documentation_structure.py -v
- flatpak_python -m compileall -q zapzap tests tools run.py
- git diff --check
@the-beper
the-beper force-pushed the feat/respect-do-not-disturb branch from 0a5d90d to 56b2a52 Compare November 11, 2026 18:32
@rafatosta
rafatosta merged commit fce1dc2 into rafatosta:main Nov 11, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants