mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-10-01 01:35:48 -04:00
reset startup timeout on sync progress
This commit is contained in:
parent
9957aa6256
commit
9fb22f6d1f
@ -181,6 +181,7 @@ public class HavenoSetup {
|
||||
private boolean allBasicServicesInitialized;
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
private MonadicBinding<Boolean> p2pNetworkAndWalletInitialized;
|
||||
private Timer startupTimeout;
|
||||
private final List<HavenoSetupListener> havenoSetupListeners = new ArrayList<>();
|
||||
|
||||
public interface HavenoSetupListener {
|
||||
@ -368,23 +369,16 @@ public class HavenoSetup {
|
||||
p2PService.getP2PDataStorage().readFromResources(postFix, completeHandler);
|
||||
}
|
||||
|
||||
private void startP2pNetworkAndWallet(Runnable nextStep) {
|
||||
ChangeListener<Boolean> walletInitializedListener = (observable, oldValue, newValue) -> {
|
||||
// TODO that seems to be called too often if Tor takes longer to start up...
|
||||
if (newValue && !p2pNetworkReady.get() && displayTorNetworkSettingsHandler != null)
|
||||
displayTorNetworkSettingsHandler.accept(true);
|
||||
};
|
||||
|
||||
Timer startupTimeout = UserThread.runAfter(() -> {
|
||||
private synchronized void resetStartupTimeout() {
|
||||
if (p2pNetworkAndWalletInitialized != null && p2pNetworkAndWalletInitialized.get()) return; // skip if already initialized
|
||||
if (startupTimeout != null) startupTimeout.stop();
|
||||
startupTimeout = UserThread.runAfter(() -> {
|
||||
if (p2PNetworkSetup.p2pNetworkFailed.get() || walletsSetup.walletsSetupFailed.get()) {
|
||||
// Skip this timeout action if the p2p network or wallet setup failed
|
||||
// since an error prompt will be shown containing the error message
|
||||
return;
|
||||
}
|
||||
log.warn("startupTimeout called");
|
||||
//TODO (niyid) This has a part to play in the display of the password prompt
|
||||
// if (walletsManager.areWalletsEncrypted())
|
||||
// walletInitialized.addListener(walletInitializedListener);
|
||||
if (displayTorNetworkSettingsHandler != null)
|
||||
displayTorNetworkSettingsHandler.accept(true);
|
||||
|
||||
@ -393,6 +387,20 @@ public class HavenoSetup {
|
||||
// Log.setCustomLogLevel("org.berndpruenster.netlayer", Level.DEBUG);
|
||||
|
||||
}, STARTUP_TIMEOUT_MINUTES, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
private void startP2pNetworkAndWallet(Runnable nextStep) {
|
||||
ChangeListener<Boolean> walletInitializedListener = (observable, oldValue, newValue) -> {
|
||||
// TODO that seems to be called too often if Tor takes longer to start up...
|
||||
if (newValue && !p2pNetworkReady.get() && displayTorNetworkSettingsHandler != null)
|
||||
displayTorNetworkSettingsHandler.accept(true);
|
||||
};
|
||||
|
||||
// start startup timeout
|
||||
resetStartupTimeout();
|
||||
|
||||
// reset startup timeout on progress
|
||||
getXmrDaemonSyncProgress().addListener((observable, oldValue, newValue) -> resetStartupTimeout());
|
||||
|
||||
log.info("Init P2P network");
|
||||
havenoSetupListeners.forEach(HavenoSetupListener::onInitP2pNetwork);
|
||||
@ -715,8 +723,8 @@ public class HavenoSetup {
|
||||
return walletAppSetup.getXmrInfo();
|
||||
}
|
||||
|
||||
public DoubleProperty getXmrSyncProgress() {
|
||||
return walletAppSetup.getXmrSyncProgress();
|
||||
public DoubleProperty getXmrDaemonSyncProgress() {
|
||||
return walletAppSetup.getXmrDaemonSyncProgress();
|
||||
}
|
||||
|
||||
public StringProperty getWalletServiceErrorMsg() {
|
||||
|
@ -69,7 +69,7 @@ public class WalletAppSetup {
|
||||
private MonadicBinding<String> xmrInfoBinding;
|
||||
|
||||
@Getter
|
||||
private final DoubleProperty xmrSyncProgress = new SimpleDoubleProperty(-1);
|
||||
private final DoubleProperty xmrDaemonSyncProgress = new SimpleDoubleProperty(-1);
|
||||
@Getter
|
||||
private final StringProperty walletServiceErrorMsg = new SimpleStringProperty();
|
||||
@Getter
|
||||
@ -118,23 +118,23 @@ public class WalletAppSetup {
|
||||
if (exception == null && errorMsg == null) {
|
||||
|
||||
// TODO: update for daemon and wallet sync progress
|
||||
double percentage = (double) chainDownloadPercentage;
|
||||
xmrSyncProgress.set(percentage);
|
||||
double chainDownloadPercentageD = (double) chainDownloadPercentage;
|
||||
xmrDaemonSyncProgress.set(chainDownloadPercentageD);
|
||||
Long bestChainHeight = chainHeight == null ? null : (Long) chainHeight;
|
||||
String chainHeightAsString = bestChainHeight != null && bestChainHeight > 0 ?
|
||||
String.valueOf(bestChainHeight) :
|
||||
"";
|
||||
if (percentage == 1) {
|
||||
if (chainDownloadPercentageD == 1) {
|
||||
String synchronizedWith = Res.get("mainView.footer.xmrInfo.synchronizedWith",
|
||||
getXmrNetworkAsString(), chainHeightAsString);
|
||||
String feeInfo = ""; // TODO: feeService.isFeeAvailable() returns true, disable
|
||||
result = Res.get("mainView.footer.xmrInfo", synchronizedWith, feeInfo);
|
||||
getXmrSplashSyncIconId().set("image-connection-synced");
|
||||
downloadCompleteHandler.run();
|
||||
} else if (percentage > 0.0) {
|
||||
} else if (chainDownloadPercentageD > 0.0) {
|
||||
String synchronizingWith = Res.get("mainView.footer.xmrInfo.synchronizingWith",
|
||||
getXmrNetworkAsString(), chainHeightAsString,
|
||||
FormattingUtils.formatToPercentWithSymbol(percentage));
|
||||
FormattingUtils.formatToRoundedPercentWithSymbol(chainDownloadPercentageD));
|
||||
result = Res.get("mainView.footer.xmrInfo", synchronizingWith, "");
|
||||
} else {
|
||||
result = Res.get("mainView.footer.xmrInfo",
|
||||
|
@ -422,7 +422,7 @@ public class MainViewModel implements ViewModel, HavenoSetup.HavenoSetupListener
|
||||
.warning(Res.get("popup.error.takeOfferRequestFailed", errorMessage))
|
||||
.show());
|
||||
|
||||
havenoSetup.getXmrSyncProgress().addListener((observable, oldValue, newValue) -> updateXmrSyncProgress());
|
||||
havenoSetup.getXmrDaemonSyncProgress().addListener((observable, oldValue, newValue) -> updateXmrDaemonSyncProgress());
|
||||
|
||||
havenoSetup.setFilterWarningHandler(warning -> new Popup().warning(warning).show());
|
||||
|
||||
@ -535,10 +535,9 @@ public class MainViewModel implements ViewModel, HavenoSetup.HavenoSetupListener
|
||||
}
|
||||
}
|
||||
|
||||
private void updateXmrSyncProgress() {
|
||||
final DoubleProperty xmrSyncProgress = havenoSetup.getXmrSyncProgress();
|
||||
|
||||
combinedSyncProgress.set(xmrSyncProgress.doubleValue());
|
||||
private void updateXmrDaemonSyncProgress() {
|
||||
final DoubleProperty xmrDaemonSyncProgress = havenoSetup.getXmrDaemonSyncProgress();
|
||||
combinedSyncProgress.set(xmrDaemonSyncProgress.doubleValue());
|
||||
}
|
||||
|
||||
private void setupInvalidOpenOffersHandler() {
|
||||
|
Loading…
Reference in New Issue
Block a user