From 8e1bab88d97b68e49f4ea5a02d7a0ba9286b778b Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sat, 30 Mar 2024 06:45:28 -0400 Subject: [PATCH 1/8] feat: show notification count in tray --- main.js | 5 +++++ src/__mocks__/mock-state.ts | 1 + src/context/App.tsx | 1 + src/routes/Settings.tsx | 15 ++++++++++++++- src/types.ts | 1 + src/utils/comms.ts | 4 ++++ 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index a6d61e19b..84ff3181e 100644 --- a/main.js +++ b/main.js @@ -75,6 +75,11 @@ menubarApp.on('ready', () => { } } }); + ipcMain.on('update-title', (_, arg) => { + if (!menubarApp.tray.isDestroyed()) { + menubarApp.tray.setTitle(String(arg)); + } + }); ipcMain.on('set-login-item-settings', (event, settings) => { app.setLoginItemSettings(settings); }); diff --git a/src/__mocks__/mock-state.ts b/src/__mocks__/mock-state.ts index 8175a7f1d..af03be21b 100644 --- a/src/__mocks__/mock-state.ts +++ b/src/__mocks__/mock-state.ts @@ -12,6 +12,7 @@ export const mockSettings: SettingsState = { playSound: true, showNotifications: true, showBots: true, + showNotificationsCountInTray: false, openAtStartup: false, appearance: Appearance.SYSTEM, colors: false, diff --git a/src/context/App.tsx b/src/context/App.tsx index 3da7ba375..5b1d7ba1c 100644 --- a/src/context/App.tsx +++ b/src/context/App.tsx @@ -35,6 +35,7 @@ export const defaultSettings: SettingsState = { playSound: true, showNotifications: true, showBots: true, + showNotificationsCountInTray: false, openAtStartup: false, appearance: Appearance.SYSTEM, colors: null, diff --git a/src/routes/Settings.tsx b/src/routes/Settings.tsx index 1c218bacf..c4b54a05e 100644 --- a/src/routes/Settings.tsx +++ b/src/routes/Settings.tsx @@ -20,7 +20,11 @@ import { AppContext } from '../context/App'; import { Appearance } from '../types'; import { apiRequestAuth } from '../utils/api-requests'; import { setAppearance } from '../utils/appearance'; -import { openExternalLink, updateTrayIcon } from '../utils/comms'; +import { + openExternalLink, + updateTrayIcon, + updateTrayTitle, +} from '../utils/comms'; import Constants from '../utils/constants'; import { generateGitHubAPIUrl } from '../utils/helpers'; @@ -71,6 +75,7 @@ export const SettingsRoute: React.FC = () => { logout(); navigate(-1); updateTrayIcon(); + updateTrayTitle(); }, []); const quitApp = useCallback(() => { @@ -152,6 +157,14 @@ export const SettingsRoute: React.FC = () => { checked={settings.showBots} onChange={(evt) => updateSetting('showBots', evt.target.checked)} /> + + updateSetting('showNotificationsCountInTray', evt.target.checked) + } + /> Date: Mon, 1 Apr 2024 09:11:15 -0400 Subject: [PATCH 2/8] feat: update title --- src/context/App.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/context/App.tsx b/src/context/App.tsx index 5b1d7ba1c..f86059be7 100644 --- a/src/context/App.tsx +++ b/src/context/App.tsx @@ -19,10 +19,11 @@ import { import { apiRequestAuth } from '../utils/api-requests'; import { setAppearance } from '../utils/appearance'; import { addAccount, authGitHub, getToken, getUserData } from '../utils/auth'; -import { setAutoLaunch } from '../utils/comms'; +import { setAutoLaunch, updateTrayTitle } from '../utils/comms'; import Constants from '../utils/constants'; import { generateGitHubAPIUrl } from '../utils/helpers'; import { clearState, loadState, saveState } from '../utils/storage'; +import { getNotificationCount } from '../utils/notifications'; const defaultAccounts: AuthState = { token: null, @@ -99,6 +100,16 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => { fetchNotifications(accounts, settings); }, [accounts.token, accounts.enterpriseAccounts.length]); + useEffect(() => { + const count = getNotificationCount(notifications); + + if (settings.showNotificationsCountInTray && count > 0) { + updateTrayTitle(String(count)); + } else { + updateTrayTitle(); + } + }, [settings.showNotificationsCountInTray, notifications]); + useInterval(() => { fetchNotifications(accounts, settings); }, 60000); From 258146b58fecaa8c76b23acc425c92794a6da840 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 1 Apr 2024 09:16:26 -0400 Subject: [PATCH 3/8] feat: update title --- main.js | 4 ++-- src/context/App.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index 84ff3181e..832a0162a 100644 --- a/main.js +++ b/main.js @@ -75,9 +75,9 @@ menubarApp.on('ready', () => { } } }); - ipcMain.on('update-title', (_, arg) => { + ipcMain.on('update-title', (_, title) => { if (!menubarApp.tray.isDestroyed()) { - menubarApp.tray.setTitle(String(arg)); + menubarApp.tray.setTitle(title); } }); ipcMain.on('set-login-item-settings', (event, settings) => { diff --git a/src/context/App.tsx b/src/context/App.tsx index f86059be7..6ae4964d6 100644 --- a/src/context/App.tsx +++ b/src/context/App.tsx @@ -104,7 +104,7 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => { const count = getNotificationCount(notifications); if (settings.showNotificationsCountInTray && count > 0) { - updateTrayTitle(String(count)); + updateTrayTitle(count.toString()); } else { updateTrayTitle(); } From 9d7603fa2649895ceeedf70ec1a05074a1c2adc8 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 1 Apr 2024 09:19:30 -0400 Subject: [PATCH 4/8] test: update snapshots --- .../__snapshots__/Settings.test.tsx.snap | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/routes/__snapshots__/Settings.test.tsx.snap b/src/routes/__snapshots__/Settings.test.tsx.snap index 2fa0d6d38..9dfcd1bb7 100644 --- a/src/routes/__snapshots__/Settings.test.tsx.snap +++ b/src/routes/__snapshots__/Settings.test.tsx.snap @@ -230,6 +230,29 @@ exports[`routes/Settings.tsx should render itself & its children 1`] = ` +
+
+ +
+
+ +
+
From 2edc471445822793159d433f0c77e3fe1b9d89d3 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Tue, 2 Apr 2024 06:11:40 -0400 Subject: [PATCH 5/8] fix test --- src/routes/Settings.test.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/routes/Settings.test.tsx b/src/routes/Settings.test.tsx index 3e36c9da1..4beabc1fe 100644 --- a/src/routes/Settings.test.tsx +++ b/src/routes/Settings.test.tsx @@ -71,8 +71,9 @@ describe('routes/Settings.tsx', () => { expect(logoutMock).toHaveBeenCalledTimes(1); - expect(ipcRenderer.send).toHaveBeenCalledTimes(1); + expect(ipcRenderer.send).toHaveBeenCalledTimes(2); expect(ipcRenderer.send).toHaveBeenCalledWith('update-icon'); + expect(ipcRenderer.send).toHaveBeenCalledWith('update-title', ''); expect(mockNavigate).toHaveBeenNthCalledWith(1, -1); }); From 139bf2d68b908340053d203b998fbb1a3201762a Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Tue, 2 Apr 2024 06:18:41 -0400 Subject: [PATCH 6/8] fix test --- src/context/App.test.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/context/App.test.tsx b/src/context/App.test.tsx index 63d0e8bfa..ce6740e9b 100644 --- a/src/context/App.test.tsx +++ b/src/context/App.test.tsx @@ -285,12 +285,13 @@ describe('context/App.tsx', () => { expect(saveStateMock).toHaveBeenCalledWith( { enterpriseAccounts: [], token: null, user: null }, { - appearance: 'SYSTEM', - openAtStartup: false, participating: true, playSound: true, showNotifications: true, showBots: true, + showNotificationsCountInTray: false, + openAtStartup: false, + appearance: 'SYSTEM', colors: null, markAsDoneOnOpen: false, }, @@ -324,12 +325,13 @@ describe('context/App.tsx', () => { expect(saveStateMock).toHaveBeenCalledWith( { enterpriseAccounts: [], token: null, user: null }, { - appearance: 'SYSTEM', - openAtStartup: true, participating: false, playSound: true, showNotifications: true, showBots: true, + showNotificationsCountInTray: false, + openAtStartup: true, + appearance: 'SYSTEM', colors: null, markAsDoneOnOpen: false, }, From fe1ea19c5498448b8f0af515a1d19450e3532f9d Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Tue, 2 Apr 2024 06:32:00 -0400 Subject: [PATCH 7/8] fix test --- src/context/App.test.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/context/App.test.tsx b/src/context/App.test.tsx index ce6740e9b..c3b3dc634 100644 --- a/src/context/App.test.tsx +++ b/src/context/App.test.tsx @@ -8,6 +8,7 @@ import { useNotifications } from '../hooks/useNotifications'; import * as apiRequests from '../utils/api-requests'; import * as comms from '../utils/comms'; import * as storage from '../utils/storage'; +import * as notifications from '../utils/notifications'; jest.mock('../hooks/useNotifications'); @@ -35,6 +36,11 @@ describe('context/App.tsx', () => { describe('api methods', () => { const apiRequestAuthMock = jest.spyOn(apiRequests, 'apiRequestAuth'); + const getNotificationCountMock = jest.spyOn( + notifications, + 'getNotificationCount', + ); + getNotificationCountMock.mockReturnValue(1); const fetchNotificationsMock = jest.fn(); const markNotificationMock = jest.fn(); From db4b05a46017ce247bf810256a15a8bba4c3e1dc Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Tue, 2 Apr 2024 06:47:57 -0400 Subject: [PATCH 8/8] test: add coverage --- src/routes/Settings.test.tsx | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/routes/Settings.test.tsx b/src/routes/Settings.test.tsx index 4beabc1fe..065fe3e23 100644 --- a/src/routes/Settings.test.tsx +++ b/src/routes/Settings.test.tsx @@ -156,6 +156,37 @@ describe('routes/Settings.tsx', () => { expect(updateSetting).toHaveBeenCalledWith('showBots', false); }); + it('should toggle the showNotificationsCountInTray checkbox', async () => { + let getByLabelText; + + await act(async () => { + const { getByLabelText: getByLabelTextLocal } = render( + + + + + , + ); + getByLabelText = getByLabelTextLocal; + }); + + fireEvent.click(getByLabelText('Show notifications count in tray'), { + target: { checked: true }, + }); + + expect(updateSetting).toHaveBeenCalledTimes(1); + expect(updateSetting).toHaveBeenCalledWith( + 'showNotificationsCountInTray', + false, + ); + }); + it('should toggle the playSound checkbox', async () => { let getByLabelText;