Skip to content

Commit

Permalink
Merge pull request #3216 from burtonemily/notifications-dot
Browse files Browse the repository at this point in the history
feat: adds in notifications dot: updated setBadgeCount and using glob…
  • Loading branch information
Bilb authored Nov 11, 2024
2 parents 8fdbe4a + ca81a50 commit 5f69acd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
19 changes: 17 additions & 2 deletions ts/components/leftpane/ActionsPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { ipcRenderer } from 'electron';
import { debounce } from 'lodash';
import { useEffect, useRef, useState } from 'react';

import { useDispatch, useSelector } from 'react-redux';
import useInterval from 'react-use/lib/useInterval';
import useTimeoutFn from 'react-use/lib/useTimeoutFn';
import useThrottleFn from 'react-use/lib/useThrottleFn';

import { Data } from '../../data/data';
import { getConversationController } from '../../session/conversations';
Expand Down Expand Up @@ -37,18 +39,18 @@ import { LeftPaneSectionContainer } from './LeftPaneSectionContainer';

import { SettingsKey } from '../../data/settings-key';
import { useFetchLatestReleaseFromFileServer } from '../../hooks/useFetchLatestReleaseFromFileServer';
import { useHotkey } from '../../hooks/useHotkey';
import {
forceRefreshRandomSnodePool,
getFreshSwarmFor,
} from '../../session/apis/snode_api/snodePool';
import { ConfigurationSync } from '../../session/utils/job_runners/jobs/ConfigurationSyncJob';
import { getIsModalVisble } from '../../state/selectors/modal';
import { useIsDarkTheme } from '../../state/selectors/theme';
import { switchThemeTo } from '../../themes/switchTheme';
import { ReleasedFeatures } from '../../util/releaseFeature';
import { getOppositeTheme } from '../../util/theme';
import { SessionNotificationCount } from '../icon/SessionNotificationCount';
import { useHotkey } from '../../hooks/useHotkey';
import { getIsModalVisble } from '../../state/selectors/modal';

const Section = (props: { type: SectionType }) => {
const ourNumber = useSelector(getOurNumber);
Expand Down Expand Up @@ -238,6 +240,19 @@ export const ActionsPanel = () => {
return () => clearTimeout(timeout);
}, []);

const globalUnreadMessageCount = useSelector(getGlobalUnreadMessageCount);

// Reuse the unreadToShow from the global state to update the badge count
useThrottleFn(
(unreadCount: number) => {
if (globalUnreadMessageCount !== undefined) {
ipcRenderer.send('update-badge-count', unreadCount);
}
},
2000,
[globalUnreadMessageCount]
);

useInterval(cleanUpOldDecryptedMedias, startCleanUpMedia ? cleanUpMediasInterval : null);

useFetchLatestReleaseFromFileServer();
Expand Down
11 changes: 10 additions & 1 deletion ts/mains/main_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
dialog,
protocol as electronProtocol,
ipcMain as ipc,
ipcMain,
IpcMainEvent,
Menu,
nativeTheme,
Expand All @@ -27,7 +28,7 @@ import { platform as osPlatform } from 'process';
import url from 'url';

import Logger from 'bunyan';
import _, { isEmpty } from 'lodash';
import _, { isEmpty, isNumber, isFinite } from 'lodash';
import pify from 'pify';

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

ipcMain.on('update-badge-count', (_event, count) => {
if (app.isReady()) {
app.setBadgeCount(
isNumber(count) && isFinite(count) && count >= 0 ? count : 0
);
}
});

ipc.on('get-opengroup-pruning', event => {
try {
const val = userConfig.get('opengroupPruning');
Expand Down

0 comments on commit 5f69acd

Please sign in to comment.