Skip to content
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
44 changes: 30 additions & 14 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ app.setAsDefaultProtocolClient(protocol);
const appUpdater = new AppUpdater(mb, menuBuilder);

let shouldUseAlternateIdleIcon = false;
let shouldUseUnreadActiveIcon = false;

app.whenReady().then(async () => {
await onFirstRunMaybe();
Expand Down Expand Up @@ -160,14 +161,25 @@ app.whenReady().then(async () => {
},
);

onMainEvent(
EVENTS.USE_UNREAD_ACTIVE_ICON,
(_, useUnreadActiveIcon: boolean) => {
shouldUseUnreadActiveIcon = useUnreadActiveIcon;

if (!shouldUseUnreadActiveIcon) {
setIdleIcon();
}
},
);

onMainEvent(EVENTS.ICON_ERROR, () => {
if (!mb.tray.isDestroyed()) {
mb.tray.setImage(TrayIcons.error);
}
});

onMainEvent(EVENTS.ICON_ACTIVE, () => {
if (!mb.tray.isDestroyed()) {
if (!mb.tray.isDestroyed() && shouldUseUnreadActiveIcon) {
mb.tray.setImage(
menuBuilder.isUpdateAvailable()
? TrayIcons.activeWithUpdate
Expand All @@ -178,19 +190,7 @@ app.whenReady().then(async () => {

onMainEvent(EVENTS.ICON_IDLE, () => {
if (!mb.tray.isDestroyed()) {
if (shouldUseAlternateIdleIcon) {
mb.tray.setImage(
menuBuilder.isUpdateAvailable()
? TrayIcons.idleAlternateWithUpdate
: TrayIcons.idleAlternate,
);
} else {
mb.tray.setImage(
menuBuilder.isUpdateAvailable()
? TrayIcons.idleWithUpdate
: TrayIcons.idle,
);
}
setIdleIcon();
}
});

Expand Down Expand Up @@ -258,3 +258,19 @@ const handleURL = (url: string) => {
sendRendererEvent(mb, EVENTS.AUTH_CALLBACK, url);
}
};

function setIdleIcon() {
if (shouldUseAlternateIdleIcon) {
mb.tray.setImage(
menuBuilder.isUpdateAvailable()
? TrayIcons.idleAlternateWithUpdate
: TrayIcons.idleAlternate,
);
} else {
mb.tray.setImage(
menuBuilder.isUpdateAvailable()
? TrayIcons.idleWithUpdate
: TrayIcons.idle,
);
}
}
3 changes: 3 additions & 0 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export const api = {

useAlternateIdleIcon: (value: boolean) =>
sendMainEvent(EVENTS.USE_ALTERNATE_IDLE_ICON, value),

useUnreadActiveIcon: (value: boolean) =>
sendMainEvent(EVENTS.USE_UNREAD_ACTIVE_ICON, value),
},

notificationSoundPath: () => invokeMainEvent(EVENTS.NOTIFICATION_SOUND_PATH),
Expand Down
1 change: 1 addition & 0 deletions src/renderer/__helpers__/jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ window.gitify = {
updateIcon: jest.fn(),
updateTitle: jest.fn(),
useAlternateIdleIcon: jest.fn(),
useUnreadActiveIcon: jest.fn(),
},
notificationSoundPath: jest.fn(),
onAuthCallback: jest.fn(),
Expand Down
10 changes: 8 additions & 2 deletions src/renderer/__mocks__/state-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
type SystemSettingsState,
Theme,
type Token,
type TraySettingsState,
} from '../types';

export const mockGitifyUser: GitifyUser = {
Expand Down Expand Up @@ -96,14 +97,18 @@ const mockNotificationSettings: NotificationSettingsState = {
delayNotificationState: false,
};

const mockTraySettings: TraySettingsState = {
showNotificationsCountInTray: true,
useUnreadActiveIcon: true,
useAlternateIdleIcon: false,
};

const mockSystemSettings: SystemSettingsState = {
openLinks: OpenPreference.FOREGROUND,
keyboardShortcut: true,
showNotificationsCountInTray: true,
showNotifications: true,
playSound: true,
notificationVolume: 20,
useAlternateIdleIcon: false,
openAtStartup: false,
};

Expand All @@ -119,6 +124,7 @@ const mockFilters: FilterSettingsState = {
export const mockSettings: SettingsState = {
...mockAppearanceSettings,
...mockNotificationSettings,
...mockTraySettings,
...mockSystemSettings,
...mockFilters,
};
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/fields/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const Tooltip: FC<ITooltip> = (props: ITooltip) => {
>
<QuestionIcon className="text-gitify-tooltip-icon" />
{showTooltip && (
<div className="absolute left-[-80px] z-10 w-60 rounded-sm border border-gray-300 p-2 shadow-sm bg-gitify-tooltip-popout">
<div className="absolute left-[-80px] z-10 w-30 rounded-sm border border-gray-300 p-2 shadow-sm bg-gitify-tooltip-popout">
<div className="text-left text-xs text-gitify-font">
{props.tooltip}
</div>
Expand Down

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

47 changes: 0 additions & 47 deletions src/renderer/components/settings/SystemSettings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,6 @@ describe('renderer/components/settings/SystemSettings.tsx', () => {
expect(updateSetting).toHaveBeenCalledWith('keyboardShortcut', false);
});

it('should toggle the showNotificationsCountInTray checkbox', async () => {
await act(async () => {
render(
<AppContext.Provider
value={{
auth: mockAuth,
settings: mockSettings,
updateSetting,
}}
>
<SystemSettings />
</AppContext.Provider>,
);
});

await userEvent.click(
screen.getByTestId('checkbox-showNotificationsCountInTray'),
);

expect(updateSetting).toHaveBeenCalledTimes(1);
expect(updateSetting).toHaveBeenCalledWith(
'showNotificationsCountInTray',
false,
);
});

it('should toggle the showNotifications checkbox', async () => {
await act(async () => {
render(
Expand Down Expand Up @@ -197,27 +171,6 @@ describe('renderer/components/settings/SystemSettings.tsx', () => {
});
});

it('should toggle the useAlternateIdleIcon checkbox', async () => {
await act(async () => {
render(
<AppContext.Provider
value={{
auth: mockAuth,
settings: mockSettings,
updateSetting,
}}
>
<SystemSettings />
</AppContext.Provider>,
);
});

await userEvent.click(screen.getByTestId('checkbox-useAlternateIdleIcon'));

expect(updateSetting).toHaveBeenCalledTimes(1);
expect(updateSetting).toHaveBeenCalledWith('useAlternateIdleIcon', true);
});

it('should toggle the openAtStartup checkbox', async () => {
await act(async () => {
render(
Expand Down
31 changes: 0 additions & 31 deletions src/renderer/components/settings/SystemSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,6 @@ export const SystemSettings: FC = () => {
}
/>

<Checkbox
checked={settings.showNotificationsCountInTray}
label="Show notification count in tray"
name="showNotificationsCountInTray"
onChange={(evt) =>
updateSetting('showNotificationsCountInTray', evt.target.checked)
}
visible={window.gitify.platform.isMacOS()}
/>

<Checkbox
checked={settings.showNotifications}
label="Show system notifications"
Expand Down Expand Up @@ -141,27 +131,6 @@ export const SystemSettings: FC = () => {
</ButtonGroup>
</Stack>

<Checkbox
checked={settings.useAlternateIdleIcon}
label="Use alternate idle icon"
name="useAlternateIdleIcon"
onChange={(evt) =>
updateSetting('useAlternateIdleIcon', evt.target.checked)
}
tooltip={
<Stack direction="vertical" gap="condensed">
<Text>
Use a white {APPLICATION.NAME} logo (instead of the default
black logo) when all notifications are read.
</Text>
<Text>
This is particularly useful for devices which have a dark-themed
menubar or taskbar.
</Text>
</Stack>
}
/>

<Checkbox
checked={settings.openAtStartup}
label="Open at startup"
Expand Down
82 changes: 82 additions & 0 deletions src/renderer/components/settings/TraySettings.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { act, render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { mockAuth, mockSettings } from '../../__mocks__/state-mocks';
import { AppContext } from '../../context/App';
import { TraySettings } from './TraySettings';

describe('renderer/components/settings/TraySettings.tsx', () => {
const updateSetting = jest.fn();

afterEach(() => {
jest.clearAllMocks();
});

it('should toggle the showNotificationsCountInTray checkbox', async () => {
await act(async () => {
render(
<AppContext.Provider
value={{
auth: mockAuth,
settings: mockSettings,
updateSetting,
}}
>
<TraySettings />
</AppContext.Provider>,
);
});

await userEvent.click(
screen.getByTestId('checkbox-showNotificationsCountInTray'),
);

expect(updateSetting).toHaveBeenCalledTimes(1);
expect(updateSetting).toHaveBeenCalledWith(
'showNotificationsCountInTray',
false,
);
});

it('should toggle the useUnreadActiveIcon checkbox', async () => {
await act(async () => {
render(
<AppContext.Provider
value={{
auth: mockAuth,
settings: mockSettings,
updateSetting,
}}
>
<TraySettings />
</AppContext.Provider>,
);
});

await userEvent.click(screen.getByTestId('checkbox-useUnreadActiveIcon'));

expect(updateSetting).toHaveBeenCalledTimes(1);
expect(updateSetting).toHaveBeenCalledWith('useUnreadActiveIcon', false);
});

it('should toggle the useAlternateIdleIcon checkbox', async () => {
await act(async () => {
render(
<AppContext.Provider
value={{
auth: mockAuth,
settings: mockSettings,
updateSetting,
}}
>
<TraySettings />
</AppContext.Provider>,
);
});

await userEvent.click(screen.getByTestId('checkbox-useAlternateIdleIcon'));

expect(updateSetting).toHaveBeenCalledTimes(1);
expect(updateSetting).toHaveBeenCalledWith('useAlternateIdleIcon', true);
});
});
Loading