feat(mobile): block Dolby Atmos downloads on Android (#147)
This commit was merged in pull request #147.
This commit is contained in:
1 parent
e66a91ed29
commit
9a4d446c83
4 files changed
+61
-32
No files matched your search
@@ -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 { useAction, useMutation, useQuery } from "convex/react"
|
||||
import { Image } from "expo-image"
|
||||
@@ -25,7 +29,6 @@ import {
|
||||
writeRememberedDownloadQuality,
|
||||
} from "@/lib/downloads"
|
||||
import {
|
||||
DOWNLOAD_QUALITIES,
|
||||
DOWNLOAD_QUALITY_DETAILS,
|
||||
DOWNLOAD_QUALITY_LABELS,
|
||||
formatBytes,
|
||||
@@ -508,7 +511,7 @@ function RememberedQualityCard() {
|
||||
detail: string
|
||||
}[] = [
|
||||
{ value: null, label: "Ask every time", detail: "Choose when downloading" },
|
||||
...DOWNLOAD_QUALITIES.map((quality) => ({
|
||||
...deviceDownloadQualities.map((quality) => ({
|
||||
value: quality,
|
||||
label: DOWNLOAD_QUALITY_LABELS[quality],
|
||||
detail: DOWNLOAD_QUALITY_DETAILS[quality],
|
||||
|
||||
@@ -34,6 +34,7 @@ import {
|
||||
writeRememberedDownloadQuality,
|
||||
} from "@/lib/downloads"
|
||||
import { loadPlaybackSongs } from "@/lib/playback-files"
|
||||
import { downloadQualitySupported } from "@/lib/playback-capabilities"
|
||||
import type { ServerConfig } from "@/lib/server-config"
|
||||
import { showError } from "@/lib/toast"
|
||||
import { useThemeColors } from "@/lib/theme"
|
||||
@@ -238,36 +239,44 @@ function DownloadQualityPopup({
|
||||
>
|
||||
{pending?.target.title}
|
||||
</Text>
|
||||
{pending?.response.options.map((option) => (
|
||||
<Pressable
|
||||
key={option.quality}
|
||||
accessibilityRole="button"
|
||||
style={[styles.row, { borderBottomColor: colors.border }]}
|
||||
onPress={() => onPick(option.quality, remember)}
|
||||
>
|
||||
<View style={styles.rowText}>
|
||||
{option.quality === "lossless" ||
|
||||
option.quality === "atmos" ? (
|
||||
<AudioFormatBadge
|
||||
format={option.quality}
|
||||
color={colors.foreground}
|
||||
backgroundColor={colors.card}
|
||||
/>
|
||||
) : (
|
||||
<Text style={[styles.label, { color: colors.foreground }]}>
|
||||
{DOWNLOAD_QUALITY_LABELS[option.quality]}
|
||||
{pending?.response.options
|
||||
.filter((option) => downloadQualitySupported(option.quality))
|
||||
.map((option) => (
|
||||
<Pressable
|
||||
key={option.quality}
|
||||
accessibilityRole="button"
|
||||
style={[styles.row, { borderBottomColor: colors.border }]}
|
||||
onPress={() => onPick(option.quality, remember)}
|
||||
>
|
||||
<View style={styles.rowText}>
|
||||
{option.quality === "lossless" ||
|
||||
option.quality === "atmos" ? (
|
||||
<AudioFormatBadge
|
||||
format={option.quality}
|
||||
color={colors.foreground}
|
||||
backgroundColor={colors.card}
|
||||
/>
|
||||
) : (
|
||||
<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 style={{ color: colors.mutedForeground, fontSize: 12 }}>
|
||||
{optionDetail(option, songCount)}
|
||||
</View>
|
||||
<Text
|
||||
style={[styles.size, { color: colors.mutedForeground }]}
|
||||
>
|
||||
{option.estimated ? "~" : ""}
|
||||
{formatBytes(option.bytes)}
|
||||
</Text>
|
||||
</View>
|
||||
<Text style={[styles.size, { color: colors.mutedForeground }]}>
|
||||
{option.estimated ? "~" : ""}
|
||||
{formatBytes(option.bytes)}
|
||||
</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</Pressable>
|
||||
))}
|
||||
<View style={styles.rememberRow}>
|
||||
<Text style={{ color: colors.foreground, fontSize: 15 }}>
|
||||
Remember my choice
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
type DownloadQuality,
|
||||
} from "@otunes/convex/download-quality"
|
||||
import { getAuthCookieHeader } from "@/lib/auth-cookies"
|
||||
import { downloadQualitySupported } from "@/lib/playback-capabilities"
|
||||
import type { ServerConfig } from "@/lib/server-config"
|
||||
|
||||
const REMEMBERED_QUALITY_KEY = "otunes.download-quality"
|
||||
@@ -298,9 +299,10 @@ export function downloadedCoverUri(url: string) {
|
||||
|
||||
export async function readRememberedDownloadQuality() {
|
||||
try {
|
||||
return parseDownloadQuality(
|
||||
const quality = parseDownloadQuality(
|
||||
await AsyncStorage.getItem(REMEMBERED_QUALITY_KEY)
|
||||
)
|
||||
return quality && downloadQualitySupported(quality) ? quality : undefined
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
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.
|
||||
export const dolbyAtmosSupported = Platform.OS === "ios"
|
||||
|
||||
@@ -7,3 +12,13 @@ export const dolbyAtmosSupported = Platform.OS === "ios"
|
||||
export function atmosEnabled(user: { preferAtmos?: boolean }) {
|
||||
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
|
||||
)
|
||||
Reference in new issue
Block a user