Compare commits
20
Commits
No files matched your search
@@ -0,0 +1,97 @@
|
|||||||
|
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 and ADTS) and FLAC.
|
# the app writes: AAC (HLS, ADTS and .m4a downloads) 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,mpegts \
|
--enable-muxer=adts,flac,hls,ipod,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,6 +32,13 @@ 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"]
|
||||||
: []),
|
: []),
|
||||||
|
|||||||
+13
-10
@@ -1,5 +1,6 @@
|
|||||||
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 { useStackScreenOptions, tabStackScreenTitles } from "@/lib/navigation"
|
||||||
import { tabletSections, TabletSectionContext } from "@/lib/tablet-navigation"
|
import { tabletSections, TabletSectionContext } from "@/lib/tablet-navigation"
|
||||||
@@ -10,16 +11,18 @@ export default function TabletSectionLayout({ segment }: { segment: string }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<TabletSectionContext value={section}>
|
<TabletSectionContext value={section}>
|
||||||
<Stack
|
<TabStackContext value={section?.group}>
|
||||||
screenLayout={renderTabScreenContent}
|
<Stack
|
||||||
screenOptions={({ route }) => ({
|
screenLayout={renderTabScreenContent}
|
||||||
...options,
|
screenOptions={({ route }) => ({
|
||||||
title:
|
...options,
|
||||||
route.name === "index"
|
title:
|
||||||
? section?.title
|
route.name === "index"
|
||||||
: tabStackScreenTitles[route.name],
|
? section?.title
|
||||||
})}
|
: tabStackScreenTitles[route.name],
|
||||||
/>
|
})}
|
||||||
|
/>
|
||||||
|
</TabStackContext>
|
||||||
</TabletSectionContext>
|
</TabletSectionContext>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
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 { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
|
||||||
|
|
||||||
@@ -12,24 +13,26 @@ export default function HomeLayout() {
|
|||||||
const baseOptions = useStackScreenOptions({ title: "Home" })
|
const baseOptions = useStackScreenOptions({ title: "Home" })
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<TabStackContext value="home">
|
||||||
screenLayout={renderTabScreenContent}
|
<Stack
|
||||||
screenOptions={({ route }) => ({
|
screenLayout={renderTabScreenContent}
|
||||||
...baseOptions,
|
screenOptions={({ route }) => ({
|
||||||
title: tabStackScreenTitles[route.name] ?? "Home",
|
...baseOptions,
|
||||||
headerRight:
|
title: tabStackScreenTitles[route.name] ?? "Home",
|
||||||
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
headerRight:
|
||||||
unstable_headerRightItems:
|
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
||||||
route.name === "index"
|
unstable_headerRightItems:
|
||||||
? () => [
|
route.name === "index"
|
||||||
{
|
? () => [
|
||||||
type: "custom",
|
{
|
||||||
element: <ProfileHeaderButton />,
|
type: "custom",
|
||||||
hidesSharedBackground: true,
|
element: <ProfileHeaderButton />,
|
||||||
},
|
hidesSharedBackground: true,
|
||||||
]
|
},
|
||||||
: undefined,
|
]
|
||||||
})}
|
: undefined,
|
||||||
/>
|
})}
|
||||||
|
/>
|
||||||
|
</TabStackContext>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -105,21 +105,21 @@ export default function OtherDownloadsScreen() {
|
|||||||
ListHeaderComponent={
|
ListHeaderComponent={
|
||||||
songs.length > 0 ? (
|
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.shuffle, { backgroundColor: colors.card }]}
|
style={[styles.iconAction, { backgroundColor: colors.muted }]}
|
||||||
>
|
>
|
||||||
<Ionicons name="shuffle" size={24} color={colors.foreground} />
|
<Ionicons name="shuffle" size={24} color={colors.foreground} />
|
||||||
</Pressable>
|
</Pressable>
|
||||||
|
<Button
|
||||||
|
title="Play"
|
||||||
|
icon="play"
|
||||||
|
onPress={() => void playInOrder(playableIds, PLAY_ORIGIN)}
|
||||||
|
style={styles.playButton}
|
||||||
|
/>
|
||||||
</View>
|
</View>
|
||||||
) : undefined
|
) : undefined
|
||||||
}
|
}
|
||||||
@@ -137,14 +137,15 @@ 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,
|
||||||
},
|
},
|
||||||
play: { flex: 1 },
|
playButton: { borderRadius: 999, minWidth: 160 },
|
||||||
shuffle: {
|
iconAction: {
|
||||||
width: 48,
|
width: 44,
|
||||||
height: 48,
|
height: 44,
|
||||||
borderRadius: 24,
|
borderRadius: 22,
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
import { atmosEnabled, dolbyAtmosSupported } from "@/lib/playback-capabilities"
|
import {
|
||||||
|
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"
|
||||||
@@ -25,7 +29,6 @@ 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,
|
||||||
@@ -450,9 +453,10 @@ 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> = {
|
||||||
medium: 0.25,
|
low: 0.2,
|
||||||
high: 0.45,
|
medium: 0.35,
|
||||||
lossless: 0.7,
|
high: 0.5,
|
||||||
|
lossless: 0.75,
|
||||||
atmos: 1,
|
atmos: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -507,7 +511,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" },
|
||||||
...DOWNLOAD_QUALITIES.map((quality) => ({
|
...deviceDownloadQualities.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,6 +2,7 @@ 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 { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
|
||||||
|
|
||||||
@@ -14,26 +15,28 @@ export default function LibraryLayout() {
|
|||||||
const baseOptions = useStackScreenOptions({ title: "Library" })
|
const baseOptions = useStackScreenOptions({ title: "Library" })
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<TabStackContext value="library">
|
||||||
screenLayout={renderTabScreenContent}
|
<Stack
|
||||||
screenOptions={({ route }) => ({
|
screenLayout={renderTabScreenContent}
|
||||||
...baseOptions,
|
screenOptions={({ route }) => ({
|
||||||
title:
|
...baseOptions,
|
||||||
tabStackScreenTitles[route.name] ??
|
title:
|
||||||
(tabletLayout ? "Recently Added" : "Library"),
|
tabStackScreenTitles[route.name] ??
|
||||||
headerRight:
|
(tabletLayout ? "Recently Added" : "Library"),
|
||||||
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
headerRight:
|
||||||
unstable_headerRightItems:
|
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
||||||
route.name === "index"
|
unstable_headerRightItems:
|
||||||
? () => [
|
route.name === "index"
|
||||||
{
|
? () => [
|
||||||
type: "custom",
|
{
|
||||||
element: <ProfileHeaderButton />,
|
type: "custom",
|
||||||
hidesSharedBackground: true,
|
element: <ProfileHeaderButton />,
|
||||||
},
|
hidesSharedBackground: true,
|
||||||
]
|
},
|
||||||
: undefined,
|
]
|
||||||
})}
|
: undefined,
|
||||||
/>
|
})}
|
||||||
|
/>
|
||||||
|
</TabStackContext>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
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 { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
|
||||||
|
|
||||||
@@ -12,24 +13,26 @@ export default function SearchLayout() {
|
|||||||
const baseOptions = useStackScreenOptions({ title: "Search" })
|
const baseOptions = useStackScreenOptions({ title: "Search" })
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<TabStackContext value="search">
|
||||||
screenLayout={renderTabScreenContent}
|
<Stack
|
||||||
screenOptions={({ route }) => ({
|
screenLayout={renderTabScreenContent}
|
||||||
...baseOptions,
|
screenOptions={({ route }) => ({
|
||||||
title: tabStackScreenTitles[route.name] ?? "Search",
|
...baseOptions,
|
||||||
headerRight:
|
title: tabStackScreenTitles[route.name] ?? "Search",
|
||||||
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
headerRight:
|
||||||
unstable_headerRightItems:
|
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
||||||
route.name === "index"
|
unstable_headerRightItems:
|
||||||
? () => [
|
route.name === "index"
|
||||||
{
|
? () => [
|
||||||
type: "custom",
|
{
|
||||||
element: <ProfileHeaderButton />,
|
type: "custom",
|
||||||
hidesSharedBackground: true,
|
element: <ProfileHeaderButton />,
|
||||||
},
|
hidesSharedBackground: true,
|
||||||
]
|
},
|
||||||
: undefined,
|
]
|
||||||
})}
|
: undefined,
|
||||||
/>
|
})}
|
||||||
|
/>
|
||||||
|
</TabStackContext>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,13 @@
|
|||||||
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react"
|
import {
|
||||||
|
memo,
|
||||||
|
type ComponentType,
|
||||||
|
type ReactElement,
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useMemo,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
} from "react"
|
||||||
import {
|
import {
|
||||||
Pressable,
|
Pressable,
|
||||||
ScrollView,
|
ScrollView,
|
||||||
@@ -6,25 +15,43 @@ 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, {
|
||||||
|
useAnimatedStyle,
|
||||||
|
type SharedValue,
|
||||||
|
} from "react-native-reanimated"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
usePlaybackActions,
|
usePlaybackActions,
|
||||||
usePlaybackProgress,
|
usePlaybackProgress,
|
||||||
usePlaybackQueue,
|
usePlaybackQueue,
|
||||||
} from "@/contexts/playback"
|
} from "@/contexts/playback"
|
||||||
import { useLyricsTime } from "@/hooks/use-lyrics"
|
import { useLyricsTime, usePlaybackClock } from "@/hooks/use-lyrics"
|
||||||
import type { NowPlayingColors } from "@/lib/now-playing-colors"
|
import type { NowPlayingColors } from "@/lib/now-playing-colors"
|
||||||
import {
|
import {
|
||||||
activeLineIndex,
|
activeLineIndex,
|
||||||
type LyricLine,
|
type LyricLine,
|
||||||
|
type LyricWord,
|
||||||
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. */
|
||||||
|
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
|
||||||
@@ -65,24 +92,28 @@ 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)
|
||||||
const lineOffsets = useRef<number[]>([])
|
const lineOffsets = useRef<number[]>([])
|
||||||
const [height, setHeight] = useState(0)
|
const [height, setHeight] = useState(0)
|
||||||
const manualScrollAt = useRef(0)
|
// While the listener scrolls, lines stay sharp and the view stays put.
|
||||||
|
const [browsing, setBrowsing] = useState(false)
|
||||||
|
const browseTimer = useRef<ReturnType<typeof setTimeout>>(undefined)
|
||||||
|
|
||||||
|
useEffect(() => () => clearTimeout(browseTimer.current), [])
|
||||||
|
|
||||||
const scrollToLine = useCallback(
|
const scrollToLine = useCallback(
|
||||||
(index: number) => {
|
(index: number) => {
|
||||||
const y = lineOffsets.current[Math.max(index, 0)]
|
const y = lineOffsets.current[Math.max(index, 0)]
|
||||||
if (y === undefined || !synced || height === 0) return
|
if (y === undefined || !synced || height === 0 || browsing) return
|
||||||
if (Date.now() - manualScrollAt.current < MANUAL_SCROLL_HOLD_MS) return
|
|
||||||
scrollRef.current?.scrollTo({
|
scrollRef.current?.scrollTo({
|
||||||
y: Math.max(0, y - height * ACTIVE_LINE_POSITION),
|
y: Math.max(0, y - height * ACTIVE_LINE_POSITION),
|
||||||
animated: true,
|
animated: true,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
[height, synced]
|
[height, synced, browsing]
|
||||||
)
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -106,11 +137,20 @@ function LyricsLines({
|
|||||||
(seconds: number) => {
|
(seconds: number) => {
|
||||||
seekTo(seconds)
|
seekTo(seconds)
|
||||||
setIsPlaying(true)
|
setIsPlaying(true)
|
||||||
manualScrollAt.current = 0
|
clearTimeout(browseTimer.current)
|
||||||
|
setBrowsing(false)
|
||||||
},
|
},
|
||||||
[seekTo, setIsPlaying]
|
[seekTo, setIsPlaying]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const releaseScroll = () => {
|
||||||
|
clearTimeout(browseTimer.current)
|
||||||
|
browseTimer.current = setTimeout(
|
||||||
|
() => setBrowsing(false),
|
||||||
|
MANUAL_SCROLL_HOLD_MS
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const lineStyle = useMemo(
|
const lineStyle = useMemo(
|
||||||
() => ({ fontSize, lineHeight: Math.round(fontSize * 1.18) }),
|
() => ({ fontSize, lineHeight: Math.round(fontSize * 1.18) }),
|
||||||
[fontSize]
|
[fontSize]
|
||||||
@@ -127,12 +167,12 @@ function LyricsLines({
|
|||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
onLayout={(event) => setHeight(event.nativeEvent.layout.height)}
|
onLayout={(event) => setHeight(event.nativeEvent.layout.height)}
|
||||||
onScrollBeginDrag={() => {
|
onScrollBeginDrag={() => {
|
||||||
manualScrollAt.current = Date.now()
|
clearTimeout(browseTimer.current)
|
||||||
}}
|
setBrowsing(true)
|
||||||
onMomentumScrollEnd={() => {
|
|
||||||
// Hold from when the scroll settles, not when the finger lifted.
|
|
||||||
if (manualScrollAt.current > 0) manualScrollAt.current = Date.now()
|
|
||||||
}}
|
}}
|
||||||
|
// Hold from when the scroll settles, not when the finger lifted.
|
||||||
|
onScrollEndDrag={releaseScroll}
|
||||||
|
onMomentumScrollEnd={releaseScroll}
|
||||||
>
|
>
|
||||||
{lyrics.lines.map((line, index) =>
|
{lyrics.lines.map((line, index) =>
|
||||||
synced ? (
|
synced ? (
|
||||||
@@ -140,10 +180,13 @@ function LyricsLines({
|
|||||||
key={index}
|
key={index}
|
||||||
index={index}
|
index={index}
|
||||||
line={line}
|
line={line}
|
||||||
state={
|
distance={
|
||||||
index === active ? "active" : index < active ? "past" : "next"
|
browsing
|
||||||
|
? 0
|
||||||
|
: Math.min(Math.abs(index - active), LINE_BLUR.length - 1)
|
||||||
}
|
}
|
||||||
time={index === active ? time : null}
|
active={index === active}
|
||||||
|
clock={clock}
|
||||||
colors={colors}
|
colors={colors}
|
||||||
textStyle={lineStyle}
|
textStyle={lineStyle}
|
||||||
onSelect={playFrom}
|
onSelect={playFrom}
|
||||||
@@ -171,14 +214,16 @@ function LyricsLines({
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One timed line. Only the playing line gets the time, so the others skip
|
* One timed line, laid out word by word whether or not it is playing, so it
|
||||||
* re-rendering as the song plays.
|
* never re-wraps. It fades and blurs by its `distance` from the playing line,
|
||||||
|
* and only the playing line's words fill.
|
||||||
*/
|
*/
|
||||||
const SyncedLine = memo(function SyncedLine({
|
const SyncedLine = memo(function SyncedLine({
|
||||||
index,
|
index,
|
||||||
line,
|
line,
|
||||||
state,
|
distance,
|
||||||
time,
|
active,
|
||||||
|
clock,
|
||||||
colors,
|
colors,
|
||||||
textStyle,
|
textStyle,
|
||||||
onSelect,
|
onSelect,
|
||||||
@@ -186,14 +231,15 @@ const SyncedLine = memo(function SyncedLine({
|
|||||||
}: {
|
}: {
|
||||||
index: number
|
index: number
|
||||||
line: LyricLine
|
line: LyricLine
|
||||||
state: "past" | "active" | "next"
|
distance: number
|
||||||
time: number | null
|
active: boolean
|
||||||
|
clock: SharedValue<number>
|
||||||
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 active = state === "active"
|
const wordStyle = [styles.lineText, textStyle, { color: colors.foreground }]
|
||||||
return (
|
return (
|
||||||
<Pressable
|
<Pressable
|
||||||
onPress={() => onSelect(line.start ?? 0)}
|
onPress={() => onSelect(line.start ?? 0)}
|
||||||
@@ -202,42 +248,104 @@ const SyncedLine = memo(function SyncedLine({
|
|||||||
accessibilityHint="Plays from this line"
|
accessibilityHint="Plays from this line"
|
||||||
style={styles.line}
|
style={styles.line}
|
||||||
>
|
>
|
||||||
<Text
|
<Animated.View
|
||||||
style={[
|
style={{
|
||||||
styles.lineText,
|
opacity: active ? 1 : INACTIVE_LINE_OPACITY,
|
||||||
textStyle,
|
filter: [{ blur: LINE_BLUR[distance] }],
|
||||||
{
|
transitionProperty: ["opacity", "filter"],
|
||||||
color:
|
transitionDuration: LINE_FADE_MS,
|
||||||
active && !line.words ? colors.foreground : colors.lyricsInactive,
|
}}
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
>
|
||||||
{active && line.words
|
{line.words ? (
|
||||||
? line.words.map((word, wordIndex) => (
|
<View
|
||||||
<Text
|
style={[styles.words, { columnGap: textStyle.fontSize * 0.25 }]}
|
||||||
key={wordIndex}
|
>
|
||||||
style={{
|
{line.words.map((word, wordIndex) =>
|
||||||
color:
|
active ? (
|
||||||
time !== null && time >= word.start
|
<FilledWord
|
||||||
? colors.foreground
|
key={wordIndex}
|
||||||
: colors.lyricsUnsung,
|
word={word}
|
||||||
}}
|
clock={clock}
|
||||||
>
|
colors={colors}
|
||||||
{word.text}
|
textStyle={textStyle}
|
||||||
</Text>
|
/>
|
||||||
))
|
) : (
|
||||||
: line.text}
|
<Text key={wordIndex} style={wordStyle}>
|
||||||
</Text>
|
{word.text.trim()}
|
||||||
|
</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
|
||||||
|
* it is sung: a gradient 2.5 times its width slides under the word's
|
||||||
|
* shape, like the web panel's.
|
||||||
|
*/
|
||||||
|
function FilledWord({
|
||||||
|
word,
|
||||||
|
clock,
|
||||||
|
colors,
|
||||||
|
textStyle,
|
||||||
|
}: {
|
||||||
|
word: LyricWord
|
||||||
|
clock: SharedValue<number>
|
||||||
|
colors: NowPlayingColors
|
||||||
|
textStyle: { fontSize: number; lineHeight: number }
|
||||||
|
}) {
|
||||||
|
const text = word.text.trim()
|
||||||
|
const slide = useAnimatedStyle(() => {
|
||||||
|
const progress =
|
||||||
|
(clock.value - word.start) / Math.max(word.end - word.start, 0.05)
|
||||||
|
const sung = 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 (
|
||||||
|
<MaskedView
|
||||||
|
maskElement={
|
||||||
|
<Text style={[styles.lineText, textStyle, styles.mask]}>{text}</Text>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{/* Sizes the word; the mask draws it. */}
|
||||||
|
<Text style={[styles.lineText, textStyle, styles.hidden]}>{text}</Text>
|
||||||
|
<Animated.View
|
||||||
|
style={[
|
||||||
|
styles.fillGradient,
|
||||||
|
{
|
||||||
|
backgroundImage: `linear-gradient(90deg, ${colors.foreground} 40%, ${colors.lyricsUnsung} 60%)`,
|
||||||
|
},
|
||||||
|
slide,
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</MaskedView>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
fill: { flex: 1 },
|
fill: { flex: 1 },
|
||||||
empty: { flex: 1, alignItems: "center", justifyContent: "center" },
|
empty: { flex: 1, alignItems: "center", justifyContent: "center" },
|
||||||
emptyText: { fontSize: 17, fontWeight: "600" },
|
emptyText: { fontSize: 17, fontWeight: "600" },
|
||||||
line: { paddingVertical: 9 },
|
line: { paddingVertical: 9 },
|
||||||
lineText: { fontWeight: "800" },
|
lineText: { fontWeight: "800" },
|
||||||
|
words: { flexDirection: "row", flexWrap: "wrap" },
|
||||||
|
mask: { color: "black" },
|
||||||
|
hidden: { opacity: 0 },
|
||||||
|
fillGradient: {
|
||||||
|
position: "absolute",
|
||||||
|
top: 0,
|
||||||
|
bottom: 0,
|
||||||
|
left: 0,
|
||||||
|
width: "250%",
|
||||||
|
},
|
||||||
plainLine: { fontWeight: "700", paddingVertical: 2 },
|
plainLine: { fontWeight: "700", paddingVertical: 2 },
|
||||||
stanzaGap: { height: 18 },
|
stanzaGap: { height: 18 },
|
||||||
})
|
})
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
import {
|
import { useAndroidTabPalette } from "@/contexts/android-tab-theme"
|
||||||
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"
|
||||||
@@ -166,20 +163,10 @@ 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,
|
||||||
@@ -267,7 +254,6 @@ 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",
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ 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 {
|
||||||
@@ -33,6 +34,7 @@ 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"
|
||||||
@@ -237,36 +239,44 @@ function DownloadQualityPopup({
|
|||||||
>
|
>
|
||||||
{pending?.target.title}
|
{pending?.target.title}
|
||||||
</Text>
|
</Text>
|
||||||
{pending?.response.options.map((option) => (
|
{pending?.response.options
|
||||||
<Pressable
|
.filter((option) => downloadQualitySupported(option.quality))
|
||||||
key={option.quality}
|
.map((option) => (
|
||||||
accessibilityRole="button"
|
<Pressable
|
||||||
style={[styles.row, { borderBottomColor: colors.border }]}
|
key={option.quality}
|
||||||
onPress={() => onPick(option.quality, remember)}
|
accessibilityRole="button"
|
||||||
>
|
style={[styles.row, { borderBottomColor: colors.border }]}
|
||||||
<View style={styles.rowText}>
|
onPress={() => onPick(option.quality, remember)}
|
||||||
{option.quality === "lossless" ||
|
>
|
||||||
option.quality === "atmos" ? (
|
<View style={styles.rowText}>
|
||||||
<AudioFormatBadge
|
{option.quality === "lossless" ||
|
||||||
format={option.quality}
|
option.quality === "atmos" ? (
|
||||||
color={colors.foreground}
|
<AudioFormatBadge
|
||||||
backgroundColor={colors.card}
|
format={option.quality}
|
||||||
/>
|
color={colors.foreground}
|
||||||
) : (
|
backgroundColor={colors.card}
|
||||||
<Text style={[styles.label, { color: colors.foreground }]}>
|
/>
|
||||||
{DOWNLOAD_QUALITY_LABELS[option.quality]}
|
) : (
|
||||||
|
<Text
|
||||||
|
style={[styles.label, { color: colors.foreground }]}
|
||||||
|
>
|
||||||
|
{DOWNLOAD_QUALITY_LABELS[option.quality]}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
<Text
|
||||||
|
style={{ color: colors.mutedForeground, fontSize: 12 }}
|
||||||
|
>
|
||||||
|
{optionDetail(option, songCount)}
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
</View>
|
||||||
<Text style={{ color: colors.mutedForeground, fontSize: 12 }}>
|
<Text
|
||||||
{optionDetail(option, songCount)}
|
style={[styles.size, { color: colors.mutedForeground }]}
|
||||||
|
>
|
||||||
|
{option.estimated ? "~" : ""}
|
||||||
|
{formatBytes(option.bytes)}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</Pressable>
|
||||||
<Text style={[styles.size, { color: colors.mutedForeground }]}>
|
))}
|
||||||
{option.estimated ? "~" : ""}
|
|
||||||
{formatBytes(option.bytes)}
|
|
||||||
</Text>
|
|
||||||
</Pressable>
|
|
||||||
))}
|
|
||||||
<View style={styles.rememberRow}>
|
<View style={styles.rememberRow}>
|
||||||
<Text style={{ color: colors.foreground, fontSize: 15 }}>
|
<Text style={{ color: colors.foreground, fontSize: 15 }}>
|
||||||
Remember my choice
|
Remember my choice
|
||||||
@@ -344,6 +354,7 @@ 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
|
||||||
@@ -391,6 +402,7 @@ 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 })
|
||||||
@@ -399,7 +411,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, queue]
|
[cacheScope, config, convex, keepDownloading, queue]
|
||||||
)
|
)
|
||||||
|
|
||||||
const removeDownload = useCallback(
|
const removeDownload = useCallback(
|
||||||
@@ -417,9 +429,14 @@ 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(queue, pending.target, pending.response.songs, quality)
|
void startDownload(
|
||||||
|
queue,
|
||||||
|
pending.target,
|
||||||
|
pending.response.songs,
|
||||||
|
quality
|
||||||
|
).then(keepDownloading)
|
||||||
},
|
},
|
||||||
[pending, queue]
|
[keepDownloading, pending, queue]
|
||||||
)
|
)
|
||||||
|
|
||||||
const value = useMemo(
|
const value = useMemo(
|
||||||
|
|||||||
@@ -9,15 +9,13 @@
|
|||||||
"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": {
|
||||||
|
|||||||
@@ -0,0 +1,164 @@
|
|||||||
|
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,5 +1,18 @@
|
|||||||
import { File } from "expo-file-system"
|
import { File } from "expo-file-system"
|
||||||
import { useEffect, useMemo, useState, useSyncExternalStore } from "react"
|
import {
|
||||||
|
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"
|
||||||
@@ -107,3 +120,39 @@ 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 { useCallback } from "react"
|
import { createContext, use, useCallback } from "react"
|
||||||
|
|
||||||
import { tabletSections } from "@/lib/tablet-navigation"
|
import { tabletSections } from "@/lib/tablet-navigation"
|
||||||
|
|
||||||
@@ -30,6 +30,13 @@ 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)
|
||||||
}
|
}
|
||||||
@@ -41,8 +48,15 @@ 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) => {
|
||||||
@@ -53,26 +67,26 @@ export function useAppNavigation() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
router.push(tabPath(getActiveTabFromRef(), path))
|
router.push(tabPath(currentTab(), path))
|
||||||
},
|
},
|
||||||
[router]
|
[router, currentTab]
|
||||||
)
|
)
|
||||||
|
|
||||||
const replace = useCallback(
|
const replace = useCallback(
|
||||||
(path: string) => {
|
(path: string) => {
|
||||||
router.replace(tabPath(getActiveTabFromRef(), path))
|
router.replace(tabPath(currentTab(), path))
|
||||||
},
|
},
|
||||||
[router]
|
[router, currentTab]
|
||||||
)
|
)
|
||||||
|
|
||||||
const href = useCallback(
|
const href = useCallback(
|
||||||
(path: string) => tabPath(getActiveTabFromRef(), path),
|
(path: string) => tabPath(currentTab(), path),
|
||||||
[]
|
[currentTab]
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
get tab() {
|
get tab() {
|
||||||
return getActiveTabFromRef()
|
return currentTab()
|
||||||
},
|
},
|
||||||
href,
|
href,
|
||||||
push,
|
push,
|
||||||
|
|||||||
@@ -16,9 +16,16 @@ 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)),
|
||||||
@@ -31,7 +38,7 @@ export async function getAuthCookieHeader(
|
|||||||
|
|
||||||
const names = authCookieNames(serverUrl)
|
const names = authCookieNames(serverUrl)
|
||||||
const parts = [`${names.jwt}=${jwt}`]
|
const parts = [`${names.jwt}=${jwt}`]
|
||||||
if (refreshToken) {
|
if (refresh && refreshToken) {
|
||||||
parts.push(`${names.refresh}=${refreshToken}`)
|
parts.push(`${names.refresh}=${refreshToken}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,19 +12,28 @@ 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 {
|
||||||
return await SecureStore.getItemAsync(key, secureStoreOptions)
|
const value = await SecureStore.getItemAsync(key, secureStoreOptions)
|
||||||
|
if (value === null) remembered.delete(key)
|
||||||
|
else remembered.set(key, value)
|
||||||
|
return value
|
||||||
} catch {
|
} catch {
|
||||||
return null
|
return remembered.get(key) ?? 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 {
|
||||||
|
|||||||
+100
-12
@@ -1,5 +1,5 @@
|
|||||||
import AsyncStorage from "@react-native-async-storage/async-storage"
|
import AsyncStorage from "@react-native-async-storage/async-storage"
|
||||||
import { Directory, File, Paths } from "expo-file-system"
|
import { Directory, DownloadTask, File, Paths } from "expo-file-system"
|
||||||
import { Platform } from "react-native"
|
import { Platform } from "react-native"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -16,6 +16,7 @@ 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"
|
||||||
@@ -73,6 +74,82 @@ 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")
|
||||||
@@ -116,7 +193,8 @@ 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")
|
||||||
|
|
||||||
@@ -126,17 +204,26 @@ function createStorage(config: ServerConfig): DownloadStorage {
|
|||||||
if (partial.exists) partial.delete()
|
if (partial.exists) partial.delete()
|
||||||
partial.create()
|
partial.create()
|
||||||
try {
|
try {
|
||||||
const path = songDownloadPath(songId, requested, {
|
const url = `${config.serverUrl}${songDownloadPath(songId, requested, {
|
||||||
losslessFormat: Platform.OS === "ios" ? "alac" : undefined,
|
losslessFormat: Platform.OS === "ios" ? "alac" : undefined,
|
||||||
|
})}`
|
||||||
|
const download =
|
||||||
|
Platform.OS === "ios" ? downloadOnIOS : downloadInForeground
|
||||||
|
return await download({
|
||||||
|
url,
|
||||||
|
destination: partial,
|
||||||
|
headers: { Cookie: cookieHeader },
|
||||||
|
signal,
|
||||||
|
finish(file) {
|
||||||
|
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)
|
||||||
|
return file.size ?? 0
|
||||||
|
},
|
||||||
})
|
})
|
||||||
const file = await File.downloadFileAsync(
|
|
||||||
`${config.serverUrl}${path}`,
|
|
||||||
partial,
|
|
||||||
{ headers: { Cookie: cookieHeader }, signal }
|
|
||||||
)
|
|
||||||
signal.throwIfAborted()
|
|
||||||
partial.rename(name)
|
|
||||||
return file.size ?? 0
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (partial.exists) partial.delete()
|
if (partial.exists) partial.delete()
|
||||||
throw error
|
throw error
|
||||||
@@ -212,9 +299,10 @@ export function downloadedCoverUri(url: string) {
|
|||||||
|
|
||||||
export async function readRememberedDownloadQuality() {
|
export async function readRememberedDownloadQuality() {
|
||||||
try {
|
try {
|
||||||
return parseDownloadQuality(
|
const quality = 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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ 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
|
||||||
@@ -32,7 +30,6 @@ 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,5 +1,10 @@
|
|||||||
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"
|
||||||
|
|
||||||
@@ -7,3 +12,13 @@ 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
|
||||||
|
)
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
plugins {
|
||||||
|
id 'com.android.library'
|
||||||
|
id 'expo-module-gradle-plugin'
|
||||||
|
}
|
||||||
|
|
||||||
|
group = 'expo.modules.downloadservice'
|
||||||
|
version = '1.0.0'
|
||||||
|
|
||||||
|
android {
|
||||||
|
namespace 'expo.modules.downloadservice'
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<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
@@ -0,0 +1,88 @@
|
|||||||
|
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
@@ -0,0 +1,15 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"platforms": ["android"],
|
||||||
|
"android": {
|
||||||
|
"modules": ["expo.modules.downloadservice.DownloadServiceModule"]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"name": "otunes-download-service",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"platforms": ["apple"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
// 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
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
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,6 +20,7 @@
|
|||||||
"@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",
|
||||||
@@ -48,8 +49,10 @@
|
|||||||
"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,6 +114,7 @@ export function AlbumView({
|
|||||||
}) {
|
}) {
|
||||||
const {
|
const {
|
||||||
isSongFavorite,
|
isSongFavorite,
|
||||||
|
areSongsFavorite,
|
||||||
isAlbumFavorite,
|
isAlbumFavorite,
|
||||||
toggleSongFavorite,
|
toggleSongFavorite,
|
||||||
toggleAlbumFavorite,
|
toggleAlbumFavorite,
|
||||||
@@ -154,6 +155,7 @@ 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(
|
||||||
() =>
|
() =>
|
||||||
@@ -413,6 +415,7 @@ 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,9 +39,10 @@ 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> = {
|
||||||
medium: 0.25,
|
low: 0.2,
|
||||||
high: 0.45,
|
medium: 0.35,
|
||||||
lossless: 0.7,
|
high: 0.5,
|
||||||
|
lossless: 0.75,
|
||||||
atmos: 1,
|
atmos: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ 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>
|
||||||
favoriteSongs: (songIds: Id<"songs">[]) => Promise<void>
|
/** True when `songIds` is non-empty and every song is favorited. */
|
||||||
|
areSongsFavorite: (songIds: Iterable<string>) => boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const FavoritesContext = React.createContext<FavoritesContextValue | null>(null)
|
const FavoritesContext = React.createContext<FavoritesContextValue | null>(null)
|
||||||
@@ -130,26 +131,16 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
|
|||||||
[songIds, favoriteSong, unfavoriteSong]
|
[songIds, favoriteSong, unfavoriteSong]
|
||||||
)
|
)
|
||||||
|
|
||||||
const favoriteSongs = React.useCallback(
|
const areSongsFavorite = React.useCallback(
|
||||||
async (ids: Id<"songs">[]) => {
|
(ids: Iterable<string>) => {
|
||||||
const unique = [...new Set(ids)]
|
let any = false
|
||||||
if (unique.length === 0) {
|
for (const id of ids) {
|
||||||
return
|
if (!songIds.has(id)) return false
|
||||||
}
|
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
|
||||||
},
|
},
|
||||||
[favoriteSongsMutation]
|
[songIds]
|
||||||
)
|
)
|
||||||
|
|
||||||
const toggleSongsFavorite = React.useCallback(
|
const toggleSongsFavorite = React.useCallback(
|
||||||
@@ -232,7 +223,7 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
|
|||||||
toggleSongsFavorite,
|
toggleSongsFavorite,
|
||||||
toggleAlbumFavorite,
|
toggleAlbumFavorite,
|
||||||
toggleArtistFavorite,
|
toggleArtistFavorite,
|
||||||
favoriteSongs,
|
areSongsFavorite,
|
||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
isSongFavorite,
|
isSongFavorite,
|
||||||
@@ -242,7 +233,7 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
|
|||||||
toggleSongsFavorite,
|
toggleSongsFavorite,
|
||||||
toggleAlbumFavorite,
|
toggleAlbumFavorite,
|
||||||
toggleArtistFavorite,
|
toggleArtistFavorite,
|
||||||
favoriteSongs,
|
areSongsFavorite,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -12,11 +12,26 @@ import { cn } from "@/lib/utils"
|
|||||||
import {
|
import {
|
||||||
activeLineIndex,
|
activeLineIndex,
|
||||||
type LyricLine,
|
type LyricLine,
|
||||||
|
type LyricWord,
|
||||||
type Lyrics,
|
type Lyrics,
|
||||||
} from "@otunes/convex/client/lyrics"
|
} from "@otunes/convex/client/lyrics"
|
||||||
|
|
||||||
/** How long a manual scroll keeps the panel from following the song. */
|
/** How long a manual scroll keeps the panel from following the song. */
|
||||||
const MANUAL_SCROLL_HOLD_MS = 3000
|
const MANUAL_SCROLL_HOLD_MS = 3000
|
||||||
|
/** Blur by distance from the playing line; farther lines share the last. */
|
||||||
|
const LINE_BLUR = ["blur-none", "blur-[1px]", "blur-[2px]", "blur-[3px]"]
|
||||||
|
/** Unsung words wipe from dim to bright, soft edge first, as they are sung. */
|
||||||
|
const WORD_FILL = {
|
||||||
|
backgroundImage:
|
||||||
|
"linear-gradient(90deg, var(--foreground) 40%, color-mix(in oklab, var(--foreground) 45%, transparent) 60%)",
|
||||||
|
backgroundSize: "250% 100%",
|
||||||
|
}
|
||||||
|
const WORD_FILL_FRAMES = [
|
||||||
|
{ backgroundPosition: "100% 0" },
|
||||||
|
{ backgroundPosition: "0% 0" },
|
||||||
|
]
|
||||||
|
/** How far a word's fill may drift from playback before it is reset. */
|
||||||
|
const FILL_DRIFT_MS = 80
|
||||||
|
|
||||||
/** Lyrics beside the page, in the queue's place. Synced lines follow playback. */
|
/** Lyrics beside the page, in the queue's place. Synced lines follow playback. */
|
||||||
export function LyricsPanel() {
|
export function LyricsPanel() {
|
||||||
@@ -47,38 +62,42 @@ function LyricsLines({ lyrics }: { lyrics: Lyrics }) {
|
|||||||
const time = useLyricsTime(lyrics, currentTime, isPlaying)
|
const time = useLyricsTime(lyrics, currentTime, isPlaying)
|
||||||
const active = activeLineIndex(lyrics, time)
|
const active = activeLineIndex(lyrics, time)
|
||||||
const scrollRef = React.useRef<HTMLDivElement>(null)
|
const scrollRef = React.useRef<HTMLDivElement>(null)
|
||||||
const manualScrollAt = React.useRef(0)
|
|
||||||
const synced = lyrics.synced !== "none"
|
const synced = lyrics.synced !== "none"
|
||||||
|
// While the listener scrolls, lines stay sharp and the panel stays put.
|
||||||
|
const [browsing, setBrowsing] = React.useState(false)
|
||||||
|
const browseTimer = React.useRef<ReturnType<typeof setTimeout>>(undefined)
|
||||||
|
|
||||||
|
React.useEffect(() => () => clearTimeout(browseTimer.current), [])
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const container = scrollRef.current
|
const container = scrollRef.current
|
||||||
const line = container?.querySelector<HTMLElement>(
|
const line = container?.querySelector<HTMLElement>(
|
||||||
`[data-line="${Math.max(active, 0)}"]`
|
`[data-line="${Math.max(active, 0)}"]`
|
||||||
)
|
)
|
||||||
if (
|
if (!container || !line || !synced || browsing) return
|
||||||
!container ||
|
|
||||||
!line ||
|
|
||||||
!synced ||
|
|
||||||
Date.now() - manualScrollAt.current < MANUAL_SCROLL_HOLD_MS
|
|
||||||
) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
container.scrollTo({
|
container.scrollTo({
|
||||||
top: line.offsetTop - container.clientHeight * 0.25,
|
top: line.offsetTop - container.clientHeight * 0.25,
|
||||||
behavior: "smooth",
|
behavior: "smooth",
|
||||||
})
|
})
|
||||||
}, [active, synced])
|
}, [active, synced, browsing])
|
||||||
|
|
||||||
const playFrom = React.useCallback(
|
const playFrom = React.useCallback(
|
||||||
(seconds: number) => {
|
(seconds: number) => {
|
||||||
seekTo(seconds)
|
seekTo(seconds)
|
||||||
setIsPlaying(true)
|
setIsPlaying(true)
|
||||||
|
clearTimeout(browseTimer.current)
|
||||||
|
setBrowsing(false)
|
||||||
},
|
},
|
||||||
[seekTo, setIsPlaying]
|
[seekTo, setIsPlaying]
|
||||||
)
|
)
|
||||||
|
|
||||||
const holdScroll = () => {
|
const holdScroll = () => {
|
||||||
manualScrollAt.current = Date.now()
|
setBrowsing(true)
|
||||||
|
clearTimeout(browseTimer.current)
|
||||||
|
browseTimer.current = setTimeout(
|
||||||
|
() => setBrowsing(false),
|
||||||
|
MANUAL_SCROLL_HOLD_MS
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -86,7 +105,7 @@ function LyricsLines({ lyrics }: { lyrics: Lyrics }) {
|
|||||||
ref={scrollRef}
|
ref={scrollRef}
|
||||||
onWheel={holdScroll}
|
onWheel={holdScroll}
|
||||||
onTouchMove={holdScroll}
|
onTouchMove={holdScroll}
|
||||||
className="relative min-h-0 flex-1 overflow-y-auto px-6 pt-[25svh] pb-[60svh]"
|
className="group relative min-h-0 flex-1 overflow-y-auto px-6 pt-[25svh] pb-[60svh]"
|
||||||
>
|
>
|
||||||
{lyrics.lines.map((line, index) =>
|
{lyrics.lines.map((line, index) =>
|
||||||
synced ? (
|
synced ? (
|
||||||
@@ -94,10 +113,14 @@ function LyricsLines({ lyrics }: { lyrics: Lyrics }) {
|
|||||||
key={index}
|
key={index}
|
||||||
index={index}
|
index={index}
|
||||||
line={line}
|
line={line}
|
||||||
state={
|
distance={
|
||||||
index === active ? "active" : index < active ? "past" : "next"
|
browsing
|
||||||
|
? 0
|
||||||
|
: Math.min(Math.abs(index - active), LINE_BLUR.length - 1)
|
||||||
}
|
}
|
||||||
|
active={index === active}
|
||||||
time={index === active ? time : null}
|
time={index === active ? time : null}
|
||||||
|
isPlaying={isPlaying}
|
||||||
onSelect={playFrom}
|
onSelect={playFrom}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
@@ -117,48 +140,104 @@ function LyricsLines({ lyrics }: { lyrics: Lyrics }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One timed line. Only the active line gets the playback time, so memoized
|
* One timed line, blurred by its `distance` from the playing line. Only the
|
||||||
* lines elsewhere skip re-rendering as the song plays.
|
* active line gets the playback time, so memoized lines elsewhere skip
|
||||||
|
* re-rendering as the song plays.
|
||||||
*/
|
*/
|
||||||
const SyncedLine = React.memo(function SyncedLine({
|
const SyncedLine = React.memo(function SyncedLine({
|
||||||
index,
|
index,
|
||||||
line,
|
line,
|
||||||
state,
|
distance,
|
||||||
|
active,
|
||||||
time,
|
time,
|
||||||
|
isPlaying,
|
||||||
onSelect,
|
onSelect,
|
||||||
}: {
|
}: {
|
||||||
index: number
|
index: number
|
||||||
line: LyricLine
|
line: LyricLine
|
||||||
state: "past" | "active" | "next"
|
distance: number
|
||||||
|
active: boolean
|
||||||
time: number | null
|
time: number | null
|
||||||
|
isPlaying: boolean
|
||||||
onSelect: (seconds: number) => void
|
onSelect: (seconds: number) => void
|
||||||
}) {
|
}) {
|
||||||
const active = state === "active"
|
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
data-line={index}
|
data-line={index}
|
||||||
onClick={() => onSelect(line.start ?? 0)}
|
onClick={() => onSelect(line.start ?? 0)}
|
||||||
className={cn(
|
className={cn(
|
||||||
"-mx-2 my-1 block w-[calc(100%+1rem)] rounded-md px-2 py-1.5 text-left text-[22px] leading-tight font-bold transition-colors duration-300 hover:bg-foreground/5",
|
"-mx-2 my-1 block w-[calc(100%+1rem)] rounded-md px-2 py-1.5 text-left text-[22px] leading-tight font-bold transition-[color,filter] duration-300 group-hover:blur-none hover:bg-foreground/5",
|
||||||
|
LINE_BLUR[distance],
|
||||||
active && !line.words ? "text-foreground" : "text-foreground/30"
|
active && !line.words ? "text-foreground" : "text-foreground/30"
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{active && line.words
|
{active && line.words && time !== null ? (
|
||||||
? line.words.map((word, wordIndex) => (
|
<FilledWords words={line.words} time={time} isPlaying={isPlaying} />
|
||||||
<span
|
) : (
|
||||||
key={wordIndex}
|
line.text
|
||||||
className={cn(
|
)}
|
||||||
"transition-colors duration-200",
|
|
||||||
time !== null && time >= word.start
|
|
||||||
? "text-foreground"
|
|
||||||
: "text-foreground/45"
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{word.text}
|
|
||||||
</span>
|
|
||||||
))
|
|
||||||
: line.text}
|
|
||||||
</button>
|
</button>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
* delay); playback updates only correct their drift.
|
||||||
|
*/
|
||||||
|
function FilledWords({
|
||||||
|
words,
|
||||||
|
time,
|
||||||
|
isPlaying,
|
||||||
|
}: {
|
||||||
|
words: LyricWord[]
|
||||||
|
time: number
|
||||||
|
isPlaying: boolean
|
||||||
|
}) {
|
||||||
|
const spans = React.useRef<(HTMLSpanElement | null)[]>([])
|
||||||
|
const fills = React.useRef<(Animation | undefined)[]>([])
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
fills.current = words.map((word, index) =>
|
||||||
|
spans.current[index]?.animate(WORD_FILL_FRAMES, {
|
||||||
|
delay: word.start * 1000,
|
||||||
|
duration: Math.max(word.end - word.start, 0.05) * 1000,
|
||||||
|
easing: "linear",
|
||||||
|
fill: "both",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
return () => fills.current.forEach((fill) => fill?.cancel())
|
||||||
|
}, [words])
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const at = time * 1000
|
||||||
|
fills.current.forEach((fill, index) => {
|
||||||
|
if (!fill) return
|
||||||
|
if (Math.abs(Number(fill.currentTime ?? 0) - at) > FILL_DRIFT_MS) {
|
||||||
|
fill.currentTime = at
|
||||||
|
}
|
||||||
|
// `play` on a finished fill would rewind it to the start.
|
||||||
|
if (isPlaying && time < words[index].end) fill.play()
|
||||||
|
else fill.pause()
|
||||||
|
})
|
||||||
|
}, [words, time, isPlaying])
|
||||||
|
|
||||||
|
return words.map((word, index) => {
|
||||||
|
const text = word.text.trimEnd()
|
||||||
|
return (
|
||||||
|
<React.Fragment key={index}>
|
||||||
|
<span
|
||||||
|
ref={(span) => {
|
||||||
|
spans.current[index] = span
|
||||||
|
}}
|
||||||
|
className="bg-clip-text text-transparent"
|
||||||
|
style={WORD_FILL}
|
||||||
|
>
|
||||||
|
{text}
|
||||||
|
</span>
|
||||||
|
{word.text.slice(text.length)}
|
||||||
|
</React.Fragment>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -48,7 +48,8 @@ export function OtherDownloadsView() {
|
|||||||
[songs]
|
[songs]
|
||||||
)
|
)
|
||||||
|
|
||||||
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
const { isSongFavorite, areSongsFavorite, toggleSongFavorite } =
|
||||||
|
useFavorites()
|
||||||
const { playFromSong, playInOrder, playShuffled } = usePlaybackActions()
|
const { playFromSong, playInOrder, playShuffled } = usePlaybackActions()
|
||||||
const {
|
const {
|
||||||
selectedIds,
|
selectedIds,
|
||||||
@@ -62,6 +63,7 @@ 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(
|
||||||
@@ -140,6 +142,7 @@ 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,8 +74,12 @@ 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 { isSongFavorite, toggleSongFavorite, toggleSongsFavorite } =
|
const {
|
||||||
useFavorites()
|
isSongFavorite,
|
||||||
|
areSongsFavorite,
|
||||||
|
toggleSongFavorite,
|
||||||
|
toggleSongsFavorite,
|
||||||
|
} = useFavorites()
|
||||||
const currentSongId = useCurrentSongId()
|
const currentSongId = useCurrentSongId()
|
||||||
const {
|
const {
|
||||||
playInOrder,
|
playInOrder,
|
||||||
@@ -143,6 +147,7 @@ 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(
|
||||||
() =>
|
() =>
|
||||||
@@ -465,6 +470,7 @@ 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"
|
||||||
@@ -522,6 +528,7 @@ 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}
|
||||||
|
|||||||
@@ -2,11 +2,18 @@
|
|||||||
|
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
|
|
||||||
|
import { useFavorites } from "@/components/favorites-provider"
|
||||||
|
import {
|
||||||
|
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 { 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"
|
||||||
import type { BrowseSong, QueueSong } from "@otunes/convex/types"
|
import type { BrowseSong, QueueSong } from "@otunes/convex/types"
|
||||||
@@ -15,6 +22,7 @@ import {
|
|||||||
moveQueueBlock,
|
moveQueueBlock,
|
||||||
} from "@/lib/move-queue-block"
|
} from "@/lib/move-queue-block"
|
||||||
import { getSelectionRangePositions } from "@/lib/selection-range-styles"
|
import { getSelectionRangePositions } from "@/lib/selection-range-styles"
|
||||||
|
import { stationArtistId } from "@/lib/station-artist"
|
||||||
import { useSongs } from "@/lib/song-cache"
|
import { useSongs } from "@/lib/song-cache"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
@@ -46,6 +54,51 @@ 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,
|
||||||
@@ -61,25 +114,27 @@ function HistorySongRow({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li
|
<SongMenuArea song={song}>
|
||||||
role="button"
|
<li
|
||||||
tabIndex={0}
|
role="button"
|
||||||
className="flex cursor-pointer items-center gap-3 px-4 py-2 text-sm hover:bg-foreground/5"
|
tabIndex={0}
|
||||||
onClick={() => onPlay(historyIndex)}
|
className="flex cursor-pointer items-center gap-3 px-4 py-2 text-sm hover:bg-foreground/5 data-[state=open]:bg-foreground/5"
|
||||||
onKeyDown={(event) => {
|
onClick={() => onPlay(historyIndex)}
|
||||||
if (event.key === "Enter" || event.key === " ") {
|
onKeyDown={(event) => {
|
||||||
event.preventDefault()
|
if (event.key === "Enter" || event.key === " ") {
|
||||||
onPlay(historyIndex)
|
event.preventDefault()
|
||||||
}
|
onPlay(historyIndex)
|
||||||
}}
|
}
|
||||||
>
|
}}
|
||||||
<TrackCover
|
>
|
||||||
albumId={song.album.id}
|
<TrackCover
|
||||||
alt={song.album.title}
|
albumId={song.album.id}
|
||||||
inRange={false}
|
alt={song.album.title}
|
||||||
/>
|
inRange={false}
|
||||||
<PlaybackSongMeta song={song} align="start" showAlbum={false} />
|
/>
|
||||||
</li>
|
<PlaybackSongMeta song={song} align="start" showAlbum={false} />
|
||||||
|
</li>
|
||||||
|
</SongMenuArea>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,8 +236,71 @@ export function QueuePanel() {
|
|||||||
() => selectableQueue.map((item) => ({ id: item.selectionId })),
|
() => selectableQueue.map((item) => ({ id: item.selectionId })),
|
||||||
[selectableQueue]
|
[selectableQueue]
|
||||||
)
|
)
|
||||||
const { selectedIds, handleSelect, handlePointerDown } =
|
const {
|
||||||
useTrackSelection(selectionItems)
|
selectedIds,
|
||||||
|
selectedCount,
|
||||||
|
handleSelect,
|
||||||
|
handlePointerDown,
|
||||||
|
prepareContextMenu,
|
||||||
|
clearSelection,
|
||||||
|
} = useTrackSelection(selectionItems)
|
||||||
|
const { isSongFavorite, areSongsFavorite } = useFavorites()
|
||||||
|
const { runSongsAction } = useMediaActions()
|
||||||
|
|
||||||
|
/** The rows a menu acts on: the selection, else just the clicked row. */
|
||||||
|
const menuTargets = React.useCallback(
|
||||||
|
(selectionId: string) => {
|
||||||
|
const ids = selectedIds.has(selectionId)
|
||||||
|
? selectedIds
|
||||||
|
: new Set([selectionId])
|
||||||
|
return selectableQueue.filter((item) => ids.has(item.selectionId))
|
||||||
|
},
|
||||||
|
[selectableQueue, selectedIds]
|
||||||
|
)
|
||||||
|
|
||||||
|
const selectedStationArtistId = React.useMemo(
|
||||||
|
() =>
|
||||||
|
stationArtistId(
|
||||||
|
selectableQueue.flatMap((item) =>
|
||||||
|
item.song ? [{ id: item.selectionId, artist: item.song.artist }] : []
|
||||||
|
),
|
||||||
|
selectedIds
|
||||||
|
),
|
||||||
|
[selectableQueue, selectedIds]
|
||||||
|
)
|
||||||
|
const selectionFavorited = areSongsFavorite(
|
||||||
|
selectableQueue.flatMap((item) =>
|
||||||
|
item.song && selectedIds.has(item.selectionId) ? [item.song.id] : []
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
const handleMediaAction = React.useCallback(
|
||||||
|
(action: MediaContextAction, selectionId: string) => {
|
||||||
|
const songs = menuTargets(selectionId).flatMap((item) =>
|
||||||
|
item.song ? [item.song] : []
|
||||||
|
)
|
||||||
|
const artistId = songs[0]?.artist.id
|
||||||
|
runSongsAction(
|
||||||
|
action,
|
||||||
|
songs.map((song) => song.id),
|
||||||
|
songs.every((song) => song.artist.id === artistId)
|
||||||
|
? artistId
|
||||||
|
: undefined
|
||||||
|
)
|
||||||
|
},
|
||||||
|
[menuTargets, runSongsAction]
|
||||||
|
)
|
||||||
|
|
||||||
|
const handleRemove = React.useCallback(
|
||||||
|
(selectionId: string) => {
|
||||||
|
const removed = new Set(
|
||||||
|
menuTargets(selectionId).map((item) => item.queueIndex)
|
||||||
|
)
|
||||||
|
clearSelection()
|
||||||
|
void reorderQueue(queueSongIds.filter((_, index) => !removed.has(index)))
|
||||||
|
},
|
||||||
|
[clearSelection, menuTargets, queueSongIds, reorderQueue]
|
||||||
|
)
|
||||||
|
|
||||||
const handleRowSelect = React.useCallback(
|
const handleRowSelect = React.useCallback(
|
||||||
(index: number, event: React.MouseEvent) => {
|
(index: number, event: React.MouseEvent) => {
|
||||||
@@ -292,25 +410,25 @@ 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">
|
||||||
{currentQueueSongId ? (
|
{currentSong ? (
|
||||||
<div className="flex items-center gap-3 px-4 py-3">
|
<SongMenuArea song={currentSong}>
|
||||||
{currentSong ? (
|
<div className="flex items-center gap-3 px-4 py-3">
|
||||||
<>
|
<TrackCover
|
||||||
<TrackCover
|
albumId={currentSong.album.id}
|
||||||
albumId={currentSong.album.id}
|
alt={currentSong.album.title}
|
||||||
alt={currentSong.album.title}
|
inRange={false}
|
||||||
inRange={false}
|
size="lg"
|
||||||
size="lg"
|
/>
|
||||||
/>
|
<PlaybackSongMeta
|
||||||
<PlaybackSongMeta
|
song={currentSong}
|
||||||
song={currentSong}
|
align="start"
|
||||||
align="start"
|
showAlbum={false}
|
||||||
showAlbum={false}
|
/>
|
||||||
/>
|
</div>
|
||||||
</>
|
</SongMenuArea>
|
||||||
) : (
|
) : currentQueueSongId ? (
|
||||||
<Skeleton className="size-14 shrink-0 rounded-md" />
|
<div className="px-4 py-3">
|
||||||
)}
|
<Skeleton className="size-14 shrink-0 rounded-md" />
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
@@ -336,6 +454,12 @@ export function QueuePanel() {
|
|||||||
variant="queue"
|
variant="queue"
|
||||||
song={item.song}
|
song={item.song}
|
||||||
index={index}
|
index={index}
|
||||||
|
selectionId={item.selectionId}
|
||||||
|
isFavorite={isSongFavorite(item.song.id)}
|
||||||
|
selectedCount={selectedCount}
|
||||||
|
selectionStationArtistId={selectedStationArtistId}
|
||||||
|
selectionFavorited={selectionFavorited}
|
||||||
|
removeLabel="Remove from Queue"
|
||||||
selectionPosition={selectionPositions[index]}
|
selectionPosition={selectionPositions[index]}
|
||||||
isDragging={draggingIndices.has(index)}
|
isDragging={draggingIndices.has(index)}
|
||||||
onPointerDown={handlePointerDown}
|
onPointerDown={handlePointerDown}
|
||||||
@@ -343,6 +467,9 @@ export function QueuePanel() {
|
|||||||
onPlay={handleRowPlay}
|
onPlay={handleRowPlay}
|
||||||
onDragStart={setDragIndex}
|
onDragStart={setDragIndex}
|
||||||
onDrop={handleDrop}
|
onDrop={handleDrop}
|
||||||
|
onPrepareContextMenu={prepareContextMenu}
|
||||||
|
onMediaAction={handleMediaAction}
|
||||||
|
onRemove={handleRemove}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<QueueSongRowSkeleton key={item.selectionId} />
|
<QueueSongRowSkeleton key={item.selectionId} />
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ const SONGS_PAGE_SIZE = 50
|
|||||||
const estimateSongRowSize = () => 56
|
const estimateSongRowSize = () => 56
|
||||||
|
|
||||||
export function SongsView() {
|
export function SongsView() {
|
||||||
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
const { isSongFavorite, areSongsFavorite, toggleSongFavorite } =
|
||||||
|
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")
|
||||||
@@ -98,6 +99,7 @@ export function SongsView() {
|
|||||||
() => stationArtistId(songs, selectedIds),
|
() => stationArtistId(songs, selectedIds),
|
||||||
[songs, selectedIds]
|
[songs, selectedIds]
|
||||||
)
|
)
|
||||||
|
const selectionFavorited = areSongsFavorite(selectedIds)
|
||||||
|
|
||||||
const selectionPositions = useMemo(
|
const selectionPositions = useMemo(
|
||||||
() =>
|
() =>
|
||||||
@@ -222,6 +224,7 @@ 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}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ import type { DownloadSource } from "@otunes/convex/client/download-queue"
|
|||||||
* columns (use with `LibraryTrackListHeader`).
|
* columns (use with `LibraryTrackListHeader`).
|
||||||
* - `album`: favorite star, track number, title with optional credits.
|
* - `album`: favorite star, track number, title with optional credits.
|
||||||
* - `playlist`: cover with favorite overlay, track number, title.
|
* - `playlist`: cover with favorite overlay, track number, title.
|
||||||
* - `queue`: cover, title and artist, duration, and a reorder grip. No menu.
|
* - `queue`: cover, title and artist, duration, and a reorder grip.
|
||||||
*/
|
*/
|
||||||
export type TrackRowVariant = "library" | "album" | "playlist" | "queue"
|
export type TrackRowVariant = "library" | "album" | "playlist" | "queue"
|
||||||
|
|
||||||
@@ -47,6 +47,12 @@ export type TrackRowProps = {
|
|||||||
song: BrowseSong
|
song: BrowseSong
|
||||||
/** Position in the list the selection hook was given. */
|
/** Position in the list the selection hook was given. */
|
||||||
index: number
|
index: number
|
||||||
|
/**
|
||||||
|
* The id the selection hook knows this row by, passed to the menu and
|
||||||
|
* remove callbacks. Defaults to the song id; the queue uses a per-position
|
||||||
|
* id since a song can appear more than once.
|
||||||
|
*/
|
||||||
|
selectionId?: string
|
||||||
/** Number shown in the track number column (`album` and `playlist`). */
|
/** Number shown in the track number column (`album` and `playlist`). */
|
||||||
trackNumber?: number
|
trackNumber?: number
|
||||||
/** Secondary line under the title, e.g. album track credits. */
|
/** Secondary line under the title, e.g. album track credits. */
|
||||||
@@ -62,6 +68,8 @@ 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`. */
|
||||||
@@ -71,10 +79,10 @@ export type TrackRowProps = {
|
|||||||
onPointerDown: (event: React.MouseEvent) => void
|
onPointerDown: (event: React.MouseEvent) => void
|
||||||
onPlay: (index: number) => void
|
onPlay: (index: number) => void
|
||||||
onToggleFavorite?: (songId: string) => void
|
onToggleFavorite?: (songId: string) => void
|
||||||
onPrepareContextMenu?: (songId: string) => void
|
onPrepareContextMenu?: (selectionId: string) => void
|
||||||
/** Renders the "more options" and right-click menus when provided. */
|
/** Renders the "more options" and right-click menus when provided. */
|
||||||
onMediaAction?: (action: MediaContextAction, songId: string) => void
|
onMediaAction?: (action: MediaContextAction, selectionId: string) => void
|
||||||
onRemove?: (songId: string) => void
|
onRemove?: (selectionId: string) => void
|
||||||
/** Makes the row draggable when provided. */
|
/** Makes the row draggable when provided. */
|
||||||
onDragStart?: (index: number) => void
|
onDragStart?: (index: number) => void
|
||||||
onDrop?: (index: number) => void
|
onDrop?: (index: number) => void
|
||||||
@@ -251,6 +259,7 @@ function TrackRowComponent({
|
|||||||
variant,
|
variant,
|
||||||
song,
|
song,
|
||||||
index,
|
index,
|
||||||
|
selectionId,
|
||||||
trackNumber,
|
trackNumber,
|
||||||
subtitle,
|
subtitle,
|
||||||
downloadCollection,
|
downloadCollection,
|
||||||
@@ -261,6 +270,7 @@ function TrackRowComponent({
|
|||||||
isDragging = false,
|
isDragging = false,
|
||||||
selectedCount = 0,
|
selectedCount = 0,
|
||||||
selectionStationArtistId,
|
selectionStationArtistId,
|
||||||
|
selectionFavorited,
|
||||||
playlistLabel,
|
playlistLabel,
|
||||||
showFavoriteInMenu = true,
|
showFavoriteInMenu = true,
|
||||||
removeLabel,
|
removeLabel,
|
||||||
@@ -284,6 +294,7 @@ function TrackRowComponent({
|
|||||||
const flush = variant === "library" || variant === "queue"
|
const flush = variant === "library" || variant === "queue"
|
||||||
const play = () => onPlay(index)
|
const play = () => onPlay(index)
|
||||||
const toggleFavorite = () => onToggleFavorite?.(song.id)
|
const toggleFavorite = () => onToggleFavorite?.(song.id)
|
||||||
|
const rowId = selectionId ?? song.id
|
||||||
|
|
||||||
const favoriteStar = (
|
const favoriteStar = (
|
||||||
<div className="flex shrink-0 items-center justify-center">
|
<div className="flex shrink-0 items-center justify-center">
|
||||||
@@ -333,11 +344,14 @@ function TrackRowComponent({
|
|||||||
stationArtistId: inRange ? selectionStationArtistId : song.artist.id,
|
stationArtistId: inRange ? selectionStationArtistId : song.artist.id,
|
||||||
selectedCount: inRange && selectedCount > 0 ? selectedCount : 1,
|
selectedCount: inRange && selectedCount > 0 ? selectedCount : 1,
|
||||||
inSelectionRange: inRange,
|
inSelectionRange: inRange,
|
||||||
onOpenMenu: () => onPrepareContextMenu?.(song.id),
|
onOpenMenu: () => onPrepareContextMenu?.(rowId),
|
||||||
onAction: (action) => onMediaAction(action, song.id),
|
onAction: (action) => onMediaAction(action, rowId),
|
||||||
playlistLabel,
|
playlistLabel,
|
||||||
showFavorite: showFavoriteInMenu,
|
showFavorite: showFavoriteInMenu,
|
||||||
favorited: isFavorite,
|
favorited:
|
||||||
|
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 },
|
||||||
@@ -351,7 +365,7 @@ function TrackRowComponent({
|
|||||||
<MediaMenuItem
|
<MediaMenuItem
|
||||||
variant="destructive"
|
variant="destructive"
|
||||||
className="justify-between"
|
className="justify-between"
|
||||||
onClick={() => onRemove(song.id)}
|
onClick={() => onRemove(rowId)}
|
||||||
>
|
>
|
||||||
{removeLabel}
|
{removeLabel}
|
||||||
<Trash2 />
|
<Trash2 />
|
||||||
@@ -555,7 +569,7 @@ function TrackRowComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pass stable callbacks: they receive the row's `index` or song id, so one
|
* Pass stable callbacks: they receive the row's `index`, song id or
|
||||||
* handler can serve every row.
|
* `selectionId`, so one handler can serve every row.
|
||||||
*/
|
*/
|
||||||
export const TrackRow = React.memo(TrackRowComponent)
|
export const TrackRow = React.memo(TrackRowComponent)
|
||||||
@@ -26,7 +26,8 @@ function songsTitle(songIds: readonly string[]) {
|
|||||||
|
|
||||||
export function useMediaActions() {
|
export function useMediaActions() {
|
||||||
const { openAddToPlaylist, openAddArtistToPlaylist } = useAddToPlaylist()
|
const { openAddToPlaylist, openAddArtistToPlaylist } = useAddToPlaylist()
|
||||||
const { favoriteSongs, toggleArtistFavorite } = useFavorites()
|
const { areSongsFavorite, toggleSongsFavorite, toggleArtistFavorite } =
|
||||||
|
useFavorites()
|
||||||
const { runQueueAction, createStation } = useQueueMediaActions()
|
const { runQueueAction, createStation } = useQueueMediaActions()
|
||||||
const convex = useConvex()
|
const convex = useConvex()
|
||||||
const cacheScope = useCacheScope()
|
const cacheScope = useCacheScope()
|
||||||
@@ -44,7 +45,8 @@ export function useMediaActions() {
|
|||||||
if (stationArtist) void createStation(stationArtist)
|
if (stationArtist) void createStation(stationArtist)
|
||||||
break
|
break
|
||||||
case "favorite":
|
case "favorite":
|
||||||
void favoriteSongs(songIds)
|
// Unfavorite only when every song already is, matching the menu label.
|
||||||
|
void toggleSongsFavorite(songIds, areSongsFavorite(songIds))
|
||||||
break
|
break
|
||||||
case "playlist":
|
case "playlist":
|
||||||
openAddToPlaylist(songIds)
|
openAddToPlaylist(songIds)
|
||||||
@@ -73,7 +75,8 @@ export function useMediaActions() {
|
|||||||
},
|
},
|
||||||
[
|
[
|
||||||
createStation,
|
createStation,
|
||||||
favoriteSongs,
|
areSongsFavorite,
|
||||||
|
toggleSongsFavorite,
|
||||||
openAddToPlaylist,
|
openAddToPlaylist,
|
||||||
runQueueAction,
|
runQueueAction,
|
||||||
requestDownload,
|
requestDownload,
|
||||||
|
|||||||
@@ -125,8 +125,9 @@ function collectionKey({ kind, id }: CollectionRef) {
|
|||||||
*/
|
*/
|
||||||
export function createDownloadQueue(
|
export function createDownloadQueue(
|
||||||
storage: DownloadStorage,
|
storage: DownloadStorage,
|
||||||
{ concurrency = 2 }: { concurrency?: number } = {}
|
options: { 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>()
|
||||||
@@ -372,6 +373,17 @@ 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],
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
/**
|
||||||
|
* 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,6 +5,8 @@
|
|||||||
* 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
|
||||||
@@ -16,11 +18,15 @@ 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[]
|
||||||
}
|
}
|
||||||
@@ -29,6 +35,8 @@ 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(":", "."))
|
||||||
@@ -107,10 +115,31 @@ 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
|
||||||
return {
|
const synced = lines.every((line) => line.words) ? "word" : "line"
|
||||||
synced: lines.every((line) => line.words) ? "word" : "line",
|
if (synced === "line") estimateWords(lines)
|
||||||
lines,
|
return { synced, 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. */
|
||||||
@@ -185,32 +214,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. */
|
/**
|
||||||
exact: boolean
|
* 2 when the line holds the query as typed, 1 when it holds every word of
|
||||||
|
* it, 0 when it does give or take typos.
|
||||||
|
*/
|
||||||
|
score: 0 | 1 | 2
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Where a search matched the lyrics: a line holding the query as typed, or
|
* Where a search matched the lyrics: the best line holding the query as
|
||||||
* else a line holding every word of it (the last may be a prefix, as when
|
* typed, or else every word of it (see `matchWords`). Null when no single
|
||||||
* typing). Null when no single line does.
|
* 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 = searchTerms(needle)
|
const terms = searchWords(needle)
|
||||||
const last = terms.at(-1)
|
// Most songs miss a word entirely, so skip them before checking lines.
|
||||||
if (!needle || last === undefined) return null
|
if (!needle || !matchWords([...new Set(searchWords(plain))], terms)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
let loose: string | null = null
|
let loose: LyricsMatch | 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) {
|
||||||
@@ -218,15 +247,13 @@ 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, exact: true }
|
return { snippet, score: 2 }
|
||||||
}
|
}
|
||||||
if (loose === null) {
|
if (loose?.score === 1) continue
|
||||||
const words = searchTerms(line)
|
const quality = matchWords(searchWords(line), terms)
|
||||||
const hasAll =
|
if (quality === "exact" || (quality && !loose)) {
|
||||||
terms.slice(0, -1).every((term) => words.includes(term)) &&
|
loose = { snippet: line.trim(), score: quality === "exact" ? 1 : 0 }
|
||||||
words.some((word) => word.startsWith(last))
|
|
||||||
if (hasAll) loose = line.trim()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return loose === null ? null : { snippet: loose, exact: false }
|
return loose
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { matchWords, searchWords } from "./fuzzy-search"
|
||||||
|
|
||||||
type SearchableSong = {
|
type SearchableSong = {
|
||||||
id: string
|
id: string
|
||||||
title: string
|
title: string
|
||||||
@@ -6,9 +8,9 @@ type SearchableSong = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Case-insensitive match on title, artist, or album, plus the songs in
|
* Case-insensitive match on title, artist, or album, give or take typos (see
|
||||||
* `lyricsMatches` (from `api.lyrics.matchingSongIds`). A blank query keeps
|
* `matchWords`), plus the songs in `lyricsMatches` (from
|
||||||
* every song.
|
* `api.lyrics.matchingSongIds`). A blank query keeps every song.
|
||||||
*/
|
*/
|
||||||
export function filterSongs<T extends SearchableSong>(
|
export function filterSongs<T extends SearchableSong>(
|
||||||
songs: T[],
|
songs: T[],
|
||||||
@@ -19,12 +21,14 @@ 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(
|
return songs.filter((song) => {
|
||||||
(song) =>
|
if (byLyrics.has(song.id)) return true
|
||||||
byLyrics.has(song.id) ||
|
const fields = [song.title, song.artist.name, song.album.title]
|
||||||
[song.title, song.artist.name, song.album.title].some((value) =>
|
return (
|
||||||
value.toLowerCase().includes(normalized)
|
fields.some((value) => value.toLowerCase().includes(normalized)) ||
|
||||||
)
|
matchWords(searchWords(fields.join(" ")), terms) !== null
|
||||||
)
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
@@ -27,6 +27,7 @@ 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,
|
||||||
@@ -618,7 +619,16 @@ 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
|
||||||
@@ -632,15 +642,20 @@ function matchScore(text: string, query: string): number {
|
|||||||
if (lower.includes(query)) {
|
if (lower.includes(query)) {
|
||||||
return 40
|
return 40
|
||||||
}
|
}
|
||||||
return 0
|
const words = matchWords(searchWords(text), terms)
|
||||||
|
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)),
|
(best, name) => Math.max(best, matchScore(name, query, terms)),
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -658,6 +673,7 @@ 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: [],
|
||||||
@@ -678,7 +694,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),
|
score: matchScore(artist.name, queryText, terms),
|
||||||
}))
|
}))
|
||||||
.filter((result) => result.score > 0)
|
.filter((result) => result.score > 0)
|
||||||
.sort(
|
.sort(
|
||||||
@@ -692,8 +708,8 @@ export const searchLibrary = query({
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
const score = Math.max(
|
const score = Math.max(
|
||||||
matchScore(album.name, queryText),
|
matchScore(album.name, queryText, terms),
|
||||||
matchScore(artist.name, queryText)
|
matchScore(artist.name, queryText, terms)
|
||||||
)
|
)
|
||||||
if (score === 0) {
|
if (score === 0) {
|
||||||
return []
|
return []
|
||||||
@@ -718,10 +734,10 @@ export const searchLibrary = query({
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
const score = Math.max(
|
const score = Math.max(
|
||||||
matchScore(song.name, queryText),
|
matchScore(song.name, queryText, terms),
|
||||||
matchScoreSongArtists(song.artist, queryText),
|
matchScoreSongArtists(song.artist, queryText, terms),
|
||||||
matchScore(album.name, queryText),
|
matchScore(album.name, queryText, terms),
|
||||||
matchScore(albumArtist.name, queryText)
|
matchScore(albumArtist.name, queryText, terms)
|
||||||
)
|
)
|
||||||
if (score === 0) {
|
if (score === 0) {
|
||||||
return []
|
return []
|
||||||
|
|||||||
@@ -62,10 +62,10 @@ export async function deleteSongLyrics(ctx: MutationCtx, songId: Id<"songs">) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Songs with a lyrics line matching `query` (see `matchLyrics`), with that
|
* Up to `limit` songs with a lyrics line matching `query` (see `matchLyrics`),
|
||||||
* line. Lines holding the query as typed come first, then the search index's
|
* with that line, best matches first. The search index matches any word
|
||||||
* relevance order. The index matches words anywhere in the lyrics, so its
|
* anywhere in the lyrics and ranks common words poorly, so its whole page is
|
||||||
* results are checked line by line.
|
* checked line by line before trimming.
|
||||||
*/
|
*/
|
||||||
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(limit)
|
.take(MAX_LYRICS_MATCHES)
|
||||||
const matches = rows.flatMap((row) => {
|
return rows
|
||||||
const match = matchLyrics(row.plain, text)
|
.flatMap((row) => {
|
||||||
return match ? [{ song: row.song, ...match }] : []
|
const match = matchLyrics(row.plain, text)
|
||||||
})
|
return match ? [{ song: row.song, ...match }] : []
|
||||||
return [
|
})
|
||||||
...matches.filter((match) => match.exact),
|
.sort((a, b) => b.score - a.score)
|
||||||
...matches.filter((match) => !match.exact),
|
.slice(0, limit)
|
||||||
].map(({ song, snippet }) => ({ song, snippet }))
|
.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,6 +2,7 @@ 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",
|
||||||
@@ -11,6 +12,7 @@ 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",
|
||||||
@@ -18,12 +20,14 @@ 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
|
||||||
|
|
||||||
@@ -54,13 +58,14 @@ 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 Medium is always transcoded.
|
* the song lacks them, and Low and Medium are 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,
|
||||||
@@ -70,7 +75,7 @@ export function downloadPlan(
|
|||||||
: "normal" in files
|
: "normal" in files
|
||||||
? "normal"
|
? "normal"
|
||||||
: "atmos",
|
: "atmos",
|
||||||
kbps: MEDIUM_KBPS,
|
kbps: quality === "low" ? LOW_KBPS : MEDIUM_KBPS,
|
||||||
}
|
}
|
||||||
case "high":
|
case "high":
|
||||||
return highPlan(files)
|
return highPlan(files)
|
||||||
@@ -84,7 +89,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. Low has no download equivalent.
|
* download can stand in for streaming.
|
||||||
*/
|
*/
|
||||||
export function streamDownloadQuality(
|
export function streamDownloadQuality(
|
||||||
plan: PlaybackStreamPlan
|
plan: PlaybackStreamPlan
|
||||||
@@ -95,6 +100,7 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,6 +135,7 @@ 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,6 +279,9 @@ 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)
|
||||||
@@ -363,12 +366,18 @@ 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)
|
||||||
@@ -5438,6 +5447,9 @@ 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'}
|
||||||
@@ -5889,6 +5901,16 @@ 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:
|
||||||
@@ -5916,6 +5938,12 @@ 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:
|
||||||
@@ -12473,6 +12501,8 @@ 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
|
||||||
@@ -12936,6 +12966,13 @@ 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
|
||||||
@@ -12967,6 +13004,12 @@ 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
|
||||||
|
|||||||
Executable
+22
@@ -0,0 +1,22 @@
|
|||||||
|
#!/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