Skip to content

Commit 4e0f509

Browse files
committed
feat(app): option to turn off sound effects
1 parent ff3b174 commit 4e0f509

6 files changed

Lines changed: 106 additions & 24 deletions

File tree

packages/app/e2e/selectors.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ export const settingsNotificationsAgentSelector = '[data-action="settings-notifi
1010
export const settingsNotificationsPermissionsSelector = '[data-action="settings-notifications-permissions"]'
1111
export const settingsNotificationsErrorsSelector = '[data-action="settings-notifications-errors"]'
1212
export const settingsSoundsAgentSelector = '[data-action="settings-sounds-agent"]'
13+
export const settingsSoundsAgentEnabledSelector = '[data-action="settings-sounds-agent-enabled"]'
1314
export const settingsSoundsPermissionsSelector = '[data-action="settings-sounds-permissions"]'
15+
export const settingsSoundsPermissionsEnabledSelector = '[data-action="settings-sounds-permissions-enabled"]'
1416
export const settingsSoundsErrorsSelector = '[data-action="settings-sounds-errors"]'
17+
export const settingsSoundsErrorsEnabledSelector = '[data-action="settings-sounds-errors-enabled"]'
1518
export const settingsUpdatesStartupSelector = '[data-action="settings-updates-startup"]'
1619
export const settingsReleaseNotesSelector = '[data-action="settings-release-notes"]'
1720

