Compare commits
No files matched your search
@@ -23,22 +23,3 @@ APP_VARIANT=development pnpm start
|
||||
An unset `APP_VARIANT` keeps the production identity. Unknown variants fail
|
||||
configuration. URL schemes are `otunes-development`, `otunes-preview`, and
|
||||
`otunes` respectively, allowing the apps to be installed together.
|
||||
|
||||
### Shared links and artwork
|
||||
|
||||
Shared URLs stay as ordinary HTTPS links. The web page's "Open App" action
|
||||
opens `otunes://open?url=<encoded HTTPS URL>`, including the server address and
|
||||
album, artist, or playlist destination. No domain association files, signing
|
||||
settings, or per-server mobile builds are needed.
|
||||
|
||||
The app checks the link's server against its configured server before opening
|
||||
media. Links for another server do not switch the current server. On a fresh
|
||||
installation, the server address is prefilled in setup. The destination is kept
|
||||
in memory through setup and sign-in, and is opened after authentication.
|
||||
The browser may ask before opening the app. If the app is absent, the web page
|
||||
remains available. Native changes still require a new mobile build.
|
||||
|
||||
Native sharing supplies media titles and artwork through iOS link metadata and Android's chooser
|
||||
thumbnail, while sharing the original HTTPS URL. Receiving apps control whether
|
||||
they display previews. If artwork cannot load, the URL is still shared. Existing
|
||||
builds without the native sharing module fall back to URL-only sharing.
|
||||
@@ -1,50 +1,31 @@
|
||||
import type { ConfigContext, ExpoConfig } from "expo/config"
|
||||
|
||||
export default ({ config }: ConfigContext): ExpoConfig => {
|
||||
const variant: string =
|
||||
process.env.APP_VARIANT ?? process.env.EAS_BUILD_PROFILE ?? "production"
|
||||
if (
|
||||
variant !== "development" &&
|
||||
variant !== "preview" &&
|
||||
variant !== "production"
|
||||
) {
|
||||
const variant = process.env.APP_VARIANT ?? "production"
|
||||
if (!["development", "preview", "production"].includes(variant)) {
|
||||
throw new Error(`Unsupported APP_VARIANT: ${variant}`)
|
||||
}
|
||||
|
||||
const suffix = variant === "production" ? "" : `.${variant}`
|
||||
const iconSuffix = variant === "production" ? "" : `-${variant}`
|
||||
const nameSuffix =
|
||||
variant === "development"
|
||||
? " (Development)"
|
||||
: variant === "preview"
|
||||
? " (Preview)"
|
||||
: ""
|
||||
const composer = {
|
||||
development: "oTunes Dev",
|
||||
preview: "oTunes Preview",
|
||||
production: "oTunes",
|
||||
}[variant]
|
||||
|
||||
return {
|
||||
...config,
|
||||
name: `${config.name}${nameSuffix}`,
|
||||
slug: config.slug!,
|
||||
scheme: variant === "production" ? "otunes" : `otunes-${variant}`,
|
||||
icon: `./assets/icon${iconSuffix}.png`,
|
||||
ios: {
|
||||
...config.ios,
|
||||
bundleIdentifier: `${config.ios!.bundleIdentifier}${suffix}`,
|
||||
icon: `./assets/${composer}.icon`,
|
||||
},
|
||||
android: {
|
||||
...config.android,
|
||||
package: `${config.android!.package}${suffix}`,
|
||||
icon: `./assets/android-icon${iconSuffix}.png`,
|
||||
adaptiveIcon: {
|
||||
monochromeImage: "./assets/android-icon-monochrome.png",
|
||||
foregroundImage: `./assets/android-icon-foreground${iconSuffix}.png`,
|
||||
backgroundImage: `./assets/android-icon-background${iconSuffix}.png`,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -26,11 +26,10 @@
|
||||
"adaptiveIcon": {
|
||||
"monochromeImage": "./assets/android-icon-monochrome.png",
|
||||
"foregroundImage": "./assets/android-icon-foreground.png",
|
||||
"backgroundImage": "./assets/android-icon-background.png"
|
||||
"backgroundColor": "#C60322"
|
||||
},
|
||||
"userInterfaceStyle": "dark",
|
||||
"softwareKeyboardLayoutMode": "resize",
|
||||
"icon": "./assets/android-icon.png"
|
||||
"softwareKeyboardLayoutMode": "resize"
|
||||
},
|
||||
"plugins": [
|
||||
"expo-router",
|
||||
|
||||
@@ -18,7 +18,6 @@ import {
|
||||
collectionInset,
|
||||
DiscHeader,
|
||||
} from "@/components/collection-list"
|
||||
import { AudioFormatBadge } from "@/components/audio-format-badge"
|
||||
import { CoverImage } from "@/components/cover-image"
|
||||
|
||||
import {
|
||||
@@ -76,20 +75,6 @@ export default function AlbumScreen() {
|
||||
[album]
|
||||
)
|
||||
|
||||
// Older servers do not include album format availability yet.
|
||||
const formatTracks = useCachedQuery(
|
||||
api.library.getSongsForPlayback,
|
||||
album && (album.hasLossless === undefined || album.hasAtmos === undefined)
|
||||
? { ids: songIds }
|
||||
: "skip"
|
||||
)
|
||||
const hasLossless =
|
||||
album?.hasLossless ??
|
||||
formatTracks?.some((track) => track && "lossless" in track.files)
|
||||
const hasAtmos =
|
||||
album?.hasAtmos ??
|
||||
formatTracks?.some((track) => track && "atmos" in track.files)
|
||||
|
||||
useEffect(() => {
|
||||
if (album) {
|
||||
rememberSongs(albumDetailSongs(album))
|
||||
@@ -111,9 +96,7 @@ export default function AlbumScreen() {
|
||||
songIds={songIds}
|
||||
palette={palette}
|
||||
favorited={isSongFavorite(item.track.id)}
|
||||
onPlay={(songId, ids) =>
|
||||
playFromSong(songId, ids, `album:${album.id}`)
|
||||
}
|
||||
onPlay={playFromSong}
|
||||
onAction={handleAlbumTrackAction}
|
||||
/>
|
||||
) : null
|
||||
@@ -186,7 +169,7 @@ export default function AlbumScreen() {
|
||||
stationArtistId={album.artist.id}
|
||||
selectedCount={album.tracks.length}
|
||||
favorited={isAlbumFav(album.id)}
|
||||
share={{ type: "album", albumId: album.id, title: album.title }}
|
||||
share={{ type: "album", albumId: album.id }}
|
||||
onAction={(action) =>
|
||||
void handleAlbumDetailAction(
|
||||
album.id as Id<"albums">,
|
||||
@@ -235,49 +218,11 @@ export default function AlbumScreen() {
|
||||
{album.artist.name}
|
||||
</Text>
|
||||
</Pressable>
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
flexWrap: "wrap",
|
||||
gap: 8,
|
||||
}}
|
||||
>
|
||||
{metadata ? (
|
||||
<Text style={{ color: palette.secondaryForeground }}>
|
||||
{metadata}
|
||||
</Text>
|
||||
) : null}
|
||||
{hasLossless ? (
|
||||
<>
|
||||
{metadata ? (
|
||||
<Text style={{ color: palette.secondaryForeground }}>
|
||||
·
|
||||
</Text>
|
||||
) : null}
|
||||
<AudioFormatBadge
|
||||
format="lossless"
|
||||
color={palette.secondaryForeground}
|
||||
backgroundColor={palette.background}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
{hasAtmos ? (
|
||||
<>
|
||||
{metadata || hasLossless ? (
|
||||
<Text style={{ color: palette.secondaryForeground }}>
|
||||
·
|
||||
</Text>
|
||||
) : null}
|
||||
<AudioFormatBadge
|
||||
format="atmos"
|
||||
color={palette.secondaryForeground}
|
||||
backgroundColor={palette.background}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
</View>
|
||||
{metadata ? (
|
||||
<Text style={{ color: palette.secondaryForeground }}>
|
||||
{metadata}
|
||||
</Text>
|
||||
) : null}
|
||||
<View style={styles.actions}>
|
||||
<Pressable
|
||||
onPress={() => void toggleAlbumFavorite(album.id)}
|
||||
@@ -406,7 +351,6 @@ const AlbumTrackRow = memo(function AlbumTrackRow({
|
||||
type: "song",
|
||||
albumId: album.id,
|
||||
songId: track.id,
|
||||
title: `${track.title} - ${album.title}`,
|
||||
}}
|
||||
onAction={(action) => void onAction(track, album, action)}
|
||||
>
|
||||
|
||||
@@ -75,11 +75,7 @@ export default function ArtistScreen() {
|
||||
<MediaActionMenu
|
||||
selectedCount={data.albums.length}
|
||||
favorited={isArtistFav(data.artist.id)}
|
||||
share={{
|
||||
type: "artist",
|
||||
artistId: data.artist.id,
|
||||
title: data.artist.name,
|
||||
}}
|
||||
share={{ type: "artist", artistId: data.artist.id }}
|
||||
onAction={(action) =>
|
||||
void handleArtistAction(data.artist, action)
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ const ArtistRow = memo(function ArtistRow({
|
||||
return (
|
||||
<MediaContextMenu
|
||||
favorited={favorited}
|
||||
share={{ type: "artist", artistId: artist.id, title: artist.name }}
|
||||
share={{ type: "artist", artistId: artist.id }}
|
||||
onAction={(action) => void onAction(artist, action)}
|
||||
>
|
||||
<Pressable
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
import {
|
||||
PlaylistSearchBar,
|
||||
usePlaylistSearch,
|
||||
} from "@/components/playlist-search-bar"
|
||||
import { useAndroidScreenPalette } from "@/contexts/android-tab-theme"
|
||||
import { MusicEntityView } from "@/components/music-entity-view"
|
||||
import { useMutation } from "convex/react"
|
||||
@@ -43,7 +39,10 @@ import { contentBottomInset, SongListRow } from "@/components/player"
|
||||
import { useFavorites } from "@/contexts/favorites"
|
||||
import { usePlaybackActions } from "@/contexts/playback"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import { useCachedQuery } from "@/hooks/use-cached-query"
|
||||
import {
|
||||
useCachedPaginatedQuery,
|
||||
useCachedQuery,
|
||||
} from "@/hooks/use-cached-query"
|
||||
import { useCoverPalette } from "@/hooks/use-cover-palette"
|
||||
import { useMediaMenuActions } from "@/hooks/use-media-menu-actions"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
@@ -56,6 +55,7 @@ import { showError } from "@/lib/toast"
|
||||
import { playlistCoverUrl } from "@/lib/urls"
|
||||
import { radius, spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
const PAGE_SIZE = 50
|
||||
const PLAYLIST_LABEL = "Add to Another Playlist"
|
||||
const OWNER_MENU_ACTIONS: MediaAction[] = [
|
||||
"share",
|
||||
@@ -74,9 +74,27 @@ export default function PlaylistScreen() {
|
||||
const playlistId = typeof id === "string" ? (id as Id<"playlists">) : null
|
||||
const playlist = useCachedQuery(
|
||||
api.playlists.browsePlaylistDetail,
|
||||
playlistId ? { id: playlistId } : "skip"
|
||||
playlistId
|
||||
? {
|
||||
id: playlistId,
|
||||
includeSongs: false,
|
||||
}
|
||||
: "skip"
|
||||
)
|
||||
const {
|
||||
results: songs,
|
||||
status,
|
||||
loadMore,
|
||||
isCached,
|
||||
} = useCachedPaginatedQuery(
|
||||
api.playlists.browsePlaylistSongsPaginated,
|
||||
playlistId ? { id: playlistId } : "skip",
|
||||
{ initialNumItems: PAGE_SIZE }
|
||||
)
|
||||
const allSongIds = useCachedQuery(
|
||||
api.playlists.getPlaylistSongIds,
|
||||
playlistId ? { playlistId } : "skip"
|
||||
)
|
||||
const songs = playlist?.songs
|
||||
const coverUri =
|
||||
config && playlistId
|
||||
? playlistCoverUrl(config.serverUrl, playlist?.id ?? playlistId)
|
||||
@@ -88,10 +106,15 @@ export default function PlaylistScreen() {
|
||||
const { palette, onLayout } = useAndroidScreenPalette(artworkPalette)
|
||||
|
||||
useEffect(() => {
|
||||
if (songs) rememberSongs(songs)
|
||||
rememberSongs(songs)
|
||||
}, [songs])
|
||||
|
||||
if (playlist === undefined || !config || !settled) {
|
||||
if (
|
||||
playlist === undefined ||
|
||||
(status === "LoadingFirstPage" && !isCached) ||
|
||||
!config ||
|
||||
!settled
|
||||
) {
|
||||
return (
|
||||
<>
|
||||
<Stack.Screen
|
||||
@@ -127,9 +150,13 @@ export default function PlaylistScreen() {
|
||||
<PlaylistContent
|
||||
onLayout={onLayout}
|
||||
playlist={playlist}
|
||||
songs={playlist.songs}
|
||||
songs={songs}
|
||||
allSongIds={allSongIds}
|
||||
coverUri={coverUri}
|
||||
palette={palette}
|
||||
onEndReached={() => {
|
||||
if (status === "CanLoadMore") loadMore(PAGE_SIZE)
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -138,14 +165,18 @@ function PlaylistContent({
|
||||
onLayout,
|
||||
playlist,
|
||||
songs,
|
||||
allSongIds,
|
||||
coverUri,
|
||||
palette,
|
||||
onEndReached,
|
||||
}: {
|
||||
onLayout?: () => void
|
||||
playlist: BrowsePlaylistDetail
|
||||
songs: BrowseSong[]
|
||||
allSongIds: Id<"songs">[] | undefined
|
||||
coverUri: string
|
||||
palette: CoverPalette
|
||||
onEndReached: () => void
|
||||
}) {
|
||||
const router = useRouter()
|
||||
const isFocused = useIsFocused()
|
||||
@@ -161,15 +192,13 @@ function PlaylistContent({
|
||||
const playlistId = playlist.id
|
||||
const isSubscribed = playlist.isSubscribed
|
||||
const canEdit = playlist.isOwner && playlistId !== null
|
||||
const songIds = useMemo(() => songs.map((song) => song.id), [songs])
|
||||
const { filteredSongs, onQueryChange, onSearchSubmit } =
|
||||
usePlaylistSearch(songs)
|
||||
const loadedSongIds = useMemo(() => songs.map((song) => song.id), [songs])
|
||||
const songIds = allSongIds ?? loadedSongIds
|
||||
const swipeGroup = useSwipeRowGroup()
|
||||
|
||||
const handlePlaySong = useCallback(
|
||||
(song: BrowseSong) =>
|
||||
void playFromSong(song.id, songIds, `playlist:${playlistId}`),
|
||||
[playFromSong, songIds, playlistId]
|
||||
(song: BrowseSong) => void playFromSong(song.id, songIds),
|
||||
[playFromSong, songIds]
|
||||
)
|
||||
|
||||
const handleSongMenuAction = useCallback(
|
||||
@@ -197,12 +226,12 @@ function PlaylistContent({
|
||||
)
|
||||
|
||||
const handlePlay = useCallback(() => {
|
||||
if (playlistId) void playPlaylist(playlistId, songIds)
|
||||
}, [playPlaylist, playlistId, songIds])
|
||||
if (playlistId) void playPlaylist(playlistId, allSongIds)
|
||||
}, [allSongIds, playPlaylist, playlistId])
|
||||
|
||||
const handleShuffle = useCallback(() => {
|
||||
if (playlistId) void playPlaylistShuffled(playlistId, songIds)
|
||||
}, [playPlaylistShuffled, playlistId, songIds])
|
||||
if (playlistId) void playPlaylistShuffled(playlistId, allSongIds)
|
||||
}, [allSongIds, playPlaylistShuffled, playlistId])
|
||||
|
||||
const handleSubscribeToggle = useCallback(async () => {
|
||||
if (!playlistId) return
|
||||
@@ -260,7 +289,6 @@ function PlaylistContent({
|
||||
share={{
|
||||
type: "playlist",
|
||||
playlistId: playlistId ?? "favorites",
|
||||
title: playlist?.title ?? "oTunes",
|
||||
}}
|
||||
includeActions={canEdit ? OWNER_MENU_ACTIONS : undefined}
|
||||
onAction={handlePlaylistMenuAction}
|
||||
@@ -283,7 +311,6 @@ function PlaylistContent({
|
||||
palette.background,
|
||||
palette.isDark,
|
||||
playlistId,
|
||||
playlist?.title,
|
||||
router,
|
||||
songIds,
|
||||
])
|
||||
@@ -318,31 +345,19 @@ function PlaylistContent({
|
||||
<StatusBar style={palette.isDark ? "light" : "dark"} />
|
||||
) : null}
|
||||
<Stack.Screen options={screenOptions} />
|
||||
<PlaylistSearchBar
|
||||
onQueryChange={onQueryChange}
|
||||
onSearchSubmit={onSearchSubmit}
|
||||
/>
|
||||
<FlatList
|
||||
onLayout={onLayout}
|
||||
{...longListProps}
|
||||
data={filteredSongs}
|
||||
data={songs}
|
||||
keyExtractor={songKey}
|
||||
renderItem={renderItem}
|
||||
style={{ flex: 1, backgroundColor: palette.background }}
|
||||
indicatorStyle={palette.isDark ? "white" : "black"}
|
||||
contentContainerStyle={styles.listContent}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
onEndReached={onEndReached}
|
||||
onEndReachedThreshold={0.5}
|
||||
onScrollBeginDrag={swipeGroup.closeOpenRow}
|
||||
ListEmptyComponent={
|
||||
<Text
|
||||
style={[
|
||||
styles.emptyResults,
|
||||
{ color: palette.secondaryForeground },
|
||||
]}
|
||||
>
|
||||
{songs.length ? "No songs found." : "No songs in this playlist."}
|
||||
</Text>
|
||||
}
|
||||
ListHeaderComponent={
|
||||
<PlaylistHero
|
||||
entityId={playlistId ?? "otunes:favorites"}
|
||||
@@ -538,7 +553,6 @@ const PlaylistHero = memo(function PlaylistHero({
|
||||
})
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
emptyResults: { padding: spacing.lg, textAlign: "center" },
|
||||
empty: { flex: 1, alignItems: "center", justifyContent: "center" },
|
||||
listContent: { paddingBottom: contentBottomInset },
|
||||
hero: { alignItems: "center", padding: spacing.lg, gap: spacing.sm },
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
import {
|
||||
PlaylistSearchBar,
|
||||
usePlaylistSearch,
|
||||
} from "@/components/playlist-search-bar"
|
||||
import { memo, useCallback, useEffect, useMemo } from "react"
|
||||
import {
|
||||
FlatList,
|
||||
@@ -19,7 +15,10 @@ import { contentBottomInset, SongListRow } from "@/components/player"
|
||||
import { useFavorites } from "@/contexts/favorites"
|
||||
import { usePlaybackActions } from "@/contexts/playback"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import { useCachedQuery } from "@/hooks/use-cached-query"
|
||||
import {
|
||||
useCachedPaginatedQuery,
|
||||
useCachedQuery,
|
||||
} from "@/hooks/use-cached-query"
|
||||
import { useMediaMenuActions } from "@/hooks/use-media-menu-actions"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { MediaAction } from "@/components/media-context-menu"
|
||||
@@ -30,23 +29,32 @@ import { radius, spacing, useThemeColors } from "@/lib/theme"
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
import { Stack } from "expo-router"
|
||||
|
||||
const PAGE_SIZE = 50
|
||||
const SCREEN_OPTIONS = { title: "", headerLargeTitle: false }
|
||||
|
||||
export default function FavoritesScreen() {
|
||||
const colors = useThemeColors()
|
||||
const { config } = useServerConfig()
|
||||
const favorites = useCachedQuery(api.favorites.browseFavoritesPlaylistDetail)
|
||||
const songs = favorites?.songs ?? []
|
||||
const favorites = useCachedQuery(api.favorites.browseFavoritesSummary)
|
||||
const {
|
||||
results: songs,
|
||||
status,
|
||||
loadMore,
|
||||
isCached,
|
||||
} = useCachedPaginatedQuery(
|
||||
api.favorites.browseFavoritesSongsPaginated,
|
||||
{},
|
||||
{ initialNumItems: PAGE_SIZE }
|
||||
)
|
||||
const { playInOrder, playShuffled, playFromSong } = usePlaybackActions()
|
||||
const { isSongFavorite } = useFavorites()
|
||||
const { handleSongAction } = useMediaMenuActions()
|
||||
const songIds = useMemo(() => songs.map((song) => song.id), [songs])
|
||||
const { filteredSongs, onQueryChange, onSearchSubmit } =
|
||||
usePlaylistSearch(songs)
|
||||
const loadedSongIds = useMemo(() => songs.map((song) => song.id), [songs])
|
||||
const songIds = favorites?.songIds ?? loadedSongIds
|
||||
|
||||
useEffect(() => {
|
||||
if (favorites) rememberSongs(favorites.songs)
|
||||
}, [favorites])
|
||||
rememberSongs(songs)
|
||||
}, [songs])
|
||||
|
||||
const handlePlaySong = useCallback(
|
||||
(song: BrowseSong) => void playFromSong(song.id, songIds),
|
||||
@@ -80,7 +88,11 @@ export default function FavoritesScreen() {
|
||||
[handlePlaySong, handleSongMenuAction, isSongFavorite]
|
||||
)
|
||||
|
||||
if (favorites === undefined || !config) {
|
||||
if (
|
||||
favorites === undefined ||
|
||||
(status === "LoadingFirstPage" && !isCached) ||
|
||||
!config
|
||||
) {
|
||||
return (
|
||||
<>
|
||||
<Stack.Screen options={SCREEN_OPTIONS} />
|
||||
@@ -105,25 +117,18 @@ export default function FavoritesScreen() {
|
||||
return (
|
||||
<>
|
||||
<Stack.Screen options={SCREEN_OPTIONS} />
|
||||
<PlaylistSearchBar
|
||||
onQueryChange={onQueryChange}
|
||||
onSearchSubmit={onSearchSubmit}
|
||||
/>
|
||||
<FlatList
|
||||
{...longListProps}
|
||||
data={filteredSongs}
|
||||
data={songs}
|
||||
keyExtractor={songKey}
|
||||
renderItem={renderItem}
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={styles.listContent}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
ListEmptyComponent={
|
||||
<Text
|
||||
style={[styles.emptyResults, { color: colors.mutedForeground }]}
|
||||
>
|
||||
{songs.length ? "No songs found." : "No songs in this playlist."}
|
||||
</Text>
|
||||
}
|
||||
onEndReached={() => {
|
||||
if (status === "CanLoadMore") loadMore(PAGE_SIZE)
|
||||
}}
|
||||
onEndReachedThreshold={0.5}
|
||||
ListHeaderComponent={
|
||||
<FavoritesHero
|
||||
title={favorites.title}
|
||||
@@ -190,7 +195,6 @@ const FavoritesHero = memo(function FavoritesHero({
|
||||
})
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
emptyResults: { padding: spacing.lg, textAlign: "center" },
|
||||
empty: { flex: 1, alignItems: "center", justifyContent: "center" },
|
||||
listContent: { paddingBottom: contentBottomInset },
|
||||
hero: { alignItems: "center", padding: spacing.lg, gap: spacing.sm },
|
||||
|
||||
@@ -382,7 +382,7 @@ function QualitySection({ user }: { user: CurrentUser }) {
|
||||
: "This device does not support Dolby Atmos playback."
|
||||
}
|
||||
disabled={!dolbyAtmosSupported}
|
||||
value={dolbyAtmosSupported && (user.preferAtmos ?? false)}
|
||||
value={user.preferAtmos ?? false}
|
||||
onValueChange={(checked) =>
|
||||
void updateAtmos({ preferAtmos: checked }).catch((error: Error) =>
|
||||
showError(error.message)
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
import { router, type Href } from "expo-router"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import {
|
||||
incomingMediaLink,
|
||||
subscribeIncomingMediaLink,
|
||||
takeIncomingMediaLink,
|
||||
} from "@/lib/incoming-media-link"
|
||||
import { useConvexAuth as useLocalConvexAuth } from "@convex-dev/auth/react"
|
||||
import {
|
||||
useConvexAuth as useServerConvexAuth,
|
||||
@@ -12,7 +5,7 @@ import {
|
||||
} from "convex/react"
|
||||
import { Stack } from "expo-router"
|
||||
import { Platform } from "react-native"
|
||||
import { useEffect, useSyncExternalStore } from "react"
|
||||
import { useEffect } from "react"
|
||||
|
||||
import { AppIntentBridge } from "@/components/app-intent-bridge"
|
||||
import { ConvexAuthRecovery } from "@/components/convex-auth-recovery"
|
||||
@@ -31,18 +24,6 @@ export default function AppLayout() {
|
||||
const { isWebSocketConnected } = useConvexConnectionState()
|
||||
const { invalidateSession } = useInvalidateAuthSession()
|
||||
const stackOptions = useStackScreenOptions()
|
||||
const { config } = useServerConfig()
|
||||
const pendingDestination = useSyncExternalStore(
|
||||
subscribeIncomingMediaLink,
|
||||
() => (config ? incomingMediaLink(config.serverUrl) : null),
|
||||
() => null
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (!config || !pendingDestination) return
|
||||
const destination = takeIncomingMediaLink(config.serverUrl)
|
||||
if (destination) router.replace(destination as Href)
|
||||
}, [config, pendingDestination])
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
import { loadServerConfig, parseServerHostname } from "@/lib/server-config"
|
||||
import { secureGetItem } from "@/lib/auth-storage"
|
||||
import { rememberIncomingMediaLink } from "@/lib/incoming-media-link"
|
||||
import { showError } from "@/lib/toast"
|
||||
|
||||
export async function redirectSystemPath({
|
||||
path,
|
||||
}: {
|
||||
path: string
|
||||
initial: boolean
|
||||
}) {
|
||||
try {
|
||||
const link = new URL(path, "otunes:///")
|
||||
if (
|
||||
!["otunes:", "otunes-development:", "otunes-preview:"].includes(
|
||||
link.protocol
|
||||
) ||
|
||||
link.hostname !== "open"
|
||||
) {
|
||||
return path
|
||||
}
|
||||
|
||||
const target = new URL(link.searchParams.get("url") ?? "")
|
||||
const server = parseServerHostname(target.host)
|
||||
if (
|
||||
!server ||
|
||||
!["https:", "http:"].includes(target.protocol) ||
|
||||
target.username ||
|
||||
target.password ||
|
||||
new URL(server.serverUrl).origin !== target.origin ||
|
||||
!/^\/(album|artist|playlist)\/[a-zA-Z0-9_-]+$/.test(target.pathname)
|
||||
) {
|
||||
return "/"
|
||||
}
|
||||
|
||||
const config = await loadServerConfig(secureGetItem)
|
||||
if (config && new URL(config.serverUrl).origin !== target.origin) {
|
||||
showError("This link belongs to a different oTunes server")
|
||||
return "/"
|
||||
}
|
||||
|
||||
const query = new URLSearchParams()
|
||||
const songId = target.searchParams.get("s")
|
||||
if (target.pathname.startsWith("/album/") && songId) query.set("s", songId)
|
||||
const suffix = query.size ? `?${query}` : ""
|
||||
const destination = `/(app)/(tabs)/home${target.pathname}${suffix}`
|
||||
rememberIncomingMediaLink(destination, target.origin)
|
||||
return config
|
||||
? destination
|
||||
: `/server?hostname=${encodeURIComponent(server.hostname)}`
|
||||
} catch {
|
||||
return "/"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import { useConvexAuth } from "@convex-dev/auth/react"
|
||||
import { incomingMediaLink } from "@/lib/incoming-media-link"
|
||||
import { Redirect, type Href } from "expo-router"
|
||||
import { Redirect } from "expo-router"
|
||||
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
|
||||
@@ -12,16 +11,9 @@ export default function Index() {
|
||||
return <Redirect href="/server" />
|
||||
}
|
||||
|
||||
const destination = auth?.isAuthenticated
|
||||
? incomingMediaLink(config.serverUrl)
|
||||
: null
|
||||
|
||||
return (
|
||||
<Redirect
|
||||
href={
|
||||
(destination as Href) ??
|
||||
(auth?.isAuthenticated ? "/(app)/(tabs)/library" : "/signin")
|
||||
}
|
||||
href={auth?.isAuthenticated ? "/(app)/(tabs)/library" : "/signin"}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import { useLocalSearchParams } from "expo-router"
|
||||
import { useEffect, useState } from "react"
|
||||
import { useState } from "react"
|
||||
import { StyleSheet, Text, View } from "react-native"
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
|
||||
@@ -12,14 +11,7 @@ import { spacing, useThemeColors } from "@/lib/theme"
|
||||
export default function ServerScreen() {
|
||||
const colors = useThemeColors()
|
||||
const { setServerHostname } = useServerConfig()
|
||||
const { hostname: linkedHostname } = useLocalSearchParams<{
|
||||
hostname?: string
|
||||
}>()
|
||||
const [hostname, setHostname] = useState(linkedHostname ?? "")
|
||||
useEffect(() => {
|
||||
if (linkedHostname) setHostname(linkedHostname)
|
||||
}, [linkedHostname])
|
||||
|
||||
const [hostname, setHostname] = useState("")
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [submitting, setSubmitting] = useState(false)
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 8.1 KiB |
|
Before Width: | Height: | Size: 8.0 KiB |
|
Before Width: | Height: | Size: 7.9 KiB |
|
Before Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 324 KiB After Width: | Height: | Size: 8.1 KiB |
|
Before Width: | Height: | Size: 310 KiB |
|
Before Width: | Height: | Size: 286 KiB |
|
Before Width: | Height: | Size: 284 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 324 KiB After Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 284 KiB After Width: | Height: | Size: 963 KiB |
|
Before Width: | Height: | Size: 8.8 KiB |
@@ -1,53 +0,0 @@
|
||||
{
|
||||
"fill" : {
|
||||
"linear-gradient" : [
|
||||
"display-p3:0.00000,0.55106,0.91748,1.00000",
|
||||
"display-p3:0.00320,0.24546,0.91602,1.00000"
|
||||
]
|
||||
},
|
||||
"groups" : [
|
||||
{
|
||||
"layers" : [
|
||||
{
|
||||
"fill-specializations" : [
|
||||
{
|
||||
"value" : "automatic"
|
||||
},
|
||||
{
|
||||
"appearance" : "dark",
|
||||
"value" : {
|
||||
"linear-gradient" : [
|
||||
"display-p3:0.00000,0.55106,0.91748,1.00000",
|
||||
"display-p3:0.00320,0.24546,0.91602,1.00000"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"image-name" : "music.note.png",
|
||||
"name" : "music.note",
|
||||
"position" : {
|
||||
"scale" : 1.5,
|
||||
"translation-in-points" : [
|
||||
0,
|
||||
0
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"shadow" : {
|
||||
"kind" : "neutral",
|
||||
"opacity" : 0.6
|
||||
},
|
||||
"translucency" : {
|
||||
"enabled" : false,
|
||||
"value" : 0.2
|
||||
}
|
||||
}
|
||||
],
|
||||
"supported-platforms" : {
|
||||
"circles" : [
|
||||
"watchOS"
|
||||
],
|
||||
"squares" : "shared"
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 8.8 KiB |
@@ -1,53 +0,0 @@
|
||||
{
|
||||
"fill" : {
|
||||
"linear-gradient" : [
|
||||
"display-p3:0.03297,0.65562,0.91748,1.00000",
|
||||
"display-p3:0.01787,0.85470,0.91602,1.00000"
|
||||
]
|
||||
},
|
||||
"groups" : [
|
||||
{
|
||||
"layers" : [
|
||||
{
|
||||
"fill-specializations" : [
|
||||
{
|
||||
"value" : "automatic"
|
||||
},
|
||||
{
|
||||
"appearance" : "dark",
|
||||
"value" : {
|
||||
"linear-gradient" : [
|
||||
"display-p3:0.03297,0.65562,0.91748,1.00000",
|
||||
"display-p3:0.01787,0.85470,0.91602,1.00000"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"image-name" : "music.note.png",
|
||||
"name" : "music.note",
|
||||
"position" : {
|
||||
"scale" : 1.5,
|
||||
"translation-in-points" : [
|
||||
0,
|
||||
0
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"shadow" : {
|
||||
"kind" : "neutral",
|
||||
"opacity" : 0.6
|
||||
},
|
||||
"translucency" : {
|
||||
"enabled" : false,
|
||||
"value" : 0.2
|
||||
}
|
||||
}
|
||||
],
|
||||
"supported-platforms" : {
|
||||
"circles" : [
|
||||
"watchOS"
|
||||
],
|
||||
"squares" : "shared"
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@
|
||||
"image-name" : "music.note.png",
|
||||
"name" : "music.note",
|
||||
"position" : {
|
||||
"scale" : 1.5,
|
||||
"scale" : 1,
|
||||
"translation-in-points" : [
|
||||
0,
|
||||
0
|
||||
|
||||
@@ -80,7 +80,7 @@ export const AlbumCard = memo(function AlbumCard({
|
||||
favorited={isAlbumFavorite(album.id)}
|
||||
stationArtistId={album.artist.id}
|
||||
navigation={{ artist: { id: album.artist.id } }}
|
||||
share={{ type: "album", albumId: album.id, title: album.title }}
|
||||
share={{ type: "album", albumId: album.id }}
|
||||
onAction={(action) => void handleAlbumAction(album, action)}
|
||||
>
|
||||
<MusicEntityView kind="album" id={album.id}>
|
||||
@@ -125,7 +125,7 @@ export const ArtistCard = memo(function ArtistCard({
|
||||
return (
|
||||
<MediaContextMenu
|
||||
favorited={isArtistFavorite(artist.id)}
|
||||
share={{ type: "artist", artistId: artist.id, title: artist.name }}
|
||||
share={{ type: "artist", artistId: artist.id }}
|
||||
onAction={(action) => void handleArtistAction(artist, action)}
|
||||
>
|
||||
<MusicEntityView kind="artist" id={artist.id}>
|
||||
@@ -176,11 +176,7 @@ export const PlaylistCard = memo(function PlaylistCard({
|
||||
return (
|
||||
<MediaContextMenu
|
||||
showFavorite={false}
|
||||
share={{
|
||||
type: "playlist",
|
||||
playlistId: playlist.id,
|
||||
title: playlist.title,
|
||||
}}
|
||||
share={{ type: "playlist", playlistId: playlist.id }}
|
||||
onAction={(action) => void handlePlaylistAction(playlist, action)}
|
||||
>
|
||||
<MusicEntityView kind="playlist" id={playlist.id}>
|
||||
|
||||
@@ -147,7 +147,6 @@ export const SongListRow = memo(function SongListRow({
|
||||
type: "song",
|
||||
albumId: song.album.id,
|
||||
songId: song.id,
|
||||
title: `${song.title} - ${song.album.title}`,
|
||||
},
|
||||
onAction: (action) => onAction(song, action),
|
||||
}}
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
import { useCallback, useMemo } from "react"
|
||||
import { Platform } from "react-native"
|
||||
import { Stack } from "expo-router"
|
||||
|
||||
import { useDebouncedSearch } from "@/hooks/use-debounced-search"
|
||||
import { useThemeColors } from "@/lib/theme"
|
||||
import type { BrowseSong } from "@otunes/convex/types"
|
||||
|
||||
export function usePlaylistSearch(songs: BrowseSong[]) {
|
||||
const search = useDebouncedSearch()
|
||||
const filteredSongs = useMemo(() => {
|
||||
const query = search.searchQuery.toLowerCase()
|
||||
if (!query) return songs
|
||||
return songs.filter((song) =>
|
||||
[song.title, song.artist.name, song.album.title].some((value) =>
|
||||
value.toLowerCase().includes(query)
|
||||
)
|
||||
)
|
||||
}, [songs, search.searchQuery])
|
||||
|
||||
return { ...search, filteredSongs }
|
||||
}
|
||||
|
||||
export function PlaylistSearchBar({
|
||||
onQueryChange,
|
||||
onSearchSubmit,
|
||||
}: Pick<
|
||||
ReturnType<typeof useDebouncedSearch>,
|
||||
"onQueryChange" | "onSearchSubmit"
|
||||
>) {
|
||||
const colors = useThemeColors()
|
||||
const handleChangeText = useCallback(
|
||||
(event: { nativeEvent: { text: string } }) => {
|
||||
onQueryChange(event.nativeEvent.text)
|
||||
},
|
||||
[onQueryChange]
|
||||
)
|
||||
|
||||
return (
|
||||
<Stack.SearchBar
|
||||
placeholder="Search playlist"
|
||||
onChangeText={handleChangeText}
|
||||
onSearchButtonPress={onSearchSubmit}
|
||||
autoCapitalize="none"
|
||||
{...(Platform.OS === "android"
|
||||
? {
|
||||
barTintColor: colors.background,
|
||||
textColor: colors.foreground,
|
||||
tintColor: colors.primary,
|
||||
hintTextColor: colors.mutedForeground,
|
||||
headerIconColor: colors.foreground,
|
||||
}
|
||||
: {})}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useRef, type ReactNode } from "react"
|
||||
import { useEffect, useRef } from "react"
|
||||
import {
|
||||
Animated,
|
||||
ScrollView,
|
||||
@@ -18,30 +18,6 @@ import {
|
||||
useTwoColumnCardWidth,
|
||||
} from "@/lib/theme"
|
||||
|
||||
/** Match the inset-adjusted lists used once screen data is available. */
|
||||
function SkeletonContent({
|
||||
children,
|
||||
embedded = false,
|
||||
}: {
|
||||
children: ReactNode
|
||||
embedded?: boolean
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
if (embedded) return <>{children}</>
|
||||
|
||||
return (
|
||||
<ScrollView
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={{ paddingBottom: contentBottomInset }}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
scrollEnabled={false}
|
||||
accessibilityLabel="Loading"
|
||||
>
|
||||
{children}
|
||||
</ScrollView>
|
||||
)
|
||||
}
|
||||
|
||||
export function Skeleton({ style }: { style?: StyleProp<ViewStyle> }) {
|
||||
const colors = useThemeColors()
|
||||
const opacity = useRef(new Animated.Value(1)).current
|
||||
@@ -98,21 +74,13 @@ export function SongRowSkeleton() {
|
||||
)
|
||||
}
|
||||
|
||||
export function SongListSkeleton({
|
||||
rows = 10,
|
||||
embedded = false,
|
||||
}: {
|
||||
rows?: number
|
||||
embedded?: boolean
|
||||
}) {
|
||||
export function SongListSkeleton({ rows = 10 }: { rows?: number }) {
|
||||
return (
|
||||
<SkeletonContent embedded={embedded}>
|
||||
<View accessibilityLabel="Loading" accessibilityRole="progressbar">
|
||||
{Array.from({ length: rows }, (_, index) => (
|
||||
<SongRowSkeleton key={index} />
|
||||
))}
|
||||
</View>
|
||||
</SkeletonContent>
|
||||
<View accessibilityLabel="Loading" accessibilityRole="progressbar">
|
||||
{Array.from({ length: rows }, (_, index) => (
|
||||
<SongRowSkeleton key={index} />
|
||||
))}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -141,28 +109,24 @@ function CardSkeleton({
|
||||
export function MediaGridSkeleton({
|
||||
items = 6,
|
||||
contentInset = true,
|
||||
embedded = false,
|
||||
}: {
|
||||
items?: number
|
||||
contentInset?: boolean
|
||||
embedded?: boolean
|
||||
}) {
|
||||
const cardWidth = useTwoColumnCardWidth()
|
||||
return (
|
||||
<SkeletonContent embedded={embedded}>
|
||||
<View
|
||||
accessibilityLabel="Loading"
|
||||
accessibilityRole="progressbar"
|
||||
style={[
|
||||
styles.grid,
|
||||
contentInset ? styles.gridInset : styles.gridRowInset,
|
||||
]}
|
||||
>
|
||||
{Array.from({ length: items }, (_, index) => (
|
||||
<CardSkeleton key={index} width={cardWidth} />
|
||||
))}
|
||||
</View>
|
||||
</SkeletonContent>
|
||||
<View
|
||||
accessibilityLabel="Loading"
|
||||
accessibilityRole="progressbar"
|
||||
style={[
|
||||
styles.grid,
|
||||
contentInset ? styles.gridInset : styles.gridRowInset,
|
||||
]}
|
||||
>
|
||||
{Array.from({ length: items }, (_, index) => (
|
||||
<CardSkeleton key={index} width={cardWidth} />
|
||||
))}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -228,9 +192,9 @@ export function CollectionDetailSkeleton({
|
||||
</View>
|
||||
</View>
|
||||
{round ? (
|
||||
<MediaGridSkeleton items={4} contentInset={false} embedded />
|
||||
<MediaGridSkeleton items={4} contentInset={false} />
|
||||
) : (
|
||||
<SongListSkeleton rows={8} embedded />
|
||||
<SongListSkeleton rows={8} />
|
||||
)}
|
||||
</ScrollView>
|
||||
)
|
||||
@@ -239,19 +203,17 @@ export function CollectionDetailSkeleton({
|
||||
export function ArtistListSkeleton({ rows = 12 }: { rows?: number }) {
|
||||
const colors = useThemeColors()
|
||||
return (
|
||||
<SkeletonContent>
|
||||
<View accessibilityLabel="Loading" accessibilityRole="progressbar">
|
||||
{Array.from({ length: rows }, (_, index) => (
|
||||
<View
|
||||
key={index}
|
||||
style={[styles.artistRow, { borderBottomColor: colors.border }]}
|
||||
>
|
||||
<Skeleton style={styles.artistAvatar} />
|
||||
<TextLine width="50%" height={16} />
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
</SkeletonContent>
|
||||
<View accessibilityLabel="Loading" accessibilityRole="progressbar">
|
||||
{Array.from({ length: rows }, (_, index) => (
|
||||
<View
|
||||
key={index}
|
||||
style={[styles.artistRow, { borderBottomColor: colors.border }]}
|
||||
>
|
||||
<Skeleton style={styles.artistAvatar} />
|
||||
<TextLine width="50%" height={16} />
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -271,7 +233,7 @@ const styles = StyleSheet.create({
|
||||
grid: { flexDirection: "row", flexWrap: "wrap", gap: spacing.md },
|
||||
gridInset: { padding: spacing.lg },
|
||||
gridRowInset: { paddingHorizontal: spacing.lg },
|
||||
carousel: { gap: spacing.md, overflow: "hidden" },
|
||||
carousel: { gap: spacing.md },
|
||||
carouselRow: { flexDirection: "row", gap: spacing.md },
|
||||
home: { padding: spacing.lg, gap: spacing.xl },
|
||||
hero: { alignItems: "center", padding: spacing.lg, gap: spacing.sm },
|
||||
|
||||
@@ -87,11 +87,7 @@ type PlaybackContextValue = {
|
||||
playShuffled: (songIds: Id<"songs">[]) => Promise<void>
|
||||
addToQueueNext: (songIds: Id<"songs">[]) => Promise<void>
|
||||
addToQueueLast: (songIds: Id<"songs">[]) => Promise<void>
|
||||
playFromSong: (
|
||||
songId: Id<"songs">,
|
||||
songIds: Id<"songs">[],
|
||||
origin?: string
|
||||
) => Promise<void>
|
||||
playFromSong: (songId: Id<"songs">, songIds: Id<"songs">[]) => Promise<void>
|
||||
playFromLibrarySong: (
|
||||
songId: Id<"songs">,
|
||||
sort: {
|
||||
@@ -268,13 +264,11 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
const pendingSeekRef = useRef<number | null>(null)
|
||||
const seekInFlightRef = useRef(false)
|
||||
const loadRequestIdRef = useRef(0)
|
||||
const queueOriginRef = useRef<string | undefined>(undefined)
|
||||
const playRequestRef = useRef(0)
|
||||
const ignoreTrackChangeTimerRef = useRef<ReturnType<
|
||||
typeof setTimeout
|
||||
> | null>(null)
|
||||
|
||||
const [queueStartVersion, setQueueStartVersion] = useState(0)
|
||||
const [isPlaying, setIsPlayingState] = useState(false)
|
||||
const [currentTime, setCurrentTime] = useState(0)
|
||||
const [measuredDuration, setDuration] = useState(0)
|
||||
@@ -354,21 +348,6 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
loadedLoadKeyRef.current = null
|
||||
}, [])
|
||||
|
||||
// A new queue must not inherit the native player's position or a pending seek.
|
||||
const resetQueuePlayback = useCallback(() => {
|
||||
loadRequestIdRef.current += 1
|
||||
destroyPlaylist()
|
||||
pendingSeekRef.current = null
|
||||
seekInFlightRef.current = false
|
||||
progressRestoredForSongRef.current = null
|
||||
lastSavedProgressRef.current = -1
|
||||
currentTimeRef.current = 0
|
||||
setCurrentTime(0)
|
||||
setDuration(0)
|
||||
setProgressToRestore(null)
|
||||
setQueueStartVersion((version) => version + 1)
|
||||
}, [destroyPlaylist])
|
||||
|
||||
const handlePlaylistStatusUpdate = useCallback(
|
||||
(status: AudioPlaylistStatus) => {
|
||||
if (!status.isLoaded) return
|
||||
@@ -586,12 +565,11 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
if (progressRestoredForSongRef.current === currentSongId) return
|
||||
progressRestoredForSongRef.current = currentSongId
|
||||
lastSavedProgressRef.current = -1
|
||||
pendingSeekRef.current = null
|
||||
currentTimeRef.current = 0
|
||||
setCurrentTime(0)
|
||||
setDuration(0)
|
||||
setProgressToRestore(store.getState().progressSeconds)
|
||||
}, [currentSongId, destroyPlaylist, queueStartVersion, store])
|
||||
}, [currentSongId, destroyPlaylist, store])
|
||||
|
||||
useEffect(() => {
|
||||
if (progressToRestore === null || progressToRestore <= 0) return
|
||||
@@ -829,7 +807,6 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
handlePlaybackLoadFailure,
|
||||
historySyncKey,
|
||||
queueSyncKey,
|
||||
queueStartVersion,
|
||||
repeatEnabled,
|
||||
scheduleTrackChangeHandling,
|
||||
userPlaybackKey,
|
||||
@@ -850,19 +827,18 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
) => playbackQueue.PlaybackQueueState,
|
||||
recorded: {
|
||||
playlistId?: Id<"playlists">
|
||||
origin?: string
|
||||
entity?: { kind: MusicEntityKind; id: string }
|
||||
} = {}
|
||||
) => {
|
||||
playRequestRef.current += 1
|
||||
queueOriginRef.current =
|
||||
recorded.origin ??
|
||||
(recorded.playlistId ? `playlist:${recorded.playlistId}` : undefined)
|
||||
resetQueuePlayback()
|
||||
const previousSongId = store.getState().queue[0]
|
||||
store.update(recipe)
|
||||
const firstSongId = store.getState().queue[0]
|
||||
if (!firstSongId) return
|
||||
|
||||
if (firstSongId === previousSongId) {
|
||||
void seekTo(0)
|
||||
}
|
||||
setIsPlaying(true)
|
||||
void (async () => {
|
||||
const deadline = Date.now() + 20_000
|
||||
@@ -893,7 +869,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
: { songId: firstSongId }
|
||||
)
|
||||
},
|
||||
[store, resetQueuePlayback, setIsPlaying, recordPlay]
|
||||
[store, seekTo, setIsPlaying, recordPlay]
|
||||
)
|
||||
|
||||
const playCollection = useCallback(
|
||||
@@ -902,7 +878,6 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
shuffled: boolean,
|
||||
recorded: {
|
||||
playlistId?: Id<"playlists">
|
||||
origin?: string
|
||||
entity?: { kind: MusicEntityKind; id: string }
|
||||
} = {}
|
||||
) => {
|
||||
@@ -967,19 +942,12 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
)
|
||||
|
||||
const playFromSong = useCallback(
|
||||
async (songId: Id<"songs">, songIds: Id<"songs">[], origin?: string) => {
|
||||
if (
|
||||
origin &&
|
||||
queueOriginRef.current === origin &&
|
||||
store.getState().queue[0] === songId
|
||||
)
|
||||
return
|
||||
startPlayback(
|
||||
(state) => playbackQueue.startQueueFromSong(state, songId, songIds),
|
||||
{ origin }
|
||||
async (songId: Id<"songs">, songIds: Id<"songs">[]) => {
|
||||
startPlayback((state) =>
|
||||
playbackQueue.startQueueFromSong(state, songId, songIds)
|
||||
)
|
||||
},
|
||||
[startPlayback, store]
|
||||
[startPlayback]
|
||||
)
|
||||
|
||||
const playFromLibrarySong = useCallback(
|
||||
@@ -1049,7 +1017,6 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
(albumId: Id<"albums">, songIds?: Id<"songs">[]) =>
|
||||
playCollection(loadAlbumSongIds(albumId, songIds), false, {
|
||||
entity: { kind: "album", id: albumId },
|
||||
origin: `album:${albumId}`,
|
||||
}),
|
||||
[playCollection, loadAlbumSongIds]
|
||||
)
|
||||
@@ -1058,7 +1025,6 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
(albumId: Id<"albums">, songIds?: Id<"songs">[]) =>
|
||||
playCollection(loadAlbumSongIds(albumId, songIds), true, {
|
||||
entity: { kind: "album", id: albumId },
|
||||
origin: `album:${albumId}`,
|
||||
}),
|
||||
[playCollection, loadAlbumSongIds]
|
||||
)
|
||||
@@ -1121,14 +1087,12 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
async (songIds: Id<"songs">[], shuffled: boolean) => {
|
||||
if (songIds.length === 0) return
|
||||
playRequestRef.current += 1
|
||||
queueOriginRef.current = undefined
|
||||
resetQueuePlayback()
|
||||
store.update((state) =>
|
||||
playbackQueue.startQueue(state, songIds, shuffled)
|
||||
)
|
||||
setIsPlaying(false)
|
||||
},
|
||||
[store, resetQueuePlayback, setIsPlaying]
|
||||
[store, setIsPlaying]
|
||||
)
|
||||
|
||||
const startFromSong = useCallback(
|
||||
@@ -1139,20 +1103,17 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
play: boolean
|
||||
) => {
|
||||
playRequestRef.current += 1
|
||||
queueOriginRef.current = undefined
|
||||
resetQueuePlayback()
|
||||
store.update((state) => playbackQueue.setShuffleEnabled(state, shuffled))
|
||||
store.update((state) =>
|
||||
playbackQueue.startQueueFromSong(state, songId, songIds)
|
||||
)
|
||||
setIsPlaying(play)
|
||||
},
|
||||
[store, resetQueuePlayback, setIsPlaying]
|
||||
[store, setIsPlaying]
|
||||
)
|
||||
|
||||
const clearQueue = useCallback(async () => {
|
||||
playRequestRef.current += 1
|
||||
queueOriginRef.current = undefined
|
||||
store.update(playbackQueue.clearQueue)
|
||||
setIsPlaying(false)
|
||||
}, [store, setIsPlaying])
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
// Keep the destination while server setup or sign-in is on screen.
|
||||
const listeners = new Set<() => void>()
|
||||
|
||||
export function subscribeIncomingMediaLink(listener: () => void) {
|
||||
listeners.add(listener)
|
||||
return () => {
|
||||
listeners.delete(listener)
|
||||
}
|
||||
}
|
||||
|
||||
let pendingLink: { path: string; serverOrigin: string } | null = null
|
||||
|
||||
export function incomingMediaLink(serverUrl: string) {
|
||||
if (!pendingLink) return null
|
||||
return new URL(serverUrl).origin === pendingLink.serverOrigin
|
||||
? pendingLink.path
|
||||
: null
|
||||
}
|
||||
|
||||
export function takeIncomingMediaLink(serverUrl: string) {
|
||||
const path = incomingMediaLink(serverUrl)
|
||||
pendingLink = null
|
||||
for (const listener of listeners) listener()
|
||||
return path
|
||||
}
|
||||
|
||||
export function rememberIncomingMediaLink(path: string, serverOrigin: string) {
|
||||
pendingLink = { path, serverOrigin }
|
||||
for (const listener of listeners) listener()
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
export type MediaShareContext = (
|
||||
export type MediaShareContext =
|
||||
| { type: "album"; albumId: string }
|
||||
| { type: "song"; albumId: string; songId: string }
|
||||
| { type: "playlist"; playlistId: string; isFavorites?: boolean }
|
||||
| { type: "artist"; artistId: string }
|
||||
) & { title: string }
|
||||
|
||||
export function shouldShowShare(
|
||||
share: MediaShareContext | undefined,
|
||||
|
||||
@@ -1,4 +1,19 @@
|
||||
import { requireOptionalNativeModule } from "expo"
|
||||
import { Platform } from "react-native"
|
||||
|
||||
// Android Dolby decoder reports do not reliably indicate working Atmos playback.
|
||||
export const dolbyAtmosSupported = Platform.OS === "ios"
|
||||
// E-AC-3 support varies by Android device. Older native builds fail closed.
|
||||
function supportsDolbyAtmos(): boolean {
|
||||
if (Platform.OS === "ios") return true
|
||||
if (Platform.OS !== "android") return false
|
||||
try {
|
||||
return (
|
||||
requireOptionalNativeModule<{
|
||||
supportsDolbyAtmos?: () => boolean
|
||||
}>("AudioOutput")?.supportsDolbyAtmos?.() ?? false
|
||||
)
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export const dolbyAtmosSupported = supportsDolbyAtmos()
|
||||
@@ -1,4 +1,3 @@
|
||||
import { requireOptionalNativeModule } from "expo"
|
||||
import * as Sharing from "expo-sharing"
|
||||
import { Platform, Share } from "react-native"
|
||||
|
||||
@@ -6,10 +5,6 @@ import type { MediaShareContext } from "@/lib/media-links"
|
||||
import { mediaShareUrl } from "@/lib/media-links"
|
||||
import { showError } from "@/lib/toast"
|
||||
|
||||
const nativeShare = requireOptionalNativeModule<{
|
||||
share: (url: string, artwork: string, title: string) => Promise<void>
|
||||
}>("MediaLinkShare")
|
||||
|
||||
export async function shareMediaLink(
|
||||
serverUrl: string,
|
||||
share: MediaShareContext
|
||||
@@ -22,32 +17,12 @@ export async function shareMediaLink(
|
||||
showError("Sharing is not available on this device")
|
||||
return
|
||||
}
|
||||
await Sharing.shareAsync(url, { dialogTitle: share.title })
|
||||
return
|
||||
}
|
||||
|
||||
if (nativeShare) {
|
||||
const type = share.type === "song" ? "album" : share.type
|
||||
const id =
|
||||
share.type === "album" || share.type === "song"
|
||||
? share.albumId
|
||||
: share.type === "artist"
|
||||
? share.artistId
|
||||
: share.isFavorites
|
||||
? "favorites"
|
||||
: share.playlistId
|
||||
await nativeShare.share(
|
||||
url,
|
||||
`${serverUrl.replace(/\/+$/, "")}/api/${type}/${id}/cover?size=512`,
|
||||
share.title
|
||||
)
|
||||
await Sharing.shareAsync(url, { dialogTitle: "Share" })
|
||||
return
|
||||
}
|
||||
|
||||
await Share.share(
|
||||
Platform.OS === "ios"
|
||||
? { url, title: share.title }
|
||||
: { message: url, title: share.title }
|
||||
Platform.OS === "ios" ? { url } : { message: url }
|
||||
)
|
||||
} catch (error) {
|
||||
if (error instanceof Error && /cancel/i.test(error.message)) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { dolbyAtmosSupported } from "@/lib/playback-capabilities"
|
||||
import { Platform } from "react-native"
|
||||
import type { AudioSource } from "expo-audio"
|
||||
|
||||
@@ -54,7 +53,7 @@ export function songPlayUrl(
|
||||
const params = new URLSearchParams()
|
||||
if (Platform.OS === "ios") params.set("losslessFormat", "alac")
|
||||
if (quality) params.set("quality", quality)
|
||||
if (dolbyAtmosSupported && preferAtmos) params.set("preferAtmos", "true")
|
||||
if (preferAtmos) params.set("preferAtmos", "true")
|
||||
const query = params.toString()
|
||||
return `${serverUrl}/api/song/${songId}/play${query ? `?${query}` : ""}`
|
||||
}
|
||||
@@ -67,7 +66,7 @@ export function songHlsPlaylistUrl(
|
||||
) {
|
||||
const params = new URLSearchParams()
|
||||
if (quality) params.set("quality", quality)
|
||||
if (dolbyAtmosSupported && preferAtmos) params.set("preferAtmos", "true")
|
||||
if (preferAtmos) params.set("preferAtmos", "true")
|
||||
const query = params.toString()
|
||||
return `${serverUrl}/api/song/${songId}/play/hls${query ? `?${query}` : ""}`
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package expo.modules.audiooutput
|
||||
|
||||
import android.media.MediaCodecList
|
||||
import android.os.Build
|
||||
import androidx.mediarouter.app.SystemOutputSwitcherDialogController
|
||||
import expo.modules.kotlin.functions.Queues
|
||||
@@ -10,6 +11,16 @@ class AudioOutputModule : Module() {
|
||||
override fun definition() = ModuleDefinition {
|
||||
Name("AudioOutput")
|
||||
|
||||
Function("supportsDolbyAtmos") {
|
||||
// Library Atmos tracks use E-AC-3. ExoPlayer needs a device decoder.
|
||||
MediaCodecList(MediaCodecList.REGULAR_CODECS).codecInfos.any { codec ->
|
||||
!codec.isEncoder && codec.supportedTypes.any { type ->
|
||||
type.equals("audio/eac3", ignoreCase = true) ||
|
||||
type.equals("audio/eac3-joc", ignoreCase = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AsyncFunction("showPicker") {
|
||||
val activity = appContext.currentActivity
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU || activity == null) {
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
package com.abunchofknowitalls.otunes
|
||||
|
||||
import android.content.ClipData
|
||||
import android.content.Intent
|
||||
import androidx.core.content.FileProvider
|
||||
import expo.modules.kotlin.modules.Module
|
||||
import expo.modules.kotlin.modules.ModuleDefinition
|
||||
import java.io.File
|
||||
import java.net.URL
|
||||
|
||||
class MediaLinkShare : Module() {
|
||||
override fun definition() = ModuleDefinition {
|
||||
Name("MediaLinkShare")
|
||||
AsyncFunction("share") { link: String, artwork: String, title: String ->
|
||||
val context = requireNotNull(appContext.reactContext)
|
||||
val intent = Intent(Intent.ACTION_SEND).apply {
|
||||
type = "text/plain"
|
||||
putExtra(Intent.EXTRA_TEXT, link)
|
||||
putExtra(Intent.EXTRA_TITLE, title)
|
||||
putExtra(Intent.EXTRA_SUBJECT, title)
|
||||
}
|
||||
// ClipData supplies the chooser thumbnail while the shared item stays a URL.
|
||||
try {
|
||||
val connection = URL(artwork).openConnection().apply {
|
||||
connectTimeout = 8000
|
||||
readTimeout = 8000
|
||||
}
|
||||
context.cacheDir.listFiles()?.filter {
|
||||
it.name.startsWith("media-link-cover-") && it.lastModified() < System.currentTimeMillis() - 86400000
|
||||
}?.forEach { it.delete() }
|
||||
val extension = when (connection.contentType?.substringBefore(";")) {
|
||||
"image/webp" -> "webp"
|
||||
"image/png" -> "png"
|
||||
"image/jpeg" -> "jpg"
|
||||
"image/gif" -> "gif"
|
||||
else -> error("Artwork format is not supported")
|
||||
}
|
||||
val file = File(context.cacheDir, "media-link-cover-${java.util.UUID.randomUUID()}.${extension}")
|
||||
connection.getInputStream().use { input ->
|
||||
file.outputStream().use { output -> input.copyTo(output) }
|
||||
}
|
||||
val uri = FileProvider.getUriForFile(context, context.packageName + ".SharingFileProvider", file)
|
||||
intent.clipData = ClipData.newUri(context.contentResolver, "Artwork", uri)
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
} catch (_: Exception) {
|
||||
// A failed artwork download must not prevent sharing the link.
|
||||
}
|
||||
appContext.throwingActivity.runOnUiThread {
|
||||
appContext.throwingActivity.startActivity(Intent.createChooser(intent, "Share"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
import UIKit
|
||||
import LinkPresentation
|
||||
internal import ExpoModulesCore
|
||||
|
||||
private final class MediaLinkItem: NSObject, UIActivityItemSource {
|
||||
let url: URL
|
||||
let image: UIImage?
|
||||
let title: String
|
||||
init(url: URL, image: UIImage?, title: String) {
|
||||
self.url = url
|
||||
self.image = image
|
||||
self.title = title
|
||||
}
|
||||
func activityViewControllerPlaceholderItem(_ controller: UIActivityViewController) -> Any { url }
|
||||
func activityViewController(_ controller: UIActivityViewController, itemForActivityType: UIActivity.ActivityType?) -> Any? { url }
|
||||
func activityViewControllerLinkMetadata(_ controller: UIActivityViewController) -> LPLinkMetadata? {
|
||||
let metadata = LPLinkMetadata()
|
||||
metadata.originalURL = url
|
||||
metadata.url = url
|
||||
metadata.title = title
|
||||
if let image {
|
||||
metadata.imageProvider = NSItemProvider(object: image)
|
||||
metadata.iconProvider = NSItemProvider(object: image)
|
||||
}
|
||||
return metadata
|
||||
}
|
||||
}
|
||||
|
||||
final class MediaLinkShare: Module {
|
||||
public func definition() -> ExpoModulesCore.ModuleDefinition {
|
||||
Name("MediaLinkShare")
|
||||
AsyncFunction("share") { (link: String, artwork: String, title: String) in
|
||||
guard let url = URL(string: link), let artworkURL = URL(string: artwork) else { return }
|
||||
var image: UIImage?
|
||||
var request = URLRequest(url: artworkURL)
|
||||
request.timeoutInterval = 8
|
||||
if let (data, response) = try? await URLSession.shared.data(for: request),
|
||||
(response as? HTTPURLResponse)?.statusCode == 200 {
|
||||
image = UIImage(data: data)
|
||||
}
|
||||
let artworkImage = image
|
||||
await MainActor.run {
|
||||
guard let presenter = self.appContext?.utilities?.currentViewController() else { return }
|
||||
let controller = UIActivityViewController(
|
||||
activityItems: [MediaLinkItem(url: url, image: artworkImage, title: title)], applicationActivities: nil)
|
||||
if let popover = controller.popoverPresentationController {
|
||||
popover.sourceView = presenter.view
|
||||
popover.sourceRect = CGRect(x: presenter.view.bounds.midX, y: presenter.view.bounds.midY, width: 0, height: 0)
|
||||
popover.permittedArrowDirections = []
|
||||
}
|
||||
presenter.present(controller, animated: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
"use client"
|
||||
|
||||
import { PageHeader } from "@/components/library-skeletons"
|
||||
|
||||
import Link from "next/link"
|
||||
import { Home, Search } from "lucide-react"
|
||||
|
||||
@@ -10,7 +8,6 @@ import { Button } from "@/components/ui/button"
|
||||
export default function Page() {
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<PageHeader />
|
||||
<div className="flex flex-1 items-center justify-center px-6 pb-28">
|
||||
<div className="flex max-w-md flex-col items-center text-center">
|
||||
<p className="text-sm font-medium text-muted-foreground">404</p>
|
||||
|
||||
@@ -5,8 +5,6 @@ import { PlayerBar } from "@/components/player-bar"
|
||||
import { LazyQueuePanel } from "@/components/lazy-queue-panel"
|
||||
import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar"
|
||||
import { AppSidebar } from "@/components/app-sidebar"
|
||||
import { ScrollRestoration } from "@/components/scroll-restoration"
|
||||
import { Suspense } from "react"
|
||||
|
||||
export default function AppLayout({
|
||||
children,
|
||||
@@ -20,11 +18,7 @@ export default function AppLayout({
|
||||
<FavoritesProvider>
|
||||
<AppSidebar />
|
||||
<div className="flex min-h-svh min-w-0 flex-1">
|
||||
<SidebarInset className="min-w-0 flex-1">
|
||||
<Suspense>
|
||||
<ScrollRestoration>{children}</ScrollRestoration>
|
||||
</Suspense>
|
||||
</SidebarInset>
|
||||
<SidebarInset className="min-w-0 flex-1">{children}</SidebarInset>
|
||||
<LazyQueuePanel />
|
||||
</div>
|
||||
<PlayerBar />
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import { useSearchParams } from "next/navigation"
|
||||
|
||||
import { MobileSidebarTrigger } from "@/components/mobile-sidebar-trigger"
|
||||
import { SearchResultsSkeleton } from "@/components/library-skeletons"
|
||||
import { SearchPrompt } from "@/components/search-prompt"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
@@ -12,8 +11,7 @@ export default function Loading() {
|
||||
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<header className="flex items-center justify-center gap-2 border-b px-4 py-3">
|
||||
<MobileSidebarTrigger />
|
||||
<header className="flex items-center justify-center border-b px-4 py-3">
|
||||
<Skeleton className="h-10 w-full max-w-xl rounded-full" />
|
||||
</header>
|
||||
{hasQuery ? <SearchResultsSkeleton /> : <SearchPrompt />}
|
||||
|
||||
|
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 35 KiB |
@@ -1,12 +1,11 @@
|
||||
"use client"
|
||||
|
||||
import { PageHeader } from "@/components/library-skeletons"
|
||||
import { MobileSidebarTrigger } from "@/components/mobile-sidebar-trigger"
|
||||
import * as React from "react"
|
||||
import Image from "next/image"
|
||||
import Link from "next/link"
|
||||
import { Play, Share2, Shuffle, Star } from "lucide-react"
|
||||
|
||||
import { AudioFormatBadge } from "@/components/audio-format-badge"
|
||||
import { MediaCollectionFooter } from "@/components/media-collection-footer"
|
||||
import { TrackNumberPlayButton } from "@/components/track-number-play-button"
|
||||
|
||||
@@ -22,8 +21,6 @@ import {
|
||||
} from "@/components/media-context-menu"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { ScrollArea } from "@/components/ui/scroll-area"
|
||||
import { useCachedQuery } from "@/hooks/use-cached-query"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import { useQueueMediaActions } from "@/hooks/use-queue-media-actions"
|
||||
import { useTrackSelection } from "@/hooks/use-track-selection"
|
||||
import { cn } from "@/lib/utils"
|
||||
@@ -276,20 +273,6 @@ export function AlbumView({
|
||||
[album.tracks]
|
||||
)
|
||||
|
||||
// Older servers do not include album format availability yet.
|
||||
const formatTracks = useCachedQuery(
|
||||
api.library.getSongsForPlayback,
|
||||
album.hasLossless === undefined || album.hasAtmos === undefined
|
||||
? { ids: albumSongIds }
|
||||
: "skip"
|
||||
)
|
||||
const hasLossless =
|
||||
album.hasLossless ??
|
||||
formatTracks?.some((track) => track && "lossless" in track.files)
|
||||
const hasAtmos =
|
||||
album.hasAtmos ??
|
||||
formatTracks?.some((track) => track && "atmos" in track.files)
|
||||
|
||||
React.useEffect(() => {
|
||||
rememberSongs(albumDetailSongs(album))
|
||||
}, [album])
|
||||
@@ -389,8 +372,7 @@ export function AlbumView({
|
||||
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<PageHeader openApp />
|
||||
<ScrollArea className="min-h-0 flex-1 [&_[data-slot=scroll-area-viewport]>div]:block!">
|
||||
<ScrollArea className="min-h-0 flex-1">
|
||||
<div className="pb-28">
|
||||
<div className="mx-auto w-full min-w-0 max-w-9/10">
|
||||
<div className="flex flex-col gap-8 pt-6 pb-8 sm:flex-row sm:items-end">
|
||||
@@ -410,32 +392,21 @@ export function AlbumView({
|
||||
<p className="text-xs font-medium tracking-wide text-muted-foreground uppercase">
|
||||
Album
|
||||
</p>
|
||||
<h1 className="text-3xl font-bold tracking-tight sm:text-4xl">
|
||||
{album.title}
|
||||
</h1>
|
||||
<div className="flex min-w-0 items-center justify-center gap-2 sm:justify-start md:contents">
|
||||
<MobileSidebarTrigger />
|
||||
<h1 className="text-3xl font-bold tracking-tight sm:text-4xl">
|
||||
{album.title}
|
||||
</h1>
|
||||
</div>
|
||||
<Link
|
||||
href={"/artist/" + album.artist.id}
|
||||
className="inline-block text-lg font-semibold text-primary hover:underline"
|
||||
>
|
||||
{album.artist.name}
|
||||
</Link>
|
||||
<div className="flex flex-wrap items-center justify-center gap-2 text-sm text-muted-foreground sm:justify-start">
|
||||
{metadata ? <span>{metadata}</span> : null}
|
||||
{hasLossless ? (
|
||||
<>
|
||||
{metadata ? <span aria-hidden>·</span> : null}
|
||||
<AudioFormatBadge format="lossless" />
|
||||
</>
|
||||
) : null}
|
||||
{hasAtmos ? (
|
||||
<>
|
||||
{metadata || hasLossless ? (
|
||||
<span aria-hidden>·</span>
|
||||
) : null}
|
||||
<AudioFormatBadge format="atmos" />
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
{metadata ? (
|
||||
<p className="text-sm text-muted-foreground">{metadata}</p>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center justify-center gap-2 sm:justify-start">
|
||||
@@ -547,8 +518,7 @@ export function AlbumView({
|
||||
onPlay={() =>
|
||||
void playFromSong(
|
||||
track.id as Id<"songs">,
|
||||
albumSongIds,
|
||||
`album:${album.id}`
|
||||
albumSongIds
|
||||
)
|
||||
}
|
||||
/>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client"
|
||||
|
||||
import { PageHeader } from "@/components/library-skeletons"
|
||||
import { MobileSidebarTrigger } from "@/components/mobile-sidebar-trigger"
|
||||
import * as React from "react"
|
||||
import Image from "next/image"
|
||||
import { Play, Shuffle } from "lucide-react"
|
||||
@@ -65,7 +65,6 @@ export function ArtistView({
|
||||
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<PageHeader openApp />
|
||||
<ScrollArea className="min-h-0 flex-1">
|
||||
<div className="pb-28">
|
||||
<div className="flex min-w-0 items-center gap-4 px-6 pt-6 pb-8 sm:gap-6">
|
||||
@@ -81,9 +80,12 @@ export function ArtistView({
|
||||
</div>
|
||||
|
||||
<div className="flex min-w-0 flex-1 flex-col gap-4">
|
||||
<h1 className="min-w-0 truncate text-3xl font-bold tracking-tight sm:text-4xl lg:text-5xl">
|
||||
{artist.name}
|
||||
</h1>
|
||||
<div className="flex min-w-0 items-center gap-2 md:contents">
|
||||
<MobileSidebarTrigger />
|
||||
<h1 className="min-w-0 truncate text-3xl font-bold tracking-tight sm:text-4xl lg:text-5xl">
|
||||
{artist.name}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Button
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
import type { PlaybackFormat } from "@otunes/convex/playback-stream"
|
||||
|
||||
const MARK_HEIGHT = 11
|
||||
|
||||
function DolbyMark({ color }: { color: string }) {
|
||||
return (
|
||||
<svg
|
||||
width={(MARK_HEIGHT * 23) / 16}
|
||||
height={MARK_HEIGHT}
|
||||
viewBox="0 0 23 16"
|
||||
>
|
||||
<path d="M0 0H2.5A8 8 0 0 1 2.5 16H0Z" fill={color} />
|
||||
<path d="M23 0H20.5A8 8 0 0 0 20.5 16H23Z" fill={color} />
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
|
||||
const LOSSLESS_PEAKS = [110, 215, 320]
|
||||
const LOSSLESS_THIN_WIDTH = 24
|
||||
const LOSSLESS_STROKES: [peak: number, d: string][] = [
|
||||
[110, "M-70 320C-62 245 -38 166 0 166"],
|
||||
[215, "M-70 320C-62 245 -38 166 0 166"],
|
||||
[320, "M-30 185C-22 173 -11 166 0 166"],
|
||||
[110, "M166 413C176 413 186 406 194 395"],
|
||||
[215, "M166 413C200 413 226 340 240 275"],
|
||||
[320, "M166 413C200 413 226 340 240 275"],
|
||||
]
|
||||
const LOSSLESS_FALL =
|
||||
"M0 178L4 179L8 181L12 184L16 189L20 196L23 204L27 213L30 223L34 233L39 243L43 254L48 266L53 278L58 289L62 301L66 313L71 325L75 336L79 347L83 357L86 364L89 370L93 377L97 382L101 387L105 392L109 397L113 401L117 405L121 408L126 412L130 415L134 417L139 419L143 421L148 423L152 424L157 424L161 425L166 425L166 401L163 401L161 400L159 400L157 399L154 397L152 396L151 394L149 392L147 389L145 386L143 383L142 380L140 376L138 371L137 367L135 362L134 357L132 351L130 345L127 339L124 330L120 319L116 308L111 297L107 285L102 272L98 260L93 248L88 235L82 223L76 212L69 201L61 192L53 183L45 175L37 168L28 163L19 158L10 155L0 154Z"
|
||||
const LOSSLESS_FALL_GAP =
|
||||
"M0 178L4 180L6 184L8 190L9 197L11 203L14 210L17 219L21 228L24 238L29 248L33 259L38 270L43 282L47 293L52 305L56 317L60 328L64 340L68 351L73 361L76 368L79 375L83 381L87 387L91 393L95 398L100 403L104 408L109 412L113 416L118 419L124 422L130 424L135 425L141 426L147 426L152 426L157 425L161 425L166 425L166 401L163 401L161 399L159 398L158 395L157 393L156 390L155 387L155 384L154 381L153 379L152 376L150 373L149 369L148 366L146 361L145 357L143 352L142 347L140 341L137 335L134 326L130 315L126 304L122 293L117 281L113 268L108 256L103 243L98 231L92 219L86 207L79 196L71 186L62 177L53 168L44 161L32 157L21 155L10 154L0 154Z"
|
||||
|
||||
/**
|
||||
* Three overlapping waves. Each thick downstroke is outlined in the
|
||||
* background color so it reads as passing over the strokes behind it.
|
||||
*/
|
||||
function LosslessMark({
|
||||
color,
|
||||
backgroundColor,
|
||||
}: {
|
||||
color: string
|
||||
backgroundColor: string
|
||||
}) {
|
||||
return (
|
||||
<svg
|
||||
width={(MARK_HEIGHT * 544) / 271}
|
||||
height={MARK_HEIGHT}
|
||||
viewBox="28 154 544 271"
|
||||
>
|
||||
{LOSSLESS_STROKES.map(([peak, d], index) => (
|
||||
<path
|
||||
key={index}
|
||||
d={d}
|
||||
transform={`translate(${peak})`}
|
||||
stroke={color}
|
||||
strokeWidth={LOSSLESS_THIN_WIDTH}
|
||||
strokeLinecap="round"
|
||||
fill="none"
|
||||
/>
|
||||
))}
|
||||
{LOSSLESS_PEAKS.map((peak) => (
|
||||
<g key={peak} transform={`translate(${peak})`}>
|
||||
<path d={LOSSLESS_FALL_GAP} fill={backgroundColor} />
|
||||
<path d={LOSSLESS_FALL} fill={color} />
|
||||
</g>
|
||||
))}
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
|
||||
export function AudioFormatBadge({
|
||||
format,
|
||||
iconOnly = false,
|
||||
backgroundColor = "var(--background)",
|
||||
}: {
|
||||
format: PlaybackFormat
|
||||
iconOnly?: boolean
|
||||
backgroundColor?: string
|
||||
}) {
|
||||
const label = format === "atmos" ? "Dolby Atmos" : "Lossless"
|
||||
return (
|
||||
<span
|
||||
className="inline-flex shrink-0 items-center gap-[3px] text-[13px] font-medium"
|
||||
title={iconOnly ? label : undefined}
|
||||
>
|
||||
<span aria-hidden="true">
|
||||
{format === "atmos" ? (
|
||||
<DolbyMark color="currentColor" />
|
||||
) : (
|
||||
<LosslessMark
|
||||
color="currentColor"
|
||||
backgroundColor={backgroundColor}
|
||||
/>
|
||||
)}
|
||||
</span>
|
||||
<span className={iconOnly ? "sr-only" : undefined}>{label}</span>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import { OpenAppButton } from "@/components/open-app-button"
|
||||
import { MobileSidebarTrigger } from "@/components/mobile-sidebar-trigger"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
import { albumGridClassName } from "@/lib/album-grid-classes"
|
||||
@@ -20,27 +19,11 @@ function LoadingRegion({
|
||||
)
|
||||
}
|
||||
|
||||
export function PageHeader({
|
||||
title,
|
||||
openApp = false,
|
||||
}: {
|
||||
title?: string
|
||||
openApp?: boolean
|
||||
}) {
|
||||
export function PageHeader({ title }: { title: string }) {
|
||||
return (
|
||||
<header
|
||||
className={cn(
|
||||
"flex shrink-0 items-center gap-2 border-b px-4 py-3",
|
||||
!title && "md:hidden"
|
||||
)}
|
||||
>
|
||||
<header className="flex items-center gap-2 border-b px-4 py-3">
|
||||
<MobileSidebarTrigger />
|
||||
{title ? (
|
||||
<h1 className="text-lg font-semibold">{title}</h1>
|
||||
) : openApp ? (
|
||||
<span className="font-semibold">oTunes</span>
|
||||
) : null}
|
||||
{openApp ? <OpenAppButton /> : null}
|
||||
<h1 className="text-lg font-semibold">{title}</h1>
|
||||
</header>
|
||||
)
|
||||
}
|
||||
@@ -152,7 +135,6 @@ export function SongListSkeleton() {
|
||||
export function CollectionDetailSkeleton() {
|
||||
return (
|
||||
<LoadingRegion className="flex h-svh flex-col overflow-hidden pb-28">
|
||||
<PageHeader />
|
||||
<div className="mx-auto w-full max-w-9/10 min-w-0">
|
||||
<div className="flex flex-col gap-8 px-6 pt-6 pb-8 sm:flex-row sm:items-end">
|
||||
<Skeleton className="mx-auto aspect-square w-full max-w-60 shrink-0 rounded-lg sm:mx-0" />
|
||||
@@ -181,7 +163,6 @@ export function CollectionDetailSkeleton() {
|
||||
export function ArtistDetailSkeleton() {
|
||||
return (
|
||||
<LoadingRegion className="flex h-svh flex-col overflow-hidden pb-28">
|
||||
<PageHeader />
|
||||
<div className="flex min-w-0 items-center gap-4 px-6 pt-6 pb-8 sm:gap-6">
|
||||
<Skeleton className="size-32 shrink-0 rounded-full sm:size-40" />
|
||||
<div className="flex min-w-0 flex-1 flex-col gap-4">
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
"use client"
|
||||
|
||||
import { ArrowUpRight } from "lucide-react"
|
||||
|
||||
export function OpenAppButton() {
|
||||
function openApp() {
|
||||
const link = new URL("otunes://open")
|
||||
link.searchParams.set("url", window.location.href)
|
||||
window.location.assign(link.href)
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={openApp}
|
||||
className="ml-auto inline-flex shrink-0 items-center gap-1 text-sm font-medium hover:underline focus-visible:outline-2 focus-visible:outline-offset-4 md:hidden"
|
||||
>
|
||||
Open App
|
||||
<ArrowUpRight aria-hidden className="size-4" />
|
||||
</button>
|
||||
)
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
import { PageHeader } from "@/components/library-skeletons"
|
||||
|
||||
export function PageMessage({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<PageHeader />
|
||||
<div className="flex flex-1 items-center justify-center pb-28">
|
||||
<p className="text-sm text-muted-foreground">{children}</p>
|
||||
</div>
|
||||
|
||||
@@ -19,11 +19,7 @@ import { toast } from "sonner"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import type { BrowseSong } from "@otunes/convex/types"
|
||||
import {
|
||||
playbackFormat,
|
||||
type PlaybackFormat,
|
||||
playbackStreamPlan,
|
||||
} from "@otunes/convex/playback-stream"
|
||||
import { playbackStreamPlan } from "@otunes/convex/playback-stream"
|
||||
import {
|
||||
ANONYMOUS_CACHE_SCOPE,
|
||||
useCacheScope,
|
||||
@@ -48,7 +44,6 @@ const PROGRESS_SAVE_INTERVAL_MS = 5000
|
||||
type PlaybackContextValue = {
|
||||
queueSongIds: Id<"songs">[]
|
||||
queueHistorySongIds: Id<"songs">[]
|
||||
currentFormat: PlaybackFormat | null
|
||||
currentSong: BrowseSong | null
|
||||
shuffleEnabled: boolean
|
||||
repeatEnabled: RepeatMode
|
||||
@@ -63,11 +58,7 @@ type PlaybackContextValue = {
|
||||
playShuffled: (songIds: Id<"songs">[]) => Promise<void>
|
||||
addToQueueNext: (songIds: Id<"songs">[]) => Promise<void>
|
||||
addToQueueLast: (songIds: Id<"songs">[]) => Promise<void>
|
||||
playFromSong: (
|
||||
songId: Id<"songs">,
|
||||
songIds: Id<"songs">[],
|
||||
origin?: string
|
||||
) => Promise<void>
|
||||
playFromSong: (songId: Id<"songs">, songIds: Id<"songs">[]) => Promise<void>
|
||||
playFromLibrarySong: (
|
||||
songId: Id<"songs">,
|
||||
sort: {
|
||||
@@ -1054,7 +1045,6 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
}
|
||||
}, [currentSongId, currentSong])
|
||||
|
||||
const queueOriginRef = useRef<string | undefined>(undefined)
|
||||
const playRequestRef = useRef(0)
|
||||
|
||||
const startPlayback = useCallback(
|
||||
@@ -1062,12 +1052,9 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
recipe: (
|
||||
state: playbackQueue.PlaybackQueueState
|
||||
) => playbackQueue.PlaybackQueueState,
|
||||
recorded: { playlistId?: Id<"playlists">; origin?: string } = {}
|
||||
recorded: { playlistId?: Id<"playlists"> } = {}
|
||||
) => {
|
||||
playRequestRef.current += 1
|
||||
queueOriginRef.current =
|
||||
recorded.origin ??
|
||||
(recorded.playlistId ? `playlist:${recorded.playlistId}` : undefined)
|
||||
const previousSongId = store.getState().queue[0]
|
||||
store.update(recipe)
|
||||
const firstSongId = store.getState().queue[0]
|
||||
@@ -1092,7 +1079,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
async (
|
||||
songIds: Id<"songs">[] | Promise<Id<"songs">[]>,
|
||||
shuffled: boolean,
|
||||
recorded: { playlistId?: Id<"playlists">; origin?: string } = {}
|
||||
recorded: { playlistId?: Id<"playlists"> } = {}
|
||||
) => {
|
||||
const request = ++playRequestRef.current
|
||||
let resolvedSongIds: Id<"songs">[]
|
||||
@@ -1157,19 +1144,12 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
)
|
||||
|
||||
const playFromSong = useCallback(
|
||||
async (songId: Id<"songs">, songIds: Id<"songs">[], origin?: string) => {
|
||||
if (
|
||||
origin &&
|
||||
queueOriginRef.current === origin &&
|
||||
store.getState().queue[0] === songId
|
||||
)
|
||||
return
|
||||
startPlayback(
|
||||
(state) => playbackQueue.startQueueFromSong(state, songId, songIds),
|
||||
{ origin }
|
||||
async (songId: Id<"songs">, songIds: Id<"songs">[]) => {
|
||||
startPlayback((state) =>
|
||||
playbackQueue.startQueueFromSong(state, songId, songIds)
|
||||
)
|
||||
},
|
||||
[startPlayback, store]
|
||||
[startPlayback]
|
||||
)
|
||||
|
||||
const playFromLibrarySong = useCallback(
|
||||
@@ -1237,17 +1217,13 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
|
||||
const playAlbum = useCallback(
|
||||
(albumId: Id<"albums">, songIds?: Id<"songs">[]) =>
|
||||
playCollection(loadAlbumSongIds(albumId, songIds), false, {
|
||||
origin: `album:${albumId}`,
|
||||
}),
|
||||
playCollection(loadAlbumSongIds(albumId, songIds), false),
|
||||
[playCollection, loadAlbumSongIds]
|
||||
)
|
||||
|
||||
const playAlbumShuffled = useCallback(
|
||||
(albumId: Id<"albums">, songIds?: Id<"songs">[]) =>
|
||||
playCollection(loadAlbumSongIds(albumId, songIds), true, {
|
||||
origin: `album:${albumId}`,
|
||||
}),
|
||||
playCollection(loadAlbumSongIds(albumId, songIds), true),
|
||||
[playCollection, loadAlbumSongIds]
|
||||
)
|
||||
|
||||
@@ -1345,21 +1321,11 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
skipPrevious,
|
||||
})
|
||||
|
||||
const currentFormat =
|
||||
currentSongDoc && user
|
||||
? playbackFormat(
|
||||
currentSongDoc.files,
|
||||
user.playbackQuality,
|
||||
dolbyAtmosSupported === true && (user.preferAtmos ?? false)
|
||||
)
|
||||
: null
|
||||
|
||||
const value = useMemo<PlaybackContextValue>(
|
||||
() => ({
|
||||
queueSongIds: playback.queue,
|
||||
queueHistorySongIds: playback.history,
|
||||
currentSong,
|
||||
currentFormat,
|
||||
shuffleEnabled: playback.shuffleEnabled,
|
||||
repeatEnabled: playback.repeatEnabled,
|
||||
queueOpen,
|
||||
@@ -1393,7 +1359,6 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
[
|
||||
playback,
|
||||
currentSong,
|
||||
currentFormat,
|
||||
queueOpen,
|
||||
isPlaybackActive,
|
||||
volume,
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
|
||||
import * as React from "react"
|
||||
import Image from "next/image"
|
||||
import Link from "next/link"
|
||||
import {
|
||||
ListMusic,
|
||||
MessageSquareQuote,
|
||||
Music,
|
||||
Pause,
|
||||
Play,
|
||||
Repeat,
|
||||
@@ -16,12 +15,7 @@ import {
|
||||
Volume2,
|
||||
} from "lucide-react"
|
||||
|
||||
import { AudioFormatBadge } from "@/components/audio-format-badge"
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from "@/components/ui/popover"
|
||||
import { PlaybackSongMeta } from "@/components/playback-song-meta"
|
||||
import {
|
||||
usePlayback,
|
||||
usePlaybackProgress,
|
||||
@@ -32,6 +26,8 @@ import { useSidebar } from "@/components/ui/sidebar"
|
||||
import { albumCoverUrl } from "@/lib/cover-urls"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const PLACEHOLDER_TIME = "--:--"
|
||||
|
||||
function formatDuration(seconds: number): string {
|
||||
const total = Math.max(0, Math.floor(seconds))
|
||||
const minutes = Math.floor(total / 60)
|
||||
@@ -42,7 +38,6 @@ function formatDuration(seconds: number): string {
|
||||
export function PlayerBar() {
|
||||
const {
|
||||
currentSong,
|
||||
currentFormat,
|
||||
shuffleEnabled,
|
||||
repeatEnabled,
|
||||
queueOpen,
|
||||
@@ -71,27 +66,23 @@ export function PlayerBar() {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"@container pointer-events-none fixed bottom-4 z-50 flex justify-center px-4 transition-[left,right] duration-200 ease-linear",
|
||||
sidebarExpanded ? "right-0 left-[16rem]" : "inset-x-0",
|
||||
"pointer-events-none fixed bottom-4 z-50 flex justify-center px-4 transition-[left,right] duration-200 ease-linear",
|
||||
sidebarExpanded ? "left-[16rem] right-0" : "inset-x-0",
|
||||
queueOpen && !isMobile && "right-72"
|
||||
)}
|
||||
>
|
||||
<div className="pointer-events-auto flex w-full max-w-[40rem] items-center gap-2 rounded-full border border-foreground/20 bg-(--player-background) px-3 py-2 text-card-foreground shadow-lg [--player-background:var(--card)] md:gap-3 md:py-1.5 dark:border-white/20 dark:text-white dark:[--player-background:#303033]">
|
||||
<div className="flex shrink-0 items-center gap-0 md:gap-0.5 [&_button]:size-7 [&_svg]:size-4">
|
||||
<div className="pointer-events-auto flex w-full max-w-3xl flex-col gap-2 rounded-xl border bg-card/80 px-3 py-2 shadow-lg backdrop-blur">
|
||||
<div className="grid grid-cols-[1fr_auto_1fr] items-center gap-2">
|
||||
<div className="flex items-center justify-start gap-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
aria-label="Shuffle"
|
||||
aria-pressed={shuffleEnabled}
|
||||
className={cn(
|
||||
"hidden @min-[640px]:inline-flex",
|
||||
shuffleEnabled
|
||||
? "text-card-foreground dark:text-white"
|
||||
: "text-muted-foreground dark:text-white/40"
|
||||
)}
|
||||
className={cn(shuffleEnabled && "text-primary")}
|
||||
onClick={() => void toggleShuffle()}
|
||||
>
|
||||
<Shuffle className="size-4" />
|
||||
<Shuffle />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
@@ -100,7 +91,7 @@ export function PlayerBar() {
|
||||
disabled={!hasQueue}
|
||||
onClick={() => void skipPrevious()}
|
||||
>
|
||||
<SkipBack className="size-4 fill-current" />
|
||||
<SkipBack />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
@@ -109,11 +100,7 @@ export function PlayerBar() {
|
||||
disabled={!hasQueue}
|
||||
onClick={() => setIsPlaying(!isPlaying)}
|
||||
>
|
||||
{isPlaying ? (
|
||||
<Pause className="size-5! fill-current" />
|
||||
) : (
|
||||
<Play className="size-5! fill-current" />
|
||||
)}
|
||||
{isPlaying ? <Pause /> : <Play className="fill-current" />}
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
@@ -122,115 +109,52 @@ export function PlayerBar() {
|
||||
disabled={!hasQueue}
|
||||
onClick={() => void skipNext()}
|
||||
>
|
||||
<SkipForward className="size-4 fill-current" />
|
||||
<SkipForward />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
aria-label="Repeat"
|
||||
aria-pressed={repeatEnabled !== "none"}
|
||||
className={cn(
|
||||
"hidden @min-[640px]:inline-flex",
|
||||
repeatEnabled !== "none"
|
||||
? "text-card-foreground dark:text-white"
|
||||
: "text-muted-foreground dark:text-white/40"
|
||||
)}
|
||||
className={cn(repeatEnabled !== "none" && "text-primary")}
|
||||
onClick={() => void cycleRepeat()}
|
||||
>
|
||||
{repeatEnabled === "once" ? (
|
||||
<Repeat1 className="size-4" />
|
||||
) : (
|
||||
<Repeat className="size-4" />
|
||||
)}
|
||||
{repeatEnabled === "once" ? <Repeat1 /> : <Repeat />}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="relative flex h-11 min-w-0 flex-1 items-center gap-2 pb-2 md:h-9 md:pb-1">
|
||||
<div className="flex h-10 min-w-0 items-center justify-center gap-3 px-2">
|
||||
{currentSong ? (
|
||||
<>
|
||||
<div className="relative size-9 shrink-0 overflow-hidden rounded md:size-8">
|
||||
<div className="relative size-8 shrink-0 overflow-hidden rounded">
|
||||
<Image
|
||||
src={albumCoverUrl(currentSong.album.id)}
|
||||
alt={currentSong.album.title}
|
||||
fill
|
||||
sizes="36px"
|
||||
sizes="32px"
|
||||
className="object-cover"
|
||||
/>
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<Link
|
||||
href={`/album/${currentSong.album.id}`}
|
||||
className="block truncate text-sm font-semibold hover:underline md:text-[13px] md:leading-4"
|
||||
>
|
||||
{currentSong.title}
|
||||
</Link>
|
||||
<p className="truncate text-xs">
|
||||
<Link
|
||||
href={`/artist/${currentSong.artist.id}`}
|
||||
className="hover:underline"
|
||||
>
|
||||
{currentSong.artist.name}
|
||||
</Link>
|
||||
<span aria-hidden> · </span>
|
||||
<Link
|
||||
href={`/album/${currentSong.album.id}`}
|
||||
className="hover:underline"
|
||||
>
|
||||
{currentSong.album.title}
|
||||
</Link>
|
||||
</p>
|
||||
<div className="flex h-10 min-w-0 max-w-48 flex-col justify-center overflow-hidden sm:max-w-64">
|
||||
<PlaybackSongMeta song={currentSong} />
|
||||
</div>
|
||||
{currentFormat ? (
|
||||
<AudioFormatBadge
|
||||
format={currentFormat}
|
||||
iconOnly
|
||||
backgroundColor="var(--player-background)"
|
||||
/>
|
||||
) : null}
|
||||
</>
|
||||
) : (
|
||||
<Image
|
||||
src="/logo.png"
|
||||
alt="oTunes"
|
||||
width={24}
|
||||
height={24}
|
||||
className="mx-auto size-6 opacity-85"
|
||||
/>
|
||||
<div className="flex size-8 shrink-0 items-center justify-center">
|
||||
<Image
|
||||
src="/logo-monochrome.svg"
|
||||
alt="oTunes"
|
||||
width={14}
|
||||
height={24}
|
||||
className="h-6 w-auto opacity-85"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="absolute inset-x-0 -bottom-1">
|
||||
<Slider
|
||||
className={cn(
|
||||
"h-3 flex-1 [&_[data-slot=slider-range]]:bg-current/80 [&_[data-slot=slider-thumb]]:size-2 [&_[data-slot=slider-thumb]]:border-current [&_[data-slot=slider-thumb]]:bg-current [&_[data-slot=slider-thumb]]:opacity-0 focus-within:[&_[data-slot=slider-thumb]]:opacity-100 hover:[&_[data-slot=slider-thumb]]:opacity-100 [&_[data-slot=slider-track]]:h-[3px] [&_[data-slot=slider-track]]:bg-current/30 md:[&_[data-slot=slider-track]]:h-0.5",
|
||||
!hasActiveSong && "[&_[data-slot=slider-thumb]]:hidden"
|
||||
)}
|
||||
min={0}
|
||||
max={maxDuration}
|
||||
step={0.1}
|
||||
value={[displayTime]}
|
||||
disabled={!hasActiveSong}
|
||||
onValueChange={([value]) => {
|
||||
setIsSeeking(true)
|
||||
setSeekValue(value)
|
||||
}}
|
||||
onValueCommit={([value]) => {
|
||||
seekTo(value)
|
||||
setIsSeeking(false)
|
||||
}}
|
||||
aria-label="Seek"
|
||||
aria-valuetext={`${formatDuration(displayTime)} of ${formatDuration(duration)}`}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex shrink-0 items-center gap-0 md:gap-1 [&_button]:size-7 [&_svg]:size-4">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="hidden @min-[640px]:inline-flex"
|
||||
aria-label="Lyrics"
|
||||
disabled
|
||||
>
|
||||
<MessageSquareQuote className="size-4" />
|
||||
<div className="flex items-center justify-end gap-1">
|
||||
<Button variant="ghost" size="icon" aria-label="Lyrics" disabled>
|
||||
<Music />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
@@ -240,24 +164,63 @@ export function PlayerBar() {
|
||||
className={cn(queueOpen && "text-primary")}
|
||||
onClick={toggleQueueOpen}
|
||||
>
|
||||
<ListMusic className="size-4" />
|
||||
<ListMusic />
|
||||
</Button>
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<Button variant="ghost" size="icon" aria-label="Volume">
|
||||
<Volume2 className="size-4" />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent side="top" align="end" className="w-40">
|
||||
<Slider
|
||||
min={0}
|
||||
max={100}
|
||||
value={[volume]}
|
||||
onValueChange={([value]) => setVolume(value)}
|
||||
aria-label="Volume"
|
||||
/>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<div className="hidden items-center gap-2 sm:flex">
|
||||
<Volume2 className="size-4 shrink-0 text-muted-foreground" />
|
||||
<Slider
|
||||
className="w-20"
|
||||
min={0}
|
||||
max={100}
|
||||
value={[volume]}
|
||||
onValueChange={([value]) => setVolume(value)}
|
||||
aria-label="Volume"
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
aria-label="Volume"
|
||||
className="sm:hidden"
|
||||
>
|
||||
<Volume2 />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2 px-1">
|
||||
<span
|
||||
className="w-9 shrink-0 text-right text-xs tabular-nums text-muted-foreground"
|
||||
aria-hidden
|
||||
>
|
||||
{hasActiveSong ? formatDuration(displayTime) : PLACEHOLDER_TIME}
|
||||
</span>
|
||||
<Slider
|
||||
className={cn(
|
||||
"flex-1",
|
||||
!hasActiveSong && "[&_[data-slot=slider-thumb]]:hidden"
|
||||
)}
|
||||
min={0}
|
||||
max={maxDuration}
|
||||
step={0.1}
|
||||
value={[displayTime]}
|
||||
disabled={!hasActiveSong}
|
||||
onValueChange={([value]) => {
|
||||
setIsSeeking(true)
|
||||
setSeekValue(value)
|
||||
}}
|
||||
onValueCommit={([value]) => {
|
||||
seekTo(value)
|
||||
setIsSeeking(false)
|
||||
}}
|
||||
aria-label="Seek"
|
||||
/>
|
||||
<span
|
||||
className="w-9 shrink-0 text-xs tabular-nums text-muted-foreground"
|
||||
aria-hidden
|
||||
>
|
||||
{hasActiveSong ? formatDuration(duration) : PLACEHOLDER_TIME}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
"use client"
|
||||
|
||||
import { PageHeader } from "@/components/library-skeletons"
|
||||
import { MobileSidebarTrigger } from "@/components/mobile-sidebar-trigger"
|
||||
import { stationArtistId } from "@/lib/station-artist"
|
||||
import * as React from "react"
|
||||
import Image from "next/image"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { useMutation } from "convex/react"
|
||||
import { Play, SearchIcon, Share2, Shuffle, Star, Trash2 } from "lucide-react"
|
||||
import { Play, Share2, Shuffle, Star, Trash2 } from "lucide-react"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { useAddToPlaylist } from "@/components/add-to-playlist-provider"
|
||||
@@ -305,19 +305,6 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
const songs = isFavorites
|
||||
? playlist.songs.filter((song) => !hiddenFavoriteIds.has(song.id))
|
||||
: playlistSongs
|
||||
const [searchQuery, setSearchQuery] = React.useState("")
|
||||
const normalizedQuery = searchQuery.trim().toLowerCase()
|
||||
const filteredSongs = React.useMemo(
|
||||
() =>
|
||||
normalizedQuery
|
||||
? songs.filter((song) =>
|
||||
[song.title, song.artist.name, song.album.title].some((value) =>
|
||||
value.toLowerCase().includes(normalizedQuery)
|
||||
)
|
||||
)
|
||||
: songs,
|
||||
[songs, normalizedQuery]
|
||||
)
|
||||
const playlistSongIds = React.useMemo(
|
||||
() => songs.map((song) => song.id as Id<"songs">),
|
||||
[songs]
|
||||
@@ -340,8 +327,7 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
handleSelect,
|
||||
handlePointerDown,
|
||||
prepareContextMenu,
|
||||
clearSelection,
|
||||
} = useTrackSelection(filteredSongs)
|
||||
} = useTrackSelection(songs)
|
||||
|
||||
const selectedStationArtistId = React.useMemo(
|
||||
() => stationArtistId(songs, selectedIds),
|
||||
@@ -349,12 +335,8 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
)
|
||||
|
||||
const selectionPositions = React.useMemo(
|
||||
() =>
|
||||
getSelectionRangePositions(
|
||||
filteredSongs.map((song) => song.id),
|
||||
selectedIds
|
||||
),
|
||||
[filteredSongs, selectedIds]
|
||||
() => getSelectionRangePositions(songs.map((song) => song.id), selectedIds),
|
||||
[songs, selectedIds]
|
||||
)
|
||||
const totalDurationSeconds = React.useMemo(
|
||||
() => sumDurationSeconds(songs),
|
||||
@@ -479,13 +461,7 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
}
|
||||
|
||||
function handleDrop(targetIndex: number) {
|
||||
if (
|
||||
normalizedQuery ||
|
||||
isFavorites ||
|
||||
!isOwner ||
|
||||
dragIndex === null ||
|
||||
dragIndex === targetIndex
|
||||
) {
|
||||
if (isFavorites || !isOwner || dragIndex === null || dragIndex === targetIndex) {
|
||||
setDragIndex(null)
|
||||
return
|
||||
}
|
||||
@@ -543,7 +519,6 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<PageHeader openApp />
|
||||
<ScrollArea className="min-h-0 flex-1">
|
||||
<div className="pb-28">
|
||||
<div className="mx-auto w-full min-w-0 max-w-9/10">
|
||||
@@ -570,9 +545,12 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
<p className="text-xs font-medium tracking-wide text-muted-foreground uppercase">
|
||||
Playlist
|
||||
</p>
|
||||
<h1 className="text-3xl font-bold tracking-tight sm:text-4xl">
|
||||
{playlist.title}
|
||||
</h1>
|
||||
<div className="flex min-w-0 items-center justify-center gap-2 sm:justify-start md:contents">
|
||||
<MobileSidebarTrigger />
|
||||
<h1 className="text-3xl font-bold tracking-tight sm:text-4xl">
|
||||
{playlist.title}
|
||||
</h1>
|
||||
</div>
|
||||
<p className="text-lg font-semibold text-primary">
|
||||
{playlist.owner.name}
|
||||
</p>
|
||||
@@ -657,31 +635,13 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="px-6 pb-4">
|
||||
<div className="relative max-w-sm">
|
||||
<SearchIcon className="pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground" />
|
||||
<input
|
||||
type="search"
|
||||
aria-label="Search playlist"
|
||||
placeholder="Search playlist"
|
||||
value={searchQuery}
|
||||
onChange={(event) => {
|
||||
setSearchQuery(event.target.value)
|
||||
clearSelection()
|
||||
setActiveTrackId("")
|
||||
setDragIndex(null)
|
||||
}}
|
||||
className="h-10 w-full min-w-0 rounded-full border border-input bg-input/30 pr-3 pl-9 text-sm text-foreground transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/50"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{filteredSongs.length > 0 ? (
|
||||
filteredSongs.map((song, index) => (
|
||||
{songs.length > 0 ? (
|
||||
songs.map((song, index) => (
|
||||
<PlaylistSongRow
|
||||
key={song.id}
|
||||
song={song}
|
||||
index={index}
|
||||
isOwner={isOwner && !isFavorites && !normalizedQuery}
|
||||
isOwner={isOwner && !isFavorites}
|
||||
canRemove={isFavorites || isOwner}
|
||||
showFavoriteInMenu={!isFavorites}
|
||||
removeLabel={
|
||||
@@ -721,14 +681,14 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
onMediaAction={handleMediaAction}
|
||||
onRemove={() => handleRemoveSong(song.id)}
|
||||
onDragStart={(event) => {
|
||||
if (normalizedQuery || isFavorites || !isOwner) {
|
||||
if (isFavorites || !isOwner) {
|
||||
return
|
||||
}
|
||||
setDragIndex(index)
|
||||
event.dataTransfer.effectAllowed = "move"
|
||||
}}
|
||||
onDragOver={(event) => {
|
||||
if (normalizedQuery || isFavorites || !isOwner) {
|
||||
if (isFavorites || !isOwner) {
|
||||
return
|
||||
}
|
||||
event.preventDefault()
|
||||
@@ -739,19 +699,13 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
}}
|
||||
isNowPlaying={currentSong?.id === song.id}
|
||||
onPlay={() =>
|
||||
void playFromSong(
|
||||
song.id as Id<"songs">,
|
||||
playlistSongIds,
|
||||
`playlist:${playlist.id}`
|
||||
)
|
||||
void playFromSong(song.id as Id<"songs">, playlistSongIds)
|
||||
}
|
||||
/>
|
||||
))
|
||||
) : (
|
||||
<p className="px-6 py-8 text-sm text-muted-foreground">
|
||||
{normalizedQuery
|
||||
? "No songs found."
|
||||
: "This playlist has no songs yet."}
|
||||
This playlist has no songs yet.
|
||||
</p>
|
||||
)}
|
||||
<MediaCollectionFooter
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
"use client"
|
||||
|
||||
import { useLayoutEffect, useRef } from "react"
|
||||
import { usePathname, useSearchParams } from "next/navigation"
|
||||
|
||||
const historyKey = "otunesScrollKey"
|
||||
const scrollSelector = '[data-slot="scroll-area-viewport"], .overflow-y-auto'
|
||||
type Position = { top: number; left: number }
|
||||
|
||||
// Track page containers independently of the window, including split library views.
|
||||
export function ScrollRestoration({ children }: { children: React.ReactNode }) {
|
||||
const pathname = usePathname()
|
||||
const searchParams = useSearchParams()
|
||||
const route = `${pathname}?${searchParams.toString()}`
|
||||
const rootRef = useRef<HTMLDivElement>(null)
|
||||
const positions = useRef(new Map<string, Map<number, Position>>())
|
||||
useLayoutEffect(() => {
|
||||
const root = rootRef.current
|
||||
if (!root) return
|
||||
|
||||
const key =
|
||||
typeof history.state?.[historyKey] === "string"
|
||||
? (history.state[historyKey] as string)
|
||||
: crypto.randomUUID()
|
||||
history.replaceState({ ...history.state, [historyKey]: key }, "")
|
||||
const saved = positions.current.get(key)
|
||||
const pending = new Map(saved)
|
||||
if (!positions.current.has(key)) positions.current.set(key, new Map())
|
||||
// Bound memory during long listening sessions.
|
||||
if (positions.current.size > 100) {
|
||||
const oldest = positions.current.keys().next().value
|
||||
if (oldest !== undefined) positions.current.delete(oldest)
|
||||
}
|
||||
|
||||
const containers = () =>
|
||||
Array.from(root.querySelectorAll<HTMLElement>(scrollSelector)).filter(
|
||||
(element) => element.getClientRects().length > 0
|
||||
)
|
||||
const restore = () => {
|
||||
for (const [index, element] of containers().entries()) {
|
||||
const position = pending.get(index)
|
||||
if (!position) continue
|
||||
element.scrollTo({
|
||||
top: position.top,
|
||||
left: position.left,
|
||||
behavior: "instant",
|
||||
})
|
||||
// Keep waiting if asynchronous content is still too short.
|
||||
if (
|
||||
Math.abs(element.scrollTop - position.top) < 1 &&
|
||||
Math.abs(element.scrollLeft - position.left) < 1
|
||||
) {
|
||||
pending.delete(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
const record = (event: Event) => {
|
||||
if (!(event.target instanceof HTMLElement)) return
|
||||
const index = containers().indexOf(event.target)
|
||||
if (index < 0 || pending.has(index)) return
|
||||
positions.current.get(key)?.set(index, {
|
||||
top: event.target.scrollTop,
|
||||
left: event.target.scrollLeft,
|
||||
})
|
||||
}
|
||||
const stopRestoring = () => {
|
||||
pending.clear()
|
||||
observer.disconnect()
|
||||
resizeObserver.disconnect()
|
||||
}
|
||||
const observer = new MutationObserver(() => {
|
||||
restore()
|
||||
for (const element of containers()) {
|
||||
resizeObserver.observe(element)
|
||||
for (const child of element.children) resizeObserver.observe(child)
|
||||
}
|
||||
})
|
||||
const resizeObserver = new ResizeObserver(restore)
|
||||
if (pending.size) {
|
||||
observer.observe(root, { childList: true, subtree: true })
|
||||
for (const element of containers()) {
|
||||
resizeObserver.observe(element)
|
||||
for (const child of element.children) resizeObserver.observe(child)
|
||||
}
|
||||
restore()
|
||||
}
|
||||
const timeout = window.setTimeout(stopRestoring, 10_000)
|
||||
root.addEventListener("scroll", record, true)
|
||||
root.addEventListener("wheel", stopRestoring, { passive: true })
|
||||
root.addEventListener("touchstart", stopRestoring, { passive: true })
|
||||
root.addEventListener("keydown", stopRestoring)
|
||||
return () => {
|
||||
window.clearTimeout(timeout)
|
||||
stopRestoring()
|
||||
root.removeEventListener("scroll", record, true)
|
||||
root.removeEventListener("wheel", stopRestoring)
|
||||
root.removeEventListener("touchstart", stopRestoring)
|
||||
root.removeEventListener("keydown", stopRestoring)
|
||||
}
|
||||
}, [route])
|
||||
|
||||
return (
|
||||
<div ref={rootRef} className="contents">
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -49,8 +49,6 @@ function Slider({
|
||||
<SliderPrimitive.Thumb
|
||||
data-slot="slider-thumb"
|
||||
key={index}
|
||||
aria-label={props["aria-label"]}
|
||||
aria-valuetext={props["aria-valuetext"]}
|
||||
className="relative block size-3 shrink-0 rounded-full border border-ring bg-white ring-ring/50 transition-[color,box-shadow] select-none after:absolute after:-inset-2 hover:ring-3 focus-visible:ring-3 focus-visible:outline-hidden active:ring-3 disabled:pointer-events-none disabled:opacity-50"
|
||||
/>
|
||||
))}
|
||||
|
||||
|
Before Width: | Height: | Size: 7.7 KiB After Width: | Height: | Size: 45 KiB |
|
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 324 KiB After Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 284 KiB After Width: | Height: | Size: 963 KiB |
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 35 KiB |
@@ -64,11 +64,7 @@ export function startQueueFromSong(
|
||||
songIds: Id<"songs">[]
|
||||
): PlaybackQueueState {
|
||||
const index = songIds.indexOf(songId)
|
||||
const rest = state.shuffleEnabled
|
||||
? uniqueSongIds(songIds).filter((id) => id !== songId)
|
||||
: index === -1
|
||||
? []
|
||||
: songIds.slice(index + 1)
|
||||
const rest = index === -1 ? [] : songIds.slice(index + 1)
|
||||
return {
|
||||
...state,
|
||||
queue: [songId, ...(state.shuffleEnabled ? shuffleArray(rest) : rest)],
|
||||
|
||||
@@ -538,8 +538,6 @@ export const browseAlbumDetail = query({
|
||||
year: primarySong?.year ?? null,
|
||||
genre: primarySong?.genres[0] ?? null,
|
||||
releaseDate: album.date,
|
||||
hasLossless: songs.some((song) => "lossless" in song.files),
|
||||
hasAtmos: songs.some((song) => "atmos" in song.files),
|
||||
tracks: songs.map((song) => toBrowseAlbumTrack(song, artist.name)),
|
||||
}
|
||||
},
|
||||
@@ -572,8 +570,6 @@ async function browseAlbumSummaryHandler(
|
||||
year: primarySong?.year ?? null,
|
||||
genre: primarySong?.genres[0] ?? null,
|
||||
releaseDate: album.date,
|
||||
hasLossless: songs.some((song) => "lossless" in song.files),
|
||||
hasAtmos: songs.some((song) => "atmos" in song.files),
|
||||
trackCount: songs.length,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -433,11 +433,7 @@ export const playFromSong = mutation({
|
||||
}
|
||||
|
||||
const index = songIds.indexOf(songId)
|
||||
const rest = user.shuffleEnabled
|
||||
? uniqueSongIds(songIds).filter((id) => id !== songId)
|
||||
: index === -1
|
||||
? []
|
||||
: songIds.slice(index + 1)
|
||||
const rest = index === -1 ? [] : songIds.slice(index + 1)
|
||||
const queueRest = user.shuffleEnabled ? shuffleArray(rest) : rest
|
||||
|
||||
await setQueueState(ctx, userId, {
|
||||
@@ -592,11 +588,7 @@ export const playFromLibrarySong = mutation({
|
||||
|
||||
const songIds = await getSortedLibrarySongIds(ctx, sortKey, sortDirection)
|
||||
const index = songIds.indexOf(songId)
|
||||
const rest = user.shuffleEnabled
|
||||
? uniqueSongIds(songIds).filter((id) => id !== songId)
|
||||
: index === -1
|
||||
? []
|
||||
: songIds.slice(index + 1)
|
||||
const rest = index === -1 ? [] : songIds.slice(index + 1)
|
||||
const queueRest = user.shuffleEnabled ? shuffleArray(rest) : rest
|
||||
|
||||
await setQueueState(ctx, userId, {
|
||||
|
||||
@@ -36,8 +36,6 @@ export type BrowseAlbumDetail = BrowseAlbum & {
|
||||
year: number | null
|
||||
genre: string | null
|
||||
releaseDate: string
|
||||
hasLossless: boolean
|
||||
hasAtmos: boolean
|
||||
tracks: BrowseAlbumTrack[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
"""Export Composer artwork with Xcode, then resize with Pillow.
|
||||
|
||||
Run on macOS with Xcode and Pillow installed: python3 scripts/generate-icons.py
|
||||
"""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
from PIL import Image
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
ASSETS = ROOT / "apps/mobile/assets"
|
||||
ICTOOL = "/Applications/Xcode.app/Contents/Applications/Icon Composer.app/Contents/Executables/ictool"
|
||||
|
||||
|
||||
def export(source, output, rendition="Default"):
|
||||
subprocess.run([
|
||||
ICTOOL, str(source), "--export-image", "--output-file", str(output),
|
||||
"--platform", "iOS", "--rendition", rendition,
|
||||
"--width", "1024", "--height", "1024", "--scale", "1",
|
||||
], check=True)
|
||||
return Image.open(output).convert("RGBA")
|
||||
|
||||
|
||||
def save(image, path, size=1024):
|
||||
image.resize((size, size), Image.Resampling.LANCZOS).save(ROOT / path)
|
||||
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="otunes-icons-") as directory:
|
||||
temp = Path(directory)
|
||||
for variant, composer in [("production", "oTunes"), ("development", "oTunes Dev"), ("preview", "oTunes Preview")]:
|
||||
source = ASSETS / f"{composer}.icon"
|
||||
icon = export(source, temp / "icon.png")
|
||||
dark = export(source, temp / "dark.png", "Dark")
|
||||
suffix = "" if variant == "production" else f"-{variant}"
|
||||
save(icon, f"apps/mobile/assets/icon{suffix}.png")
|
||||
|
||||
# Android uses the Composer artwork without Apple's rounded glass base.
|
||||
document = json.loads((source / "icon.json").read_text())
|
||||
layer = document["groups"][0]["layers"][0]
|
||||
artwork = Image.open(source / "Assets" / layer["image-name"]).convert("RGBA")
|
||||
position = layer["position"]
|
||||
scale = position["scale"]
|
||||
artwork = artwork.resize(tuple(round(size * scale) for size in artwork.size), Image.Resampling.LANCZOS)
|
||||
x, y = position["translation-in-points"]
|
||||
foreground = Image.new("RGBA", (1024, 1024))
|
||||
foreground.alpha_composite(artwork, (round((1024 - artwork.width) / 2 + x), round((1024 - artwork.height) / 2 + y)))
|
||||
# Android's adaptive canvas includes an outer area reserved for motion.
|
||||
adaptive = Image.new("RGBA", (1024, 1024))
|
||||
adaptive.alpha_composite(foreground.resize((682, 682), Image.Resampling.LANCZOS), (171, 171))
|
||||
save(adaptive, f"apps/mobile/assets/android-icon-foreground{suffix}.png")
|
||||
# Use the rendered background's center column to retain Composer colors.
|
||||
background_source = temp / "background.icon"
|
||||
shutil.copytree(source, background_source, dirs_exist_ok=True)
|
||||
document = json.loads((source / "icon.json").read_text())
|
||||
document["groups"] = []
|
||||
(background_source / "icon.json").write_text(json.dumps(document))
|
||||
background = export(background_source, temp / "background.png")
|
||||
background = background.crop((512, 0, 513, 1024)).resize((1024, 1024))
|
||||
save(background, f"apps/mobile/assets/android-icon-background{suffix}.png")
|
||||
save(Image.alpha_composite(background, foreground), f"apps/mobile/assets/android-icon{suffix}.png")
|
||||
if variant != "production":
|
||||
continue
|
||||
monochrome = Image.new("RGBA", adaptive.size, "white")
|
||||
monochrome.putalpha(adaptive.getchannel("A"))
|
||||
save(monochrome, "apps/mobile/assets/android-icon-monochrome.png")
|
||||
for name, image in [("icon-dark", dark), ("ios-icon", icon), ("ios-icon-dark", dark)]:
|
||||
save(image, f"apps/mobile/assets/{name}.png")
|
||||
for name, image in [("logo", icon), ("logo-dark", dark)]:
|
||||
save(image, f"apps/web/public/{name}.png")
|
||||
for path, size, image in [
|
||||
("favicon.png", 64, icon),
|
||||
("apps/mobile/assets/favicon.png", 64, icon),
|
||||
("apps/web/app/favicon.png", 128, icon),
|
||||
("apps/web/public/favicon.png", 128, icon),
|
||||
("apps/web/public/favicon-dark.png", 128, dark),
|
||||
]:
|
||||
save(image, path, size)
|
||||