This module provides an enhanced toast notification system that automatically integrates with the system tray to manage notification badge counts.
The toastWithTray.ts module wraps the sonner toast library and automatically:
- Increments the tray badge count when a toast is shown
- Decrements the count when a toast is dismissed or auto-closes
- Syncs with the system tray via the
useTrayhook
Import toast from toastWithTray instead of directly from sonner:
// ❌ Old way
import { toast } from 'sonner';
// ✅ New way
import { toast } from '../lib/toastWithTray';All standard toast methods are supported:
// Success notification (increments badge)
toast.success('Server created successfully');
// Error notification (increments badge)
toast.error('Failed to connect to server');
// Info notification (increments badge)
toast.info('Configuration updated');
// Warning notification (increments badge)
toast.warning('Server is running low on resources');
// Loading notification (does NOT increment badge)
toast.loading('Connecting to server...');
// Custom message (increments badge)
toast.message('Custom notification');
// Dismiss a toast
toast.dismiss(toastId);-
Initialization: The
useTrayhook is called inmainapp.tsx, which connects the notification manager to the tray badge update function. -
Toast Display: When a toast is shown, the notification count increments and the tray badge updates.
-
Toast Dismissal: When a toast is dismissed (manually or auto-closed), the count decrements and the badge updates.
-
Badge Sync: The badge count is always kept in sync with the number of active toast notifications.
┌─────────────────┐
│ Components │
│ (use toast) │
└────────┬────────┘
│
▼
┌─────────────────┐
│ toastWithTray │
│ (wraps sonner) │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Notification │
│ Manager │
└────────┬────────┘
│
▼
┌─────────────────┐
│ useTray │
│ (IPC bridge) │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Electron Tray │
│ (badge count) │
└─────────────────┘
src/lib/toastWithTray.ts- New wrapper modulesrc/hooks/useTray.ts- Updated to connect notification managersrc/mainapp.tsx- Initializes tray integrationsrc/lib/serverUtils.ts- Updated importsrc/hooks/useServerActions.ts- Updated importsrc/components/AddServerForm.tsx- Updated importsrc/components/BulkImportForm.tsx- Updated importsrc/components/ToolsPage.tsx- Updated import
- Loading toasts do NOT increment the badge count as they are typically replaced by success/error toasts
- The notification manager is a singleton, ensuring consistent state across the app
- Badge count never goes below 0
- All existing toast functionality remains unchanged