Skip to content

Commit

Permalink
Fix scrobbler setup screen keeping the browser prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
LostLuma committed Sep 25, 2024
1 parent 41d1c7a commit 4eb2fec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public Point endPos() {
return startPos.offset(0, this.height());
}

public void clear() {
this.lines.clear();
}

public void push(Component text, Color color) {
Point newLinePos = MinecraftClient.textSize(text).centerHorizontally(startPos).offset(0, this.height());
this.lines.add(new PositionedText(text, color, newLinePos));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ public ScrobblerSetupScreen(Screen previous, ScrobblerType<T> scrobblerType) {
this.setupStatus = Optional.empty();
}

private void sendMessage(Component message) {
this.setupStatus.get().push(message, Color.WHITE);
private void setMessage(Component message) {
PushableTextLines output = this.setupStatus.orElseThrow(RuntimeException::new);

output.clear();
output.push(message, Color.WHITE);
}

private void sendError(KitTunesException exception) {
PushableTextLines output = this.setupStatus.get();
PushableTextLines output = this.setupStatus.orElseThrow(RuntimeException::new);

output.push(exception.userMessage(), Color.RED);
if (exception.isPrinted()) {
Expand Down Expand Up @@ -84,7 +87,7 @@ protected void firstInit() {
try {
this.awaitedScrobbler = Optional.of(this.scrobblerType.setup(5, TimeUnit.MINUTES));

this.sendMessage(SETUP_STARTED);
this.setMessage(SETUP_STARTED);
} catch (IOException e) {
this.sendError(new ScrobblerSetupStartException(e));

Expand Down Expand Up @@ -121,7 +124,7 @@ public void tick() {
T scrobbler = awaitedScrobbler.get();
this.saveScrobbler(scrobbler);

this.sendMessage(SETUP_COMPLETED);
this.setMessage(SETUP_COMPLETED);
} catch (ExecutionException | InterruptedException | IOException e) {
this.sendError(KitTunesException.convert(e));
}
Expand Down

0 comments on commit 4eb2fec

Please sign in to comment.