From 2d4586deed9589059a7a9f6a7a7447f739183d65 Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Tue, 3 Nov 2026 15:28:33 -0500 Subject: [PATCH 1/4] feat: open shared links in the mobile app and share artwork --- apps/mobile/README.md | 19 ++++++++ apps/mobile/app/(app)/_layout.tsx | 11 +++++ apps/mobile/app/+native-intent.ts | 56 +++++++++++++++++++++++ apps/mobile/app/index.tsx | 12 ++++- apps/mobile/app/server.tsx | 6 ++- apps/mobile/lib/incoming-media-link.ts | 19 ++++++++ apps/mobile/lib/share-media-link.ts | 26 +++++++++-- apps/mobile/native/MediaLinkShare.kt | 44 ++++++++++++++++++ apps/mobile/native/MediaLinkShare.swift | 52 +++++++++++++++++++++ apps/web/components/album-view.tsx | 2 +- apps/web/components/artist-view.tsx | 2 +- apps/web/components/library-skeletons.tsx | 18 ++++++-- apps/web/components/open-app-button.tsx | 22 +++++++++ apps/web/components/playlist-view.tsx | 2 +- 14 files changed, 279 insertions(+), 12 deletions(-) create mode 100644 apps/mobile/app/+native-intent.ts create mode 100644 apps/mobile/lib/incoming-media-link.ts create mode 100644 apps/mobile/native/MediaLinkShare.kt create mode 100644 apps/mobile/native/MediaLinkShare.swift create mode 100644 apps/web/components/open-app-button.tsx diff --git a/apps/mobile/README.md b/apps/mobile/README.md index 000f86b..110a662 100644 --- a/apps/mobile/README.md +++ b/apps/mobile/README.md @@ -23,3 +23,22 @@ APP_VARIANT=development pnpm start An unset `APP_VARIANT` keeps the production identity. Unknown variants fail configuration. URL schemes are `otunes-development`, `otunes-preview`, and `otunes` respectively, allowing the apps to be installed together. + +### Shared links and artwork + +Shared URLs stay as ordinary HTTPS links. The web page's "Open App" action +opens `otunes://open?url=`, including the server address and +album, artist, or playlist destination. No domain association files, signing +settings, or per-server mobile builds are needed. + +The app checks the link's server against its configured server before opening +media. Links for another server do not switch the current server. On a fresh +installation, the server address is prefilled in setup. The destination is kept +in memory through setup and sign-in, and is opened after authentication. +The browser may ask before opening the app. If the app is absent, the web page +remains available. Native changes still require a new mobile build. + +Native sharing supplies artwork through iOS link metadata and Android's chooser +thumbnail, while sharing the original HTTPS URL. Receiving apps control whether +they display previews. If artwork cannot load, the URL is still shared. Existing +builds without the native sharing module fall back to URL-only sharing. diff --git a/apps/mobile/app/(app)/_layout.tsx b/apps/mobile/app/(app)/_layout.tsx index f393702..327bab9 100644 --- a/apps/mobile/app/(app)/_layout.tsx +++ b/apps/mobile/app/(app)/_layout.tsx @@ -1,3 +1,6 @@ +import { router, usePathname, type Href } from "expo-router" +import { useServerConfig } from "@/contexts/server-config" +import { takeIncomingMediaLink } from "@/lib/incoming-media-link" import { useConvexAuth as useLocalConvexAuth } from "@convex-dev/auth/react" import { useConvexAuth as useServerConvexAuth, @@ -24,6 +27,14 @@ export default function AppLayout() { const { isWebSocketConnected } = useConvexConnectionState() const { invalidateSession } = useInvalidateAuthSession() const stackOptions = useStackScreenOptions() + const { config } = useServerConfig() + const pathname = usePathname() + + useEffect(() => { + if (!config) return + const destination = takeIncomingMediaLink(config.serverUrl) + if (destination) router.replace(destination as Href) + }, [config, pathname]) useEffect(() => { if ( diff --git a/apps/mobile/app/+native-intent.ts b/apps/mobile/app/+native-intent.ts new file mode 100644 index 0000000..5281acb --- /dev/null +++ b/apps/mobile/app/+native-intent.ts @@ -0,0 +1,56 @@ +import { loadServerConfig, parseServerHostname } from "@/lib/server-config" +import { secureGetItem } from "@/lib/auth-storage" +import { rememberIncomingMediaLink } from "@/lib/incoming-media-link" +import { showError } from "@/lib/toast" + +export async function redirectSystemPath({ + path, +}: { + path: string + initial: boolean +}) { + try { + const link = new URL(path, "otunes:///") + if ( + !["otunes:", "otunes-development:", "otunes-preview:"].includes( + link.protocol + ) || + link.hostname !== "open" + ) { + return path + } + + const target = new URL(link.searchParams.get("url") ?? "") + const server = parseServerHostname(target.host) + if ( + !server || + !["https:", "http:"].includes(target.protocol) || + target.username || + target.password || + new URL(server.serverUrl).origin !== target.origin || + !/^\/(album|artist|playlist)\/[a-zA-Z0-9_-]+$/.test(target.pathname) + ) { + return "/" + } + + const config = await loadServerConfig(secureGetItem) + if (config && new URL(config.serverUrl).origin !== target.origin) { + showError("This link belongs to a different oTunes server") + return "/" + } + + const query = new URLSearchParams() + const songId = target.searchParams.get("s") + if (target.pathname.startsWith("/album/") && songId) query.set("s", songId) + const suffix = query.size ? `?${query}` : "" + rememberIncomingMediaLink( + `/(app)/(tabs)/home${target.pathname}${suffix}`, + target.origin + ) + return config + ? "/" + : `/server?hostname=${encodeURIComponent(server.hostname)}` + } catch { + return "/" + } +} diff --git a/apps/mobile/app/index.tsx b/apps/mobile/app/index.tsx index 0a2502f..e922a76 100644 --- a/apps/mobile/app/index.tsx +++ b/apps/mobile/app/index.tsx @@ -1,5 +1,6 @@ import { useConvexAuth } from "@convex-dev/auth/react" -import { Redirect } from "expo-router" +import { incomingMediaLink } from "@/lib/incoming-media-link" +import { Redirect, type Href } from "expo-router" import { useServerConfig } from "@/contexts/server-config" @@ -11,9 +12,16 @@ export default function Index() { return } + const destination = auth?.isAuthenticated + ? incomingMediaLink(config.serverUrl) + : null + return ( ) } diff --git a/apps/mobile/app/server.tsx b/apps/mobile/app/server.tsx index 6433fc3..f7a5ebf 100644 --- a/apps/mobile/app/server.tsx +++ b/apps/mobile/app/server.tsx @@ -1,3 +1,4 @@ +import { useLocalSearchParams } from "expo-router" import { useState } from "react" import { StyleSheet, Text, View } from "react-native" import { SafeAreaView } from "react-native-safe-area-context" @@ -11,7 +12,10 @@ import { spacing, useThemeColors } from "@/lib/theme" export default function ServerScreen() { const colors = useThemeColors() const { setServerHostname } = useServerConfig() - const [hostname, setHostname] = useState("") + const { hostname: linkedHostname } = useLocalSearchParams<{ + hostname?: string + }>() + const [hostname, setHostname] = useState(linkedHostname ?? "") const [error, setError] = useState(null) const [submitting, setSubmitting] = useState(false) diff --git a/apps/mobile/lib/incoming-media-link.ts b/apps/mobile/lib/incoming-media-link.ts new file mode 100644 index 0000000..aac4422 --- /dev/null +++ b/apps/mobile/lib/incoming-media-link.ts @@ -0,0 +1,19 @@ +// Keep the destination while server setup or sign-in is on screen. +let pendingLink: { path: string; serverOrigin: string } | null = null + +export function incomingMediaLink(serverUrl: string) { + if (!pendingLink) return null + return new URL(serverUrl).origin === pendingLink.serverOrigin + ? pendingLink.path + : null +} + +export function takeIncomingMediaLink(serverUrl: string) { + const path = incomingMediaLink(serverUrl) + pendingLink = null + return path +} + +export function rememberIncomingMediaLink(path: string, serverOrigin: string) { + pendingLink = { path, serverOrigin } +} diff --git a/apps/mobile/lib/share-media-link.ts b/apps/mobile/lib/share-media-link.ts index 00c30c5..c62b667 100644 --- a/apps/mobile/lib/share-media-link.ts +++ b/apps/mobile/lib/share-media-link.ts @@ -1,3 +1,4 @@ +import { requireOptionalNativeModule } from "expo" import * as Sharing from "expo-sharing" import { Platform, Share } from "react-native" @@ -5,6 +6,10 @@ import type { MediaShareContext } from "@/lib/media-links" import { mediaShareUrl } from "@/lib/media-links" import { showError } from "@/lib/toast" +const nativeShare = requireOptionalNativeModule<{ + share: (url: string, artwork: string) => Promise +}>("MediaLinkShare") + export async function shareMediaLink( serverUrl: string, share: MediaShareContext @@ -21,9 +26,24 @@ export async function shareMediaLink( return } - await Share.share( - Platform.OS === "ios" ? { url } : { message: url } - ) + if (nativeShare) { + const type = share.type === "song" ? "album" : share.type + const id = + share.type === "album" || share.type === "song" + ? share.albumId + : share.type === "artist" + ? share.artistId + : share.isFavorites + ? "favorites" + : share.playlistId + await nativeShare.share( + url, + `${serverUrl.replace(/\/+$/, "")}/api/${type}/${id}/cover?size=512` + ) + return + } + + await Share.share(Platform.OS === "ios" ? { url } : { message: url }) } catch (error) { if (error instanceof Error && /cancel/i.test(error.message)) { return diff --git a/apps/mobile/native/MediaLinkShare.kt b/apps/mobile/native/MediaLinkShare.kt new file mode 100644 index 0000000..11393fe --- /dev/null +++ b/apps/mobile/native/MediaLinkShare.kt @@ -0,0 +1,44 @@ +package com.abunchofknowitalls.otunes + +import android.content.ClipData +import android.content.Intent +import androidx.core.content.FileProvider +import expo.modules.kotlin.modules.Module +import expo.modules.kotlin.modules.ModuleDefinition +import java.io.File +import java.net.URL + +class MediaLinkShare : Module() { + override fun definition() = ModuleDefinition { + Name("MediaLinkShare") + AsyncFunction("share") { link: String, artwork: String -> + val context = requireNotNull(appContext.reactContext) + val intent = Intent(Intent.ACTION_SEND).apply { + type = "text/plain" + putExtra(Intent.EXTRA_TEXT, link) + } + // ClipData supplies the chooser thumbnail while the shared item stays a URL. + try { + val connection = URL(artwork).openConnection().apply { + connectTimeout = 8000 + readTimeout = 8000 + } + context.cacheDir.listFiles()?.filter { + it.name.startsWith("media-link-cover-") && it.lastModified() < System.currentTimeMillis() - 86400000 + }?.forEach { it.delete() } + val file = File(context.cacheDir, "media-link-cover-${java.util.UUID.randomUUID()}.img") + connection.getInputStream().use { input -> + file.outputStream().use { output -> input.copyTo(output) } + } + val uri = FileProvider.getUriForFile(context, context.packageName + ".SharingFileProvider", file) + intent.clipData = ClipData.newUri(context.contentResolver, "Artwork", uri) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + } catch (_: Exception) { + // A failed artwork download must not prevent sharing the link. + } + appContext.throwingActivity.runOnUiThread { + appContext.throwingActivity.startActivity(Intent.createChooser(intent, "Share")) + } + } + } +} diff --git a/apps/mobile/native/MediaLinkShare.swift b/apps/mobile/native/MediaLinkShare.swift new file mode 100644 index 0000000..add7086 --- /dev/null +++ b/apps/mobile/native/MediaLinkShare.swift @@ -0,0 +1,52 @@ +import UIKit +import LinkPresentation +internal import ExpoModulesCore + +private final class MediaLinkItem: NSObject, UIActivityItemSource { + let url: URL + let image: UIImage? + init(url: URL, image: UIImage?) { + self.url = url + self.image = image + } + func activityViewControllerPlaceholderItem(_ controller: UIActivityViewController) -> Any { url } + func activityViewController(_ controller: UIActivityViewController, itemForActivityType: UIActivity.ActivityType?) -> Any? { url } + func activityViewControllerLinkMetadata(_ controller: UIActivityViewController) -> LPLinkMetadata? { + let metadata = LPLinkMetadata() + metadata.originalURL = url + metadata.url = url + if let image { + metadata.imageProvider = NSItemProvider(object: image) + metadata.iconProvider = NSItemProvider(object: image) + } + return metadata + } +} + +final class MediaLinkShare: Module { + public func definition() -> ExpoModulesCore.ModuleDefinition { + Name("MediaLinkShare") + AsyncFunction("share") { (link: String, artwork: String) in + guard let url = URL(string: link), let artworkURL = URL(string: artwork) else { return } + var image: UIImage? + var request = URLRequest(url: artworkURL) + request.timeoutInterval = 8 + if let (data, response) = try? await URLSession.shared.data(for: request), + (response as? HTTPURLResponse)?.statusCode == 200 { + image = UIImage(data: data) + } + let artworkImage = image + await MainActor.run { + guard let presenter = self.appContext?.utilities?.currentViewController() else { return } + let controller = UIActivityViewController( + activityItems: [MediaLinkItem(url: url, image: artworkImage)], applicationActivities: nil) + if let popover = controller.popoverPresentationController { + popover.sourceView = presenter.view + popover.sourceRect = CGRect(x: presenter.view.bounds.midX, y: presenter.view.bounds.midY, width: 0, height: 0) + popover.permittedArrowDirections = [] + } + presenter.present(controller, animated: true) + } + } + } +} diff --git a/apps/web/components/album-view.tsx b/apps/web/components/album-view.tsx index d819197..ec3ce45 100644 --- a/apps/web/components/album-view.tsx +++ b/apps/web/components/album-view.tsx @@ -389,7 +389,7 @@ export function AlbumView({ return (
- +
diff --git a/apps/web/components/artist-view.tsx b/apps/web/components/artist-view.tsx index a9c3fb5..4b2fbf9 100644 --- a/apps/web/components/artist-view.tsx +++ b/apps/web/components/artist-view.tsx @@ -65,7 +65,7 @@ export function ArtistView({ return (
- +
diff --git a/apps/web/components/library-skeletons.tsx b/apps/web/components/library-skeletons.tsx index 3b76fee..84a5098 100644 --- a/apps/web/components/library-skeletons.tsx +++ b/apps/web/components/library-skeletons.tsx @@ -1,3 +1,4 @@ +import { OpenAppButton } from "@/components/open-app-button" import { MobileSidebarTrigger } from "@/components/mobile-sidebar-trigger" import { Skeleton } from "@/components/ui/skeleton" import { albumGridClassName } from "@/lib/album-grid-classes" @@ -19,16 +20,27 @@ function LoadingRegion({ ) } -export function PageHeader({ title }: { title?: string }) { +export function PageHeader({ + title, + openApp = false, +}: { + title?: string + openApp?: boolean +}) { return (
- {title ?

{title}

: null} + {title ? ( +

{title}

+ ) : openApp ? ( + oTunes + ) : null} + {openApp ? : null}
) } diff --git a/apps/web/components/open-app-button.tsx b/apps/web/components/open-app-button.tsx new file mode 100644 index 0000000..6aa8ec4 --- /dev/null +++ b/apps/web/components/open-app-button.tsx @@ -0,0 +1,22 @@ +"use client" + +import { ArrowUpRight } from "lucide-react" + +export function OpenAppButton() { + function openApp() { + const link = new URL("otunes://open") + link.searchParams.set("url", window.location.href) + window.location.assign(link.href) + } + + return ( + + ) +} diff --git a/apps/web/components/playlist-view.tsx b/apps/web/components/playlist-view.tsx index b0bfbec..1a9a430 100644 --- a/apps/web/components/playlist-view.tsx +++ b/apps/web/components/playlist-view.tsx @@ -519,7 +519,7 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) { return (
- +
-- 2.54.1 From f73a31f7864cf8f76d71f25ba3edc016c2f4a67d Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Tue, 3 Nov 2026 15:33:34 -0500 Subject: [PATCH 2/4] fix(mobile): refresh the server address when opening a link during setup --- apps/mobile/app/server.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/mobile/app/server.tsx b/apps/mobile/app/server.tsx index f7a5ebf..7f9226d 100644 --- a/apps/mobile/app/server.tsx +++ b/apps/mobile/app/server.tsx @@ -1,5 +1,5 @@ import { useLocalSearchParams } from "expo-router" -import { useState } from "react" +import { useEffect, useState } from "react" import { StyleSheet, Text, View } from "react-native" import { SafeAreaView } from "react-native-safe-area-context" @@ -16,6 +16,10 @@ export default function ServerScreen() { hostname?: string }>() const [hostname, setHostname] = useState(linkedHostname ?? "") + useEffect(() => { + if (linkedHostname) setHostname(linkedHostname) + }, [linkedHostname]) + const [error, setError] = useState(null) const [submitting, setSubmitting] = useState(false) -- 2.54.1 From dfc851375e07993f6b4f474a19c3107751c8e8b5 Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Tue, 3 Nov 2026 17:34:38 -0500 Subject: [PATCH 3/4] fix(mobile): handle warm links and show artwork in Android sharing --- apps/mobile/app/(app)/_layout.tsx | 20 ++++++++++++++------ apps/mobile/app/+native-intent.ts | 8 +++----- apps/mobile/lib/incoming-media-link.ts | 11 +++++++++++ apps/mobile/native/MediaLinkShare.kt | 10 +++++++++- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/apps/mobile/app/(app)/_layout.tsx b/apps/mobile/app/(app)/_layout.tsx index 327bab9..34df800 100644 --- a/apps/mobile/app/(app)/_layout.tsx +++ b/apps/mobile/app/(app)/_layout.tsx @@ -1,6 +1,10 @@ -import { router, usePathname, type Href } from "expo-router" +import { router, type Href } from "expo-router" import { useServerConfig } from "@/contexts/server-config" -import { takeIncomingMediaLink } from "@/lib/incoming-media-link" +import { + incomingMediaLink, + subscribeIncomingMediaLink, + takeIncomingMediaLink, +} from "@/lib/incoming-media-link" import { useConvexAuth as useLocalConvexAuth } from "@convex-dev/auth/react" import { useConvexAuth as useServerConvexAuth, @@ -8,7 +12,7 @@ import { } from "convex/react" import { Stack } from "expo-router" import { Platform } from "react-native" -import { useEffect } from "react" +import { useEffect, useSyncExternalStore } from "react" import { AppIntentBridge } from "@/components/app-intent-bridge" import { ConvexAuthRecovery } from "@/components/convex-auth-recovery" @@ -28,13 +32,17 @@ export default function AppLayout() { const { invalidateSession } = useInvalidateAuthSession() const stackOptions = useStackScreenOptions() const { config } = useServerConfig() - const pathname = usePathname() + const pendingDestination = useSyncExternalStore( + subscribeIncomingMediaLink, + () => (config ? incomingMediaLink(config.serverUrl) : null), + () => null + ) useEffect(() => { - if (!config) return + if (!config || !pendingDestination) return const destination = takeIncomingMediaLink(config.serverUrl) if (destination) router.replace(destination as Href) - }, [config, pathname]) + }, [config, pendingDestination]) useEffect(() => { if ( diff --git a/apps/mobile/app/+native-intent.ts b/apps/mobile/app/+native-intent.ts index 5281acb..62f3efb 100644 --- a/apps/mobile/app/+native-intent.ts +++ b/apps/mobile/app/+native-intent.ts @@ -43,12 +43,10 @@ export async function redirectSystemPath({ const songId = target.searchParams.get("s") if (target.pathname.startsWith("/album/") && songId) query.set("s", songId) const suffix = query.size ? `?${query}` : "" - rememberIncomingMediaLink( - `/(app)/(tabs)/home${target.pathname}${suffix}`, - target.origin - ) + const destination = `/(app)/(tabs)/home${target.pathname}${suffix}` + rememberIncomingMediaLink(destination, target.origin) return config - ? "/" + ? destination : `/server?hostname=${encodeURIComponent(server.hostname)}` } catch { return "/" diff --git a/apps/mobile/lib/incoming-media-link.ts b/apps/mobile/lib/incoming-media-link.ts index aac4422..e2a59be 100644 --- a/apps/mobile/lib/incoming-media-link.ts +++ b/apps/mobile/lib/incoming-media-link.ts @@ -1,4 +1,13 @@ // Keep the destination while server setup or sign-in is on screen. +const listeners = new Set<() => void>() + +export function subscribeIncomingMediaLink(listener: () => void) { + listeners.add(listener) + return () => { + listeners.delete(listener) + } +} + let pendingLink: { path: string; serverOrigin: string } | null = null export function incomingMediaLink(serverUrl: string) { @@ -11,9 +20,11 @@ export function incomingMediaLink(serverUrl: string) { export function takeIncomingMediaLink(serverUrl: string) { const path = incomingMediaLink(serverUrl) pendingLink = null + for (const listener of listeners) listener() return path } export function rememberIncomingMediaLink(path: string, serverOrigin: string) { pendingLink = { path, serverOrigin } + for (const listener of listeners) listener() } diff --git a/apps/mobile/native/MediaLinkShare.kt b/apps/mobile/native/MediaLinkShare.kt index 11393fe..a6a6c41 100644 --- a/apps/mobile/native/MediaLinkShare.kt +++ b/apps/mobile/native/MediaLinkShare.kt @@ -16,6 +16,7 @@ class MediaLinkShare : Module() { val intent = Intent(Intent.ACTION_SEND).apply { type = "text/plain" putExtra(Intent.EXTRA_TEXT, link) + putExtra(Intent.EXTRA_TITLE, "oTunes") } // ClipData supplies the chooser thumbnail while the shared item stays a URL. try { @@ -26,7 +27,14 @@ class MediaLinkShare : Module() { context.cacheDir.listFiles()?.filter { it.name.startsWith("media-link-cover-") && it.lastModified() < System.currentTimeMillis() - 86400000 }?.forEach { it.delete() } - val file = File(context.cacheDir, "media-link-cover-${java.util.UUID.randomUUID()}.img") + val extension = when (connection.contentType?.substringBefore(";")) { + "image/webp" -> "webp" + "image/png" -> "png" + "image/jpeg" -> "jpg" + "image/gif" -> "gif" + else -> error("Artwork format is not supported") + } + val file = File(context.cacheDir, "media-link-cover-${java.util.UUID.randomUUID()}.${extension}") connection.getInputStream().use { input -> file.outputStream().use { output -> input.copyTo(output) } } -- 2.54.1 From 7d2a2cc4d5b4a0ab0c476f098c8c7f5354ccff10 Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Tue, 3 Nov 2026 21:02:36 -0500 Subject: [PATCH 4/4] feat(mobile): include media names in share previews --- apps/mobile/README.md | 2 +- apps/mobile/app/(app)/(tabs)/home/album/[id].tsx | 3 ++- apps/mobile/app/(app)/(tabs)/home/artist/[id].tsx | 6 +++++- .../mobile/app/(app)/(tabs)/home/browse/artists.tsx | 2 +- apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx | 2 ++ apps/mobile/components/media-cards.tsx | 10 +++++++--- apps/mobile/components/player.tsx | 1 + apps/mobile/lib/media-links.ts | 3 ++- apps/mobile/lib/share-media-link.ts | 13 +++++++++---- apps/mobile/native/MediaLinkShare.kt | 5 +++-- apps/mobile/native/MediaLinkShare.swift | 9 ++++++--- 11 files changed, 39 insertions(+), 17 deletions(-) diff --git a/apps/mobile/README.md b/apps/mobile/README.md index 110a662..7fb65bd 100644 --- a/apps/mobile/README.md +++ b/apps/mobile/README.md @@ -38,7 +38,7 @@ in memory through setup and sign-in, and is opened after authentication. The browser may ask before opening the app. If the app is absent, the web page remains available. Native changes still require a new mobile build. -Native sharing supplies artwork through iOS link metadata and Android's chooser +Native sharing supplies media titles and artwork through iOS link metadata and Android's chooser thumbnail, while sharing the original HTTPS URL. Receiving apps control whether they display previews. If artwork cannot load, the URL is still shared. Existing builds without the native sharing module fall back to URL-only sharing. diff --git a/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx b/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx index 9c8dbf2..c1de515 100644 --- a/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx +++ b/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx @@ -186,7 +186,7 @@ export default function AlbumScreen() { stationArtistId={album.artist.id} selectedCount={album.tracks.length} favorited={isAlbumFav(album.id)} - share={{ type: "album", albumId: album.id }} + share={{ type: "album", albumId: album.id, title: album.title }} onAction={(action) => void handleAlbumDetailAction( album.id as Id<"albums">, @@ -406,6 +406,7 @@ const AlbumTrackRow = memo(function AlbumTrackRow({ type: "song", albumId: album.id, songId: track.id, + title: `${track.title} - ${album.title}`, }} onAction={(action) => void onAction(track, album, action)} > diff --git a/apps/mobile/app/(app)/(tabs)/home/artist/[id].tsx b/apps/mobile/app/(app)/(tabs)/home/artist/[id].tsx index bf9f835..ef90e47 100644 --- a/apps/mobile/app/(app)/(tabs)/home/artist/[id].tsx +++ b/apps/mobile/app/(app)/(tabs)/home/artist/[id].tsx @@ -75,7 +75,11 @@ export default function ArtistScreen() { void handleArtistAction(data.artist, action) } diff --git a/apps/mobile/app/(app)/(tabs)/home/browse/artists.tsx b/apps/mobile/app/(app)/(tabs)/home/browse/artists.tsx index 42999a1..260a1c8 100644 --- a/apps/mobile/app/(app)/(tabs)/home/browse/artists.tsx +++ b/apps/mobile/app/(app)/(tabs)/home/browse/artists.tsx @@ -142,7 +142,7 @@ const ArtistRow = memo(function ArtistRow({ return ( void onAction(artist, action)} > void handleAlbumAction(album, action)} > @@ -125,7 +125,7 @@ export const ArtistCard = memo(function ArtistCard({ return ( void handleArtistAction(artist, action)} > @@ -176,7 +176,11 @@ export const PlaylistCard = memo(function PlaylistCard({ return ( void handlePlaylistAction(playlist, action)} > diff --git a/apps/mobile/components/player.tsx b/apps/mobile/components/player.tsx index 25dc922..2d074ad 100644 --- a/apps/mobile/components/player.tsx +++ b/apps/mobile/components/player.tsx @@ -147,6 +147,7 @@ export const SongListRow = memo(function SongListRow({ type: "song", albumId: song.album.id, songId: song.id, + title: `${song.title} - ${song.album.title}`, }, onAction: (action) => onAction(song, action), }} diff --git a/apps/mobile/lib/media-links.ts b/apps/mobile/lib/media-links.ts index a87be1e..d04d8b3 100644 --- a/apps/mobile/lib/media-links.ts +++ b/apps/mobile/lib/media-links.ts @@ -1,8 +1,9 @@ -export type MediaShareContext = +export type MediaShareContext = ( | { type: "album"; albumId: string } | { type: "song"; albumId: string; songId: string } | { type: "playlist"; playlistId: string; isFavorites?: boolean } | { type: "artist"; artistId: string } +) & { title: string } export function shouldShowShare( share: MediaShareContext | undefined, diff --git a/apps/mobile/lib/share-media-link.ts b/apps/mobile/lib/share-media-link.ts index c62b667..076992b 100644 --- a/apps/mobile/lib/share-media-link.ts +++ b/apps/mobile/lib/share-media-link.ts @@ -7,7 +7,7 @@ import { mediaShareUrl } from "@/lib/media-links" import { showError } from "@/lib/toast" const nativeShare = requireOptionalNativeModule<{ - share: (url: string, artwork: string) => Promise + share: (url: string, artwork: string, title: string) => Promise }>("MediaLinkShare") export async function shareMediaLink( @@ -22,7 +22,7 @@ export async function shareMediaLink( showError("Sharing is not available on this device") return } - await Sharing.shareAsync(url, { dialogTitle: "Share" }) + await Sharing.shareAsync(url, { dialogTitle: share.title }) return } @@ -38,12 +38,17 @@ export async function shareMediaLink( : share.playlistId await nativeShare.share( url, - `${serverUrl.replace(/\/+$/, "")}/api/${type}/${id}/cover?size=512` + `${serverUrl.replace(/\/+$/, "")}/api/${type}/${id}/cover?size=512`, + share.title ) return } - await Share.share(Platform.OS === "ios" ? { url } : { message: url }) + await Share.share( + Platform.OS === "ios" + ? { url, title: share.title } + : { message: url, title: share.title } + ) } catch (error) { if (error instanceof Error && /cancel/i.test(error.message)) { return diff --git a/apps/mobile/native/MediaLinkShare.kt b/apps/mobile/native/MediaLinkShare.kt index a6a6c41..0937c67 100644 --- a/apps/mobile/native/MediaLinkShare.kt +++ b/apps/mobile/native/MediaLinkShare.kt @@ -11,12 +11,13 @@ import java.net.URL class MediaLinkShare : Module() { override fun definition() = ModuleDefinition { Name("MediaLinkShare") - AsyncFunction("share") { link: String, artwork: String -> + AsyncFunction("share") { link: String, artwork: String, title: String -> val context = requireNotNull(appContext.reactContext) val intent = Intent(Intent.ACTION_SEND).apply { type = "text/plain" putExtra(Intent.EXTRA_TEXT, link) - putExtra(Intent.EXTRA_TITLE, "oTunes") + putExtra(Intent.EXTRA_TITLE, title) + putExtra(Intent.EXTRA_SUBJECT, title) } // ClipData supplies the chooser thumbnail while the shared item stays a URL. try { diff --git a/apps/mobile/native/MediaLinkShare.swift b/apps/mobile/native/MediaLinkShare.swift index add7086..0a91454 100644 --- a/apps/mobile/native/MediaLinkShare.swift +++ b/apps/mobile/native/MediaLinkShare.swift @@ -5,9 +5,11 @@ internal import ExpoModulesCore private final class MediaLinkItem: NSObject, UIActivityItemSource { let url: URL let image: UIImage? - init(url: URL, image: UIImage?) { + let title: String + init(url: URL, image: UIImage?, title: String) { self.url = url self.image = image + self.title = title } func activityViewControllerPlaceholderItem(_ controller: UIActivityViewController) -> Any { url } func activityViewController(_ controller: UIActivityViewController, itemForActivityType: UIActivity.ActivityType?) -> Any? { url } @@ -15,6 +17,7 @@ private final class MediaLinkItem: NSObject, UIActivityItemSource { let metadata = LPLinkMetadata() metadata.originalURL = url metadata.url = url + metadata.title = title if let image { metadata.imageProvider = NSItemProvider(object: image) metadata.iconProvider = NSItemProvider(object: image) @@ -26,7 +29,7 @@ private final class MediaLinkItem: NSObject, UIActivityItemSource { final class MediaLinkShare: Module { public func definition() -> ExpoModulesCore.ModuleDefinition { Name("MediaLinkShare") - AsyncFunction("share") { (link: String, artwork: String) in + AsyncFunction("share") { (link: String, artwork: String, title: String) in guard let url = URL(string: link), let artworkURL = URL(string: artwork) else { return } var image: UIImage? var request = URLRequest(url: artworkURL) @@ -39,7 +42,7 @@ final class MediaLinkShare: Module { await MainActor.run { guard let presenter = self.appContext?.utilities?.currentViewController() else { return } let controller = UIActivityViewController( - activityItems: [MediaLinkItem(url: url, image: artworkImage)], applicationActivities: nil) + activityItems: [MediaLinkItem(url: url, image: artworkImage, title: title)], applicationActivities: nil) if let popover = controller.popoverPresentationController { popover.sourceView = presenter.view popover.sourceRect = CGRect(x: presenter.view.bounds.midX, y: presenter.view.bounds.midY, width: 0, height: 0) -- 2.54.1