chore: support plugin incompatibility

This commit is contained in:
hstyi
2025-07-15 09:34:38 +08:00
committed by GitHub
parent 89b22ba984
commit b5ca8b988c
9 changed files with 85 additions and 38 deletions

View File

@@ -16,9 +16,8 @@ import java.awt.Dimension
import java.awt.event.WindowAdapter
import java.awt.event.WindowEvent
import java.io.File
import java.time.Duration
import javax.swing.*
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
object OptionPane {
private val coroutineScope = swingCoroutineScope
@@ -95,7 +94,7 @@ object OptionPane {
message: String,
title: String = UIManager.getString("OptionPane.messageDialogTitle"),
messageType: Int = JOptionPane.INFORMATION_MESSAGE,
duration: Duration = 0.milliseconds,
duration: Duration = Duration.ZERO,
) {
val label = JTextPane()
label.contentType = "text/html"
@@ -105,11 +104,12 @@ object OptionPane {
label.border = BorderFactory.createEmptyBorder()
val pane = JOptionPane(label, messageType, JOptionPane.DEFAULT_OPTION)
val dialog = initDialog(pane.createDialog(parentComponent, title))
if (duration.inWholeMilliseconds > 0) {
if (duration.toMillis() > 0) {
dialog.addWindowListener(object : WindowAdapter() {
override fun windowOpened(e: WindowEvent) {
coroutineScope.launch(Dispatchers.Swing) {
delay(duration.inWholeMilliseconds)
delay(duration.toMillis())
if (dialog.isVisible) {
dialog.isVisible = false
}

View File

@@ -6,6 +6,7 @@ import org.apache.commons.io.FileUtils
import org.apache.commons.lang3.StringUtils
import org.slf4j.LoggerFactory
import java.awt.Component
import java.awt.event.WindowEvent
import java.nio.file.Paths
import java.util.concurrent.atomic.AtomicBoolean
import javax.swing.JOptionPane
@@ -118,9 +119,11 @@ class TermoraRestarter {
Restarter.restart(commands.toTypedArray())
}
for (window in TermoraFrameManager.getInstance().getWindows()) {
window.dispose()
val instance = TermoraFrameManager.getInstance()
for (window in instance.getWindows()) {
window.dispatchEvent(WindowEvent(window, WindowEvent.WINDOW_CLOSED))
}
Disposer.dispose(instance)
}