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