Close Iris GUI windows on the Swing thread when the plugin shuts down

Windows otherwise outlive the plugin and keep drawing with threads its shutdown has stopped. GuiHost.closeWindows disposes every managed frame on the Swing thread and waits at most 5 s, in case that thread is itself waiting on the server. The Bukkit plugin runs it with its post-shutdown cleanup and the modded stop sequence runs it before clearing the GUI host.

v3: 6793e34d8
This commit is contained in:
piexel committed 2026-11-10 10:28:12 +01:00
1 parent 7e4c159039
commit 88ee0e89f7
4 files changed
+57 -2

No files matched your search

@@ -6,10 +6,12 @@ import org.mockito.ArgumentCaptor;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import java.awt.EventQueue;
import java.awt.GraphicsEnvironment;
import java.awt.desktop.QuitResponse;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
@@ -17,6 +19,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -51,6 +54,30 @@ public class GuiHostTest {
listenerCaptor.getValue().windowClosed(mock(WindowEvent.class));
}
@Test
public void closeWindowsDisposesManagedWindowsOnTheSwingThreadBeforeReturning() throws Exception {
JFrame frame = mock(JFrame.class);
AtomicBoolean disposedOnSwingThread = new AtomicBoolean();
doAnswer(invocation -> {
disposedOnSwingThread.set(EventQueue.isDispatchThread());
return null;
}).when(frame).dispose();
ArgumentCaptor<WindowListener> listenerCaptor = ArgumentCaptor.forClass(WindowListener.class);
GuiHost.prepareFrame(frame);
GuiHost.closeWindows();
verify(frame).dispose();
assertTrue(disposedOnSwingThread.get());
verify(frame, atLeastOnce()).addWindowListener(listenerCaptor.capture());
listenerCaptor.getValue().windowClosed(mock(WindowEvent.class));
}
@Test
public void closeWindowsWithoutWindowsReturnsImmediately() {
GuiHost.closeWindows();
}
@Test
public void preparedFramesDisposeWhenClosed() throws Exception {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());