Skip to content

feat: error tray icon #1742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/images/tray-error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/tray-error@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions src/main/icons.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@ describe('main/icons.ts', () => {
it('should return icon images', () => {
expect(TrayIcons.active).toContain('assets/images/tray-active.png');

expect(TrayIcons.activeUpdateIcon).toContain(
expect(TrayIcons.activeWithUpdate).toContain(
'assets/images/tray-active-update.png',
);

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

expect(TrayIcons.idleUpdateIcon).toContain(
expect(TrayIcons.idleWithUpdate).toContain(
'assets/images/tray-idle-update.png',
);

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

expect(TrayIcons.idleAlternateUpdateIcon).toContain(
expect(TrayIcons.idleAlternateWithUpdate).toContain(
'assets/images/tray-idle-white-update.png',
);

expect(TrayIcons.error).toContain('assets/images/tray-error.png');
});
});
7 changes: 4 additions & 3 deletions src/main/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import path from 'node:path';

export const TrayIcons = {
active: getIconPath('tray-active.png'),
activeUpdateIcon: getIconPath('tray-active-update.png'),
activeWithUpdate: getIconPath('tray-active-update.png'),
idle: getIconPath('tray-idleTemplate.png'),
idleUpdateIcon: getIconPath('tray-idle-update.png'),
idleWithUpdate: getIconPath('tray-idle-update.png'),
idleAlternate: getIconPath('tray-idle-white.png'),
idleAlternateUpdateIcon: getIconPath('tray-idle-white-update.png'),
idleAlternateWithUpdate: getIconPath('tray-idle-white-update.png'),
error: getIconPath('tray-error.png'),
};

function getIconPath(iconName: string) {
Expand Down
12 changes: 9 additions & 3 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,17 @@ app.whenReady().then(async () => {
},
);

ipc.on(namespacedEvent('icon-error'), () => {
if (!mb.tray.isDestroyed()) {
mb.tray.setImage(TrayIcons.error);
}
});

ipc.on(namespacedEvent('icon-active'), () => {
if (!mb.tray.isDestroyed()) {
mb.tray.setImage(
menuBuilder.isUpdateAvailable()
? TrayIcons.activeUpdateIcon
? TrayIcons.activeWithUpdate
: TrayIcons.active,
);
}
Expand All @@ -133,13 +139,13 @@ app.whenReady().then(async () => {
if (shouldUseAlternateIdleIcon) {
mb.tray.setImage(
menuBuilder.isUpdateAvailable()
? TrayIcons.idleAlternateUpdateIcon
? TrayIcons.idleAlternateWithUpdate
: TrayIcons.idleAlternate,
);
} else {
mb.tray.setImage(
menuBuilder.isUpdateAvailable()
? TrayIcons.idleUpdateIcon
? TrayIcons.idleWithUpdate
: TrayIcons.idle,
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/Oops.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const Oops: FC<IOops> = ({ error }: IOops) => {
return (
<Centered>
<Stack direction="vertical" align="center">
<div className="mt-2 mb-5 text-5xl">
<div className="mt-2 text-5xl">
<EmojiText text={emoji} />
</div>

Expand Down
8 changes: 4 additions & 4 deletions src/renderer/components/__snapshots__/AllRead.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/renderer/components/__snapshots__/Oops.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/renderer/components/primitives/Centered.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface ICentered {

export const Centered: FC<ICentered> = (props: ICentered) => {
return (
<div className="flex flex-1 flex-col items-center justify-center min-h-screen">
<div className="flex flex-1 flex-col items-center justify-center p-8 min-h-screen">
{props.children}
</div>
);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 16 additions & 14 deletions src/renderer/hooks/useNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
markNotificationThreadAsDone,
markNotificationThreadAsRead,
} from '../utils/api/client';
import { updateTrayIcon } from '../utils/comms';
import { isMarkAsDoneFeatureSupported } from '../utils/features';
import { triggerNativeNotifications } from '../utils/notifications/native';
import {
Expand Down Expand Up @@ -73,26 +74,27 @@ export const useNotifications = (): NotificationsState => {
const fetchedNotifications = await getAllNotifications(state);

// Set Global Error if all accounts have the same error
if (fetchNotifications.length > 0) {
const allAccountsHaveErrors = fetchedNotifications.every((account) => {
const allAccountsHaveErrors =
fetchedNotifications.length > 0 &&
fetchedNotifications.every((account) => {
return account.error !== null;
});

let accountErrorsAreAllSame = true;
const accountError = fetchedNotifications[0]?.error;
let accountErrorsAreAllSame = true;
const accountError = fetchedNotifications[0]?.error;

for (const fetchedNotification of fetchedNotifications) {
if (accountError !== fetchedNotification.error) {
accountErrorsAreAllSame = false;
break;
}
for (const fetchedNotification of fetchedNotifications) {
if (accountError !== fetchedNotification.error) {
accountErrorsAreAllSame = false;
break;
}
}

if (allAccountsHaveErrors) {
setStatus('error');
setGlobalError(accountErrorsAreAllSame ? accountError : null);
return;
}
if (allAccountsHaveErrors) {
setStatus('error');
setGlobalError(accountErrorsAreAllSame ? accountError : null);
updateTrayIcon(-1);
return;
}

setNotifications(fetchedNotifications);
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/routes/__snapshots__/Login.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/renderer/utils/comms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,13 @@ describe('renderer/utils/comms.ts', () => {
expect(ipcRenderer.send).toHaveBeenCalledTimes(1);
expect(ipcRenderer.send).toHaveBeenCalledWith(namespacedEvent('icon-idle'));
});

it('should send mark the icons as error', () => {
const notificationsLength = -1;
updateTrayIcon(notificationsLength);
expect(ipcRenderer.send).toHaveBeenCalledTimes(1);
expect(ipcRenderer.send).toHaveBeenCalledWith(
namespacedEvent('icon-error'),
);
});
});
10 changes: 8 additions & 2 deletions src/renderer/utils/comms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,17 @@ export function setKeyboardShortcut(keyboardShortcut: boolean): void {
}

export function updateTrayIcon(notificationsLength = 0): void {
if (notificationsLength < 0) {
ipcRenderer.send(namespacedEvent('icon-error'));
return;
}

if (notificationsLength > 0) {
ipcRenderer.send(namespacedEvent('icon-active'));
} else {
ipcRenderer.send(namespacedEvent('icon-idle'));
return;
}

ipcRenderer.send(namespacedEvent('icon-idle'));
}

export function updateTrayTitle(title = ''): void {
Expand Down
Loading