enableSuppression
enableSuppression
Info
Enables toast notification suppression on the system. When suppression is active, incoming toast notifications are silently consumed and getNotifications() returns an empty array. This is useful for building distraction-free modes or temporary "do not disturb" features in your application.
Signature
function enableSuppression(): booleanUsage
Call enableSuppression() when you want to silence all toast notifications. Suppression remains active until you explicitly call disableSuppression(). You can check the current state at any time with isSuppressionEnabled().
Tips
Pair suppression with a UI toggle so users can opt in and out. Always provide a visible way to restore notifications.
Note
Suppression is a global setting. It affects all toast notifications across the system, not just those from your application.
Return Value
Returns true if suppression was successfully enabled. Returns false if suppression was already active (i.e., no state change occurred).
Warning
Do not assume the return value means the system is in a brand-new suppressed state. A false return simply means suppression was already on. Use isSuppressionEnabled() to query the actual current state if needed.
Example
import { enableSuppression, isSuppressionEnabled, getNotifications } from '@eisland/windows-toast-listener';
// Enable toast notification suppression
const enabled = enableSuppression();
// Check if suppression was newly activated
if (enabled) {
console.log('Suppression enabled');
} else {
console.log('Suppression was already active');
}
// Verify the current suppression state
console.log('Suppression active:', isSuppressionEnabled());
// Notifications list is now empty while suppression is on
const notifs = getNotifications();
console.log('Notification count:', notifs.length); // 0const { enableSuppression, isSuppressionEnabled, getNotifications } = require('@eisland/windows-toast-listener');
// Enable toast notification suppression
const enabled = enableSuppression();
// Check if suppression was newly activated
if (enabled) {
console.log('Suppression enabled');
} else {
console.log('Suppression was already active');
}
// Verify the current suppression state
console.log('Suppression active:', isSuppressionEnabled());
// Notifications list is now empty while suppression is on
const notifs = getNotifications();
console.log('Notification count:', notifs.length); // 0Notes
Note
Suppression persists as long as your process holds it. If your application crashes or exits without calling disableSuppression(), the system may restore normal notification behavior automatically, but this is not guaranteed on all Windows versions.
Tips
If you only need to temporarily hide notifications during a specific operation, call enableSuppression() before the operation and disableSuppression() immediately after. Avoid leaving suppression on indefinitely without a clear user-facing reason.
Note
The startListening() callback still receives change events while suppression is active, but the notification content is not available through getNotifications().
Danger Avoidance
Caution
Never leave suppression enabled indefinitely without giving the user a way to restore notifications. Silent suppression can cause users to miss critical alerts (e.g., security warnings, calendar reminders). Always pair with a visible UI control or a timeout mechanism.
Caution
Do not call enableSuppression() in a tight loop or on every render cycle. The function modifies global system state and may have performance implications if invoked repeatedly. Call it once when entering "do not disturb" mode, not continuously.
Changelog
4f6b6-on