packages/app/e2e/settings/settings.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
settingsNotificationsPermissionsSelector,
1010
settingsReleaseNotesSelector,
1111
settingsSoundsAgentSelector,
12+
settingsSoundsAgentEnabledSelector,
1213
settingsSoundsErrorsSelector,
1314
settingsSoundsPermissionsSelector,
1415
settingsThemeSelector,
@@ -335,6 +336,30 @@ test("changing sound agent selection persists in localStorage", async ({ page, g
335336
expect(stored?.sounds?.agent).not.toBe("staplebops-01")
336337
})
337338

339+
test("disabling agent sound disables sound selection", async ({ page, gotoSession }) => {
340+
await gotoSession()
341+
342+
const dialog = await openSettings(page)
343+
const select = dialog.locator(settingsSoundsAgentSelector)
344+
const switchContainer = dialog.locator(settingsSoundsAgentEnabledSelector)
345+
const trigger = select.locator('[data-slot="select-select-trigger"]')
346+
await expect(select).toBeVisible()
347+
await expect(switchContainer).toBeVisible()
348+
await expect(trigger).toBeEnabled()
349+
350+
await switchContainer.locator('[data-slot="switch-control"]').click()
351+
await page.waitForTimeout(100)
352+
353+
await expect(trigger).toBeDisabled()
354+
355+
const stored = await page.evaluate((key) => {
356+
const raw = localStorage.getItem(key)
357+
return raw ? JSON.parse(raw) : null
358+
}, settingsKey)
359+
360+
expect(stored?.sounds?.agentEnabled).toBe(false)
361+
})
362+
338363
test("changing permissions and errors sounds updates localStorage", async ({ page, gotoSession }) => {
339364
await gotoSession()
340365

packages/app/src/components/settings-general.tsx

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -306,39 +306,66 @@ export const SettingsGeneral: Component = () => {
306306
title={language.t("settings.general.sounds.agent.title")}
307307
description={language.t("settings.general.sounds.agent.description")}
308308
>
309-
<Select
310-
data-action="settings-sounds-agent"
311-
{...soundSelectProps(
312-
() => settings.sounds.agent(),
313-
(id) => settings.sounds.setAgent(id),
314-
)}
315-
/>
309+
<div class="flex items-center gap-2">
310+
<div data-action="settings-sounds-agent-enabled">
311+
<Switch
312+
checked={settings.sounds.agentEnabled()}
313+
onChange={(checked) => settings.sounds.setAgentEnabled(checked)}
314+
/>
315+
</div>
316+
<Select
317+
disabled={!settings.sounds.agentEnabled()}
318+
data-action="settings-sounds-agent"
319+
{...soundSelectProps(
320+
() => settings.sounds.agent(),
321+
(id) => settings.sounds.setAgent(id),
322+
)}
323+
/>
324+
</div>
316325
</SettingsRow>
317326

318327
<SettingsRow
319328
title={language.t("settings.general.sounds.permissions.title")}
320329
description={language.t("settings.general.sounds.permissions.description")}
321330
>
322-
<Select
323-
data-action="settings-sounds-permissions"
324-
{...soundSelectProps(
325-
() => settings.sounds.permissions(),
326-
(id) => settings.sounds.setPermissions(id),
327-
)}
328-
/>
331+
<div class="flex items-center gap-2">
332+
<div data-action="settings-sounds-permissions-enabled">
333+
<Switch
334+
checked={settings.sounds.permissionsEnabled()}
335+
onChange={(checked) => settings.sounds.setPermissionsEnabled(checked)}
336+
/>
337+
</div>
338+
<Select
339+
disabled={!settings.sounds.permissionsEnabled()}
340+
data-action="settings-sounds-permissions"
341+
{...soundSelectProps(
342+
() => settings.sounds.permissions(),
343+
(id) => settings.sounds.setPermissions(id),
344+
)}
345+
/>
346+
</div>
329347
</SettingsRow>
330348

331349
<SettingsRow
332350
title={language.t("settings.general.sounds.errors.title")}
333351
description={language.t("settings.general.sounds.errors.description")}
334352
>
335-
<Select
336-
data-action="settings-sounds-errors"
337-
{...soundSelectProps(
338-
() => settings.sounds.errors(),
339-
(id) => settings.sounds.setErrors(id),
340-
)}
341-
/>
353+
<div class="flex items-center gap-2">
354+
<div data-action="settings-sounds-errors-enabled">
355+
<Switch
356+
checked={settings.sounds.errorsEnabled()}
357+
onChange={(checked) => settings.sounds.setErrorsEnabled(checked)}
358+
/>
359+
</div>
360+
<Select
361+
disabled={!settings.sounds.errorsEnabled()}
362+
data-action="settings-sounds-errors"
363+
{...soundSelectProps(
364+
() => settings.sounds.errors(),
365+
(id) => settings.sounds.setErrors(id),
366+
)}
367+
/>
368+
</div>
342369
</SettingsRow>
343370
</div>
344371
</div>

packages/app/src/context/notification.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ export const { use: useNotification, provider: NotificationProvider } = createSi
233233
if (!session) return
234234
if (session.parentID) return
235235

236-
playSound(soundSrc(settings.sounds.agent()))
236+
if (settings.sounds.agentEnabled()) {
237+
playSound(soundSrc(settings.sounds.agent()))
238+
}
237239

238240
append({
239241
directory,
@@ -260,7 +262,9 @@ export const { use: useNotification, provider: NotificationProvider } = createSi
260262
if (meta.disposed) return
261263
if (session?.parentID) return
262264

263-
playSound(soundSrc(settings.sounds.errors()))
265+
if (settings.sounds.errorsEnabled()) {
266+
playSound(soundSrc(settings.sounds.errors()))
267+
}
264268

265269
const error = "error" in event.properties ? event.properties.error : undefined
266270
append({

packages/app/src/context/settings.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ export interface NotificationSettings {
1010
}
1111

1212
export interface SoundSettings {
13+
agentEnabled: boolean
1314
agent: string
15+
permissionsEnabled: boolean
1416
permissions: string
17+
errorsEnabled: boolean
1518
errors: string
1619
}
1720

@@ -57,8 +60,11 @@ const defaultSettings: Settings = {
5760
errors: false,
5861
},
5962
sounds: {
63+
agentEnabled: true,
6064
agent: "staplebops-01",
65+
permissionsEnabled: true,
6166
permissions: "staplebops-02",
67+
errorsEnabled: true,
6268
errors: "nope-03",
6369
},
6470
}
@@ -168,14 +174,29 @@ export const { use: useSettings, provider: SettingsProvider } = createSimpleCont
168174
},
169175
},
170176
sounds: {
177+
agentEnabled: withFallback(() => store.sounds?.agentEnabled, defaultSettings.sounds.agentEnabled),
178+
setAgentEnabled(value: boolean) {
179+
setStore("sounds", "agentEnabled", value)
180+
},
171181
agent: withFallback(() => store.sounds?.agent, defaultSettings.sounds.agent),
172182
setAgent(value: string) {
173183
setStore("sounds", "agent", value)
174184
},
185+
permissionsEnabled: withFallback(
186+
() => store.sounds?.permissionsEnabled,
187+
defaultSettings.sounds.permissionsEnabled,
188+
),
189+
setPermissionsEnabled(value: boolean) {
190+
setStore("sounds", "permissionsEnabled", value)
191+
},
175192
permissions: withFallback(() => store.sounds?.permissions, defaultSettings.sounds.permissions),
176193
setPermissions(value: string) {
177194
setStore("sounds", "permissions", value)
178195
},
196+
errorsEnabled: withFallback(() => store.sounds?.errorsEnabled, defaultSettings.sounds.errorsEnabled),
197+
setErrorsEnabled(value: boolean) {
198+
setStore("sounds", "errorsEnabled", value)
199+
},
179200
errors: withFallback(() => store.sounds?.errors, defaultSettings.sounds.errors),
180201
setErrors(value: string) {
181202
setStore("sounds", "errors", value)

packages/app/src/pages/layout.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,9 @@ export default function Layout(props: ParentProps) {
388388
alertedAtBySession.set(sessionKey, now)
389389

390390
if (e.details.type === "permission.asked") {
391-
playSound(soundSrc(settings.sounds.permissions()))
391+
if (settings.sounds.permissionsEnabled()) {
392+
playSound(soundSrc(settings.sounds.permissions()))
393+
}
392394
if (settings.notifications.permissions()) {
393395
void platform.notify(title, description, href)
394396
}

0 commit comments

Comments
 (0)