Skip to content

Fix Discord presence module error handling (Fixes #5535) #5568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public enum SelectMode {
private SmallImage currentSmallImage;
private int ticks;
private boolean forceUpdate, lastWasInMainMenu;
private boolean hasLoggedError = false;

private final List<Script> line1Scripts = new ArrayList<>();
private int line1Ticks, line1I;
Expand Down Expand Up @@ -146,31 +147,42 @@ public static void unregisterCustomState(String packageName) {

@Override
public void onActivate() {
DiscordIPC.start(835240968533049424L, null);
try {
DiscordIPC.start(835240968533049424L, null);

rpc.setStart(System.currentTimeMillis() / 1000L);
rpc.setStart(System.currentTimeMillis() / 1000L);

String largeText = "%s %s".formatted(MeteorClient.NAME, MeteorClient.VERSION);
if (!MeteorClient.BUILD_NUMBER.isEmpty()) largeText += " Build: " + MeteorClient.BUILD_NUMBER;
rpc.setLargeImage("meteor_client", largeText);
String largeText = "%s %s".formatted(MeteorClient.NAME, MeteorClient.VERSION);
if (!MeteorClient.BUILD_NUMBER.isEmpty()) largeText += " Build: " + MeteorClient.BUILD_NUMBER;
rpc.setLargeImage("meteor_client", largeText);

currentSmallImage = SmallImage.Snail;
currentSmallImage = SmallImage.Snail;

recompileLine1();
recompileLine2();
recompileLine1();
recompileLine2();

ticks = 0;
line1Ticks = 0;
line2Ticks = 0;
lastWasInMainMenu = false;

line1I = 0;
line2I = 0;
ticks = 0;
line1Ticks = 0;
line2Ticks = 0;
lastWasInMainMenu = false;
hasLoggedError = false;

line1I = 0;
line2I = 0;
} catch (Exception e) {
error("Failed to start Discord Rich Presence: " + e.getMessage());
error("Make sure Discord is running and try again.");
toggle();
}
}

@Override
public void onDeactivate() {
DiscordIPC.stop();
try {
DiscordIPC.stop();
} catch (Exception e) {
// Ignore errors when stopping
}
}

private void recompile(List<String> messages, List<Script> scripts) {
Expand Down Expand Up @@ -277,7 +289,18 @@ private void onTick(TickEvent.Post event) {
}

// Update
if (update) DiscordIPC.setActivity(rpc);
if (update) {
try {
DiscordIPC.setActivity(rpc);
} catch (Exception e) {
if (!hasLoggedError) {
error("Failed to update Discord Rich Presence: " + e.getMessage());
error("Make sure Discord is running. Module will be disabled.");
hasLoggedError = true;
}
toggle();
}
}
forceUpdate = false;
lastWasInMainMenu = !Utils.canUpdate();
}
Expand Down Expand Up @@ -315,4 +338,4 @@ SmallImage next() {
return MineGame;
}
}
}
}