Skip to content

Commit ba02345

Browse files
committed
Shutdown Discord Integration at launcher shutdown
1 parent 84ba88c commit ba02345

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/api/java/com/mcmoddev/relauncher/api/DiscordIntegration.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ public interface DiscordIntegration {
3030
*/
3131
void setActivity(ActivityType type, String name);
3232

33+
/**
34+
* Shuts down the integration.
35+
*/
36+
default void shutdown() {
37+
38+
}
39+
3340
enum ActivityType {
3441
PLAYING,
3542
STREAMING,

src/launcher/java/com/mcmoddev/relauncher/Main.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ public static void main(String[] args) throws IOException {
143143
updater.tryFirstStart();
144144
SERVICE.allowCoreThreadTimeOut(true);
145145
}
146+
147+
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
148+
if (discordIntegration != null) {
149+
discordIntegration.shutdown();
150+
}
151+
}));
146152
}
147153

148154
@Nullable
@@ -211,6 +217,7 @@ public static void selfUpdate(String tagName) throws Exception {
211217
)
212218
.inheritIO()
213219
.start();
220+
214221
System.exit(0);
215222
}
216223

src/launcher/java/com/mcmoddev/relauncher/discord/DefaultDiscordIntegration.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ public DefaultDiscordIntegration(final Path basePath, final Config.Discord confi
7373
.setGatewayPool(Main.SERVICE)
7474
.build()
7575
.setRequiredScopes("applications.commands", "bot");
76-
77-
Runtime.getRuntime().addShutdownHook(new Thread(jda::shutdownNow));
7876
} catch (LoginException e) {
7977
throw new RuntimeException("Please provide a valid bot token!");
8078
}
@@ -85,4 +83,9 @@ public DefaultDiscordIntegration(final Path basePath, final Config.Discord confi
8583
public void setActivity(final ActivityType type, final String name) {
8684
jda.getPresence().setActivity(Activity.of(Activity.ActivityType.valueOf(type.name()), name));
8785
}
86+
87+
@Override
88+
public void shutdown() {
89+
jda.shutdown();
90+
}
8891
}

0 commit comments

Comments
 (0)