Compare commits

..
15 changed files with 25 additions and 223 deletions

No files matched your search

+2 -7
View File
@@ -19,10 +19,9 @@ export default ({ config }: ConfigContext): ExpoConfig => {
: variant === "preview"
? " (Preview)"
: ""
// Expo writes this filename into Xcode build settings without quoting it.
const composer = {
development: "oTunesDev",
preview: "oTunesPreview",
development: "oTunes Dev",
preview: "oTunes Preview",
production: "oTunes",
}[variant]
@@ -36,10 +35,6 @@ export default ({ config }: ConfigContext): ExpoConfig => {
...config.ios,
bundleIdentifier: `${config.ios!.bundleIdentifier}${suffix}`,
icon: `./assets/${composer}.icon`,
infoPlist: {
...config.ios?.infoPlist,
NSUserActivityTypes: [`com.abunchofknowitalls.otunes${suffix}.media`],
},
},
android: {
...config.android,
+2 -5
View File
@@ -1,9 +1,6 @@
import { loadServerConfig, parseServerHostname } from "@/lib/server-config"
import { secureGetItem } from "@/lib/auth-storage"
import {
isMediaRoute,
rememberIncomingMediaLink,
} from "@/lib/incoming-media-link"
import { rememberIncomingMediaLink } from "@/lib/incoming-media-link"
import { showError } from "@/lib/toast"
export async function redirectSystemPath({
@@ -31,7 +28,7 @@ export async function redirectSystemPath({
target.username ||
target.password ||
new URL(server.serverUrl).origin !== target.origin ||
!isMediaRoute(target.pathname)
!/^\/(album|artist|playlist)\/[a-zA-Z0-9_-]+$/.test(target.pathname)
) {
return "/"
}
-3
View File
@@ -9,8 +9,6 @@ import { Toaster } from "@/components/ui/toaster"
import { ConvexAppProvider } from "@/contexts/convex-app"
import { ServerConfigProvider, useServerConfig } from "@/contexts/server-config"
import { HandoffBridge } from "@/components/handoff-bridge"
const navigationTheme = {
...DarkTheme,
colors: { ...DarkTheme.colors, background: "#000", card: "#000" },
@@ -58,7 +56,6 @@ export default function RootLayout() {
<ConvexAppProvider>
<StatusBar style={isDark ? "light" : "dark"} />
<ThemeProvider value={navigationTheme}>
<HandoffBridge />
<RootNavigator />
</ThemeProvider>
<Toaster />
File renamed without changes.

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

-81
View File
@@ -1,81 +0,0 @@
import { useConvexAuth } from "@convex-dev/auth/react"
import { requireOptionalNativeModule, type NativeModule } from "expo"
import { usePathname } from "expo-router"
import { useEffect } from "react"
import { Platform } from "react-native"
import { useServerConfig } from "@/contexts/server-config"
import {
isMediaRoute,
rememberIncomingMediaLink,
} from "@/lib/incoming-media-link"
import { showError } from "@/lib/toast"
type Activity = { server: string; route: string }
declare class HandoffModule extends NativeModule<{ onActivity: () => void }> {
takeActivity(): Promise<Activity | null>
publish(server: string | null, route: string | null): Promise<void>
}
const handoff =
Platform.OS === "ios"
? requireOptionalNativeModule<HandoffModule>("Handoff")
: null
export function HandoffBridge() {
const { config, isLoading } = useServerConfig()
const auth = useConvexAuth()
const pathname = usePathname()
useEffect(() => {
if (!handoff || isLoading) return
let active = true
async function receive() {
const activity = await handoff!.takeActivity()
if (!active || !activity) return
try {
const source = new URL(activity.server)
if (!config || source.origin !== new URL(config.serverUrl).origin) {
showError("This activity belongs to a different oTunes server.")
return
}
if (
!["http:", "https:"].includes(source.protocol) ||
source.username ||
source.password ||
!isMediaRoute(activity.route)
)
return
rememberIncomingMediaLink(
`/(app)/(tabs)/home${activity.route}`,
source.origin
)
} catch {
// Ignore malformed activities without navigating or changing servers.
}
}
const subscription = handoff.addListener("onActivity", () => {
void receive()
})
void receive()
return () => {
active = false
subscription.remove()
}
}, [config, isLoading])
useEffect(() => {
if (!handoff) return
const route = pathname.replace(/^\/(home|search|library)/, "")
const canPublish = config && auth?.isAuthenticated && isMediaRoute(route)
void handoff.publish(
canPublish ? config.serverUrl : null,
canPublish ? route : null
)
return () => {
void handoff.publish(null, null)
}
}, [config, auth?.isAuthenticated, pathname])
return null
}
@@ -59,8 +59,7 @@ export function MenuView({
outlineVariant: "#545458",
error: "#FF453A",
}}
// Rows fill their parent width; compact action buttons keep intrinsic sizing.
matchContents={shouldOpenOnLongPress ? { vertical: true } : true}
matchContents
>
<DropdownMenu
expanded={expanded}
@@ -71,9 +70,7 @@ export function MenuView({
properties={{ clippingEnabled: false }}
>
<DropdownMenu.Trigger>
<RNHostView
matchContents={shouldOpenOnLongPress ? { vertical: true } : true}
>
<RNHostView matchContents>
{shouldOpenOnLongPress ? (
<GestureDetector gesture={longPress}>
<View collapsable={false}>{children}</View>
-5
View File
@@ -28,8 +28,3 @@ export function rememberIncomingMediaLink(path: string, serverOrigin: string) {
pendingLink = { path, serverOrigin }
for (const listener of listeners) listener()
}
// Shared by native links and Handoff. Only concrete media screens are routable.
export function isMediaRoute(path: string) {
return /^\/(album|artist|playlist)\/[a-zA-Z0-9_-]+$/.test(path)
}
@@ -1,7 +0,0 @@
{
"platforms": ["apple"],
"apple": {
"modules": ["HandoffModule"],
"appDelegateSubscribers": ["HandoffAppDelegateSubscriber"]
}
}
@@ -1,16 +0,0 @@
Pod::Spec.new do |s|
s.name = 'Handoff'
s.version = '1.0.0'
s.summary = 'Native media screen Handoff for oTunes'
s.description = s.summary
s.license = { :type => 'MIT' }
s.author = 'oTunes'
s.homepage = 'https://otunes.abunchofknowitalls.com'
s.platforms = { :ios => '16.4' }
s.swift_version = '5.9'
s.source = { :git => '' }
s.static_framework = true
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
s.dependency 'ExpoModulesCore'
s.source_files = '**/*.swift'
end
@@ -1,70 +0,0 @@
import ExpoModulesCore
import UIKit
// Retain the latest continuation until JS is mounted, including cold launches.
private enum HandoffState {
static var activity: NSUserActivity?
static var pending: [String: String]?
static var notify: (() -> Void)?
static var activityType: String {
"\(Bundle.main.bundleIdentifier!).media"
}
}
public final class HandoffAppDelegateSubscriber: ExpoAppDelegateSubscriber {
public func application(
_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
) -> Bool {
guard userActivity.activityType == HandoffState.activityType,
let server = userActivity.userInfo?["server"] as? String,
let route = userActivity.userInfo?["route"] as? String
else { return false }
HandoffState.pending = ["server": server, "route": route]
HandoffState.notify?()
return true
}
}
public final class HandoffModule: Module {
public func definition() -> ModuleDefinition {
Name("Handoff")
Events("onActivity")
OnStartObserving {
HandoffState.notify = { [weak self] in self?.sendEvent("onActivity") }
if HandoffState.pending != nil { HandoffState.notify?() }
}
OnStopObserving { HandoffState.notify = nil }
AsyncFunction("takeActivity") { () -> [String: String]? in
defer { HandoffState.pending = nil }
return HandoffState.pending
}.runOnQueue(.main)
AsyncFunction("publish") { (server: String?, route: String?) in
HandoffState.activity?.invalidate()
HandoffState.activity = nil
guard let server, let route else { return }
let activity = NSUserActivity(activityType: HandoffState.activityType)
activity.title = "oTunes"
activity.userInfo = ["server": server, "route": route]
activity.requiredUserInfoKeys = ["server", "route"]
activity.isEligibleForHandoff = true
activity.isEligibleForSearch = false
activity.isEligibleForPublicIndexing = false
HandoffState.activity = activity
activity.becomeCurrent()
}.runOnQueue(.main)
OnDestroy {
DispatchQueue.main.async {
HandoffState.activity?.invalidate()
HandoffState.activity = nil
HandoffState.notify = nil
}
}
}
}
-5
View File
@@ -1,5 +0,0 @@
{
"name": "otunes-handoff",
"version": "1.0.0",
"private": true
}
+19 -19
View File
@@ -76,8 +76,8 @@ export function PlayerBar() {
queueOpen && !isMobile && "right-72"
)}
>
<div className="pointer-events-auto flex w-full max-w-[40rem] items-center gap-2 rounded-full border border-foreground/20 bg-(--player-background) px-3 py-2 text-card-foreground shadow-lg [--player-background:var(--card)] md:gap-3 md:py-1.5 dark:border-white/20 dark:text-white dark:[--player-background:#303033]">
<div className="flex shrink-0 items-center gap-0 md:gap-0.5 [&_button]:size-7 [&_svg]:size-4">
<div className="pointer-events-auto flex w-full max-w-6xl items-center gap-2 rounded-full border border-foreground/20 bg-(--player-background) px-3 py-2 text-card-foreground shadow-lg [--player-background:var(--card)] @min-[640px]:gap-5 @min-[640px]:px-5 @min-[640px]:py-3 dark:border-white/20 dark:text-white dark:[--player-background:#303033]">
<div className="flex shrink-0 items-center gap-0 @min-[640px]:gap-1 [&_button]:size-7 @min-[640px]:[&_button]:size-10 [&_svg]:size-4 @min-[640px]:[&_svg]:size-6">
<Button
variant="ghost"
size="icon"
@@ -91,7 +91,7 @@ export function PlayerBar() {
)}
onClick={() => void toggleShuffle()}
>
<Shuffle className="size-4" />
<Shuffle className="size-4 @min-[640px]:size-6" />
</Button>
<Button
variant="ghost"
@@ -100,7 +100,7 @@ export function PlayerBar() {
disabled={!hasQueue}
onClick={() => void skipPrevious()}
>
<SkipBack className="size-4 fill-current" />
<SkipBack className="size-4 fill-current @min-[640px]:size-6" />
</Button>
<Button
variant="ghost"
@@ -110,9 +110,9 @@ export function PlayerBar() {
onClick={() => setIsPlaying(!isPlaying)}
>
{isPlaying ? (
<Pause className="size-5! fill-current" />
<Pause className="size-5! fill-current @min-[640px]:size-8!" />
) : (
<Play className="size-5! fill-current" />
<Play className="size-5! fill-current @min-[640px]:size-8!" />
)}
</Button>
<Button
@@ -122,7 +122,7 @@ export function PlayerBar() {
disabled={!hasQueue}
onClick={() => void skipNext()}
>
<SkipForward className="size-4 fill-current" />
<SkipForward className="size-4 fill-current @min-[640px]:size-6" />
</Button>
<Button
variant="ghost"
@@ -138,33 +138,33 @@ export function PlayerBar() {
onClick={() => void cycleRepeat()}
>
{repeatEnabled === "once" ? (
<Repeat1 className="size-4" />
<Repeat1 className="size-4 @min-[640px]:size-6" />
) : (
<Repeat className="size-4" />
<Repeat className="size-4 @min-[640px]:size-6" />
)}
</Button>
</div>
<div className="relative flex h-11 min-w-0 flex-1 items-center gap-2 pb-2 md:h-9 md:pb-1">
<div className="relative flex h-11 min-w-0 flex-1 items-center gap-2 pb-2 @min-[640px]:h-16 @min-[640px]:gap-3">
{currentSong ? (
<>
<div className="relative size-9 shrink-0 overflow-hidden rounded md:size-8">
<div className="relative size-9 shrink-0 overflow-hidden rounded @min-[640px]:size-14">
<Image
src={albumCoverUrl(currentSong.album.id)}
alt={currentSong.album.title}
fill
sizes="36px"
sizes="56px"
className="object-cover"
/>
</div>
<div className="min-w-0 flex-1">
<Link
href={`/album/${currentSong.album.id}`}
className="block truncate text-sm font-semibold hover:underline md:text-[13px] md:leading-4"
className="block truncate text-sm font-semibold hover:underline @min-[640px]:text-xl"
>
{currentSong.title}
</Link>
<p className="truncate text-xs">
<p className="truncate text-xs @min-[640px]:text-lg">
<Link
href={`/artist/${currentSong.artist.id}`}
className="hover:underline"
@@ -200,7 +200,7 @@ export function PlayerBar() {
<div className="absolute inset-x-0 -bottom-1">
<Slider
className={cn(
"h-3 flex-1 [&_[data-slot=slider-range]]:bg-current/80 [&_[data-slot=slider-thumb]]:size-2 [&_[data-slot=slider-thumb]]:border-current [&_[data-slot=slider-thumb]]:bg-current [&_[data-slot=slider-thumb]]:opacity-0 focus-within:[&_[data-slot=slider-thumb]]:opacity-100 hover:[&_[data-slot=slider-thumb]]:opacity-100 [&_[data-slot=slider-track]]:h-[3px] [&_[data-slot=slider-track]]:bg-current/30 md:[&_[data-slot=slider-track]]:h-0.5",
"h-3 flex-1 [&_[data-slot=slider-range]]:bg-current/80 [&_[data-slot=slider-thumb]]:size-2 [&_[data-slot=slider-thumb]]:border-current [&_[data-slot=slider-thumb]]:bg-current [&_[data-slot=slider-thumb]]:opacity-0 focus-within:[&_[data-slot=slider-thumb]]:opacity-100 hover:[&_[data-slot=slider-thumb]]:opacity-100 [&_[data-slot=slider-track]]:h-[3px] [&_[data-slot=slider-track]]:bg-current/30",
!hasActiveSong && "[&_[data-slot=slider-thumb]]:hidden"
)}
min={0}
@@ -222,7 +222,7 @@ export function PlayerBar() {
</div>
</div>
<div className="flex shrink-0 items-center gap-0 md:gap-1 [&_button]:size-7 [&_svg]:size-4">
<div className="flex shrink-0 items-center gap-0 @min-[640px]:gap-2 [&_button]:size-7 @min-[640px]:[&_button]:size-10 [&_svg]:size-4 @min-[640px]:[&_svg]:size-6">
<Button
variant="ghost"
size="icon"
@@ -230,7 +230,7 @@ export function PlayerBar() {
aria-label="Lyrics"
disabled
>
<MessageSquareQuote className="size-4" />
<MessageSquareQuote className="size-4 @min-[640px]:size-6" />
</Button>
<Button
variant="ghost"
@@ -240,12 +240,12 @@ export function PlayerBar() {
className={cn(queueOpen && "text-primary")}
onClick={toggleQueueOpen}
>
<ListMusic className="size-4" />
<ListMusic className="size-4 @min-[640px]:size-6" />
</Button>
<Popover>
<PopoverTrigger asChild>
<Button variant="ghost" size="icon" aria-label="Volume">
<Volume2 className="size-4" />
<Volume2 className="size-4 @min-[640px]:size-6" />
</Button>
</PopoverTrigger>
<PopoverContent side="top" align="end" className="w-40">