From 9fb22f6d1fa37db6616ba00627f357f985490832 Mon Sep 17 00:00:00 2001 From: woodser Date: Tue, 28 Nov 2023 12:18:52 -0500 Subject: [PATCH] reset startup timeout on sync progress --- .../java/haveno/core/app/HavenoSetup.java | 34 ++++++++++++------- .../java/haveno/core/app/WalletAppSetup.java | 12 +++---- .../haveno/desktop/main/MainViewModel.java | 9 +++-- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/haveno/core/app/HavenoSetup.java b/core/src/main/java/haveno/core/app/HavenoSetup.java index 624e6bd2aa..7a74a3bf81 100644 --- a/core/src/main/java/haveno/core/app/HavenoSetup.java +++ b/core/src/main/java/haveno/core/app/HavenoSetup.java @@ -181,6 +181,7 @@ public class HavenoSetup { private boolean allBasicServicesInitialized; @SuppressWarnings("FieldCanBeLocal") private MonadicBinding p2pNetworkAndWalletInitialized; + private Timer startupTimeout; private final List havenoSetupListeners = new ArrayList<>(); public interface HavenoSetupListener { @@ -368,23 +369,16 @@ public class HavenoSetup { p2PService.getP2PDataStorage().readFromResources(postFix, completeHandler); } - private void startP2pNetworkAndWallet(Runnable nextStep) { - ChangeListener 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 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() { diff --git a/core/src/main/java/haveno/core/app/WalletAppSetup.java b/core/src/main/java/haveno/core/app/WalletAppSetup.java index 9c731c89c0..92410ff1a4 100644 --- a/core/src/main/java/haveno/core/app/WalletAppSetup.java +++ b/core/src/main/java/haveno/core/app/WalletAppSetup.java @@ -69,7 +69,7 @@ public class WalletAppSetup { private MonadicBinding 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", diff --git a/desktop/src/main/java/haveno/desktop/main/MainViewModel.java b/desktop/src/main/java/haveno/desktop/main/MainViewModel.java index bae021ba3e..1d27d26f48 100644 --- a/desktop/src/main/java/haveno/desktop/main/MainViewModel.java +++ b/desktop/src/main/java/haveno/desktop/main/MainViewModel.java @@ -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() {