Skip to content

feat: make the volume of notifications adjustable #1967

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 11 commits into from
Apr 23, 2025
1 change: 1 addition & 0 deletions src/renderer/__mocks__/state-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const mockSystemSettings: SystemSettingsState = {
showNotificationsCountInTray: true,
showNotifications: true,
playSound: true,
notificationVolume: 20,
useAlternateIdleIcon: false,
openAtStartup: false,
};
Expand Down
18 changes: 18 additions & 0 deletions src/renderer/components/icons/VolumeDownIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { FC } from 'react';

export const VolumeDownIcon: FC = () => (
<svg
className="size-4"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
width="24"
height="24"
role="img"
aria-label="Volume Down Icon"
>
<g transform="translate(2, 0)">
<path d="M11.553 3.064A.75.75 0 0 1 12 3.75v16.5a.75.75 0 0 1-1.255.555L5.46 16H2.75A1.75 1.75 0 0 1 1 14.25v-4.5C1 8.784 1.784 8 2.75 8h2.71l5.285-4.805a.752.752 0 0 1 .808-.13ZM10.5 5.445l-4.245 3.86a.748.748 0 0 1-.505.195h-3a.25.25 0 0 0-.25.25v4.5c0 .138.112.25.25.25h3c.187 0 .367.069.505.195l4.245 3.86z" />
<path d="M16.243 7.757a.75.75 0 1 0-1.061 1.061 4.5 4.5 0 0 1 0 6.364.75.75 0 0 0 1.06 1.06 6 6 0 0 0 0-8.485Z" />
</g>
</svg>
);
16 changes: 16 additions & 0 deletions src/renderer/components/icons/VolumeUpIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { FC } from 'react';

export const VolumeUpIcon: FC = () => (
<svg
className="size-4"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
width="24"
height="24"
role="img"
aria-label="Volume Up Icon"
>
<path d="M11.553 3.064A.75.75 0 0 1 12 3.75v16.5a.75.75 0 0 1-1.255.555L5.46 16H2.75A1.75 1.75 0 0 1 1 14.25v-4.5C1 8.784 1.784 8 2.75 8h2.71l5.285-4.805a.752.752 0 0 1 .808-.13ZM10.5 5.445l-4.245 3.86a.748.748 0 0 1-.505.195h-3a.25.25 0 0 0-.25.25v4.5c0 .138.112.25.25.25h3c.187 0 .367.069.505.195l4.245 3.86Zm8.218-1.223a.75.75 0 0 1 1.06 0c4.296 4.296 4.296 11.26 0 15.556a.75.75 0 0 1-1.06-1.06 9.5 9.5 0 0 0 0-13.436.75.75 0 0 1 0-1.06Z" />
<path d="M16.243 7.757a.75.75 0 1 0-1.061 1.061 4.5 4.5 0 0 1 0 6.364.75.75 0 0 0 1.06 1.06 6 6 0 0 0 0-8.485Z" />
</svg>
);
87 changes: 78 additions & 9 deletions src/renderer/components/settings/SystemSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { type FC, useContext } from 'react';

import { DeviceDesktopIcon } from '@primer/octicons-react';
import { Box, Stack, Text } from '@primer/react';
import { DeviceDesktopIcon, SyncIcon } from '@primer/octicons-react';
import {
Box,
Button,
ButtonGroup,
IconButton,
Stack,
Text,
} from '@primer/react';

import { APPLICATION } from '../../../shared/constants';
import { isLinux, isMacOS } from '../../../shared/platform';
import { AppContext } from '../../context/App';
import { AppContext, defaultSettings } from '../../context/App';
import { OpenPreference } from '../../types';
import { Constants } from '../../utils/constants';
import { Checkbox } from '../fields/Checkbox';
import { RadioGroup } from '../fields/RadioGroup';
import { VolumeDownIcon } from '../icons/VolumeDownIcon';
import { VolumeUpIcon } from '../icons/VolumeUpIcon';
import { Title } from '../primitives/Title';

export const SystemSettings: FC = () => {
Expand Down Expand Up @@ -70,12 +79,72 @@ export const SystemSettings: FC = () => {
}
/>

<Checkbox
name="playSound"
label="Play sound"
checked={settings.playSound}
onChange={(evt) => updateSetting('playSound', evt.target.checked)}
/>
<Box>
<Stack
direction="horizontal"
gap="condensed"
align="center"
className="text-sm"
>
<Checkbox
name="playSound"
label="Play sound"
checked={settings.playSound}
onChange={(evt) => updateSetting('playSound', evt.target.checked)}
/>

<ButtonGroup className="ml-2" hidden={!settings.playSound}>
<IconButton
aria-label="Volume down"
size="small"
icon={VolumeDownIcon}
unsafeDisableTooltip={true}
onClick={() => {
const newVolume = Math.max(
settings.notificationVolume - 10,
0,
);
updateSetting('notificationVolume', newVolume);
}}
data-testid="settings-volume-down"
/>

<Button aria-label="Volume percentage" size="small" disabled>
{settings.notificationVolume.toFixed(0)}%
</Button>

<IconButton
aria-label="Volume up"
size="small"
icon={VolumeUpIcon}
unsafeDisableTooltip={true}
onClick={() => {
const newVolume = Math.min(
settings.notificationVolume + 10,
100,
);
updateSetting('notificationVolume', newVolume);
}}
data-testid="settings-volume-up"
/>

<IconButton
aria-label="Reset volume"
size="small"
variant="danger"
icon={SyncIcon}
unsafeDisableTooltip={true}
onClick={() => {
updateSetting(
'notificationVolume',
defaultSettings.notificationVolume,
);
}}
data-testid="settings-volume-reset"
/>
</ButtonGroup>
</Stack>
</Box>

<Checkbox
name="useAlternateIdleIcon"
Expand Down
1 change: 1 addition & 0 deletions src/renderer/context/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const defaultSystemSettings: SystemSettingsState = {
showNotificationsCountInTray: true,
showNotifications: true,
playSound: true,
notificationVolume: 20,
useAlternateIdleIcon: false,
openAtStartup: false,
};
Expand Down
185 changes: 159 additions & 26 deletions src/renderer/routes/__snapshots__/Settings.test.tsx.snap

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

1 change: 1 addition & 0 deletions src/renderer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export interface SystemSettingsState {
showNotifications: boolean;
useAlternateIdleIcon: boolean;
playSound: boolean;
notificationVolume: number;
openAtStartup: boolean;
}

Expand Down
Loading