Compare commits
7
Commits
No files matched your search
@@ -0,0 +1,70 @@
|
||||
name: Desktop builds
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
# Both targets build in electronuserland/builder:wine. Wine lets
|
||||
# electron-builder stamp the Windows executable; the Flatpak job adds
|
||||
# flatpak-builder and needs a privileged container for its sandbox.
|
||||
# See apps/desktop/README.md for the runner setup.
|
||||
name: Desktop ${{ matrix.target }}
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 90
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- target: windows
|
||||
options: ""
|
||||
- target: linux
|
||||
options: --privileged
|
||||
container:
|
||||
image: electronuserland/builder:wine
|
||||
options: ${{ matrix.options }}
|
||||
env:
|
||||
OTUNES_DESKTOP_REF: ${{ gitea.ref }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up pnpm
|
||||
uses: pnpm/action-setup@v4
|
||||
with:
|
||||
version: 10.1.0
|
||||
run_install: false
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "24"
|
||||
|
||||
- name: Install Flatpak tools
|
||||
if: matrix.target == 'linux'
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install -y flatpak flatpak-builder
|
||||
flatpak remote-add --user --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
|
||||
|
||||
- name: Install desktop and web dependencies
|
||||
run: pnpm --filter @otunes/desktop --filter @otunes/web... install --frozen-lockfile
|
||||
|
||||
- name: Check desktop scripts
|
||||
run: pnpm --filter @otunes/desktop typecheck
|
||||
|
||||
- name: Build x64 and ARM64 installers
|
||||
run: pnpm --filter @otunes/desktop build:${{ matrix.target }}
|
||||
|
||||
# Gitea's artifact service uses the v3 protocol, not GitHub's v4 service.
|
||||
- name: Upload installers
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: otunes-desktop-${{ matrix.target }}
|
||||
path: |
|
||||
apps/desktop/dist/*.exe
|
||||
apps/desktop/dist/*.flatpak
|
||||
if-no-files-found: error
|
||||
@@ -47,3 +47,9 @@ docker-compose.yml
|
||||
**/credentials/
|
||||
**/*.ipa
|
||||
**/*.apk
|
||||
|
||||
# Electron desktop build artifacts
|
||||
apps/desktop/.package/
|
||||
apps/desktop/dist/
|
||||
apps/web/.next-desktop/
|
||||
apps/desktop/web/
|
||||
+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,
|
||||
# Vorbis, WavPack, WMA, E-AC-3/TrueHD for Atmos). Encoders are only the two
|
||||
# the app writes: AAC (HLS, ADTS and .m4a downloads) and FLAC.
|
||||
# the app writes: AAC (HLS and ADTS) and FLAC.
|
||||
RUN ./configure \
|
||||
--prefix=/opt/ffmpeg \
|
||||
--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-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-muxer=adts,flac,hls,ipod,mpegts \
|
||||
--enable-muxer=adts,flac,hls,mpegts \
|
||||
--enable-parser=aac,aac_latm,ac3,flac,mpegaudio,opus,vorbis \
|
||||
--enable-bsf=aac_adtstoasc \
|
||||
--enable-filter=aresample,aformat \
|
||||
|
||||
@@ -9,6 +9,7 @@ This project uses [pnpm workspaces](https://pnpm.io/workspaces):
|
||||
| Package | Path | Description |
|
||||
| --- | --- | --- |
|
||||
| `@otunes/web` | `apps/web` | Next.js web app |
|
||||
| `@otunes/desktop` | `apps/desktop` | Electron client for Windows and Linux |
|
||||
| `@otunes/mobile` | `apps/mobile` | Expo React Native mobile app |
|
||||
| `@otunes/convex` | `packages/convex` | Shared Convex backend and client types |
|
||||
|
||||
@@ -94,3 +95,7 @@ If Convex has to live somewhere else, set `PUBLIC_CONVEX_URL` on the container t
|
||||
## Downloads
|
||||
|
||||
Check the releases tab for the latest downloads for apps: [Releases](https://git.abunchofknowitalls.com/joshuafhiggins/otunes/releases)
|
||||
|
||||
## Desktop builds
|
||||
|
||||
See [the desktop build guide](apps/desktop/README.md) to package the web player for Windows or Linux. The UI is bundled locally, and users choose their oTunes server before signing in.
|
||||
@@ -0,0 +1,38 @@
|
||||
# oTunes desktop
|
||||
|
||||
The Windows and Linux desktop app. It runs stock Electron and serves the web app's static export (`pnpm --filter @otunes/web build:export`) from `http://127.0.0.1:47836`. There is no bundled Node.js server: the UI talks to the selected oTunes server and its Convex backend directly. On first launch, enter the oTunes server domain, then sign in. The address and session are saved in the app's local storage, not compiled into the package.
|
||||
|
||||
For `music.example.com`, Convex connects to `https://convex.music.example.com`. Local hosts follow the mobile convention and use port 3210. The selected server streams audio and serves cover art and avatars. Streams and avatars pass the session token as a `token` query parameter, since the app is on another origin and has no cookie there. The desktop app does not bundle Convex, FFmpeg or a music library.
|
||||
|
||||
Use **Server > Change server** or **Change Server** in the account menu to select another server. Sessions are kept per server; switching clears the cached library data.
|
||||
|
||||
Stock Chromium cannot decode EAC-3, so the player's codec check reports no Dolby Atmos support and the server streams the regular track instead.
|
||||
|
||||
## Run and package
|
||||
|
||||
```sh
|
||||
pnpm install
|
||||
pnpm dev:desktop
|
||||
# Or create installers for this OS, x64 and ARM64:
|
||||
pnpm build:desktop
|
||||
# Or a specific target from a Linux host:
|
||||
pnpm --filter @otunes/desktop build:windows
|
||||
pnpm --filter @otunes/desktop build:linux
|
||||
```
|
||||
|
||||
All of these first build the static export and copy it to `apps/desktop/web`. `pnpm --filter @otunes/desktop build:web` does that step alone. A single instance owns port 47836, so the app's local storage keeps the same origin between launches.
|
||||
|
||||
Packaging writes to `apps/desktop/dist`: an NSIS installer per architecture for Windows, a Flatpak per architecture for Linux. To pick one architecture, pass it after the target: `node scripts/package.mjs linux x64`. Building Windows installers on Linux needs Wine. Flatpaks need flatpak-builder with Flathub added, and ARM64 Flatpaks on an x64 host need `qemu-user-static` registered with binfmt. Installers are unsigned unless you configure electron-builder's signing environment.
|
||||
|
||||
Flatpaks pin `org.freedesktop.Platform`, its SDK and `org.electronjs.Electron2.BaseApp` to `25.08`. Network, audio, graphics and display access are enabled. Home-directory access is not needed.
|
||||
|
||||
## Gitea builds
|
||||
|
||||
`.gitea/workflows/desktop-build.yml` runs manually and on `v*` tags, matching the Docker workflow. Both jobs run on the `ubuntu-latest` Docker runner and upload installers with `actions/upload-artifact@v3`. Tags set the installer version, so use semantic version tags such as `v1.2.3`. Manual runs use the desktop package version. Nothing is published.
|
||||
|
||||
Both jobs use the `electronuserland/builder:wine` container: `windows` builds x64 and ARM64 NSIS installers, and `linux` installs flatpak-builder from apt and builds x64 and ARM64 Flatpaks.
|
||||
|
||||
The Linux job needs two things from the runner host:
|
||||
|
||||
- Privileged job containers, since flatpak-builder sandboxes its build. Set `container.privileged: true` in the runner's config.
|
||||
- An ARM64 binfmt handler. Register it once with `apt install qemu-user-static` on Debian/Ubuntu, which persists across reboots.
|
||||
@@ -0,0 +1,144 @@
|
||||
const { app, BrowserWindow, Menu, nativeTheme, session } = require("electron")
|
||||
const { createServer } = require("node:http")
|
||||
const { readFile } = require("node:fs/promises")
|
||||
const path = require("node:path")
|
||||
|
||||
// The UI is the web app's static export, served on a fixed loopback origin so
|
||||
// its localStorage (picked server, session) persists between launches. An
|
||||
// http://127.0.0.1 page is a secure context that can still reach http servers
|
||||
// on the local network.
|
||||
const host = "127.0.0.1:47836"
|
||||
const origin = `http://${host}`
|
||||
const webRoot = path.join(
|
||||
app.isPackaged ? process.resourcesPath : __dirname,
|
||||
"web"
|
||||
)
|
||||
const contentTypes = {
|
||||
".html": "text/html; charset=utf-8",
|
||||
".txt": "text/plain; charset=utf-8",
|
||||
".js": "text/javascript; charset=utf-8",
|
||||
".css": "text/css; charset=utf-8",
|
||||
".json": "application/json",
|
||||
".webmanifest": "application/manifest+json",
|
||||
".png": "image/png",
|
||||
".svg": "image/svg+xml",
|
||||
".ico": "image/x-icon",
|
||||
".woff2": "font/woff2",
|
||||
}
|
||||
let window, server
|
||||
|
||||
// Resolves paths the way static hosts serve a Next.js export: /album is
|
||||
// album.html, / is index.html, and anything missing is 404.html.
|
||||
async function serveStatic(request, response) {
|
||||
if (request.headers.host !== host) return response.writeHead(403).end()
|
||||
if (request.method !== "GET" && request.method !== "HEAD")
|
||||
return response.writeHead(405).end()
|
||||
let pathname
|
||||
try {
|
||||
pathname = decodeURIComponent(new URL(request.url, origin).pathname)
|
||||
} catch {
|
||||
return response.writeHead(400).end()
|
||||
}
|
||||
const relative = pathname.replace(/^\/+|\/+$/g, "")
|
||||
const candidates = relative
|
||||
? [relative, `${relative}.html`, `${relative}/index.html`]
|
||||
: ["index.html"]
|
||||
for (const candidate of [...candidates, "404.html"]) {
|
||||
const file = path.resolve(webRoot, candidate)
|
||||
if (!file.startsWith(webRoot + path.sep)) continue
|
||||
try {
|
||||
const body = await readFile(file)
|
||||
response.writeHead(candidate === "404.html" ? 404 : 200, {
|
||||
"Content-Type":
|
||||
contentTypes[path.extname(file)] ?? "application/octet-stream",
|
||||
"Cache-Control": file.includes(`${path.sep}_next${path.sep}static`)
|
||||
? "public, max-age=31536000, immutable"
|
||||
: "no-cache",
|
||||
})
|
||||
return response.end(request.method === "HEAD" ? undefined : body)
|
||||
} catch {
|
||||
// Try the next candidate.
|
||||
}
|
||||
}
|
||||
response.writeHead(404).end()
|
||||
}
|
||||
|
||||
function openWindow() {
|
||||
window = new BrowserWindow({
|
||||
title: "oTunes",
|
||||
width: 1280,
|
||||
height: 850,
|
||||
backgroundColor: nativeTheme.shouldUseDarkColors ? "#000000" : "#ffffff",
|
||||
webPreferences: {
|
||||
nodeIntegration: false,
|
||||
contextIsolation: true,
|
||||
sandbox: true,
|
||||
webSecurity: true,
|
||||
},
|
||||
})
|
||||
window.webContents.setWindowOpenHandler(() => ({ action: "deny" }))
|
||||
const restrictNavigation = (event, target) => {
|
||||
if (new URL(target).origin !== origin) event.preventDefault()
|
||||
}
|
||||
window.webContents.on("will-navigate", restrictNavigation)
|
||||
window.webContents.on("will-redirect", restrictNavigation)
|
||||
session.defaultSession.setPermissionRequestHandler(
|
||||
(_contents, _permission, callback) => callback(false)
|
||||
)
|
||||
session.defaultSession.setPermissionCheckHandler(() => false)
|
||||
window.loadURL(`${origin}/`).catch(console.error)
|
||||
window.on("closed", () => {
|
||||
window = undefined
|
||||
})
|
||||
}
|
||||
|
||||
if (!app.requestSingleInstanceLock()) app.quit()
|
||||
else {
|
||||
app.on("second-instance", () => {
|
||||
window?.show()
|
||||
window?.focus()
|
||||
})
|
||||
app
|
||||
.whenReady()
|
||||
.then(async () => {
|
||||
server = createServer((request, response) => {
|
||||
serveStatic(request, response).catch(() => {
|
||||
if (!response.headersSent) response.writeHead(500)
|
||||
response.end()
|
||||
})
|
||||
})
|
||||
await new Promise((resolve, reject) => {
|
||||
server.once("error", reject)
|
||||
server.listen(47836, "127.0.0.1", resolve)
|
||||
})
|
||||
Menu.setApplicationMenu(
|
||||
Menu.buildFromTemplate([
|
||||
...(process.platform === "darwin" ? [{ role: "appMenu" }] : []),
|
||||
{
|
||||
label: "Server",
|
||||
submenu: [
|
||||
{
|
||||
label: "Change server…",
|
||||
click: () => window?.loadURL(`${origin}/server`),
|
||||
},
|
||||
],
|
||||
},
|
||||
{ role: "editMenu" },
|
||||
{ role: "viewMenu" },
|
||||
{ role: "windowMenu" },
|
||||
])
|
||||
)
|
||||
openWindow()
|
||||
app.on("activate", () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) openWindow()
|
||||
})
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error)
|
||||
app.quit()
|
||||
})
|
||||
}
|
||||
app.on("before-quit", () => server?.close())
|
||||
app.on("window-all-closed", () => {
|
||||
if (process.platform !== "darwin") app.quit()
|
||||
})
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "@otunes/desktop",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"description": "oTunes desktop client for Windows and Linux",
|
||||
"author": "oTunes contributors",
|
||||
"main": "main.cjs",
|
||||
"scripts": {
|
||||
"start": "pnpm build:web && electron .",
|
||||
"build": "pnpm build:web && node scripts/package.mjs",
|
||||
"build:windows": "pnpm build:web && node scripts/package.mjs windows",
|
||||
"build:linux": "pnpm build:web && node scripts/package.mjs linux",
|
||||
"build:web": "node scripts/build-web.mjs",
|
||||
"typecheck": "node --check main.cjs && node --check scripts/build-web.mjs && node --check scripts/package.mjs"
|
||||
},
|
||||
"devDependencies": {
|
||||
"electron": "45.3.4",
|
||||
"electron-builder": "26.18.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { execFileSync } from "node:child_process"
|
||||
import { createRequire } from "node:module"
|
||||
import { cp, rm } from "node:fs/promises"
|
||||
import path from "node:path"
|
||||
import { fileURLToPath } from "node:url"
|
||||
|
||||
// Builds the web app's static export and copies it to apps/desktop/web,
|
||||
// which main.cjs serves and package.mjs ships.
|
||||
const desktopRoot = fileURLToPath(new URL("../", import.meta.url))
|
||||
const web = path.resolve(desktopRoot, "../web")
|
||||
const webRequire = createRequire(path.join(web, "package.json"))
|
||||
execFileSync(
|
||||
process.execPath,
|
||||
[webRequire.resolve("next/dist/bin/next"), "build"],
|
||||
{
|
||||
cwd: web,
|
||||
stdio: "inherit",
|
||||
env: { ...process.env, OTUNES_STATIC_EXPORT: "1" },
|
||||
}
|
||||
)
|
||||
|
||||
const destination = path.join(desktopRoot, "web")
|
||||
await rm(destination, { recursive: true, force: true })
|
||||
await cp(path.join(web, "out"), destination, { recursive: true })
|
||||
@@ -0,0 +1,77 @@
|
||||
import { build, Platform, Arch } from "electron-builder"
|
||||
import { mkdir, copyFile, writeFile, rm, readFile } from "node:fs/promises"
|
||||
import { createRequire } from "node:module"
|
||||
import path from "node:path"
|
||||
import { fileURLToPath } from "node:url"
|
||||
|
||||
// Packages stock Electron with the bundled UI from build-web.mjs.
|
||||
// Usage: node scripts/package.mjs [windows|linux] [x64|arm64]
|
||||
// Defaults to the host OS and both architectures. Linux hosts can build both
|
||||
// targets: Windows needs Wine, ARM64 Flatpaks need qemu-user binfmt.
|
||||
const desktopRoot = fileURLToPath(new URL("../", import.meta.url))
|
||||
const hostTarget = { win32: "windows", linux: "linux" }[process.platform]
|
||||
const [target = hostTarget, onlyArch] = process.argv.slice(2)
|
||||
const platform = { windows: Platform.WINDOWS, linux: Platform.LINUX }[target]
|
||||
if (!platform) throw new Error("Targets are windows or linux")
|
||||
const architectures = onlyArch ? [onlyArch] : ["x64", "arm64"]
|
||||
if (!architectures.every((arch) => arch === "x64" || arch === "arm64"))
|
||||
throw new Error("Architectures are x64 or arm64")
|
||||
|
||||
const staging = path.join(desktopRoot, ".package")
|
||||
await rm(staging, { recursive: true, force: true })
|
||||
await mkdir(staging, { recursive: true })
|
||||
await copyFile(
|
||||
path.join(desktopRoot, "main.cjs"),
|
||||
path.join(staging, "main.cjs")
|
||||
)
|
||||
const pkg = JSON.parse(
|
||||
await readFile(path.join(desktopRoot, "package.json"), "utf8")
|
||||
)
|
||||
const ref = process.env.OTUNES_DESKTOP_REF ?? ""
|
||||
if (ref.startsWith("refs/tags/"))
|
||||
pkg.version = ref.slice("refs/tags/".length).replace(/^v/, "")
|
||||
delete pkg.devDependencies
|
||||
delete pkg.scripts
|
||||
await writeFile(
|
||||
path.join(staging, "package.json"),
|
||||
JSON.stringify(pkg, null, 2)
|
||||
)
|
||||
|
||||
const { version: electronVersion } = createRequire(import.meta.url)(
|
||||
"electron/package.json"
|
||||
)
|
||||
// One build per architecture: a multi-arch NSIS build merges both into one installer.
|
||||
for (const arch of architectures) {
|
||||
await build({
|
||||
targets: platform.createTarget(undefined, Arch[arch]),
|
||||
config: {
|
||||
appId: "com.otunes.desktop",
|
||||
productName: "oTunes",
|
||||
electronVersion,
|
||||
artifactName: "oTunes-${version}-${os}-${arch}.${ext}",
|
||||
icon: path.resolve(desktopRoot, "../web/public/logo.png"),
|
||||
directories: { app: staging, output: path.join(desktopRoot, "dist") },
|
||||
files: ["main.cjs", "package.json"],
|
||||
extraResources: [
|
||||
{ from: path.join(desktopRoot, "web"), to: "web", filter: ["**/*"] },
|
||||
],
|
||||
npmRebuild: false,
|
||||
win: { target: ["nsis"] },
|
||||
linux: { category: "AudioVideo", target: ["flatpak"] },
|
||||
flatpak: {
|
||||
runtimeVersion: "25.08",
|
||||
baseVersion: "25.08",
|
||||
finishArgs: [
|
||||
"--socket=wayland",
|
||||
"--socket=fallback-x11",
|
||||
"--share=ipc",
|
||||
"--device=dri",
|
||||
"--socket=pulseaudio",
|
||||
"--share=network",
|
||||
],
|
||||
},
|
||||
publish: null,
|
||||
},
|
||||
publish: "never",
|
||||
})
|
||||
}
|
||||
@@ -32,13 +32,6 @@ export default ({ config }: ConfigContext): ExpoConfig => {
|
||||
...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"
|
||||
? ["./plugins/with-mac-catalyst"]
|
||||
: []),
|
||||
|
||||
+16
-14
@@ -1,8 +1,11 @@
|
||||
import { Stack } from "expo-router"
|
||||
|
||||
import { TabStackContext } from "@/lib/app-navigation"
|
||||
import { renderTabScreenContent } from "@/components/tab-screen-content"
|
||||
import { useStackScreenOptions, tabStackScreenTitles } from "@/lib/navigation"
|
||||
import {
|
||||
inlineTitleOptions,
|
||||
tabStackScreenTitles,
|
||||
useStackScreenOptions,
|
||||
} from "@/lib/navigation"
|
||||
import { tabletSections, TabletSectionContext } from "@/lib/tablet-navigation"
|
||||
|
||||
export default function TabletSectionLayout({ segment }: { segment: string }) {
|
||||
@@ -11,18 +14,17 @@ export default function TabletSectionLayout({ segment }: { segment: string }) {
|
||||
|
||||
return (
|
||||
<TabletSectionContext value={section}>
|
||||
<TabStackContext value={section?.group}>
|
||||
<Stack
|
||||
screenLayout={renderTabScreenContent}
|
||||
screenOptions={({ route }) => ({
|
||||
...options,
|
||||
title:
|
||||
route.name === "index"
|
||||
? section?.title
|
||||
: tabStackScreenTitles[route.name],
|
||||
})}
|
||||
/>
|
||||
</TabStackContext>
|
||||
<Stack
|
||||
screenLayout={renderTabScreenContent}
|
||||
screenOptions={({ route }) => ({
|
||||
...options,
|
||||
...inlineTitleOptions,
|
||||
title:
|
||||
route.name === "index"
|
||||
? section?.title
|
||||
: tabStackScreenTitles[route.name],
|
||||
})}
|
||||
/>
|
||||
</TabletSectionContext>
|
||||
)
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
import { renderTabScreenContent } from "@/components/tab-screen-content"
|
||||
import { Stack } from "expo-router"
|
||||
|
||||
import { TabStackContext } from "@/lib/app-navigation"
|
||||
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
||||
import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
|
||||
import {
|
||||
inlineTitleOptions,
|
||||
tabStackScreenTitles,
|
||||
useStackScreenOptions,
|
||||
} from "@/lib/navigation"
|
||||
|
||||
export const unstable_settings = {
|
||||
anchor: "index",
|
||||
@@ -13,26 +16,25 @@ export default function HomeLayout() {
|
||||
const baseOptions = useStackScreenOptions({ title: "Home" })
|
||||
|
||||
return (
|
||||
<TabStackContext value="home">
|
||||
<Stack
|
||||
screenLayout={renderTabScreenContent}
|
||||
screenOptions={({ route }) => ({
|
||||
...baseOptions,
|
||||
title: tabStackScreenTitles[route.name] ?? "Home",
|
||||
headerRight:
|
||||
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
||||
unstable_headerRightItems:
|
||||
route.name === "index"
|
||||
? () => [
|
||||
{
|
||||
type: "custom",
|
||||
element: <ProfileHeaderButton />,
|
||||
hidesSharedBackground: true,
|
||||
},
|
||||
]
|
||||
: undefined,
|
||||
})}
|
||||
/>
|
||||
</TabStackContext>
|
||||
<Stack
|
||||
screenLayout={renderTabScreenContent}
|
||||
screenOptions={({ route }) => ({
|
||||
...baseOptions,
|
||||
...inlineTitleOptions,
|
||||
title: tabStackScreenTitles[route.name] ?? "Home",
|
||||
headerRight:
|
||||
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
||||
unstable_headerRightItems:
|
||||
route.name === "index"
|
||||
? () => [
|
||||
{
|
||||
type: "custom",
|
||||
element: <ProfileHeaderButton />,
|
||||
hidesSharedBackground: true,
|
||||
},
|
||||
]
|
||||
: undefined,
|
||||
})}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -53,7 +53,7 @@ export default function AlbumsScreen() {
|
||||
return (
|
||||
<>
|
||||
{searchBar}
|
||||
<MediaGridSkeleton />
|
||||
<MediaGridSkeleton title="Albums" />
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -63,6 +63,7 @@ export default function AlbumsScreen() {
|
||||
{searchBar}
|
||||
|
||||
<MediaGridList
|
||||
title="Albums"
|
||||
content={albums}
|
||||
paddingBottom={contentBottomInset}
|
||||
onEndReached={() => {
|
||||
|
||||
@@ -2,12 +2,13 @@ import { Ionicons } from "@expo/vector-icons"
|
||||
import { Stack } from "expo-router"
|
||||
import { memo, useCallback } from "react"
|
||||
import {
|
||||
FlatList,
|
||||
type FlatList,
|
||||
Pressable,
|
||||
StyleSheet,
|
||||
Text,
|
||||
type ListRenderItemInfo,
|
||||
} from "react-native"
|
||||
import Animated from "react-native-reanimated"
|
||||
|
||||
import {
|
||||
MediaContextMenu,
|
||||
@@ -15,6 +16,7 @@ import {
|
||||
} from "@/components/media-context-menu"
|
||||
import { CoverImage } from "@/components/cover-image"
|
||||
import { ArtistListSkeleton } from "@/components/skeletons"
|
||||
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||
import { contentBottomInset } from "@/components/player"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import {
|
||||
@@ -33,6 +35,7 @@ import { spacing, useThemeColors } from "@/lib/theme"
|
||||
const PAGE_SIZE = 50
|
||||
|
||||
export default function ArtistsScreen() {
|
||||
const { ref, scrollY } = useScreenTitleScroll<FlatList<BrowseArtist>>()
|
||||
const { push } = useAppNavigation()
|
||||
const colors = useThemeColors()
|
||||
const { config } = useServerConfig()
|
||||
@@ -94,7 +97,7 @@ export default function ArtistsScreen() {
|
||||
return (
|
||||
<>
|
||||
{searchBar}
|
||||
<ArtistListSkeleton />
|
||||
<ArtistListSkeleton title="Artists" />
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -103,8 +106,11 @@ export default function ArtistsScreen() {
|
||||
<>
|
||||
{searchBar}
|
||||
|
||||
<FlatList
|
||||
<Animated.FlatList
|
||||
{...longListProps}
|
||||
ref={ref}
|
||||
scrollEventThrottle={16}
|
||||
ListHeaderComponent={<ScreenTitle title="Artists" scrollY={scrollY} />}
|
||||
data={artists}
|
||||
keyExtractor={artistKey}
|
||||
renderItem={renderItem}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useContext } from "react"
|
||||
import { Pressable } from "react-native"
|
||||
|
||||
import { MediaGridList } from "@/components/media-cards"
|
||||
@@ -10,19 +11,20 @@ import { Ionicons } from "@expo/vector-icons"
|
||||
import { Stack } from "expo-router"
|
||||
import { SymbolView } from "expo-symbols"
|
||||
import { useAddToPlaylist } from "@/contexts/add-to-playlist"
|
||||
import { TabletSectionContext } from "@/lib/tablet-navigation"
|
||||
|
||||
export default function PlaylistsTabScreen() {
|
||||
const colors = useThemeColors()
|
||||
const playlists = useCachedQuery(api.playlists.listAllPlaylists)
|
||||
const { openCreatePlaylist } = useAddToPlaylist()
|
||||
const title = useContext(TabletSectionContext)?.title ?? "Playlists"
|
||||
|
||||
if (playlists === undefined) {
|
||||
return (
|
||||
<>
|
||||
<Stack.Screen
|
||||
options={{
|
||||
title: "Playlists",
|
||||
headerLargeTitle: true,
|
||||
title,
|
||||
headerRight: () => (
|
||||
<Pressable
|
||||
onPress={openCreatePlaylist}
|
||||
@@ -38,7 +40,7 @@ export default function PlaylistsTabScreen() {
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<MediaGridSkeleton />
|
||||
<MediaGridSkeleton title={title} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -47,8 +49,7 @@ export default function PlaylistsTabScreen() {
|
||||
<>
|
||||
<Stack.Screen
|
||||
options={{
|
||||
title: "Playlists",
|
||||
headerLargeTitle: true,
|
||||
title,
|
||||
headerRight: () => (
|
||||
<Pressable
|
||||
onPress={openCreatePlaylist}
|
||||
@@ -61,6 +62,7 @@ export default function PlaylistsTabScreen() {
|
||||
}}
|
||||
/>
|
||||
<MediaGridList
|
||||
title={title}
|
||||
content={playlists}
|
||||
paddingBottom={tabContentBottomInset}
|
||||
/>
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import { Stack } from "expo-router"
|
||||
import { useCallback, useState } from "react"
|
||||
import { FlatList, StyleSheet, type ListRenderItemInfo } from "react-native"
|
||||
import {
|
||||
type FlatList,
|
||||
StyleSheet,
|
||||
type ListRenderItemInfo,
|
||||
} from "react-native"
|
||||
import Animated from "react-native-reanimated"
|
||||
|
||||
import type { MediaAction } from "@/components/media-context-menu"
|
||||
import { contentBottomInset, SongListRow } from "@/components/player"
|
||||
import { SongListSkeleton } from "@/components/skeletons"
|
||||
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||
import { useFavorites } from "@/contexts/favorites"
|
||||
import { usePlaybackActions } from "@/contexts/playback"
|
||||
import {
|
||||
@@ -20,6 +26,7 @@ import { longListProps } from "@/lib/list"
|
||||
const PAGE_SIZE = 50
|
||||
|
||||
export default function SongsScreen() {
|
||||
const { ref, scrollY } = useScreenTitleScroll<FlatList<BrowseSong>>()
|
||||
const { playFromLibrarySong } = usePlaybackActions()
|
||||
const { isSongFavorite } = useFavorites()
|
||||
const { handleSongAction } = useMediaMenuActions()
|
||||
@@ -87,7 +94,7 @@ export default function SongsScreen() {
|
||||
return (
|
||||
<>
|
||||
{searchBar}
|
||||
<SongListSkeleton />
|
||||
<SongListSkeleton title="Songs" />
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -96,8 +103,11 @@ export default function SongsScreen() {
|
||||
<>
|
||||
{searchBar}
|
||||
|
||||
<FlatList
|
||||
<Animated.FlatList
|
||||
{...longListProps}
|
||||
ref={ref}
|
||||
scrollEventThrottle={16}
|
||||
ListHeaderComponent={<ScreenTitle title="Songs" scrollY={scrollY} />}
|
||||
data={songs}
|
||||
keyExtractor={songKey}
|
||||
renderItem={renderItem}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useMemo } from "react"
|
||||
import {
|
||||
FlatList,
|
||||
type FlatList,
|
||||
Pressable,
|
||||
StyleSheet,
|
||||
Text,
|
||||
@@ -8,8 +8,10 @@ import {
|
||||
type ListRenderItemInfo,
|
||||
} from "react-native"
|
||||
import { Stack } from "expo-router"
|
||||
import Animated from "react-native-reanimated"
|
||||
|
||||
import { CoverImage } from "@/components/cover-image"
|
||||
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||
import { tabContentBottomInset } from "@/components/player"
|
||||
import {
|
||||
FAVORITES_DOWNLOAD_ID,
|
||||
@@ -53,6 +55,7 @@ export default function DownloadsScreen() {
|
||||
const { push } = useAppNavigation()
|
||||
const { columns, cardWidth, onLayout, horizontalPadding, gap } =
|
||||
useMediaGridLayout()
|
||||
const { ref, scrollY } = useScreenTitleScroll<FlatList<Card>>()
|
||||
|
||||
const cards = useMemo<Card[]>(() => {
|
||||
if (!queue) return []
|
||||
@@ -135,8 +138,10 @@ export default function DownloadsScreen() {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack.Screen options={{ title: "Downloads", headerLargeTitle: true }} />
|
||||
<FlatList
|
||||
<Stack.Screen options={{ title: "Downloads" }} />
|
||||
<Animated.FlatList
|
||||
ref={ref}
|
||||
scrollEventThrottle={16}
|
||||
key={columns}
|
||||
onLayout={onLayout}
|
||||
data={cards}
|
||||
@@ -149,13 +154,20 @@ export default function DownloadsScreen() {
|
||||
numColumns={columns}
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={{
|
||||
paddingTop: spacing.lg,
|
||||
paddingHorizontal: horizontalPadding,
|
||||
paddingBottom: tabContentBottomInset,
|
||||
gap,
|
||||
}}
|
||||
columnWrapperStyle={columns > 1 ? { gap } : undefined}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
ListHeaderComponent={
|
||||
<ScreenTitle
|
||||
title="Downloads"
|
||||
scrollY={scrollY}
|
||||
// The list padding already insets the title.
|
||||
style={{ paddingHorizontal: 0 }}
|
||||
/>
|
||||
}
|
||||
ListEmptyComponent={
|
||||
<View style={styles.empty}>
|
||||
<Text style={{ color: colors.mutedForeground }}>
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
import { useCallback, useMemo } from "react"
|
||||
import {
|
||||
FlatList,
|
||||
type FlatList,
|
||||
Pressable,
|
||||
StyleSheet,
|
||||
Text,
|
||||
View,
|
||||
type ListRenderItemInfo,
|
||||
} from "react-native"
|
||||
import Animated from "react-native-reanimated"
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
import { Stack } from "expo-router"
|
||||
|
||||
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||
import { useSwipeRowGroup } from "@/components/ios-swipe-to-remove-row"
|
||||
import type { MediaAction } from "@/components/media-context-menu"
|
||||
import { contentBottomInset, SongListRow } from "@/components/player"
|
||||
@@ -52,6 +54,7 @@ export default function OtherDownloadsScreen() {
|
||||
const { isSongFavorite } = useFavorites()
|
||||
const { handleSongAction } = useMediaMenuActions()
|
||||
const swipeGroup = useSwipeRowGroup()
|
||||
const { ref, scrollY } = useScreenTitleScroll<FlatList<BrowseSong>>()
|
||||
|
||||
const handlePlaySong = useCallback(
|
||||
(song: BrowseSong) => void playFromSong(song.id, playableIds, PLAY_ORIGIN),
|
||||
@@ -90,11 +93,11 @@ export default function OtherDownloadsScreen() {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack.Screen
|
||||
options={{ title: OTHER_DOWNLOADS_TITLE, headerLargeTitle: false }}
|
||||
/>
|
||||
<FlatList
|
||||
<Stack.Screen options={{ title: OTHER_DOWNLOADS_TITLE }} />
|
||||
<Animated.FlatList
|
||||
{...longListProps}
|
||||
ref={ref}
|
||||
scrollEventThrottle={16}
|
||||
data={songs}
|
||||
keyExtractor={(song) => song.id}
|
||||
renderItem={renderItem}
|
||||
@@ -103,25 +106,32 @@ export default function OtherDownloadsScreen() {
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
onScrollBeginDrag={swipeGroup.closeOpenRow}
|
||||
ListHeaderComponent={
|
||||
songs.length > 0 ? (
|
||||
<View style={styles.actions}>
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel="Shuffle"
|
||||
hitSlop={8}
|
||||
onPress={() => void playShuffled(playableIds, PLAY_ORIGIN)}
|
||||
style={[styles.iconAction, { backgroundColor: colors.muted }]}
|
||||
>
|
||||
<Ionicons name="shuffle" size={24} color={colors.foreground} />
|
||||
</Pressable>
|
||||
<Button
|
||||
title="Play"
|
||||
icon="play"
|
||||
onPress={() => void playInOrder(playableIds, PLAY_ORIGIN)}
|
||||
style={styles.playButton}
|
||||
/>
|
||||
</View>
|
||||
) : undefined
|
||||
<>
|
||||
<ScreenTitle title={OTHER_DOWNLOADS_TITLE} scrollY={scrollY} />
|
||||
{songs.length > 0 ? (
|
||||
<View style={styles.actions}>
|
||||
<Button
|
||||
title="Play"
|
||||
icon="play"
|
||||
onPress={() => void playInOrder(playableIds, PLAY_ORIGIN)}
|
||||
style={styles.play}
|
||||
/>
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel="Shuffle"
|
||||
hitSlop={8}
|
||||
onPress={() => void playShuffled(playableIds, PLAY_ORIGIN)}
|
||||
style={[styles.shuffle, { backgroundColor: colors.card }]}
|
||||
>
|
||||
<Ionicons
|
||||
name="shuffle"
|
||||
size={24}
|
||||
color={colors.foreground}
|
||||
/>
|
||||
</Pressable>
|
||||
</View>
|
||||
) : null}
|
||||
</>
|
||||
}
|
||||
ListEmptyComponent={
|
||||
<Text style={[styles.empty, { color: colors.mutedForeground }]}>
|
||||
@@ -137,15 +147,14 @@ const styles = StyleSheet.create({
|
||||
actions: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
gap: spacing.sm,
|
||||
padding: spacing.lg,
|
||||
},
|
||||
playButton: { borderRadius: 999, minWidth: 160 },
|
||||
iconAction: {
|
||||
width: 44,
|
||||
height: 44,
|
||||
borderRadius: 22,
|
||||
play: { flex: 1 },
|
||||
shuffle: {
|
||||
width: 48,
|
||||
height: 48,
|
||||
borderRadius: 24,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
},
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { memo } from "react"
|
||||
import { ScrollView, StyleSheet } from "react-native"
|
||||
import { type ScrollViewInstance, StyleSheet } from "react-native"
|
||||
import Animated from "react-native-reanimated"
|
||||
|
||||
import { ContentCarousel } from "@/components/media-cards"
|
||||
import { HomeSkeleton } from "@/components/skeletons"
|
||||
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||
import { tabContentBottomInset } from "@/components/player"
|
||||
import { useCachedPaginatedQuery } from "@/hooks/use-cached-query"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
@@ -38,6 +40,7 @@ const HomeCarousels = memo(function HomeCarousels({
|
||||
|
||||
export default function HomeScreen() {
|
||||
const colors = useThemeColors()
|
||||
const { ref, scrollY } = useScreenTitleScroll<ScrollViewInstance>()
|
||||
const recentlyAdded = useCachedPaginatedQuery(
|
||||
api.library.browseRecentlyAddedPaginated,
|
||||
{},
|
||||
@@ -53,14 +56,16 @@ export default function HomeScreen() {
|
||||
(result) => result.status === "LoadingFirstPage" && !result.isCached
|
||||
)
|
||||
if (isLoading) {
|
||||
return <HomeSkeleton />
|
||||
return <HomeSkeleton title="Home" />
|
||||
}
|
||||
|
||||
const added = recentlyAdded.results.slice(0, CAROUSEL_ITEM_LIMIT)
|
||||
const played = recentlyPlayed.results.slice(0, CAROUSEL_ITEM_LIMIT)
|
||||
|
||||
return (
|
||||
<ScrollView
|
||||
<Animated.ScrollView
|
||||
ref={ref}
|
||||
scrollEventThrottle={16}
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={[
|
||||
styles.content,
|
||||
@@ -68,8 +73,9 @@ export default function HomeScreen() {
|
||||
]}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
>
|
||||
<ScreenTitle title="Home" scrollY={scrollY} style={styles.title} />
|
||||
<HomeCarousels recentlyAdded={added} recentlyPlayed={played} />
|
||||
</ScrollView>
|
||||
</Animated.ScrollView>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -78,4 +84,10 @@ const styles = StyleSheet.create({
|
||||
padding: spacing.lg,
|
||||
gap: spacing.xl,
|
||||
},
|
||||
// The content padding already insets the title.
|
||||
title: {
|
||||
paddingHorizontal: 0,
|
||||
marginTop: -spacing.lg,
|
||||
marginBottom: -spacing.md,
|
||||
},
|
||||
})
|
||||
@@ -14,11 +14,12 @@ export default function RecentlyAddedScreen() {
|
||||
)
|
||||
|
||||
if (status === "LoadingFirstPage" && !isCached) {
|
||||
return <MediaGridSkeleton />
|
||||
return <MediaGridSkeleton title="Recently Added" />
|
||||
}
|
||||
|
||||
return (
|
||||
<MediaGridList
|
||||
title="Recently Added"
|
||||
content={results}
|
||||
paddingBottom={contentBottomInset}
|
||||
onEndReached={() => {
|
||||
|
||||
@@ -14,11 +14,12 @@ export default function RecentlyPlayedScreen() {
|
||||
)
|
||||
|
||||
if (status === "LoadingFirstPage" && !isCached) {
|
||||
return <MediaGridSkeleton />
|
||||
return <MediaGridSkeleton title="Recently Played" />
|
||||
}
|
||||
|
||||
return (
|
||||
<MediaGridList
|
||||
title="Recently Played"
|
||||
content={results}
|
||||
paddingBottom={contentBottomInset}
|
||||
onEndReached={() => {
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import {
|
||||
atmosEnabled,
|
||||
deviceDownloadQualities,
|
||||
dolbyAtmosSupported,
|
||||
} from "@/lib/playback-capabilities"
|
||||
import { atmosEnabled, dolbyAtmosSupported } from "@/lib/playback-capabilities"
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
import { useAction, useMutation, useQuery } from "convex/react"
|
||||
import { Image } from "expo-image"
|
||||
@@ -29,6 +25,7 @@ import {
|
||||
writeRememberedDownloadQuality,
|
||||
} from "@/lib/downloads"
|
||||
import {
|
||||
DOWNLOAD_QUALITIES,
|
||||
DOWNLOAD_QUALITY_DETAILS,
|
||||
DOWNLOAD_QUALITY_LABELS,
|
||||
formatBytes,
|
||||
@@ -453,10 +450,9 @@ function QualitySection({ user }: { user: CurrentUser }) {
|
||||
|
||||
/** Shades of the text color, faintest for the smallest files. */
|
||||
const QUALITY_OPACITY: Record<DownloadQuality, number> = {
|
||||
low: 0.2,
|
||||
medium: 0.35,
|
||||
high: 0.5,
|
||||
lossless: 0.75,
|
||||
medium: 0.25,
|
||||
high: 0.45,
|
||||
lossless: 0.7,
|
||||
atmos: 1,
|
||||
}
|
||||
|
||||
@@ -511,7 +507,7 @@ function RememberedQualityCard() {
|
||||
detail: string
|
||||
}[] = [
|
||||
{ value: null, label: "Ask every time", detail: "Choose when downloading" },
|
||||
...deviceDownloadQualities.map((quality) => ({
|
||||
...DOWNLOAD_QUALITIES.map((quality) => ({
|
||||
value: quality,
|
||||
label: DOWNLOAD_QUALITY_LABELS[quality],
|
||||
detail: DOWNLOAD_QUALITY_DETAILS[quality],
|
||||
|
||||
@@ -2,9 +2,12 @@ import { useTabletLayout } from "@/hooks/use-tablet-layout"
|
||||
import { renderTabScreenContent } from "@/components/tab-screen-content"
|
||||
import { Stack } from "expo-router"
|
||||
|
||||
import { TabStackContext } from "@/lib/app-navigation"
|
||||
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
||||
import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
|
||||
import {
|
||||
inlineTitleOptions,
|
||||
tabStackScreenTitles,
|
||||
useStackScreenOptions,
|
||||
} from "@/lib/navigation"
|
||||
|
||||
export const unstable_settings = {
|
||||
anchor: "index",
|
||||
@@ -15,28 +18,27 @@ export default function LibraryLayout() {
|
||||
const baseOptions = useStackScreenOptions({ title: "Library" })
|
||||
|
||||
return (
|
||||
<TabStackContext value="library">
|
||||
<Stack
|
||||
screenLayout={renderTabScreenContent}
|
||||
screenOptions={({ route }) => ({
|
||||
...baseOptions,
|
||||
title:
|
||||
tabStackScreenTitles[route.name] ??
|
||||
(tabletLayout ? "Recently Added" : "Library"),
|
||||
headerRight:
|
||||
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
||||
unstable_headerRightItems:
|
||||
route.name === "index"
|
||||
? () => [
|
||||
{
|
||||
type: "custom",
|
||||
element: <ProfileHeaderButton />,
|
||||
hidesSharedBackground: true,
|
||||
},
|
||||
]
|
||||
: undefined,
|
||||
})}
|
||||
/>
|
||||
</TabStackContext>
|
||||
<Stack
|
||||
screenLayout={renderTabScreenContent}
|
||||
screenOptions={({ route }) => ({
|
||||
...baseOptions,
|
||||
...inlineTitleOptions,
|
||||
title:
|
||||
tabStackScreenTitles[route.name] ??
|
||||
(tabletLayout ? "Recently Added" : "Library"),
|
||||
headerRight:
|
||||
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
||||
unstable_headerRightItems:
|
||||
route.name === "index"
|
||||
? () => [
|
||||
{
|
||||
type: "custom",
|
||||
element: <ProfileHeaderButton />,
|
||||
hidesSharedBackground: true,
|
||||
},
|
||||
]
|
||||
: undefined,
|
||||
})}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -72,6 +72,7 @@ export default function LibraryScreen() {
|
||||
const { push } = useAppNavigation()
|
||||
const isTablet = tabletLayout
|
||||
const colors = useThemeColors()
|
||||
const title = isTablet ? "Recently Added" : "Library"
|
||||
const { results, status, loadMore, isCached } = useCachedPaginatedQuery(
|
||||
api.library.browseRecentlyAddedPaginated,
|
||||
{},
|
||||
@@ -124,11 +125,18 @@ export default function LibraryScreen() {
|
||||
)
|
||||
|
||||
if (status === "LoadingFirstPage" && !isCached) {
|
||||
return <MediaGridSkeleton contentInset={false} header={listHeader} />
|
||||
return (
|
||||
<MediaGridSkeleton
|
||||
title={title}
|
||||
contentInset={false}
|
||||
header={listHeader}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<MediaGridList
|
||||
title={title}
|
||||
content={results}
|
||||
paddingBottom={tabContentBottomInset}
|
||||
contentInset={false}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { renderTabScreenContent } from "@/components/tab-screen-content"
|
||||
import { Stack } from "expo-router"
|
||||
|
||||
import { TabStackContext } from "@/lib/app-navigation"
|
||||
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
||||
import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
|
||||
import {
|
||||
inlineTitleOptions,
|
||||
tabStackScreenTitles,
|
||||
useStackScreenOptions,
|
||||
} from "@/lib/navigation"
|
||||
|
||||
export const unstable_settings = {
|
||||
anchor: "index",
|
||||
@@ -13,26 +16,25 @@ export default function SearchLayout() {
|
||||
const baseOptions = useStackScreenOptions({ title: "Search" })
|
||||
|
||||
return (
|
||||
<TabStackContext value="search">
|
||||
<Stack
|
||||
screenLayout={renderTabScreenContent}
|
||||
screenOptions={({ route }) => ({
|
||||
...baseOptions,
|
||||
title: tabStackScreenTitles[route.name] ?? "Search",
|
||||
headerRight:
|
||||
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
||||
unstable_headerRightItems:
|
||||
route.name === "index"
|
||||
? () => [
|
||||
{
|
||||
type: "custom",
|
||||
element: <ProfileHeaderButton />,
|
||||
hidesSharedBackground: true,
|
||||
},
|
||||
]
|
||||
: undefined,
|
||||
})}
|
||||
/>
|
||||
</TabStackContext>
|
||||
<Stack
|
||||
screenLayout={renderTabScreenContent}
|
||||
screenOptions={({ route }) => ({
|
||||
...baseOptions,
|
||||
...inlineTitleOptions,
|
||||
title: tabStackScreenTitles[route.name] ?? "Search",
|
||||
headerRight:
|
||||
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
||||
unstable_headerRightItems:
|
||||
route.name === "index"
|
||||
? () => [
|
||||
{
|
||||
type: "custom",
|
||||
element: <ProfileHeaderButton />,
|
||||
hidesSharedBackground: true,
|
||||
},
|
||||
]
|
||||
: undefined,
|
||||
})}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -35,7 +35,7 @@ export default function SearchScreen() {
|
||||
: {})}
|
||||
/>
|
||||
|
||||
<SearchResults searchQuery={searchQuery} />
|
||||
<SearchResults searchQuery={searchQuery} title="Search" />
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,13 +1,4 @@
|
||||
import {
|
||||
memo,
|
||||
type ComponentType,
|
||||
type ReactElement,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react"
|
||||
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react"
|
||||
import {
|
||||
Pressable,
|
||||
ScrollView,
|
||||
@@ -15,11 +6,13 @@ import {
|
||||
Text,
|
||||
View,
|
||||
type ScrollViewInstance,
|
||||
type ViewProps,
|
||||
} from "react-native"
|
||||
import MaskedViewClass from "@react-native-masked-view/masked-view"
|
||||
import Animated, {
|
||||
cancelAnimation,
|
||||
Easing,
|
||||
useAnimatedStyle,
|
||||
useSharedValue,
|
||||
withTiming,
|
||||
type SharedValue,
|
||||
} from "react-native-reanimated"
|
||||
|
||||
@@ -28,7 +21,7 @@ import {
|
||||
usePlaybackProgress,
|
||||
usePlaybackQueue,
|
||||
} from "@/contexts/playback"
|
||||
import { useLyricsTime, usePlaybackClock } from "@/hooks/use-lyrics"
|
||||
import { useLyricsTime } from "@/hooks/use-lyrics"
|
||||
import type { NowPlayingColors } from "@/lib/now-playing-colors"
|
||||
import {
|
||||
activeLineIndex,
|
||||
@@ -37,21 +30,12 @@ import {
|
||||
type 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. */
|
||||
const MANUAL_SCROLL_HOLD_MS = 3000
|
||||
/** Where the playing line sits, as a share of the view's height from the top. */
|
||||
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
|
||||
@@ -92,7 +76,6 @@ function LyricsLines({
|
||||
const { isPlaying } = usePlaybackQueue()
|
||||
const { seekTo, setIsPlaying } = usePlaybackActions()
|
||||
const time = useLyricsTime(lyrics, currentTime, isPlaying)
|
||||
const clock = usePlaybackClock(currentTime, isPlaying)
|
||||
const active = activeLineIndex(lyrics, time)
|
||||
const synced = lyrics.synced !== "none"
|
||||
const scrollRef = useRef<ScrollViewInstance>(null)
|
||||
@@ -186,7 +169,8 @@ function LyricsLines({
|
||||
: Math.min(Math.abs(index - active), LINE_BLUR.length - 1)
|
||||
}
|
||||
active={index === active}
|
||||
clock={clock}
|
||||
time={index === active ? time : null}
|
||||
isPlaying={isPlaying}
|
||||
colors={colors}
|
||||
textStyle={lineStyle}
|
||||
onSelect={playFrom}
|
||||
@@ -214,16 +198,17 @@ function LyricsLines({
|
||||
}
|
||||
|
||||
/**
|
||||
* One timed line, laid out word by word whether or not it is playing, so it
|
||||
* never re-wraps. It fades and blurs by its `distance` from the playing line,
|
||||
* and only the playing line's words fill.
|
||||
* One timed line, blurred by its `distance` from the playing line. Only the
|
||||
* playing line gets the time, so the others skip re-rendering as the song
|
||||
* plays.
|
||||
*/
|
||||
const SyncedLine = memo(function SyncedLine({
|
||||
index,
|
||||
line,
|
||||
distance,
|
||||
active,
|
||||
clock,
|
||||
time,
|
||||
isPlaying,
|
||||
colors,
|
||||
textStyle,
|
||||
onSelect,
|
||||
@@ -233,100 +218,136 @@ const SyncedLine = memo(function SyncedLine({
|
||||
line: LyricLine
|
||||
distance: number
|
||||
active: boolean
|
||||
clock: SharedValue<number>
|
||||
time: number | null
|
||||
isPlaying: boolean
|
||||
colors: NowPlayingColors
|
||||
textStyle: { fontSize: number; lineHeight: number }
|
||||
onSelect: (seconds: number) => void
|
||||
onLayoutY: (index: number, y: number) => void
|
||||
}) {
|
||||
const wordStyle = [styles.lineText, textStyle, { color: colors.foreground }]
|
||||
const blur = LINE_BLUR[distance]
|
||||
return (
|
||||
<Pressable
|
||||
onPress={() => onSelect(line.start ?? 0)}
|
||||
onLayout={(event) => onLayoutY(index, event.nativeEvent.layout.y)}
|
||||
accessibilityRole="button"
|
||||
accessibilityHint="Plays from this line"
|
||||
style={styles.line}
|
||||
style={[styles.line, blur > 0 && { filter: [{ blur }] }]}
|
||||
>
|
||||
<Animated.View
|
||||
style={{
|
||||
opacity: active ? 1 : INACTIVE_LINE_OPACITY,
|
||||
filter: [{ blur: LINE_BLUR[distance] }],
|
||||
transitionProperty: ["opacity", "filter"],
|
||||
transitionDuration: LINE_FADE_MS,
|
||||
}}
|
||||
>
|
||||
{line.words ? (
|
||||
<View
|
||||
style={[styles.words, { columnGap: textStyle.fontSize * 0.25 }]}
|
||||
>
|
||||
{line.words.map((word, wordIndex) =>
|
||||
active ? (
|
||||
<FilledWord
|
||||
key={wordIndex}
|
||||
word={word}
|
||||
clock={clock}
|
||||
colors={colors}
|
||||
textStyle={textStyle}
|
||||
/>
|
||||
) : (
|
||||
<Text key={wordIndex} style={wordStyle}>
|
||||
{word.text.trim()}
|
||||
</Text>
|
||||
)
|
||||
)}
|
||||
</View>
|
||||
) : (
|
||||
<Text style={wordStyle}>{line.text}</Text>
|
||||
)}
|
||||
</Animated.View>
|
||||
{active && line.words && time !== null ? (
|
||||
<FilledWords
|
||||
words={line.words}
|
||||
time={time}
|
||||
isPlaying={isPlaying}
|
||||
colors={colors}
|
||||
textStyle={textStyle}
|
||||
/>
|
||||
) : (
|
||||
<Text
|
||||
style={[
|
||||
styles.lineText,
|
||||
textStyle,
|
||||
{
|
||||
color:
|
||||
active && !line.words
|
||||
? colors.foreground
|
||||
: colors.lyricsInactive,
|
||||
},
|
||||
]}
|
||||
>
|
||||
{line.text}
|
||||
</Text>
|
||||
)}
|
||||
</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.
|
||||
* The playing line's words, each wiping from dim to bright as it is sung.
|
||||
* Reanimated runs the wipe; playback updates only re-anchor it.
|
||||
*/
|
||||
function FilledWords({
|
||||
words,
|
||||
time,
|
||||
isPlaying,
|
||||
colors,
|
||||
textStyle,
|
||||
}: {
|
||||
words: LyricWord[]
|
||||
time: number
|
||||
isPlaying: boolean
|
||||
colors: NowPlayingColors
|
||||
textStyle: { fontSize: number; lineHeight: number }
|
||||
}) {
|
||||
const sung = useSharedValue(time)
|
||||
const end = words.at(-1)?.end ?? time
|
||||
|
||||
useEffect(() => {
|
||||
cancelAnimation(sung)
|
||||
sung.value = time
|
||||
if (isPlaying && end > time) {
|
||||
sung.value = withTiming(end, {
|
||||
duration: (end - time) * 1000,
|
||||
easing: Easing.linear,
|
||||
})
|
||||
}
|
||||
}, [sung, time, isPlaying, end])
|
||||
|
||||
return (
|
||||
<View style={[styles.words, { columnGap: textStyle.fontSize * 0.25 }]}>
|
||||
{words.map((word, index) => (
|
||||
<FilledWord
|
||||
key={index}
|
||||
word={word}
|
||||
sung={sung}
|
||||
colors={colors}
|
||||
textStyle={textStyle}
|
||||
/>
|
||||
))}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
function FilledWord({
|
||||
word,
|
||||
clock,
|
||||
sung,
|
||||
colors,
|
||||
textStyle,
|
||||
}: {
|
||||
word: LyricWord
|
||||
clock: SharedValue<number>
|
||||
sung: SharedValue<number>
|
||||
colors: NowPlayingColors
|
||||
textStyle: { fontSize: number; lineHeight: number }
|
||||
}) {
|
||||
const [width, setWidth] = useState(0)
|
||||
const text = word.text.trim()
|
||||
const slide = useAnimatedStyle(() => {
|
||||
const wipe = 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)}%` }] }
|
||||
(sung.value - word.start) / Math.max(word.end - word.start, 0.05)
|
||||
return { width: width * Math.min(Math.max(progress, 0), 1) }
|
||||
})
|
||||
|
||||
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>
|
||||
<View>
|
||||
<Text
|
||||
style={[styles.lineText, textStyle, { color: colors.lyricsUnsung }]}
|
||||
onLayout={(event) => setWidth(event.nativeEvent.layout.width)}
|
||||
>
|
||||
{text}
|
||||
</Text>
|
||||
<Animated.View style={[styles.wipe, wipe]}>
|
||||
<Text
|
||||
numberOfLines={1}
|
||||
style={[
|
||||
styles.lineText,
|
||||
textStyle,
|
||||
{ color: colors.foreground, width },
|
||||
]}
|
||||
>
|
||||
{text}
|
||||
</Text>
|
||||
</Animated.View>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -337,14 +358,12 @@ const styles = StyleSheet.create({
|
||||
line: { paddingVertical: 9 },
|
||||
lineText: { fontWeight: "800" },
|
||||
words: { flexDirection: "row", flexWrap: "wrap" },
|
||||
mask: { color: "black" },
|
||||
hidden: { opacity: 0 },
|
||||
fillGradient: {
|
||||
wipe: {
|
||||
position: "absolute",
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
width: "250%",
|
||||
overflow: "hidden",
|
||||
},
|
||||
plainLine: { fontWeight: "700", paddingVertical: 2 },
|
||||
stanzaGap: { height: 18 },
|
||||
|
||||
@@ -4,6 +4,7 @@ import { tabletLayoutTransition } from "@/lib/tablet-motion"
|
||||
import { TabletMediaGrid } from "@/components/tablet-media-grid"
|
||||
import { useMediaGridLayout } from "@/hooks/use-media-grid-layout"
|
||||
import { MusicEntityView } from "@/components/music-entity-view"
|
||||
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||
import { Link } from "expo-router"
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
import { memo, useCallback, type ReactElement } from "react"
|
||||
@@ -300,17 +301,21 @@ export function MediaGridList({
|
||||
onEndReached,
|
||||
ListHeaderComponent,
|
||||
contentInset = true,
|
||||
title,
|
||||
}: {
|
||||
content: MediaItem[]
|
||||
paddingBottom: number
|
||||
onEndReached?: () => void
|
||||
ListHeaderComponent?: ReactElement
|
||||
contentInset?: boolean
|
||||
/** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */
|
||||
title?: string
|
||||
}) {
|
||||
const tabletLayout = useTabletLayout()
|
||||
const { columns, cardWidth, onLayout, horizontalPadding, gap } =
|
||||
useMediaGridLayout()
|
||||
const colors = useThemeColors()
|
||||
const { ref, scrollY } = useScreenTitleScroll<FlatList<MediaItem>>()
|
||||
const renderItem = useCallback(
|
||||
({ item }: ListRenderItemInfo<MediaItem>) => (
|
||||
<View style={{ width: cardWidth }}>
|
||||
@@ -328,13 +333,30 @@ export function MediaGridList({
|
||||
onEndReached={onEndReached}
|
||||
ListHeaderComponent={ListHeaderComponent}
|
||||
contentInset={contentInset}
|
||||
title={title}
|
||||
renderCard={renderTabletCard}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const header = title ? (
|
||||
<View>
|
||||
<ScreenTitle
|
||||
title={title}
|
||||
scrollY={scrollY}
|
||||
// Inset grids already pad the whole list horizontally.
|
||||
style={{ paddingHorizontal: contentInset ? 0 : horizontalPadding }}
|
||||
/>
|
||||
{ListHeaderComponent}
|
||||
</View>
|
||||
) : (
|
||||
ListHeaderComponent
|
||||
)
|
||||
|
||||
return (
|
||||
<FlatList
|
||||
<Animated.FlatList
|
||||
ref={ref}
|
||||
scrollEventThrottle={16}
|
||||
key={columns}
|
||||
onLayout={onLayout}
|
||||
data={content}
|
||||
@@ -351,6 +373,7 @@ export function MediaGridList({
|
||||
paddingBottom,
|
||||
gap,
|
||||
...(contentInset ? { paddingHorizontal: horizontalPadding } : {}),
|
||||
...(title ? { paddingTop: 0 } : {}),
|
||||
},
|
||||
]}
|
||||
columnWrapperStyle={[
|
||||
@@ -359,7 +382,7 @@ export function MediaGridList({
|
||||
{ gap },
|
||||
]}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
ListHeaderComponent={ListHeaderComponent}
|
||||
ListHeaderComponent={header}
|
||||
onEndReached={onEndReached}
|
||||
onEndReachedThreshold={0.5}
|
||||
/>
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import { useHeaderHeight } from "expo-router/react-navigation"
|
||||
import type { Component } from "react"
|
||||
import {
|
||||
Platform,
|
||||
StyleSheet,
|
||||
type ScrollViewInstance,
|
||||
type StyleProp,
|
||||
type TextStyle,
|
||||
} from "react-native"
|
||||
import Animated, {
|
||||
useAnimatedRef,
|
||||
useAnimatedStyle,
|
||||
useScrollOffset,
|
||||
type SharedValue,
|
||||
} from "react-native-reanimated"
|
||||
|
||||
import { spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
/**
|
||||
* Tracks the scroll view that renders a `ScreenTitle`. Attach `ref` to that
|
||||
* Reanimated `Animated.ScrollView` / `Animated.FlatList` and pass `scrollY`
|
||||
* to the title.
|
||||
*/
|
||||
export function useScreenTitleScroll<
|
||||
TScrollView extends Component | ScrollViewInstance,
|
||||
>() {
|
||||
const ref = useAnimatedRef<TScrollView>()
|
||||
const scrollY = useScrollOffset(ref)
|
||||
return { ref, scrollY }
|
||||
}
|
||||
|
||||
/**
|
||||
* iOS screen title rendered as the first item of a screen's scroll content,
|
||||
* in place of the native large title (Apple Music style): it scrolls away
|
||||
* with the content, never collapses into the bar, and stays put on
|
||||
* pull-down. Android keeps its native header title, so this renders nothing.
|
||||
*/
|
||||
export function ScreenTitle({
|
||||
title,
|
||||
scrollY,
|
||||
style,
|
||||
}: {
|
||||
title: string
|
||||
/** From `useScreenTitleScroll`; omit for screens that never scroll. */
|
||||
scrollY?: SharedValue<number>
|
||||
style?: StyleProp<TextStyle>
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
// At rest the scroll offset is minus the automatic header inset, so any
|
||||
// offset below that is overscroll the title should cancel out.
|
||||
const headerHeight = useHeaderHeight()
|
||||
const pinStyle = useAnimatedStyle(() => ({
|
||||
transform: [
|
||||
{
|
||||
translateY: scrollY ? Math.min(0, scrollY.value + headerHeight) : 0,
|
||||
},
|
||||
],
|
||||
}))
|
||||
|
||||
if (Platform.OS !== "ios") return null
|
||||
|
||||
return (
|
||||
<Animated.Text
|
||||
accessibilityRole="header"
|
||||
numberOfLines={2}
|
||||
style={[styles.title, { color: colors.foreground }, style, pinStyle]}
|
||||
>
|
||||
{title}
|
||||
</Animated.Text>
|
||||
)
|
||||
}
|
||||
|
||||
// Matches UIKit's large title metrics: 34pt bold in a 52pt tall area.
|
||||
const styles = StyleSheet.create({
|
||||
title: {
|
||||
fontSize: 34,
|
||||
lineHeight: 41,
|
||||
fontWeight: "700",
|
||||
letterSpacing: 0.37,
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingTop: 3,
|
||||
paddingBottom: 8,
|
||||
},
|
||||
})
|
||||
@@ -1,13 +1,15 @@
|
||||
import { memo, useCallback, useMemo } from "react"
|
||||
import {
|
||||
FlatList,
|
||||
type FlatList,
|
||||
StyleSheet,
|
||||
Text,
|
||||
View,
|
||||
type ListRenderItemInfo,
|
||||
} from "react-native"
|
||||
import Animated from "react-native-reanimated"
|
||||
|
||||
import { ContentCarousel } from "@/components/media-cards"
|
||||
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||
import type { MediaAction } from "@/components/media-context-menu"
|
||||
import { tabContentBottomInset, SongListRow } from "@/components/player"
|
||||
import { SongListSkeleton } from "@/components/skeletons"
|
||||
@@ -19,8 +21,16 @@ import { api } from "@otunes/convex/_generated/api"
|
||||
import type { BrowseSong, SearchSong } from "@otunes/convex/types"
|
||||
import { spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
|
||||
function SearchResultsBody({
|
||||
searchQuery,
|
||||
title,
|
||||
}: {
|
||||
searchQuery: string
|
||||
/** iOS `ScreenTitle`, shown above the results and while idle. */
|
||||
title: string
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
const { ref, scrollY } = useScreenTitleScroll<FlatList<BrowseSong>>()
|
||||
const { playFromSong } = usePlaybackActions()
|
||||
const { isSongFavorite } = useFavorites()
|
||||
const { handleSongAction } = useMediaMenuActions()
|
||||
@@ -76,16 +86,14 @@ function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
|
||||
)
|
||||
|
||||
if (isSearching) {
|
||||
return <SongListSkeleton />
|
||||
}
|
||||
|
||||
if (!hasQuery) {
|
||||
return <></>
|
||||
return <SongListSkeleton title={title} />
|
||||
}
|
||||
|
||||
return (
|
||||
<FlatList
|
||||
data={results?.songs ?? []}
|
||||
<Animated.FlatList
|
||||
ref={ref}
|
||||
scrollEventThrottle={16}
|
||||
data={hasQuery ? (results?.songs ?? []) : []}
|
||||
keyExtractor={(song) => song.id}
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={{ paddingBottom: tabContentBottomInset }}
|
||||
@@ -93,7 +101,8 @@ function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
|
||||
keyboardShouldPersistTaps="handled"
|
||||
ListHeaderComponent={
|
||||
<>
|
||||
{!hasResults ? (
|
||||
<ScreenTitle title={title} scrollY={scrollY} />
|
||||
{hasQuery && !hasResults ? (
|
||||
<View style={styles.empty}>
|
||||
<Text
|
||||
style={[styles.emptyText, { color: colors.mutedForeground }]}
|
||||
@@ -103,13 +112,13 @@ function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{results?.artists.length ? (
|
||||
{hasQuery && results?.artists.length ? (
|
||||
<View style={styles.section}>
|
||||
<ContentCarousel title="Artists" content={results.artists} />
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{results?.albums.length ? (
|
||||
{hasQuery && results?.albums.length ? (
|
||||
<View style={styles.section}>
|
||||
<ContentCarousel title="Albums" content={results.albums} />
|
||||
</View>
|
||||
@@ -118,7 +127,7 @@ function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
|
||||
}
|
||||
renderItem={renderItem}
|
||||
ListFooterComponent={
|
||||
playlistResults && playlistResults.length > 0 ? (
|
||||
hasQuery && playlistResults && playlistResults.length > 0 ? (
|
||||
<View style={styles.section}>
|
||||
<ContentCarousel title="Playlists" content={playlistResults} />
|
||||
</View>
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
collectionInset,
|
||||
} from "@/components/collection-list"
|
||||
import { tabletCardTextHeight } from "@/components/tablet-media-grid"
|
||||
import { ScreenTitle } from "@/components/screen-title"
|
||||
import { Link } from "expo-router"
|
||||
import { useHeaderHeight } from "expo-router/react-navigation"
|
||||
import Reanimated from "react-native-reanimated"
|
||||
@@ -151,9 +152,16 @@ function SongRows({ rows, inset }: { rows: number; inset?: boolean }) {
|
||||
))
|
||||
}
|
||||
|
||||
export function SongListSkeleton({ rows = 10 }: { rows?: number }) {
|
||||
export function SongListSkeleton({
|
||||
rows = 10,
|
||||
title,
|
||||
}: {
|
||||
rows?: number
|
||||
title?: string
|
||||
}) {
|
||||
return (
|
||||
<SkeletonScreen>
|
||||
{title ? <ScreenTitle title={title} /> : null}
|
||||
<SongRows rows={rows} />
|
||||
</SkeletonScreen>
|
||||
)
|
||||
@@ -234,23 +242,45 @@ export function MediaGridSkeleton({
|
||||
items = 6,
|
||||
contentInset = true,
|
||||
header,
|
||||
title,
|
||||
}: {
|
||||
items?: number
|
||||
contentInset?: boolean
|
||||
/** The loaded list's `ListHeaderComponent`, so it keeps its position. */
|
||||
header?: ReactNode
|
||||
/** The loaded list's `ScreenTitle`, which replaces its top inset. */
|
||||
title?: string
|
||||
}) {
|
||||
return (
|
||||
<SkeletonScreen>
|
||||
<MediaGridContent
|
||||
items={items}
|
||||
contentInset={contentInset}
|
||||
header={header}
|
||||
contentInset={contentInset && !title}
|
||||
header={
|
||||
title ? (
|
||||
<>
|
||||
<MediaGridTitle title={title} />
|
||||
{header}
|
||||
</>
|
||||
) : (
|
||||
header
|
||||
)
|
||||
}
|
||||
/>
|
||||
</SkeletonScreen>
|
||||
)
|
||||
}
|
||||
|
||||
function MediaGridTitle({ title }: { title: string }) {
|
||||
const { horizontalPadding } = useMediaGridLayout()
|
||||
return (
|
||||
<ScreenTitle
|
||||
title={title}
|
||||
style={{ paddingHorizontal: horizontalPadding }}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export function CarouselSkeleton() {
|
||||
return (
|
||||
<View style={styles.carousel}>
|
||||
@@ -264,10 +294,11 @@ export function CarouselSkeleton() {
|
||||
)
|
||||
}
|
||||
|
||||
export function HomeSkeleton() {
|
||||
export function HomeSkeleton({ title }: { title: string }) {
|
||||
return (
|
||||
<SkeletonScreen>
|
||||
<View style={styles.home}>
|
||||
<ScreenTitle title={title} style={styles.homeTitle} />
|
||||
<CarouselSkeleton />
|
||||
<CarouselSkeleton />
|
||||
</View>
|
||||
@@ -388,10 +419,17 @@ export function CollectionDetailSkeleton({
|
||||
)
|
||||
}
|
||||
|
||||
export function ArtistListSkeleton({ rows = 12 }: { rows?: number }) {
|
||||
export function ArtistListSkeleton({
|
||||
rows = 12,
|
||||
title,
|
||||
}: {
|
||||
rows?: number
|
||||
title?: string
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
return (
|
||||
<SkeletonScreen>
|
||||
{title ? <ScreenTitle title={title} /> : null}
|
||||
{Array.from({ length: rows }, (_, index) => (
|
||||
<View
|
||||
key={index}
|
||||
@@ -456,6 +494,12 @@ const styles = StyleSheet.create({
|
||||
carousel: { gap: spacing.md, overflow: "hidden" },
|
||||
carouselRow: { flexDirection: "row", gap: spacing.md },
|
||||
home: { padding: spacing.lg, gap: spacing.xl },
|
||||
// Mirrors the home screen's title spacing.
|
||||
homeTitle: {
|
||||
paddingHorizontal: 0,
|
||||
marginTop: -spacing.lg,
|
||||
marginBottom: -spacing.md,
|
||||
},
|
||||
centeredHero: { alignItems: "center", padding: spacing.lg, gap: spacing.sm },
|
||||
actions: {
|
||||
flexDirection: "row",
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
type ReactElement,
|
||||
} from "react"
|
||||
import {
|
||||
ScrollView,
|
||||
type ScrollViewInstance,
|
||||
View,
|
||||
type NativeSyntheticEvent,
|
||||
type NativeScrollEvent,
|
||||
@@ -15,6 +15,7 @@ import Animated from "react-native-reanimated"
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context"
|
||||
|
||||
import type { MediaItem } from "@/components/media-cards"
|
||||
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||
import { useMediaGridLayout } from "@/hooks/use-media-grid-layout"
|
||||
import { tabletLayoutTransition } from "@/lib/tablet-motion"
|
||||
import { useThemeColors } from "@/lib/theme"
|
||||
@@ -28,6 +29,8 @@ type GridProps = {
|
||||
onEndReached?: () => void
|
||||
ListHeaderComponent?: ReactElement
|
||||
contentInset?: boolean
|
||||
/** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */
|
||||
title?: string
|
||||
renderCard: (item: MediaItem, width: number) => ReactElement
|
||||
}
|
||||
|
||||
@@ -41,9 +44,12 @@ export function TabletMediaGrid({
|
||||
onEndReached,
|
||||
ListHeaderComponent,
|
||||
contentInset = true,
|
||||
title,
|
||||
renderCard,
|
||||
}: GridProps) {
|
||||
const colors = useThemeColors()
|
||||
const { ref, scrollY: titleScrollY } =
|
||||
useScreenTitleScroll<ScrollViewInstance>()
|
||||
const insets = useSafeAreaInsets()
|
||||
const { columns, cardWidth, onLayout, horizontalPadding, gap, ready } =
|
||||
useMediaGridLayout()
|
||||
@@ -102,18 +108,27 @@ export function TabletMediaGrid({
|
||||
setViewportHeight(event.nativeEvent.layout.height)
|
||||
}}
|
||||
>
|
||||
<ScrollView
|
||||
<Animated.ScrollView
|
||||
ref={ref}
|
||||
onScroll={onScroll}
|
||||
scrollEventThrottle={32}
|
||||
// Every frame, so the title pins smoothly on pull-down.
|
||||
scrollEventThrottle={16}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
contentContainerStyle={{
|
||||
paddingTop: contentInset ? horizontalPadding : 0,
|
||||
paddingTop: contentInset && !title ? horizontalPadding : 0,
|
||||
paddingBottom: paddingBottom + insets.bottom,
|
||||
}}
|
||||
>
|
||||
<View
|
||||
onLayout={(event) => setHeaderHeight(event.nativeEvent.layout.height)}
|
||||
>
|
||||
{title ? (
|
||||
<ScreenTitle
|
||||
title={title}
|
||||
scrollY={titleScrollY}
|
||||
style={{ paddingHorizontal: horizontalPadding }}
|
||||
/>
|
||||
) : null}
|
||||
{ListHeaderComponent}
|
||||
</View>
|
||||
<View style={{ height: gridHeight }}>
|
||||
@@ -136,7 +151,7 @@ export function TabletMediaGrid({
|
||||
)
|
||||
})}
|
||||
</View>
|
||||
</ScrollView>
|
||||
</Animated.ScrollView>
|
||||
</Animated.View>
|
||||
)
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import { AndroidSheet } from "@/components/android-sheet"
|
||||
import { AudioFormatBadge } from "@/components/audio-format-badge"
|
||||
import { useCacheScope } from "@/contexts/persistent-cache"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import { useBackgroundDownloads } from "@/hooks/use-background-downloads"
|
||||
import { useCachedQuery } from "@/hooks/use-cached-query"
|
||||
import { getAuthCookieHeader } from "@/lib/auth-cookies"
|
||||
import {
|
||||
@@ -34,7 +33,6 @@ 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"
|
||||
@@ -239,44 +237,36 @@ function DownloadQualityPopup({
|
||||
>
|
||||
{pending?.target.title}
|
||||
</Text>
|
||||
{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)}
|
||||
{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]}
|
||||
</Text>
|
||||
</View>
|
||||
<Text
|
||||
style={[styles.size, { color: colors.mutedForeground }]}
|
||||
>
|
||||
{option.estimated ? "~" : ""}
|
||||
{formatBytes(option.bytes)}
|
||||
)}
|
||||
<Text style={{ color: colors.mutedForeground, fontSize: 12 }}>
|
||||
{optionDetail(option, songCount)}
|
||||
</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</View>
|
||||
<Text style={[styles.size, { color: colors.mutedForeground }]}>
|
||||
{option.estimated ? "~" : ""}
|
||||
{formatBytes(option.bytes)}
|
||||
</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
<View style={styles.rememberRow}>
|
||||
<Text style={{ color: colors.foreground, fontSize: 15 }}>
|
||||
Remember my choice
|
||||
@@ -354,7 +344,6 @@ export function DownloadsProvider({ children }: { children: ReactNode }) {
|
||||
target: DownloadTarget
|
||||
response: DownloadOptionsResponse
|
||||
} | null>(null)
|
||||
const keepDownloading = useBackgroundDownloads(queue)
|
||||
|
||||
useEffect(() => {
|
||||
if (!queue) return
|
||||
@@ -402,7 +391,6 @@ export function DownloadsProvider({ children }: { children: ReactNode }) {
|
||||
const remembered = await readRememberedDownloadQuality()
|
||||
if (remembered) {
|
||||
await startDownload(queue, target, response.songs, remembered)
|
||||
keepDownloading()
|
||||
toast(`Downloading ${target.title}`)
|
||||
} else {
|
||||
setPending({ target, response })
|
||||
@@ -411,7 +399,7 @@ export function DownloadsProvider({ children }: { children: ReactNode }) {
|
||||
showError(error instanceof Error ? error.message : "Download failed")
|
||||
}
|
||||
},
|
||||
[cacheScope, config, convex, keepDownloading, queue]
|
||||
[cacheScope, config, convex, queue]
|
||||
)
|
||||
|
||||
const removeDownload = useCallback(
|
||||
@@ -429,14 +417,9 @@ export function DownloadsProvider({ children }: { children: ReactNode }) {
|
||||
if (!pending || !queue) return
|
||||
setPending(null)
|
||||
if (remember) void writeRememberedDownloadQuality(quality)
|
||||
void startDownload(
|
||||
queue,
|
||||
pending.target,
|
||||
pending.response.songs,
|
||||
quality
|
||||
).then(keepDownloading)
|
||||
void startDownload(queue, pending.target, pending.response.songs, quality)
|
||||
},
|
||||
[keepDownloading, pending, queue]
|
||||
[pending, queue]
|
||||
)
|
||||
|
||||
const value = useMemo(
|
||||
|
||||
@@ -9,13 +9,15 @@
|
||||
"APP_VARIANT": "development"
|
||||
},
|
||||
"developmentClient": true,
|
||||
"distribution": "internal"
|
||||
"distribution": "internal",
|
||||
"credentialsSource": "local"
|
||||
},
|
||||
"preview": {
|
||||
"env": {
|
||||
"APP_VARIANT": "preview"
|
||||
},
|
||||
"distribution": "internal"
|
||||
"distribution": "internal",
|
||||
"credentialsSource": "local"
|
||||
},
|
||||
"production": {
|
||||
"env": {
|
||||
|
||||
@@ -1,164 +0,0 @@
|
||||
import { requireOptionalNativeModule } from "expo"
|
||||
import Constants from "expo-constants"
|
||||
import { useCallback, useEffect, useRef } from "react"
|
||||
import { AppState, Platform } from "react-native"
|
||||
import {
|
||||
ContinuedTasks,
|
||||
type ContinuedTask,
|
||||
} from "react-native-continued-task"
|
||||
|
||||
import { setKeptRunning } from "@/lib/downloads"
|
||||
import type { DownloadQueue } from "@otunes/convex/client/download-queue"
|
||||
|
||||
const downloadService = requireOptionalNativeModule<{
|
||||
update: (remaining: number) => void
|
||||
}>("DownloadService")
|
||||
|
||||
/** Songs downloading at once while the app runs, as the queue defaults to. */
|
||||
const RUNNING_CONCURRENCY = 2
|
||||
|
||||
// Stopping right after starting can beat the service to `startForeground`,
|
||||
// which Android treats as a crash.
|
||||
const STOP_DELAY_MS = 2000
|
||||
|
||||
// Must match `identifierPrefixes` in app.config.ts.
|
||||
const TASK_PREFIX = `${Constants.expoConfig?.ios?.bundleIdentifier}.downloads`
|
||||
|
||||
function songsLeft(count: number) {
|
||||
return count === 1 ? "1 song left" : `${count} songs left`
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps downloads going while the app is in the background. Call the returned
|
||||
* function right after the person starts a download.
|
||||
*
|
||||
* iOS 26+: a continued processing task keeps the app running, with progress
|
||||
* in a Live Activity, so songs keep downloading a few at a time with fresh
|
||||
* sign-in tokens. It must start from the person's action, so it covers
|
||||
* downloads they start, not playlist syncs.
|
||||
*
|
||||
* iOS otherwise (and once that task ends): songs download in a background URL
|
||||
* session. Songs started while suspended may wait for Wi-Fi and power, so
|
||||
* every waiting song is handed over as the app leaves the screen.
|
||||
*
|
||||
* Android: a foreground service keeps the app running while songs are queued.
|
||||
*/
|
||||
export function useBackgroundDownloads(queue: DownloadQueue | null) {
|
||||
const startTask = useRef<() => void>(() => {})
|
||||
|
||||
useEffect(() => {
|
||||
if (!queue) return
|
||||
|
||||
if (Platform.OS === "ios") {
|
||||
let active = AppState.currentState === "active"
|
||||
let task: ContinuedTask | null = null
|
||||
let submitting = false
|
||||
let total = 0
|
||||
let lastPending = 0
|
||||
|
||||
const updateConcurrency = () =>
|
||||
queue.setConcurrency(
|
||||
active || task?.state === "running" ? RUNNING_CONCURRENCY : Infinity
|
||||
)
|
||||
|
||||
const end = () => {
|
||||
task = null
|
||||
setKeptRunning(false)
|
||||
updateConcurrency()
|
||||
}
|
||||
|
||||
const report = () => {
|
||||
const pending = queue.pendingCount()
|
||||
if (pending > lastPending) total += pending - lastPending
|
||||
lastPending = pending
|
||||
if (task?.state !== "running") return
|
||||
if (pending === 0) {
|
||||
task.complete(true)
|
||||
end()
|
||||
return
|
||||
}
|
||||
task.setProgress(total - pending, total)
|
||||
task.updateTitle("Downloading", songsLeft(pending))
|
||||
}
|
||||
|
||||
startTask.current = () => {
|
||||
if (!ContinuedTasks.isSupported || task || submitting) return
|
||||
const pending = queue.pendingCount()
|
||||
if (pending === 0) return
|
||||
submitting = true
|
||||
total = pending
|
||||
lastPending = pending
|
||||
ContinuedTasks.submit({
|
||||
identifierPrefix: TASK_PREFIX,
|
||||
title: "Downloading",
|
||||
subtitle: songsLeft(pending),
|
||||
totalUnitCount: total,
|
||||
// A task that cannot start now is no use once the app is closed.
|
||||
ios: { submissionStrategy: "fail" },
|
||||
})
|
||||
.then((submitted) => {
|
||||
task = submitted
|
||||
submitted.addOnStartListener(() => {
|
||||
setKeptRunning(true)
|
||||
updateConcurrency()
|
||||
report()
|
||||
})
|
||||
// iOS reports a cancel from the Live Activity as expiry too, so
|
||||
// either way the songs carry on in the background session.
|
||||
submitted.addOnStopListener(() => {
|
||||
if (task === submitted) end()
|
||||
})
|
||||
})
|
||||
.catch(() => {
|
||||
// Not permitted or unavailable: the background session covers it.
|
||||
})
|
||||
.finally(() => {
|
||||
submitting = false
|
||||
})
|
||||
}
|
||||
|
||||
updateConcurrency()
|
||||
const unsubscribe = queue.subscribe(report)
|
||||
const subscription = AppState.addEventListener("change", (state) => {
|
||||
active = state === "active"
|
||||
updateConcurrency()
|
||||
})
|
||||
return () => {
|
||||
startTask.current = () => {}
|
||||
unsubscribe()
|
||||
subscription.remove()
|
||||
task?.cancel()
|
||||
end()
|
||||
}
|
||||
}
|
||||
|
||||
if (!downloadService) return
|
||||
const service = downloadService
|
||||
let shown = 0
|
||||
let stopTimer: ReturnType<typeof setTimeout> | null = null
|
||||
const update = () => {
|
||||
const remaining = queue.pendingCount()
|
||||
if (remaining === shown) return
|
||||
if (stopTimer) clearTimeout(stopTimer)
|
||||
stopTimer = null
|
||||
if (remaining > 0) {
|
||||
shown = remaining
|
||||
service.update(remaining)
|
||||
} else {
|
||||
stopTimer = setTimeout(() => {
|
||||
shown = 0
|
||||
service.update(0)
|
||||
}, STOP_DELAY_MS)
|
||||
}
|
||||
}
|
||||
update()
|
||||
const unsubscribe = queue.subscribe(update)
|
||||
return () => {
|
||||
unsubscribe()
|
||||
if (stopTimer) clearTimeout(stopTimer)
|
||||
service.update(0)
|
||||
}
|
||||
}, [queue])
|
||||
|
||||
return useCallback(() => startTask.current(), [])
|
||||
}
|
||||
@@ -1,18 +1,5 @@
|
||||
import { File } from "expo-file-system"
|
||||
import {
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
useSyncExternalStore,
|
||||
} from "react"
|
||||
import {
|
||||
cancelAnimation,
|
||||
Easing,
|
||||
useSharedValue,
|
||||
withSequence,
|
||||
withTiming,
|
||||
} from "react-native-reanimated"
|
||||
import { useEffect, useMemo, useState, useSyncExternalStore } from "react"
|
||||
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
@@ -120,39 +107,3 @@ export function useLyricsTime(
|
||||
? advanced.time
|
||||
: 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 { createContext, use, useCallback } from "react"
|
||||
import { useCallback } from "react"
|
||||
|
||||
import { tabletSections } from "@/lib/tablet-navigation"
|
||||
|
||||
@@ -30,13 +30,6 @@ export function tabPath(tab: AppTab, path: string): Href {
|
||||
return `/(app)/(tabs)/${tab}${normalized}` as Href
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
return getActiveTab(activeSegmentsRef.current)
|
||||
}
|
||||
@@ -48,15 +41,8 @@ export function AppNavigationSync() {
|
||||
return null
|
||||
}
|
||||
|
||||
/** Tab-aware navigation: paths resolve inside the caller's tab stack, falling back to the active tab outside one. */
|
||||
export function useAppNavigation() {
|
||||
const router = useRouter()
|
||||
const stackTab = use(TabStackContext)
|
||||
|
||||
const currentTab = useCallback(
|
||||
() => stackTab ?? getActiveTabFromRef(),
|
||||
[stackTab]
|
||||
)
|
||||
|
||||
const push = useCallback(
|
||||
(path: string) => {
|
||||
@@ -67,26 +53,26 @@ export function useAppNavigation() {
|
||||
return
|
||||
}
|
||||
|
||||
router.push(tabPath(currentTab(), path))
|
||||
router.push(tabPath(getActiveTabFromRef(), path))
|
||||
},
|
||||
[router, currentTab]
|
||||
[router]
|
||||
)
|
||||
|
||||
const replace = useCallback(
|
||||
(path: string) => {
|
||||
router.replace(tabPath(currentTab(), path))
|
||||
router.replace(tabPath(getActiveTabFromRef(), path))
|
||||
},
|
||||
[router, currentTab]
|
||||
[router]
|
||||
)
|
||||
|
||||
const href = useCallback(
|
||||
(path: string) => tabPath(currentTab(), path),
|
||||
[currentTab]
|
||||
(path: string) => tabPath(getActiveTabFromRef(), path),
|
||||
[]
|
||||
)
|
||||
|
||||
return {
|
||||
get tab() {
|
||||
return currentTab()
|
||||
return getActiveTabFromRef()
|
||||
},
|
||||
href,
|
||||
push,
|
||||
|
||||
@@ -16,16 +16,9 @@ function authCookieNames(serverUrl: string) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cookies that sign a request to the server in. Pass `refresh: false` for
|
||||
* requests that may run after the JWT expires (iOS background downloads): the
|
||||
* server would spend the refresh token, and the app's next refresh of the same
|
||||
* token would then end the session.
|
||||
*/
|
||||
export async function getAuthCookieHeader(
|
||||
serverUrl: string,
|
||||
convexUrl: string,
|
||||
{ refresh = true }: { refresh?: boolean } = {}
|
||||
convexUrl: string
|
||||
): Promise<string | null> {
|
||||
const [jwt, refreshToken] = await Promise.all([
|
||||
secureGetItem(authStorageKey(JWT_STORAGE_KEY, convexUrl)),
|
||||
@@ -38,7 +31,7 @@ export async function getAuthCookieHeader(
|
||||
|
||||
const names = authCookieNames(serverUrl)
|
||||
const parts = [`${names.jwt}=${jwt}`]
|
||||
if (refresh && refreshToken) {
|
||||
if (refreshToken) {
|
||||
parts.push(`${names.refresh}=${refreshToken}`)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,28 +12,19 @@ const secureStoreOptions: SecureStore.SecureStoreOptions = {
|
||||
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> {
|
||||
try {
|
||||
const value = await SecureStore.getItemAsync(key, secureStoreOptions)
|
||||
if (value === null) remembered.delete(key)
|
||||
else remembered.set(key, value)
|
||||
return value
|
||||
return await SecureStore.getItemAsync(key, secureStoreOptions)
|
||||
} catch {
|
||||
return remembered.get(key) ?? null
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export async function secureSetItem(key: string, value: string): Promise<void> {
|
||||
remembered.set(key, value)
|
||||
await SecureStore.setItemAsync(key, value, secureStoreOptions)
|
||||
}
|
||||
|
||||
export async function secureRemoveItem(key: string): Promise<void> {
|
||||
remembered.delete(key)
|
||||
try {
|
||||
await SecureStore.deleteItemAsync(key, secureStoreOptions)
|
||||
} catch {
|
||||
|
||||
+12
-100
@@ -1,5 +1,5 @@
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage"
|
||||
import { Directory, DownloadTask, File, Paths } from "expo-file-system"
|
||||
import { Directory, File, Paths } from "expo-file-system"
|
||||
import { Platform } from "react-native"
|
||||
|
||||
import {
|
||||
@@ -16,7 +16,6 @@ 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"
|
||||
@@ -74,82 +73,6 @@ function audioFile(folder: Directory) {
|
||||
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 {
|
||||
const root = serverDirectory(config)
|
||||
const indexFile = new File(root, "index.json")
|
||||
@@ -193,8 +116,7 @@ function createStorage(config: ServerConfig): DownloadStorage {
|
||||
async save({ songId, requested, quality, albumId }, signal) {
|
||||
const cookieHeader = await getAuthCookieHeader(
|
||||
config.serverUrl,
|
||||
config.convexUrl,
|
||||
{ refresh: Platform.OS !== "ios" }
|
||||
config.convexUrl
|
||||
)
|
||||
if (!cookieHeader) throw new Error("Sign in to download")
|
||||
|
||||
@@ -204,26 +126,17 @@ function createStorage(config: ServerConfig): DownloadStorage {
|
||||
if (partial.exists) partial.delete()
|
||||
partial.create()
|
||||
try {
|
||||
const url = `${config.serverUrl}${songDownloadPath(songId, requested, {
|
||||
const path = songDownloadPath(songId, requested, {
|
||||
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) {
|
||||
if (partial.exists) partial.delete()
|
||||
throw error
|
||||
@@ -299,10 +212,9 @@ export function downloadedCoverUri(url: string) {
|
||||
|
||||
export async function readRememberedDownloadQuality() {
|
||||
try {
|
||||
const quality = parseDownloadQuality(
|
||||
return parseDownloadQuality(
|
||||
await AsyncStorage.getItem(REMEMBERED_QUALITY_KEY)
|
||||
)
|
||||
return quality && downloadQualitySupported(quality) ? quality : undefined
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
|
||||
@@ -17,13 +17,20 @@ export const tabStackScreenTitles: Record<string, string> = {
|
||||
"downloads/other": "Other Downloaded Songs",
|
||||
}
|
||||
|
||||
/**
|
||||
* iOS tab stacks render their titles in the scroll content with
|
||||
* `ScreenTitle`, so the bar keeps the title (for back menus) but hides it.
|
||||
*/
|
||||
export const inlineTitleOptions: StackScreenOptions =
|
||||
Platform.OS === "ios" ? { headerTitleStyle: { color: "transparent" } } : {}
|
||||
|
||||
export function useStackScreenOptions(
|
||||
overrides?: StackScreenOptions
|
||||
): StackScreenOptions {
|
||||
const theme = useThemeColors()
|
||||
|
||||
return {
|
||||
headerLargeTitle: true,
|
||||
headerLargeTitle: false,
|
||||
headerTransparent: true,
|
||||
headerTintColor: theme.foreground,
|
||||
headerLargeTitleStyle: { color: theme.foreground },
|
||||
|
||||
@@ -12,6 +12,8 @@ export type NowPlayingColors = {
|
||||
selected: string
|
||||
selectedForeground: string
|
||||
highlight: string
|
||||
/** Lyrics lines other than the one playing. */
|
||||
lyricsInactive: string
|
||||
/** Words of the playing line not yet sung. */
|
||||
lyricsUnsung: string
|
||||
isDark: boolean
|
||||
@@ -30,6 +32,7 @@ export function nowPlayingColors(palette: CoverPalette): NowPlayingColors {
|
||||
selected: withAlpha(foreground, 0.8),
|
||||
selectedForeground: palette.background,
|
||||
highlight: withAlpha(foreground, 0.1),
|
||||
lyricsInactive: withAlpha(foreground, 0.35),
|
||||
lyricsUnsung: withAlpha(foreground, 0.55),
|
||||
isDark: palette.isDark,
|
||||
}
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
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"
|
||||
|
||||
@@ -12,13 +7,3 @@ 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
|
||||
)
|
||||
@@ -1,44 +1,13 @@
|
||||
import { buildConvexUrl, isLocalHost } from "@otunes/convex/server-url"
|
||||
import type { ServerConfig } from "@otunes/convex/server-url"
|
||||
|
||||
export type ServerConfig = {
|
||||
/** Raw hostname the user entered, e.g. `music.example.com` or `192.168.86.25:3000` */
|
||||
hostname: string
|
||||
/** Base URL for the Next.js server, e.g. `https://music.example.com` */
|
||||
serverUrl: string
|
||||
/** Convex deployment URL, e.g. `https://convex.music.example.com` */
|
||||
convexUrl: string
|
||||
}
|
||||
export {
|
||||
parseServerHostname,
|
||||
type ServerConfig,
|
||||
} from "@otunes/convex/server-url"
|
||||
|
||||
const SERVER_CONFIG_KEY = "otunes.server-config"
|
||||
const LEGACY_SERVER_CONFIG_KEY = "otunes:server-config"
|
||||
|
||||
function normalizeHostnameInput(input: string): string {
|
||||
return input
|
||||
.trim()
|
||||
.replace(/^https?:\/\//i, "")
|
||||
.replace(/\/+$/, "")
|
||||
}
|
||||
|
||||
function buildServerUrl(hostname: string): string {
|
||||
const protocol = isLocalHost(hostname) ? "http" : "https"
|
||||
return `${protocol}://${hostname}`
|
||||
}
|
||||
|
||||
export function parseServerHostname(input: string): ServerConfig | null {
|
||||
const hostname = normalizeHostnameInput(input)
|
||||
if (!hostname) return null
|
||||
|
||||
try {
|
||||
const serverUrl = buildServerUrl(hostname)
|
||||
const convexUrl = buildConvexUrl(hostname)
|
||||
new URL(serverUrl)
|
||||
new URL(convexUrl)
|
||||
return { hostname, serverUrl, convexUrl }
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export async function loadServerConfig(
|
||||
getItem: (key: string) => Promise<string | null>
|
||||
): Promise<ServerConfig | null> {
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
plugins {
|
||||
id 'com.android.library'
|
||||
id 'expo-module-gradle-plugin'
|
||||
}
|
||||
|
||||
group = 'expo.modules.downloadservice'
|
||||
version = '1.0.0'
|
||||
|
||||
android {
|
||||
namespace 'expo.modules.downloadservice'
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
|
||||
|
||||
<application>
|
||||
<service
|
||||
android:name="expo.modules.downloadservice.DownloadService"
|
||||
android:exported="false"
|
||||
android:foregroundServiceType="dataSync" />
|
||||
</application>
|
||||
</manifest>
|
||||
-88
@@ -1,88 +0,0 @@
|
||||
package expo.modules.downloadservice
|
||||
|
||||
import android.app.Notification
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.app.Service
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.ServiceInfo
|
||||
import android.os.Build
|
||||
import android.os.IBinder
|
||||
|
||||
/**
|
||||
* Keeps the app running while songs download, so Android does not freeze the
|
||||
* JS downloads when the app leaves the screen. Started with the number of
|
||||
* songs left, and stopped by the module once none are.
|
||||
*/
|
||||
class DownloadService : Service() {
|
||||
override fun onBind(intent: Intent?): IBinder? = null
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
val remaining = intent?.getIntExtra(EXTRA_REMAINING, 0) ?: 0
|
||||
val notification = notification(remaining)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
startForeground(NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
|
||||
} else {
|
||||
startForeground(NOTIFICATION_ID, notification)
|
||||
}
|
||||
// A restarted service would have no downloads to keep alive.
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
|
||||
// Android 15 limits data sync services to six hours a day.
|
||||
override fun onTimeout(startId: Int, fgsType: Int) {
|
||||
stopSelf()
|
||||
}
|
||||
|
||||
private fun notification(remaining: Int): Notification {
|
||||
val manager = getSystemService(NotificationManager::class.java)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
manager.createNotificationChannel(
|
||||
NotificationChannel(CHANNEL_ID, "Downloads", NotificationManager.IMPORTANCE_LOW)
|
||||
)
|
||||
}
|
||||
val builder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
Notification.Builder(this, CHANNEL_ID)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
Notification.Builder(this)
|
||||
}
|
||||
val launch = packageManager.getLaunchIntentForPackage(packageName)?.let {
|
||||
PendingIntent.getActivity(this, 0, it, PendingIntent.FLAG_IMMUTABLE)
|
||||
}
|
||||
return builder
|
||||
.setSmallIcon(android.R.drawable.stat_sys_download)
|
||||
.setContentTitle(if (remaining == 1) "Downloading 1 song" else "Downloading $remaining songs")
|
||||
.setContentIntent(launch)
|
||||
.setOngoing(true)
|
||||
.setOnlyAlertOnce(true)
|
||||
.build()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val CHANNEL_ID = "downloads"
|
||||
private const val NOTIFICATION_ID = 7301
|
||||
private const val EXTRA_REMAINING = "remaining"
|
||||
|
||||
fun update(context: Context, remaining: Int) {
|
||||
val intent = Intent(context, DownloadService::class.java)
|
||||
if (remaining == 0) {
|
||||
context.stopService(intent)
|
||||
return
|
||||
}
|
||||
intent.putExtra(EXTRA_REMAINING, remaining)
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
context.startForegroundService(intent)
|
||||
} else {
|
||||
context.startService(intent)
|
||||
}
|
||||
} catch (_: IllegalStateException) {
|
||||
// Android 12+ refuses to start one from the background (say, a
|
||||
// playlist syncing); downloads then run only while the app does.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
package expo.modules.downloadservice
|
||||
|
||||
import expo.modules.kotlin.modules.Module
|
||||
import expo.modules.kotlin.modules.ModuleDefinition
|
||||
|
||||
class DownloadServiceModule : Module() {
|
||||
override fun definition() = ModuleDefinition {
|
||||
Name("DownloadService")
|
||||
|
||||
/** Shows how many songs are left, or stops the service at zero. */
|
||||
Function("update") { remaining: Int ->
|
||||
DownloadService.update(requireNotNull(appContext.reactContext), remaining)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"platforms": ["android"],
|
||||
"android": {
|
||||
"modules": ["expo.modules.downloadservice.DownloadServiceModule"]
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"name": "otunes-download-service",
|
||||
"version": "1.0.0",
|
||||
"private": true
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"platforms": ["apple"]
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
// React Native draws `filter: [{ blur }]` on iOS only with its SwiftUI
|
||||
// filters flag, which the stable release leaves off. This keeps the stable
|
||||
// flags and turns that one on.
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <react/featureflags/ReactNativeFeatureFlags.h>
|
||||
#import <react/featureflags/ReactNativeFeatureFlagsOverridesOSSStable.h>
|
||||
|
||||
using namespace facebook::react;
|
||||
|
||||
class SwiftUIFilterFlags : public ReactNativeFeatureFlagsOverridesOSSStable {
|
||||
public:
|
||||
bool enableSwiftUIBasedFilters() override {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@interface SwiftUIFilters : NSObject
|
||||
@end
|
||||
|
||||
@implementation SwiftUIFilters
|
||||
|
||||
+ (void)load
|
||||
{
|
||||
// React Native sets its flags once while launching and throws if they were
|
||||
// set first, so this waits for launch to finish. No views exist yet then.
|
||||
[NSNotificationCenter.defaultCenter
|
||||
addObserverForName:UIApplicationDidFinishLaunchingNotification
|
||||
object:nil
|
||||
queue:nil
|
||||
usingBlock:^(NSNotification *notification) {
|
||||
ReactNativeFeatureFlags::dangerouslyForceOverride(
|
||||
std::make_unique<SwiftUIFilterFlags>());
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,14 +0,0 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'SwiftUIFilters'
|
||||
s.version = '1.0.0'
|
||||
s.summary = 'Turns on React Native view filters like blur on iOS'
|
||||
s.description = s.summary
|
||||
s.license = { :type => 'MIT' }
|
||||
s.author = 'oTunes'
|
||||
s.homepage = 'https://otunes.abunchofknowitalls.com'
|
||||
s.platforms = { :ios => '16.4' }
|
||||
s.source = { :git => '' }
|
||||
s.static_framework = true
|
||||
install_modules_dependencies(s)
|
||||
s.source_files = '**/*.{h,mm}'
|
||||
end
|
||||
@@ -20,7 +20,6 @@
|
||||
"@otunes/convex": "workspace:*",
|
||||
"@react-native-async-storage/async-storage": "2.2.0",
|
||||
"@react-native-community/slider": "5.2.1",
|
||||
"@react-native-masked-view/masked-view": "0.3.2",
|
||||
"@react-native/metro-config": "0.88.0",
|
||||
"convex": "^1.40.0",
|
||||
"expo": "~58.0.17",
|
||||
@@ -49,10 +48,8 @@
|
||||
"react": "19.3.0",
|
||||
"react-dom": "19.3.0",
|
||||
"react-native": "0.88.0",
|
||||
"react-native-continued-task": "0.1.0",
|
||||
"react-native-gesture-handler": "~3.3.0",
|
||||
"react-native-image-colors": "^2.6.0",
|
||||
"react-native-nitro-modules": "0.37.2",
|
||||
"react-native-reanimated": "4.7.1",
|
||||
"react-native-safe-area-context": "~5.10.1",
|
||||
"react-native-screens": "4.30.0",
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ export default function Page() {
|
||||
</p>
|
||||
<div className="mt-6 flex flex-wrap justify-center gap-2">
|
||||
<Button asChild>
|
||||
<Link href="/public">
|
||||
<Link href="/">
|
||||
<Home />
|
||||
Home
|
||||
</Link>
|
||||
@@ -1,3 +1,5 @@
|
||||
// Share links (/album/<id>) land here on the server build, which adds
|
||||
// link-preview metadata. The app itself links to /album?id=<id>.
|
||||
import { AlbumPage } from "@/components/album-page"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import { fetchQuery } from "convex/nextjs"
|
||||
File renamed without changes.
@@ -0,0 +1,19 @@
|
||||
"use client"
|
||||
|
||||
import { useSearchParams } from "next/navigation"
|
||||
|
||||
import { AlbumPage } from "@/components/album-page"
|
||||
import { PageMessage } from "@/components/page-message"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
|
||||
export default function Page() {
|
||||
const searchParams = useSearchParams()
|
||||
const id = searchParams.get("id")
|
||||
if (!id) return <PageMessage>Album not found.</PageMessage>
|
||||
return (
|
||||
<AlbumPage
|
||||
albumId={id as Id<"albums">}
|
||||
highlightedSongId={searchParams.get("s") ?? undefined}
|
||||
/>
|
||||
)
|
||||
}
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// Share links (/artist/<id>) land here on the server build, which adds
|
||||
// link-preview metadata. The app itself links to /artist?id=<id>.
|
||||
import { fetchQuery } from "convex/nextjs"
|
||||
import { convexServerOptions } from "@/lib/convex-server"
|
||||
import { ArtistPage } from "@/components/artist-page"
|
||||
File renamed without changes.
@@ -0,0 +1,13 @@
|
||||
"use client"
|
||||
|
||||
import { useSearchParams } from "next/navigation"
|
||||
|
||||
import { ArtistPage } from "@/components/artist-page"
|
||||
import { PageMessage } from "@/components/page-message"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
|
||||
export default function Page() {
|
||||
const id = useSearchParams().get("id")
|
||||
if (!id) return <PageMessage>Artist not found.</PageMessage>
|
||||
return <ArtistPage artistId={id as Id<"artists">} />
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { AuthRedirect } from "@/components/auth-redirect"
|
||||
import { AddToPlaylistProvider } from "@/components/add-to-playlist-provider"
|
||||
import { DownloadsProvider } from "@/components/downloads-provider"
|
||||
import { FavoritesProvider } from "@/components/favorites-provider"
|
||||
@@ -21,6 +22,9 @@ export default function AppLayout({
|
||||
<AddToPlaylistProvider>
|
||||
<DownloadsProvider>
|
||||
<FavoritesProvider>
|
||||
{process.env.OTUNES_STATIC_EXPORT === "1" && (
|
||||
<AuthRedirect area="app" />
|
||||
)}
|
||||
<AppSidebar />
|
||||
<div className="flex min-h-svh min-w-0 flex-1">
|
||||
<SidebarInset className="min-w-0 flex-1">
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
import { fetchQuery } from "convex/nextjs"
|
||||
import { convexServerOptions } from "@/lib/convex-server"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import { Metadata } from "next"
|
||||
|
||||
interface PageProps {
|
||||
params: Promise<{ id: string }>
|
||||
}
|
||||
|
||||
export async function generateMetadata({
|
||||
params,
|
||||
}: PageProps): Promise<Metadata> {
|
||||
const { id } = await params
|
||||
const detail = await fetchQuery(
|
||||
api.library.browseArtistDetail,
|
||||
{ id: id as Id<"artists"> },
|
||||
convexServerOptions()
|
||||
).catch(() => null)
|
||||
const selectedArtist = detail?.artist
|
||||
|
||||
return {
|
||||
title: `${selectedArtist ? `${selectedArtist.name}` : "oTunes"}`,
|
||||
openGraph: {
|
||||
title: `${selectedArtist ? `${selectedArtist.name}` : "oTunes"}`,
|
||||
description: "oTunes",
|
||||
images: selectedArtist
|
||||
? {
|
||||
url: `/api/artist/${selectedArtist.id}/cover`,
|
||||
width: 512,
|
||||
height: 512,
|
||||
}
|
||||
: [],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export default function Page() {
|
||||
return null
|
||||
}
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// Share links (/playlist/<id>) land here on the server build, which adds
|
||||
// link-preview metadata. The app itself links to /playlist?id=<id>.
|
||||
import { PlaylistPage } from "@/components/playlist-page"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import { convexAuthNextjsToken } from "@convex-dev/auth/nextjs/server"
|
||||
File renamed without changes.
@@ -0,0 +1,13 @@
|
||||
"use client"
|
||||
|
||||
import { useSearchParams } from "next/navigation"
|
||||
|
||||
import { PageMessage } from "@/components/page-message"
|
||||
import { PlaylistPage } from "@/components/playlist-page"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
|
||||
export default function Page() {
|
||||
const id = useSearchParams().get("id")
|
||||
if (!id) return <PageMessage>Playlist not found.</PageMessage>
|
||||
return <PlaylistPage playlistId={id as Id<"playlists">} />
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { AuthRedirect } from "@/components/auth-redirect"
|
||||
export default function AuthLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
@@ -5,6 +6,7 @@ export default function AuthLayout({
|
||||
}>) {
|
||||
return (
|
||||
<div className="flex min-h-svh flex-col items-center justify-center bg-muted/30 p-6">
|
||||
{process.env.OTUNES_STATIC_EXPORT === "1" && <AuthRedirect area="auth" />}
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -1,18 +1,5 @@
|
||||
import { fetchQuery } from "convex/nextjs"
|
||||
import { connection } from "next/server"
|
||||
import { AuthForm } from "@/components/auth-form"
|
||||
import { convexServerOptions } from "@/lib/convex-server"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
|
||||
export default async function SignInPage() {
|
||||
await connection()
|
||||
const { disableAccountCreation } = await fetchQuery(
|
||||
api.users.getAppSettings,
|
||||
{},
|
||||
convexServerOptions()
|
||||
)
|
||||
|
||||
return (
|
||||
<AuthForm flow="signIn" accountCreationDisabled={disableAccountCreation} />
|
||||
)
|
||||
export default function SignInPage() {
|
||||
return <AuthForm flow="signIn" />
|
||||
}
|
||||
@@ -1,18 +1,30 @@
|
||||
import { fetchQuery } from "convex/nextjs"
|
||||
import { connection } from "next/server"
|
||||
"use client"
|
||||
|
||||
import { useQuery } from "convex/react"
|
||||
import Link from "next/link"
|
||||
|
||||
import { AuthForm } from "@/components/auth-form"
|
||||
import { convexServerOptions } from "@/lib/convex-server"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
|
||||
export default async function SignUpPage() {
|
||||
await connection()
|
||||
const { disableAccountCreation } = await fetchQuery(
|
||||
api.users.getAppSettings,
|
||||
{},
|
||||
convexServerOptions()
|
||||
)
|
||||
|
||||
export default function SignUpPage() {
|
||||
const settings = useQuery(api.users.getAppSettings)
|
||||
// Render nothing until the setting loads so the form never flashes.
|
||||
if (settings === undefined) return null
|
||||
if (!settings.disableAccountCreation) return <AuthForm flow="signUp" />
|
||||
return (
|
||||
<AuthForm flow="signUp" accountCreationDisabled={disableAccountCreation} />
|
||||
<Card className="w-full max-w-sm">
|
||||
<CardHeader>
|
||||
<CardTitle className="text-lg">
|
||||
This server has disabled new signups :(
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Button asChild className="w-full">
|
||||
<Link href="/signin">Back</Link>
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
+1
-1
@@ -37,7 +37,7 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
let songs: Awaited<ReturnType<typeof getSongSources>>
|
||||
try {
|
||||
songs = await getSongSources(songIds)
|
||||
songs = await getSongSources(songIds, request)
|
||||
} catch {
|
||||
return new Response("Not found", { status: 404 })
|
||||
}
|
||||
File renamed without changes.
+5
-9
@@ -53,9 +53,10 @@ async function transcodeResponse(
|
||||
songId: string,
|
||||
source: string,
|
||||
kbps: number,
|
||||
signal: AbortSignal
|
||||
request: NextRequest
|
||||
) {
|
||||
const lyrics = await getSongLyrics(songId)
|
||||
const { signal } = request
|
||||
const lyrics = await getSongLyrics(songId, request)
|
||||
const lyricsArgs =
|
||||
lyrics && Buffer.byteLength(lyrics) <= MAX_LYRICS_ARGUMENT_BYTES
|
||||
? ["-metadata", `lyrics=${lyrics}`]
|
||||
@@ -115,7 +116,7 @@ export async function GET(
|
||||
|
||||
let song: Awaited<ReturnType<typeof getSongSource>>
|
||||
try {
|
||||
song = await getSongSource(id)
|
||||
song = await getSongSource(id, request)
|
||||
} catch {
|
||||
return new Response("Not found", { status: 404 })
|
||||
}
|
||||
@@ -128,12 +129,7 @@ export async function GET(
|
||||
|
||||
try {
|
||||
if (plan.kbps > 0) {
|
||||
return await transcodeResponse(
|
||||
song._id,
|
||||
sourceFile,
|
||||
plan.kbps,
|
||||
request.signal
|
||||
)
|
||||
return await transcodeResponse(song._id, sourceFile, plan.kbps, request)
|
||||
}
|
||||
|
||||
if (plan.source === "lossless") {
|
||||
+1
-1
@@ -15,7 +15,7 @@ export async function GET(
|
||||
const { id } = await params
|
||||
|
||||
try {
|
||||
const song = await getSongSource(id)
|
||||
const song = await getSongSource(id, request)
|
||||
|
||||
const quality = request.nextUrl.searchParams.get("quality")
|
||||
const preferAtmos =
|
||||
+1
-1
@@ -35,7 +35,7 @@ export async function GET(
|
||||
const preferAtmos =
|
||||
request.nextUrl.searchParams.get("preferAtmos") === "true"
|
||||
// Resolve the source even when a job is cached so every segment is authorized.
|
||||
const song = await getSongSource(id)
|
||||
const song = await getSongSource(id, request)
|
||||
const job =
|
||||
getExistingHlsJob(id, quality, preferAtmos) ??
|
||||
(await ensureHlsJob(song, quality, preferAtmos))
|
||||
+1
-1
@@ -120,7 +120,7 @@ export async function GET(
|
||||
const { browser } = userAgent(request)
|
||||
|
||||
try {
|
||||
const song = await getSongSource(id)
|
||||
const song = await getSongSource(id, request)
|
||||
|
||||
const {
|
||||
source: originalCodec,
|
||||
File renamed without changes.
+18
-9
@@ -37,8 +37,11 @@ async function hostedUrl() {
|
||||
}
|
||||
}
|
||||
|
||||
const staticExport = process.env.OTUNES_STATIC_EXPORT === "1"
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const url = await hostedUrl()
|
||||
// Static exports have no request to read the host from.
|
||||
const url = staticExport ? undefined : await hostedUrl()
|
||||
|
||||
return {
|
||||
title: "oTunes",
|
||||
@@ -70,6 +73,13 @@ export default function RootLayout({
|
||||
}: Readonly<{
|
||||
children: React.ReactNode
|
||||
}>) {
|
||||
const content = (
|
||||
<ThemeProvider defaultTheme="system">
|
||||
{children}
|
||||
<Toaster />
|
||||
</ThemeProvider>
|
||||
)
|
||||
|
||||
return (
|
||||
<html
|
||||
lang="en"
|
||||
@@ -82,14 +92,13 @@ export default function RootLayout({
|
||||
)}
|
||||
>
|
||||
<body className={"overflow-x-hidden"}>
|
||||
<ConvexAuthNextjsServerProvider storageNamespace="otunes">
|
||||
<ConvexClientProvider convexUrl={process.env.PUBLIC_CONVEX_URL}>
|
||||
<ThemeProvider>
|
||||
{children}
|
||||
<Toaster />
|
||||
</ThemeProvider>
|
||||
</ConvexClientProvider>
|
||||
</ConvexAuthNextjsServerProvider>
|
||||
{staticExport ? (
|
||||
<ConvexClientProvider>{content}</ConvexClientProvider>
|
||||
) : (
|
||||
<ConvexAuthNextjsServerProvider storageNamespace="otunes">
|
||||
<ConvexClientProvider>{content}</ConvexClientProvider>
|
||||
</ConvexAuthNextjsServerProvider>
|
||||
)}
|
||||
</body>
|
||||
</html>
|
||||
)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import type { MetadataRoute } from "next"
|
||||
|
||||
export const dynamic = "force-static"
|
||||
|
||||
export default function manifest(): MetadataRoute.Manifest {
|
||||
return {
|
||||
name: "oTunes",
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { notFound } from "next/navigation"
|
||||
|
||||
import { ServerForm } from "@/components/server-form"
|
||||
|
||||
export default function ServerPage() {
|
||||
// The server build is the server; only desktop apps pick one.
|
||||
if (process.env.OTUNES_STATIC_EXPORT !== "1") notFound()
|
||||
return <ServerForm />
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import { playlistPath } from "@/lib/routes"
|
||||
|
||||
import * as React from "react"
|
||||
import { useConvex, useMutation, useQuery } from "convex/react"
|
||||
import { useRouter } from "next/navigation"
|
||||
@@ -256,7 +258,7 @@ export function AddToPlaylistProvider({
|
||||
setNewPlaylistName("")
|
||||
setPendingSongIds([])
|
||||
if (count === 0) {
|
||||
router.push(`/playlist/${playlistId}`)
|
||||
router.push(playlistPath(playlistId))
|
||||
}
|
||||
} catch (error) {
|
||||
toast.error(
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import { albumPath, artistPath } from "@/lib/routes"
|
||||
|
||||
import * as React from "react"
|
||||
import Image from "next/image"
|
||||
import Link from "next/link"
|
||||
@@ -123,7 +125,7 @@ export function AlbumCard({ album }: { album: BrowseAlbum }) {
|
||||
onMouseEnter={() => setHovered(true)}
|
||||
onMouseLeave={() => setHovered(false)}
|
||||
>
|
||||
<Link className="absolute inset-0" href={"/album/" + album.id}>
|
||||
<Link className="absolute inset-0" href={albumPath(album.id)}>
|
||||
<Image
|
||||
src={albumCoverUrl(album.id)}
|
||||
alt={album.title}
|
||||
@@ -186,11 +188,11 @@ export function AlbumCard({ album }: { album: BrowseAlbum }) {
|
||||
</div>
|
||||
|
||||
<div className="min-w-0">
|
||||
<Link href={"/album/" + album.id} className="hover:underline">
|
||||
<Link href={albumPath(album.id)} className="hover:underline">
|
||||
<p className="truncate text-sm font-medium">{album.title}</p>
|
||||
</Link>
|
||||
<Link
|
||||
href={"/artist/" + album.artist.id}
|
||||
href={artistPath(album.artist.id)}
|
||||
className="text-muted-foreground decoration-muted-foreground hover:underline"
|
||||
>
|
||||
<p className="truncate text-xs">{album.artist.name}</p>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import { artistPath } from "@/lib/routes"
|
||||
|
||||
import { PageHeader } from "@/components/library-skeletons"
|
||||
import * as React from "react"
|
||||
import Image from "next/image"
|
||||
@@ -114,7 +116,6 @@ export function AlbumView({
|
||||
}) {
|
||||
const {
|
||||
isSongFavorite,
|
||||
areSongsFavorite,
|
||||
isAlbumFavorite,
|
||||
toggleSongFavorite,
|
||||
toggleAlbumFavorite,
|
||||
@@ -155,7 +156,6 @@ export function AlbumView({
|
||||
handlePointerDown,
|
||||
prepareContextMenu,
|
||||
} = useTrackSelection(album.tracks, validHighlightedSongId)
|
||||
const selectionFavorited = areSongsFavorite(selectedIds)
|
||||
|
||||
const selectionPositions = React.useMemo(
|
||||
() =>
|
||||
@@ -289,7 +289,7 @@ export function AlbumView({
|
||||
{album.title}
|
||||
</h1>
|
||||
<Link
|
||||
href={"/artist/" + album.artist.id}
|
||||
href={artistPath(album.artist.id)}
|
||||
className="inline-block text-lg font-semibold text-primary hover:underline"
|
||||
>
|
||||
{album.artist.name}
|
||||
@@ -415,7 +415,6 @@ export function AlbumView({
|
||||
isFavorite={isSongFavorite(track.id)}
|
||||
selectedCount={selectedCount}
|
||||
selectionStationArtistId={album.artist.id}
|
||||
selectionFavorited={selectionFavorited}
|
||||
isNowPlaying={currentSongId === track.id}
|
||||
onPointerDown={handlePointerDown}
|
||||
onSelect={handleRowSelect}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
"use client"
|
||||
|
||||
import { playlistPath } from "@/lib/routes"
|
||||
import { serverUrl, staticExport } from "@/lib/server"
|
||||
|
||||
import {
|
||||
ArrowDownToLine,
|
||||
Disc3,
|
||||
@@ -10,11 +13,12 @@ import {
|
||||
Mic,
|
||||
Music2,
|
||||
Search,
|
||||
Server,
|
||||
Settings,
|
||||
Star,
|
||||
} from "lucide-react"
|
||||
|
||||
import { usePathname, useRouter } from "next/navigation"
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation"
|
||||
import dynamic from "next/dynamic"
|
||||
import { useAuthActions } from "@convex-dev/auth/react"
|
||||
|
||||
@@ -43,6 +47,7 @@ import Image from "next/image"
|
||||
import Link from "next/link"
|
||||
import { useTheme } from "next-themes"
|
||||
import * as React from "react"
|
||||
import { Suspense } from "react"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import { playlistCoverUrl } from "@/lib/cover-urls"
|
||||
import { useCachedQuery } from "@/hooks/use-cached-query"
|
||||
@@ -109,7 +114,7 @@ export function AppSidebar() {
|
||||
...(sidebarPlaylists?.subscribed ?? []),
|
||||
].map((playlist) => ({
|
||||
title: playlist.title,
|
||||
path: `/playlist/${playlist.id}`,
|
||||
path: playlistPath(playlist.id),
|
||||
icon: playlist.cover ? (
|
||||
// eslint-disable-next-line @next/next/no-img-element -- versioned cover, already sized by the route
|
||||
<img
|
||||
@@ -196,18 +201,20 @@ export function AppSidebar() {
|
||||
<SidebarGroup>
|
||||
<SidebarGroupLabel>Playlists</SidebarGroupLabel>
|
||||
<SidebarGroupContent>
|
||||
<SidebarMenu>
|
||||
{playlistNav.map((item) => (
|
||||
<SidebarMenuItem key={item.path}>
|
||||
<SidebarMenuButton isActive={pathname === item.path} asChild>
|
||||
<Link href={item.path} onClick={() => setOpenMobile(false)}>
|
||||
{item.icon}
|
||||
<span>{item.title}</span>
|
||||
</Link>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
))}
|
||||
</SidebarMenu>
|
||||
<Suspense
|
||||
fallback={
|
||||
<PlaylistMenu
|
||||
items={playlistNav}
|
||||
route={pathname}
|
||||
onNavigate={() => setOpenMobile(false)}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<CurrentPlaylistMenu
|
||||
items={playlistNav}
|
||||
onNavigate={() => setOpenMobile(false)}
|
||||
/>
|
||||
</Suspense>
|
||||
</SidebarGroupContent>
|
||||
</SidebarGroup>
|
||||
</SidebarContent>
|
||||
@@ -220,7 +227,10 @@ export function AppSidebar() {
|
||||
<SidebarMenuButton size="lg" className="min-w-0 flex-1">
|
||||
<Avatar size="sm" key={user?.image ?? "fallback"}>
|
||||
{user?.image ? (
|
||||
<AvatarImage src={user.image} alt={user.name} />
|
||||
<AvatarImage
|
||||
src={serverUrl(user.image)}
|
||||
alt={user.name}
|
||||
/>
|
||||
) : null}
|
||||
<AvatarFallback>{fallbackLetters}</AvatarFallback>
|
||||
</Avatar>
|
||||
@@ -243,6 +253,15 @@ export function AppSidebar() {
|
||||
Options
|
||||
<Settings />
|
||||
</DropdownMenuItem>
|
||||
{staticExport ? (
|
||||
<DropdownMenuItem
|
||||
className="justify-between"
|
||||
onClick={() => router.push("/server")}
|
||||
>
|
||||
Change Server
|
||||
<Server />
|
||||
</DropdownMenuItem>
|
||||
) : null}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
{optionsOpen ? (
|
||||
@@ -255,3 +274,46 @@ export function AppSidebar() {
|
||||
</Sidebar>
|
||||
)
|
||||
}
|
||||
|
||||
type NavItem = { title: string; path: string; icon: React.ReactNode }
|
||||
|
||||
// Playlist routes differ only by `?id=`. Reading the query needs a Suspense
|
||||
// boundary in static exports, so the fallback matches on the path alone.
|
||||
function CurrentPlaylistMenu(props: {
|
||||
items: NavItem[]
|
||||
onNavigate: () => void
|
||||
}) {
|
||||
const pathname = usePathname()
|
||||
const query = useSearchParams().toString()
|
||||
return (
|
||||
<PlaylistMenu
|
||||
{...props}
|
||||
route={query ? `${pathname}?${query}` : pathname}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function PlaylistMenu({
|
||||
items,
|
||||
route,
|
||||
onNavigate,
|
||||
}: {
|
||||
items: NavItem[]
|
||||
route: string
|
||||
onNavigate: () => void
|
||||
}) {
|
||||
return (
|
||||
<SidebarMenu>
|
||||
{items.map((item) => (
|
||||
<SidebarMenuItem key={item.path}>
|
||||
<SidebarMenuButton isActive={route === item.path} asChild>
|
||||
<Link href={item.path} onClick={onNavigate}>
|
||||
{item.icon}
|
||||
<span>{item.title}</span>
|
||||
</Link>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
))}
|
||||
</SidebarMenu>
|
||||
)
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import { artistPath } from "@/lib/routes"
|
||||
|
||||
import Image from "next/image"
|
||||
import Link from "next/link"
|
||||
|
||||
@@ -11,7 +13,7 @@ export function ArtistCard({ artist }: { artist: BrowseArtist }) {
|
||||
<div className="group flex flex-col items-center gap-2">
|
||||
<Link
|
||||
className="relative flex aspect-square w-full items-center justify-center overflow-hidden rounded-full ring-1 ring-foreground/10"
|
||||
href={"/artist/" + artist.id}
|
||||
href={artistPath(artist.id)}
|
||||
>
|
||||
<Image
|
||||
src={artistCoverUrl(artist.id)}
|
||||
@@ -22,7 +24,7 @@ export function ArtistCard({ artist }: { artist: BrowseArtist }) {
|
||||
/>
|
||||
</Link>
|
||||
<div className="min-w-0">
|
||||
<Link href={"/artist/" + artist.id} className="hover:underline">
|
||||
<Link href={artistPath(artist.id)} className="hover:underline">
|
||||
<p className="truncate text-center text-sm font-medium">
|
||||
{artist.name}
|
||||
</p>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client"
|
||||
|
||||
import { usePathname } from "next/navigation"
|
||||
import { useSearchParams } from "next/navigation"
|
||||
import { useCallback } from "react"
|
||||
|
||||
import { ArtistsView } from "@/components/artists-view"
|
||||
@@ -8,20 +8,17 @@ import { ArtistsSkeleton, PageHeader } from "@/components/library-skeletons"
|
||||
import { useCachedQuery } from "@/hooks/use-cached-query"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
|
||||
const ARTISTS_PATH = "/library/artists"
|
||||
|
||||
function artistIdFromPathname(pathname: string) {
|
||||
const [, id] = pathname.slice(ARTISTS_PATH.length).split("/")
|
||||
return id ? decodeURIComponent(id) : undefined
|
||||
}
|
||||
|
||||
export function ArtistsPage() {
|
||||
const pathname = usePathname()
|
||||
const artistId = useSearchParams().get("id") ?? undefined
|
||||
const artists = useCachedQuery(api.library.browseArtists)
|
||||
const albums = useCachedQuery(api.library.browseAlbums)
|
||||
|
||||
const selectArtist = useCallback((artistId: string) => {
|
||||
window.history.pushState(null, "", `${ARTISTS_PATH}/${artistId}`)
|
||||
window.history.pushState(
|
||||
null,
|
||||
"",
|
||||
`/library/artists?${new URLSearchParams({ id: artistId })}`
|
||||
)
|
||||
}, [])
|
||||
|
||||
return (
|
||||
@@ -34,7 +31,7 @@ export function ArtistsPage() {
|
||||
<ArtistsView
|
||||
artists={artists.flat()}
|
||||
albums={albums.flat()}
|
||||
artistId={artistIdFromPathname(pathname)}
|
||||
artistId={artistId}
|
||||
onSelectArtist={selectArtist}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import { artistPath } from "@/lib/routes"
|
||||
|
||||
import * as React from "react"
|
||||
import Image from "next/image"
|
||||
import Link from "next/link"
|
||||
@@ -155,7 +157,7 @@ export function ArtistsView({
|
||||
<div className="pb-28">
|
||||
<div className="flex min-w-0 items-center justify-between gap-4 border-b px-6 py-4">
|
||||
<Link
|
||||
href={`/artist/${selectedArtist.id}`}
|
||||
href={artistPath(selectedArtist.id)}
|
||||
className="group inline-flex min-w-0 flex-1 items-center gap-1 text-xl font-bold tracking-tight hover:underline"
|
||||
>
|
||||
<span className="min-w-0 truncate">{selectedArtist.name}</span>
|
||||
|
||||
@@ -53,27 +53,16 @@ const copy: Record<
|
||||
},
|
||||
}
|
||||
|
||||
export function AuthForm({
|
||||
flow,
|
||||
accountCreationDisabled,
|
||||
}: {
|
||||
flow: AuthFlow
|
||||
accountCreationDisabled: boolean
|
||||
}) {
|
||||
export function AuthForm({ flow }: { flow: AuthFlow }) {
|
||||
const { signIn } = useAuthActions()
|
||||
const router = useRouter()
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [submitting, setSubmitting] = useState(false)
|
||||
|
||||
const text = copy[flow]
|
||||
const signupsDisabled = flow === "signUp" && accountCreationDisabled
|
||||
const hideSignUpLink = flow === "signIn" && accountCreationDisabled
|
||||
|
||||
async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault()
|
||||
if (signupsDisabled) {
|
||||
return
|
||||
}
|
||||
setError(null)
|
||||
setSubmitting(true)
|
||||
|
||||
@@ -100,71 +89,62 @@ export function AuthForm({
|
||||
<CardDescription>{text.description}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{signupsDisabled ? (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
New account registration is currently disabled. Contact an
|
||||
administrator if you need access.
|
||||
</p>
|
||||
) : (
|
||||
<form onSubmit={handleSubmit}>
|
||||
<FieldGroup>
|
||||
{flow === "signUp" && (
|
||||
<Field>
|
||||
<FieldLabel htmlFor="name">Name</FieldLabel>
|
||||
<Input
|
||||
id="name"
|
||||
name="name"
|
||||
type="text"
|
||||
autoComplete="name"
|
||||
placeholder="Ada Lovelace"
|
||||
required
|
||||
/>
|
||||
</Field>
|
||||
)}
|
||||
<form onSubmit={handleSubmit}>
|
||||
<FieldGroup>
|
||||
{flow === "signUp" && (
|
||||
<Field>
|
||||
<FieldLabel htmlFor="email">Email</FieldLabel>
|
||||
<FieldLabel htmlFor="name">Name</FieldLabel>
|
||||
<Input
|
||||
id="email"
|
||||
name="email"
|
||||
type="email"
|
||||
autoComplete="email"
|
||||
placeholder="you@example.com"
|
||||
id="name"
|
||||
name="name"
|
||||
type="text"
|
||||
autoComplete="name"
|
||||
placeholder="Ada Lovelace"
|
||||
required
|
||||
/>
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel htmlFor="password">Password</FieldLabel>
|
||||
<Input
|
||||
id="password"
|
||||
name="password"
|
||||
type="password"
|
||||
autoComplete={
|
||||
flow === "signIn" ? "current-password" : "new-password"
|
||||
}
|
||||
required
|
||||
/>
|
||||
</Field>
|
||||
{error && <FieldError>{error}</FieldError>}
|
||||
<Field>
|
||||
<Button type="submit" disabled={submitting}>
|
||||
{submitting && <Spinner />}
|
||||
{text.submit}
|
||||
</Button>
|
||||
</Field>
|
||||
{!hideSignUpLink ? (
|
||||
<p className="text-center text-sm text-muted-foreground">
|
||||
{text.switchPrompt}{" "}
|
||||
<Link
|
||||
href={text.switchHref}
|
||||
className="text-primary underline-offset-4 hover:underline"
|
||||
>
|
||||
{text.switchLabel}
|
||||
</Link>
|
||||
</p>
|
||||
) : null}
|
||||
</FieldGroup>
|
||||
</form>
|
||||
)}
|
||||
)}
|
||||
<Field>
|
||||
<FieldLabel htmlFor="email">Email</FieldLabel>
|
||||
<Input
|
||||
id="email"
|
||||
name="email"
|
||||
type="email"
|
||||
autoComplete="email"
|
||||
placeholder="you@example.com"
|
||||
required
|
||||
/>
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel htmlFor="password">Password</FieldLabel>
|
||||
<Input
|
||||
id="password"
|
||||
name="password"
|
||||
type="password"
|
||||
autoComplete={
|
||||
flow === "signIn" ? "current-password" : "new-password"
|
||||
}
|
||||
required
|
||||
/>
|
||||
</Field>
|
||||
{error && <FieldError>{error}</FieldError>}
|
||||
<Field>
|
||||
<Button type="submit" disabled={submitting}>
|
||||
{submitting && <Spinner />}
|
||||
{text.submit}
|
||||
</Button>
|
||||
</Field>
|
||||
<p className="text-center text-sm text-muted-foreground">
|
||||
{text.switchPrompt}{" "}
|
||||
<Link
|
||||
href={text.switchHref}
|
||||
className="text-primary underline-offset-4 hover:underline"
|
||||
>
|
||||
{text.switchLabel}
|
||||
</Link>
|
||||
</p>
|
||||
</FieldGroup>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
"use client"
|
||||
|
||||
import { useConvexAuth } from "convex/react"
|
||||
import { usePathname, useRouter } from "next/navigation"
|
||||
import { useEffect } from "react"
|
||||
|
||||
// Media pages that signed-out visitors can open from share links.
|
||||
const PUBLIC_PATHS = new Set(["/album", "/artist", "/playlist"])
|
||||
|
||||
/**
|
||||
* Static exports have no proxy, so this keeps signed-out users on the auth
|
||||
* pages and signed-in users off them. Server builds redirect in proxy.server.ts.
|
||||
*/
|
||||
export function AuthRedirect({ area }: { area: "app" | "auth" }) {
|
||||
const { isAuthenticated, isLoading } = useConvexAuth()
|
||||
const pathname = usePathname()
|
||||
const router = useRouter()
|
||||
|
||||
useEffect(() => {
|
||||
if (isLoading) return
|
||||
if (area === "auth" && isAuthenticated) router.replace("/")
|
||||
if (area === "app" && !isAuthenticated && !PUBLIC_PATHS.has(pathname))
|
||||
router.replace("/signin")
|
||||
}, [area, isAuthenticated, isLoading, pathname, router])
|
||||
|
||||
return null
|
||||
}
|
||||
@@ -1,11 +1,19 @@
|
||||
"use client"
|
||||
|
||||
import { ConvexAuthNextjsProvider } from "@convex-dev/auth/nextjs"
|
||||
import { ConvexAuthProvider, useAuthToken } from "@convex-dev/auth/react"
|
||||
import { buildConvexUrl } from "@otunes/convex/server-url"
|
||||
import { ConvexReactClient } from "convex/react"
|
||||
import { ReactNode } from "react"
|
||||
import { usePathname, useRouter } from "next/navigation"
|
||||
import { ReactNode, useEffect } from "react"
|
||||
|
||||
import { PersistentCacheProvider } from "@/components/persistent-cache-provider"
|
||||
import {
|
||||
selectedServer,
|
||||
setMediaToken,
|
||||
staticExport,
|
||||
useSelectedServer,
|
||||
} from "@/lib/server"
|
||||
|
||||
// Server rendering never runs Convex queries, so this URL is never contacted.
|
||||
const SSR_CONVEX_URL = "http://127.0.0.1:3210"
|
||||
@@ -17,29 +25,50 @@ function browserConvexUrl() {
|
||||
return buildConvexUrl(host, protocol === "https:" ? "https" : "http")
|
||||
}
|
||||
|
||||
function getConvexClient(convexUrl: string | undefined) {
|
||||
if (!client) {
|
||||
client = new ConvexReactClient(
|
||||
typeof window === "undefined"
|
||||
? SSR_CONVEX_URL
|
||||
: (convexUrl ??
|
||||
process.env.NEXT_PUBLIC_CONVEX_URL ??
|
||||
browserConvexUrl())
|
||||
)
|
||||
}
|
||||
function getConvexClient(convexUrl: string) {
|
||||
client ??= new ConvexReactClient(convexUrl)
|
||||
return client
|
||||
}
|
||||
|
||||
export function ConvexClientProvider({
|
||||
convexUrl,
|
||||
children,
|
||||
}: {
|
||||
convexUrl?: string
|
||||
children: ReactNode
|
||||
}) {
|
||||
export function ConvexClientProvider({ children }: { children: ReactNode }) {
|
||||
if (staticExport) return <ExportProviders>{children}</ExportProviders>
|
||||
const url =
|
||||
typeof window === "undefined"
|
||||
? SSR_CONVEX_URL
|
||||
: (process.env.NEXT_PUBLIC_CONVEX_URL ?? browserConvexUrl())
|
||||
return (
|
||||
<ConvexAuthNextjsProvider client={getConvexClient(convexUrl)}>
|
||||
<PersistentCacheProvider>{children}</PersistentCacheProvider>{" "}
|
||||
<ConvexAuthNextjsProvider client={getConvexClient(url)}>
|
||||
<PersistentCacheProvider>{children}</PersistentCacheProvider>
|
||||
</ConvexAuthNextjsProvider>
|
||||
)
|
||||
}
|
||||
|
||||
// Static exports pick a server at /server first. With no Next.js server to
|
||||
// hold the session in cookies, tokens live in localStorage, keyed by the
|
||||
// Convex URL, as in the mobile app. Changing servers reloads the page.
|
||||
function ExportProviders({ children }: { children: ReactNode }) {
|
||||
const server = useSelectedServer()
|
||||
const pathname = usePathname()
|
||||
const router = useRouter()
|
||||
const onServerPage = pathname === "/server"
|
||||
|
||||
useEffect(() => {
|
||||
if (!onServerPage && !selectedServer()) router.replace("/server")
|
||||
}, [onServerPage, router])
|
||||
|
||||
if (onServerPage) return children
|
||||
if (!server) return null
|
||||
return (
|
||||
<ConvexAuthProvider client={getConvexClient(server.convexUrl)}>
|
||||
<MediaTokenSync />
|
||||
<PersistentCacheProvider>{children}</PersistentCacheProvider>
|
||||
</ConvexAuthProvider>
|
||||
)
|
||||
}
|
||||
|
||||
function MediaTokenSync() {
|
||||
const token = useAuthToken()
|
||||
// Set during render so players created in this commit see the new token.
|
||||
setMediaToken(token)
|
||||
return null
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import { Label } from "@/components/ui/label"
|
||||
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
|
||||
import { useCachedQuery } from "@/hooks/use-cached-query"
|
||||
import { useDownloadsVersion } from "@/hooks/use-downloads"
|
||||
import { authedUrl } from "@/lib/server"
|
||||
import {
|
||||
downloadQueue,
|
||||
readRememberedDownloadQuality,
|
||||
@@ -78,7 +79,7 @@ export function useDownloads() {
|
||||
}
|
||||
|
||||
async function fetchDownloadOptions(songIds: string[]) {
|
||||
const response = await fetch(DOWNLOAD_OPTIONS_PATH, {
|
||||
const response = await fetch(authedUrl(DOWNLOAD_OPTIONS_PATH), {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ songIds }),
|
||||
|
||||
@@ -39,10 +39,9 @@ const ASK_EVERY_TIME = "ask"
|
||||
|
||||
/** Shades of the text color, darkest for the smallest files. */
|
||||
const QUALITY_OPACITY: Record<DownloadQuality, number> = {
|
||||
low: 0.2,
|
||||
medium: 0.35,
|
||||
high: 0.5,
|
||||
lossless: 0.75,
|
||||
medium: 0.25,
|
||||
high: 0.45,
|
||||
lossless: 0.7,
|
||||
atmos: 1,
|
||||
}
|
||||
|
||||
|
||||
@@ -37,8 +37,7 @@ type FavoritesContextValue = {
|
||||
) => Promise<boolean>
|
||||
toggleAlbumFavorite: (albumId: Id<"albums">) => Promise<void>
|
||||
toggleArtistFavorite: (artistId: Id<"artists">) => Promise<void>
|
||||
/** True when `songIds` is non-empty and every song is favorited. */
|
||||
areSongsFavorite: (songIds: Iterable<string>) => boolean
|
||||
favoriteSongs: (songIds: Id<"songs">[]) => Promise<void>
|
||||
}
|
||||
|
||||
const FavoritesContext = React.createContext<FavoritesContextValue | null>(null)
|
||||
@@ -131,16 +130,26 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
|
||||
[songIds, favoriteSong, unfavoriteSong]
|
||||
)
|
||||
|
||||
const areSongsFavorite = React.useCallback(
|
||||
(ids: Iterable<string>) => {
|
||||
let any = false
|
||||
for (const id of ids) {
|
||||
if (!songIds.has(id)) return false
|
||||
any = true
|
||||
const favoriteSongs = React.useCallback(
|
||||
async (ids: Id<"songs">[]) => {
|
||||
const unique = [...new Set(ids)]
|
||||
if (unique.length === 0) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await favoriteSongsMutation({ songIds: unique })
|
||||
toast.success(
|
||||
unique.length > 1
|
||||
? `Favorited ${unique.length} songs`
|
||||
: "Added to favorites"
|
||||
)
|
||||
} catch (error) {
|
||||
toast.error(
|
||||
error instanceof Error ? error.message : "Failed to update favorites"
|
||||
)
|
||||
}
|
||||
return any
|
||||
},
|
||||
[songIds]
|
||||
[favoriteSongsMutation]
|
||||
)
|
||||
|
||||
const toggleSongsFavorite = React.useCallback(
|
||||
@@ -223,7 +232,7 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
|
||||
toggleSongsFavorite,
|
||||
toggleAlbumFavorite,
|
||||
toggleArtistFavorite,
|
||||
areSongsFavorite,
|
||||
favoriteSongs,
|
||||
}),
|
||||
[
|
||||
isSongFavorite,
|
||||
@@ -233,7 +242,7 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
|
||||
toggleSongsFavorite,
|
||||
toggleAlbumFavorite,
|
||||
toggleArtistFavorite,
|
||||
areSongsFavorite,
|
||||
favoriteSongs,
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@@ -183,8 +183,7 @@ const SyncedLine = React.memo(function SyncedLine({
|
||||
|
||||
/**
|
||||
* The playing line's words, each filled as far as it has been sung. The
|
||||
* browser runs the fills on the song's timeline (a word's start is its
|
||||
* delay); playback updates only correct their drift.
|
||||
* browser runs the fills; playback updates only correct their drift.
|
||||
*/
|
||||
function FilledWords({
|
||||
words,
|
||||
@@ -201,7 +200,6 @@ function FilledWords({
|
||||
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",
|
||||
@@ -211,14 +209,15 @@ function FilledWords({
|
||||
}, [words])
|
||||
|
||||
React.useEffect(() => {
|
||||
const at = time * 1000
|
||||
fills.current.forEach((fill, index) => {
|
||||
if (!fill) return
|
||||
const at = (time - words[index].start) * 1000
|
||||
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()
|
||||
// `play` on a finished fill would rewind it.
|
||||
const duration = Number(fill.effect?.getTiming().duration ?? 0)
|
||||
if (isPlaying && at < duration) fill.play()
|
||||
else fill.pause()
|
||||
})
|
||||
}, [words, time, isPlaying])
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import { albumPath, artistPath } from "@/lib/routes"
|
||||
|
||||
import * as React from "react"
|
||||
import Link from "next/link"
|
||||
import {
|
||||
@@ -165,7 +167,7 @@ export function MediaContextMenuItems({
|
||||
<MediaMenuSeparator />
|
||||
{artist ? (
|
||||
<MediaMenuItem asChild className="justify-between">
|
||||
<Link href={`/artist/${artist.id}`}>
|
||||
<Link href={artistPath(artist.id)}>
|
||||
Go to Artist
|
||||
<MicVocal />
|
||||
</Link>
|
||||
@@ -173,7 +175,7 @@ export function MediaContextMenuItems({
|
||||
) : null}
|
||||
{album ? (
|
||||
<MediaMenuItem asChild className="justify-between">
|
||||
<Link href={`/album/${album.id}`}>
|
||||
<Link href={albumPath(album.id)}>
|
||||
Go to Album
|
||||
<GalleryVerticalEnd />
|
||||
</Link>
|
||||
|
||||
@@ -2,10 +2,20 @@
|
||||
|
||||
import { ArrowUpRight } from "lucide-react"
|
||||
|
||||
import { serverOrigin } from "@/lib/server"
|
||||
|
||||
export function OpenAppButton() {
|
||||
function openApp() {
|
||||
const link = new URL("otunes://open")
|
||||
link.searchParams.set("url", window.location.href)
|
||||
// The app understands share links (/album/<id>), not in-app /album?id=<id>.
|
||||
const { pathname, search } = window.location
|
||||
const page = new URL(`${pathname}${search}`, serverOrigin())
|
||||
const id = page.searchParams.get("id")
|
||||
if (id && /^\/(album|artist|playlist)$/.test(page.pathname)) {
|
||||
page.pathname += `/${encodeURIComponent(id)}`
|
||||
page.searchParams.delete("id")
|
||||
}
|
||||
link.searchParams.set("url", page.href)
|
||||
window.location.assign(link.href)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import { serverUrl } from "@/lib/server"
|
||||
|
||||
import { useAction, useMutation, useQuery } from "convex/react"
|
||||
import { MoreHorizontal, Trash2, Upload, UserPlus } from "lucide-react"
|
||||
import { useCallback, useEffect, useRef, useState } from "react"
|
||||
@@ -149,7 +151,9 @@ function UserAvatar({
|
||||
key={user.image ?? "fallback"}
|
||||
size={size === "sm" ? "sm" : "default"}
|
||||
>
|
||||
{user.image ? <AvatarImage src={user.image} alt={user.name} /> : null}
|
||||
{user.image ? (
|
||||
<AvatarImage src={serverUrl(user.image)} alt={user.name} />
|
||||
) : null}
|
||||
<AvatarFallback>{initials}</AvatarFallback>
|
||||
</Avatar>
|
||||
)
|
||||
|
||||
@@ -48,8 +48,7 @@ export function OtherDownloadsView() {
|
||||
[songs]
|
||||
)
|
||||
|
||||
const { isSongFavorite, areSongsFavorite, toggleSongFavorite } =
|
||||
useFavorites()
|
||||
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
||||
const { playFromSong, playInOrder, playShuffled } = usePlaybackActions()
|
||||
const {
|
||||
selectedIds,
|
||||
@@ -63,7 +62,6 @@ export function OtherDownloadsView() {
|
||||
() => stationArtistId(songs, selectedIds),
|
||||
[songs, selectedIds]
|
||||
)
|
||||
const selectionFavorited = areSongsFavorite(selectedIds)
|
||||
const selectionPositions = useMemo(
|
||||
() =>
|
||||
getSelectionRangePositions(
|
||||
@@ -142,7 +140,6 @@ export function OtherDownloadsView() {
|
||||
isFavorite={isSongFavorite(songs[index].id)}
|
||||
selectedCount={selectedCount}
|
||||
selectionStationArtistId={selectedStationArtistId}
|
||||
selectionFavorited={selectionFavorited}
|
||||
onPointerDown={handlePointerDown}
|
||||
onSelect={handleRowSelect}
|
||||
onPlay={handleRowPlay}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import { authedUrl } from "@/lib/server"
|
||||
|
||||
import {
|
||||
useState,
|
||||
useEffect,
|
||||
@@ -354,15 +356,11 @@ function loadAudioSource(
|
||||
}
|
||||
|
||||
const { settings } = source
|
||||
const directUrl = songPlayPath(
|
||||
songId,
|
||||
settings.playbackQuality,
|
||||
settings.preferAtmos
|
||||
const directUrl = authedUrl(
|
||||
songPlayPath(songId, settings.playbackQuality, settings.preferAtmos)
|
||||
)
|
||||
const hlsUrl = songHlsPlaylistPath(
|
||||
songId,
|
||||
settings.playbackQuality,
|
||||
settings.preferAtmos
|
||||
const hlsUrl = authedUrl(
|
||||
songHlsPlaylistPath(songId, settings.playbackQuality, settings.preferAtmos)
|
||||
)
|
||||
|
||||
const loadDirectSource = () => {
|
||||
|
||||
Loaded 100 of 134 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user