mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-16 16:20:04 +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(
|
data class DownloadProviderDto(
|
||||||
val key: String,
|
val key: String,
|
||||||
val name: String,
|
val name: String,
|
||||||
|
val priority: Int,
|
||||||
val description: String,
|
val description: String,
|
||||||
val shortDescription: String? = null
|
val shortDescription: String? = null
|
||||||
)
|
)
|
||||||
|
|||||||
+1
-1
@@ -9,6 +9,6 @@ class DownloadProviderEndpoint(
|
|||||||
private val downloadService: DownloadService
|
private val downloadService: DownloadService
|
||||||
) {
|
) {
|
||||||
fun getProviders(): List<DownloadProviderDto> {
|
fun getProviders(): List<DownloadProviderDto> {
|
||||||
return downloadService.getProviders()
|
return downloadService.getProviders().sortedByDescending { it.priority }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,11 +17,13 @@ class DownloadService(
|
|||||||
fun getProviders(): List<DownloadProviderDto> {
|
fun getProviders(): List<DownloadProviderDto> {
|
||||||
return downloadPlugins.map {
|
return downloadPlugins.map {
|
||||||
val plugin = pluginManager.whichPlugin(it.javaClass.enclosingClass)
|
val plugin = pluginManager.whichPlugin(it.javaClass.enclosingClass)
|
||||||
|
val managementEntry = pluginManager.getManagementEntry(plugin.pluginId)
|
||||||
val descriptor = plugin.descriptor as GameyfinPluginDescriptor
|
val descriptor = plugin.descriptor as GameyfinPluginDescriptor
|
||||||
|
|
||||||
DownloadProviderDto(
|
DownloadProviderDto(
|
||||||
key = it.javaClass.name,
|
key = it.javaClass.name,
|
||||||
name = descriptor.pluginName,
|
name = descriptor.pluginName,
|
||||||
|
priority = managementEntry.priority,
|
||||||
description = descriptor.pluginDescription,
|
description = descriptor.pluginDescription,
|
||||||
shortDescription = descriptor.pluginShortDescription,
|
shortDescription = descriptor.pluginShortDescription,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class PluginEndpoint(
|
|||||||
else Flux.empty()
|
else Flux.empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAll() = pluginService.getAll()
|
fun getAll() = pluginService.getAll().sortedByDescending { it.priority }
|
||||||
|
|
||||||
fun enablePlugin(pluginId: String) = pluginService.enablePlugin(pluginId)
|
fun enablePlugin(pluginId: String) = pluginService.enablePlugin(pluginId)
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ class PluginService(
|
|||||||
|
|
||||||
fun setPluginPriorities(pluginPriorities: Map<String, Int>) {
|
fun setPluginPriorities(pluginPriorities: Map<String, Int>) {
|
||||||
pluginPriorities.forEach { (pluginId, priority) ->
|
pluginPriorities.forEach { (pluginId, priority) ->
|
||||||
val pluginManagementEntry = getPluginManagementEntry(pluginId)
|
val pluginManagementEntry = pluginManager.getManagementEntry(pluginId)
|
||||||
pluginManagementEntry.priority = priority
|
pluginManagementEntry.priority = priority
|
||||||
pluginManagementRepository.save(pluginManagementEntry)
|
pluginManagementRepository.save(pluginManagementEntry)
|
||||||
}
|
}
|
||||||
@@ -155,13 +155,8 @@ class PluginService(
|
|||||||
return pluginManager.validatePluginConfig(pluginId, configToValidate)
|
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 {
|
private fun toDto(pluginWrapper: PluginWrapper): PluginDto {
|
||||||
val pluginManagementEntry = getPluginManagementEntry(pluginWrapper.pluginId)
|
val pluginManagementEntry = pluginManager.getManagementEntry(pluginWrapper.pluginId)
|
||||||
|
|
||||||
val hasLogo = try {
|
val hasLogo = try {
|
||||||
when (pluginWrapper.plugin is GameyfinPlugin) {
|
when (pluginWrapper.plugin is GameyfinPlugin) {
|
||||||
|
|||||||
+5
@@ -209,6 +209,11 @@ class GameyfinPluginManager(
|
|||||||
.map { it.simpleName }
|
.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) {
|
private fun configurePlugin(pluginWrapper: PluginWrapper) {
|
||||||
val plugin = pluginWrapper.plugin
|
val plugin = pluginWrapper.plugin
|
||||||
if (plugin is Configurable) {
|
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? {
|
private fun castConfigValue(meta: ConfigMetadata<*>, value: Any): Any? {
|
||||||
val expectedType = meta.type
|
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<*> {
|
private fun resolveMetadata(key: String): ConfigMetadata<*> {
|
||||||
return configMetadata.find { it.key == key }
|
return configMetadata.find { it.key == key }
|
||||||
?: throw PluginConfigError("Unknown configuration key: $key")
|
?: throw PluginConfigError("Unknown configuration key: $key")
|
||||||
|
|||||||
Reference in New Issue
Block a user