mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-19 21:10:19 -07:00
remote fetch
This commit is contained in:
parent
973149e859
commit
905393d2be
5 changed files with 257 additions and 14 deletions
|
|
@ -5,6 +5,7 @@ import KondoKit.components.*
|
|||
import KondoKit.components.ReflectiveEditorComponents.CustomSearchField
|
||||
import KondoKit.components.ReflectiveEditorComponents.GitLabPlugin
|
||||
import KondoKit.components.ReflectiveEditorComponents.GitLabPluginFetcher
|
||||
import KondoKit.components.ReflectiveEditorComponents.PluginStatus
|
||||
import KondoKit.Helpers.showToast
|
||||
import KondoKit.plugin
|
||||
import KondoKit.plugin.Companion.TITLE_BAR_COLOR
|
||||
|
|
@ -42,6 +43,9 @@ object ReflectiveEditorView : View {
|
|||
|
||||
// Store fetched GitLab plugins
|
||||
private var gitLabPlugins: List<GitLabPlugin> = listOf()
|
||||
|
||||
// Store combined plugin status (installed + remote)
|
||||
private var pluginStatuses: List<PluginStatus> = listOf()
|
||||
|
||||
// Store the cog icon to be reused
|
||||
private var cogIcon: Icon? = null
|
||||
|
|
@ -114,7 +118,10 @@ object ReflectiveEditorView : View {
|
|||
|
||||
// Fetch GitLab plugins in the background
|
||||
GitLabPluginFetcher.fetchGitLabPlugins { plugins ->
|
||||
System.out.println("GitLab plugins fetched: ${plugins.size}")
|
||||
gitLabPlugins = plugins
|
||||
// Update plugin statuses with comparison between installed and remote plugins
|
||||
updatePluginStatuses()
|
||||
// We'll update the UI when needed
|
||||
}
|
||||
}
|
||||
|
|
@ -226,13 +233,22 @@ object ReflectiveEditorView : View {
|
|||
// 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 &&
|
||||
(plugin.path.contains(pluginSearchText, ignoreCase = true) ||
|
||||
plugin.pluginProperties.description.contains(pluginSearchText, ignoreCase = true))
|
||||
System.out.println("Filtering plugins for search term: '$pluginSearchText'")
|
||||
System.out.println("Total plugin statuses: ${pluginStatuses.size}")
|
||||
|
||||
val matchingPluginStatuses = pluginStatuses.filter { pluginStatus ->
|
||||
// Only show plugins that are not currently loaded
|
||||
val shouldShow = !pluginStatus.isInstalled &&
|
||||
(pluginStatus.name.contains(pluginSearchText, ignoreCase = true) ||
|
||||
(pluginStatus.description?.contains(pluginSearchText, ignoreCase = true) ?: false))
|
||||
|
||||
System.out.println("Plugin: ${pluginStatus.name}, isInstalled: ${pluginStatus.isInstalled}, shouldShow: $shouldShow")
|
||||
shouldShow
|
||||
}
|
||||
|
||||
if (matchingGitLabPlugins.isNotEmpty()) {
|
||||
System.out.println("Matching plugin statuses: ${matchingPluginStatuses.size}")
|
||||
|
||||
if (matchingPluginStatuses.isNotEmpty()) {
|
||||
// Add a separator
|
||||
val separator = JPanel()
|
||||
separator.background = VIEW_BACKGROUND_COLOR
|
||||
|
|
@ -252,9 +268,10 @@ object ReflectiveEditorView : View {
|
|||
panel.add(headerPanel)
|
||||
panel.add(Box.createVerticalStrut(5))
|
||||
|
||||
// Add matching GitLab plugins
|
||||
for (gitLabPlugin in matchingGitLabPlugins) {
|
||||
val pluginPanel = createGitLabPluginItemPanel(gitLabPlugin)
|
||||
// Add matching plugin statuses
|
||||
for (pluginStatus in matchingPluginStatuses) {
|
||||
System.out.println("Adding plugin to UI: ${pluginStatus.name}")
|
||||
val pluginPanel = createPluginStatusItemPanel(pluginStatus)
|
||||
panel.add(pluginPanel)
|
||||
panel.add(Box.createVerticalStrut(5))
|
||||
}
|
||||
|
|
@ -419,6 +436,72 @@ object ReflectiveEditorView : View {
|
|||
return panel
|
||||
}
|
||||
|
||||
private fun createPluginStatusItemPanel(pluginStatus: PluginStatus): JPanel {
|
||||
val panel = JPanel(BorderLayout())
|
||||
panel.background = WIDGET_COLOR
|
||||
panel.border = BorderFactory.createEmptyBorder(10, 10, 10, 10)
|
||||
panel.maximumSize = Dimension(220, 60)
|
||||
|
||||
// Plugin name
|
||||
val nameLabel = JLabel(pluginStatus.name)
|
||||
nameLabel.foreground = secondaryColor
|
||||
nameLabel.font = Font("RuneScape Small", Font.PLAIN, 16)
|
||||
|
||||
// Action button based on plugin status
|
||||
val actionButton = JButton()
|
||||
actionButton.background = TITLE_BAR_COLOR
|
||||
actionButton.foreground = secondaryColor
|
||||
actionButton.font = Font("RuneScape Small", Font.PLAIN, 14)
|
||||
|
||||
if (pluginStatus.isInstalled) {
|
||||
if (pluginStatus.needsUpdate) {
|
||||
actionButton.text = "Update"
|
||||
actionButton.addActionListener {
|
||||
// TODO: Implement update functionality
|
||||
showToast(mainPanel, "Update functionality not yet implemented", JOptionPane.INFORMATION_MESSAGE)
|
||||
}
|
||||
} else {
|
||||
actionButton.text = "Installed"
|
||||
actionButton.isEnabled = false
|
||||
}
|
||||
} else {
|
||||
actionButton.text = "Download"
|
||||
actionButton.addActionListener {
|
||||
// TODO: Implement download functionality
|
||||
showToast(mainPanel, "Download functionality not yet implemented", JOptionPane.INFORMATION_MESSAGE)
|
||||
}
|
||||
}
|
||||
|
||||
// Plugin toggle switch (iOS style)
|
||||
val toggleSwitch = ToggleSwitch()
|
||||
toggleSwitch.setActivated(pluginStatus.isInstalled && !pluginStatus.needsUpdate)
|
||||
toggleSwitch.isEnabled = pluginStatus.isInstalled && !pluginStatus.needsUpdate
|
||||
|
||||
if (pluginStatus.isInstalled && !pluginStatus.needsUpdate) {
|
||||
toggleSwitch.onToggleListener = { activated ->
|
||||
// TODO: Implement enable/disable functionality
|
||||
showToast(mainPanel, "Enable/disable functionality not yet implemented", JOptionPane.INFORMATION_MESSAGE)
|
||||
// Reset for now since functionality not implemented
|
||||
toggleSwitch.setActivated(true)
|
||||
}
|
||||
}
|
||||
|
||||
// Layout
|
||||
val infoPanel = JPanel(BorderLayout())
|
||||
infoPanel.background = WIDGET_COLOR
|
||||
infoPanel.add(nameLabel, BorderLayout.WEST)
|
||||
|
||||
val controlsPanel = JPanel(FlowLayout(FlowLayout.RIGHT, 5, 0))
|
||||
controlsPanel.background = WIDGET_COLOR
|
||||
controlsPanel.add(actionButton)
|
||||
controlsPanel.add(toggleSwitch)
|
||||
|
||||
panel.add(infoPanel, BorderLayout.CENTER)
|
||||
panel.add(controlsPanel, BorderLayout.EAST)
|
||||
|
||||
return panel
|
||||
}
|
||||
|
||||
private fun enablePlugin(pluginName: String) {
|
||||
try {
|
||||
// Source and destination directories
|
||||
|
|
@ -639,12 +722,16 @@ object ReflectiveEditorView : View {
|
|||
}
|
||||
|
||||
fun addPlugins(reflectiveEditorView: JPanel) {
|
||||
System.out.println("addPlugins called")
|
||||
// Ensure we run on the EDT; if not, reschedule and return
|
||||
if (!SwingUtilities.isEventDispatchThread()) {
|
||||
SwingUtilities.invokeLater { addPlugins(reflectiveEditorView) }
|
||||
return
|
||||
}
|
||||
|
||||
// Update plugin statuses to reflect current loaded plugins
|
||||
updatePluginStatuses()
|
||||
|
||||
// Batch updates to avoid intermediate repaints/flicker
|
||||
mainPanel.ignoreRepaint = true
|
||||
try {
|
||||
|
|
@ -755,4 +842,77 @@ object ReflectiveEditorView : View {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Helper method to get currently loaded plugin names
|
||||
private fun getLoadedPluginNames(): Set<String> {
|
||||
val loadedPluginNames = mutableSetOf<String>()
|
||||
|
||||
try {
|
||||
// Get loaded plugins
|
||||
val loadedPluginsField = PluginRepository::class.java.getDeclaredField("loadedPlugins")
|
||||
loadedPluginsField.isAccessible = true
|
||||
val loadedPlugins = loadedPluginsField.get(null) as HashMap<*, *>
|
||||
|
||||
System.out.println("Found ${loadedPlugins.size} loaded plugins")
|
||||
|
||||
for ((_, plugin) in loadedPlugins) {
|
||||
val pluginName = getPluginDirName(plugin as Plugin)
|
||||
loadedPluginNames.add(pluginName)
|
||||
System.out.println("Loaded plugin: $pluginName")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
System.out.println("Returning loaded plugin names: ${loadedPluginNames.joinToString(", ")}")
|
||||
return loadedPluginNames
|
||||
}
|
||||
|
||||
// Update plugin statuses by comparing installed and remote plugins
|
||||
private fun updatePluginStatuses() {
|
||||
val loadedPluginNames = getLoadedPluginNames()
|
||||
val statuses = mutableListOf<PluginStatus>()
|
||||
|
||||
System.out.println("Updating plugin statuses. Loaded plugins: ${loadedPluginNames.joinToString(", ")}")
|
||||
|
||||
// Process remote plugins
|
||||
for (gitLabPlugin in gitLabPlugins) {
|
||||
val pluginName = gitLabPlugin.path
|
||||
val remoteVersion = gitLabPlugin.pluginProperties?.version ?: "Unknown"
|
||||
val description = gitLabPlugin.pluginProperties?.description ?: "No description available"
|
||||
val author = gitLabPlugin.pluginProperties?.author ?: "Unknown"
|
||||
|
||||
val isLoaded = loadedPluginNames.contains(pluginName)
|
||||
System.out.println("Processing plugin: $pluginName, isLoaded: $isLoaded")
|
||||
|
||||
if (isLoaded) {
|
||||
// Plugin is currently loaded
|
||||
statuses.add(PluginStatus(
|
||||
name = pluginName,
|
||||
installedVersion = remoteVersion, // We don't have the actual installed version, but we know it's loaded
|
||||
remoteVersion = remoteVersion,
|
||||
description = description,
|
||||
author = author,
|
||||
gitLabPlugin = gitLabPlugin,
|
||||
isInstalled = true,
|
||||
needsUpdate = false // We assume it's up-to-date since it's loaded
|
||||
))
|
||||
} else {
|
||||
// Plugin is not loaded
|
||||
statuses.add(PluginStatus(
|
||||
name = pluginName,
|
||||
installedVersion = null,
|
||||
remoteVersion = remoteVersion,
|
||||
description = description,
|
||||
author = author,
|
||||
gitLabPlugin = gitLabPlugin,
|
||||
isInstalled = false,
|
||||
needsUpdate = false
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Updated plugin statuses. Total statuses: ${statuses.size}")
|
||||
pluginStatuses = statuses
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue