Skip to content

Commit e9ac7bd

Browse files
committed
Ensure toasts are always queued on the main thread
1 parent 40dd7c4 commit e9ac7bd

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

platforms/common/src/main/java/dynamic_fps/impl/feature/battery/BatteryTracker.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import net.lostluma.battery.api.State;
1010
import net.lostluma.battery.api.exception.LibraryLoadError;
1111
import net.lostluma.battery.api.util.LibraryUtil;
12+
import net.minecraft.client.Minecraft;
1213
import org.jetbrains.annotations.Nullable;
1314

1415
import java.io.IOException;
@@ -26,6 +27,7 @@ public class BatteryTracker {
2627
private static @Nullable Manager manager = null;
2728
private static Collection<Battery> batteries = Collections.emptyList();
2829

30+
private static final Minecraft minecraft = Minecraft.getInstance();
2931
private static final Duration updateInterval = Duration.of(15, ChronoUnit.SECONDS);
3032

3133
public static int charge() {
@@ -87,11 +89,17 @@ private static void updateState() {
8789

8890
if (readInitialData && charge != newCharge) {
8991
changed = true;
90-
DynamicFPSMod.onBatteryChargeChanged(charge, newCharge);
92+
93+
int current = charge;
94+
minecraft.tell(() -> DynamicFPSMod.onBatteryChargeChanged(current, newCharge));
9195
}
9296

9397
if (readInitialData && status != newStatus) {
94-
DynamicFPSMod.onBatteryStatusChanged(status ,newStatus);
98+
changed = true;
99+
100+
State current = status;
101+
State updated = newStatus;
102+
minecraft.tell(() -> DynamicFPSMod.onBatteryStatusChanged(current, updated));
95103
}
96104

97105
charge = newCharge;

0 commit comments

Comments
 (0)