mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-13 16:40:01 +00:00
Sort plugins by priority in UI
This commit is contained in:
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonInclude
|
||||
data class DownloadProviderDto(
|
||||
val key: String,
|
||||
val name: String,
|
||||
val priority: Int,
|
||||
val description: String,
|
||||
val shortDescription: String? = null
|
||||
)
|
||||
|
||||
+1
-1
@@ -9,6 +9,6 @@ class DownloadProviderEndpoint(
|
||||
private val downloadService: DownloadService
|
||||
) {
|
||||
fun getProviders(): List<DownloadProviderDto> {
|
||||
return downloadService.getProviders()
|
||||
return downloadService.getProviders().sortedByDescending { it.priority }
|
||||
}
|
||||
}
|
||||
@@ -17,11 +17,13 @@ class DownloadService(
|
||||
fun getProviders(): List<DownloadProviderDto> {
|
||||
return downloadPlugins.map {
|
||||
val plugin = pluginManager.whichPlugin(it.javaClass.enclosingClass)
|
||||
val managementEntry = pluginManager.getManagementEntry(plugin.pluginId)
|
||||
val descriptor = plugin.descriptor as GameyfinPluginDescriptor
|
||||
|
||||
DownloadProviderDto(
|
||||
key = it.javaClass.name,
|
||||
name = descriptor.pluginName,
|
||||
priority = managementEntry.priority,
|
||||
description = descriptor.pluginDescription,
|
||||
shortDescription = descriptor.pluginShortDescription,
|
||||
)
|
||||
|
||||
@@ -24,7 +24,7 @@ class PluginEndpoint(
|
||||
else Flux.empty()
|
||||
}
|
||||
|
||||
fun getAll() = pluginService.getAll()
|
||||
fun getAll() = pluginService.getAll().sortedByDescending { it.priority }
|
||||
|
||||
fun enablePlugin(pluginId: String) = pluginService.enablePlugin(pluginId)
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ class PluginService(
|
||||
|
||||
fun setPluginPriorities(pluginPriorities: Map<String, Int>) {
|
||||
pluginPriorities.forEach { (pluginId, priority) ->
|
||||
val pluginManagementEntry = getPluginManagementEntry(pluginId)
|
||||
val pluginManagementEntry = pluginManager.getManagementEntry(pluginId)
|
||||
pluginManagementEntry.priority = priority
|
||||
pluginManagementRepository.save(pluginManagementEntry)
|
||||
}
|
||||
@@ -155,13 +155,8 @@ class PluginService(
|
||||
return pluginManager.validatePluginConfig(pluginId, configToValidate)
|
||||
}
|
||||
|
||||
private fun getPluginManagementEntry(pluginId: String): PluginManagementEntry {
|
||||
return pluginManagementRepository.findByIdOrNull(pluginId)
|
||||
?: throw IllegalArgumentException("Plugin with ID $pluginId not found")
|
||||
}
|
||||
|
||||
private fun toDto(pluginWrapper: PluginWrapper): PluginDto {
|
||||
val pluginManagementEntry = getPluginManagementEntry(pluginWrapper.pluginId)
|
||||
val pluginManagementEntry = pluginManager.getManagementEntry(pluginWrapper.pluginId)
|
||||
|
||||
val hasLogo = try {
|
||||
when (pluginWrapper.plugin is GameyfinPlugin) {
|
||||
|
||||
+5
@@ -209,6 +209,11 @@ class GameyfinPluginManager(
|
||||
.map { it.simpleName }
|
||||
}
|
||||
|
||||
fun getManagementEntry(pluginId: String): PluginManagementEntry {
|
||||
return pluginManagementRepository.findByIdOrNull(pluginId)
|
||||
?: throw IllegalArgumentException("Plugin with ID $pluginId not found")
|
||||
}
|
||||
|
||||
private fun configurePlugin(pluginWrapper: PluginWrapper) {
|
||||
val plugin = pluginWrapper.plugin
|
||||
if (plugin is Configurable) {
|
||||
|
||||
+8
-8
@@ -55,6 +55,14 @@ abstract class ConfigurableGameyfinPlugin(wrapper: PluginWrapper) : GameyfinPlug
|
||||
}
|
||||
}
|
||||
|
||||
override fun <T : Serializable> config(key: String): T {
|
||||
val value = optionalConfig<T>(key)
|
||||
if (value == null) {
|
||||
throw PluginConfigError("Required configuration key '$key' is missing or has no value")
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
private fun castConfigValue(meta: ConfigMetadata<*>, value: Any): Any? {
|
||||
val expectedType = meta.type
|
||||
|
||||
@@ -98,14 +106,6 @@ abstract class ConfigurableGameyfinPlugin(wrapper: PluginWrapper) : GameyfinPlug
|
||||
}
|
||||
}
|
||||
|
||||
override fun <T : Serializable> config(key: String): T {
|
||||
val value = optionalConfig<T>(key)
|
||||
if (value == null) {
|
||||
throw PluginConfigError("Required configuration key '$key' is missing or has no value")
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
private fun resolveMetadata(key: String): ConfigMetadata<*> {
|
||||
return configMetadata.find { it.key == key }
|
||||
?: throw PluginConfigError("Unknown configuration key: $key")
|
||||
|
||||
Reference in New Issue
Block a user