diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 6bbbaea5e3..d7739fd5e6 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -130,6 +130,13 @@ configure { // WeaselFin: base name of the release asset the updater looks for, and of the // downloaded APK. Upstream's own name here so every upstream flavor is unchanged. buildConfigField("String", "UPDATE_ASSET_NAME", "\"Wholphin\"") + + // WeaselFin: where a phone can approve this TV's Quick Connect code ("Sign in with + // theweasel.tv"). Blank for every upstream flavor, which keeps the plain code dialog; + // only `weaselfin` overrides it, and the dialog shows a QR code when it is set. + buildConfigField("String", "QUICK_CONNECT_APPROVE_URL", "\"\"") + // The short address shown next to the QR code for typing it by hand. + buildConfigField("String", "QUICK_CONNECT_APPROVE_LABEL", "\"\"") } signingConfigs { @@ -258,6 +265,12 @@ configure { buildConfigField("String", "DEFAULT_SERVER_URL", "\"https://media.theweasel.tv\"") buildConfigField("String", "UPDATE_REPO", "\"Weaseltv/Wholphin\"") buildConfigField("String", "DEFAULT_SEERR_URL", "\"https://requests.theweasel.tv\"") + buildConfigField( + "String", + "QUICK_CONNECT_APPROVE_URL", + "\"https://theweasel.tv/weaselplex/connect\"", + ) + buildConfigField("String", "QUICK_CONNECT_APPROVE_LABEL", "\"theweasel.tv/plex\"") buildConfigField("String", "DEFAULT_THEME", "\"WEASELTV\"") // 🛑 Deliberately still "WeaselFin" (ruling R5, 2026-08-25). The in-app updater // matches the GitHub release asset by FILENAME, so renaming this and the assets @@ -446,6 +459,9 @@ dependencies { implementation(libs.jellyfin.api) implementation(libs.jellyfin.api.okhttp) + // QR code for "Sign in with theweasel.tv" in the Quick Connect dialog (pure Java). + implementation(libs.zxing.core) + implementation(libs.androidx.navigation3.ui) implementation(libs.androidx.navigation3.runtime) implementation(libs.androidx.lifecycle.viewmodel.navigation3) diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/BaseItem.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/BaseItem.kt index dd1236a49d..eefb001b80 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/BaseItem.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/BaseItem.kt @@ -237,21 +237,30 @@ data class BaseItem( // Redirect episodes & seasons to their series if possible when (type) { BaseItemKind.EPISODE -> { - data.seasonId?.let { seasonId -> + val seasonId = data.seasonId + val seriesId = data.seriesId + if (seasonId != null && seriesId != null) { Destination.SeriesOverview( - data.seriesId!!, + seriesId, BaseItemKind.SERIES, SeasonEpisodeIds(seasonId, data.parentIndexNumber, id, indexNumber), ) - } ?: Destination.MediaItem(this) + } else { + Destination.MediaItem(this) + } } BaseItemKind.SEASON -> { - Destination.SeriesOverview( - data.seriesId!!, - BaseItemKind.SERIES, - SeasonEpisodeIds(id, indexNumber, null, null), - ) + val seriesId = data.seriesId + if (seriesId != null) { + Destination.SeriesOverview( + seriesId, + BaseItemKind.SERIES, + SeasonEpisodeIds(id, indexNumber, null, null), + ) + } else { + Destination.MediaItem(this) + } } BaseItemKind.TV_CHANNEL -> { diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/detail/series/SeriesViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/detail/series/SeriesViewModel.kt index cb2146df38..2b92f71b0d 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/detail/series/SeriesViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/detail/series/SeriesViewModel.kt @@ -124,10 +124,18 @@ class SeriesViewModel Timber.v("Start") addCloseable { themeSongPlayer.stop() } val series = - api.userLibraryApi - .getItem(seriesId) - .content - .let { BaseItem(it) } + try { + api.userLibraryApi + .getItem(seriesId) + .content + .let { BaseItem(it) } + } catch (ex: CancellationException) { + throw ex + } catch (ex: Exception) { + Timber.e(ex, "Error fetching series %s", seriesId) + _state.update { it.copy(series = DataLoadingState.Error(ex)) } + return@launchIO + } viewModelScope.launchDefault { mediaManagementService.collectCanDelete(flowOf(series)) { canDelete -> _state.update { it.copy(canDeleteSeries = canDelete) } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/setup/QuickConnectQrCode.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/setup/QuickConnectQrCode.kt new file mode 100644 index 0000000000..9e50cb2c6b --- /dev/null +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/setup/QuickConnectQrCode.kt @@ -0,0 +1,72 @@ +package com.github.damontecres.wholphin.ui.setup + +import android.graphics.Bitmap +import android.graphics.Color +import android.net.Uri +import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.size +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.asImageBitmap +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import com.github.damontecres.wholphin.BuildConfig +import com.google.zxing.BarcodeFormat +import com.google.zxing.EncodeHintType +import com.google.zxing.qrcode.QRCodeWriter +import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel + +/** + * The page a phone opens to approve this TV's Quick Connect [code], or null when the flavor has + * no approve page (every upstream flavor) or there is no code yet. The web page signs the + * customer in with their website account and approves the code; the TV keeps polling as usual. + */ +fun quickConnectApproveUrl(code: String?): String? { + val base = BuildConfig.QUICK_CONNECT_APPROVE_URL + if (base.isBlank() || code.isNullOrBlank()) return null + return "$base?code=${Uri.encode(code)}&device=tv" +} + +/** + * A QR code for [content], black on white so a phone camera reads it off a TV screen. + */ +@Composable +fun QrCode( + content: String, + modifier: Modifier = Modifier, + size: Dp = 200.dp, +) { + val bitmap = remember(content) { renderQrCode(content, QR_PIXELS) } + Image( + bitmap = bitmap.asImageBitmap(), + contentDescription = null, + contentScale = ContentScale.Fit, + modifier = modifier.size(size), + ) +} + +private const val QR_PIXELS = 512 + +internal fun renderQrCode( + content: String, + pixels: Int, +): Bitmap { + val hints = + mapOf( + EncodeHintType.ERROR_CORRECTION to ErrorCorrectionLevel.M, + EncodeHintType.MARGIN to 2, + ) + val matrix = QRCodeWriter().encode(content, BarcodeFormat.QR_CODE, pixels, pixels, hints) + val width = matrix.width + val height = matrix.height + val colors = IntArray(width * height) + for (y in 0 until height) { + val row = y * width + for (x in 0 until width) { + colors[row + x] = if (matrix[x, y]) Color.BLACK else Color.WHITE + } + } + return Bitmap.createBitmap(colors, width, height, Bitmap.Config.RGB_565) +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/setup/SwitchUserContent.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/setup/SwitchUserContent.kt index b2ae63cc6b..41f3ab17dd 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/setup/SwitchUserContent.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/setup/SwitchUserContent.kt @@ -39,6 +39,7 @@ import androidx.compose.ui.window.DialogProperties import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel import androidx.tv.material3.MaterialTheme import androidx.tv.material3.Text +import com.github.damontecres.wholphin.BuildConfig import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.data.model.JellyfinServer import com.github.damontecres.wholphin.data.model.JellyfinUser @@ -286,13 +287,34 @@ fun SwitchUserContent( ) } } else if (state.quickConnectStatus != null) { - Text( - text = "Use Quick Connect on your device to authenticate to ${server.name ?: server.url}", - style = MaterialTheme.typography.titleMedium, - color = MaterialTheme.colorScheme.onSurface, - textAlign = TextAlign.Center, - modifier = Modifier.fillMaxWidth(), - ) + val approveUrl = quickConnectApproveUrl(state.quickConnectStatus?.code) + if (approveUrl != null) { + // WeaselFin: the phone scans this, signs in with the website account + // and approves the code. Typing the code on theweasel.tv/plex works too. + Text( + text = + stringResource( + R.string.quick_connect_scan_hint, + BuildConfig.QUICK_CONNECT_APPROVE_LABEL, + ), + style = MaterialTheme.typography.titleMedium, + color = MaterialTheme.colorScheme.onSurface, + textAlign = TextAlign.Center, + modifier = Modifier.fillMaxWidth(), + ) + QrCode( + content = approveUrl, + modifier = Modifier.align(Alignment.CenterHorizontally), + ) + } else { + Text( + text = "Use Quick Connect on your device to authenticate to ${server.name ?: server.url}", + style = MaterialTheme.typography.titleMedium, + color = MaterialTheme.colorScheme.onSurface, + textAlign = TextAlign.Center, + modifier = Modifier.fillMaxWidth(), + ) + } Text( text = state.quickConnectStatus?.code ?: "Failed to get code", style = MaterialTheme.typography.displayMedium, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/setup/SwitchUserViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/setup/SwitchUserViewModel.kt index c47b86c54d..68ec53fc58 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/setup/SwitchUserViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/setup/SwitchUserViewModel.kt @@ -208,7 +208,8 @@ class SwitchUserViewModel _state.update { it.copy(quickConnectStatus = quickConnectStatus) } while (!quickConnectStatus.authenticated) { - delay(5_000L) + // Two seconds so a phone-approved code signs the TV in promptly. + delay(2_000L) quickConnectStatus = api.quickConnectApi .getQuickConnectState( diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3db492ef86..160c3c659e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -507,6 +507,7 @@ Enter Quick Connect code Code must be 6 digits Device authorized successfully + Scan with your phone, or go to %1$s and enter the code Password Username URL diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e7c6ca9287..3a2604644c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -27,6 +27,7 @@ activityCompose = "1.13.0" androidx-media3 = "1.11.1" coil = "3.6.2" jellyfin-sdk = "1.7.1" +zxing = "3.5.3" nav3Core = "1.1.7" lifecycleViewmodelNav3 = "2.11.0" material3AdaptiveNav3 = "1.3.0" @@ -124,6 +125,7 @@ coil-gif = { module = "io.coil-kt.coil3:coil-gif", version.ref = "coil" } coil-svg = { module = "io.coil-kt.coil3:coil-svg", version.ref = "coil" } jellyfin-core = { module = "org.jellyfin.sdk:jellyfin-core", version.ref = "jellyfin-sdk" } +zxing-core = { module = "com.google.zxing:core", version.ref = "zxing" } jellyfin-api = { module = "org.jellyfin.sdk:jellyfin-api", version.ref = "jellyfin-sdk" } jellyfin-api-okhttp = { module = "org.jellyfin.sdk:jellyfin-api-okhttp-jvm", version.ref = "jellyfin-sdk" }