Skip to content

Commit d9755e7

Browse files
committed
feat(settings): tray icon color
Signed-off-by: Adam Setch <[email protected]>
1 parent ebe1d23 commit d9755e7

File tree

14 files changed

+67
-65
lines changed

14 files changed

+67
-65
lines changed

src/main/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ app.setAsDefaultProtocolClient(protocol);
7575
const appUpdater = new AppUpdater(mb, menuBuilder);
7676

7777
let shouldUseAlternateIdleIcon = false;
78-
let shouldUseTrayIconStatusColors = true;
78+
let shouldUseMonochromeIcon = false;
7979

8080
app.whenReady().then(async () => {
8181
await onFirstRunMaybe();
@@ -161,22 +161,22 @@ app.whenReady().then(async () => {
161161
},
162162
);
163163

164-
onMainEvent(
165-
EVENTS.TRAY_ICON_STATUS_COLORS,
166-
(_, trayIconStatusColors: boolean) => {
167-
shouldUseTrayIconStatusColors = trayIconStatusColors;
164+
onMainEvent(EVENTS.USE_MONOCHROME_ICON, (_, useMonochromeIcon: boolean) => {
165+
shouldUseMonochromeIcon = useMonochromeIcon;
166+
167+
if (shouldUseMonochromeIcon) {
168168
setIdleIcon();
169-
},
170-
);
169+
}
170+
});
171171

172172
onMainEvent(EVENTS.ICON_ERROR, () => {
173-
if (!mb.tray.isDestroyed() && shouldUseTrayIconStatusColors) {
173+
if (!mb.tray.isDestroyed() && !shouldUseMonochromeIcon) {
174174
mb.tray.setImage(TrayIcons.error);
175175
}
176176
});
177177

178178
onMainEvent(EVENTS.ICON_ACTIVE, () => {
179-
if (!mb.tray.isDestroyed() && shouldUseTrayIconStatusColors) {
179+
if (!mb.tray.isDestroyed() && !shouldUseMonochromeIcon) {
180180
mb.tray.setImage(
181181
menuBuilder.isUpdateAvailable()
182182
? TrayIcons.activeWithUpdate

src/preload/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ export const api = {
5151

5252
updateTitle: (title = '') => sendMainEvent(EVENTS.UPDATE_TITLE, title),
5353

54-
trayIconStatusColors: (value: boolean) =>
55-
sendMainEvent(EVENTS.TRAY_ICON_STATUS_COLORS, value),
56-
5754
useAlternateIdleIcon: (value: boolean) =>
5855
sendMainEvent(EVENTS.USE_ALTERNATE_IDLE_ICON, value),
56+
57+
useMonochromeIcon: (value: boolean) =>
58+
sendMainEvent(EVENTS.USE_MONOCHROME_ICON, value),
5959
},
6060

6161
notificationSoundPath: () => invokeMainEvent(EVENTS.NOTIFICATION_SOUND_PATH),

src/renderer/__helpers__/jest.setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ window.gitify = {
2828
tray: {
2929
updateIcon: jest.fn(),
3030
updateTitle: jest.fn(),
31-
trayIconStatusColors: jest.fn(),
3231
useAlternateIdleIcon: jest.fn(),
32+
useMonochromeIcon: jest.fn(),
3333
},
3434
notificationSoundPath: jest.fn(),
3535
onAuthCallback: jest.fn(),

src/renderer/__mocks__/state-mocks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ const mockNotificationSettings: NotificationSettingsState = {
9999

100100
const mockTraySettings: TraySettingsState = {
101101
showNotificationsCountInTray: true,
102+
useMonochromeIcon: false,
102103
useAlternateIdleIcon: false,
103-
trayIconStatusColors: true,
104104
};
105105

106106
const mockSystemSettings: SystemSettingsState = {

src/renderer/components/fields/Tooltip.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const Tooltip: FC<ITooltip> = (props: ITooltip) => {
2222
>
2323
<QuestionIcon className="text-gitify-tooltip-icon" />
2424
{showTooltip && (
25-
<div className="absolute left-[-80px] z-10 w-60 rounded-sm border border-gray-300 p-2 shadow-sm bg-gitify-tooltip-popout">
25+
<div className="absolute left-[-80px] z-10 w-30 rounded-sm border border-gray-300 p-2 shadow-sm bg-gitify-tooltip-popout">
2626
<div className="text-left text-xs text-gitify-font">
2727
{props.tooltip}
2828
</div>

src/renderer/components/fields/__snapshots__/Tooltip.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderer/components/settings/TraySettings.test.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import userEvent from '@testing-library/user-event';
33

44
import { mockAuth, mockSettings } from '../../__mocks__/state-mocks';
55
import { AppContext } from '../../context/App';
6-
import { SystemSettings } from './SystemSettings';
6+
import { TraySettings } from './TraySettings';
77

88
describe('renderer/components/settings/TraySettings.tsx', () => {
99
const updateSetting = jest.fn();
@@ -22,7 +22,7 @@ describe('renderer/components/settings/TraySettings.tsx', () => {
2222
updateSetting,
2323
}}
2424
>
25-
<SystemSettings />
25+
<TraySettings />
2626
</AppContext.Provider>,
2727
);
2828
});
@@ -38,7 +38,7 @@ describe('renderer/components/settings/TraySettings.tsx', () => {
3838
);
3939
});
4040

41-
it('should toggle the useAlternateIdleIcon checkbox', async () => {
41+
it('should toggle the useMonochromeIcon checkbox', async () => {
4242
await act(async () => {
4343
render(
4444
<AppContext.Provider
@@ -48,18 +48,18 @@ describe('renderer/components/settings/TraySettings.tsx', () => {
4848
updateSetting,
4949
}}
5050
>
51-
<SystemSettings />
51+
<TraySettings />
5252
</AppContext.Provider>,
5353
);
5454
});
5555

56-
await userEvent.click(screen.getByTestId('checkbox-useAlternateIdleIcon'));
56+
await userEvent.click(screen.getByTestId('checkbox-useMonochromeIcon'));
5757

5858
expect(updateSetting).toHaveBeenCalledTimes(1);
59-
expect(updateSetting).toHaveBeenCalledWith('useAlternateIdleIcon', true);
59+
expect(updateSetting).toHaveBeenCalledWith('useMonochromeIcon', true);
6060
});
6161

62-
it('should toggle the trayIconStatusColors checkbox', async () => {
62+
it('should toggle the useAlternateIdleIcon checkbox', async () => {
6363
await act(async () => {
6464
render(
6565
<AppContext.Provider
@@ -69,14 +69,14 @@ describe('renderer/components/settings/TraySettings.tsx', () => {
6969
updateSetting,
7070
}}
7171
>
72-
<SystemSettings />
72+
<TraySettings />
7373
</AppContext.Provider>,
7474
);
7575
});
7676

77-
await userEvent.click(screen.getByTestId('checkbox-trayIconStatusColors'));
77+
await userEvent.click(screen.getByTestId('checkbox-useAlternateIdleIcon'));
7878

7979
expect(updateSetting).toHaveBeenCalledTimes(1);
80-
expect(updateSetting).toHaveBeenCalledWith('trayIconStatusColors', true);
80+
expect(updateSetting).toHaveBeenCalledWith('useAlternateIdleIcon', true);
8181
});
8282
});

src/renderer/components/settings/TraySettings.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const TraySettings: FC = () => {
1919
<Stack direction="vertical" gap="condensed">
2020
<Checkbox
2121
checked={settings.showNotificationsCountInTray}
22-
label="Show notification count in tray"
22+
label="Show notification count"
2323
name="showNotificationsCountInTray"
2424
onChange={(evt) =>
2525
updateSetting('showNotificationsCountInTray', evt.target.checked)
@@ -28,21 +28,17 @@ export const TraySettings: FC = () => {
2828
/>
2929

3030
<Checkbox
31-
checked={settings.trayIconStatusColors}
32-
label="Show tray icon status colors"
33-
name="trayIconStatusColors"
31+
checked={settings.useMonochromeIcon}
32+
label="Use monochrome icon"
33+
name="useMonochromeIcon"
3434
onChange={(evt) =>
35-
updateSetting('trayIconStatusColors', evt.target.checked)
35+
updateSetting('useMonochromeIcon', evt.target.checked)
3636
}
3737
tooltip={
3838
<Stack direction="vertical" gap="condensed">
3939
<Text>
40-
When enabled the {APPLICATION.NAME} tray icon will change color
41-
to indicate active, idle or error statuses.
42-
</Text>
43-
<Text>
44-
When disabled the {APPLICATION.NAME} tray icon will not show any
45-
status information.
40+
Display a neutral (monochrome) icon for unread notifications and
41+
errors, instead of using color highlights.
4642
</Text>
4743
</Stack>
4844
}

src/renderer/context/App.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ import {
4444
setAlternateIdleIcon,
4545
setAutoLaunch,
4646
setKeyboardShortcut,
47-
setTrayIconStatusColors,
47+
setMonochromeIcon,
48+
updateTrayIcon,
4849
updateTrayTitle,
4950
} from '../utils/comms';
5051
import { getNotificationCount } from '../utils/notifications/notifications';
@@ -158,6 +159,22 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
158159
}
159160
}, [settings.showNotificationsCountInTray, notifications]);
160161

162+
useEffect(() => {
163+
const count = getNotificationCount(notifications);
164+
165+
setMonochromeIcon(settings.useMonochromeIcon);
166+
167+
updateTrayIcon(count);
168+
}, [settings.useMonochromeIcon, notifications]);
169+
170+
useEffect(() => {
171+
setAutoLaunch(settings.openAtStartup);
172+
}, [settings.openAtStartup]);
173+
174+
useEffect(() => {
175+
setAlternateIdleIcon(settings.useAlternateIdleIcon);
176+
}, [settings.useAlternateIdleIcon]);
177+
161178
useEffect(() => {
162179
setKeyboardShortcut(settings.keyboardShortcut);
163180
}, [settings.keyboardShortcut]);
@@ -183,18 +200,6 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
183200

184201
const updateSetting = useCallback(
185202
(name: keyof SettingsState, value: SettingsValue) => {
186-
if (name === 'openAtStartup') {
187-
setAutoLaunch(value as boolean);
188-
}
189-
190-
if (name === 'trayIconStatusColors') {
191-
setTrayIconStatusColors(value as boolean);
192-
}
193-
194-
if (name === 'useAlternateIdleIcon') {
195-
setAlternateIdleIcon(value as boolean);
196-
}
197-
198203
const newSettings = { ...settings, [name]: value };
199204
setSettings(newSettings);
200205
saveState({ auth, settings: newSettings });
@@ -273,6 +278,7 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
273278
// Restore settings before accounts to ensure filters are available before fetching notifications
274279
if (existing.settings) {
275280
setKeyboardShortcut(existing.settings.keyboardShortcut);
281+
setMonochromeIcon(existing.settings.useMonochromeIcon);
276282
setAlternateIdleIcon(existing.settings.useAlternateIdleIcon);
277283
setSettings({ ...defaultSettings, ...existing.settings });
278284
window.gitify.zoom.setLevel(

src/renderer/context/defaults.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const defaultNotificationSettings: NotificationSettingsState = {
3737

3838
const defaultTraySettings: TraySettingsState = {
3939
showNotificationsCountInTray: true,
40-
trayIconStatusColors: true,
40+
useMonochromeIcon: false,
4141
useAlternateIdleIcon: false,
4242
};
4343

0 commit comments

Comments
 (0)