Skip to content

Commit 5f69acd

Browse files
authored
Merge pull request #3216 from burtonemily/notifications-dot
feat: adds in notifications dot: updated setBadgeCount and using glob…
2 parents 8fdbe4a + ca81a50 commit 5f69acd

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

ts/components/leftpane/ActionsPanel.tsx

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import { ipcRenderer } from 'electron';
12
import { debounce } from 'lodash';
23
import { useEffect, useRef, useState } from 'react';
34

45
import { useDispatch, useSelector } from 'react-redux';
56
import useInterval from 'react-use/lib/useInterval';
67
import useTimeoutFn from 'react-use/lib/useTimeoutFn';
8+
import useThrottleFn from 'react-use/lib/useThrottleFn';
79

810
import { Data } from '../../data/data';
911
import { getConversationController } from '../../session/conversations';
@@ -37,18 +39,18 @@ import { LeftPaneSectionContainer } from './LeftPaneSectionContainer';
3739

3840
import { SettingsKey } from '../../data/settings-key';
3941
import { useFetchLatestReleaseFromFileServer } from '../../hooks/useFetchLatestReleaseFromFileServer';
42+
import { useHotkey } from '../../hooks/useHotkey';
4043
import {
4144
forceRefreshRandomSnodePool,
4245
getFreshSwarmFor,
4346
} from '../../session/apis/snode_api/snodePool';
4447
import { ConfigurationSync } from '../../session/utils/job_runners/jobs/ConfigurationSyncJob';
48+
import { getIsModalVisble } from '../../state/selectors/modal';
4549
import { useIsDarkTheme } from '../../state/selectors/theme';
4650
import { switchThemeTo } from '../../themes/switchTheme';
4751
import { ReleasedFeatures } from '../../util/releaseFeature';
4852
import { getOppositeTheme } from '../../util/theme';
4953
import { SessionNotificationCount } from '../icon/SessionNotificationCount';
50-
import { useHotkey } from '../../hooks/useHotkey';
51-
import { getIsModalVisble } from '../../state/selectors/modal';
5254

5355
const Section = (props: { type: SectionType }) => {
5456
const ourNumber = useSelector(getOurNumber);
@@ -238,6 +240,19 @@ export const ActionsPanel = () => {
238240
return () => clearTimeout(timeout);
239241
}, []);
240242

243+
const globalUnreadMessageCount = useSelector(getGlobalUnreadMessageCount);
244+
245+
// Reuse the unreadToShow from the global state to update the badge count
246+
useThrottleFn(
247+
(unreadCount: number) => {
248+
if (globalUnreadMessageCount !== undefined) {
249+
ipcRenderer.send('update-badge-count', unreadCount);
250+
}
251+
},
252+
2000,
253+
[globalUnreadMessageCount]
254+
);
255+
241256
useInterval(cleanUpOldDecryptedMedias, startCleanUpMedia ? cleanUpMediasInterval : null);
242257

243258
useFetchLatestReleaseFromFileServer();

ts/mains/main_node.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
dialog,
1111
protocol as electronProtocol,
1212
ipcMain as ipc,
13+
ipcMain,
1314
IpcMainEvent,
1415
Menu,
1516
nativeTheme,
@@ -27,7 +28,7 @@ import { platform as osPlatform } from 'process';
2728
import url from 'url';
2829

2930
import Logger from 'bunyan';
30-
import _, { isEmpty } from 'lodash';
31+
import _, { isEmpty, isNumber, isFinite } from 'lodash';
3132
import pify from 'pify';
3233

3334
import { setupGlobalErrorHandler } from '../node/global_errors'; // checked - only node
@@ -1019,6 +1020,14 @@ ipc.on('get-start-in-tray', event => {
10191020
}
10201021
});
10211022

1023+
ipcMain.on('update-badge-count', (_event, count) => {
1024+
if (app.isReady()) {
1025+
app.setBadgeCount(
1026+
isNumber(count) && isFinite(count) && count >= 0 ? count : 0
1027+
);
1028+
}
1029+
});
1030+
10221031
ipc.on('get-opengroup-pruning', event => {
10231032
try {
10241033
const val = userConfig.get('opengroupPruning');

0 commit comments

Comments
 (0)