diff --git a/plugin-playground/src/main/kotlin/KondoKit/views/ReflectiveEditorView.kt b/plugin-playground/src/main/kotlin/KondoKit/views/ReflectiveEditorView.kt index f4f0bef..b2b82ae 100644 --- a/plugin-playground/src/main/kotlin/KondoKit/views/ReflectiveEditorView.kt +++ b/plugin-playground/src/main/kotlin/KondoKit/views/ReflectiveEditorView.kt @@ -58,6 +58,9 @@ object ReflectiveEditorView : View { // Store reference to the search field private var searchField: CustomSearchField? = null + // Flag for scheduled plugin reload to avoid crashes + private var reloadPlugins = false + private fun loadCogIcon() { try { val imageStream = this::class.java.getResourceAsStream("res/cog.png") @@ -579,8 +582,8 @@ object ReflectiveEditorView : View { if (sourceDir.renameTo(destDir)) { showToast(mainPanel, "Plugin enabled") - // Reload plugins to apply the change - PluginRepository.reloadPlugins() + // Schedule plugin reload to avoid crashes + reloadPlugins = true // Refresh the plugin list view SwingUtilities.invokeLater { @@ -661,8 +664,8 @@ object ReflectiveEditorView : View { if (sourceDir.renameTo(destDir)) { showToast(mainPanel, if (activated) "Plugin enabled" else "Plugin disabled") - // Reload plugins to apply the change - PluginRepository.reloadPlugins() + // Schedule plugin reload to avoid crashes + reloadPlugins = true // Refresh the plugin list view SwingUtilities.invokeLater { @@ -789,6 +792,12 @@ object ReflectiveEditorView : View { return } + // Check if we need to reload plugins + if (reloadPlugins) { + PluginRepository.reloadPlugins() + reloadPlugins = false + } + // Update plugin statuses to reflect current loaded plugins updatePluginStatuses() @@ -1279,9 +1288,9 @@ object ReflectiveEditorView : View { if (deleteRecursively(pluginDir)) { showToast(mainPanel, "Plugin deleted successfully", JOptionPane.INFORMATION_MESSAGE) - // If we deleted a loaded plugin, reload plugins + // If we deleted a loaded plugin, schedule plugin reload if (!isDisabled) { - PluginRepository.reloadPlugins() + reloadPlugins = true } // Refresh the plugin list view