Skip to content
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
f02f66c
WIP
damontecres Apr 30, 2026
a27bb2a
Option to load from server plugin
damontecres May 13, 2026
3f8dfac
Update unit test
damontecres May 13, 2026
af75b2e
Merge branch 'main' into develop/server-plugin
damontecres May 23, 2026
4901c8d
Merge branch 'main' into develop/server-plugin
damontecres May 27, 2026
20547fe
Merge branch 'main' into develop/server-plugin
damontecres May 31, 2026
6207c3a
WIP broken
damontecres May 31, 2026
bdaa6d5
Add CustomEndpoint home row
matschi95 Jun 1, 2026
d968c84
Address custom endpoint review comments
matschi95 Jun 1, 2026
23b6570
Fix custom endpoint compile errors
matschi95 Jun 1, 2026
a50b07a
Require relative custom endpoints
matschi95 Jun 1, 2026
bf9e0e5
Choose home settings source
damontecres Jun 2, 2026
f379224
Fix ktlint formatting
matschi95 Jun 10, 2026
144cbae
Merge branch 'main' into develop/server-plugin
damontecres Jun 18, 2026
8ba8d7f
Merge branch 'develop/server-plugin' into develop/server-plugin-custo…
damontecres Jun 21, 2026
6eaa5c2
Auto-configure Seerr from Wholphin server plugin
matschi95 Jun 23, 2026
01a438d
Remove automatic Seerr Jellyfin plugin auth
matschi95 Jun 23, 2026
324eaeb
Address Seerr plugin review feedback
matschi95 Jun 28, 2026
a98634c
Merge branch 'main' into develop/server-plugin
damontecres Jul 9, 2026
6f82997
Merge branch 'main' into develop/server-plugin
damontecres Jul 29, 2026
6fcc77e
Merge branch 'main' into develop/server-plugin
damontecres Aug 13, 2026
3a34d59
Merge branch 'main' into develop/server-plugin
damontecres Oct 1, 2026
98afcde
Update unit tests
damontecres Oct 1, 2026
73b9d20
Handle discarding changes
damontecres Oct 1, 2026
b59e511
Add logging & track source better
damontecres Oct 2, 2026
f682d04
Tweaks to get items row
damontecres Oct 2, 2026
2874841
Naming & javadocs
damontecres Oct 2, 2026
368b350
Code clean up
damontecres Oct 3, 2026
6e88f98
Update unit tests
damontecres Oct 3, 2026
48628db
Split home row data fetching into HomeDataService
damontecres Oct 3, 2026
947528a
Merge branch 'develop/server-plugin' into develop/server-plugin-custo…
damontecres Oct 4, 2026
f8e0a21
Stricter endpoint checking & simplify code
damontecres Oct 4, 2026
11ba5fe
Fix unit tests
damontecres Oct 4, 2026
4be3c68
Add CustomEndpoint home row (#1430)
damontecres Oct 12, 2026
ff329ef
Merge branch 'develop/server-plugin' into develop/server-plugin-seerr
damontecres Oct 12, 2026
584ccf4
Minor context change
damontecres Oct 12, 2026
d7f8efa
Merge branch 'main' into develop/server-plugin
damontecres Oct 19, 2026
c3762d5
Merge branch 'develop/server-plugin' into develop/server-plugin-seerr
damontecres Oct 19, 2026
b96f991
Focus fixes
damontecres Oct 19, 2026
f7c14cf
Merge branch 'main' into develop/server-plugin-seerr
damontecres Oct 19, 2026
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
727 changes: 727 additions & 0 deletions app/schemas/com.github.damontecres.wholphin.data.AppDatabase/40.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import java.util.UUID
SeerrUser::class,
RememberedTab::class,
],
version = 34,
version = 40,
exportSchema = true,
autoMigrations = [
AutoMigration(3, 4),
Expand All @@ -67,6 +67,7 @@ import java.util.UUID
AutoMigration(31, 32),
AutoMigration(32, 33),
AutoMigration(33, 34),
AutoMigration(34, 40),
],
)
@TypeConverters(Converters::class)
Expand Down Expand Up @@ -141,6 +142,12 @@ class Converters {

@TypeConverter
fun convertToLocalDateTime(dateTime: String): ZonedDateTime = ZonedDateTime.parse(dateTime, DateTimeFormatter.ISO_ZONED_DATE_TIME)

// @TypeConverter
// fun convertToHomePageSettingsSource(str: String): HomePageSettingsSource = HomePageSettingsSource.valueOf(str)
//
// @TypeConverter
// fun convertHomePageSettingsSource(value: HomePageSettingsSource): String = value.name
}

