Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ configure<ApplicationExtension> {
// 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 {
Expand Down Expand Up @@ -258,6 +265,12 @@ configure<ApplicationExtension> {
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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@
<string name="quick_connect_code">Enter Quick Connect code</string>
<string name="quick_connect_code_error">Code must be 6 digits</string>
<string name="quick_connect_success">Device authorized successfully</string>
<string name="quick_connect_scan_hint">Scan with your phone, or go to %1$s and enter the code</string>
<string name="password">Password</string>
<string name="username">Username</string>
<string name="url">URL</string>
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" }

Expand Down
Loading