Compare commits

..
9 changed files with 80 additions and 175 deletions

No files matched your search

-97
View File
@@ -1,97 +0,0 @@
name: Mobile Build
# Tags build preview Android and iOS and attach them to the tag's release.
# Manual runs pick the profile and platforms and keep the builds as run artifacts.
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
profile:
description: EAS build profile
type: choice
options:
- preview
- development
default: preview
platforms:
description: Platforms to build
type: choice
options:
- all
- android
- ios
default: all
env:
# Tag pushes have no inputs, so they fall back to preview on all platforms.
PROFILE: ${{ inputs.profile || 'preview' }}
EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
jobs:
android:
if: inputs.platforms != 'ios'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 24
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- uses: android-actions/setup-android@v3
- name: Build
id: build
working-directory: apps/mobile
run: |
version=$([[ "$GITHUB_REF" == refs/tags/* ]] && echo "$GITHUB_REF_NAME" || echo "${GITHUB_SHA::7}")
out="$PWD/otunes-$PROFILE-$version.apk"
npx --yes eas-cli@latest build --local --non-interactive --platform android --profile "$PROFILE" --output "$out"
echo "file=$out" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@v3
with:
name: android-${{ env.PROFILE }}
path: ${{ steps.build.outputs.file }}
- name: Attach to release
if: startsWith(gitea.ref, 'refs/tags/')
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
run: scripts/upload-release-asset.sh "${{ steps.build.outputs.file }}"
ios:
if: inputs.platforms != 'android'
# Queues until a self-hosted macOS runner (Xcode, CocoaPods, fastlane) picks it up.
runs-on: macos
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 24
- name: Build
id: build
working-directory: apps/mobile
run: |
version=$([[ "$GITHUB_REF" == refs/tags/* ]] && echo "$GITHUB_REF_NAME" || echo "${GITHUB_SHA::7}")
out="$PWD/otunes-$PROFILE-$version.ipa"
npx --yes eas-cli@latest build --local --non-interactive --platform ios --profile "$PROFILE" --output "$out"
echo "file=$out" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@v3
with:
name: ios-${{ env.PROFILE }}
path: ${{ steps.build.outputs.file }}
- name: Attach to release
if: startsWith(gitea.ref, 'refs/tags/')
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
run: scripts/upload-release-asset.sh "${{ steps.build.outputs.file }}"
+10 -6
View File
@@ -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,
@@ -450,9 +453,10 @@ function QualitySection({ user }: { user: CurrentUser }) {
/** Shades of the text color, faintest for the smallest files. */
const QUALITY_OPACITY: Record<DownloadQuality, number> = {
medium: 0.25,
high: 0.45,
lossless: 0.7,
low: 0.2,
medium: 0.35,
high: 0.5,
lossless: 0.75,
atmos: 1,
}
@@ -507,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],
+1 -15
View File
@@ -1,7 +1,4 @@
import {
useAndroidTabPalette,
useAndroidTabHasArtworkPalette,
} from "@/contexts/android-tab-theme"
import { useAndroidTabPalette } from "@/contexts/android-tab-theme"
import { Ionicons } from "@expo/vector-icons"
import { NativeTabs } from "expo-router/native-tabs"
import { useRouter } from "expo-router"
@@ -166,20 +163,10 @@ function MiniPlayerContent({
function MiniPlayerChrome({ children }: { children: React.ReactNode }) {
const palette = useAndroidTabPalette()
const hasArtworkPalette = useAndroidTabHasArtworkPalette()
return (
<View style={[styles.androidBar, { backgroundColor: palette.background }]}>
{children}
{hasArtworkPalette ? (
<View
style={[
styles.separator,
styles.topBorder,
{ backgroundColor: palette.secondaryForeground },
]}
/>
) : null}
<View
style={[
styles.separator,
@@ -267,7 +254,6 @@ const styles = StyleSheet.create({
height: 1,
zIndex: 1,
},
topBorder: { top: 0 },
bottomBorder: { bottom: 0 },
content: {
flexDirection: "row",
+37 -28
View File
@@ -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
+3 -1
View File
@@ -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
}
+15
View File
@@ -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
)
+4 -3
View File
@@ -39,9 +39,10 @@ const ASK_EVERY_TIME = "ask"
/** Shades of the text color, darkest for the smallest files. */
const QUALITY_OPACITY: Record<DownloadQuality, number> = {
medium: 0.25,
high: 0.45,
lossless: 0.7,
low: 0.2,
medium: 0.35,
high: 0.5,
lossless: 0.75,
atmos: 1,
}
+10 -3
View File
@@ -2,6 +2,7 @@ import type { PlaybackSource, PlaybackStreamPlan } from "./playback-stream"
/** Qualities a listener can pick when downloading, lowest first. */
export const DOWNLOAD_QUALITIES = [
"low",
"medium",
"high",
"lossless",
@@ -11,6 +12,7 @@ export const DOWNLOAD_QUALITIES = [
export type DownloadQuality = (typeof DOWNLOAD_QUALITIES)[number]
export const DOWNLOAD_QUALITY_LABELS: Record<DownloadQuality, string> = {
low: "Low",
medium: "Medium",
high: "High",
lossless: "Lossless",
@@ -18,12 +20,14 @@ export const DOWNLOAD_QUALITY_LABELS: Record<DownloadQuality, string> = {
}
export const DOWNLOAD_QUALITY_DETAILS: Record<DownloadQuality, string> = {
low: "AAC 64 kbps",
medium: "AAC 128 kbps",
high: "AAC 256 kbps",
lossless: "ALAC or FLAC",
atmos: "Spatial audio",
}
const LOW_KBPS = 64
const MEDIUM_KBPS = 128
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
* the song lacks them, and Medium is always transcoded.
* the song lacks them, and Low and Medium are always transcoded.
*/
export function downloadPlan(
files: Record<string, unknown>,
quality: DownloadQuality
): DownloadPlan {
switch (quality) {
case "low":
case "medium":
return {
quality,
@@ -70,7 +75,7 @@ export function downloadPlan(
: "normal" in files
? "normal"
: "atmos",
kbps: MEDIUM_KBPS,
kbps: quality === "low" ? LOW_KBPS : MEDIUM_KBPS,
}
case "high":
return highPlan(files)
@@ -84,7 +89,7 @@ export function downloadPlan(
/**
* 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(
plan: PlaybackStreamPlan
@@ -95,6 +100,7 @@ export function streamDownloadQuality(
}
if (plan.kbps === HIGH_KBPS) return "high"
if (plan.kbps === MEDIUM_KBPS) return "medium"
if (plan.kbps === LOW_KBPS) return "low"
return undefined
}
@@ -129,6 +135,7 @@ export function downloadOptions(
).length
if (
fallbackCount === songs.length &&
quality !== "low" &&
quality !== "medium" &&
quality !== "high"
) {
-22
View File
@@ -1,22 +0,0 @@
#!/usr/bin/env bash
# Uploads a file to the Gitea release for the current tag, creating the release
# if it does not exist yet. Used by .gitea/workflows/mobile-build.yml.
# Usage: GITEA_TOKEN=... upload-release-asset.sh <file>
set -euo pipefail
file=$1
api="$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY/releases"
auth=(-H "Authorization: token $GITEA_TOKEN")
json_id() { node -pe 'JSON.parse(require("fs").readFileSync(0, "utf8")).id'; }
existing_id() { curl -fsS "${auth[@]}" "$api/tags/$GITHUB_REF_NAME" | json_id; }
create_id() {
curl -fsS "${auth[@]}" -H "Content-Type: application/json" \
-d "{\"tag_name\":\"$GITHUB_REF_NAME\",\"name\":\"$GITHUB_REF_NAME\"}" "$api" | json_id
}
# Android and iOS race to create the release; whoever loses re-reads it.
id=$(existing_id 2>/dev/null || create_id || existing_id)
curl -fsS "${auth[@]}" -F "attachment=@$file" \
"$api/$id/assets?name=$(basename "$file")" > /dev/null