Merge pull request #4568 from deathbeam/proper-shutdown

Properly shutdown everything on window close
This commit is contained in:
Tomas Slusny
2018-08-29 15:20:28 +02:00
committed by GitHub
5 changed files with 47 additions and 0 deletions

View File

@@ -51,4 +51,9 @@ public interface GameEngine
* @return true if on the main thread, false otherwise
*/
boolean isClientThread();
/**
* Shut downs all open connections and files in client and serializes not serialized data.
*/
void shutDown();
}

View File

@@ -35,6 +35,7 @@ import java.io.File;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.Locale;
import java.util.concurrent.ScheduledExecutorService;
import javax.annotation.Nullable;
import javax.inject.Provider;
import javax.inject.Singleton;
@@ -111,6 +112,9 @@ public class RuneLite
@Inject
private OverlayManager overlayManager;
@Inject
private ScheduledExecutorService executorService;
@Inject
private Provider<ItemManager> itemManager;
@@ -292,8 +296,10 @@ public class RuneLite
public void shutdown()
{
pluginManager.stopCorePlugins();
clientSessionManager.shutdown();
discordService.close();
executorService.shutdown();
}
@VisibleForTesting

View File

@@ -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
{
MutableGraph<Class<? extends Plugin>> graph = GraphBuilder

View File

@@ -36,6 +36,7 @@ import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.LayoutManager;
import java.awt.Rectangle;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
@@ -271,6 +272,21 @@ public class ClientUI
{
saveClientBoundsConfig();
runelite.shutdown();
if (SystemTray.isSupported())
{
SystemTray.getSystemTray().remove(trayIcon);
}
if (client != null)
{
client.stop();
}
if (client instanceof Client)
{
((Client)client).shutDown();
}
},
this::showWarningOnExit
);

View File

@@ -32,4 +32,7 @@ public interface RSGameEngine extends GameEngine
{
@Import("canvas")
Canvas getCanvas();
@Import("shutDown")
void shutDown();
}