class ZonedDateTimeSerializer : KSerializer<ZonedDateTime> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class ServerRepository
val currentUser: JellyfinUser? get() = _current.value?.user
val currentUserFlow: Flow<JellyfinUser?> get() = _current.map { it?.user }

val serverPluginInstalled = MutableStateFlow<Boolean>(false)

/**
* Adds a server to the app database and updated the [ApiClient] to the server's URL
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.room.Index
import androidx.room.PrimaryKey
import androidx.room.Relation
import com.github.damontecres.wholphin.data.ZonedDateTimeSerializer
import com.github.damontecres.wholphin.services.HomePageSettingsSource
import com.github.damontecres.wholphin.ui.isNotNullOrBlank
import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers
Expand Down Expand Up @@ -65,13 +66,22 @@ data class JellyfinUser(
val requireLogin: Boolean = false,
val lastUsed: ZonedDateTime? = null,
val uiLanguage: String? = null,
@Embedded(prefix = "c_") val config: JellyfinUserConfig = JellyfinUserConfig(),
) {
val hasPin: Boolean get() = pin.isNotNullOrBlank()

override fun toString(): String =
"JellyfinUser(rowId=$rowId, id=$id, name=$name, serverId=$serverId, lastUsed=$lastUsed, accessToken?=${accessToken.isNotNullOrBlank()}, pin?=${pin.isNotNullOrBlank()})"

fun updateConfig(copy: (JellyfinUserConfig) -> JellyfinUserConfig): JellyfinUser = this.copy(config = copy.invoke(this.config))
}

@Serializable
data class JellyfinUserConfig(
@ColumnInfo(defaultValue = "UNSET")
val homeSettingsSource: HomePageSettingsSource = HomePageSettingsSource.UNSET,
)

/**
* Represents the relationship between [JellyfinServer] and its [JellyfinUser]
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.github.damontecres.wholphin.data.model

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
enum class SeerrPluginLoginType {
Comment thread
matschi95 marked this conversation as resolved.
Resolved
@SerialName("None")
NONE,

@SerialName("ApiKey")
API_KEY,

@SerialName("Local")
LOCAL,
}

@Serializable
data class SeerrPluginLocalLogin(
val username: String? = null,
val password: String? = null,
)

@Serializable
data class SeerrPluginLogin(
val type: SeerrPluginLoginType = SeerrPluginLoginType.NONE,
val apiKey: String? = null,
val local: SeerrPluginLocalLogin? = null,
)

@Serializable
data class SeerrPluginSettings(
val version: Int = 1,
val serverUrl: String? = null,
val login: SeerrPluginLogin? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package com.github.damontecres.wholphin.services
import android.content.Context
import androidx.annotation.StringRes
import com.github.damontecres.wholphin.R
import com.github.damontecres.wholphin.data.JellyfinServerDao
import com.github.damontecres.wholphin.data.ServerRepository
import com.github.damontecres.wholphin.data.model.BaseItem
import com.github.damontecres.wholphin.data.model.HomePageSettings
import com.github.damontecres.wholphin.data.model.HomeRowConfig
import com.github.damontecres.wholphin.data.model.JellyfinUser
import com.github.damontecres.wholphin.data.model.SUPPORTED_HOME_PAGE_SETTINGS_VERSION
import com.github.damontecres.wholphin.data.model.createGenreDestination
import com.github.damontecres.wholphin.data.model.createStudioDestination
Expand Down Expand Up @@ -38,6 +40,7 @@ import com.github.damontecres.wholphin.util.HomeRowLoadingState
import com.github.damontecres.wholphin.util.HomeRowLoadingState.Success
import com.github.damontecres.wholphin.util.supportedHomeCollectionTypes
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.firstOrNull
Expand Down Expand Up @@ -87,7 +90,9 @@ class HomeSettingsService
constructor(
@param:ApplicationContext private val context: Context,
private val api: ApiClient,
private val serverPluginApi: ServerPluginApi,
private val serverRepository: ServerRepository,
private val serverDao: JellyfinServerDao,
private val userPreferencesService: UserPreferencesService,
private val navDrawerService: NavDrawerService,
private val latestNextUpService: LatestNextUpService,
Expand Down Expand Up @@ -207,59 +212,99 @@ class HomeSettingsService
return HomePageSettings(rows, version)
}

private suspend fun tryLoad(block: suspend () -> HomePageSettings?): HomePageSettings? =
try {
block.invoke()
} catch (ex: Exception) {
Timber.w(ex, "Error loading settings")
null
}

suspend fun fetchSettingsFor(
userId: UUID,
source: HomePageSettingsSource,
): HomePageResolvedSettings? {
val settings =
when (source) {
HomePageSettingsSource.UNSET -> loadInOrder(userId)
HomePageSettingsSource.LOCAL -> loadFromLocal(userId)
HomePageSettingsSource.SERVER_PROFILE -> loadFromServer(userId)
HomePageSettingsSource.PLUGIN -> serverPluginApi.fetchHomePageSettings()
}
return settings?.let {
val resolvedRows =
settings.rows.mapIndexed { index, config ->
resolve(index, config)
}
HomePageResolvedSettings(resolvedRows)
}
}

/**
* Loads [HomePageSettings] into [currentSettings]
*
* First checks locally, then on the server, and finally creates a default if needed
*
* Does not persist either the server nor default
* Loads [HomePageSettings] into [currentSettings] based on the user's config
*/
suspend fun loadCurrentSettings(userId: UUID) {
Timber.v("Getting setting for %s", userId)
// User local then server/remote otherwise create a default
suspend fun loadCurrentSettings(user: JellyfinUser) {
currentSettings.update { HomePageResolvedSettings.EMPTY }

Timber.v("Getting setting for %s", user.id)
val settings =
try {
val local = loadFromLocal(userId)
Timber.v("Found local? %s", local != null)
local
} catch (ex: Exception) {
Timber.w(ex, "Error loading local settings")
// TODO show toast?
null
} ?: try {
val remote = loadFromServer(userId)
Timber.v("Found remote? %s", remote != null)
remote
fetchSettingsFor(user.id, user.config.homeSettingsSource)
} catch (ex: CancellationException) {
throw ex
} catch (ex: Exception) {
Timber.w(ex, "Error loading remote settings")
Timber.e(ex, "Error loading settings for %s", user.config.homeSettingsSource)
null
}
val resolvedSettings =
if (settings != null) {
Timber.v("Found settings")
// Resolve
val resolvedRows =
settings.rows.mapIndexed { index, config ->
resolve(index, config)
}
HomePageResolvedSettings(resolvedRows)
} else {
createDefault(userId)
}
if (settings != null) {
Timber.v("Found settings")
}

val resolvedSettings = settings ?: createDefault(user.id)
currentSettings.update { resolvedSettings }
}

/**
* Tries to load settings from local->server->plugin
*/
private suspend fun loadInOrder(userId: UUID): HomePageSettings? {
var settings =
tryLoad {
loadFromLocal(userId)
}

if (settings == null) {
settings =
tryLoad {
loadFromServer(userId)
}
}

if (settings == null) {
settings =
tryLoad {
serverPluginApi.fetchHomePageSettings()
}
}
return settings
}

/**
* Resolve the settings and set them to be the current settings
*/
suspend fun updateCurrent(settings: HomePageSettings) {
suspend fun updateCurrent(
source: HomePageSettingsSource,
settings: HomePageSettings,
) {
val resolvedRows =
settings.rows.mapIndexed { index, config ->
resolve(index, config)
}
val resolvedSettings = HomePageResolvedSettings(resolvedRows)
currentSettings.update { resolvedSettings }
currentSettings.update { it.copy(rows = resolvedRows) }
serverRepository.currentUser?.let { user ->
val toSave = user.updateConfig { it.copy(homeSettingsSource = source) }
serverDao.updateUser(toSave)
}
}

/**
Expand Down Expand Up @@ -838,7 +883,7 @@ class HomeSettingsService
GetItemsRequestHandler
.execute(api, request)
.content.items
.map { BaseItem.from(it, api, row.viewOptions.useSeries) }
.map { BaseItem(it, row.viewOptions.useSeries) }
}.let {
Success(
title,
Expand Down Expand Up @@ -1184,11 +1229,22 @@ data class HomeRowConfigDisplay(
data class HomePageResolvedSettings(
val rows: List<HomeRowConfigDisplay>,
) {
fun asHomePageSettings(): HomePageSettings = HomePageSettings(rows.map { it.config }, SUPPORTED_HOME_PAGE_SETTINGS_VERSION)

companion object {
val EMPTY = HomePageResolvedSettings(listOf())
val EMPTY = HomePageResolvedSettings(emptyList())
}
}

enum class HomePageSettingsSource(
@param:StringRes val stringResId: Int,
) {
UNSET(R.string.home_settings_source_unset),
LOCAL(R.string.home_settings_source_local),
SERVER_PROFILE(R.string.home_settings_source_server_profile),
PLUGIN(R.string.home_settings_source_plugin),
}

// https://github.com/jellyfin/jellyfin/blob/v10.11.6/src/Jellyfin.Database/Jellyfin.Database.Implementations/Enums/HomeSectionType.cs
enum class HomeSectionType(
val serialName: String,
Expand Down
Loading