diff --git a/web/src/i18n/locales/en.json b/web/src/i18n/locales/en.json
index 76bce94..562ac11 100644
--- a/web/src/i18n/locales/en.json
+++ b/web/src/i18n/locales/en.json
@@ -67,6 +67,8 @@
"appearance": "Appearance",
"theme": "Theme",
"language": "Language",
+ "spectrogram": "Spectrogram in the player",
+ "spectrogramHelp": "It draws the last seconds of the sound as you listen. Turn it off to keep a phone or a laptop cooler. The choice stays on this device.",
"password": "Password",
"currentPassword": "Current password",
"newPassword": "New password",
diff --git a/web/src/i18n/locales/it.json b/web/src/i18n/locales/it.json
index 1af99df..ffde783 100644
--- a/web/src/i18n/locales/it.json
+++ b/web/src/i18n/locales/it.json
@@ -67,6 +67,8 @@
"appearance": "Aspetto",
"theme": "Tema",
"language": "Lingua",
+ "spectrogram": "Spettrogramma nel player",
+ "spectrogramHelp": "Disegna gli ultimi secondi del suono mentre ascolti. Spegnilo per tenere più fresco un telefono o un portatile. La scelta resta su questo dispositivo.",
"password": "Password",
"currentPassword": "Password attuale",
"newPassword": "Nuova password",
diff --git a/web/src/pages/SettingsPage.test.tsx b/web/src/pages/SettingsPage.test.tsx
index 2e2d9e8..1a76f99 100644
--- a/web/src/pages/SettingsPage.test.tsx
+++ b/web/src/pages/SettingsPage.test.tsx
@@ -5,6 +5,7 @@ import { MemoryRouter } from 'react-router-dom'
import { beforeEach, expect, test, vi } from 'vitest'
import { sessionStore } from '@/auth/session'
import { initI18n } from '@/i18n'
+import { useSpectrogramPref } from '@/player/prefs'
import { usePlayer } from '@/player/store'
import { apiError, mockFetch } from '@/test/mockFetch'
import { initTheme } from '@/theme/theme'
@@ -28,6 +29,8 @@ beforeEach(async () => {
vi.spyOn(navigator, 'language', 'get').mockReturnValue('en-US')
await initI18n()
initTheme()
+ localStorage.removeItem('sonda.spectrogram')
+ useSpectrogramPref.setState({ on: true })
sessionStore.setState({
status: 'authenticated',
user: { id: 1, email: 'tom@example.org', is_admin: true },
@@ -195,3 +198,14 @@ test('when the browser offers it, the page can ask to install the app, once', as
expect(offer.prompt).toHaveBeenCalledTimes(1)
await vi.waitFor(() => expect(screen.queryByRole('button', { name: 'Install Sonda' })).not.toBeInTheDocument())
})
+
+test('the spectrogram of the player can be turned off, and the choice stays on this device', async () => {
+ renderSettings()
+ const toggle = screen.getByRole('switch', { name: 'Spectrogram in the player' })
+ expect(toggle).toHaveAttribute('aria-checked', 'true')
+ await userEvent.click(toggle)
+ expect(toggle).toHaveAttribute('aria-checked', 'false')
+ expect(localStorage.getItem('sonda.spectrogram')).toBe('off')
+ await userEvent.click(toggle)
+ expect(toggle).toHaveAttribute('aria-checked', 'true')
+})
diff --git a/web/src/pages/SettingsPage.tsx b/web/src/pages/SettingsPage.tsx
index 6763a58..6971257 100644
--- a/web/src/pages/SettingsPage.tsx
+++ b/web/src/pages/SettingsPage.tsx
@@ -11,6 +11,8 @@ import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { errorMessageKey, useLanguage, type Lang } from '@/i18n'
import { usePlayer } from '@/player/store'
+import { useSpectrogramPref } from '@/player/prefs'
+import { Switch } from '@/components/ui/switch'
import { THEMES, useTheme, type ThemeId } from '@/theme/theme'
import PageTitle from '@/components/PageTitle'
@@ -105,6 +107,7 @@ export default function SettingsPage() {
const { theme, setTheme } = useTheme()
const { lang, setLanguage } = useLanguage()
const app = useInstall()
+ const spectrogram = useSpectrogramPref()
return (
@@ -138,6 +141,15 @@ export default function SettingsPage() {
{ value: 'it', label: t('lang.it') },
]}
/>
+
+
+ spectrogram.setOn(!spectrogram.on)} />
+
+ {t('settings.spectrogram')}
+
+
+
{t('settings.spectrogramHelp')}
+
{app.available && (
diff --git a/web/src/player/prefs.test.ts b/web/src/player/prefs.test.ts
new file mode 100644
index 0000000..67ca4e6
--- /dev/null
+++ b/web/src/player/prefs.test.ts
@@ -0,0 +1,19 @@
+import { beforeEach, expect, test } from 'vitest'
+import { useSpectrogramPref } from './prefs'
+
+beforeEach(() => {
+ localStorage.clear()
+ useSpectrogramPref.setState({ on: true })
+})
+
+test('the spectrogram is on until it is turned off', () => {
+ expect(useSpectrogramPref.getState().on).toBe(true)
+})
+
+test('turning it off is remembered on this device, turning it on again too', () => {
+ useSpectrogramPref.getState().setOn(false)
+ expect(useSpectrogramPref.getState().on).toBe(false)
+ expect(localStorage.getItem('sonda.spectrogram')).toBe('off')
+ useSpectrogramPref.getState().setOn(true)
+ expect(localStorage.getItem('sonda.spectrogram')).toBe('on')
+})
diff --git a/web/src/player/prefs.ts b/web/src/player/prefs.ts
new file mode 100644
index 0000000..923c765
--- /dev/null
+++ b/web/src/player/prefs.ts
@@ -0,0 +1,24 @@
+import { create } from 'zustand'
+
+const KEY = 'sonda.spectrogram'
+
+function read(): boolean {
+ try {
+ return localStorage.getItem(KEY) !== 'off'
+ } catch {
+ return true
+ }
+}
+
+/** Whether the player draws its spectrogram. A choice of this device, like the theme: on until it is turned off. */
+export const useSpectrogramPref = create<{ on: boolean; setOn(on: boolean): void }>()((set) => ({
+ on: read(),
+ setOn: (on) => {
+ set({ on })
+ try {
+ localStorage.setItem(KEY, on ? 'on' : 'off')
+ } catch {
+ // The choice still applies for this page view.
+ }
+ },
+}))