Merge pull request #4568 from deathbeam/proper-shutdown
Properly shutdown everything on window close
This commit is contained in:
@@ -51,4 +51,9 @@ public interface GameEngine
|
|||||||
* @return true if on the main thread, false otherwise
|
* @return true if on the main thread, false otherwise
|
||||||
*/
|
*/
|
||||||
boolean isClientThread();
|
boolean isClientThread();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shut downs all open connections and files in client and serializes not serialized data.
|
||||||
|
*/
|
||||||
|
void shutDown();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import java.io.File;
|
|||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
import java.lang.management.RuntimeMXBean;
|
import java.lang.management.RuntimeMXBean;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
@@ -111,6 +112,9 @@ public class RuneLite
|
|||||||
@Inject
|
@Inject
|
||||||
private OverlayManager overlayManager;
|
private OverlayManager overlayManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ScheduledExecutorService executorService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Provider<ItemManager> itemManager;
|
private Provider<ItemManager> itemManager;
|
||||||
|
|
||||||
@@ -292,8 +296,10 @@ public class RuneLite
|
|||||||
|
|
||||||
public void shutdown()
|
public void shutdown()
|
||||||
{
|
{
|
||||||
|
pluginManager.stopCorePlugins();
|
||||||
clientSessionManager.shutdown();
|
clientSessionManager.shutdown();
|
||||||
discordService.close();
|
discordService.close();
|
||||||
|
executorService.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
|||||||
@@ -214,6 +214,23 @@ public class PluginManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void stopCorePlugins()
|
||||||
|
{
|
||||||
|
List<Plugin> scannedPlugins = new ArrayList<>(plugins);
|
||||||
|
for (Plugin plugin : scannedPlugins)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
stopPlugin(plugin);
|
||||||
|
plugins.remove(plugin);
|
||||||
|
}
|
||||||
|
catch (PluginInstantiationException ex)
|
||||||
|
{
|
||||||
|
log.warn("Unable to stop plugin {}. {}", plugin.getClass().getSimpleName(), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<Plugin> scanAndInstantiate(ClassLoader classLoader, String packageName) throws IOException
|
List<Plugin> scanAndInstantiate(ClassLoader classLoader, String packageName) throws IOException
|
||||||
{
|
{
|
||||||
MutableGraph<Class<? extends Plugin>> graph = GraphBuilder
|
MutableGraph<Class<? extends Plugin>> graph = GraphBuilder
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import java.awt.Graphics;
|
|||||||
import java.awt.GraphicsConfiguration;
|
import java.awt.GraphicsConfiguration;
|
||||||
import java.awt.LayoutManager;
|
import java.awt.LayoutManager;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.SystemTray;
|
||||||
import java.awt.TrayIcon;
|
import java.awt.TrayIcon;
|
||||||
import java.awt.event.InputEvent;
|
import java.awt.event.InputEvent;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
@@ -271,6 +272,21 @@ public class ClientUI
|
|||||||
{
|
{
|
||||||
saveClientBoundsConfig();
|
saveClientBoundsConfig();
|
||||||
runelite.shutdown();
|
runelite.shutdown();
|
||||||
|
|
||||||
|
if (SystemTray.isSupported())
|
||||||
|
{
|
||||||
|
SystemTray.getSystemTray().remove(trayIcon);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (client != null)
|
||||||
|
{
|
||||||
|
client.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (client instanceof Client)
|
||||||
|
{
|
||||||
|
((Client)client).shutDown();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
this::showWarningOnExit
|
this::showWarningOnExit
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -32,4 +32,7 @@ public interface RSGameEngine extends GameEngine
|
|||||||
{
|
{
|
||||||
@Import("canvas")
|
@Import("canvas")
|
||||||
Canvas getCanvas();
|
Canvas getCanvas();
|
||||||
|
|
||||||
|
@Import("shutDown")
|
||||||
|
void shutDown();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user