Skip to content

Commit 3744758

Browse files
authored
feat: error tray icon (#1742)
Signed-off-by: Adam Setch <[email protected]>
1 parent 778d9f7 commit 3744758

File tree

15 files changed

+71
-45
lines changed

15 files changed

+71
-45
lines changed

assets/images/tray-error.png

1.88 KB
Loading

assets/images/[email protected]

3.21 KB
Loading

src/main/icons.test.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@ describe('main/icons.ts', () => {
44
it('should return icon images', () => {
55
expect(TrayIcons.active).toContain('assets/images/tray-active.png');
66

7-
expect(TrayIcons.activeUpdateIcon).toContain(
7+
expect(TrayIcons.activeWithUpdate).toContain(
88
'assets/images/tray-active-update.png',
99
);
1010

1111
expect(TrayIcons.idle).toContain('assets/images/tray-idleTemplate.png');
1212

13-
expect(TrayIcons.idleUpdateIcon).toContain(
13+
expect(TrayIcons.idleWithUpdate).toContain(
1414
'assets/images/tray-idle-update.png',
1515
);
1616

1717
expect(TrayIcons.idleAlternate).toContain(
1818
'assets/images/tray-idle-white.png',
1919
);
2020

21-
expect(TrayIcons.idleAlternateUpdateIcon).toContain(
21+
expect(TrayIcons.idleAlternateWithUpdate).toContain(
2222
'assets/images/tray-idle-white-update.png',
2323
);
24+
25+
expect(TrayIcons.error).toContain('assets/images/tray-error.png');
2426
});
2527
});

src/main/icons.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import path from 'node:path';
22

33
export const TrayIcons = {
44
active: getIconPath('tray-active.png'),
5-
activeUpdateIcon: getIconPath('tray-active-update.png'),
5+
activeWithUpdate: getIconPath('tray-active-update.png'),
66
idle: getIconPath('tray-idleTemplate.png'),
7-
idleUpdateIcon: getIconPath('tray-idle-update.png'),
7+
idleWithUpdate: getIconPath('tray-idle-update.png'),
88
idleAlternate: getIconPath('tray-idle-white.png'),
9-
idleAlternateUpdateIcon: getIconPath('tray-idle-white-update.png'),
9+
idleAlternateWithUpdate: getIconPath('tray-idle-white-update.png'),
10+
error: getIconPath('tray-error.png'),
1011
};
1112

1213
function getIconPath(iconName: string) {

src/main/main.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,17 @@ app.whenReady().then(async () => {
118118
},
119119
);
120120

121+
ipc.on(namespacedEvent('icon-error'), () => {
122+
if (!mb.tray.isDestroyed()) {
123+
mb.tray.setImage(TrayIcons.error);
124+
}
125+
});
126+
121127
ipc.on(namespacedEvent('icon-active'), () => {
122128
if (!mb.tray.isDestroyed()) {
123129
mb.tray.setImage(
124130
menuBuilder.isUpdateAvailable()
125-
? TrayIcons.activeUpdateIcon
131+
? TrayIcons.activeWithUpdate
126132
: TrayIcons.active,
127133
);
128134
}
@@ -133,13 +139,13 @@ app.whenReady().then(async () => {
133139
if (shouldUseAlternateIdleIcon) {
134140
mb.tray.setImage(
135141
menuBuilder.isUpdateAvailable()
136-
? TrayIcons.idleAlternateUpdateIcon
142+
? TrayIcons.idleAlternateWithUpdate
137143
: TrayIcons.idleAlternate,
138144
);
139145
} else {
140146
mb.tray.setImage(
141147
menuBuilder.isUpdateAvailable()
142-
? TrayIcons.idleUpdateIcon
148+
? TrayIcons.idleWithUpdate
143149
: TrayIcons.idle,
144150
);
145151
}

src/renderer/components/Oops.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const Oops: FC<IOops> = ({ error }: IOops) => {
1818
return (
1919
<Centered>
2020
<Stack direction="vertical" align="center">
21-
<div className="mt-2 mb-5 text-5xl">
21+
<div className="mt-2 text-5xl">
2222
<EmojiText text={emoji} />
2323
</div>
2424

src/renderer/components/__snapshots__/AllRead.test.tsx.snap

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderer/components/__snapshots__/Oops.test.tsx.snap

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderer/components/notifications/__snapshots__/AccountNotifications.test.tsx.snap

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderer/components/primitives/Centered.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface ICentered {
66

77
export const Centered: FC<ICentered> = (props: ICentered) => {
88
return (
9-
<div className="flex flex-1 flex-col items-center justify-center min-h-screen">
9+
<div className="flex flex-1 flex-col items-center justify-center p-8 min-h-screen">
1010
{props.children}
1111
</div>
1212
);

src/renderer/components/primitives/__snapshots__/Centered.test.tsx.snap

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderer/hooks/useNotifications.ts

+16-14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
markNotificationThreadAsDone,
1515
markNotificationThreadAsRead,
1616
} from '../utils/api/client';
17+
import { updateTrayIcon } from '../utils/comms';
1718
import { isMarkAsDoneFeatureSupported } from '../utils/features';
1819
import { triggerNativeNotifications } from '../utils/notifications/native';
1920
import {
@@ -73,26 +74,27 @@ export const useNotifications = (): NotificationsState => {
7374
const fetchedNotifications = await getAllNotifications(state);
7475

7576
// Set Global Error if all accounts have the same error
76-
if (fetchNotifications.length > 0) {
77-
const allAccountsHaveErrors = fetchedNotifications.every((account) => {
77+
const allAccountsHaveErrors =
78+
fetchedNotifications.length > 0 &&
79+
fetchedNotifications.every((account) => {
7880
return account.error !== null;
7981
});
8082

81-
let accountErrorsAreAllSame = true;
82-
const accountError = fetchedNotifications[0]?.error;
83+
let accountErrorsAreAllSame = true;
84+
const accountError = fetchedNotifications[0]?.error;
8385

84-
for (const fetchedNotification of fetchedNotifications) {
85-
if (accountError !== fetchedNotification.error) {
86-
accountErrorsAreAllSame = false;
87-
break;
88-
}
86+
for (const fetchedNotification of fetchedNotifications) {
87+
if (accountError !== fetchedNotification.error) {
88+
accountErrorsAreAllSame = false;
89+
break;
8990
}
91+
}
9092

91-
if (allAccountsHaveErrors) {
92-
setStatus('error');
93-
setGlobalError(accountErrorsAreAllSame ? accountError : null);
94-
return;
95-
}
93+
if (allAccountsHaveErrors) {
94+
setStatus('error');
95+
setGlobalError(accountErrorsAreAllSame ? accountError : null);
96+
updateTrayIcon(-1);
97+
return;
9698
}
9799

98100
setNotifications(fetchedNotifications);

src/renderer/routes/__snapshots__/Login.test.tsx.snap

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderer/utils/comms.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,13 @@ describe('renderer/utils/comms.ts', () => {
162162
expect(ipcRenderer.send).toHaveBeenCalledTimes(1);
163163
expect(ipcRenderer.send).toHaveBeenCalledWith(namespacedEvent('icon-idle'));
164164
});
165+
166+
it('should send mark the icons as error', () => {
167+
const notificationsLength = -1;
168+
updateTrayIcon(notificationsLength);
169+
expect(ipcRenderer.send).toHaveBeenCalledTimes(1);
170+
expect(ipcRenderer.send).toHaveBeenCalledWith(
171+
namespacedEvent('icon-error'),
172+
);
173+
});
165174
});

src/renderer/utils/comms.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,17 @@ export function setKeyboardShortcut(keyboardShortcut: boolean): void {
5555
}
5656

5757
export function updateTrayIcon(notificationsLength = 0): void {
58+
if (notificationsLength < 0) {
59+
ipcRenderer.send(namespacedEvent('icon-error'));
60+
return;
61+
}
62+
5863
if (notificationsLength > 0) {
5964
ipcRenderer.send(namespacedEvent('icon-active'));
60-
} else {
61-
ipcRenderer.send(namespacedEvent('icon-idle'));
65+
return;
6266
}
67+
68+
ipcRenderer.send(namespacedEvent('icon-idle'));
6369
}
6470

6571
export function updateTrayTitle(title = ''): void {

0 commit comments

Comments
 (0)