Avoid crashing when enabling/disable/installing/deleting

This commit is contained in:
downthecrop 2025-09-18 23:35:37 -07:00
parent 07e5fb08b3
commit 50e03baea7

View file

@ -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