From eea48d6c741ab165be17579daf66c6d4d8cf068a Mon Sep 17 00:00:00 2001 From: FlorianMichael Date: Fri, 6 Sep 2024 20:52:53 +0200 Subject: [PATCH] Fix bedrock login cancel button breaking resource reloading Closes https://github.com/ViaVersion/ViaFabricPlus/issues/552 --- .../settings/impl/BedrockSettings.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/florianmichael/viafabricplus/settings/impl/BedrockSettings.java b/src/main/java/de/florianmichael/viafabricplus/settings/impl/BedrockSettings.java index 72af0afb..7d721d7d 100644 --- a/src/main/java/de/florianmichael/viafabricplus/settings/impl/BedrockSettings.java +++ b/src/main/java/de/florianmichael/viafabricplus/settings/impl/BedrockSettings.java @@ -19,7 +19,6 @@ package de.florianmichael.viafabricplus.settings.impl; -import com.mojang.blaze3d.systems.RenderSystem; import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.injection.access.IConfirmScreen; import de.florianmichael.viafabricplus.save.impl.AccountsSave; @@ -41,7 +40,6 @@ import net.raphimc.minecraftauth.util.logging.ILogger; import java.util.Locale; -import java.util.concurrent.CompletableFuture; public class BedrockSettings extends SettingGroup { @@ -49,7 +47,11 @@ public class BedrockSettings extends SettingGroup { private static final BedrockSettings INSTANCE = new BedrockSettings(); - private final ButtonSetting clickToSetBedrockAccount = new ButtonSetting(this, Text.translatable("bedrock_settings.viafabricplus.click_to_set_bedrock_account"), () -> CompletableFuture.runAsync(this::openBedrockAccountLogin)) { + private Thread thread; + private final ButtonSetting clickToSetBedrockAccount = new ButtonSetting(this, Text.translatable("bedrock_settings.viafabricplus.click_to_set_bedrock_account"), () -> { + thread = new Thread(this::openBedrockAccountLogin); + thread.start(); + }) { @Override public MutableText displayValue() { @@ -94,15 +96,18 @@ private void openBedrockAccountLogin() { client.keyboard.setClipboard(msaDeviceCode.getDirectVerificationUri()); } else { client.setScreen(prevScreen); - Thread.currentThread().interrupt(); + this.thread.interrupt(); } }, TITLE, Text.translatable("click_to_set_bedrock_account.viafabricplus.notice"), Text.translatable("base.viafabricplus.copy_link"), Text.translatable("base.viafabricplus.cancel"))); Util.getOperatingSystem().open(msaDeviceCode.getDirectVerificationUri()); }))); VFPScreen.setScreen(prevScreen); - } catch (Throwable e) { - Thread.currentThread().interrupt(); + } catch (Exception e) { + if (e instanceof InterruptedException) { + return; + } + this.thread.interrupt(); VFPScreen.showErrorScreen(TITLE, e, prevScreen); } }