mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
improve status bar feedback when starting bwt, syncing and scanning
This commit is contained in:
parent
64a9cce837
commit
ff828b483b
5 changed files with 61 additions and 13 deletions
|
@ -1196,7 +1196,7 @@ public class AppController implements Initializable {
|
||||||
if(wait != null && wait.getStatus() == Animation.Status.RUNNING) {
|
if(wait != null && wait.getStatus() == Animation.Status.RUNNING) {
|
||||||
wait.stop();
|
wait.stop();
|
||||||
}
|
}
|
||||||
wait = new PauseTransition(Duration.seconds(20));
|
wait = new PauseTransition(Duration.seconds(event.getShowDuration()));
|
||||||
wait.setOnFinished((e) -> {
|
wait.setOnFinished((e) -> {
|
||||||
if(statusBar.getText().equals(event.getStatus())) {
|
if(statusBar.getText().equals(event.getStatus())) {
|
||||||
statusBar.setText("");
|
statusBar.setText("");
|
||||||
|
@ -1272,14 +1272,20 @@ public class AppController implements Initializable {
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void bwtBootStatus(BwtBootStatusEvent event) {
|
public void bwtBootStatus(BwtBootStatusEvent event) {
|
||||||
serverToggle.setDisable(true);
|
serverToggle.setDisable(true);
|
||||||
statusUpdated(new StatusEvent(event.getStatus()));
|
statusUpdated(new StatusEvent(event.getStatus(), 60));
|
||||||
|
if(statusTimeline == null || statusTimeline.getStatus() != Animation.Status.RUNNING) {
|
||||||
|
statusBar.setProgress(0.01);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void bwtSyncStatus(BwtSyncStatusEvent event) {
|
public void bwtSyncStatus(BwtSyncStatusEvent event) {
|
||||||
serverToggle.setDisable(false);
|
serverToggle.setDisable(false);
|
||||||
if((AppServices.isConnecting() || AppServices.isConnected()) && !event.isCompleted()) {
|
if((AppServices.isConnecting() || AppServices.isConnected()) && !event.isCompleted()) {
|
||||||
statusUpdated(new StatusEvent(event.getStatus()));
|
statusUpdated(new StatusEvent("Syncing... (" + event.getProgress() + "% complete, synced to " + event.getTipAsString() + ")"));
|
||||||
|
if(event.getProgress() > 0 && (statusTimeline == null || statusTimeline.getStatus() != Animation.Status.RUNNING)) {
|
||||||
|
statusBar.setProgress((double)event.getProgress() / 100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1287,13 +1293,19 @@ public class AppController implements Initializable {
|
||||||
public void bwtScanStatus(BwtScanStatusEvent event) {
|
public void bwtScanStatus(BwtScanStatusEvent event) {
|
||||||
serverToggle.setDisable(true);
|
serverToggle.setDisable(true);
|
||||||
if((AppServices.isConnecting() || AppServices.isConnected()) && !event.isCompleted()) {
|
if((AppServices.isConnecting() || AppServices.isConnected()) && !event.isCompleted()) {
|
||||||
statusUpdated(new StatusEvent(event.getStatus()));
|
statusUpdated(new StatusEvent("Scanning... (" + event.getProgress() + "% complete" + (event.getProgress() > 30 ? ", " + event.getRemainingAsString() + " remaining)" : ")")));
|
||||||
|
if(event.getProgress() > 0 && (statusTimeline == null || statusTimeline.getStatus() != Animation.Status.RUNNING)) {
|
||||||
|
statusBar.setProgress((double)event.getProgress() / 100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void bwtReadyStatus(BwtReadyStatusEvent event) {
|
public void bwtReadyStatus(BwtReadyStatusEvent event) {
|
||||||
serverToggle.setDisable(false);
|
serverToggle.setDisable(false);
|
||||||
|
if(statusTimeline == null || statusTimeline.getStatus() != Animation.Status.RUNNING) {
|
||||||
|
statusBar.setProgress(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
|
@ -1302,6 +1314,9 @@ public class AppController implements Initializable {
|
||||||
if(!AppServices.isConnecting() && !AppServices.isConnected() && !statusBar.getText().startsWith("Connection error")) {
|
if(!AppServices.isConnecting() && !AppServices.isConnected() && !statusBar.getText().startsWith("Connection error")) {
|
||||||
statusUpdated(new StatusEvent("Disconnected"));
|
statusUpdated(new StatusEvent("Disconnected"));
|
||||||
}
|
}
|
||||||
|
if(statusTimeline == null || statusTimeline.getStatus() != Animation.Status.RUNNING) {
|
||||||
|
statusBar.setProgress(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package com.sparrowwallet.sparrow.event;
|
package com.sparrowwallet.sparrow.event;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.time.Duration;
|
||||||
|
|
||||||
public class BwtScanStatusEvent extends BwtStatusEvent {
|
public class BwtScanStatusEvent extends BwtStatusEvent {
|
||||||
private final int progress;
|
private final int progress;
|
||||||
private final Date eta;
|
private final Duration remainingDuration;
|
||||||
|
|
||||||
public BwtScanStatusEvent(String status, int progress, Date eta) {
|
public BwtScanStatusEvent(String status, int progress, Duration remainingDuration) {
|
||||||
super(status);
|
super(status);
|
||||||
this.progress = progress;
|
this.progress = progress;
|
||||||
this.eta = eta;
|
this.remainingDuration = remainingDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getProgress() {
|
public int getProgress() {
|
||||||
|
@ -20,7 +20,19 @@ public class BwtScanStatusEvent extends BwtStatusEvent {
|
||||||
return progress == 100;
|
return progress == 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getEta() {
|
public Duration getRemaining() {
|
||||||
return eta;
|
return remainingDuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRemainingAsString() {
|
||||||
|
if(remainingDuration != null) {
|
||||||
|
if(progress < 30) {
|
||||||
|
return Math.round((double)remainingDuration.toSeconds() / 60) + "m";
|
||||||
|
} else {
|
||||||
|
return remainingDuration.toMinutesPart() + "m " + remainingDuration.toSecondsPart() + "s";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
package com.sparrowwallet.sparrow.event;
|
package com.sparrowwallet.sparrow.event;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class BwtSyncStatusEvent extends BwtStatusEvent {
|
public class BwtSyncStatusEvent extends BwtStatusEvent {
|
||||||
|
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd HH:mm");
|
||||||
|
|
||||||
private final int progress;
|
private final int progress;
|
||||||
private final Date tip;
|
private final Date tip;
|
||||||
|
|
||||||
|
@ -23,4 +27,8 @@ public class BwtSyncStatusEvent extends BwtStatusEvent {
|
||||||
public Date getTip() {
|
public Date getTip() {
|
||||||
return tip;
|
return tip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTipAsString() {
|
||||||
|
return tip == null ? "" : DATE_FORMAT.format(tip);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,25 @@
|
||||||
package com.sparrowwallet.sparrow.event;
|
package com.sparrowwallet.sparrow.event;
|
||||||
|
|
||||||
public class StatusEvent {
|
public class StatusEvent {
|
||||||
|
public static final int DEFAULT_SHOW_DURATION_SECS = 20;
|
||||||
|
|
||||||
private final String status;
|
private final String status;
|
||||||
|
private final int showDuration;
|
||||||
|
|
||||||
public StatusEvent(String status) {
|
public StatusEvent(String status) {
|
||||||
|
this(status, DEFAULT_SHOW_DURATION_SECS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StatusEvent(String status, int showDuration) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
|
this.showDuration = showDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStatus() {
|
public String getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getShowDuration() {
|
||||||
|
return showDuration;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -254,12 +255,12 @@ public class Bwt {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onScanProgress(float progress, int eta) {
|
public void onScanProgress(float progress, int remaining) {
|
||||||
int percent = (int) (progress * 100.0);
|
int percent = (int) (progress * 100.0);
|
||||||
Date date = new Date((long) eta * 1000);
|
Duration remainingDuration = Duration.ofSeconds(remaining);
|
||||||
log.debug("Scanning " + percent + "%");
|
log.debug("Scanning " + percent + "%");
|
||||||
if(!terminating) {
|
if(!terminating) {
|
||||||
Platform.runLater(() -> EventManager.get().post(new BwtScanStatusEvent("Scanning" + (percent < 100 ? " (" + percent + "%)" : ""), percent, date)));
|
Platform.runLater(() -> EventManager.get().post(new BwtScanStatusEvent("Scanning" + (percent < 100 ? " (" + percent + "%)" : ""), percent, remainingDuration)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue