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 @@ -93,6 +93,7 @@ const mockNotificationSettings: NotificationSettingsState = {
markAsDoneOnOpen: false,
markAsDoneOnUnsubscribe: false,
delayNotificationState: false,
notificationVolume: 20,
};

const mockSystemSettings: SystemSettingsState = {
Expand Down

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.

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

27 changes: 27 additions & 0 deletions src/renderer/components/settings/NotificationSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,33 @@ export const NotificationSettings: FC = () => {
</Text>
}
/>

<Stack direction="horizontal" gap="condensed" alignItems="center">
<Text as="label" htmlFor="notificationVolume">
Notification Volume:
</Text>
<input
id="notificationVolume"
type="number"
min={0}
max={100}
step={1}
value={settings.notificationVolume}
onChange={(evt) => {
let val = Number(evt.target.value);
if (Number.isNaN(val)) val = 0;
if (val > 100) val = 100;
if (val < 0) val = 0;
updateSetting('notificationVolume', val);
}}
style={{
width: '3rem',
textAlign: 'center',
border: '1px solid #ccc',
borderRadius: '4px',
}}
/>
</Stack>
</Stack>
</fieldset>
);
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 @@ -85,6 +85,7 @@ const defaultNotificationSettings: NotificationSettingsState = {
markAsDoneOnOpen: false,
markAsDoneOnUnsubscribe: false,
delayNotificationState: false,
notificationVolume: 20,
};

const defaultSystemSettings: SystemSettingsState = {
Expand Down
26 changes: 26 additions & 0 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 @@ -81,6 +81,7 @@ export interface NotificationSettingsState {
markAsDoneOnOpen: boolean;
markAsDoneOnUnsubscribe: boolean;
delayNotificationState: boolean;
notificationVolume: number;
}

export interface SystemSettingsState {
Expand Down
29 changes: 29 additions & 0 deletions src/renderer/utils/notifications/native.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,33 @@ describe('renderer/utils/notifications/native.ts', () => {
expect(window.Audio.prototype.play).toHaveBeenCalledTimes(1);
});
});

describe('triggerNativeNotifications', () => {
afterEach(() => {
jest.clearAllMocks();
});

it('should raise only sound notification with correct volume', () => {
const settings: SettingsState = {
...defaultSettings,
playSound: true,
showNotifications: false,
notificationVolume: 80,
};

const raiseSoundNotificationMock = jest.spyOn(
native,
'raiseSoundNotification',
);
jest.spyOn(native, 'raiseNativeNotification');

native.triggerNativeNotifications([], mockAccountNotifications, {
auth: mockAuth,
settings,
});

expect(raiseSoundNotificationMock).toHaveBeenCalledWith(0.8);
expect(native.raiseNativeNotification).not.toHaveBeenCalled();
});
});
});
6 changes: 3 additions & 3 deletions src/renderer/utils/notifications/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const triggerNativeNotifications = (
}

if (state.settings.playSound) {
raiseSoundNotification();
raiseSoundNotification(state.settings.notificationVolume / 100);
}

if (state.settings.showNotifications) {
Expand Down Expand Up @@ -86,7 +86,7 @@ export const raiseNativeNotification = (notifications: Notification[]) => {
return nativeNotification;
};

export const raiseSoundNotification = () => {
export const raiseSoundNotification = (volume = 0.2) => {
const audio = new Audio(
path.join(
__dirname,
Expand All @@ -96,6 +96,6 @@ export const raiseSoundNotification = () => {
Constants.NOTIFICATION_SOUND,
),
);
audio.volume = 0.2;
audio.volume = volume;
audio.play();
};
Loading