From 4bb17a06195373f9fa5d15fae0b176b853fa8334 Mon Sep 17 00:00:00 2001 From: Sebastian Erives Date: Sun, 27 Oct 2024 16:53:37 -0600 Subject: [PATCH] Improving plugin output GUI --- .../eocvsim/config/ConfigManager.java | 5 +++++ .../eocvsim/gui/dialog/PluginOutput.kt | 15 +++++++++++++-- .../deltacv/eocvsim/plugin/loader/PluginLoader.kt | 4 ++-- .../eocvsim/plugin/loader/PluginManager.kt | 3 ++- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/config/ConfigManager.java b/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/config/ConfigManager.java index 5777ada9..d8c1605a 100644 --- a/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/config/ConfigManager.java +++ b/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/config/ConfigManager.java @@ -49,6 +49,11 @@ public void init() { logger.info("Creating config file..."); configLoader.saveToFile(config); } + + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + logger.info("SHUTDOWN - Saving config to file..."); + saveToFile(); + })); } public void saveToFile() { diff --git a/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/dialog/PluginOutput.kt b/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/dialog/PluginOutput.kt index e6b9d8ec..41ba0042 100644 --- a/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/dialog/PluginOutput.kt +++ b/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/dialog/PluginOutput.kt @@ -98,6 +98,7 @@ class PluginOutput( } private val output = JDialog() + private val tabbedPane: JTabbedPane private val mavenBottomButtonsPanel: MavenOutputBottomButtonsPanel = MavenOutputBottomButtonsPanel(::close) { mavenOutputPanel.outputArea.text @@ -108,9 +109,16 @@ class PluginOutput( init { output.isModal = true output.isAlwaysOnTop = true - output.title = "Plugin Output" + output.title = "Plugin Manager" - output.add(JTabbedPane().apply { + tabbedPane = JTabbedPane() + + output.add(tabbedPane.apply { + addTab("Plugins", JPanel().apply { + layout = BoxLayout(this, BoxLayout.PAGE_AXIS) + + add(JLabel("Plugins output will be shown here")) + }) addTab("Output", mavenOutputPanel) }) @@ -156,6 +164,9 @@ class PluginOutput( if(!text.startsWith(SPECIAL_SILENT) && text != SPECIAL_CLOSE && text != SPECIAL_FREE) { SwingUtilities.invokeLater { + SwingUtilities.invokeLater { + tabbedPane.selectedIndex = tabbedPane.indexOfTab("Output") // focus on output tab + } output.isVisible = true } } diff --git a/EOCV-Sim/src/main/java/io/github/deltacv/eocvsim/plugin/loader/PluginLoader.kt b/EOCV-Sim/src/main/java/io/github/deltacv/eocvsim/plugin/loader/PluginLoader.kt index ace814df..183ced53 100644 --- a/EOCV-Sim/src/main/java/io/github/deltacv/eocvsim/plugin/loader/PluginLoader.kt +++ b/EOCV-Sim/src/main/java/io/github/deltacv/eocvsim/plugin/loader/PluginLoader.kt @@ -198,7 +198,7 @@ class PluginLoader( fun enable() { if(enabled || !loaded) return - logger.info("Enabling plugin $pluginName v$pluginVersion") + appender.appendln("${PluginOutput.SPECIAL_SILENT}Enabling plugin $pluginName v$pluginVersion") plugin.enabled = true plugin.onEnable() @@ -212,7 +212,7 @@ class PluginLoader( fun disable() { if(!enabled || !loaded) return - logger.info("Disabling plugin $pluginName v$pluginVersion") + appender.appendln("${PluginOutput.SPECIAL_SILENT}Disabling plugin $pluginName v$pluginVersion") plugin.enabled = false plugin.onDisable() diff --git a/EOCV-Sim/src/main/java/io/github/deltacv/eocvsim/plugin/loader/PluginManager.kt b/EOCV-Sim/src/main/java/io/github/deltacv/eocvsim/plugin/loader/PluginManager.kt index 9ce1f49c..9ce1a5aa 100644 --- a/EOCV-Sim/src/main/java/io/github/deltacv/eocvsim/plugin/loader/PluginManager.kt +++ b/EOCV-Sim/src/main/java/io/github/deltacv/eocvsim/plugin/loader/PluginManager.kt @@ -163,7 +163,8 @@ class PluginManager(val eocvSim: EOCVSim) { loader.load() _loadedPluginHashes.add(hash) } catch (e: Throwable) { - appender.appendln("Failure loading ${loader.pluginName} v${loader.pluginVersion}: ${e.message}") + appender.appendln("Failure loading ${loader.pluginName} v${loader.pluginVersion}:") + appender.appendln(e.message ?: "Unknown error") logger.error("Failure loading ${loader.pluginName} v${loader.pluginVersion}", e) loaders.remove(file)