Working Gitlab search

This commit is contained in:
downthecrop 2025-09-08 12:12:57 -07:00
parent cf6bb51d2c
commit eee924e915
6 changed files with 26 additions and 30 deletions

View file

@ -36,11 +36,10 @@ object GitLabPluginFetcher {
// Parse JSON response
val gson = Gson()
val treeItems = gson.fromJson(response, Array::class.java)
val treeItems = gson.fromJson(response, Array<JsonObject>::class.java)
// Filter for directories (trees)
for (item in treeItems) {
val jsonObject = item as JsonObject
for (jsonObject in treeItems) {
if (jsonObject["type"].asString == "tree") {
val folderId = jsonObject["id"].asString
val folderPath = jsonObject["path"].asString

View file

@ -4,6 +4,7 @@ import KondoKit.ImageCanvas
import KondoKit.SpriteToBufferedImage
import KondoKit.plugin.Companion.WIDGET_COLOR
import KondoKit.plugin.Companion.secondaryColor
import KondoKit.plugin.StateManager.focusedView
import plugin.api.API
import java.awt.*
import java.awt.datatransfer.DataFlavor
@ -11,10 +12,11 @@ import java.awt.event.*
import javax.swing.*
open class SearchField(
private val onSearch: (String) -> Unit,
protected val onSearch: (String) -> Unit,
private val placeholderText: String = "Search...",
private val fieldWidth: Int = 230,
private val fieldHeight: Int = 30
private val fieldHeight: Int = 30,
private val viewName: String? = null
) : Canvas() {
private var cursorVisible: Boolean = true
@ -101,8 +103,11 @@ open class SearchField(
Timer(500) { _ ->
cursorVisible = !cursorVisible
SwingUtilities.invokeLater {
repaint()
// Only repaint if the view is active or if viewName is not specified
if (viewName == null || focusedView == viewName) {
SwingUtilities.invokeLater {
repaint()
}
}
}.start()
}

View file

@ -531,7 +531,7 @@ class plugin : Plugin() {
commit.run()
} else {
try {
javax.swing.SwingUtilities.invokeAndWait(commit)
SwingUtilities.invokeAndWait(commit)
} catch (e: Exception) {
// Fallback to async if invokeAndWait fails for any reason
SwingUtilities.invokeLater(commit)

View file

@ -16,11 +16,6 @@ import com.google.gson.Gson
import plugin.api.API
import rt4.Sprites
import java.awt.*
import java.awt.datatransfer.DataFlavor
import java.awt.event.KeyAdapter
import java.awt.event.KeyEvent
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import java.io.BufferedReader
import java.io.InputStreamReader
import java.net.HttpURLConnection
@ -66,12 +61,19 @@ object HiscoresView {
const val VIEW_NAME = "HISCORE_SEARCH_VIEW"
var hiScoreView: JPanel? = null
class CustomSearchField(private val hiscoresPanel: JPanel) : SearchField({ username ->
// Handle search action
(this as CustomSearchField).searchPlayer(username)
}) {
class CustomSearchField(private val hiscoresPanel: JPanel) : SearchField(
onSearch = { _ -> }, // Placeholder, will be replaced
viewName = VIEW_NAME
) {
private val gson = Gson()
init {
// This is a workaround to set the onSearch callback after the class is fully initialized
val onSearchField = javaClass.superclass.getDeclaredField("onSearch")
onSearchField.isAccessible = true
onSearchField.set(this, { username: String -> searchPlayer(username) })
}
fun searchPlayer(username: String) {
val cleanUsername = username.replace(" ", "_")

View file

@ -10,9 +10,6 @@ import KondoKit.components.PopupMenuComponent
import KondoKit.components.ProgressBar
import KondoKit.plugin.Companion.useLiveGEPrices
import KondoKit.plugin.Companion.WIDGET_COLOR
import KondoKit.plugin.Companion.VIEW_BACKGROUND_COLOR
import KondoKit.plugin.Companion.POPUP_BACKGROUND
import KondoKit.plugin.Companion.POPUP_FOREGROUND
import KondoKit.plugin.Companion.TITLE_BAR_COLOR
import KondoKit.plugin.Companion.TOOLTIP_BACKGROUND
import KondoKit.plugin.Companion.TOTAL_XP_WIDGET_SIZE
@ -20,7 +17,6 @@ import KondoKit.plugin.Companion.primaryColor
import KondoKit.plugin.Companion.registerDrawAction
import KondoKit.plugin.Companion.secondaryColor
import KondoKit.plugin.StateManager.focusedView
import KondoKit.views.BaseView
import plugin.api.API
import rt4.*
import java.awt.*
@ -29,10 +25,8 @@ import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import java.awt.image.BufferedImage
import java.io.BufferedReader
import java.io.InputStreamReader
import java.net.HttpURLConnection
import java.net.URL
import java.nio.charset.StandardCharsets
import java.text.DecimalFormat
import javax.swing.*
import kotlin.math.ceil

View file

@ -5,8 +5,6 @@ import KondoKit.components.*
import KondoKit.components.ReflectiveEditorComponents.CustomSearchField
import KondoKit.components.ReflectiveEditorComponents.GitLabPlugin
import KondoKit.components.ReflectiveEditorComponents.GitLabPluginFetcher
import KondoKit.components.ReflectiveEditorComponents.PluginProperties
import KondoKit.views.Constants
import KondoKit.Helpers.showToast
import KondoKit.plugin
import KondoKit.plugin.Companion.TOOLTIP_BACKGROUND
@ -17,12 +15,9 @@ import plugin.PluginInfo
import plugin.PluginRepository
import rt4.GlobalJsonConfig
import java.awt.*
import java.awt.datatransfer.DataFlavor
import java.awt.event.*
import java.awt.image.BufferedImage
import java.io.File
import java.util.*
import java.util.Timer
import javax.imageio.ImageIO
import javax.swing.*
import javax.swing.border.AbstractBorder
@ -143,7 +138,7 @@ object ReflectiveEditorView {
panel.add(Box.createVerticalStrut(10)) // Spacer
try {
panel.add(Box.createVerticalStrut(10)) // Spacer
// Get loaded plugins
val loadedPluginsField = PluginRepository::class.java.getDeclaredField("loadedPlugins")
loadedPluginsField.isAccessible = true
val loadedPlugins = loadedPluginsField.get(null) as HashMap<*, *>
@ -218,6 +213,7 @@ object ReflectiveEditorView {
}
// Add a section for available plugins from GitLab that are not installed
// Only show this section when there's a search term
if (pluginSearchText.isNotBlank()) {
val matchingGitLabPlugins = gitLabPlugins.filter { plugin ->
plugin.pluginProperties != null &&