@@ -48,7 +48,7 @@ export default function Scrubber({ positionMs, durationMs, onSeek, size, peaks,
data-bar
aria-hidden="true"
style={{ height: `${height}%` }}
- className={cn('min-w-0 flex-1 rounded-[2px]', heard ? (friend ? 'bg-friend' : 'bg-primary') : 'bg-input')}
+ className={cn('min-w-px flex-1 rounded-[2px]', heard ? (friend ? 'bg-friend' : 'bg-primary') : 'bg-input')}
/>
)
})}
diff --git a/web/src/components/layout/NowPlaying.tsx b/web/src/components/layout/NowPlaying.tsx
index 8b1dbeb..9dc7f98 100644
--- a/web/src/components/layout/NowPlaying.tsx
+++ b/web/src/components/layout/NowPlaying.tsx
@@ -118,7 +118,7 @@ export default function NowPlaying() {
-
+
@@ -155,16 +155,11 @@ export default function NowPlaying() {
{radio &&
{t('radio.now', { name: radio.title })}
}
-
+
- {/* On a phone the seek bar and the controls stay at the bottom of the screen while the page scrolls; wide, they are in the flow as before. */}
-
+
+
+
{upNext.length > 0 && (
diff --git a/web/src/components/layout/Player.test.tsx b/web/src/components/layout/Player.test.tsx
index 01daa39..09c045c 100644
--- a/web/src/components/layout/Player.test.tsx
+++ b/web/src/components/layout/Player.test.tsx
@@ -584,29 +584,6 @@ test('the full-screen player controls come in full: shuffle, previous and repeat
for (const name of ['Shuffle', 'Previous', 'Repeat: off']) expect(dialog.getByRole('button', { name })).not.toHaveClass('max-sm:hidden')
})
-test('on a phone the seek bar and the controls of the full-screen player stay at the bottom while the page scrolls', async () => {
- act(() => usePlayer.getState().playTracks([a, b, c]))
- renderBar()
- await userEvent.click(screen.getByRole('button', { name: 'Open the full-screen player' }))
- const full = within(screen.getByRole('dialog'))
- const dock = full.getByRole('button', { name: 'Previous' }).closest('[data-phone-dock]')
- expect(dock).not.toBeNull()
- expect(dock).toHaveClass('max-sm:sticky', 'max-sm:bottom-0')
- // The seek bar and the play button are in the same block, so that both stay on screen.
- expect(within(dock as HTMLElement).getByRole('slider')).toBeInTheDocument()
- expect(within(dock as HTMLElement).getByRole('button', { name: 'Pause' })).toBeInTheDocument()
- // What comes next is not in it: it is what scrolls beneath.
- expect(within(dock as HTMLElement).queryByRole('region', { name: 'Up next' })).toBeNull()
-})
-
-test('on a short phone the cover of the full-screen player shrinks to leave room for the controls', async () => {
- act(() => usePlayer.getState().playTracks([a, b]))
- renderBar()
- await userEvent.click(screen.getByRole('button', { name: 'Open the full-screen player' }))
- const full = screen.getByRole('dialog')
- expect(full.querySelector('[data-phone-cover]')?.className).toContain('max-sm:max-w-[min(18rem,34dvh)]')
-})
-
// --- Gestures on a phone -----------------------------------------------------------------------
const touch = (x: number, y: number) => ({ clientX: x, clientY: y })
diff --git a/web/src/i18n/locales/en.json b/web/src/i18n/locales/en.json
index ca50a53..89a49b7 100644
--- a/web/src/i18n/locales/en.json
+++ b/web/src/i18n/locales/en.json
@@ -121,8 +121,6 @@
"admin": "Admin",
"signOut": "Sign out",
"app": "App",
- "changeServer": "Change server",
- "changeServerHelp": "Choose another Sonda server for this app. You will be asked for its address.",
"appearance": "Appearance",
"theme": "Theme",
"language": "Language",
diff --git a/web/src/i18n/locales/it.json b/web/src/i18n/locales/it.json
index e684f77..e8edf28 100644
--- a/web/src/i18n/locales/it.json
+++ b/web/src/i18n/locales/it.json
@@ -121,8 +121,6 @@
"admin": "Admin",
"signOut": "Esci",
"app": "App",
- "changeServer": "Cambia server",
- "changeServerHelp": "Scegli un altro server Sonda per questa app. Ti verrà chiesto il suo indirizzo.",
"appearance": "Aspetto",
"theme": "Tema",
"language": "Lingua",
diff --git a/web/src/pages/SettingsPage.test.tsx b/web/src/pages/SettingsPage.test.tsx
index 1e7548e..f7ed293 100644
--- a/web/src/pages/SettingsPage.test.tsx
+++ b/web/src/pages/SettingsPage.test.tsx
@@ -252,19 +252,3 @@ test('it has a section for the passwords of other apps', async () => {
expect(await screen.findByRole('heading', { name: 'Apps and devices' })).toBeInTheDocument()
expect(await screen.findByLabelText('Name of the app or device')).toBeInTheDocument()
})
-
-test('inside the Android app there is a way to choose another server, and in a browser there is not', async () => {
- const agent = vi.spyOn(navigator, 'userAgent', 'get')
- agent.mockReturnValue('Mozilla/5.0 (Linux; Android 16) Chrome/140 Mobile')
- const { unmount } = renderSettings()
- await screen.findByRole('heading', { name: 'Settings' })
- expect(screen.queryByRole('link', { name: 'Change server' })).toBeNull()
- unmount()
-
- agent.mockReturnValue('Mozilla/5.0 (Linux; Android 16) Chrome/140 Mobile SondaApp')
- renderSettings()
- const link = await screen.findByRole('link', { name: 'Change server' })
- // The page that asks for the address is the one of the app itself.
- expect(link).toHaveAttribute('href', 'http://localhost/?change')
- expect(screen.getByRole('region', { name: 'App' })).toContainElement(link)
-})
diff --git a/web/src/pages/SettingsPage.tsx b/web/src/pages/SettingsPage.tsx
index ed32a0e..223e272 100644
--- a/web/src/pages/SettingsPage.tsx
+++ b/web/src/pages/SettingsPage.tsx
@@ -10,7 +10,6 @@ import RadioInAppsSwitch from '@/components/RadioInAppsSwitch'
import MastodonBlock from '@/components/MastodonBlock'
import Section from '@/components/Section'
import VersionLabel from '@/components/VersionLabel'
-import { CHANGE_SERVER_URL, inAndroidApp } from '@/pwa/androidApp'
import { useInstall } from '@/pwa/useInstall'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
@@ -180,18 +179,6 @@ export default function SettingsPage() {
)}
- {inAndroidApp() && (
-
- )}
-
diff --git a/web/src/player/mediaSession.test.ts b/web/src/player/mediaSession.test.ts
index ff392c7..7c661cb 100644
--- a/web/src/player/mediaSession.test.ts
+++ b/web/src/player/mediaSession.test.ts
@@ -2,13 +2,6 @@ import { afterEach, expect, test, vi } from 'vitest'
import type { Track } from '@/api/catalog'
import { setMediaSession, setPlaybackState, setPosition } from './mediaSession'
-declare global {
- interface Window {
- SondaNative?: { update(json: string): void; stop(): void }
- sondaNativeAction?: (name: string, ms: number) => void
- }
-}
-
class FakeMetadata {
title = ''
artist = ''
@@ -134,71 +127,3 @@ test('the playback state and the position are left alone where the API is missin
setPosition(1000, 2000)
}).not.toThrow()
})
-
-// --- The Android app -----------------------------------------------------------------------------
-// A WebView has no Media Session API: the app gives the page a small object of its own, and asks the page back through a function.
-
-function withNativeApp() {
- const native = { update: vi.fn(), stop: vi.fn() }
- window.SondaNative = native
- return native
-}
-
-afterEach(() => {
- delete window.SondaNative
- delete window.sondaNativeAction
-})
-
-const flush = () => new Promise
((resolve) => queueMicrotask(resolve))
-
-test('the app is told once what plays, whether it plays and where it is, however many calls say it', async () => {
- const native = withNativeApp()
- setMediaSession(track, handlers)
- setPlaybackState(true)
- setPosition(60_000, 387_000)
- await flush()
- expect(native.update).toHaveBeenCalledTimes(1)
- const sent = JSON.parse(native.update.mock.calls[0][0])
- expect(sent).toMatchObject({ title: 'Paranoid Android', artist: 'Radiohead, Guest', album: 'OK Computer', playing: true, positionMs: 60_000, durationMs: 387_000 })
- expect(sent.artworkUrl).toMatch(/^https?:\/\/.+\/albums\/3\/cover/)
-})
-
-test('a pause is told to the app too, with the same song', async () => {
- const native = withNativeApp()
- setMediaSession(track, handlers)
- setPlaybackState(true)
- setPosition(1000, 387_000)
- await flush()
- setPlaybackState(false)
- await flush()
- expect(native.update).toHaveBeenCalledTimes(2)
- expect(JSON.parse(native.update.mock.calls[1][0])).toMatchObject({ title: 'Paranoid Android', playing: false })
-})
-
-test('nothing playing tells the app to stop', async () => {
- const native = withNativeApp()
- setMediaSession(track, handlers)
- await flush()
- setMediaSession(null, handlers)
- await flush()
- expect(native.stop).toHaveBeenCalledTimes(1)
-})
-
-test('the buttons of the notification of the app move the player', () => {
- withNativeApp()
- setMediaSession(track, handlers)
- for (const name of ['play', 'pause', 'next', 'previous']) window.sondaNativeAction!(name, 0)
- window.sondaNativeAction!('seekto', 12_500)
- expect(handlers.play).toHaveBeenCalled()
- expect(handlers.pause).toHaveBeenCalled()
- expect(handlers.next).toHaveBeenCalled()
- expect(handlers.prev).toHaveBeenCalled()
- expect(handlers.seekTo).toHaveBeenCalledWith(12_500)
-})
-
-test('in a browser the page does not look for the app', async () => {
- setMediaSession(track, handlers)
- setPlaybackState(true)
- await flush()
- expect(window.sondaNativeAction).toBeUndefined()
-})
diff --git a/web/src/player/mediaSession.ts b/web/src/player/mediaSession.ts
index cebeba9..5a2c714 100644
--- a/web/src/player/mediaSession.ts
+++ b/web/src/player/mediaSession.ts
@@ -10,70 +10,8 @@ export interface MediaKeyHandlers {
seekTo(ms: number): void
}
-// --- The Android app -----------------------------------------------------------------------------
-// A WebView has no Media Session API. The app (android/ in this repository) gives the page an object of its own,
-// SondaNative, which keeps a notification with the controls and the playback alive; the app asks the page back
-// through window.sondaNativeAction when one of its buttons is pressed.
-
-declare global {
- interface Window {
- SondaNative?: { update(json: string): void; stop(): void }
- sondaNativeAction?: (name: string, ms: number) => void
- }
-}
-
-interface NativeState {
- track: QueuedTrack | null
- playing: boolean
- positionMs: number
- durationMs: number
-}
-
-const nativeState: NativeState = { track: null, playing: false, positionMs: 0, durationMs: 0 }
-let nativeScheduled = false
-
-/** Tells the app what plays. Calls that come together (a new song, its state, its position) make one message. */
-function pushNative(): void {
- if (!window.SondaNative || nativeScheduled) return
- nativeScheduled = true
- queueMicrotask(() => {
- nativeScheduled = false
- const native = window.SondaNative
- if (!native) return
- const { track } = nativeState
- if (!track) return native.stop()
- native.update(
- JSON.stringify({
- title: track.title,
- artist: track.artists.map((a) => a.name).join(', '),
- album: track.album?.title ?? '',
- // The app fetches the cover itself, so the address is absolute.
- artworkUrl: track.album ? new URL(mediaUrl(coverPath(track.friend, track.album.id)), location.origin).href : '',
- playing: nativeState.playing,
- positionMs: nativeState.positionMs,
- durationMs: nativeState.durationMs,
- }),
- )
- })
-}
-
-function listenToNative(handlers: MediaKeyHandlers): void {
- if (!window.SondaNative) return
- window.sondaNativeAction = (name, ms) => {
- if (name === 'play') handlers.play()
- else if (name === 'pause') handlers.pause()
- else if (name === 'next') handlers.next()
- else if (name === 'previous') handlers.prev()
- else if (name === 'seekto') handlers.seekTo(Math.round(ms))
- }
-}
-
/** Tells the operating system what is playing (lock screen, media keys). Does nothing where the API is missing. */
export function setMediaSession(track: QueuedTrack | null, handlers: MediaKeyHandlers): void {
- listenToNative(handlers)
- nativeState.track = track
- if (!track) Object.assign(nativeState, { playing: false, positionMs: 0, durationMs: 0 })
- pushNative()
const session = navigator.mediaSession as MediaSession | undefined
if (!session) return
if (!track) {
@@ -97,19 +35,12 @@ export function setMediaSession(track: QueuedTrack | null, handlers: MediaKeyHan
/** Tells the operating system whether the player plays: the play and pause button of the lock screen follows it. */
export function setPlaybackState(playing: boolean): void {
- nativeState.playing = playing
- pushNative()
const session = navigator.mediaSession as MediaSession | undefined
if (session) session.playbackState = playing ? 'playing' : 'paused'
}
/** Tells the operating system the length of the song and where it is: it draws the seek bar of the lock screen from it. */
export function setPosition(positionMs: number, durationMs: number): void {
- if (durationMs > 0) {
- nativeState.positionMs = Math.min(Math.max(positionMs, 0), durationMs)
- nativeState.durationMs = durationMs
- pushNative()
- }
const session = navigator.mediaSession as MediaSession | undefined
if (!session?.setPositionState || durationMs <= 0) return
try {
diff --git a/web/src/player/usePlayer.test.tsx b/web/src/player/usePlayer.test.tsx
index cc1edc0..4487661 100644
--- a/web/src/player/usePlayer.test.tsx
+++ b/web/src/player/usePlayer.test.tsx
@@ -151,25 +151,6 @@ test('a queue saved by an earlier page comes back paused, on the same song and a
expect(audio.currentTime).toBe(61)
})
-test('a queue that comes back is on the lock screen at once, paused, where it was', async () => {
- const native = { update: vi.fn(), stop: vi.fn() }
- window.SondaNative = native
- try {
- usePlayer.getState().playTracks([track, { ...track, id: 2, title: 'Paranoid Android' }], 1)
- usePlayer.setState({ positionMs: 61_000 })
- saveQueue(1, usePlayer.getState())
- usePlayer.getState().playTracks([])
- native.update.mockClear()
- native.stop.mockClear()
- renderHook(() => usePlayerEngine())
- await waitFor(() => expect(native.update).toHaveBeenCalled())
- expect(JSON.parse(native.update.mock.calls.at(-1)![0])).toMatchObject({ title: 'Paranoid Android', playing: false, positionMs: 61_000, durationMs: 284_000 })
- } finally {
- delete window.SondaNative
- delete window.sondaNativeAction
- }
-})
-
test('the queue of another person is not restored', () => {
usePlayer.getState().playTracks([track])
saveQueue(2, usePlayer.getState())
diff --git a/web/src/player/usePlayer.ts b/web/src/player/usePlayer.ts
index aece0be..535fd65 100644
--- a/web/src/player/usePlayer.ts
+++ b/web/src/player/usePlayer.ts
@@ -48,14 +48,6 @@ export function usePlayerEngine(): void {
prev: () => usePlayer.getState().prev(),
seekTo: (ms: number) => usePlayer.getState().seek(ms),
}
- // A queue that came back above was there before this started listening: tell the lock screen about it now.
- const current = usePlayer.getState()
- const restored = currentTrack(current)
- if (restored) {
- setMediaSession(restored, keys)
- setPlaybackState(current.playing)
- setPosition(current.positionMs, restored.duration_ms)
- }
const stopMediaSession = usePlayer.subscribe((state, previous) => {
const track = currentTrack(state)
const before = currentTrack(previous)
diff --git a/web/src/pwa/androidApp.ts b/web/src/pwa/androidApp.ts
deleted file mode 100644
index aa2bb0a..0000000
--- a/web/src/pwa/androidApp.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-/** The Android app is Sonda in a WebView; it says so in its user agent. */
-export const inAndroidApp = () => navigator.userAgent.includes('SondaApp')
-
-/** The page of the app that asks for the address of the server. It is the app's own, not the server's. */
-export const CHANGE_SERVER_URL = 'http://localhost/?change'