1 import { useEffect } from 'react';
3 import { useConversationCounts } from '@proton/mail/counts/conversationCounts';
4 import { useMessageCounts } from '@proton/mail/counts/messageCounts';
5 import { useMailSettings } from '@proton/mail/mailSettings/hooks';
6 import { MAILBOX_LABEL_IDS } from '@proton/shared/lib/constants';
7 import { invokeInboxDesktopIPC } from '@proton/shared/lib/desktop/ipcHelpers';
8 import { isElectronMail } from '@proton/shared/lib/helpers/desktop';
9 import { captureMessage } from '@proton/shared/lib/helpers/sentry';
10 import { VIEW_MODE } from '@proton/shared/lib/mail/mailSettings';
12 const useInboxDesktopBadgeCount = () => {
13 const [mailSettings] = useMailSettings();
14 const [conversationCounts] = useConversationCounts();
15 const [messageCounts] = useMessageCounts();
16 const counts = mailSettings?.ViewMode === VIEW_MODE.GROUP ? conversationCounts : messageCounts;
18 // Updates the notification badge on the desktop app icon depending on the unread count
20 if (!isElectronMail) {
24 const inboxConvCount = counts?.find(({ LabelID }) => LabelID === MAILBOX_LABEL_IDS.INBOX);
25 let payload = inboxConvCount?.Unread;
27 if (payload === undefined) {
28 captureMessage('Invalid undefined unread count', {
30 extra: { inboxConvCount, payload },
34 } else if (payload < 0) {
35 captureMessage('Invalid negative unread count', {
37 extra: { inboxConvCount, payload },
43 invokeInboxDesktopIPC({
44 type: 'updateNotification',
50 export default useInboxDesktopBadgeCount;