Show process during bedrock login in the screen

This commit is contained in:
FlorianMichael 2024-07-16 07:07:54 +02:00
parent 9348c7674a
commit 2faa857ecd
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
5 changed files with 112 additions and 4 deletions

View File

@ -21,7 +21,7 @@ viaaprilfools_version=3.0.1-SNAPSHOT
vialoader_version=3.0.2-SNAPSHOT
# RaphiMC Libraries
minecraftauth_version=4.0.2
minecraftauth_version=4.0.3-SNAPSHOT
viabedrock_version=0.0.10-SNAPSHOT
raknet_transport_version=1.0.0.CR3-SNAPSHOT

View File

@ -0,0 +1,28 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> and RK_01/RaphiMC
* Copyright (C) 2023-2024 contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.access;
import net.minecraft.text.Text;
public interface IConfirmScreen {
void viaFabricPlus$setMessage(final Text message);
}

View File

@ -0,0 +1,59 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> and RK_01/RaphiMC
* Copyright (C) 2023-2024 contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.mixin.base.integration;
import de.florianmichael.viafabricplus.injection.access.IConfirmScreen;
import net.minecraft.client.gui.screen.ConfirmScreen;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ConfirmScreen.class)
public abstract class MixinConfirmScreen implements IConfirmScreen {
@Mutable
@Shadow
@Final
private Text message;
@Shadow
protected abstract void init();
@Unique
private boolean viaFabricPlus$selfInflicted = false;
@Inject(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(III)I", shift = At.Shift.AFTER), cancellable = true)
private void preventButtonClearing(CallbackInfo ci) {
if (viaFabricPlus$selfInflicted) {
viaFabricPlus$selfInflicted = false;
ci.cancel();
}
}
@Override
public void viaFabricPlus$setMessage(Text message) {
viaFabricPlus$selfInflicted = true;
this.message = message;
this.init();
}
}

View File

@ -21,6 +21,7 @@ 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.screen.VFPScreen;
import de.florianmichael.viafabricplus.settings.base.BooleanSetting;
import de.florianmichael.viafabricplus.settings.base.ButtonSetting;
@ -33,6 +34,8 @@ import net.minecraft.text.Text;
import net.minecraft.util.Util;
import net.raphimc.minecraftauth.MinecraftAuth;
import net.raphimc.minecraftauth.step.msa.StepMsaDeviceCode;
import net.raphimc.minecraftauth.util.logging.ConsoleLogger;
import net.raphimc.minecraftauth.util.logging.ILogger;
import java.net.URI;
import java.net.URISyntaxException;
@ -40,9 +43,11 @@ import java.util.concurrent.CompletableFuture;
public class BedrockSettings extends SettingGroup {
private static final Text TITLE = Text.literal("Microsoft Bedrock login");
private static final BedrockSettings INSTANCE = new BedrockSettings();
private final ButtonSetting ignored = new ButtonSetting(this, Text.translatable("bedrock_settings.viafabricplus.click_to_set_bedrock_account"), () -> CompletableFuture.runAsync(this::openBedrockAccountLogin)) {
private final ButtonSetting _IGNORED = new ButtonSetting(this, Text.translatable("bedrock_settings.viafabricplus.click_to_set_bedrock_account"), () -> CompletableFuture.runAsync(this::openBedrockAccountLogin)) {
@Override
public MutableText displayValue() {
@ -56,6 +61,21 @@ public class BedrockSettings extends SettingGroup {
};
public final BooleanSetting replaceDefaultPort = new BooleanSetting(this, Text.translatable("bedrock_settings.viafabricplus.replace_default_port"), true);
private final ILogger GUI_LOGGER = new ConsoleLogger() {
@Override
public void info(String message) {
super.info(message);
if (message.equals("Waiting for MSA login via device code...")) {
return;
}
MinecraftClient.getInstance().execute(() -> {
if (MinecraftClient.getInstance().currentScreen instanceof ConfirmScreen confirmScreen) {
((IConfirmScreen) confirmScreen).viaFabricPlus$setMessage(Text.literal(message));
}
});
}
};
public BedrockSettings() {
super(Text.translatable("setting_group_name.viafabricplus.bedrock"));
}
@ -64,7 +84,7 @@ public class BedrockSettings extends SettingGroup {
final MinecraftClient client = MinecraftClient.getInstance();
final Screen prevScreen = client.currentScreen;
try {
ViaFabricPlus.global().getSaveManager().getAccountsSave().setBedrockAccount(MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.getFromInput(MinecraftAuth.createHttpClient(), new StepMsaDeviceCode.MsaDeviceCodeCallback(msaDeviceCode -> {
ViaFabricPlus.global().getSaveManager().getAccountsSave().setBedrockAccount(MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.getFromInput(GUI_LOGGER, MinecraftAuth.createHttpClient(), new StepMsaDeviceCode.MsaDeviceCodeCallback(msaDeviceCode -> {
client.execute(() -> client.setScreen(new ConfirmScreen(copyUrl -> {
if (copyUrl) {
client.keyboard.setClipboard(msaDeviceCode.getDirectVerificationUri());
@ -72,7 +92,7 @@ public class BedrockSettings extends SettingGroup {
client.setScreen(prevScreen);
Thread.currentThread().interrupt();
}
}, Text.literal("Microsoft Bedrock login"), Text.translatable("bedrock.viafabricplus.login"), Text.translatable("base.viafabricplus.copy_link"), Text.translatable("base.viafabricplus.cancel"))));
}, TITLE, Text.translatable("bedrock.viafabricplus.login"), Text.translatable("base.viafabricplus.copy_link"), Text.translatable("base.viafabricplus.cancel"))));
try {
Util.getOperatingSystem().open(new URI(msaDeviceCode.getDirectVerificationUri()));
} catch (URISyntaxException e) {

View File

@ -14,6 +14,7 @@
"base.integration.MixinAddServerScreen",
"base.integration.MixinChunkTracker",
"base.integration.MixinClientConnection",
"base.integration.MixinConfirmScreen",
"base.integration.MixinConnectScreen_1",
"base.integration.MixinDebugHud",
"base.integration.MixinDirectConnectScreen",