Compare commits
1
Commits
No files matched your search
@@ -1,97 +0,0 @@
|
|||||||
name: Mobile Build
|
|
||||||
|
|
||||||
# Tags build preview Android and iOS and attach them to the tag's release.
|
|
||||||
# Manual runs pick the profile and platforms and keep the builds as run artifacts.
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- 'v*'
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
profile:
|
|
||||||
description: EAS build profile
|
|
||||||
type: choice
|
|
||||||
options:
|
|
||||||
- preview
|
|
||||||
- development
|
|
||||||
default: preview
|
|
||||||
platforms:
|
|
||||||
description: Platforms to build
|
|
||||||
type: choice
|
|
||||||
options:
|
|
||||||
- all
|
|
||||||
- android
|
|
||||||
- ios
|
|
||||||
default: all
|
|
||||||
|
|
||||||
env:
|
|
||||||
# Tag pushes have no inputs, so they fall back to preview on all platforms.
|
|
||||||
PROFILE: ${{ inputs.profile || 'preview' }}
|
|
||||||
EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
android:
|
|
||||||
if: inputs.platforms != 'ios'
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: pnpm/action-setup@v4
|
|
||||||
- uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 24
|
|
||||||
- uses: actions/setup-java@v4
|
|
||||||
with:
|
|
||||||
distribution: temurin
|
|
||||||
java-version: 17
|
|
||||||
- uses: android-actions/setup-android@v3
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
id: build
|
|
||||||
working-directory: apps/mobile
|
|
||||||
run: |
|
|
||||||
version=$([[ "$GITHUB_REF" == refs/tags/* ]] && echo "$GITHUB_REF_NAME" || echo "${GITHUB_SHA::7}")
|
|
||||||
out="$PWD/otunes-$PROFILE-$version.apk"
|
|
||||||
npx --yes eas-cli@latest build --local --non-interactive --platform android --profile "$PROFILE" --output "$out"
|
|
||||||
echo "file=$out" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: android-${{ env.PROFILE }}
|
|
||||||
path: ${{ steps.build.outputs.file }}
|
|
||||||
|
|
||||||
- name: Attach to release
|
|
||||||
if: startsWith(gitea.ref, 'refs/tags/')
|
|
||||||
env:
|
|
||||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
||||||
run: scripts/upload-release-asset.sh "${{ steps.build.outputs.file }}"
|
|
||||||
|
|
||||||
ios:
|
|
||||||
if: inputs.platforms != 'android'
|
|
||||||
# Queues until a self-hosted macOS runner (Xcode, CocoaPods, fastlane) picks it up.
|
|
||||||
runs-on: macos
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: pnpm/action-setup@v4
|
|
||||||
- uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 24
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
id: build
|
|
||||||
working-directory: apps/mobile
|
|
||||||
run: |
|
|
||||||
version=$([[ "$GITHUB_REF" == refs/tags/* ]] && echo "$GITHUB_REF_NAME" || echo "${GITHUB_SHA::7}")
|
|
||||||
out="$PWD/otunes-$PROFILE-$version.ipa"
|
|
||||||
npx --yes eas-cli@latest build --local --non-interactive --platform ios --profile "$PROFILE" --output "$out"
|
|
||||||
echo "file=$out" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: ios-${{ env.PROFILE }}
|
|
||||||
path: ${{ steps.build.outputs.file }}
|
|
||||||
|
|
||||||
- name: Attach to release
|
|
||||||
if: startsWith(gitea.ref, 'refs/tags/')
|
|
||||||
env:
|
|
||||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
||||||
run: scripts/upload-release-asset.sh "${{ steps.build.outputs.file }}"
|
|
||||||
+2
-2
@@ -121,7 +121,7 @@ RUN curl -fsSL -o ffmpeg.tar.xz "https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VER
|
|||||||
|
|
||||||
# Decoders cover the library formats (FLAC, ALAC/AAC in m4a, MP3, Opus,
|
# Decoders cover the library formats (FLAC, ALAC/AAC in m4a, MP3, Opus,
|
||||||
# Vorbis, WavPack, WMA, E-AC-3/TrueHD for Atmos). Encoders are only the two
|
# Vorbis, WavPack, WMA, E-AC-3/TrueHD for Atmos). Encoders are only the two
|
||||||
# the app writes: AAC (HLS, ADTS and .m4a downloads) and FLAC.
|
# the app writes: AAC (HLS and ADTS) and FLAC.
|
||||||
RUN ./configure \
|
RUN ./configure \
|
||||||
--prefix=/opt/ffmpeg \
|
--prefix=/opt/ffmpeg \
|
||||||
--disable-shared \
|
--disable-shared \
|
||||||
@@ -138,7 +138,7 @@ RUN ./configure \
|
|||||||
--enable-demuxer=aac,ac3,aiff,ape,asf,au,caf,dsf,flac,matroska,mov,mp3,ogg,wav,wv \
|
--enable-demuxer=aac,ac3,aiff,ape,asf,au,caf,dsf,flac,matroska,mov,mp3,ogg,wav,wv \
|
||||||
--enable-decoder=aac,aac_latm,ac3,alac,ape,dsd_lsbf,dsd_msbf,eac3,flac,mlp,mp3,opus,pcm_f32le,pcm_s16be,pcm_s16le,pcm_s24be,pcm_s24le,pcm_s32be,pcm_s32le,pcm_u8,truehd,vorbis,wavpack,wmav1,wmav2 \
|
--enable-decoder=aac,aac_latm,ac3,alac,ape,dsd_lsbf,dsd_msbf,eac3,flac,mlp,mp3,opus,pcm_f32le,pcm_s16be,pcm_s16le,pcm_s24be,pcm_s24le,pcm_s32be,pcm_s32le,pcm_u8,truehd,vorbis,wavpack,wmav1,wmav2 \
|
||||||
--enable-encoder=aac,flac \
|
--enable-encoder=aac,flac \
|
||||||
--enable-muxer=adts,flac,hls,ipod,mpegts \
|
--enable-muxer=adts,flac,hls,mpegts \
|
||||||
--enable-parser=aac,aac_latm,ac3,flac,mpegaudio,opus,vorbis \
|
--enable-parser=aac,aac_latm,ac3,flac,mpegaudio,opus,vorbis \
|
||||||
--enable-bsf=aac_adtstoasc \
|
--enable-bsf=aac_adtstoasc \
|
||||||
--enable-filter=aresample,aformat \
|
--enable-filter=aresample,aformat \
|
||||||
|
|||||||
@@ -32,13 +32,6 @@ export default ({ config }: ConfigContext): ExpoConfig => {
|
|||||||
...config,
|
...config,
|
||||||
plugins: [
|
plugins: [
|
||||||
...(config.plugins ?? []),
|
...(config.plugins ?? []),
|
||||||
[
|
|
||||||
"react-native-continued-task",
|
|
||||||
{
|
|
||||||
// Matches TASK_PREFIX in hooks/use-background-downloads.ts.
|
|
||||||
identifierPrefixes: [`${bundleIdentifier}.downloads`],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
...(process.env.MAC_CATALYST === "1"
|
...(process.env.MAC_CATALYST === "1"
|
||||||
? ["./plugins/with-mac-catalyst"]
|
? ["./plugins/with-mac-catalyst"]
|
||||||
: []),
|
: []),
|
||||||
|
|||||||
+6
-4
@@ -1,8 +1,11 @@
|
|||||||
import { Stack } from "expo-router"
|
import { Stack } from "expo-router"
|
||||||
|
|
||||||
import { TabStackContext } from "@/lib/app-navigation"
|
|
||||||
import { renderTabScreenContent } from "@/components/tab-screen-content"
|
import { renderTabScreenContent } from "@/components/tab-screen-content"
|
||||||
import { useStackScreenOptions, tabStackScreenTitles } from "@/lib/navigation"
|
import {
|
||||||
|
inlineTitleOptions,
|
||||||
|
tabStackScreenTitles,
|
||||||
|
useStackScreenOptions,
|
||||||
|
} from "@/lib/navigation"
|
||||||
import { tabletSections, TabletSectionContext } from "@/lib/tablet-navigation"
|
import { tabletSections, TabletSectionContext } from "@/lib/tablet-navigation"
|
||||||
|
|
||||||
export default function TabletSectionLayout({ segment }: { segment: string }) {
|
export default function TabletSectionLayout({ segment }: { segment: string }) {
|
||||||
@@ -11,18 +14,17 @@ export default function TabletSectionLayout({ segment }: { segment: string }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<TabletSectionContext value={section}>
|
<TabletSectionContext value={section}>
|
||||||
<TabStackContext value={section?.group}>
|
|
||||||
<Stack
|
<Stack
|
||||||
screenLayout={renderTabScreenContent}
|
screenLayout={renderTabScreenContent}
|
||||||
screenOptions={({ route }) => ({
|
screenOptions={({ route }) => ({
|
||||||
...options,
|
...options,
|
||||||
|
...inlineTitleOptions,
|
||||||
title:
|
title:
|
||||||
route.name === "index"
|
route.name === "index"
|
||||||
? section?.title
|
? section?.title
|
||||||
: tabStackScreenTitles[route.name],
|
: tabStackScreenTitles[route.name],
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
</TabStackContext>
|
|
||||||
</TabletSectionContext>
|
</TabletSectionContext>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
import { renderTabScreenContent } from "@/components/tab-screen-content"
|
import { renderTabScreenContent } from "@/components/tab-screen-content"
|
||||||
import { Stack } from "expo-router"
|
import { Stack } from "expo-router"
|
||||||
|
|
||||||
import { TabStackContext } from "@/lib/app-navigation"
|
|
||||||
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
||||||
import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
|
import {
|
||||||
|
inlineTitleOptions,
|
||||||
|
tabStackScreenTitles,
|
||||||
|
useStackScreenOptions,
|
||||||
|
} from "@/lib/navigation"
|
||||||
|
|
||||||
export const unstable_settings = {
|
export const unstable_settings = {
|
||||||
anchor: "index",
|
anchor: "index",
|
||||||
@@ -13,11 +16,11 @@ export default function HomeLayout() {
|
|||||||
const baseOptions = useStackScreenOptions({ title: "Home" })
|
const baseOptions = useStackScreenOptions({ title: "Home" })
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TabStackContext value="home">
|
|
||||||
<Stack
|
<Stack
|
||||||
screenLayout={renderTabScreenContent}
|
screenLayout={renderTabScreenContent}
|
||||||
screenOptions={({ route }) => ({
|
screenOptions={({ route }) => ({
|
||||||
...baseOptions,
|
...baseOptions,
|
||||||
|
...inlineTitleOptions,
|
||||||
title: tabStackScreenTitles[route.name] ?? "Home",
|
title: tabStackScreenTitles[route.name] ?? "Home",
|
||||||
headerRight:
|
headerRight:
|
||||||
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
||||||
@@ -33,6 +36,5 @@ export default function HomeLayout() {
|
|||||||
: undefined,
|
: undefined,
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
</TabStackContext>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,7 @@ export default function AlbumsScreen() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{searchBar}
|
{searchBar}
|
||||||
<MediaGridSkeleton />
|
<MediaGridSkeleton title="Albums" />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -63,6 +63,7 @@ export default function AlbumsScreen() {
|
|||||||
{searchBar}
|
{searchBar}
|
||||||
|
|
||||||
<MediaGridList
|
<MediaGridList
|
||||||
|
title="Albums"
|
||||||
content={albums}
|
content={albums}
|
||||||
paddingBottom={contentBottomInset}
|
paddingBottom={contentBottomInset}
|
||||||
onEndReached={() => {
|
onEndReached={() => {
|
||||||
|
|||||||
@@ -2,12 +2,13 @@ import { Ionicons } from "@expo/vector-icons"
|
|||||||
import { Stack } from "expo-router"
|
import { Stack } from "expo-router"
|
||||||
import { memo, useCallback } from "react"
|
import { memo, useCallback } from "react"
|
||||||
import {
|
import {
|
||||||
FlatList,
|
type FlatList,
|
||||||
Pressable,
|
Pressable,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
Text,
|
Text,
|
||||||
type ListRenderItemInfo,
|
type ListRenderItemInfo,
|
||||||
} from "react-native"
|
} from "react-native"
|
||||||
|
import Animated from "react-native-reanimated"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
MediaContextMenu,
|
MediaContextMenu,
|
||||||
@@ -15,6 +16,7 @@ import {
|
|||||||
} from "@/components/media-context-menu"
|
} from "@/components/media-context-menu"
|
||||||
import { CoverImage } from "@/components/cover-image"
|
import { CoverImage } from "@/components/cover-image"
|
||||||
import { ArtistListSkeleton } from "@/components/skeletons"
|
import { ArtistListSkeleton } from "@/components/skeletons"
|
||||||
|
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||||
import { contentBottomInset } from "@/components/player"
|
import { contentBottomInset } from "@/components/player"
|
||||||
import { useServerConfig } from "@/contexts/server-config"
|
import { useServerConfig } from "@/contexts/server-config"
|
||||||
import {
|
import {
|
||||||
@@ -33,6 +35,7 @@ import { spacing, useThemeColors } from "@/lib/theme"
|
|||||||
const PAGE_SIZE = 50
|
const PAGE_SIZE = 50
|
||||||
|
|
||||||
export default function ArtistsScreen() {
|
export default function ArtistsScreen() {
|
||||||
|
const { ref, scrollY } = useScreenTitleScroll<FlatList<BrowseArtist>>()
|
||||||
const { push } = useAppNavigation()
|
const { push } = useAppNavigation()
|
||||||
const colors = useThemeColors()
|
const colors = useThemeColors()
|
||||||
const { config } = useServerConfig()
|
const { config } = useServerConfig()
|
||||||
@@ -94,7 +97,7 @@ export default function ArtistsScreen() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{searchBar}
|
{searchBar}
|
||||||
<ArtistListSkeleton />
|
<ArtistListSkeleton title="Artists" />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -103,8 +106,11 @@ export default function ArtistsScreen() {
|
|||||||
<>
|
<>
|
||||||
{searchBar}
|
{searchBar}
|
||||||
|
|
||||||
<FlatList
|
<Animated.FlatList
|
||||||
{...longListProps}
|
{...longListProps}
|
||||||
|
ref={ref}
|
||||||
|
scrollEventThrottle={16}
|
||||||
|
ListHeaderComponent={<ScreenTitle title="Artists" scrollY={scrollY} />}
|
||||||
data={artists}
|
data={artists}
|
||||||
keyExtractor={artistKey}
|
keyExtractor={artistKey}
|
||||||
renderItem={renderItem}
|
renderItem={renderItem}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { useContext } from "react"
|
||||||
import { Pressable } from "react-native"
|
import { Pressable } from "react-native"
|
||||||
|
|
||||||
import { MediaGridList } from "@/components/media-cards"
|
import { MediaGridList } from "@/components/media-cards"
|
||||||
@@ -10,19 +11,20 @@ import { Ionicons } from "@expo/vector-icons"
|
|||||||
import { Stack } from "expo-router"
|
import { Stack } from "expo-router"
|
||||||
import { SymbolView } from "expo-symbols"
|
import { SymbolView } from "expo-symbols"
|
||||||
import { useAddToPlaylist } from "@/contexts/add-to-playlist"
|
import { useAddToPlaylist } from "@/contexts/add-to-playlist"
|
||||||
|
import { TabletSectionContext } from "@/lib/tablet-navigation"
|
||||||
|
|
||||||
export default function PlaylistsTabScreen() {
|
export default function PlaylistsTabScreen() {
|
||||||
const colors = useThemeColors()
|
const colors = useThemeColors()
|
||||||
const playlists = useCachedQuery(api.playlists.listAllPlaylists)
|
const playlists = useCachedQuery(api.playlists.listAllPlaylists)
|
||||||
const { openCreatePlaylist } = useAddToPlaylist()
|
const { openCreatePlaylist } = useAddToPlaylist()
|
||||||
|
const title = useContext(TabletSectionContext)?.title ?? "Playlists"
|
||||||
|
|
||||||
if (playlists === undefined) {
|
if (playlists === undefined) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
title: "Playlists",
|
title,
|
||||||
headerLargeTitle: true,
|
|
||||||
headerRight: () => (
|
headerRight: () => (
|
||||||
<Pressable
|
<Pressable
|
||||||
onPress={openCreatePlaylist}
|
onPress={openCreatePlaylist}
|
||||||
@@ -38,7 +40,7 @@ export default function PlaylistsTabScreen() {
|
|||||||
),
|
),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<MediaGridSkeleton />
|
<MediaGridSkeleton title={title} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -47,8 +49,7 @@ export default function PlaylistsTabScreen() {
|
|||||||
<>
|
<>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
title: "Playlists",
|
title,
|
||||||
headerLargeTitle: true,
|
|
||||||
headerRight: () => (
|
headerRight: () => (
|
||||||
<Pressable
|
<Pressable
|
||||||
onPress={openCreatePlaylist}
|
onPress={openCreatePlaylist}
|
||||||
@@ -61,6 +62,7 @@ export default function PlaylistsTabScreen() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<MediaGridList
|
<MediaGridList
|
||||||
|
title={title}
|
||||||
content={playlists}
|
content={playlists}
|
||||||
paddingBottom={tabContentBottomInset}
|
paddingBottom={tabContentBottomInset}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
import { Stack } from "expo-router"
|
import { Stack } from "expo-router"
|
||||||
import { useCallback, useState } from "react"
|
import { useCallback, useState } from "react"
|
||||||
import { FlatList, StyleSheet, type ListRenderItemInfo } from "react-native"
|
import {
|
||||||
|
type FlatList,
|
||||||
|
StyleSheet,
|
||||||
|
type ListRenderItemInfo,
|
||||||
|
} from "react-native"
|
||||||
|
import Animated from "react-native-reanimated"
|
||||||
|
|
||||||
import type { MediaAction } from "@/components/media-context-menu"
|
import type { MediaAction } from "@/components/media-context-menu"
|
||||||
import { contentBottomInset, SongListRow } from "@/components/player"
|
import { contentBottomInset, SongListRow } from "@/components/player"
|
||||||
import { SongListSkeleton } from "@/components/skeletons"
|
import { SongListSkeleton } from "@/components/skeletons"
|
||||||
|
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||||
import { useFavorites } from "@/contexts/favorites"
|
import { useFavorites } from "@/contexts/favorites"
|
||||||
import { usePlaybackActions } from "@/contexts/playback"
|
import { usePlaybackActions } from "@/contexts/playback"
|
||||||
import {
|
import {
|
||||||
@@ -20,6 +26,7 @@ import { longListProps } from "@/lib/list"
|
|||||||
const PAGE_SIZE = 50
|
const PAGE_SIZE = 50
|
||||||
|
|
||||||
export default function SongsScreen() {
|
export default function SongsScreen() {
|
||||||
|
const { ref, scrollY } = useScreenTitleScroll<FlatList<BrowseSong>>()
|
||||||
const { playFromLibrarySong } = usePlaybackActions()
|
const { playFromLibrarySong } = usePlaybackActions()
|
||||||
const { isSongFavorite } = useFavorites()
|
const { isSongFavorite } = useFavorites()
|
||||||
const { handleSongAction } = useMediaMenuActions()
|
const { handleSongAction } = useMediaMenuActions()
|
||||||
@@ -87,7 +94,7 @@ export default function SongsScreen() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{searchBar}
|
{searchBar}
|
||||||
<SongListSkeleton />
|
<SongListSkeleton title="Songs" />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -96,8 +103,11 @@ export default function SongsScreen() {
|
|||||||
<>
|
<>
|
||||||
{searchBar}
|
{searchBar}
|
||||||
|
|
||||||
<FlatList
|
<Animated.FlatList
|
||||||
{...longListProps}
|
{...longListProps}
|
||||||
|
ref={ref}
|
||||||
|
scrollEventThrottle={16}
|
||||||
|
ListHeaderComponent={<ScreenTitle title="Songs" scrollY={scrollY} />}
|
||||||
data={songs}
|
data={songs}
|
||||||
keyExtractor={songKey}
|
keyExtractor={songKey}
|
||||||
renderItem={renderItem}
|
renderItem={renderItem}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useMemo } from "react"
|
import { useMemo } from "react"
|
||||||
import {
|
import {
|
||||||
FlatList,
|
type FlatList,
|
||||||
Pressable,
|
Pressable,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
Text,
|
Text,
|
||||||
@@ -8,8 +8,10 @@ import {
|
|||||||
type ListRenderItemInfo,
|
type ListRenderItemInfo,
|
||||||
} from "react-native"
|
} from "react-native"
|
||||||
import { Stack } from "expo-router"
|
import { Stack } from "expo-router"
|
||||||
|
import Animated from "react-native-reanimated"
|
||||||
|
|
||||||
import { CoverImage } from "@/components/cover-image"
|
import { CoverImage } from "@/components/cover-image"
|
||||||
|
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||||
import { tabContentBottomInset } from "@/components/player"
|
import { tabContentBottomInset } from "@/components/player"
|
||||||
import {
|
import {
|
||||||
FAVORITES_DOWNLOAD_ID,
|
FAVORITES_DOWNLOAD_ID,
|
||||||
@@ -53,6 +55,7 @@ export default function DownloadsScreen() {
|
|||||||
const { push } = useAppNavigation()
|
const { push } = useAppNavigation()
|
||||||
const { columns, cardWidth, onLayout, horizontalPadding, gap } =
|
const { columns, cardWidth, onLayout, horizontalPadding, gap } =
|
||||||
useMediaGridLayout()
|
useMediaGridLayout()
|
||||||
|
const { ref, scrollY } = useScreenTitleScroll<FlatList<Card>>()
|
||||||
|
|
||||||
const cards = useMemo<Card[]>(() => {
|
const cards = useMemo<Card[]>(() => {
|
||||||
if (!queue) return []
|
if (!queue) return []
|
||||||
@@ -135,8 +138,10 @@ export default function DownloadsScreen() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack.Screen options={{ title: "Downloads", headerLargeTitle: true }} />
|
<Stack.Screen options={{ title: "Downloads" }} />
|
||||||
<FlatList
|
<Animated.FlatList
|
||||||
|
ref={ref}
|
||||||
|
scrollEventThrottle={16}
|
||||||
key={columns}
|
key={columns}
|
||||||
onLayout={onLayout}
|
onLayout={onLayout}
|
||||||
data={cards}
|
data={cards}
|
||||||
@@ -149,13 +154,20 @@ export default function DownloadsScreen() {
|
|||||||
numColumns={columns}
|
numColumns={columns}
|
||||||
style={{ flex: 1, backgroundColor: colors.background }}
|
style={{ flex: 1, backgroundColor: colors.background }}
|
||||||
contentContainerStyle={{
|
contentContainerStyle={{
|
||||||
paddingTop: spacing.lg,
|
|
||||||
paddingHorizontal: horizontalPadding,
|
paddingHorizontal: horizontalPadding,
|
||||||
paddingBottom: tabContentBottomInset,
|
paddingBottom: tabContentBottomInset,
|
||||||
gap,
|
gap,
|
||||||
}}
|
}}
|
||||||
columnWrapperStyle={columns > 1 ? { gap } : undefined}
|
columnWrapperStyle={columns > 1 ? { gap } : undefined}
|
||||||
contentInsetAdjustmentBehavior="automatic"
|
contentInsetAdjustmentBehavior="automatic"
|
||||||
|
ListHeaderComponent={
|
||||||
|
<ScreenTitle
|
||||||
|
title="Downloads"
|
||||||
|
scrollY={scrollY}
|
||||||
|
// The list padding already insets the title.
|
||||||
|
style={{ paddingHorizontal: 0 }}
|
||||||
|
/>
|
||||||
|
}
|
||||||
ListEmptyComponent={
|
ListEmptyComponent={
|
||||||
<View style={styles.empty}>
|
<View style={styles.empty}>
|
||||||
<Text style={{ color: colors.mutedForeground }}>
|
<Text style={{ color: colors.mutedForeground }}>
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
import { useCallback, useMemo } from "react"
|
import { useCallback, useMemo } from "react"
|
||||||
import {
|
import {
|
||||||
FlatList,
|
type FlatList,
|
||||||
Pressable,
|
Pressable,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
Text,
|
Text,
|
||||||
View,
|
View,
|
||||||
type ListRenderItemInfo,
|
type ListRenderItemInfo,
|
||||||
} from "react-native"
|
} from "react-native"
|
||||||
|
import Animated from "react-native-reanimated"
|
||||||
import { Ionicons } from "@expo/vector-icons"
|
import { Ionicons } from "@expo/vector-icons"
|
||||||
import { Stack } from "expo-router"
|
import { Stack } from "expo-router"
|
||||||
|
|
||||||
|
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||||
import { useSwipeRowGroup } from "@/components/ios-swipe-to-remove-row"
|
import { useSwipeRowGroup } from "@/components/ios-swipe-to-remove-row"
|
||||||
import type { MediaAction } from "@/components/media-context-menu"
|
import type { MediaAction } from "@/components/media-context-menu"
|
||||||
import { contentBottomInset, SongListRow } from "@/components/player"
|
import { contentBottomInset, SongListRow } from "@/components/player"
|
||||||
@@ -52,6 +54,7 @@ export default function OtherDownloadsScreen() {
|
|||||||
const { isSongFavorite } = useFavorites()
|
const { isSongFavorite } = useFavorites()
|
||||||
const { handleSongAction } = useMediaMenuActions()
|
const { handleSongAction } = useMediaMenuActions()
|
||||||
const swipeGroup = useSwipeRowGroup()
|
const swipeGroup = useSwipeRowGroup()
|
||||||
|
const { ref, scrollY } = useScreenTitleScroll<FlatList<BrowseSong>>()
|
||||||
|
|
||||||
const handlePlaySong = useCallback(
|
const handlePlaySong = useCallback(
|
||||||
(song: BrowseSong) => void playFromSong(song.id, playableIds, PLAY_ORIGIN),
|
(song: BrowseSong) => void playFromSong(song.id, playableIds, PLAY_ORIGIN),
|
||||||
@@ -90,11 +93,11 @@ export default function OtherDownloadsScreen() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack.Screen
|
<Stack.Screen options={{ title: OTHER_DOWNLOADS_TITLE }} />
|
||||||
options={{ title: OTHER_DOWNLOADS_TITLE, headerLargeTitle: false }}
|
<Animated.FlatList
|
||||||
/>
|
|
||||||
<FlatList
|
|
||||||
{...longListProps}
|
{...longListProps}
|
||||||
|
ref={ref}
|
||||||
|
scrollEventThrottle={16}
|
||||||
data={songs}
|
data={songs}
|
||||||
keyExtractor={(song) => song.id}
|
keyExtractor={(song) => song.id}
|
||||||
renderItem={renderItem}
|
renderItem={renderItem}
|
||||||
@@ -103,25 +106,32 @@ export default function OtherDownloadsScreen() {
|
|||||||
contentInsetAdjustmentBehavior="automatic"
|
contentInsetAdjustmentBehavior="automatic"
|
||||||
onScrollBeginDrag={swipeGroup.closeOpenRow}
|
onScrollBeginDrag={swipeGroup.closeOpenRow}
|
||||||
ListHeaderComponent={
|
ListHeaderComponent={
|
||||||
songs.length > 0 ? (
|
<>
|
||||||
|
<ScreenTitle title={OTHER_DOWNLOADS_TITLE} scrollY={scrollY} />
|
||||||
|
{songs.length > 0 ? (
|
||||||
<View style={styles.actions}>
|
<View style={styles.actions}>
|
||||||
|
<Button
|
||||||
|
title="Play"
|
||||||
|
icon="play"
|
||||||
|
onPress={() => void playInOrder(playableIds, PLAY_ORIGIN)}
|
||||||
|
style={styles.play}
|
||||||
|
/>
|
||||||
<Pressable
|
<Pressable
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
accessibilityLabel="Shuffle"
|
accessibilityLabel="Shuffle"
|
||||||
hitSlop={8}
|
hitSlop={8}
|
||||||
onPress={() => void playShuffled(playableIds, PLAY_ORIGIN)}
|
onPress={() => void playShuffled(playableIds, PLAY_ORIGIN)}
|
||||||
style={[styles.iconAction, { backgroundColor: colors.muted }]}
|
style={[styles.shuffle, { backgroundColor: colors.card }]}
|
||||||
>
|
>
|
||||||
<Ionicons name="shuffle" size={24} color={colors.foreground} />
|
<Ionicons
|
||||||
</Pressable>
|
name="shuffle"
|
||||||
<Button
|
size={24}
|
||||||
title="Play"
|
color={colors.foreground}
|
||||||
icon="play"
|
|
||||||
onPress={() => void playInOrder(playableIds, PLAY_ORIGIN)}
|
|
||||||
style={styles.playButton}
|
|
||||||
/>
|
/>
|
||||||
|
</Pressable>
|
||||||
</View>
|
</View>
|
||||||
) : undefined
|
) : null}
|
||||||
|
</>
|
||||||
}
|
}
|
||||||
ListEmptyComponent={
|
ListEmptyComponent={
|
||||||
<Text style={[styles.empty, { color: colors.mutedForeground }]}>
|
<Text style={[styles.empty, { color: colors.mutedForeground }]}>
|
||||||
@@ -137,15 +147,14 @@ const styles = StyleSheet.create({
|
|||||||
actions: {
|
actions: {
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
justifyContent: "center",
|
|
||||||
gap: spacing.sm,
|
gap: spacing.sm,
|
||||||
padding: spacing.lg,
|
padding: spacing.lg,
|
||||||
},
|
},
|
||||||
playButton: { borderRadius: 999, minWidth: 160 },
|
play: { flex: 1 },
|
||||||
iconAction: {
|
shuffle: {
|
||||||
width: 44,
|
width: 48,
|
||||||
height: 44,
|
height: 48,
|
||||||
borderRadius: 22,
|
borderRadius: 24,
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { memo } from "react"
|
import { memo } from "react"
|
||||||
import { ScrollView, StyleSheet } from "react-native"
|
import { type ScrollViewInstance, StyleSheet } from "react-native"
|
||||||
|
import Animated from "react-native-reanimated"
|
||||||
|
|
||||||
import { ContentCarousel } from "@/components/media-cards"
|
import { ContentCarousel } from "@/components/media-cards"
|
||||||
import { HomeSkeleton } from "@/components/skeletons"
|
import { HomeSkeleton } from "@/components/skeletons"
|
||||||
|
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||||
import { tabContentBottomInset } from "@/components/player"
|
import { tabContentBottomInset } from "@/components/player"
|
||||||
import { useCachedPaginatedQuery } from "@/hooks/use-cached-query"
|
import { useCachedPaginatedQuery } from "@/hooks/use-cached-query"
|
||||||
import { api } from "@otunes/convex/_generated/api"
|
import { api } from "@otunes/convex/_generated/api"
|
||||||
@@ -38,6 +40,7 @@ const HomeCarousels = memo(function HomeCarousels({
|
|||||||
|
|
||||||
export default function HomeScreen() {
|
export default function HomeScreen() {
|
||||||
const colors = useThemeColors()
|
const colors = useThemeColors()
|
||||||
|
const { ref, scrollY } = useScreenTitleScroll<ScrollViewInstance>()
|
||||||
const recentlyAdded = useCachedPaginatedQuery(
|
const recentlyAdded = useCachedPaginatedQuery(
|
||||||
api.library.browseRecentlyAddedPaginated,
|
api.library.browseRecentlyAddedPaginated,
|
||||||
{},
|
{},
|
||||||
@@ -53,14 +56,16 @@ export default function HomeScreen() {
|
|||||||
(result) => result.status === "LoadingFirstPage" && !result.isCached
|
(result) => result.status === "LoadingFirstPage" && !result.isCached
|
||||||
)
|
)
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return <HomeSkeleton />
|
return <HomeSkeleton title="Home" />
|
||||||
}
|
}
|
||||||
|
|
||||||
const added = recentlyAdded.results.slice(0, CAROUSEL_ITEM_LIMIT)
|
const added = recentlyAdded.results.slice(0, CAROUSEL_ITEM_LIMIT)
|
||||||
const played = recentlyPlayed.results.slice(0, CAROUSEL_ITEM_LIMIT)
|
const played = recentlyPlayed.results.slice(0, CAROUSEL_ITEM_LIMIT)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ScrollView
|
<Animated.ScrollView
|
||||||
|
ref={ref}
|
||||||
|
scrollEventThrottle={16}
|
||||||
style={{ flex: 1, backgroundColor: colors.background }}
|
style={{ flex: 1, backgroundColor: colors.background }}
|
||||||
contentContainerStyle={[
|
contentContainerStyle={[
|
||||||
styles.content,
|
styles.content,
|
||||||
@@ -68,8 +73,9 @@ export default function HomeScreen() {
|
|||||||
]}
|
]}
|
||||||
contentInsetAdjustmentBehavior="automatic"
|
contentInsetAdjustmentBehavior="automatic"
|
||||||
>
|
>
|
||||||
|
<ScreenTitle title="Home" scrollY={scrollY} style={styles.title} />
|
||||||
<HomeCarousels recentlyAdded={added} recentlyPlayed={played} />
|
<HomeCarousels recentlyAdded={added} recentlyPlayed={played} />
|
||||||
</ScrollView>
|
</Animated.ScrollView>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,4 +84,10 @@ const styles = StyleSheet.create({
|
|||||||
padding: spacing.lg,
|
padding: spacing.lg,
|
||||||
gap: spacing.xl,
|
gap: spacing.xl,
|
||||||
},
|
},
|
||||||
|
// The content padding already insets the title.
|
||||||
|
title: {
|
||||||
|
paddingHorizontal: 0,
|
||||||
|
marginTop: -spacing.lg,
|
||||||
|
marginBottom: -spacing.md,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
@@ -14,11 +14,12 @@ export default function RecentlyAddedScreen() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (status === "LoadingFirstPage" && !isCached) {
|
if (status === "LoadingFirstPage" && !isCached) {
|
||||||
return <MediaGridSkeleton />
|
return <MediaGridSkeleton title="Recently Added" />
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MediaGridList
|
<MediaGridList
|
||||||
|
title="Recently Added"
|
||||||
content={results}
|
content={results}
|
||||||
paddingBottom={contentBottomInset}
|
paddingBottom={contentBottomInset}
|
||||||
onEndReached={() => {
|
onEndReached={() => {
|
||||||
|
|||||||
@@ -14,11 +14,12 @@ export default function RecentlyPlayedScreen() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (status === "LoadingFirstPage" && !isCached) {
|
if (status === "LoadingFirstPage" && !isCached) {
|
||||||
return <MediaGridSkeleton />
|
return <MediaGridSkeleton title="Recently Played" />
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MediaGridList
|
<MediaGridList
|
||||||
|
title="Recently Played"
|
||||||
content={results}
|
content={results}
|
||||||
paddingBottom={contentBottomInset}
|
paddingBottom={contentBottomInset}
|
||||||
onEndReached={() => {
|
onEndReached={() => {
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
import {
|
import { atmosEnabled, dolbyAtmosSupported } from "@/lib/playback-capabilities"
|
||||||
atmosEnabled,
|
|
||||||
deviceDownloadQualities,
|
|
||||||
dolbyAtmosSupported,
|
|
||||||
} from "@/lib/playback-capabilities"
|
|
||||||
import { Ionicons } from "@expo/vector-icons"
|
import { Ionicons } from "@expo/vector-icons"
|
||||||
import { useAction, useMutation, useQuery } from "convex/react"
|
import { useAction, useMutation, useQuery } from "convex/react"
|
||||||
import { Image } from "expo-image"
|
import { Image } from "expo-image"
|
||||||
@@ -29,6 +25,7 @@ import {
|
|||||||
writeRememberedDownloadQuality,
|
writeRememberedDownloadQuality,
|
||||||
} from "@/lib/downloads"
|
} from "@/lib/downloads"
|
||||||
import {
|
import {
|
||||||
|
DOWNLOAD_QUALITIES,
|
||||||
DOWNLOAD_QUALITY_DETAILS,
|
DOWNLOAD_QUALITY_DETAILS,
|
||||||
DOWNLOAD_QUALITY_LABELS,
|
DOWNLOAD_QUALITY_LABELS,
|
||||||
formatBytes,
|
formatBytes,
|
||||||
@@ -453,10 +450,9 @@ function QualitySection({ user }: { user: CurrentUser }) {
|
|||||||
|
|
||||||
/** Shades of the text color, faintest for the smallest files. */
|
/** Shades of the text color, faintest for the smallest files. */
|
||||||
const QUALITY_OPACITY: Record<DownloadQuality, number> = {
|
const QUALITY_OPACITY: Record<DownloadQuality, number> = {
|
||||||
low: 0.2,
|
medium: 0.25,
|
||||||
medium: 0.35,
|
high: 0.45,
|
||||||
high: 0.5,
|
lossless: 0.7,
|
||||||
lossless: 0.75,
|
|
||||||
atmos: 1,
|
atmos: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -511,7 +507,7 @@ function RememberedQualityCard() {
|
|||||||
detail: string
|
detail: string
|
||||||
}[] = [
|
}[] = [
|
||||||
{ value: null, label: "Ask every time", detail: "Choose when downloading" },
|
{ value: null, label: "Ask every time", detail: "Choose when downloading" },
|
||||||
...deviceDownloadQualities.map((quality) => ({
|
...DOWNLOAD_QUALITIES.map((quality) => ({
|
||||||
value: quality,
|
value: quality,
|
||||||
label: DOWNLOAD_QUALITY_LABELS[quality],
|
label: DOWNLOAD_QUALITY_LABELS[quality],
|
||||||
detail: DOWNLOAD_QUALITY_DETAILS[quality],
|
detail: DOWNLOAD_QUALITY_DETAILS[quality],
|
||||||
|
|||||||
@@ -2,9 +2,12 @@ import { useTabletLayout } from "@/hooks/use-tablet-layout"
|
|||||||
import { renderTabScreenContent } from "@/components/tab-screen-content"
|
import { renderTabScreenContent } from "@/components/tab-screen-content"
|
||||||
import { Stack } from "expo-router"
|
import { Stack } from "expo-router"
|
||||||
|
|
||||||
import { TabStackContext } from "@/lib/app-navigation"
|
|
||||||
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
||||||
import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
|
import {
|
||||||
|
inlineTitleOptions,
|
||||||
|
tabStackScreenTitles,
|
||||||
|
useStackScreenOptions,
|
||||||
|
} from "@/lib/navigation"
|
||||||
|
|
||||||
export const unstable_settings = {
|
export const unstable_settings = {
|
||||||
anchor: "index",
|
anchor: "index",
|
||||||
@@ -15,11 +18,11 @@ export default function LibraryLayout() {
|
|||||||
const baseOptions = useStackScreenOptions({ title: "Library" })
|
const baseOptions = useStackScreenOptions({ title: "Library" })
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TabStackContext value="library">
|
|
||||||
<Stack
|
<Stack
|
||||||
screenLayout={renderTabScreenContent}
|
screenLayout={renderTabScreenContent}
|
||||||
screenOptions={({ route }) => ({
|
screenOptions={({ route }) => ({
|
||||||
...baseOptions,
|
...baseOptions,
|
||||||
|
...inlineTitleOptions,
|
||||||
title:
|
title:
|
||||||
tabStackScreenTitles[route.name] ??
|
tabStackScreenTitles[route.name] ??
|
||||||
(tabletLayout ? "Recently Added" : "Library"),
|
(tabletLayout ? "Recently Added" : "Library"),
|
||||||
@@ -37,6 +40,5 @@ export default function LibraryLayout() {
|
|||||||
: undefined,
|
: undefined,
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
</TabStackContext>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -72,6 +72,7 @@ export default function LibraryScreen() {
|
|||||||
const { push } = useAppNavigation()
|
const { push } = useAppNavigation()
|
||||||
const isTablet = tabletLayout
|
const isTablet = tabletLayout
|
||||||
const colors = useThemeColors()
|
const colors = useThemeColors()
|
||||||
|
const title = isTablet ? "Recently Added" : "Library"
|
||||||
const { results, status, loadMore, isCached } = useCachedPaginatedQuery(
|
const { results, status, loadMore, isCached } = useCachedPaginatedQuery(
|
||||||
api.library.browseRecentlyAddedPaginated,
|
api.library.browseRecentlyAddedPaginated,
|
||||||
{},
|
{},
|
||||||
@@ -124,11 +125,18 @@ export default function LibraryScreen() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (status === "LoadingFirstPage" && !isCached) {
|
if (status === "LoadingFirstPage" && !isCached) {
|
||||||
return <MediaGridSkeleton contentInset={false} header={listHeader} />
|
return (
|
||||||
|
<MediaGridSkeleton
|
||||||
|
title={title}
|
||||||
|
contentInset={false}
|
||||||
|
header={listHeader}
|
||||||
|
/>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MediaGridList
|
<MediaGridList
|
||||||
|
title={title}
|
||||||
content={results}
|
content={results}
|
||||||
paddingBottom={tabContentBottomInset}
|
paddingBottom={tabContentBottomInset}
|
||||||
contentInset={false}
|
contentInset={false}
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
import { renderTabScreenContent } from "@/components/tab-screen-content"
|
import { renderTabScreenContent } from "@/components/tab-screen-content"
|
||||||
import { Stack } from "expo-router"
|
import { Stack } from "expo-router"
|
||||||
|
|
||||||
import { TabStackContext } from "@/lib/app-navigation"
|
|
||||||
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
||||||
import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
|
import {
|
||||||
|
inlineTitleOptions,
|
||||||
|
tabStackScreenTitles,
|
||||||
|
useStackScreenOptions,
|
||||||
|
} from "@/lib/navigation"
|
||||||
|
|
||||||
export const unstable_settings = {
|
export const unstable_settings = {
|
||||||
anchor: "index",
|
anchor: "index",
|
||||||
@@ -13,11 +16,11 @@ export default function SearchLayout() {
|
|||||||
const baseOptions = useStackScreenOptions({ title: "Search" })
|
const baseOptions = useStackScreenOptions({ title: "Search" })
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TabStackContext value="search">
|
|
||||||
<Stack
|
<Stack
|
||||||
screenLayout={renderTabScreenContent}
|
screenLayout={renderTabScreenContent}
|
||||||
screenOptions={({ route }) => ({
|
screenOptions={({ route }) => ({
|
||||||
...baseOptions,
|
...baseOptions,
|
||||||
|
...inlineTitleOptions,
|
||||||
title: tabStackScreenTitles[route.name] ?? "Search",
|
title: tabStackScreenTitles[route.name] ?? "Search",
|
||||||
headerRight:
|
headerRight:
|
||||||
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
||||||
@@ -33,6 +36,5 @@ export default function SearchLayout() {
|
|||||||
: undefined,
|
: undefined,
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
</TabStackContext>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ export default function SearchScreen() {
|
|||||||
: {})}
|
: {})}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<SearchResults searchQuery={searchQuery} />
|
<SearchResults searchQuery={searchQuery} title="Search" />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,4 @@
|
|||||||
import {
|
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react"
|
||||||
memo,
|
|
||||||
type ComponentType,
|
|
||||||
type ReactElement,
|
|
||||||
useCallback,
|
|
||||||
useEffect,
|
|
||||||
useMemo,
|
|
||||||
useRef,
|
|
||||||
useState,
|
|
||||||
} from "react"
|
|
||||||
import {
|
import {
|
||||||
Pressable,
|
Pressable,
|
||||||
ScrollView,
|
ScrollView,
|
||||||
@@ -15,11 +6,13 @@ import {
|
|||||||
Text,
|
Text,
|
||||||
View,
|
View,
|
||||||
type ScrollViewInstance,
|
type ScrollViewInstance,
|
||||||
type ViewProps,
|
|
||||||
} from "react-native"
|
} from "react-native"
|
||||||
import MaskedViewClass from "@react-native-masked-view/masked-view"
|
|
||||||
import Animated, {
|
import Animated, {
|
||||||
|
cancelAnimation,
|
||||||
|
Easing,
|
||||||
useAnimatedStyle,
|
useAnimatedStyle,
|
||||||
|
useSharedValue,
|
||||||
|
withTiming,
|
||||||
type SharedValue,
|
type SharedValue,
|
||||||
} from "react-native-reanimated"
|
} from "react-native-reanimated"
|
||||||
|
|
||||||
@@ -28,7 +21,7 @@ import {
|
|||||||
usePlaybackProgress,
|
usePlaybackProgress,
|
||||||
usePlaybackQueue,
|
usePlaybackQueue,
|
||||||
} from "@/contexts/playback"
|
} from "@/contexts/playback"
|
||||||
import { useLyricsTime, usePlaybackClock } from "@/hooks/use-lyrics"
|
import { useLyricsTime } from "@/hooks/use-lyrics"
|
||||||
import type { NowPlayingColors } from "@/lib/now-playing-colors"
|
import type { NowPlayingColors } from "@/lib/now-playing-colors"
|
||||||
import {
|
import {
|
||||||
activeLineIndex,
|
activeLineIndex,
|
||||||
@@ -37,21 +30,12 @@ import {
|
|||||||
type Lyrics,
|
type Lyrics,
|
||||||
} from "@otunes/convex/client/lyrics"
|
} from "@otunes/convex/client/lyrics"
|
||||||
|
|
||||||
// The package's class typings predate React 19's; this is its documented API.
|
|
||||||
const MaskedView = MaskedViewClass as unknown as ComponentType<
|
|
||||||
ViewProps & { maskElement: ReactElement }
|
|
||||||
>
|
|
||||||
|
|
||||||
/** How long a manual scroll keeps the view from following the song. */
|
/** How long a manual scroll keeps the view from following the song. */
|
||||||
const MANUAL_SCROLL_HOLD_MS = 3000
|
const MANUAL_SCROLL_HOLD_MS = 3000
|
||||||
/** Where the playing line sits, as a share of the view's height from the top. */
|
/** Where the playing line sits, as a share of the view's height from the top. */
|
||||||
const ACTIVE_LINE_POSITION = 0.12
|
const ACTIVE_LINE_POSITION = 0.12
|
||||||
/** Blur radius by distance from the playing line; farther lines share the last. */
|
/** Blur radius by distance from the playing line; farther lines share the last. */
|
||||||
const LINE_BLUR = [0, 1, 2, 3]
|
const LINE_BLUR = [0, 1, 2, 3]
|
||||||
/** Opacity of lines other than the one playing. */
|
|
||||||
const INACTIVE_LINE_OPACITY = 0.35
|
|
||||||
/** How long a line takes to brighten, dim, or change blur. */
|
|
||||||
const LINE_FADE_MS = 300
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lyrics in the player's own colors. Synced lines follow playback and seek
|
* Lyrics in the player's own colors. Synced lines follow playback and seek
|
||||||
@@ -92,7 +76,6 @@ function LyricsLines({
|
|||||||
const { isPlaying } = usePlaybackQueue()
|
const { isPlaying } = usePlaybackQueue()
|
||||||
const { seekTo, setIsPlaying } = usePlaybackActions()
|
const { seekTo, setIsPlaying } = usePlaybackActions()
|
||||||
const time = useLyricsTime(lyrics, currentTime, isPlaying)
|
const time = useLyricsTime(lyrics, currentTime, isPlaying)
|
||||||
const clock = usePlaybackClock(currentTime, isPlaying)
|
|
||||||
const active = activeLineIndex(lyrics, time)
|
const active = activeLineIndex(lyrics, time)
|
||||||
const synced = lyrics.synced !== "none"
|
const synced = lyrics.synced !== "none"
|
||||||
const scrollRef = useRef<ScrollViewInstance>(null)
|
const scrollRef = useRef<ScrollViewInstance>(null)
|
||||||
@@ -186,7 +169,8 @@ function LyricsLines({
|
|||||||
: Math.min(Math.abs(index - active), LINE_BLUR.length - 1)
|
: Math.min(Math.abs(index - active), LINE_BLUR.length - 1)
|
||||||
}
|
}
|
||||||
active={index === active}
|
active={index === active}
|
||||||
clock={clock}
|
time={index === active ? time : null}
|
||||||
|
isPlaying={isPlaying}
|
||||||
colors={colors}
|
colors={colors}
|
||||||
textStyle={lineStyle}
|
textStyle={lineStyle}
|
||||||
onSelect={playFrom}
|
onSelect={playFrom}
|
||||||
@@ -214,16 +198,17 @@ function LyricsLines({
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One timed line, laid out word by word whether or not it is playing, so it
|
* One timed line, blurred by its `distance` from the playing line. Only the
|
||||||
* never re-wraps. It fades and blurs by its `distance` from the playing line,
|
* playing line gets the time, so the others skip re-rendering as the song
|
||||||
* and only the playing line's words fill.
|
* plays.
|
||||||
*/
|
*/
|
||||||
const SyncedLine = memo(function SyncedLine({
|
const SyncedLine = memo(function SyncedLine({
|
||||||
index,
|
index,
|
||||||
line,
|
line,
|
||||||
distance,
|
distance,
|
||||||
active,
|
active,
|
||||||
clock,
|
time,
|
||||||
|
isPlaying,
|
||||||
colors,
|
colors,
|
||||||
textStyle,
|
textStyle,
|
||||||
onSelect,
|
onSelect,
|
||||||
@@ -233,100 +218,136 @@ const SyncedLine = memo(function SyncedLine({
|
|||||||
line: LyricLine
|
line: LyricLine
|
||||||
distance: number
|
distance: number
|
||||||
active: boolean
|
active: boolean
|
||||||
clock: SharedValue<number>
|
time: number | null
|
||||||
|
isPlaying: boolean
|
||||||
colors: NowPlayingColors
|
colors: NowPlayingColors
|
||||||
textStyle: { fontSize: number; lineHeight: number }
|
textStyle: { fontSize: number; lineHeight: number }
|
||||||
onSelect: (seconds: number) => void
|
onSelect: (seconds: number) => void
|
||||||
onLayoutY: (index: number, y: number) => void
|
onLayoutY: (index: number, y: number) => void
|
||||||
}) {
|
}) {
|
||||||
const wordStyle = [styles.lineText, textStyle, { color: colors.foreground }]
|
const blur = LINE_BLUR[distance]
|
||||||
return (
|
return (
|
||||||
<Pressable
|
<Pressable
|
||||||
onPress={() => onSelect(line.start ?? 0)}
|
onPress={() => onSelect(line.start ?? 0)}
|
||||||
onLayout={(event) => onLayoutY(index, event.nativeEvent.layout.y)}
|
onLayout={(event) => onLayoutY(index, event.nativeEvent.layout.y)}
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
accessibilityHint="Plays from this line"
|
accessibilityHint="Plays from this line"
|
||||||
style={styles.line}
|
style={[styles.line, blur > 0 && { filter: [{ blur }] }]}
|
||||||
>
|
>
|
||||||
<Animated.View
|
{active && line.words && time !== null ? (
|
||||||
style={{
|
<FilledWords
|
||||||
opacity: active ? 1 : INACTIVE_LINE_OPACITY,
|
words={line.words}
|
||||||
filter: [{ blur: LINE_BLUR[distance] }],
|
time={time}
|
||||||
transitionProperty: ["opacity", "filter"],
|
isPlaying={isPlaying}
|
||||||
transitionDuration: LINE_FADE_MS,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{line.words ? (
|
|
||||||
<View
|
|
||||||
style={[styles.words, { columnGap: textStyle.fontSize * 0.25 }]}
|
|
||||||
>
|
|
||||||
{line.words.map((word, wordIndex) =>
|
|
||||||
active ? (
|
|
||||||
<FilledWord
|
|
||||||
key={wordIndex}
|
|
||||||
word={word}
|
|
||||||
clock={clock}
|
|
||||||
colors={colors}
|
colors={colors}
|
||||||
textStyle={textStyle}
|
textStyle={textStyle}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Text key={wordIndex} style={wordStyle}>
|
<Text
|
||||||
{word.text.trim()}
|
style={[
|
||||||
|
styles.lineText,
|
||||||
|
textStyle,
|
||||||
|
{
|
||||||
|
color:
|
||||||
|
active && !line.words
|
||||||
|
? colors.foreground
|
||||||
|
: colors.lyricsInactive,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{line.text}
|
||||||
</Text>
|
</Text>
|
||||||
)
|
|
||||||
)}
|
)}
|
||||||
</View>
|
|
||||||
) : (
|
|
||||||
<Text style={wordStyle}>{line.text}</Text>
|
|
||||||
)}
|
|
||||||
</Animated.View>
|
|
||||||
</Pressable>
|
</Pressable>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A word of the playing line, filled from dim to bright with a soft edge as
|
* The playing line's words, each wiping from dim to bright as it is sung.
|
||||||
* it is sung: a gradient 2.5 times its width slides under the word's
|
* Reanimated runs the wipe; playback updates only re-anchor it.
|
||||||
* shape, like the web panel's.
|
|
||||||
*/
|
*/
|
||||||
|
function FilledWords({
|
||||||
|
words,
|
||||||
|
time,
|
||||||
|
isPlaying,
|
||||||
|
colors,
|
||||||
|
textStyle,
|
||||||
|
}: {
|
||||||
|
words: LyricWord[]
|
||||||
|
time: number
|
||||||
|
isPlaying: boolean
|
||||||
|
colors: NowPlayingColors
|
||||||
|
textStyle: { fontSize: number; lineHeight: number }
|
||||||
|
}) {
|
||||||
|
const sung = useSharedValue(time)
|
||||||
|
const end = words.at(-1)?.end ?? time
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
cancelAnimation(sung)
|
||||||
|
sung.value = time
|
||||||
|
if (isPlaying && end > time) {
|
||||||
|
sung.value = withTiming(end, {
|
||||||
|
duration: (end - time) * 1000,
|
||||||
|
easing: Easing.linear,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [sung, time, isPlaying, end])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={[styles.words, { columnGap: textStyle.fontSize * 0.25 }]}>
|
||||||
|
{words.map((word, index) => (
|
||||||
|
<FilledWord
|
||||||
|
key={index}
|
||||||
|
word={word}
|
||||||
|
sung={sung}
|
||||||
|
colors={colors}
|
||||||
|
textStyle={textStyle}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
function FilledWord({
|
function FilledWord({
|
||||||
word,
|
word,
|
||||||
clock,
|
sung,
|
||||||
colors,
|
colors,
|
||||||
textStyle,
|
textStyle,
|
||||||
}: {
|
}: {
|
||||||
word: LyricWord
|
word: LyricWord
|
||||||
clock: SharedValue<number>
|
sung: SharedValue<number>
|
||||||
colors: NowPlayingColors
|
colors: NowPlayingColors
|
||||||
textStyle: { fontSize: number; lineHeight: number }
|
textStyle: { fontSize: number; lineHeight: number }
|
||||||
}) {
|
}) {
|
||||||
|
const [width, setWidth] = useState(0)
|
||||||
const text = word.text.trim()
|
const text = word.text.trim()
|
||||||
const slide = useAnimatedStyle(() => {
|
const wipe = useAnimatedStyle(() => {
|
||||||
const progress =
|
const progress =
|
||||||
(clock.value - word.start) / Math.max(word.end - word.start, 0.05)
|
(sung.value - word.start) / Math.max(word.end - word.start, 0.05)
|
||||||
const sung = Math.min(Math.max(progress, 0), 1)
|
return { width: width * Math.min(Math.max(progress, 0), 1) }
|
||||||
// -60% of the gradient's width shows its dim end; 0% its bright one.
|
|
||||||
return { transform: [{ translateX: `${-60 * (1 - sung)}%` }] }
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MaskedView
|
<View>
|
||||||
maskElement={
|
<Text
|
||||||
<Text style={[styles.lineText, textStyle, styles.mask]}>{text}</Text>
|
style={[styles.lineText, textStyle, { color: colors.lyricsUnsung }]}
|
||||||
}
|
onLayout={(event) => setWidth(event.nativeEvent.layout.width)}
|
||||||
>
|
>
|
||||||
{/* Sizes the word; the mask draws it. */}
|
{text}
|
||||||
<Text style={[styles.lineText, textStyle, styles.hidden]}>{text}</Text>
|
</Text>
|
||||||
<Animated.View
|
<Animated.View style={[styles.wipe, wipe]}>
|
||||||
|
<Text
|
||||||
|
numberOfLines={1}
|
||||||
style={[
|
style={[
|
||||||
styles.fillGradient,
|
styles.lineText,
|
||||||
{
|
textStyle,
|
||||||
backgroundImage: `linear-gradient(90deg, ${colors.foreground} 40%, ${colors.lyricsUnsung} 60%)`,
|
{ color: colors.foreground, width },
|
||||||
},
|
|
||||||
slide,
|
|
||||||
]}
|
]}
|
||||||
/>
|
>
|
||||||
</MaskedView>
|
{text}
|
||||||
|
</Text>
|
||||||
|
</Animated.View>
|
||||||
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -337,14 +358,12 @@ const styles = StyleSheet.create({
|
|||||||
line: { paddingVertical: 9 },
|
line: { paddingVertical: 9 },
|
||||||
lineText: { fontWeight: "800" },
|
lineText: { fontWeight: "800" },
|
||||||
words: { flexDirection: "row", flexWrap: "wrap" },
|
words: { flexDirection: "row", flexWrap: "wrap" },
|
||||||
mask: { color: "black" },
|
wipe: {
|
||||||
hidden: { opacity: 0 },
|
|
||||||
fillGradient: {
|
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
top: 0,
|
top: 0,
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
left: 0,
|
left: 0,
|
||||||
width: "250%",
|
overflow: "hidden",
|
||||||
},
|
},
|
||||||
plainLine: { fontWeight: "700", paddingVertical: 2 },
|
plainLine: { fontWeight: "700", paddingVertical: 2 },
|
||||||
stanzaGap: { height: 18 },
|
stanzaGap: { height: 18 },
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { tabletLayoutTransition } from "@/lib/tablet-motion"
|
|||||||
import { TabletMediaGrid } from "@/components/tablet-media-grid"
|
import { TabletMediaGrid } from "@/components/tablet-media-grid"
|
||||||
import { useMediaGridLayout } from "@/hooks/use-media-grid-layout"
|
import { useMediaGridLayout } from "@/hooks/use-media-grid-layout"
|
||||||
import { MusicEntityView } from "@/components/music-entity-view"
|
import { MusicEntityView } from "@/components/music-entity-view"
|
||||||
|
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||||
import { Link } from "expo-router"
|
import { Link } from "expo-router"
|
||||||
import { Ionicons } from "@expo/vector-icons"
|
import { Ionicons } from "@expo/vector-icons"
|
||||||
import { memo, useCallback, type ReactElement } from "react"
|
import { memo, useCallback, type ReactElement } from "react"
|
||||||
@@ -300,17 +301,21 @@ export function MediaGridList({
|
|||||||
onEndReached,
|
onEndReached,
|
||||||
ListHeaderComponent,
|
ListHeaderComponent,
|
||||||
contentInset = true,
|
contentInset = true,
|
||||||
|
title,
|
||||||
}: {
|
}: {
|
||||||
content: MediaItem[]
|
content: MediaItem[]
|
||||||
paddingBottom: number
|
paddingBottom: number
|
||||||
onEndReached?: () => void
|
onEndReached?: () => void
|
||||||
ListHeaderComponent?: ReactElement
|
ListHeaderComponent?: ReactElement
|
||||||
contentInset?: boolean
|
contentInset?: boolean
|
||||||
|
/** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */
|
||||||
|
title?: string
|
||||||
}) {
|
}) {
|
||||||
const tabletLayout = useTabletLayout()
|
const tabletLayout = useTabletLayout()
|
||||||
const { columns, cardWidth, onLayout, horizontalPadding, gap } =
|
const { columns, cardWidth, onLayout, horizontalPadding, gap } =
|
||||||
useMediaGridLayout()
|
useMediaGridLayout()
|
||||||
const colors = useThemeColors()
|
const colors = useThemeColors()
|
||||||
|
const { ref, scrollY } = useScreenTitleScroll<FlatList<MediaItem>>()
|
||||||
const renderItem = useCallback(
|
const renderItem = useCallback(
|
||||||
({ item }: ListRenderItemInfo<MediaItem>) => (
|
({ item }: ListRenderItemInfo<MediaItem>) => (
|
||||||
<View style={{ width: cardWidth }}>
|
<View style={{ width: cardWidth }}>
|
||||||
@@ -328,13 +333,30 @@ export function MediaGridList({
|
|||||||
onEndReached={onEndReached}
|
onEndReached={onEndReached}
|
||||||
ListHeaderComponent={ListHeaderComponent}
|
ListHeaderComponent={ListHeaderComponent}
|
||||||
contentInset={contentInset}
|
contentInset={contentInset}
|
||||||
|
title={title}
|
||||||
renderCard={renderTabletCard}
|
renderCard={renderTabletCard}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const header = title ? (
|
||||||
|
<View>
|
||||||
|
<ScreenTitle
|
||||||
|
title={title}
|
||||||
|
scrollY={scrollY}
|
||||||
|
// Inset grids already pad the whole list horizontally.
|
||||||
|
style={{ paddingHorizontal: contentInset ? 0 : horizontalPadding }}
|
||||||
|
/>
|
||||||
|
{ListHeaderComponent}
|
||||||
|
</View>
|
||||||
|
) : (
|
||||||
|
ListHeaderComponent
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FlatList
|
<Animated.FlatList
|
||||||
|
ref={ref}
|
||||||
|
scrollEventThrottle={16}
|
||||||
key={columns}
|
key={columns}
|
||||||
onLayout={onLayout}
|
onLayout={onLayout}
|
||||||
data={content}
|
data={content}
|
||||||
@@ -351,6 +373,7 @@ export function MediaGridList({
|
|||||||
paddingBottom,
|
paddingBottom,
|
||||||
gap,
|
gap,
|
||||||
...(contentInset ? { paddingHorizontal: horizontalPadding } : {}),
|
...(contentInset ? { paddingHorizontal: horizontalPadding } : {}),
|
||||||
|
...(title ? { paddingTop: 0 } : {}),
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
columnWrapperStyle={[
|
columnWrapperStyle={[
|
||||||
@@ -359,7 +382,7 @@ export function MediaGridList({
|
|||||||
{ gap },
|
{ gap },
|
||||||
]}
|
]}
|
||||||
contentInsetAdjustmentBehavior="automatic"
|
contentInsetAdjustmentBehavior="automatic"
|
||||||
ListHeaderComponent={ListHeaderComponent}
|
ListHeaderComponent={header}
|
||||||
onEndReached={onEndReached}
|
onEndReached={onEndReached}
|
||||||
onEndReachedThreshold={0.5}
|
onEndReachedThreshold={0.5}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { useAndroidTabPalette } from "@/contexts/android-tab-theme"
|
import {
|
||||||
|
useAndroidTabPalette,
|
||||||
|
useAndroidTabHasArtworkPalette,
|
||||||
|
} from "@/contexts/android-tab-theme"
|
||||||
import { Ionicons } from "@expo/vector-icons"
|
import { Ionicons } from "@expo/vector-icons"
|
||||||
import { NativeTabs } from "expo-router/native-tabs"
|
import { NativeTabs } from "expo-router/native-tabs"
|
||||||
import { useRouter } from "expo-router"
|
import { useRouter } from "expo-router"
|
||||||
@@ -163,10 +166,20 @@ function MiniPlayerContent({
|
|||||||
|
|
||||||
function MiniPlayerChrome({ children }: { children: React.ReactNode }) {
|
function MiniPlayerChrome({ children }: { children: React.ReactNode }) {
|
||||||
const palette = useAndroidTabPalette()
|
const palette = useAndroidTabPalette()
|
||||||
|
const hasArtworkPalette = useAndroidTabHasArtworkPalette()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[styles.androidBar, { backgroundColor: palette.background }]}>
|
<View style={[styles.androidBar, { backgroundColor: palette.background }]}>
|
||||||
{children}
|
{children}
|
||||||
|
{hasArtworkPalette ? (
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
styles.separator,
|
||||||
|
styles.topBorder,
|
||||||
|
{ backgroundColor: palette.secondaryForeground },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
<View
|
<View
|
||||||
style={[
|
style={[
|
||||||
styles.separator,
|
styles.separator,
|
||||||
@@ -254,6 +267,7 @@ const styles = StyleSheet.create({
|
|||||||
height: 1,
|
height: 1,
|
||||||
zIndex: 1,
|
zIndex: 1,
|
||||||
},
|
},
|
||||||
|
topBorder: { top: 0 },
|
||||||
bottomBorder: { bottom: 0 },
|
bottomBorder: { bottom: 0 },
|
||||||
content: {
|
content: {
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
import { useHeaderHeight } from "expo-router/react-navigation"
|
||||||
|
import type { Component } from "react"
|
||||||
|
import {
|
||||||
|
Platform,
|
||||||
|
StyleSheet,
|
||||||
|
type ScrollViewInstance,
|
||||||
|
type StyleProp,
|
||||||
|
type TextStyle,
|
||||||
|
} from "react-native"
|
||||||
|
import Animated, {
|
||||||
|
useAnimatedRef,
|
||||||
|
useAnimatedStyle,
|
||||||
|
useScrollOffset,
|
||||||
|
type SharedValue,
|
||||||
|
} from "react-native-reanimated"
|
||||||
|
|
||||||
|
import { spacing, useThemeColors } from "@/lib/theme"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tracks the scroll view that renders a `ScreenTitle`. Attach `ref` to that
|
||||||
|
* Reanimated `Animated.ScrollView` / `Animated.FlatList` and pass `scrollY`
|
||||||
|
* to the title.
|
||||||
|
*/
|
||||||
|
export function useScreenTitleScroll<
|
||||||
|
TScrollView extends Component | ScrollViewInstance,
|
||||||
|
>() {
|
||||||
|
const ref = useAnimatedRef<TScrollView>()
|
||||||
|
const scrollY = useScrollOffset(ref)
|
||||||
|
return { ref, scrollY }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* iOS screen title rendered as the first item of a screen's scroll content,
|
||||||
|
* in place of the native large title (Apple Music style): it scrolls away
|
||||||
|
* with the content, never collapses into the bar, and stays put on
|
||||||
|
* pull-down. Android keeps its native header title, so this renders nothing.
|
||||||
|
*/
|
||||||
|
export function ScreenTitle({
|
||||||
|
title,
|
||||||
|
scrollY,
|
||||||
|
style,
|
||||||
|
}: {
|
||||||
|
title: string
|
||||||
|
/** From `useScreenTitleScroll`; omit for screens that never scroll. */
|
||||||
|
scrollY?: SharedValue<number>
|
||||||
|
style?: StyleProp<TextStyle>
|
||||||
|
}) {
|
||||||
|
const colors = useThemeColors()
|
||||||
|
// At rest the scroll offset is minus the automatic header inset, so any
|
||||||
|
// offset below that is overscroll the title should cancel out.
|
||||||
|
const headerHeight = useHeaderHeight()
|
||||||
|
const pinStyle = useAnimatedStyle(() => ({
|
||||||
|
transform: [
|
||||||
|
{
|
||||||
|
translateY: scrollY ? Math.min(0, scrollY.value + headerHeight) : 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}))
|
||||||
|
|
||||||
|
if (Platform.OS !== "ios") return null
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Animated.Text
|
||||||
|
accessibilityRole="header"
|
||||||
|
numberOfLines={2}
|
||||||
|
style={[styles.title, { color: colors.foreground }, style, pinStyle]}
|
||||||
|
>
|
||||||
|
{title}
|
||||||
|
</Animated.Text>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Matches UIKit's large title metrics: 34pt bold in a 52pt tall area.
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
title: {
|
||||||
|
fontSize: 34,
|
||||||
|
lineHeight: 41,
|
||||||
|
fontWeight: "700",
|
||||||
|
letterSpacing: 0.37,
|
||||||
|
paddingHorizontal: spacing.lg,
|
||||||
|
paddingTop: 3,
|
||||||
|
paddingBottom: 8,
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -1,13 +1,15 @@
|
|||||||
import { memo, useCallback, useMemo } from "react"
|
import { memo, useCallback, useMemo } from "react"
|
||||||
import {
|
import {
|
||||||
FlatList,
|
type FlatList,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
Text,
|
Text,
|
||||||
View,
|
View,
|
||||||
type ListRenderItemInfo,
|
type ListRenderItemInfo,
|
||||||
} from "react-native"
|
} from "react-native"
|
||||||
|
import Animated from "react-native-reanimated"
|
||||||
|
|
||||||
import { ContentCarousel } from "@/components/media-cards"
|
import { ContentCarousel } from "@/components/media-cards"
|
||||||
|
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||||
import type { MediaAction } from "@/components/media-context-menu"
|
import type { MediaAction } from "@/components/media-context-menu"
|
||||||
import { tabContentBottomInset, SongListRow } from "@/components/player"
|
import { tabContentBottomInset, SongListRow } from "@/components/player"
|
||||||
import { SongListSkeleton } from "@/components/skeletons"
|
import { SongListSkeleton } from "@/components/skeletons"
|
||||||
@@ -19,8 +21,16 @@ import { api } from "@otunes/convex/_generated/api"
|
|||||||
import type { BrowseSong, SearchSong } from "@otunes/convex/types"
|
import type { BrowseSong, SearchSong } from "@otunes/convex/types"
|
||||||
import { spacing, useThemeColors } from "@/lib/theme"
|
import { spacing, useThemeColors } from "@/lib/theme"
|
||||||
|
|
||||||
function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
|
function SearchResultsBody({
|
||||||
|
searchQuery,
|
||||||
|
title,
|
||||||
|
}: {
|
||||||
|
searchQuery: string
|
||||||
|
/** iOS `ScreenTitle`, shown above the results and while idle. */
|
||||||
|
title: string
|
||||||
|
}) {
|
||||||
const colors = useThemeColors()
|
const colors = useThemeColors()
|
||||||
|
const { ref, scrollY } = useScreenTitleScroll<FlatList<BrowseSong>>()
|
||||||
const { playFromSong } = usePlaybackActions()
|
const { playFromSong } = usePlaybackActions()
|
||||||
const { isSongFavorite } = useFavorites()
|
const { isSongFavorite } = useFavorites()
|
||||||
const { handleSongAction } = useMediaMenuActions()
|
const { handleSongAction } = useMediaMenuActions()
|
||||||
@@ -76,16 +86,14 @@ function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (isSearching) {
|
if (isSearching) {
|
||||||
return <SongListSkeleton />
|
return <SongListSkeleton title={title} />
|
||||||
}
|
|
||||||
|
|
||||||
if (!hasQuery) {
|
|
||||||
return <></>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FlatList
|
<Animated.FlatList
|
||||||
data={results?.songs ?? []}
|
ref={ref}
|
||||||
|
scrollEventThrottle={16}
|
||||||
|
data={hasQuery ? (results?.songs ?? []) : []}
|
||||||
keyExtractor={(song) => song.id}
|
keyExtractor={(song) => song.id}
|
||||||
style={{ flex: 1, backgroundColor: colors.background }}
|
style={{ flex: 1, backgroundColor: colors.background }}
|
||||||
contentContainerStyle={{ paddingBottom: tabContentBottomInset }}
|
contentContainerStyle={{ paddingBottom: tabContentBottomInset }}
|
||||||
@@ -93,7 +101,8 @@ function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
|
|||||||
keyboardShouldPersistTaps="handled"
|
keyboardShouldPersistTaps="handled"
|
||||||
ListHeaderComponent={
|
ListHeaderComponent={
|
||||||
<>
|
<>
|
||||||
{!hasResults ? (
|
<ScreenTitle title={title} scrollY={scrollY} />
|
||||||
|
{hasQuery && !hasResults ? (
|
||||||
<View style={styles.empty}>
|
<View style={styles.empty}>
|
||||||
<Text
|
<Text
|
||||||
style={[styles.emptyText, { color: colors.mutedForeground }]}
|
style={[styles.emptyText, { color: colors.mutedForeground }]}
|
||||||
@@ -103,13 +112,13 @@ function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
|
|||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{results?.artists.length ? (
|
{hasQuery && results?.artists.length ? (
|
||||||
<View style={styles.section}>
|
<View style={styles.section}>
|
||||||
<ContentCarousel title="Artists" content={results.artists} />
|
<ContentCarousel title="Artists" content={results.artists} />
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{results?.albums.length ? (
|
{hasQuery && results?.albums.length ? (
|
||||||
<View style={styles.section}>
|
<View style={styles.section}>
|
||||||
<ContentCarousel title="Albums" content={results.albums} />
|
<ContentCarousel title="Albums" content={results.albums} />
|
||||||
</View>
|
</View>
|
||||||
@@ -118,7 +127,7 @@ function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
|
|||||||
}
|
}
|
||||||
renderItem={renderItem}
|
renderItem={renderItem}
|
||||||
ListFooterComponent={
|
ListFooterComponent={
|
||||||
playlistResults && playlistResults.length > 0 ? (
|
hasQuery && playlistResults && playlistResults.length > 0 ? (
|
||||||
<View style={styles.section}>
|
<View style={styles.section}>
|
||||||
<ContentCarousel title="Playlists" content={playlistResults} />
|
<ContentCarousel title="Playlists" content={playlistResults} />
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
collectionInset,
|
collectionInset,
|
||||||
} from "@/components/collection-list"
|
} from "@/components/collection-list"
|
||||||
import { tabletCardTextHeight } from "@/components/tablet-media-grid"
|
import { tabletCardTextHeight } from "@/components/tablet-media-grid"
|
||||||
|
import { ScreenTitle } from "@/components/screen-title"
|
||||||
import { Link } from "expo-router"
|
import { Link } from "expo-router"
|
||||||
import { useHeaderHeight } from "expo-router/react-navigation"
|
import { useHeaderHeight } from "expo-router/react-navigation"
|
||||||
import Reanimated from "react-native-reanimated"
|
import Reanimated from "react-native-reanimated"
|
||||||
@@ -151,9 +152,16 @@ function SongRows({ rows, inset }: { rows: number; inset?: boolean }) {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SongListSkeleton({ rows = 10 }: { rows?: number }) {
|
export function SongListSkeleton({
|
||||||
|
rows = 10,
|
||||||
|
title,
|
||||||
|
}: {
|
||||||
|
rows?: number
|
||||||
|
title?: string
|
||||||
|
}) {
|
||||||
return (
|
return (
|
||||||
<SkeletonScreen>
|
<SkeletonScreen>
|
||||||
|
{title ? <ScreenTitle title={title} /> : null}
|
||||||
<SongRows rows={rows} />
|
<SongRows rows={rows} />
|
||||||
</SkeletonScreen>
|
</SkeletonScreen>
|
||||||
)
|
)
|
||||||
@@ -234,23 +242,45 @@ export function MediaGridSkeleton({
|
|||||||
items = 6,
|
items = 6,
|
||||||
contentInset = true,
|
contentInset = true,
|
||||||
header,
|
header,
|
||||||
|
title,
|
||||||
}: {
|
}: {
|
||||||
items?: number
|
items?: number
|
||||||
contentInset?: boolean
|
contentInset?: boolean
|
||||||
/** The loaded list's `ListHeaderComponent`, so it keeps its position. */
|
/** The loaded list's `ListHeaderComponent`, so it keeps its position. */
|
||||||
header?: ReactNode
|
header?: ReactNode
|
||||||
|
/** The loaded list's `ScreenTitle`, which replaces its top inset. */
|
||||||
|
title?: string
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<SkeletonScreen>
|
<SkeletonScreen>
|
||||||
<MediaGridContent
|
<MediaGridContent
|
||||||
items={items}
|
items={items}
|
||||||
contentInset={contentInset}
|
contentInset={contentInset && !title}
|
||||||
header={header}
|
header={
|
||||||
|
title ? (
|
||||||
|
<>
|
||||||
|
<MediaGridTitle title={title} />
|
||||||
|
{header}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
header
|
||||||
|
)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</SkeletonScreen>
|
</SkeletonScreen>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function MediaGridTitle({ title }: { title: string }) {
|
||||||
|
const { horizontalPadding } = useMediaGridLayout()
|
||||||
|
return (
|
||||||
|
<ScreenTitle
|
||||||
|
title={title}
|
||||||
|
style={{ paddingHorizontal: horizontalPadding }}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export function CarouselSkeleton() {
|
export function CarouselSkeleton() {
|
||||||
return (
|
return (
|
||||||
<View style={styles.carousel}>
|
<View style={styles.carousel}>
|
||||||
@@ -264,10 +294,11 @@ export function CarouselSkeleton() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function HomeSkeleton() {
|
export function HomeSkeleton({ title }: { title: string }) {
|
||||||
return (
|
return (
|
||||||
<SkeletonScreen>
|
<SkeletonScreen>
|
||||||
<View style={styles.home}>
|
<View style={styles.home}>
|
||||||
|
<ScreenTitle title={title} style={styles.homeTitle} />
|
||||||
<CarouselSkeleton />
|
<CarouselSkeleton />
|
||||||
<CarouselSkeleton />
|
<CarouselSkeleton />
|
||||||
</View>
|
</View>
|
||||||
@@ -388,10 +419,17 @@ export function CollectionDetailSkeleton({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ArtistListSkeleton({ rows = 12 }: { rows?: number }) {
|
export function ArtistListSkeleton({
|
||||||
|
rows = 12,
|
||||||
|
title,
|
||||||
|
}: {
|
||||||
|
rows?: number
|
||||||
|
title?: string
|
||||||
|
}) {
|
||||||
const colors = useThemeColors()
|
const colors = useThemeColors()
|
||||||
return (
|
return (
|
||||||
<SkeletonScreen>
|
<SkeletonScreen>
|
||||||
|
{title ? <ScreenTitle title={title} /> : null}
|
||||||
{Array.from({ length: rows }, (_, index) => (
|
{Array.from({ length: rows }, (_, index) => (
|
||||||
<View
|
<View
|
||||||
key={index}
|
key={index}
|
||||||
@@ -456,6 +494,12 @@ const styles = StyleSheet.create({
|
|||||||
carousel: { gap: spacing.md, overflow: "hidden" },
|
carousel: { gap: spacing.md, overflow: "hidden" },
|
||||||
carouselRow: { flexDirection: "row", gap: spacing.md },
|
carouselRow: { flexDirection: "row", gap: spacing.md },
|
||||||
home: { padding: spacing.lg, gap: spacing.xl },
|
home: { padding: spacing.lg, gap: spacing.xl },
|
||||||
|
// Mirrors the home screen's title spacing.
|
||||||
|
homeTitle: {
|
||||||
|
paddingHorizontal: 0,
|
||||||
|
marginTop: -spacing.lg,
|
||||||
|
marginBottom: -spacing.md,
|
||||||
|
},
|
||||||
centeredHero: { alignItems: "center", padding: spacing.lg, gap: spacing.sm },
|
centeredHero: { alignItems: "center", padding: spacing.lg, gap: spacing.sm },
|
||||||
actions: {
|
actions: {
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
type ReactElement,
|
type ReactElement,
|
||||||
} from "react"
|
} from "react"
|
||||||
import {
|
import {
|
||||||
ScrollView,
|
type ScrollViewInstance,
|
||||||
View,
|
View,
|
||||||
type NativeSyntheticEvent,
|
type NativeSyntheticEvent,
|
||||||
type NativeScrollEvent,
|
type NativeScrollEvent,
|
||||||
@@ -15,6 +15,7 @@ import Animated from "react-native-reanimated"
|
|||||||
import { useSafeAreaInsets } from "react-native-safe-area-context"
|
import { useSafeAreaInsets } from "react-native-safe-area-context"
|
||||||
|
|
||||||
import type { MediaItem } from "@/components/media-cards"
|
import type { MediaItem } from "@/components/media-cards"
|
||||||
|
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||||
import { useMediaGridLayout } from "@/hooks/use-media-grid-layout"
|
import { useMediaGridLayout } from "@/hooks/use-media-grid-layout"
|
||||||
import { tabletLayoutTransition } from "@/lib/tablet-motion"
|
import { tabletLayoutTransition } from "@/lib/tablet-motion"
|
||||||
import { useThemeColors } from "@/lib/theme"
|
import { useThemeColors } from "@/lib/theme"
|
||||||
@@ -28,6 +29,8 @@ type GridProps = {
|
|||||||
onEndReached?: () => void
|
onEndReached?: () => void
|
||||||
ListHeaderComponent?: ReactElement
|
ListHeaderComponent?: ReactElement
|
||||||
contentInset?: boolean
|
contentInset?: boolean
|
||||||
|
/** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */
|
||||||
|
title?: string
|
||||||
renderCard: (item: MediaItem, width: number) => ReactElement
|
renderCard: (item: MediaItem, width: number) => ReactElement
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,9 +44,12 @@ export function TabletMediaGrid({
|
|||||||
onEndReached,
|
onEndReached,
|
||||||
ListHeaderComponent,
|
ListHeaderComponent,
|
||||||
contentInset = true,
|
contentInset = true,
|
||||||
|
title,
|
||||||
renderCard,
|
renderCard,
|
||||||
}: GridProps) {
|
}: GridProps) {
|
||||||
const colors = useThemeColors()
|
const colors = useThemeColors()
|
||||||
|
const { ref, scrollY: titleScrollY } =
|
||||||
|
useScreenTitleScroll<ScrollViewInstance>()
|
||||||
const insets = useSafeAreaInsets()
|
const insets = useSafeAreaInsets()
|
||||||
const { columns, cardWidth, onLayout, horizontalPadding, gap, ready } =
|
const { columns, cardWidth, onLayout, horizontalPadding, gap, ready } =
|
||||||
useMediaGridLayout()
|
useMediaGridLayout()
|
||||||
@@ -102,18 +108,27 @@ export function TabletMediaGrid({
|
|||||||
setViewportHeight(event.nativeEvent.layout.height)
|
setViewportHeight(event.nativeEvent.layout.height)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ScrollView
|
<Animated.ScrollView
|
||||||
|
ref={ref}
|
||||||
onScroll={onScroll}
|
onScroll={onScroll}
|
||||||
scrollEventThrottle={32}
|
// Every frame, so the title pins smoothly on pull-down.
|
||||||
|
scrollEventThrottle={16}
|
||||||
contentInsetAdjustmentBehavior="automatic"
|
contentInsetAdjustmentBehavior="automatic"
|
||||||
contentContainerStyle={{
|
contentContainerStyle={{
|
||||||
paddingTop: contentInset ? horizontalPadding : 0,
|
paddingTop: contentInset && !title ? horizontalPadding : 0,
|
||||||
paddingBottom: paddingBottom + insets.bottom,
|
paddingBottom: paddingBottom + insets.bottom,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<View
|
<View
|
||||||
onLayout={(event) => setHeaderHeight(event.nativeEvent.layout.height)}
|
onLayout={(event) => setHeaderHeight(event.nativeEvent.layout.height)}
|
||||||
>
|
>
|
||||||
|
{title ? (
|
||||||
|
<ScreenTitle
|
||||||
|
title={title}
|
||||||
|
scrollY={titleScrollY}
|
||||||
|
style={{ paddingHorizontal: horizontalPadding }}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
{ListHeaderComponent}
|
{ListHeaderComponent}
|
||||||
</View>
|
</View>
|
||||||
<View style={{ height: gridHeight }}>
|
<View style={{ height: gridHeight }}>
|
||||||
@@ -136,7 +151,7 @@ export function TabletMediaGrid({
|
|||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</Animated.ScrollView>
|
||||||
</Animated.View>
|
</Animated.View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -25,7 +25,6 @@ import { AndroidSheet } from "@/components/android-sheet"
|
|||||||
import { AudioFormatBadge } from "@/components/audio-format-badge"
|
import { AudioFormatBadge } from "@/components/audio-format-badge"
|
||||||
import { useCacheScope } from "@/contexts/persistent-cache"
|
import { useCacheScope } from "@/contexts/persistent-cache"
|
||||||
import { useServerConfig } from "@/contexts/server-config"
|
import { useServerConfig } from "@/contexts/server-config"
|
||||||
import { useBackgroundDownloads } from "@/hooks/use-background-downloads"
|
|
||||||
import { useCachedQuery } from "@/hooks/use-cached-query"
|
import { useCachedQuery } from "@/hooks/use-cached-query"
|
||||||
import { getAuthCookieHeader } from "@/lib/auth-cookies"
|
import { getAuthCookieHeader } from "@/lib/auth-cookies"
|
||||||
import {
|
import {
|
||||||
@@ -34,7 +33,6 @@ import {
|
|||||||
writeRememberedDownloadQuality,
|
writeRememberedDownloadQuality,
|
||||||
} from "@/lib/downloads"
|
} from "@/lib/downloads"
|
||||||
import { loadPlaybackSongs } from "@/lib/playback-files"
|
import { loadPlaybackSongs } from "@/lib/playback-files"
|
||||||
import { downloadQualitySupported } from "@/lib/playback-capabilities"
|
|
||||||
import type { ServerConfig } from "@/lib/server-config"
|
import type { ServerConfig } from "@/lib/server-config"
|
||||||
import { showError } from "@/lib/toast"
|
import { showError } from "@/lib/toast"
|
||||||
import { useThemeColors } from "@/lib/theme"
|
import { useThemeColors } from "@/lib/theme"
|
||||||
@@ -239,9 +237,7 @@ function DownloadQualityPopup({
|
|||||||
>
|
>
|
||||||
{pending?.target.title}
|
{pending?.target.title}
|
||||||
</Text>
|
</Text>
|
||||||
{pending?.response.options
|
{pending?.response.options.map((option) => (
|
||||||
.filter((option) => downloadQualitySupported(option.quality))
|
|
||||||
.map((option) => (
|
|
||||||
<Pressable
|
<Pressable
|
||||||
key={option.quality}
|
key={option.quality}
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
@@ -257,21 +253,15 @@ function DownloadQualityPopup({
|
|||||||
backgroundColor={colors.card}
|
backgroundColor={colors.card}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Text
|
<Text style={[styles.label, { color: colors.foreground }]}>
|
||||||
style={[styles.label, { color: colors.foreground }]}
|
|
||||||
>
|
|
||||||
{DOWNLOAD_QUALITY_LABELS[option.quality]}
|
{DOWNLOAD_QUALITY_LABELS[option.quality]}
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
<Text
|
<Text style={{ color: colors.mutedForeground, fontSize: 12 }}>
|
||||||
style={{ color: colors.mutedForeground, fontSize: 12 }}
|
|
||||||
>
|
|
||||||
{optionDetail(option, songCount)}
|
{optionDetail(option, songCount)}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
<Text
|
<Text style={[styles.size, { color: colors.mutedForeground }]}>
|
||||||
style={[styles.size, { color: colors.mutedForeground }]}
|
|
||||||
>
|
|
||||||
{option.estimated ? "~" : ""}
|
{option.estimated ? "~" : ""}
|
||||||
{formatBytes(option.bytes)}
|
{formatBytes(option.bytes)}
|
||||||
</Text>
|
</Text>
|
||||||
@@ -354,7 +344,6 @@ export function DownloadsProvider({ children }: { children: ReactNode }) {
|
|||||||
target: DownloadTarget
|
target: DownloadTarget
|
||||||
response: DownloadOptionsResponse
|
response: DownloadOptionsResponse
|
||||||
} | null>(null)
|
} | null>(null)
|
||||||
const keepDownloading = useBackgroundDownloads(queue)
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!queue) return
|
if (!queue) return
|
||||||
@@ -402,7 +391,6 @@ export function DownloadsProvider({ children }: { children: ReactNode }) {
|
|||||||
const remembered = await readRememberedDownloadQuality()
|
const remembered = await readRememberedDownloadQuality()
|
||||||
if (remembered) {
|
if (remembered) {
|
||||||
await startDownload(queue, target, response.songs, remembered)
|
await startDownload(queue, target, response.songs, remembered)
|
||||||
keepDownloading()
|
|
||||||
toast(`Downloading ${target.title}`)
|
toast(`Downloading ${target.title}`)
|
||||||
} else {
|
} else {
|
||||||
setPending({ target, response })
|
setPending({ target, response })
|
||||||
@@ -411,7 +399,7 @@ export function DownloadsProvider({ children }: { children: ReactNode }) {
|
|||||||
showError(error instanceof Error ? error.message : "Download failed")
|
showError(error instanceof Error ? error.message : "Download failed")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[cacheScope, config, convex, keepDownloading, queue]
|
[cacheScope, config, convex, queue]
|
||||||
)
|
)
|
||||||
|
|
||||||
const removeDownload = useCallback(
|
const removeDownload = useCallback(
|
||||||
@@ -429,14 +417,9 @@ export function DownloadsProvider({ children }: { children: ReactNode }) {
|
|||||||
if (!pending || !queue) return
|
if (!pending || !queue) return
|
||||||
setPending(null)
|
setPending(null)
|
||||||
if (remember) void writeRememberedDownloadQuality(quality)
|
if (remember) void writeRememberedDownloadQuality(quality)
|
||||||
void startDownload(
|
void startDownload(queue, pending.target, pending.response.songs, quality)
|
||||||
queue,
|
|
||||||
pending.target,
|
|
||||||
pending.response.songs,
|
|
||||||
quality
|
|
||||||
).then(keepDownloading)
|
|
||||||
},
|
},
|
||||||
[keepDownloading, pending, queue]
|
[pending, queue]
|
||||||
)
|
)
|
||||||
|
|
||||||
const value = useMemo(
|
const value = useMemo(
|
||||||
|
|||||||
@@ -9,13 +9,15 @@
|
|||||||
"APP_VARIANT": "development"
|
"APP_VARIANT": "development"
|
||||||
},
|
},
|
||||||
"developmentClient": true,
|
"developmentClient": true,
|
||||||
"distribution": "internal"
|
"distribution": "internal",
|
||||||
|
"credentialsSource": "local"
|
||||||
},
|
},
|
||||||
"preview": {
|
"preview": {
|
||||||
"env": {
|
"env": {
|
||||||
"APP_VARIANT": "preview"
|
"APP_VARIANT": "preview"
|
||||||
},
|
},
|
||||||
"distribution": "internal"
|
"distribution": "internal",
|
||||||
|
"credentialsSource": "local"
|
||||||
},
|
},
|
||||||
"production": {
|
"production": {
|
||||||
"env": {
|
"env": {
|
||||||
|
|||||||
@@ -1,164 +0,0 @@
|
|||||||
import { requireOptionalNativeModule } from "expo"
|
|
||||||
import Constants from "expo-constants"
|
|
||||||
import { useCallback, useEffect, useRef } from "react"
|
|
||||||
import { AppState, Platform } from "react-native"
|
|
||||||
import {
|
|
||||||
ContinuedTasks,
|
|
||||||
type ContinuedTask,
|
|
||||||
} from "react-native-continued-task"
|
|
||||||
|
|
||||||
import { setKeptRunning } from "@/lib/downloads"
|
|
||||||
import type { DownloadQueue } from "@otunes/convex/client/download-queue"
|
|
||||||
|
|
||||||
const downloadService = requireOptionalNativeModule<{
|
|
||||||
update: (remaining: number) => void
|
|
||||||
}>("DownloadService")
|
|
||||||
|
|
||||||
/** Songs downloading at once while the app runs, as the queue defaults to. */
|
|
||||||
const RUNNING_CONCURRENCY = 2
|
|
||||||
|
|
||||||
// Stopping right after starting can beat the service to `startForeground`,
|
|
||||||
// which Android treats as a crash.
|
|
||||||
const STOP_DELAY_MS = 2000
|
|
||||||
|
|
||||||
// Must match `identifierPrefixes` in app.config.ts.
|
|
||||||
const TASK_PREFIX = `${Constants.expoConfig?.ios?.bundleIdentifier}.downloads`
|
|
||||||
|
|
||||||
function songsLeft(count: number) {
|
|
||||||
return count === 1 ? "1 song left" : `${count} songs left`
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Keeps downloads going while the app is in the background. Call the returned
|
|
||||||
* function right after the person starts a download.
|
|
||||||
*
|
|
||||||
* iOS 26+: a continued processing task keeps the app running, with progress
|
|
||||||
* in a Live Activity, so songs keep downloading a few at a time with fresh
|
|
||||||
* sign-in tokens. It must start from the person's action, so it covers
|
|
||||||
* downloads they start, not playlist syncs.
|
|
||||||
*
|
|
||||||
* iOS otherwise (and once that task ends): songs download in a background URL
|
|
||||||
* session. Songs started while suspended may wait for Wi-Fi and power, so
|
|
||||||
* every waiting song is handed over as the app leaves the screen.
|
|
||||||
*
|
|
||||||
* Android: a foreground service keeps the app running while songs are queued.
|
|
||||||
*/
|
|
||||||
export function useBackgroundDownloads(queue: DownloadQueue | null) {
|
|
||||||
const startTask = useRef<() => void>(() => {})
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!queue) return
|
|
||||||
|
|
||||||
if (Platform.OS === "ios") {
|
|
||||||
let active = AppState.currentState === "active"
|
|
||||||
let task: ContinuedTask | null = null
|
|
||||||
let submitting = false
|
|
||||||
let total = 0
|
|
||||||
let lastPending = 0
|
|
||||||
|
|
||||||
const updateConcurrency = () =>
|
|
||||||
queue.setConcurrency(
|
|
||||||
active || task?.state === "running" ? RUNNING_CONCURRENCY : Infinity
|
|
||||||
)
|
|
||||||
|
|
||||||
const end = () => {
|
|
||||||
task = null
|
|
||||||
setKeptRunning(false)
|
|
||||||
updateConcurrency()
|
|
||||||
}
|
|
||||||
|
|
||||||
const report = () => {
|
|
||||||
const pending = queue.pendingCount()
|
|
||||||
if (pending > lastPending) total += pending - lastPending
|
|
||||||
lastPending = pending
|
|
||||||
if (task?.state !== "running") return
|
|
||||||
if (pending === 0) {
|
|
||||||
task.complete(true)
|
|
||||||
end()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
task.setProgress(total - pending, total)
|
|
||||||
task.updateTitle("Downloading", songsLeft(pending))
|
|
||||||
}
|
|
||||||
|
|
||||||
startTask.current = () => {
|
|
||||||
if (!ContinuedTasks.isSupported || task || submitting) return
|
|
||||||
const pending = queue.pendingCount()
|
|
||||||
if (pending === 0) return
|
|
||||||
submitting = true
|
|
||||||
total = pending
|
|
||||||
lastPending = pending
|
|
||||||
ContinuedTasks.submit({
|
|
||||||
identifierPrefix: TASK_PREFIX,
|
|
||||||
title: "Downloading",
|
|
||||||
subtitle: songsLeft(pending),
|
|
||||||
totalUnitCount: total,
|
|
||||||
// A task that cannot start now is no use once the app is closed.
|
|
||||||
ios: { submissionStrategy: "fail" },
|
|
||||||
})
|
|
||||||
.then((submitted) => {
|
|
||||||
task = submitted
|
|
||||||
submitted.addOnStartListener(() => {
|
|
||||||
setKeptRunning(true)
|
|
||||||
updateConcurrency()
|
|
||||||
report()
|
|
||||||
})
|
|
||||||
// iOS reports a cancel from the Live Activity as expiry too, so
|
|
||||||
// either way the songs carry on in the background session.
|
|
||||||
submitted.addOnStopListener(() => {
|
|
||||||
if (task === submitted) end()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
// Not permitted or unavailable: the background session covers it.
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
submitting = false
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
updateConcurrency()
|
|
||||||
const unsubscribe = queue.subscribe(report)
|
|
||||||
const subscription = AppState.addEventListener("change", (state) => {
|
|
||||||
active = state === "active"
|
|
||||||
updateConcurrency()
|
|
||||||
})
|
|
||||||
return () => {
|
|
||||||
startTask.current = () => {}
|
|
||||||
unsubscribe()
|
|
||||||
subscription.remove()
|
|
||||||
task?.cancel()
|
|
||||||
end()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!downloadService) return
|
|
||||||
const service = downloadService
|
|
||||||
let shown = 0
|
|
||||||
let stopTimer: ReturnType<typeof setTimeout> | null = null
|
|
||||||
const update = () => {
|
|
||||||
const remaining = queue.pendingCount()
|
|
||||||
if (remaining === shown) return
|
|
||||||
if (stopTimer) clearTimeout(stopTimer)
|
|
||||||
stopTimer = null
|
|
||||||
if (remaining > 0) {
|
|
||||||
shown = remaining
|
|
||||||
service.update(remaining)
|
|
||||||
} else {
|
|
||||||
stopTimer = setTimeout(() => {
|
|
||||||
shown = 0
|
|
||||||
service.update(0)
|
|
||||||
}, STOP_DELAY_MS)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
update()
|
|
||||||
const unsubscribe = queue.subscribe(update)
|
|
||||||
return () => {
|
|
||||||
unsubscribe()
|
|
||||||
if (stopTimer) clearTimeout(stopTimer)
|
|
||||||
service.update(0)
|
|
||||||
}
|
|
||||||
}, [queue])
|
|
||||||
|
|
||||||
return useCallback(() => startTask.current(), [])
|
|
||||||
}
|
|
||||||
@@ -1,18 +1,5 @@
|
|||||||
import { File } from "expo-file-system"
|
import { File } from "expo-file-system"
|
||||||
import {
|
import { useEffect, useMemo, useState, useSyncExternalStore } from "react"
|
||||||
useEffect,
|
|
||||||
useMemo,
|
|
||||||
useRef,
|
|
||||||
useState,
|
|
||||||
useSyncExternalStore,
|
|
||||||
} from "react"
|
|
||||||
import {
|
|
||||||
cancelAnimation,
|
|
||||||
Easing,
|
|
||||||
useSharedValue,
|
|
||||||
withSequence,
|
|
||||||
withTiming,
|
|
||||||
} from "react-native-reanimated"
|
|
||||||
|
|
||||||
import { api } from "@otunes/convex/_generated/api"
|
import { api } from "@otunes/convex/_generated/api"
|
||||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||||
@@ -120,39 +107,3 @@ export function useLyricsTime(
|
|||||||
? advanced.time
|
? advanced.time
|
||||||
: currentTime
|
: currentTime
|
||||||
}
|
}
|
||||||
|
|
||||||
/** How far the clock may drift from the player before it is reset. */
|
|
||||||
const CLOCK_DRIFT_SECONDS = 0.15
|
|
||||||
/** How far ahead the clock runs on its own; progress updates come long before. */
|
|
||||||
const CLOCK_RUN_SECONDS = 3600
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Playback time in seconds on the UI thread, running smoothly between the
|
|
||||||
* player's progress updates. It is reset only when it drifts, so animations
|
|
||||||
* driven by it never restart mid-word.
|
|
||||||
*/
|
|
||||||
export function usePlaybackClock(currentTime: number, isPlaying: boolean) {
|
|
||||||
const clock = useSharedValue(currentTime)
|
|
||||||
const running = useRef(false)
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!isPlaying) {
|
|
||||||
running.current = false
|
|
||||||
cancelAnimation(clock)
|
|
||||||
clock.value = currentTime
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const drift = Math.abs(clock.value - currentTime)
|
|
||||||
if (running.current && drift < CLOCK_DRIFT_SECONDS) return
|
|
||||||
running.current = true
|
|
||||||
clock.value = withSequence(
|
|
||||||
withTiming(currentTime, { duration: 0 }),
|
|
||||||
withTiming(currentTime + CLOCK_RUN_SECONDS, {
|
|
||||||
duration: CLOCK_RUN_SECONDS * 1000,
|
|
||||||
easing: Easing.linear,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}, [clock, currentTime, isPlaying])
|
|
||||||
|
|
||||||
return clock
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useRouter, useSegments, type Href } from "expo-router"
|
import { useRouter, useSegments, type Href } from "expo-router"
|
||||||
import { createContext, use, useCallback } from "react"
|
import { useCallback } from "react"
|
||||||
|
|
||||||
import { tabletSections } from "@/lib/tablet-navigation"
|
import { tabletSections } from "@/lib/tablet-navigation"
|
||||||
|
|
||||||
@@ -30,13 +30,6 @@ export function tabPath(tab: AppTab, path: string): Href {
|
|||||||
return `/(app)/(tabs)/${tab}${normalized}` as Href
|
return `/(app)/(tabs)/${tab}${normalized}` as Href
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The tab whose stack a screen lives in. Each tab stack layout provides it so
|
|
||||||
* links resolve against the screen's own tab, even when the global segments
|
|
||||||
* ref has not caught up with a tab switch yet.
|
|
||||||
*/
|
|
||||||
export const TabStackContext = createContext<AppTab | undefined>(undefined)
|
|
||||||
|
|
||||||
function getActiveTabFromRef(): AppTab {
|
function getActiveTabFromRef(): AppTab {
|
||||||
return getActiveTab(activeSegmentsRef.current)
|
return getActiveTab(activeSegmentsRef.current)
|
||||||
}
|
}
|
||||||
@@ -48,15 +41,8 @@ export function AppNavigationSync() {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Tab-aware navigation: paths resolve inside the caller's tab stack, falling back to the active tab outside one. */
|
|
||||||
export function useAppNavigation() {
|
export function useAppNavigation() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const stackTab = use(TabStackContext)
|
|
||||||
|
|
||||||
const currentTab = useCallback(
|
|
||||||
() => stackTab ?? getActiveTabFromRef(),
|
|
||||||
[stackTab]
|
|
||||||
)
|
|
||||||
|
|
||||||
const push = useCallback(
|
const push = useCallback(
|
||||||
(path: string) => {
|
(path: string) => {
|
||||||
@@ -67,26 +53,26 @@ export function useAppNavigation() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
router.push(tabPath(currentTab(), path))
|
router.push(tabPath(getActiveTabFromRef(), path))
|
||||||
},
|
},
|
||||||
[router, currentTab]
|
[router]
|
||||||
)
|
)
|
||||||
|
|
||||||
const replace = useCallback(
|
const replace = useCallback(
|
||||||
(path: string) => {
|
(path: string) => {
|
||||||
router.replace(tabPath(currentTab(), path))
|
router.replace(tabPath(getActiveTabFromRef(), path))
|
||||||
},
|
},
|
||||||
[router, currentTab]
|
[router]
|
||||||
)
|
)
|
||||||
|
|
||||||
const href = useCallback(
|
const href = useCallback(
|
||||||
(path: string) => tabPath(currentTab(), path),
|
(path: string) => tabPath(getActiveTabFromRef(), path),
|
||||||
[currentTab]
|
[]
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
get tab() {
|
get tab() {
|
||||||
return currentTab()
|
return getActiveTabFromRef()
|
||||||
},
|
},
|
||||||
href,
|
href,
|
||||||
push,
|
push,
|
||||||
|
|||||||
@@ -16,16 +16,9 @@ function authCookieNames(serverUrl: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Cookies that sign a request to the server in. Pass `refresh: false` for
|
|
||||||
* requests that may run after the JWT expires (iOS background downloads): the
|
|
||||||
* server would spend the refresh token, and the app's next refresh of the same
|
|
||||||
* token would then end the session.
|
|
||||||
*/
|
|
||||||
export async function getAuthCookieHeader(
|
export async function getAuthCookieHeader(
|
||||||
serverUrl: string,
|
serverUrl: string,
|
||||||
convexUrl: string,
|
convexUrl: string
|
||||||
{ refresh = true }: { refresh?: boolean } = {}
|
|
||||||
): Promise<string | null> {
|
): Promise<string | null> {
|
||||||
const [jwt, refreshToken] = await Promise.all([
|
const [jwt, refreshToken] = await Promise.all([
|
||||||
secureGetItem(authStorageKey(JWT_STORAGE_KEY, convexUrl)),
|
secureGetItem(authStorageKey(JWT_STORAGE_KEY, convexUrl)),
|
||||||
@@ -38,7 +31,7 @@ export async function getAuthCookieHeader(
|
|||||||
|
|
||||||
const names = authCookieNames(serverUrl)
|
const names = authCookieNames(serverUrl)
|
||||||
const parts = [`${names.jwt}=${jwt}`]
|
const parts = [`${names.jwt}=${jwt}`]
|
||||||
if (refresh && refreshToken) {
|
if (refreshToken) {
|
||||||
parts.push(`${names.refresh}=${refreshToken}`)
|
parts.push(`${names.refresh}=${refreshToken}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,28 +12,19 @@ const secureStoreOptions: SecureStore.SecureStoreOptions = {
|
|||||||
keychainAccessible: SecureStore.AFTER_FIRST_UNLOCK,
|
keychainAccessible: SecureStore.AFTER_FIRST_UNLOCK,
|
||||||
}
|
}
|
||||||
|
|
||||||
// The last value read or written per key, for when the keychain refuses a
|
|
||||||
// read (say, while the phone is locked and downloads continue).
|
|
||||||
const remembered = new Map<string, string>()
|
|
||||||
|
|
||||||
export async function secureGetItem(key: string): Promise<string | null> {
|
export async function secureGetItem(key: string): Promise<string | null> {
|
||||||
try {
|
try {
|
||||||
const value = await SecureStore.getItemAsync(key, secureStoreOptions)
|
return await SecureStore.getItemAsync(key, secureStoreOptions)
|
||||||
if (value === null) remembered.delete(key)
|
|
||||||
else remembered.set(key, value)
|
|
||||||
return value
|
|
||||||
} catch {
|
} catch {
|
||||||
return remembered.get(key) ?? null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function secureSetItem(key: string, value: string): Promise<void> {
|
export async function secureSetItem(key: string, value: string): Promise<void> {
|
||||||
remembered.set(key, value)
|
|
||||||
await SecureStore.setItemAsync(key, value, secureStoreOptions)
|
await SecureStore.setItemAsync(key, value, secureStoreOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function secureRemoveItem(key: string): Promise<void> {
|
export async function secureRemoveItem(key: string): Promise<void> {
|
||||||
remembered.delete(key)
|
|
||||||
try {
|
try {
|
||||||
await SecureStore.deleteItemAsync(key, secureStoreOptions)
|
await SecureStore.deleteItemAsync(key, secureStoreOptions)
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import AsyncStorage from "@react-native-async-storage/async-storage"
|
import AsyncStorage from "@react-native-async-storage/async-storage"
|
||||||
import { Directory, DownloadTask, File, Paths } from "expo-file-system"
|
import { Directory, File, Paths } from "expo-file-system"
|
||||||
import { Platform } from "react-native"
|
import { Platform } from "react-native"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -16,7 +16,6 @@ import {
|
|||||||
type DownloadQuality,
|
type DownloadQuality,
|
||||||
} from "@otunes/convex/download-quality"
|
} from "@otunes/convex/download-quality"
|
||||||
import { getAuthCookieHeader } from "@/lib/auth-cookies"
|
import { getAuthCookieHeader } from "@/lib/auth-cookies"
|
||||||
import { downloadQualitySupported } from "@/lib/playback-capabilities"
|
|
||||||
import type { ServerConfig } from "@/lib/server-config"
|
import type { ServerConfig } from "@/lib/server-config"
|
||||||
|
|
||||||
const REMEMBERED_QUALITY_KEY = "otunes.download-quality"
|
const REMEMBERED_QUALITY_KEY = "otunes.download-quality"
|
||||||
@@ -74,82 +73,6 @@ function audioFile(folder: Directory) {
|
|||||||
return folder.list().find((entry): entry is File => entry instanceof File)
|
return folder.list().find((entry): entry is File => entry instanceof File)
|
||||||
}
|
}
|
||||||
|
|
||||||
type SongDownload = {
|
|
||||||
url: string
|
|
||||||
destination: Directory
|
|
||||||
headers: Record<string, string>
|
|
||||||
signal: AbortSignal
|
|
||||||
/** Checks and keeps the downloaded file, returning its size. */
|
|
||||||
finish: (file: File) => number
|
|
||||||
}
|
|
||||||
|
|
||||||
// Whether a continued processing task keeps the app running in the
|
|
||||||
// background (iOS 26+, see `useBackgroundDownloads`).
|
|
||||||
let keptRunning = false
|
|
||||||
const regularSessionDownloads = new Set<() => void>()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* While a continued task keeps the app running, songs download through the
|
|
||||||
* regular session: iOS treats background session downloads started from the
|
|
||||||
* background as deferrable until Wi-Fi and power. When the task ends, running
|
|
||||||
* songs restart in the background session before iOS suspends the app.
|
|
||||||
*/
|
|
||||||
export function setKeptRunning(running: boolean) {
|
|
||||||
keptRunning = running
|
|
||||||
if (!running) for (const handOff of regularSessionDownloads) handOff()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Downloads through an iOS URL session. The background one keeps going while
|
|
||||||
* the app is suspended and wakes it when done; iOS keeps the app awake until
|
|
||||||
* `finish` returns (up to 25 seconds). Downloads still running when iOS
|
|
||||||
* terminates the app are lost.
|
|
||||||
*/
|
|
||||||
async function runDownloadTask(
|
|
||||||
{ url, destination, headers, signal, finish }: SongDownload,
|
|
||||||
sessionType: "foreground" | "background"
|
|
||||||
) {
|
|
||||||
const task = new DownloadTask(url, destination, {
|
|
||||||
headers,
|
|
||||||
signal,
|
|
||||||
sessionType,
|
|
||||||
deferBackgroundSessionCompletion: sessionType === "background",
|
|
||||||
})
|
|
||||||
const handOff = () => task.cancel()
|
|
||||||
if (sessionType === "foreground") regularSessionDownloads.add(handOff)
|
|
||||||
try {
|
|
||||||
const file = await task.downloadAsync()
|
|
||||||
if (!file) throw new Error("Download paused")
|
|
||||||
return finish(file)
|
|
||||||
} finally {
|
|
||||||
regularSessionDownloads.delete(handOff)
|
|
||||||
if (task.state === "completed") {
|
|
||||||
await task.acknowledgeBackgroundCompletionAsync().catch(() => {})
|
|
||||||
}
|
|
||||||
task.release()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function downloadOnIOS(download: SongDownload) {
|
|
||||||
if (keptRunning) {
|
|
||||||
try {
|
|
||||||
return await runDownloadTask(download, "foreground")
|
|
||||||
} catch (error) {
|
|
||||||
// Still running means a real failure; otherwise it was handed off.
|
|
||||||
if (keptRunning || download.signal.aborted) throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return runDownloadTask(download, "background")
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Android keeps the app running with a foreground service instead. */
|
|
||||||
async function downloadInForeground(download: SongDownload) {
|
|
||||||
const { url, destination, headers, signal, finish } = download
|
|
||||||
return finish(
|
|
||||||
await File.downloadFileAsync(url, destination, { headers, signal })
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function createStorage(config: ServerConfig): DownloadStorage {
|
function createStorage(config: ServerConfig): DownloadStorage {
|
||||||
const root = serverDirectory(config)
|
const root = serverDirectory(config)
|
||||||
const indexFile = new File(root, "index.json")
|
const indexFile = new File(root, "index.json")
|
||||||
@@ -193,8 +116,7 @@ function createStorage(config: ServerConfig): DownloadStorage {
|
|||||||
async save({ songId, requested, quality, albumId }, signal) {
|
async save({ songId, requested, quality, albumId }, signal) {
|
||||||
const cookieHeader = await getAuthCookieHeader(
|
const cookieHeader = await getAuthCookieHeader(
|
||||||
config.serverUrl,
|
config.serverUrl,
|
||||||
config.convexUrl,
|
config.convexUrl
|
||||||
{ refresh: Platform.OS !== "ios" }
|
|
||||||
)
|
)
|
||||||
if (!cookieHeader) throw new Error("Sign in to download")
|
if (!cookieHeader) throw new Error("Sign in to download")
|
||||||
|
|
||||||
@@ -204,26 +126,17 @@ function createStorage(config: ServerConfig): DownloadStorage {
|
|||||||
if (partial.exists) partial.delete()
|
if (partial.exists) partial.delete()
|
||||||
partial.create()
|
partial.create()
|
||||||
try {
|
try {
|
||||||
const url = `${config.serverUrl}${songDownloadPath(songId, requested, {
|
const path = songDownloadPath(songId, requested, {
|
||||||
losslessFormat: Platform.OS === "ios" ? "alac" : undefined,
|
losslessFormat: Platform.OS === "ios" ? "alac" : undefined,
|
||||||
})}`
|
})
|
||||||
const download =
|
const file = await File.downloadFileAsync(
|
||||||
Platform.OS === "ios" ? downloadOnIOS : downloadInForeground
|
`${config.serverUrl}${path}`,
|
||||||
return await download({
|
partial,
|
||||||
url,
|
{ headers: { Cookie: cookieHeader }, signal }
|
||||||
destination: partial,
|
)
|
||||||
headers: { Cookie: cookieHeader },
|
|
||||||
signal,
|
|
||||||
finish(file) {
|
|
||||||
signal.throwIfAborted()
|
signal.throwIfAborted()
|
||||||
// A lapsed sign-in redirects to the sign-in page instead of failing.
|
|
||||||
if (file.extension === ".html") {
|
|
||||||
throw new Error("Sign in to download")
|
|
||||||
}
|
|
||||||
partial.rename(name)
|
partial.rename(name)
|
||||||
return file.size ?? 0
|
return file.size ?? 0
|
||||||
},
|
|
||||||
})
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (partial.exists) partial.delete()
|
if (partial.exists) partial.delete()
|
||||||
throw error
|
throw error
|
||||||
@@ -299,10 +212,9 @@ export function downloadedCoverUri(url: string) {
|
|||||||
|
|
||||||
export async function readRememberedDownloadQuality() {
|
export async function readRememberedDownloadQuality() {
|
||||||
try {
|
try {
|
||||||
const quality = parseDownloadQuality(
|
return parseDownloadQuality(
|
||||||
await AsyncStorage.getItem(REMEMBERED_QUALITY_KEY)
|
await AsyncStorage.getItem(REMEMBERED_QUALITY_KEY)
|
||||||
)
|
)
|
||||||
return quality && downloadQualitySupported(quality) ? quality : undefined
|
|
||||||
} catch {
|
} catch {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,13 +17,20 @@ export const tabStackScreenTitles: Record<string, string> = {
|
|||||||
"downloads/other": "Other Downloaded Songs",
|
"downloads/other": "Other Downloaded Songs",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* iOS tab stacks render their titles in the scroll content with
|
||||||
|
* `ScreenTitle`, so the bar keeps the title (for back menus) but hides it.
|
||||||
|
*/
|
||||||
|
export const inlineTitleOptions: StackScreenOptions =
|
||||||
|
Platform.OS === "ios" ? { headerTitleStyle: { color: "transparent" } } : {}
|
||||||
|
|
||||||
export function useStackScreenOptions(
|
export function useStackScreenOptions(
|
||||||
overrides?: StackScreenOptions
|
overrides?: StackScreenOptions
|
||||||
): StackScreenOptions {
|
): StackScreenOptions {
|
||||||
const theme = useThemeColors()
|
const theme = useThemeColors()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
headerLargeTitle: true,
|
headerLargeTitle: false,
|
||||||
headerTransparent: true,
|
headerTransparent: true,
|
||||||
headerTintColor: theme.foreground,
|
headerTintColor: theme.foreground,
|
||||||
headerLargeTitleStyle: { color: theme.foreground },
|
headerLargeTitleStyle: { color: theme.foreground },
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ export type NowPlayingColors = {
|
|||||||
selected: string
|
selected: string
|
||||||
selectedForeground: string
|
selectedForeground: string
|
||||||
highlight: string
|
highlight: string
|
||||||
|
/** Lyrics lines other than the one playing. */
|
||||||
|
lyricsInactive: string
|
||||||
/** Words of the playing line not yet sung. */
|
/** Words of the playing line not yet sung. */
|
||||||
lyricsUnsung: string
|
lyricsUnsung: string
|
||||||
isDark: boolean
|
isDark: boolean
|
||||||
@@ -30,6 +32,7 @@ export function nowPlayingColors(palette: CoverPalette): NowPlayingColors {
|
|||||||
selected: withAlpha(foreground, 0.8),
|
selected: withAlpha(foreground, 0.8),
|
||||||
selectedForeground: palette.background,
|
selectedForeground: palette.background,
|
||||||
highlight: withAlpha(foreground, 0.1),
|
highlight: withAlpha(foreground, 0.1),
|
||||||
|
lyricsInactive: withAlpha(foreground, 0.35),
|
||||||
lyricsUnsung: withAlpha(foreground, 0.55),
|
lyricsUnsung: withAlpha(foreground, 0.55),
|
||||||
isDark: palette.isDark,
|
isDark: palette.isDark,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
import { Platform } from "react-native"
|
import { Platform } from "react-native"
|
||||||
|
|
||||||
import {
|
|
||||||
DOWNLOAD_QUALITIES,
|
|
||||||
type DownloadQuality,
|
|
||||||
} from "@otunes/convex/download-quality"
|
|
||||||
|
|
||||||
// Android Dolby decoder reports do not reliably indicate working Atmos playback.
|
// Android Dolby decoder reports do not reliably indicate working Atmos playback.
|
||||||
export const dolbyAtmosSupported = Platform.OS === "ios"
|
export const dolbyAtmosSupported = Platform.OS === "ios"
|
||||||
|
|
||||||
@@ -12,13 +7,3 @@ export const dolbyAtmosSupported = Platform.OS === "ios"
|
|||||||
export function atmosEnabled(user: { preferAtmos?: boolean }) {
|
export function atmosEnabled(user: { preferAtmos?: boolean }) {
|
||||||
return dolbyAtmosSupported && (user.preferAtmos ?? false)
|
return dolbyAtmosSupported && (user.preferAtmos ?? false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Whether this device may download in a quality. Android cannot download Atmos. */
|
|
||||||
export function downloadQualitySupported(quality: DownloadQuality) {
|
|
||||||
return quality !== "atmos" || dolbyAtmosSupported
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Download qualities this device offers, lowest first. */
|
|
||||||
export const deviceDownloadQualities = DOWNLOAD_QUALITIES.filter(
|
|
||||||
downloadQualitySupported
|
|
||||||
)
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id 'com.android.library'
|
|
||||||
id 'expo-module-gradle-plugin'
|
|
||||||
}
|
|
||||||
|
|
||||||
group = 'expo.modules.downloadservice'
|
|
||||||
version = '1.0.0'
|
|
||||||
|
|
||||||
android {
|
|
||||||
namespace 'expo.modules.downloadservice'
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
|
|
||||||
|
|
||||||
<application>
|
|
||||||
<service
|
|
||||||
android:name="expo.modules.downloadservice.DownloadService"
|
|
||||||
android:exported="false"
|
|
||||||
android:foregroundServiceType="dataSync" />
|
|
||||||
</application>
|
|
||||||
</manifest>
|
|
||||||
-88
@@ -1,88 +0,0 @@
|
|||||||
package expo.modules.downloadservice
|
|
||||||
|
|
||||||
import android.app.Notification
|
|
||||||
import android.app.NotificationChannel
|
|
||||||
import android.app.NotificationManager
|
|
||||||
import android.app.PendingIntent
|
|
||||||
import android.app.Service
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
|
||||||
import android.content.pm.ServiceInfo
|
|
||||||
import android.os.Build
|
|
||||||
import android.os.IBinder
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Keeps the app running while songs download, so Android does not freeze the
|
|
||||||
* JS downloads when the app leaves the screen. Started with the number of
|
|
||||||
* songs left, and stopped by the module once none are.
|
|
||||||
*/
|
|
||||||
class DownloadService : Service() {
|
|
||||||
override fun onBind(intent: Intent?): IBinder? = null
|
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
|
||||||
val remaining = intent?.getIntExtra(EXTRA_REMAINING, 0) ?: 0
|
|
||||||
val notification = notification(remaining)
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
startForeground(NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
|
|
||||||
} else {
|
|
||||||
startForeground(NOTIFICATION_ID, notification)
|
|
||||||
}
|
|
||||||
// A restarted service would have no downloads to keep alive.
|
|
||||||
return START_NOT_STICKY
|
|
||||||
}
|
|
||||||
|
|
||||||
// Android 15 limits data sync services to six hours a day.
|
|
||||||
override fun onTimeout(startId: Int, fgsType: Int) {
|
|
||||||
stopSelf()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun notification(remaining: Int): Notification {
|
|
||||||
val manager = getSystemService(NotificationManager::class.java)
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
manager.createNotificationChannel(
|
|
||||||
NotificationChannel(CHANNEL_ID, "Downloads", NotificationManager.IMPORTANCE_LOW)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
val builder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
Notification.Builder(this, CHANNEL_ID)
|
|
||||||
} else {
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
Notification.Builder(this)
|
|
||||||
}
|
|
||||||
val launch = packageManager.getLaunchIntentForPackage(packageName)?.let {
|
|
||||||
PendingIntent.getActivity(this, 0, it, PendingIntent.FLAG_IMMUTABLE)
|
|
||||||
}
|
|
||||||
return builder
|
|
||||||
.setSmallIcon(android.R.drawable.stat_sys_download)
|
|
||||||
.setContentTitle(if (remaining == 1) "Downloading 1 song" else "Downloading $remaining songs")
|
|
||||||
.setContentIntent(launch)
|
|
||||||
.setOngoing(true)
|
|
||||||
.setOnlyAlertOnce(true)
|
|
||||||
.build()
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val CHANNEL_ID = "downloads"
|
|
||||||
private const val NOTIFICATION_ID = 7301
|
|
||||||
private const val EXTRA_REMAINING = "remaining"
|
|
||||||
|
|
||||||
fun update(context: Context, remaining: Int) {
|
|
||||||
val intent = Intent(context, DownloadService::class.java)
|
|
||||||
if (remaining == 0) {
|
|
||||||
context.stopService(intent)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
intent.putExtra(EXTRA_REMAINING, remaining)
|
|
||||||
try {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
context.startForegroundService(intent)
|
|
||||||
} else {
|
|
||||||
context.startService(intent)
|
|
||||||
}
|
|
||||||
} catch (_: IllegalStateException) {
|
|
||||||
// Android 12+ refuses to start one from the background (say, a
|
|
||||||
// playlist syncing); downloads then run only while the app does.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-15
@@ -1,15 +0,0 @@
|
|||||||
package expo.modules.downloadservice
|
|
||||||
|
|
||||||
import expo.modules.kotlin.modules.Module
|
|
||||||
import expo.modules.kotlin.modules.ModuleDefinition
|
|
||||||
|
|
||||||
class DownloadServiceModule : Module() {
|
|
||||||
override fun definition() = ModuleDefinition {
|
|
||||||
Name("DownloadService")
|
|
||||||
|
|
||||||
/** Shows how many songs are left, or stops the service at zero. */
|
|
||||||
Function("update") { remaining: Int ->
|
|
||||||
DownloadService.update(requireNotNull(appContext.reactContext), remaining)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"platforms": ["android"],
|
|
||||||
"android": {
|
|
||||||
"modules": ["expo.modules.downloadservice.DownloadServiceModule"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "otunes-download-service",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"private": true
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"platforms": ["apple"]
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
// React Native draws `filter: [{ blur }]` on iOS only with its SwiftUI
|
|
||||||
// filters flag, which the stable release leaves off. This keeps the stable
|
|
||||||
// flags and turns that one on.
|
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
#import <react/featureflags/ReactNativeFeatureFlags.h>
|
|
||||||
#import <react/featureflags/ReactNativeFeatureFlagsOverridesOSSStable.h>
|
|
||||||
|
|
||||||
using namespace facebook::react;
|
|
||||||
|
|
||||||
class SwiftUIFilterFlags : public ReactNativeFeatureFlagsOverridesOSSStable {
|
|
||||||
public:
|
|
||||||
bool enableSwiftUIBasedFilters() override {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@interface SwiftUIFilters : NSObject
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation SwiftUIFilters
|
|
||||||
|
|
||||||
+ (void)load
|
|
||||||
{
|
|
||||||
// React Native sets its flags once while launching and throws if they were
|
|
||||||
// set first, so this waits for launch to finish. No views exist yet then.
|
|
||||||
[NSNotificationCenter.defaultCenter
|
|
||||||
addObserverForName:UIApplicationDidFinishLaunchingNotification
|
|
||||||
object:nil
|
|
||||||
queue:nil
|
|
||||||
usingBlock:^(NSNotification *notification) {
|
|
||||||
ReactNativeFeatureFlags::dangerouslyForceOverride(
|
|
||||||
std::make_unique<SwiftUIFilterFlags>());
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
Pod::Spec.new do |s|
|
|
||||||
s.name = 'SwiftUIFilters'
|
|
||||||
s.version = '1.0.0'
|
|
||||||
s.summary = 'Turns on React Native view filters like blur on iOS'
|
|
||||||
s.description = s.summary
|
|
||||||
s.license = { :type => 'MIT' }
|
|
||||||
s.author = 'oTunes'
|
|
||||||
s.homepage = 'https://otunes.abunchofknowitalls.com'
|
|
||||||
s.platforms = { :ios => '16.4' }
|
|
||||||
s.source = { :git => '' }
|
|
||||||
s.static_framework = true
|
|
||||||
install_modules_dependencies(s)
|
|
||||||
s.source_files = '**/*.{h,mm}'
|
|
||||||
end
|
|
||||||
@@ -20,7 +20,6 @@
|
|||||||
"@otunes/convex": "workspace:*",
|
"@otunes/convex": "workspace:*",
|
||||||
"@react-native-async-storage/async-storage": "2.2.0",
|
"@react-native-async-storage/async-storage": "2.2.0",
|
||||||
"@react-native-community/slider": "5.2.1",
|
"@react-native-community/slider": "5.2.1",
|
||||||
"@react-native-masked-view/masked-view": "0.3.2",
|
|
||||||
"@react-native/metro-config": "0.88.0",
|
"@react-native/metro-config": "0.88.0",
|
||||||
"convex": "^1.40.0",
|
"convex": "^1.40.0",
|
||||||
"expo": "~58.0.17",
|
"expo": "~58.0.17",
|
||||||
@@ -49,10 +48,8 @@
|
|||||||
"react": "19.3.0",
|
"react": "19.3.0",
|
||||||
"react-dom": "19.3.0",
|
"react-dom": "19.3.0",
|
||||||
"react-native": "0.88.0",
|
"react-native": "0.88.0",
|
||||||
"react-native-continued-task": "0.1.0",
|
|
||||||
"react-native-gesture-handler": "~3.3.0",
|
"react-native-gesture-handler": "~3.3.0",
|
||||||
"react-native-image-colors": "^2.6.0",
|
"react-native-image-colors": "^2.6.0",
|
||||||
"react-native-nitro-modules": "0.37.2",
|
|
||||||
"react-native-reanimated": "4.7.1",
|
"react-native-reanimated": "4.7.1",
|
||||||
"react-native-safe-area-context": "~5.10.1",
|
"react-native-safe-area-context": "~5.10.1",
|
||||||
"react-native-screens": "4.30.0",
|
"react-native-screens": "4.30.0",
|
||||||
|
|||||||
@@ -114,7 +114,6 @@ export function AlbumView({
|
|||||||
}) {
|
}) {
|
||||||
const {
|
const {
|
||||||
isSongFavorite,
|
isSongFavorite,
|
||||||
areSongsFavorite,
|
|
||||||
isAlbumFavorite,
|
isAlbumFavorite,
|
||||||
toggleSongFavorite,
|
toggleSongFavorite,
|
||||||
toggleAlbumFavorite,
|
toggleAlbumFavorite,
|
||||||
@@ -155,7 +154,6 @@ export function AlbumView({
|
|||||||
handlePointerDown,
|
handlePointerDown,
|
||||||
prepareContextMenu,
|
prepareContextMenu,
|
||||||
} = useTrackSelection(album.tracks, validHighlightedSongId)
|
} = useTrackSelection(album.tracks, validHighlightedSongId)
|
||||||
const selectionFavorited = areSongsFavorite(selectedIds)
|
|
||||||
|
|
||||||
const selectionPositions = React.useMemo(
|
const selectionPositions = React.useMemo(
|
||||||
() =>
|
() =>
|
||||||
@@ -415,7 +413,6 @@ export function AlbumView({
|
|||||||
isFavorite={isSongFavorite(track.id)}
|
isFavorite={isSongFavorite(track.id)}
|
||||||
selectedCount={selectedCount}
|
selectedCount={selectedCount}
|
||||||
selectionStationArtistId={album.artist.id}
|
selectionStationArtistId={album.artist.id}
|
||||||
selectionFavorited={selectionFavorited}
|
|
||||||
isNowPlaying={currentSongId === track.id}
|
isNowPlaying={currentSongId === track.id}
|
||||||
onPointerDown={handlePointerDown}
|
onPointerDown={handlePointerDown}
|
||||||
onSelect={handleRowSelect}
|
onSelect={handleRowSelect}
|
||||||
|
|||||||
@@ -39,10 +39,9 @@ const ASK_EVERY_TIME = "ask"
|
|||||||
|
|
||||||
/** Shades of the text color, darkest for the smallest files. */
|
/** Shades of the text color, darkest for the smallest files. */
|
||||||
const QUALITY_OPACITY: Record<DownloadQuality, number> = {
|
const QUALITY_OPACITY: Record<DownloadQuality, number> = {
|
||||||
low: 0.2,
|
medium: 0.25,
|
||||||
medium: 0.35,
|
high: 0.45,
|
||||||
high: 0.5,
|
lossless: 0.7,
|
||||||
lossless: 0.75,
|
|
||||||
atmos: 1,
|
atmos: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,8 +37,7 @@ type FavoritesContextValue = {
|
|||||||
) => Promise<boolean>
|
) => Promise<boolean>
|
||||||
toggleAlbumFavorite: (albumId: Id<"albums">) => Promise<void>
|
toggleAlbumFavorite: (albumId: Id<"albums">) => Promise<void>
|
||||||
toggleArtistFavorite: (artistId: Id<"artists">) => Promise<void>
|
toggleArtistFavorite: (artistId: Id<"artists">) => Promise<void>
|
||||||
/** True when `songIds` is non-empty and every song is favorited. */
|
favoriteSongs: (songIds: Id<"songs">[]) => Promise<void>
|
||||||
areSongsFavorite: (songIds: Iterable<string>) => boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const FavoritesContext = React.createContext<FavoritesContextValue | null>(null)
|
const FavoritesContext = React.createContext<FavoritesContextValue | null>(null)
|
||||||
@@ -131,16 +130,26 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
|
|||||||
[songIds, favoriteSong, unfavoriteSong]
|
[songIds, favoriteSong, unfavoriteSong]
|
||||||
)
|
)
|
||||||
|
|
||||||
const areSongsFavorite = React.useCallback(
|
const favoriteSongs = React.useCallback(
|
||||||
(ids: Iterable<string>) => {
|
async (ids: Id<"songs">[]) => {
|
||||||
let any = false
|
const unique = [...new Set(ids)]
|
||||||
for (const id of ids) {
|
if (unique.length === 0) {
|
||||||
if (!songIds.has(id)) return false
|
return
|
||||||
any = true
|
}
|
||||||
|
try {
|
||||||
|
await favoriteSongsMutation({ songIds: unique })
|
||||||
|
toast.success(
|
||||||
|
unique.length > 1
|
||||||
|
? `Favorited ${unique.length} songs`
|
||||||
|
: "Added to favorites"
|
||||||
|
)
|
||||||
|
} catch (error) {
|
||||||
|
toast.error(
|
||||||
|
error instanceof Error ? error.message : "Failed to update favorites"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return any
|
|
||||||
},
|
},
|
||||||
[songIds]
|
[favoriteSongsMutation]
|
||||||
)
|
)
|
||||||
|
|
||||||
const toggleSongsFavorite = React.useCallback(
|
const toggleSongsFavorite = React.useCallback(
|
||||||
@@ -223,7 +232,7 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
|
|||||||
toggleSongsFavorite,
|
toggleSongsFavorite,
|
||||||
toggleAlbumFavorite,
|
toggleAlbumFavorite,
|
||||||
toggleArtistFavorite,
|
toggleArtistFavorite,
|
||||||
areSongsFavorite,
|
favoriteSongs,
|
||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
isSongFavorite,
|
isSongFavorite,
|
||||||
@@ -233,7 +242,7 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
|
|||||||
toggleSongsFavorite,
|
toggleSongsFavorite,
|
||||||
toggleAlbumFavorite,
|
toggleAlbumFavorite,
|
||||||
toggleArtistFavorite,
|
toggleArtistFavorite,
|
||||||
areSongsFavorite,
|
favoriteSongs,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -183,8 +183,7 @@ const SyncedLine = React.memo(function SyncedLine({
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The playing line's words, each filled as far as it has been sung. The
|
* The playing line's words, each filled as far as it has been sung. The
|
||||||
* browser runs the fills on the song's timeline (a word's start is its
|
* browser runs the fills; playback updates only correct their drift.
|
||||||
* delay); playback updates only correct their drift.
|
|
||||||
*/
|
*/
|
||||||
function FilledWords({
|
function FilledWords({
|
||||||
words,
|
words,
|
||||||
@@ -201,7 +200,6 @@ function FilledWords({
|
|||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
fills.current = words.map((word, index) =>
|
fills.current = words.map((word, index) =>
|
||||||
spans.current[index]?.animate(WORD_FILL_FRAMES, {
|
spans.current[index]?.animate(WORD_FILL_FRAMES, {
|
||||||
delay: word.start * 1000,
|
|
||||||
duration: Math.max(word.end - word.start, 0.05) * 1000,
|
duration: Math.max(word.end - word.start, 0.05) * 1000,
|
||||||
easing: "linear",
|
easing: "linear",
|
||||||
fill: "both",
|
fill: "both",
|
||||||
@@ -211,14 +209,15 @@ function FilledWords({
|
|||||||
}, [words])
|
}, [words])
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const at = time * 1000
|
|
||||||
fills.current.forEach((fill, index) => {
|
fills.current.forEach((fill, index) => {
|
||||||
if (!fill) return
|
if (!fill) return
|
||||||
|
const at = (time - words[index].start) * 1000
|
||||||
if (Math.abs(Number(fill.currentTime ?? 0) - at) > FILL_DRIFT_MS) {
|
if (Math.abs(Number(fill.currentTime ?? 0) - at) > FILL_DRIFT_MS) {
|
||||||
fill.currentTime = at
|
fill.currentTime = at
|
||||||
}
|
}
|
||||||
// `play` on a finished fill would rewind it to the start.
|
// `play` on a finished fill would rewind it.
|
||||||
if (isPlaying && time < words[index].end) fill.play()
|
const duration = Number(fill.effect?.getTiming().duration ?? 0)
|
||||||
|
if (isPlaying && at < duration) fill.play()
|
||||||
else fill.pause()
|
else fill.pause()
|
||||||
})
|
})
|
||||||
}, [words, time, isPlaying])
|
}, [words, time, isPlaying])
|
||||||
|
|||||||
@@ -48,8 +48,7 @@ export function OtherDownloadsView() {
|
|||||||
[songs]
|
[songs]
|
||||||
)
|
)
|
||||||
|
|
||||||
const { isSongFavorite, areSongsFavorite, toggleSongFavorite } =
|
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
||||||
useFavorites()
|
|
||||||
const { playFromSong, playInOrder, playShuffled } = usePlaybackActions()
|
const { playFromSong, playInOrder, playShuffled } = usePlaybackActions()
|
||||||
const {
|
const {
|
||||||
selectedIds,
|
selectedIds,
|
||||||
@@ -63,7 +62,6 @@ export function OtherDownloadsView() {
|
|||||||
() => stationArtistId(songs, selectedIds),
|
() => stationArtistId(songs, selectedIds),
|
||||||
[songs, selectedIds]
|
[songs, selectedIds]
|
||||||
)
|
)
|
||||||
const selectionFavorited = areSongsFavorite(selectedIds)
|
|
||||||
const selectionPositions = useMemo(
|
const selectionPositions = useMemo(
|
||||||
() =>
|
() =>
|
||||||
getSelectionRangePositions(
|
getSelectionRangePositions(
|
||||||
@@ -142,7 +140,6 @@ export function OtherDownloadsView() {
|
|||||||
isFavorite={isSongFavorite(songs[index].id)}
|
isFavorite={isSongFavorite(songs[index].id)}
|
||||||
selectedCount={selectedCount}
|
selectedCount={selectedCount}
|
||||||
selectionStationArtistId={selectedStationArtistId}
|
selectionStationArtistId={selectedStationArtistId}
|
||||||
selectionFavorited={selectionFavorited}
|
|
||||||
onPointerDown={handlePointerDown}
|
onPointerDown={handlePointerDown}
|
||||||
onSelect={handleRowSelect}
|
onSelect={handleRowSelect}
|
||||||
onPlay={handleRowPlay}
|
onPlay={handleRowPlay}
|
||||||
|
|||||||
@@ -74,12 +74,8 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
|||||||
currentUser === undefined
|
currentUser === undefined
|
||||||
? playlist.isOwner
|
? playlist.isOwner
|
||||||
: currentUser?._id === playlist.owner.id
|
: currentUser?._id === playlist.owner.id
|
||||||
const {
|
const { isSongFavorite, toggleSongFavorite, toggleSongsFavorite } =
|
||||||
isSongFavorite,
|
useFavorites()
|
||||||
areSongsFavorite,
|
|
||||||
toggleSongFavorite,
|
|
||||||
toggleSongsFavorite,
|
|
||||||
} = useFavorites()
|
|
||||||
const currentSongId = useCurrentSongId()
|
const currentSongId = useCurrentSongId()
|
||||||
const {
|
const {
|
||||||
playInOrder,
|
playInOrder,
|
||||||
@@ -147,7 +143,6 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
|||||||
() => stationArtistId(songs, selectedIds),
|
() => stationArtistId(songs, selectedIds),
|
||||||
[songs, selectedIds]
|
[songs, selectedIds]
|
||||||
)
|
)
|
||||||
const selectionFavorited = areSongsFavorite(selectedIds)
|
|
||||||
|
|
||||||
const selectionPositions = React.useMemo(
|
const selectionPositions = React.useMemo(
|
||||||
() =>
|
() =>
|
||||||
@@ -470,7 +465,6 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
|||||||
onAction={handlePlaylistMediaAction}
|
onAction={handlePlaylistMediaAction}
|
||||||
playlistLabel={ADD_TO_ANOTHER_PLAYLIST}
|
playlistLabel={ADD_TO_ANOTHER_PLAYLIST}
|
||||||
showFavorite={!isFavorites}
|
showFavorite={!isFavorites}
|
||||||
favorited={areSongsFavorite(playlistSongIds)}
|
|
||||||
downloaded={playlistDownloaded}
|
downloaded={playlistDownloaded}
|
||||||
trackRowTrigger={false}
|
trackRowTrigger={false}
|
||||||
triggerVariant="secondary"
|
triggerVariant="secondary"
|
||||||
@@ -528,7 +522,6 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
|||||||
selectionPosition={selectionPositions[index]}
|
selectionPosition={selectionPositions[index]}
|
||||||
selectedCount={selectedCount}
|
selectedCount={selectedCount}
|
||||||
selectionStationArtistId={selectedStationArtistId}
|
selectionStationArtistId={selectedStationArtistId}
|
||||||
selectionFavorited={selectionFavorited}
|
|
||||||
playlistLabel={ADD_TO_ANOTHER_PLAYLIST}
|
playlistLabel={ADD_TO_ANOTHER_PLAYLIST}
|
||||||
downloadCollection={downloadRef}
|
downloadCollection={downloadRef}
|
||||||
showFavoriteInMenu={!isFavorites}
|
showFavoriteInMenu={!isFavorites}
|
||||||
|
|||||||
@@ -3,16 +3,12 @@
|
|||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
|
|
||||||
import { useFavorites } from "@/components/favorites-provider"
|
import { useFavorites } from "@/components/favorites-provider"
|
||||||
import {
|
import type { MediaContextAction } from "@/components/media-context-menu"
|
||||||
MediaContextMenuArea,
|
|
||||||
type MediaContextAction,
|
|
||||||
} from "@/components/media-context-menu"
|
|
||||||
import { PlaybackSongMeta } from "@/components/playback-song-meta"
|
import { PlaybackSongMeta } from "@/components/playback-song-meta"
|
||||||
import { usePlayback } from "@/components/playback-provider"
|
import { usePlayback } from "@/components/playback-provider"
|
||||||
import { TrackCover, TrackRow } from "@/components/track-row"
|
import { TrackCover, TrackRow } from "@/components/track-row"
|
||||||
import { Skeleton } from "@/components/ui/skeleton"
|
import { Skeleton } from "@/components/ui/skeleton"
|
||||||
import { Spinner } from "@/components/ui/spinner"
|
import { Spinner } from "@/components/ui/spinner"
|
||||||
import { useSongDownloadState } from "@/hooks/use-downloads"
|
|
||||||
import { useMediaActions } from "@/hooks/use-media-actions"
|
import { useMediaActions } from "@/hooks/use-media-actions"
|
||||||
import { useTrackSelection } from "@/hooks/use-track-selection"
|
import { useTrackSelection } from "@/hooks/use-track-selection"
|
||||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||||
@@ -54,51 +50,6 @@ function toSelectableQueue(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens the song's right-click menu over `children`, for the queue rows that
|
|
||||||
* stand alone (history and the current song) rather than in the selection.
|
|
||||||
*/
|
|
||||||
function SongMenuArea({
|
|
||||||
song,
|
|
||||||
children,
|
|
||||||
}: {
|
|
||||||
song: BrowseSong
|
|
||||||
children: React.ReactElement
|
|
||||||
}) {
|
|
||||||
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
|
||||||
const { runSongsAction } = useMediaActions()
|
|
||||||
const downloaded = useSongDownloadState(song.id) === "here"
|
|
||||||
|
|
||||||
function handleAction(action: MediaContextAction) {
|
|
||||||
if (action === "favorite") {
|
|
||||||
void toggleSongFavorite(song.id)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
runSongsAction(action, [song.id], song.artist.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<MediaContextMenuArea
|
|
||||||
menu={{
|
|
||||||
label: `More options for ${song.title}`,
|
|
||||||
stationArtistId: song.artist.id,
|
|
||||||
selectedCount: 1,
|
|
||||||
onOpenMenu: () => {},
|
|
||||||
onAction: handleAction,
|
|
||||||
favorited: isSongFavorite(song.id),
|
|
||||||
downloaded,
|
|
||||||
navigation: {
|
|
||||||
artist: { id: song.artist.id },
|
|
||||||
album: { id: song.album.id },
|
|
||||||
},
|
|
||||||
share: { type: "song", albumId: song.album.id, songId: song.id },
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</MediaContextMenuArea>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/** A played song; clicking it plays it again from that point in history. */
|
/** A played song; clicking it plays it again from that point in history. */
|
||||||
function HistorySongRow({
|
function HistorySongRow({
|
||||||
song,
|
song,
|
||||||
@@ -114,11 +65,10 @@ function HistorySongRow({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SongMenuArea song={song}>
|
|
||||||
<li
|
<li
|
||||||
role="button"
|
role="button"
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
className="flex cursor-pointer items-center gap-3 px-4 py-2 text-sm hover:bg-foreground/5 data-[state=open]:bg-foreground/5"
|
className="flex cursor-pointer items-center gap-3 px-4 py-2 text-sm hover:bg-foreground/5"
|
||||||
onClick={() => onPlay(historyIndex)}
|
onClick={() => onPlay(historyIndex)}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
if (event.key === "Enter" || event.key === " ") {
|
if (event.key === "Enter" || event.key === " ") {
|
||||||
@@ -134,7 +84,6 @@ function HistorySongRow({
|
|||||||
/>
|
/>
|
||||||
<PlaybackSongMeta song={song} align="start" showAlbum={false} />
|
<PlaybackSongMeta song={song} align="start" showAlbum={false} />
|
||||||
</li>
|
</li>
|
||||||
</SongMenuArea>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,7 +193,7 @@ export function QueuePanel() {
|
|||||||
prepareContextMenu,
|
prepareContextMenu,
|
||||||
clearSelection,
|
clearSelection,
|
||||||
} = useTrackSelection(selectionItems)
|
} = useTrackSelection(selectionItems)
|
||||||
const { isSongFavorite, areSongsFavorite } = useFavorites()
|
const { isSongFavorite } = useFavorites()
|
||||||
const { runSongsAction } = useMediaActions()
|
const { runSongsAction } = useMediaActions()
|
||||||
|
|
||||||
/** The rows a menu acts on: the selection, else just the clicked row. */
|
/** The rows a menu acts on: the selection, else just the clicked row. */
|
||||||
@@ -268,11 +217,6 @@ export function QueuePanel() {
|
|||||||
),
|
),
|
||||||
[selectableQueue, selectedIds]
|
[selectableQueue, selectedIds]
|
||||||
)
|
)
|
||||||
const selectionFavorited = areSongsFavorite(
|
|
||||||
selectableQueue.flatMap((item) =>
|
|
||||||
item.song && selectedIds.has(item.selectionId) ? [item.song.id] : []
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
const handleMediaAction = React.useCallback(
|
const handleMediaAction = React.useCallback(
|
||||||
(action: MediaContextAction, selectionId: string) => {
|
(action: MediaContextAction, selectionId: string) => {
|
||||||
@@ -410,9 +354,10 @@ export function QueuePanel() {
|
|||||||
|
|
||||||
{/* Fills the viewport so the current song can always scroll to the top. */}
|
{/* Fills the viewport so the current song can always scroll to the top. */}
|
||||||
<div ref={currentRef} className="flex min-h-full flex-col">
|
<div ref={currentRef} className="flex min-h-full flex-col">
|
||||||
{currentSong ? (
|
{currentQueueSongId ? (
|
||||||
<SongMenuArea song={currentSong}>
|
|
||||||
<div className="flex items-center gap-3 px-4 py-3">
|
<div className="flex items-center gap-3 px-4 py-3">
|
||||||
|
{currentSong ? (
|
||||||
|
<>
|
||||||
<TrackCover
|
<TrackCover
|
||||||
albumId={currentSong.album.id}
|
albumId={currentSong.album.id}
|
||||||
alt={currentSong.album.title}
|
alt={currentSong.album.title}
|
||||||
@@ -424,11 +369,10 @@ export function QueuePanel() {
|
|||||||
align="start"
|
align="start"
|
||||||
showAlbum={false}
|
showAlbum={false}
|
||||||
/>
|
/>
|
||||||
</div>
|
</>
|
||||||
</SongMenuArea>
|
) : (
|
||||||
) : currentQueueSongId ? (
|
|
||||||
<div className="px-4 py-3">
|
|
||||||
<Skeleton className="size-14 shrink-0 rounded-md" />
|
<Skeleton className="size-14 shrink-0 rounded-md" />
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
@@ -458,7 +402,6 @@ export function QueuePanel() {
|
|||||||
isFavorite={isSongFavorite(item.song.id)}
|
isFavorite={isSongFavorite(item.song.id)}
|
||||||
selectedCount={selectedCount}
|
selectedCount={selectedCount}
|
||||||
selectionStationArtistId={selectedStationArtistId}
|
selectionStationArtistId={selectedStationArtistId}
|
||||||
selectionFavorited={selectionFavorited}
|
|
||||||
removeLabel="Remove from Queue"
|
removeLabel="Remove from Queue"
|
||||||
selectionPosition={selectionPositions[index]}
|
selectionPosition={selectionPositions[index]}
|
||||||
isDragging={draggingIndices.has(index)}
|
isDragging={draggingIndices.has(index)}
|
||||||
|
|||||||
@@ -47,8 +47,7 @@ const SONGS_PAGE_SIZE = 50
|
|||||||
const estimateSongRowSize = () => 56
|
const estimateSongRowSize = () => 56
|
||||||
|
|
||||||
export function SongsView() {
|
export function SongsView() {
|
||||||
const { isSongFavorite, areSongsFavorite, toggleSongFavorite } =
|
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
||||||
useFavorites()
|
|
||||||
const { playFromLibrarySong } = usePlaybackActions()
|
const { playFromLibrarySong } = usePlaybackActions()
|
||||||
const [sortKey, setSortKey] = useState<SortKey>("title")
|
const [sortKey, setSortKey] = useState<SortKey>("title")
|
||||||
const [sortDirection, setSortDirection] = useState<SortDirection>("asc")
|
const [sortDirection, setSortDirection] = useState<SortDirection>("asc")
|
||||||
@@ -99,7 +98,6 @@ export function SongsView() {
|
|||||||
() => stationArtistId(songs, selectedIds),
|
() => stationArtistId(songs, selectedIds),
|
||||||
[songs, selectedIds]
|
[songs, selectedIds]
|
||||||
)
|
)
|
||||||
const selectionFavorited = areSongsFavorite(selectedIds)
|
|
||||||
|
|
||||||
const selectionPositions = useMemo(
|
const selectionPositions = useMemo(
|
||||||
() =>
|
() =>
|
||||||
@@ -224,7 +222,6 @@ export function SongsView() {
|
|||||||
isFavorite={isSongFavorite(songs[index].id)}
|
isFavorite={isSongFavorite(songs[index].id)}
|
||||||
selectedCount={selectedCount}
|
selectedCount={selectedCount}
|
||||||
selectionStationArtistId={selectedStationArtistId}
|
selectionStationArtistId={selectedStationArtistId}
|
||||||
selectionFavorited={selectionFavorited}
|
|
||||||
onPointerDown={handlePointerDown}
|
onPointerDown={handlePointerDown}
|
||||||
onSelect={handleRowSelect}
|
onSelect={handleRowSelect}
|
||||||
onPlay={handleRowPlay}
|
onPlay={handleRowPlay}
|
||||||
|
|||||||
@@ -68,8 +68,6 @@ export type TrackRowProps = {
|
|||||||
selectedCount?: number
|
selectedCount?: number
|
||||||
/** Station artist for the selection when this row is selected. */
|
/** Station artist for the selection when this row is selected. */
|
||||||
selectionStationArtistId?: string
|
selectionStationArtistId?: string
|
||||||
/** Whether every selected song is favorited, when this row is selected. */
|
|
||||||
selectionFavorited?: boolean
|
|
||||||
playlistLabel?: string
|
playlistLabel?: string
|
||||||
showFavoriteInMenu?: boolean
|
showFavoriteInMenu?: boolean
|
||||||
/** Adds a destructive menu item calling `onRemove`. */
|
/** Adds a destructive menu item calling `onRemove`. */
|
||||||
@@ -270,7 +268,6 @@ function TrackRowComponent({
|
|||||||
isDragging = false,
|
isDragging = false,
|
||||||
selectedCount = 0,
|
selectedCount = 0,
|
||||||
selectionStationArtistId,
|
selectionStationArtistId,
|
||||||
selectionFavorited,
|
|
||||||
playlistLabel,
|
playlistLabel,
|
||||||
showFavoriteInMenu = true,
|
showFavoriteInMenu = true,
|
||||||
removeLabel,
|
removeLabel,
|
||||||
@@ -348,10 +345,7 @@ function TrackRowComponent({
|
|||||||
onAction: (action) => onMediaAction(action, rowId),
|
onAction: (action) => onMediaAction(action, rowId),
|
||||||
playlistLabel,
|
playlistLabel,
|
||||||
showFavorite: showFavoriteInMenu,
|
showFavorite: showFavoriteInMenu,
|
||||||
favorited:
|
favorited: isFavorite,
|
||||||
inRange && selectedCount > 0
|
|
||||||
? (selectionFavorited ?? isFavorite)
|
|
||||||
: isFavorite,
|
|
||||||
navigation: {
|
navigation: {
|
||||||
artist: { id: song.artist.id },
|
artist: { id: song.artist.id },
|
||||||
album: { id: song.album.id },
|
album: { id: song.album.id },
|
||||||
|
|||||||
@@ -26,8 +26,7 @@ function songsTitle(songIds: readonly string[]) {
|
|||||||
|
|
||||||
export function useMediaActions() {
|
export function useMediaActions() {
|
||||||
const { openAddToPlaylist, openAddArtistToPlaylist } = useAddToPlaylist()
|
const { openAddToPlaylist, openAddArtistToPlaylist } = useAddToPlaylist()
|
||||||
const { areSongsFavorite, toggleSongsFavorite, toggleArtistFavorite } =
|
const { favoriteSongs, toggleArtistFavorite } = useFavorites()
|
||||||
useFavorites()
|
|
||||||
const { runQueueAction, createStation } = useQueueMediaActions()
|
const { runQueueAction, createStation } = useQueueMediaActions()
|
||||||
const convex = useConvex()
|
const convex = useConvex()
|
||||||
const cacheScope = useCacheScope()
|
const cacheScope = useCacheScope()
|
||||||
@@ -45,8 +44,7 @@ export function useMediaActions() {
|
|||||||
if (stationArtist) void createStation(stationArtist)
|
if (stationArtist) void createStation(stationArtist)
|
||||||
break
|
break
|
||||||
case "favorite":
|
case "favorite":
|
||||||
// Unfavorite only when every song already is, matching the menu label.
|
void favoriteSongs(songIds)
|
||||||
void toggleSongsFavorite(songIds, areSongsFavorite(songIds))
|
|
||||||
break
|
break
|
||||||
case "playlist":
|
case "playlist":
|
||||||
openAddToPlaylist(songIds)
|
openAddToPlaylist(songIds)
|
||||||
@@ -75,8 +73,7 @@ export function useMediaActions() {
|
|||||||
},
|
},
|
||||||
[
|
[
|
||||||
createStation,
|
createStation,
|
||||||
areSongsFavorite,
|
favoriteSongs,
|
||||||
toggleSongsFavorite,
|
|
||||||
openAddToPlaylist,
|
openAddToPlaylist,
|
||||||
runQueueAction,
|
runQueueAction,
|
||||||
requestDownload,
|
requestDownload,
|
||||||
|
|||||||
@@ -125,9 +125,8 @@ function collectionKey({ kind, id }: CollectionRef) {
|
|||||||
*/
|
*/
|
||||||
export function createDownloadQueue(
|
export function createDownloadQueue(
|
||||||
storage: DownloadStorage,
|
storage: DownloadStorage,
|
||||||
options: { concurrency?: number } = {}
|
{ concurrency = 2 }: { concurrency?: number } = {}
|
||||||
) {
|
) {
|
||||||
let concurrency = options.concurrency ?? 2
|
|
||||||
const downloaded = new Map<string, DownloadedSong>()
|
const downloaded = new Map<string, DownloadedSong>()
|
||||||
const collections = new Map<string, DownloadedCollection>()
|
const collections = new Map<string, DownloadedCollection>()
|
||||||
const otherSongIds = new Set<string>()
|
const otherSongIds = new Set<string>()
|
||||||
@@ -373,17 +372,6 @@ export function createDownloadQueue(
|
|||||||
collections: () => [...collections.values()],
|
collections: () => [...collections.values()],
|
||||||
isQueued,
|
isQueued,
|
||||||
status,
|
status,
|
||||||
/** Songs downloading or waiting to. */
|
|
||||||
pendingCount: () => running.size + waiting.length,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* How many songs download at once. Raising it starts waiting songs now;
|
|
||||||
* lowering it lets running songs finish.
|
|
||||||
*/
|
|
||||||
setConcurrency(limit: number) {
|
|
||||||
concurrency = limit
|
|
||||||
pump()
|
|
||||||
},
|
|
||||||
|
|
||||||
/** Songs downloaded on their own, in the order they were added. */
|
/** Songs downloaded on their own, in the order they were added. */
|
||||||
otherSongIds: () => [...otherSongIds],
|
otherSongIds: () => [...otherSongIds],
|
||||||
|
|||||||
@@ -1,93 +0,0 @@
|
|||||||
/**
|
|
||||||
* Typo-tolerant word matching, shared by library search, lyrics search and
|
|
||||||
* in-list song filters.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Lowercase words without accents or apostrophes, so "Don't Stop Beyoncé"
|
|
||||||
* gives ["dont", "stop", "beyonce"].
|
|
||||||
*/
|
|
||||||
export function searchWords(text: string): string[] {
|
|
||||||
return (
|
|
||||||
text
|
|
||||||
.normalize("NFKD")
|
|
||||||
.replace(/\p{M}/gu, "")
|
|
||||||
.toLowerCase()
|
|
||||||
.replace(/['’]/g, "")
|
|
||||||
.match(/[\p{L}\p{N}]+/gu) ?? []
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Typos a query word may hold. Short words get none, or they match too much. */
|
|
||||||
function allowedTypos(term: string) {
|
|
||||||
if (term.length < 4) return 0
|
|
||||||
return term.length < 8 ? 1 : 2
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Edits (insert, delete, substitute or swap neighbors) turning `a` into `b`,
|
|
||||||
* or `max + 1` once it is sure to exceed `max`.
|
|
||||||
*/
|
|
||||||
function editDistance(a: string, b: string, max: number): number {
|
|
||||||
if (Math.abs(a.length - b.length) > max) return max + 1
|
|
||||||
let before: number[] = []
|
|
||||||
let previous = Array.from({ length: b.length + 1 }, (_, j) => j)
|
|
||||||
for (let i = 1; i <= a.length; i++) {
|
|
||||||
const current = [i]
|
|
||||||
let rowMin = i
|
|
||||||
for (let j = 1; j <= b.length; j++) {
|
|
||||||
const cost = a[i - 1] === b[j - 1] ? 0 : 1
|
|
||||||
let distance = Math.min(
|
|
||||||
previous[j]! + 1,
|
|
||||||
current[j - 1]! + 1,
|
|
||||||
previous[j - 1]! + cost
|
|
||||||
)
|
|
||||||
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
||||||
distance = Math.min(distance, before[j - 2]! + 1)
|
|
||||||
}
|
|
||||||
current.push(distance)
|
|
||||||
rowMin = Math.min(rowMin, distance)
|
|
||||||
}
|
|
||||||
if (rowMin > max) return max + 1
|
|
||||||
before = previous
|
|
||||||
previous = current
|
|
||||||
}
|
|
||||||
return previous[b.length]!
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether `word` is query `term` give or take a few typos. With `prefix` the
|
|
||||||
* word may also just start with the term, as when it is still being typed.
|
|
||||||
*/
|
|
||||||
function wordMatchesTerm(term: string, word: string, prefix: boolean) {
|
|
||||||
const typos = allowedTypos(term)
|
|
||||||
if (typos === 0) return false
|
|
||||||
if (editDistance(term, word, typos) <= typos) return true
|
|
||||||
return (
|
|
||||||
prefix &&
|
|
||||||
word.length > term.length &&
|
|
||||||
editDistance(term, word.slice(0, term.length), typos) <= typos
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* How every query term (from `searchWords`) appears among `words`: "exact"
|
|
||||||
* when each is a word, "fuzzy" when some only match give or take typos, or
|
|
||||||
* null when one is missing. The last term may be a word's prefix.
|
|
||||||
*/
|
|
||||||
export function matchWords(
|
|
||||||
words: readonly string[],
|
|
||||||
terms: readonly string[]
|
|
||||||
): "exact" | "fuzzy" | null {
|
|
||||||
let quality: "exact" | "fuzzy" = "exact"
|
|
||||||
for (const [index, term] of terms.entries()) {
|
|
||||||
const prefix = index === terms.length - 1
|
|
||||||
const exact = words.some((word) =>
|
|
||||||
prefix ? word.startsWith(term) : word === term
|
|
||||||
)
|
|
||||||
if (exact) continue
|
|
||||||
if (!words.some((word) => wordMatchesTerm(term, word, prefix))) return null
|
|
||||||
quality = "fuzzy"
|
|
||||||
}
|
|
||||||
return terms.length > 0 ? quality : null
|
|
||||||
}
|
|
||||||
@@ -5,8 +5,6 @@
|
|||||||
* the same.
|
* the same.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { matchWords, searchWords } from "./fuzzy-search"
|
|
||||||
|
|
||||||
export type LyricWord = {
|
export type LyricWord = {
|
||||||
/** Includes its trailing space, so a line's words join back into its text. */
|
/** Includes its trailing space, so a line's words join back into its text. */
|
||||||
text: string
|
text: string
|
||||||
@@ -18,15 +16,11 @@ export type LyricLine = {
|
|||||||
text: string
|
text: string
|
||||||
/** Seconds; `null` for plain lyrics. */
|
/** Seconds; `null` for plain lyrics. */
|
||||||
start: number | null
|
start: number | null
|
||||||
/**
|
/** Set only on word-timed lines. */
|
||||||
* The line's words as they are sung. Line-timed lyrics get estimated
|
|
||||||
* ones (see `estimateWords`); plain lyrics have none.
|
|
||||||
*/
|
|
||||||
words: LyricWord[] | null
|
words: LyricWord[] | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Lyrics = {
|
export type Lyrics = {
|
||||||
/** How the source was timed, whatever `words` were estimated. */
|
|
||||||
synced: "none" | "line" | "word"
|
synced: "none" | "line" | "word"
|
||||||
lines: LyricLine[]
|
lines: LyricLine[]
|
||||||
}
|
}
|
||||||
@@ -35,8 +29,6 @@ const LINE_STAMP = /^\[(\d+):(\d+(?:[.:]\d+)?)\]/
|
|||||||
const WORD_STAMP = /<(\d+):(\d+(?:[.:]\d+)?)>/g
|
const WORD_STAMP = /<(\d+):(\d+(?:[.:]\d+)?)>/g
|
||||||
const HAS_WORD_STAMP = /<\d+:\d+(?:[.:]\d+)?>/
|
const HAS_WORD_STAMP = /<\d+:\d+(?:[.:]\d+)?>/
|
||||||
const ID_TAG = /^\[[a-z]+:.*\]$/i
|
const ID_TAG = /^\[[a-z]+:.*\]$/i
|
||||||
/** A rough singing pace, so a line-timed line's fill tracks its words. */
|
|
||||||
const ESTIMATED_SECONDS_PER_CHAR = 0.07
|
|
||||||
|
|
||||||
function seconds(minutes: string, rest: string) {
|
function seconds(minutes: string, rest: string) {
|
||||||
return Number(minutes) * 60 + Number(rest.replace(":", "."))
|
return Number(minutes) * 60 + Number(rest.replace(":", "."))
|
||||||
@@ -115,31 +107,10 @@ export function parseLyrics(raw: string): Lyrics | null {
|
|||||||
}
|
}
|
||||||
lines.sort((a, b) => a.start! - b.start!)
|
lines.sort((a, b) => a.start! - b.start!)
|
||||||
if (lines.length === 0) return null
|
if (lines.length === 0) return null
|
||||||
const synced = lines.every((line) => line.words) ? "word" : "line"
|
return {
|
||||||
if (synced === "line") estimateWords(lines)
|
synced: lines.every((line) => line.words) ? "word" : "line",
|
||||||
return { synced, lines }
|
lines,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gives timed lines without word timing words spread over them by length,
|
|
||||||
* at a singing pace but never past the next line, so they fill as they play.
|
|
||||||
*/
|
|
||||||
function estimateWords(lines: LyricLine[]) {
|
|
||||||
lines.forEach((line, index) => {
|
|
||||||
if (line.words || line.start === null) return
|
|
||||||
const next = lines[index + 1]?.start ?? Infinity
|
|
||||||
const duration = Math.min(
|
|
||||||
next - line.start,
|
|
||||||
line.text.length * ESTIMATED_SECONDS_PER_CHAR
|
|
||||||
)
|
|
||||||
const perChar = duration / line.text.length
|
|
||||||
let at = line.start
|
|
||||||
line.words = (line.text.match(/\S+\s*/g) ?? []).map((text) => {
|
|
||||||
const start = at
|
|
||||||
at += text.length * perChar
|
|
||||||
return { text, start, end: at }
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The text without timestamps, one line per row, for search and snippets. */
|
/** The text without timestamps, one line per row, for search and snippets. */
|
||||||
@@ -214,32 +185,32 @@ export function followLyrics(
|
|||||||
return () => clearTimeout(timer)
|
return () => clearTimeout(timer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Lowercase words of a search, for matching lyrics the way the search index does. */
|
||||||
|
function searchTerms(query: string): string[] {
|
||||||
|
return query.toLowerCase().match(/[\p{L}\p{N}']+/gu) ?? []
|
||||||
|
}
|
||||||
|
|
||||||
const SNIPPET_LEAD = 24
|
const SNIPPET_LEAD = 24
|
||||||
|
|
||||||
export type LyricsMatch = {
|
export type LyricsMatch = {
|
||||||
/** The matched line, trimmed to start near the match. */
|
/** The matched line, trimmed to start near the match. */
|
||||||
snippet: string
|
snippet: string
|
||||||
/**
|
/** Whether the line holds the query as typed, not just its words. */
|
||||||
* 2 when the line holds the query as typed, 1 when it holds every word of
|
exact: boolean
|
||||||
* it, 0 when it does give or take typos.
|
|
||||||
*/
|
|
||||||
score: 0 | 1 | 2
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Where a search matched the lyrics: the best line holding the query as
|
* Where a search matched the lyrics: a line holding the query as typed, or
|
||||||
* typed, or else every word of it (see `matchWords`). Null when no single
|
* else a line holding every word of it (the last may be a prefix, as when
|
||||||
* line does.
|
* typing). Null when no single line does.
|
||||||
*/
|
*/
|
||||||
export function matchLyrics(plain: string, query: string): LyricsMatch | null {
|
export function matchLyrics(plain: string, query: string): LyricsMatch | null {
|
||||||
const needle = query.trim().toLowerCase()
|
const needle = query.trim().toLowerCase()
|
||||||
const terms = searchWords(needle)
|
const terms = searchTerms(needle)
|
||||||
// Most songs miss a word entirely, so skip them before checking lines.
|
const last = terms.at(-1)
|
||||||
if (!needle || !matchWords([...new Set(searchWords(plain))], terms)) {
|
if (!needle || last === undefined) return null
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
let loose: LyricsMatch | null = null
|
let loose: string | null = null
|
||||||
for (const line of plain.split("\n")) {
|
for (const line of plain.split("\n")) {
|
||||||
const column = line.toLowerCase().indexOf(needle)
|
const column = line.toLowerCase().indexOf(needle)
|
||||||
if (column !== -1) {
|
if (column !== -1) {
|
||||||
@@ -247,13 +218,15 @@ export function matchLyrics(plain: string, query: string): LyricsMatch | null {
|
|||||||
column > SNIPPET_LEAD
|
column > SNIPPET_LEAD
|
||||||
? `…${line.slice(column - SNIPPET_LEAD).trimStart()}`
|
? `…${line.slice(column - SNIPPET_LEAD).trimStart()}`
|
||||||
: line.trim()
|
: line.trim()
|
||||||
return { snippet, score: 2 }
|
return { snippet, exact: true }
|
||||||
}
|
}
|
||||||
if (loose?.score === 1) continue
|
if (loose === null) {
|
||||||
const quality = matchWords(searchWords(line), terms)
|
const words = searchTerms(line)
|
||||||
if (quality === "exact" || (quality && !loose)) {
|
const hasAll =
|
||||||
loose = { snippet: line.trim(), score: quality === "exact" ? 1 : 0 }
|
terms.slice(0, -1).every((term) => words.includes(term)) &&
|
||||||
|
words.some((word) => word.startsWith(last))
|
||||||
|
if (hasAll) loose = line.trim()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return loose
|
return loose === null ? null : { snippet: loose, exact: false }
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
import { matchWords, searchWords } from "./fuzzy-search"
|
|
||||||
|
|
||||||
type SearchableSong = {
|
type SearchableSong = {
|
||||||
id: string
|
id: string
|
||||||
title: string
|
title: string
|
||||||
@@ -8,9 +6,9 @@ type SearchableSong = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Case-insensitive match on title, artist, or album, give or take typos (see
|
* Case-insensitive match on title, artist, or album, plus the songs in
|
||||||
* `matchWords`), plus the songs in `lyricsMatches` (from
|
* `lyricsMatches` (from `api.lyrics.matchingSongIds`). A blank query keeps
|
||||||
* `api.lyrics.matchingSongIds`). A blank query keeps every song.
|
* every song.
|
||||||
*/
|
*/
|
||||||
export function filterSongs<T extends SearchableSong>(
|
export function filterSongs<T extends SearchableSong>(
|
||||||
songs: T[],
|
songs: T[],
|
||||||
@@ -21,14 +19,12 @@ export function filterSongs<T extends SearchableSong>(
|
|||||||
if (!normalized) {
|
if (!normalized) {
|
||||||
return songs
|
return songs
|
||||||
}
|
}
|
||||||
const terms = searchWords(normalized)
|
|
||||||
const byLyrics = new Set(lyricsMatches)
|
const byLyrics = new Set(lyricsMatches)
|
||||||
return songs.filter((song) => {
|
return songs.filter(
|
||||||
if (byLyrics.has(song.id)) return true
|
(song) =>
|
||||||
const fields = [song.title, song.artist.name, song.album.title]
|
byLyrics.has(song.id) ||
|
||||||
return (
|
[song.title, song.artist.name, song.album.title].some((value) =>
|
||||||
fields.some((value) => value.toLowerCase().includes(normalized)) ||
|
value.toLowerCase().includes(normalized)
|
||||||
matchWords(searchWords(fields.join(" ")), terms) !== null
|
)
|
||||||
)
|
)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,6 @@ import { chunk, type Chunked } from "./limits"
|
|||||||
import { recordIntentCatalogChanges } from "./intentCatalogChanges"
|
import { recordIntentCatalogChanges } from "./intentCatalogChanges"
|
||||||
import { playlistCoverVersion } from "./playlistCover"
|
import { playlistCoverVersion } from "./playlistCover"
|
||||||
import { deleteSongLyrics, searchSongLyrics, writeSongLyrics } from "./lyrics"
|
import { deleteSongLyrics, searchSongLyrics, writeSongLyrics } from "./lyrics"
|
||||||
import { matchWords, searchWords } from "../client/fuzzy-search"
|
|
||||||
|
|
||||||
export type {
|
export type {
|
||||||
BrowseAlbum,
|
BrowseAlbum,
|
||||||
@@ -619,16 +618,7 @@ export const browseArtistDetail = query({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
function matchScore(text: string, query: string): number {
|
||||||
* How well `text` matches a lowercase search, from 100 (the whole text) down
|
|
||||||
* to 20 (every word, give or take typos); 0 is no match. `terms` are the
|
|
||||||
* query's `searchWords`.
|
|
||||||
*/
|
|
||||||
function matchScore(
|
|
||||||
text: string,
|
|
||||||
query: string,
|
|
||||||
terms: readonly string[]
|
|
||||||
): number {
|
|
||||||
const lower = text.toLowerCase()
|
const lower = text.toLowerCase()
|
||||||
if (lower === query) {
|
if (lower === query) {
|
||||||
return 100
|
return 100
|
||||||
@@ -642,20 +632,15 @@ function matchScore(
|
|||||||
if (lower.includes(query)) {
|
if (lower.includes(query)) {
|
||||||
return 40
|
return 40
|
||||||
}
|
}
|
||||||
const words = matchWords(searchWords(text), terms)
|
return 0
|
||||||
if (words === "exact") {
|
|
||||||
return 30
|
|
||||||
}
|
|
||||||
return words === "fuzzy" ? 20 : 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function matchScoreSongArtists(
|
function matchScoreSongArtists(
|
||||||
artist: string | string[],
|
artist: string | string[],
|
||||||
query: string,
|
query: string
|
||||||
terms: readonly string[]
|
|
||||||
): number {
|
): number {
|
||||||
return getSongArtistNames(artist).reduce(
|
return getSongArtistNames(artist).reduce(
|
||||||
(best, name) => Math.max(best, matchScore(name, query, terms)),
|
(best, name) => Math.max(best, matchScore(name, query)),
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -673,7 +658,6 @@ export const searchLibrary = query({
|
|||||||
args: { query: v.string() },
|
args: { query: v.string() },
|
||||||
handler: async (ctx, args) => {
|
handler: async (ctx, args) => {
|
||||||
const queryText = args.query.trim().toLowerCase()
|
const queryText = args.query.trim().toLowerCase()
|
||||||
const terms = searchWords(queryText)
|
|
||||||
if (!queryText || !(await isSignedIn(ctx))) {
|
if (!queryText || !(await isSignedIn(ctx))) {
|
||||||
return {
|
return {
|
||||||
topResults: [],
|
topResults: [],
|
||||||
@@ -694,7 +678,7 @@ export const searchLibrary = query({
|
|||||||
.map((artist) => ({
|
.map((artist) => ({
|
||||||
kind: "artist" as const,
|
kind: "artist" as const,
|
||||||
item: toBrowseArtist(artist),
|
item: toBrowseArtist(artist),
|
||||||
score: matchScore(artist.name, queryText, terms),
|
score: matchScore(artist.name, queryText),
|
||||||
}))
|
}))
|
||||||
.filter((result) => result.score > 0)
|
.filter((result) => result.score > 0)
|
||||||
.sort(
|
.sort(
|
||||||
@@ -708,8 +692,8 @@ export const searchLibrary = query({
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
const score = Math.max(
|
const score = Math.max(
|
||||||
matchScore(album.name, queryText, terms),
|
matchScore(album.name, queryText),
|
||||||
matchScore(artist.name, queryText, terms)
|
matchScore(artist.name, queryText)
|
||||||
)
|
)
|
||||||
if (score === 0) {
|
if (score === 0) {
|
||||||
return []
|
return []
|
||||||
@@ -734,10 +718,10 @@ export const searchLibrary = query({
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
const score = Math.max(
|
const score = Math.max(
|
||||||
matchScore(song.name, queryText, terms),
|
matchScore(song.name, queryText),
|
||||||
matchScoreSongArtists(song.artist, queryText, terms),
|
matchScoreSongArtists(song.artist, queryText),
|
||||||
matchScore(album.name, queryText, terms),
|
matchScore(album.name, queryText),
|
||||||
matchScore(albumArtist.name, queryText, terms)
|
matchScore(albumArtist.name, queryText)
|
||||||
)
|
)
|
||||||
if (score === 0) {
|
if (score === 0) {
|
||||||
return []
|
return []
|
||||||
|
|||||||
@@ -62,10 +62,10 @@ export async function deleteSongLyrics(ctx: MutationCtx, songId: Id<"songs">) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Up to `limit` songs with a lyrics line matching `query` (see `matchLyrics`),
|
* Songs with a lyrics line matching `query` (see `matchLyrics`), with that
|
||||||
* with that line, best matches first. The search index matches any word
|
* line. Lines holding the query as typed come first, then the search index's
|
||||||
* anywhere in the lyrics and ranks common words poorly, so its whole page is
|
* relevance order. The index matches words anywhere in the lyrics, so its
|
||||||
* checked line by line before trimming.
|
* results are checked line by line.
|
||||||
*/
|
*/
|
||||||
export async function searchSongLyrics(
|
export async function searchSongLyrics(
|
||||||
ctx: QueryCtx,
|
ctx: QueryCtx,
|
||||||
@@ -77,15 +77,15 @@ export async function searchSongLyrics(
|
|||||||
const rows = await ctx.db
|
const rows = await ctx.db
|
||||||
.query("lyricsSearch")
|
.query("lyricsSearch")
|
||||||
.withSearchIndex("search_plain", (q) => q.search("plain", text))
|
.withSearchIndex("search_plain", (q) => q.search("plain", text))
|
||||||
.take(MAX_LYRICS_MATCHES)
|
.take(limit)
|
||||||
return rows
|
const matches = rows.flatMap((row) => {
|
||||||
.flatMap((row) => {
|
|
||||||
const match = matchLyrics(row.plain, text)
|
const match = matchLyrics(row.plain, text)
|
||||||
return match ? [{ song: row.song, ...match }] : []
|
return match ? [{ song: row.song, ...match }] : []
|
||||||
})
|
})
|
||||||
.sort((a, b) => b.score - a.score)
|
return [
|
||||||
.slice(0, limit)
|
...matches.filter((match) => match.exact),
|
||||||
.map(({ song, snippet }) => ({ song, snippet }))
|
...matches.filter((match) => !match.exact),
|
||||||
|
].map(({ song, snippet }) => ({ song, snippet }))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The song's lyrics tag (see `client/lyrics.ts`), or null without lyrics. */
|
/** The song's lyrics tag (see `client/lyrics.ts`), or null without lyrics. */
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import type { PlaybackSource, PlaybackStreamPlan } from "./playback-stream"
|
|||||||
|
|
||||||
/** Qualities a listener can pick when downloading, lowest first. */
|
/** Qualities a listener can pick when downloading, lowest first. */
|
||||||
export const DOWNLOAD_QUALITIES = [
|
export const DOWNLOAD_QUALITIES = [
|
||||||
"low",
|
|
||||||
"medium",
|
"medium",
|
||||||
"high",
|
"high",
|
||||||
"lossless",
|
"lossless",
|
||||||
@@ -12,7 +11,6 @@ export const DOWNLOAD_QUALITIES = [
|
|||||||
export type DownloadQuality = (typeof DOWNLOAD_QUALITIES)[number]
|
export type DownloadQuality = (typeof DOWNLOAD_QUALITIES)[number]
|
||||||
|
|
||||||
export const DOWNLOAD_QUALITY_LABELS: Record<DownloadQuality, string> = {
|
export const DOWNLOAD_QUALITY_LABELS: Record<DownloadQuality, string> = {
|
||||||
low: "Low",
|
|
||||||
medium: "Medium",
|
medium: "Medium",
|
||||||
high: "High",
|
high: "High",
|
||||||
lossless: "Lossless",
|
lossless: "Lossless",
|
||||||
@@ -20,14 +18,12 @@ export const DOWNLOAD_QUALITY_LABELS: Record<DownloadQuality, string> = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const DOWNLOAD_QUALITY_DETAILS: Record<DownloadQuality, string> = {
|
export const DOWNLOAD_QUALITY_DETAILS: Record<DownloadQuality, string> = {
|
||||||
low: "AAC 64 kbps",
|
|
||||||
medium: "AAC 128 kbps",
|
medium: "AAC 128 kbps",
|
||||||
high: "AAC 256 kbps",
|
high: "AAC 256 kbps",
|
||||||
lossless: "ALAC or FLAC",
|
lossless: "ALAC or FLAC",
|
||||||
atmos: "Spatial audio",
|
atmos: "Spatial audio",
|
||||||
}
|
}
|
||||||
|
|
||||||
const LOW_KBPS = 64
|
|
||||||
const MEDIUM_KBPS = 128
|
const MEDIUM_KBPS = 128
|
||||||
const HIGH_KBPS = 256
|
const HIGH_KBPS = 256
|
||||||
|
|
||||||
@@ -58,14 +54,13 @@ function highPlan(files: Record<string, unknown>): DownloadPlan {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Picks the file for one song. Lossless and Dolby Atmos fall back to High when
|
* Picks the file for one song. Lossless and Dolby Atmos fall back to High when
|
||||||
* the song lacks them, and Low and Medium are always transcoded.
|
* the song lacks them, and Medium is always transcoded.
|
||||||
*/
|
*/
|
||||||
export function downloadPlan(
|
export function downloadPlan(
|
||||||
files: Record<string, unknown>,
|
files: Record<string, unknown>,
|
||||||
quality: DownloadQuality
|
quality: DownloadQuality
|
||||||
): DownloadPlan {
|
): DownloadPlan {
|
||||||
switch (quality) {
|
switch (quality) {
|
||||||
case "low":
|
|
||||||
case "medium":
|
case "medium":
|
||||||
return {
|
return {
|
||||||
quality,
|
quality,
|
||||||
@@ -75,7 +70,7 @@ export function downloadPlan(
|
|||||||
: "normal" in files
|
: "normal" in files
|
||||||
? "normal"
|
? "normal"
|
||||||
: "atmos",
|
: "atmos",
|
||||||
kbps: quality === "low" ? LOW_KBPS : MEDIUM_KBPS,
|
kbps: MEDIUM_KBPS,
|
||||||
}
|
}
|
||||||
case "high":
|
case "high":
|
||||||
return highPlan(files)
|
return highPlan(files)
|
||||||
@@ -89,7 +84,7 @@ export function downloadPlan(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The download quality holding the same audio a stream plan plays, so a
|
* The download quality holding the same audio a stream plan plays, so a
|
||||||
* download can stand in for streaming.
|
* download can stand in for streaming. Low has no download equivalent.
|
||||||
*/
|
*/
|
||||||
export function streamDownloadQuality(
|
export function streamDownloadQuality(
|
||||||
plan: PlaybackStreamPlan
|
plan: PlaybackStreamPlan
|
||||||
@@ -100,7 +95,6 @@ export function streamDownloadQuality(
|
|||||||
}
|
}
|
||||||
if (plan.kbps === HIGH_KBPS) return "high"
|
if (plan.kbps === HIGH_KBPS) return "high"
|
||||||
if (plan.kbps === MEDIUM_KBPS) return "medium"
|
if (plan.kbps === MEDIUM_KBPS) return "medium"
|
||||||
if (plan.kbps === LOW_KBPS) return "low"
|
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +129,6 @@ export function downloadOptions(
|
|||||||
).length
|
).length
|
||||||
if (
|
if (
|
||||||
fallbackCount === songs.length &&
|
fallbackCount === songs.length &&
|
||||||
quality !== "low" &&
|
|
||||||
quality !== "medium" &&
|
quality !== "medium" &&
|
||||||
quality !== "high"
|
quality !== "high"
|
||||||
) {
|
) {
|
||||||
|
|||||||
Generated
-43
@@ -279,9 +279,6 @@ importers:
|
|||||||
'@react-native-community/slider':
|
'@react-native-community/slider':
|
||||||
specifier: 5.2.1
|
specifier: 5.2.1
|
||||||
version: 5.2.1(patch_hash=73deacaea9aae000a42050d343517da9e16e736e92a4fff3f61f81dba093a1c4)
|
version: 5.2.1(patch_hash=73deacaea9aae000a42050d343517da9e16e736e92a4fff3f61f81dba093a1c4)
|
||||||
'@react-native-masked-view/masked-view':
|
|
||||||
specifier: 0.3.2
|
|
||||||
version: 0.3.2(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1))(react@19.3.0)
|
|
||||||
'@react-native/metro-config':
|
'@react-native/metro-config':
|
||||||
specifier: 0.88.0
|
specifier: 0.88.0
|
||||||
version: 0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1)
|
version: 0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1)
|
||||||
@@ -366,18 +363,12 @@ importers:
|
|||||||
react-native:
|
react-native:
|
||||||
specifier: 0.88.0
|
specifier: 0.88.0
|
||||||
version: 0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1)
|
version: 0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1)
|
||||||
react-native-continued-task:
|
|
||||||
specifier: 0.1.0
|
|
||||||
version: 0.1.0(react-native-nitro-modules@0.37.2(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1))(react@19.3.0))(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1))(react@19.3.0)
|
|
||||||
react-native-gesture-handler:
|
react-native-gesture-handler:
|
||||||
specifier: ~3.3.0
|
specifier: ~3.3.0
|
||||||
version: 3.3.0(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1))(react@19.3.0)
|
version: 3.3.0(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1))(react@19.3.0)
|
||||||
react-native-image-colors:
|
react-native-image-colors:
|
||||||
specifier: ^2.6.0
|
specifier: ^2.6.0
|
||||||
version: 2.6.0(expo@58.0.17)(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1))(react@19.3.0)(supports-color@8.1.1)
|
version: 2.6.0(expo@58.0.17)(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1))(react@19.3.0)(supports-color@8.1.1)
|
||||||
react-native-nitro-modules:
|
|
||||||
specifier: 0.37.2
|
|
||||||
version: 0.37.2(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1))(react@19.3.0)
|
|
||||||
react-native-reanimated:
|
react-native-reanimated:
|
||||||
specifier: 4.7.1
|
specifier: 4.7.1
|
||||||
version: 4.7.1(patch_hash=badfed6babfff7fa495b3a06ba8f324be0e5ff82cedb6084f9f4d1dad65984d3)(react-native-worklets@0.13.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1))(react@19.3.0)(supports-color@8.1.1))(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1))(react@19.3.0)
|
version: 4.7.1(patch_hash=badfed6babfff7fa495b3a06ba8f324be0e5ff82cedb6084f9f4d1dad65984d3)(react-native-worklets@0.13.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1))(react@19.3.0)(supports-color@8.1.1))(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1))(react@19.3.0)
|
||||||
@@ -5447,9 +5438,6 @@ packages:
|
|||||||
sass:
|
sass:
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
nitro-core@0.37.2:
|
|
||||||
resolution: {integrity: sha512-dhagikz9VXXzfidRH/vPNJfYWPmTBArDOo9wE/wEqeERU9C8uRWz9YccOyNUOvADccPAZq319yzhDMoJ9excSQ==}
|
|
||||||
|
|
||||||
node-exports-info@1.6.2:
|
node-exports-info@1.6.2:
|
||||||
resolution: {integrity: sha512-kXs9Go0cah0qHVV2v389IXQLdLCeE1xfFtjOAF+iobu0OIoG1pje8At2vMHyaPMiPMnG/LWP50twML21eMcAag==}
|
resolution: {integrity: sha512-kXs9Go0cah0qHVV2v389IXQLdLCeE1xfFtjOAF+iobu0OIoG1pje8At2vMHyaPMiPMnG/LWP50twML21eMcAag==}
|
||||||
engines: {node: '>= 0.4'}
|
engines: {node: '>= 0.4'}
|
||||||
@@ -5901,16 +5889,6 @@ packages:
|
|||||||
react-is@19.2.7:
|
react-is@19.2.7:
|
||||||
resolution: {integrity: sha512-kZFnouyVv7eP/Phmrlo9FK+zcAdriZJvzxXHF1Sl1P377WSGe2G/JxVolhTrB/jeV47lKImhNUsijjHAAbcl/A==}
|
resolution: {integrity: sha512-kZFnouyVv7eP/Phmrlo9FK+zcAdriZJvzxXHF1Sl1P377WSGe2G/JxVolhTrB/jeV47lKImhNUsijjHAAbcl/A==}
|
||||||
|
|
||||||
react-native-continued-task@0.1.0:
|
|
||||||
resolution: {integrity: sha512-6x9YesK++u6vraaReebWEKbcDjMeRInsQzd+uWXAbNiXasgZ2zulTextzK/zBZ2mBrCZqTZVK60eoPp07BF0MA==}
|
|
||||||
peerDependencies:
|
|
||||||
react: '*'
|
|
||||||
react-native: '*'
|
|
||||||
react-native-nitro-modules: '*'
|
|
||||||
peerDependenciesMeta:
|
|
||||||
react-native-nitro-modules:
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
react-native-drawer-layout@4.2.12:
|
react-native-drawer-layout@4.2.12:
|
||||||
resolution: {integrity: sha512-qYmntEctkMSodN7pnC2llV21nswImLFPHJeT3PJXSJqZdU4jzDATR8iVi66sXkrtoOLJ2+EvXxgd7sMMpV4ViA==}
|
resolution: {integrity: sha512-qYmntEctkMSodN7pnC2llV21nswImLFPHJeT3PJXSJqZdU4jzDATR8iVi66sXkrtoOLJ2+EvXxgd7sMMpV4ViA==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
@@ -5938,12 +5916,6 @@ packages:
|
|||||||
react: '*'
|
react: '*'
|
||||||
react-native: '*'
|
react-native: '*'
|
||||||
|
|
||||||
react-native-nitro-modules@0.37.2:
|
|
||||||
resolution: {integrity: sha512-Odnrq/p6/q0R01qZlkqeXu9VHHMuGEnZZmyxMvehEu6QiACNHhBCmAHgyBDqOSo9Lb3G0TscFAT+HG0uxsR/GA==}
|
|
||||||
peerDependencies:
|
|
||||||
react: '*'
|
|
||||||
react-native: '*'
|
|
||||||
|
|
||||||
react-native-reanimated@4.7.1:
|
react-native-reanimated@4.7.1:
|
||||||
resolution: {integrity: sha512-HviDFSZ6V4KTRsrLS6hRbBJ4j63l/L8a5az0EoWdJwaMLYnBNyYISTDxwXpEYkMbAbLzCMCviIdiOxXHYQWcNA==}
|
resolution: {integrity: sha512-HviDFSZ6V4KTRsrLS6hRbBJ4j63l/L8a5az0EoWdJwaMLYnBNyYISTDxwXpEYkMbAbLzCMCviIdiOxXHYQWcNA==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
@@ -12501,8 +12473,6 @@ snapshots:
|
|||||||
- '@types/node'
|
- '@types/node'
|
||||||
- babel-plugin-macros
|
- babel-plugin-macros
|
||||||
|
|
||||||
nitro-core@0.37.2: {}
|
|
||||||
|
|
||||||
node-exports-info@1.6.2:
|
node-exports-info@1.6.2:
|
||||||
dependencies:
|
dependencies:
|
||||||
array.prototype.flatmap: 1.3.3
|
array.prototype.flatmap: 1.3.3
|
||||||
@@ -12966,13 +12936,6 @@ snapshots:
|
|||||||
|
|
||||||
react-is@19.2.7: {}
|
react-is@19.2.7: {}
|
||||||
|
|
||||||
react-native-continued-task@0.1.0(react-native-nitro-modules@0.37.2(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1))(react@19.3.0))(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1))(react@19.3.0):
|
|
||||||
dependencies:
|
|
||||||
react: 19.3.0
|
|
||||||
react-native: 0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1)
|
|
||||||
optionalDependencies:
|
|
||||||
react-native-nitro-modules: 0.37.2(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1))(react@19.3.0)
|
|
||||||
|
|
||||||
react-native-drawer-layout@4.2.12(309f9235979e0472ca5a2d24f8d225b6):
|
react-native-drawer-layout@4.2.12(309f9235979e0472ca5a2d24f8d225b6):
|
||||||
dependencies:
|
dependencies:
|
||||||
color: 4.2.3
|
color: 4.2.3
|
||||||
@@ -13004,12 +12967,6 @@ snapshots:
|
|||||||
react: 19.3.0
|
react: 19.3.0
|
||||||
react-native: 0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1)
|
react-native: 0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1)
|
||||||
|
|
||||||
react-native-nitro-modules@0.37.2(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1))(react@19.3.0):
|
|
||||||
dependencies:
|
|
||||||
nitro-core: 0.37.2
|
|
||||||
react: 19.3.0
|
|
||||||
react-native: 0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1)
|
|
||||||
|
|
||||||
react-native-reanimated@4.7.1(patch_hash=badfed6babfff7fa495b3a06ba8f324be0e5ff82cedb6084f9f4d1dad65984d3)(react-native-worklets@0.13.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1))(react@19.3.0)(supports-color@8.1.1))(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1))(react@19.3.0):
|
react-native-reanimated@4.7.1(patch_hash=badfed6babfff7fa495b3a06ba8f324be0e5ff82cedb6084f9f4d1dad65984d3)(react-native-worklets@0.13.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1))(react@19.3.0)(supports-color@8.1.1))(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1))(react@19.3.0):
|
||||||
dependencies:
|
dependencies:
|
||||||
react: 19.3.0
|
react: 19.3.0
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# Uploads a file to the Gitea release for the current tag, creating the release
|
|
||||||
# if it does not exist yet. Used by .gitea/workflows/mobile-build.yml.
|
|
||||||
# Usage: GITEA_TOKEN=... upload-release-asset.sh <file>
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
file=$1
|
|
||||||
api="$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY/releases"
|
|
||||||
auth=(-H "Authorization: token $GITEA_TOKEN")
|
|
||||||
json_id() { node -pe 'JSON.parse(require("fs").readFileSync(0, "utf8")).id'; }
|
|
||||||
|
|
||||||
existing_id() { curl -fsS "${auth[@]}" "$api/tags/$GITHUB_REF_NAME" | json_id; }
|
|
||||||
create_id() {
|
|
||||||
curl -fsS "${auth[@]}" -H "Content-Type: application/json" \
|
|
||||||
-d "{\"tag_name\":\"$GITHUB_REF_NAME\",\"name\":\"$GITHUB_REF_NAME\"}" "$api" | json_id
|
|
||||||
}
|
|
||||||
|
|
||||||
# Android and iOS race to create the release; whoever loses re-reads it.
|
|
||||||
id=$(existing_id 2>/dev/null || create_id || existing_id)
|
|
||||||
|
|
||||||
curl -fsS "${auth[@]}" -F "attachment=@$file" \
|
|
||||||
"$api/$id/assets?name=$(basename "$file")" > /dev/null
|
|
||||||
Reference in new issue
Block a user