From 25c05e1461fb9e0af7eee90a6dc1afb92bc2a0af Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 30 Apr 2018 22:57:19 -0500 Subject: [PATCH 1/4] Fix bug with not showing popup when database files got corrupted. The recent changes in the startup broke the sequence if the setup for the CorruptedDataBaseFilesHandler. We read the data base files before the UI is created and the UI was set as listener to errors. So we missed the errors and did not display a popup. Fix: Use as CorruptedDataBaseFilesHandler as guice instance to store corrupted files at startup when UI is still not ready. Inject that instance in MainViewModel and shop popup in case there are corrupted files in the list. --- src/main/java/bisq/desktop/app/BisqApp.java | 13 --------- src/main/java/bisq/desktop/main/MainView.java | 22 --------------- .../java/bisq/desktop/main/MainViewModel.java | 27 ++++++++++++++++++- 3 files changed, 26 insertions(+), 36 deletions(-) diff --git a/src/main/java/bisq/desktop/app/BisqApp.java b/src/main/java/bisq/desktop/app/BisqApp.java index 661c983844..57a0efeee8 100644 --- a/src/main/java/bisq/desktop/app/BisqApp.java +++ b/src/main/java/bisq/desktop/app/BisqApp.java @@ -45,7 +45,6 @@ import bisq.common.UserThread; import bisq.common.app.DevEnv; import bisq.common.setup.GracefulShutDownHandler; import bisq.common.setup.UncaughtExceptionHandler; -import bisq.common.storage.Storage; import bisq.common.util.Profiler; import bisq.common.util.Utilities; @@ -127,8 +126,6 @@ public class BisqApp extends Application implements UncaughtExceptionHandler { scene = createAndConfigScene(mainView, injector); setupStage(scene); - setDatabaseCorruptionHandler(mainView); - checkForCorrectOSArchitecture(); UserThread.runPeriodically(() -> Profiler.printSystemLoad(log), LOG_MEMORY_PERIOD_MIN, TimeUnit.MINUTES); @@ -249,16 +246,6 @@ public class BisqApp extends Application implements UncaughtExceptionHandler { return (MainView) viewLoader.load(MainView.class); } - private void setDatabaseCorruptionHandler(MainView mainView) { - Storage.setDatabaseCorruptionHandler((String fileName) -> { - corruptedDatabaseFiles.add(fileName); - if (mainView != null) - mainView.setPersistedFilesCorrupted(corruptedDatabaseFiles); - }); - mainView.setPersistedFilesCorrupted(corruptedDatabaseFiles); - } - - private void addSceneKeyEventHandler(Scene scene, Injector injector) { scene.addEventHandler(KeyEvent.KEY_RELEASED, keyEvent -> { Utilities.isAltOrCtrlPressed(KeyCode.W, keyEvent); diff --git a/src/main/java/bisq/desktop/main/MainView.java b/src/main/java/bisq/desktop/main/MainView.java index cf2cdc4277..b50de56dd9 100644 --- a/src/main/java/bisq/desktop/main/MainView.java +++ b/src/main/java/bisq/desktop/main/MainView.java @@ -83,8 +83,6 @@ import javafx.geometry.Pos; import javafx.beans.value.ChangeListener; -import java.util.List; - import lombok.extern.slf4j.Slf4j; import static javafx.scene.layout.AnchorPane.setBottomAnchor; @@ -149,7 +147,6 @@ public class MainView extends InitializableView { private Label splashP2PNetworkLabel; private ProgressBar btcSyncIndicator; private Label btcSplashInfo; - private List persistedFilesCorrupted; private Popup p2PNetworkWarnMsgPopup, btcNetworkWarnMsgPopup; @SuppressWarnings("WeakerAccess") @@ -312,21 +309,6 @@ public class MainView extends InitializableView { if (newValue) { navigation.navigateToPreviousVisitedView(); - if (!persistedFilesCorrupted.isEmpty()) { - if (persistedFilesCorrupted.size() > 1 || !persistedFilesCorrupted.get(0).equals("ViewPathAsString")) { - // show warning that some files has been corrupted - new Popup<>() - .warning(Res.get("popup.warning.incompatibleDB", - persistedFilesCorrupted.toString(), - model.getAppDateDir())) - .useShutDownButton() - .show(); - } else { - log.debug("We detected incompatible data base file for Navigation. That is a minor issue happening with refactoring of UI classes " + - "and we don't display a warning popup to the user."); - } - } - transitions.fadeOutAndRemove(splashScreen, 1500, actionEvent -> disposeSplashScreen()); } }); @@ -464,10 +446,6 @@ public class MainView extends InitializableView { } } - public void setPersistedFilesCorrupted(List persistedFilesCorrupted) { - this.persistedFilesCorrupted = persistedFilesCorrupted; - } - private VBox createSplashScreen() { VBox vBox = new VBox(); vBox.setAlignment(Pos.CENTER); diff --git a/src/main/java/bisq/desktop/main/MainViewModel.java b/src/main/java/bisq/desktop/main/MainViewModel.java index e6addcec3e..3baea883b3 100644 --- a/src/main/java/bisq/desktop/main/MainViewModel.java +++ b/src/main/java/bisq/desktop/main/MainViewModel.java @@ -88,6 +88,7 @@ import bisq.common.app.Version; import bisq.common.crypto.CryptoException; import bisq.common.crypto.KeyRing; import bisq.common.crypto.SealedAndSigned; +import bisq.common.storage.CorruptedDataBaseFilesHandler; import org.bitcoinj.core.Address; import org.bitcoinj.core.Coin; @@ -174,6 +175,7 @@ public class MainViewModel implements ViewModel { private final ClosedTradableManager closedTradableManager; private final AccountAgeWitnessService accountAgeWitnessService; final TorNetworkSettingsWindow torNetworkSettingsWindow; + private final CorruptedDataBaseFilesHandler corruptedDataBaseFilesHandler; private final BSFormatter formatter; // BTC network @@ -248,7 +250,8 @@ public class MainViewModel implements ViewModel { DaoSetup daoSetup, EncryptionService encryptionService, KeyRing keyRing, BisqEnvironment bisqEnvironment, FailedTradesManager failedTradesManager, ClosedTradableManager closedTradableManager, AccountAgeWitnessService accountAgeWitnessService, - TorNetworkSettingsWindow torNetworkSettingsWindow, BSFormatter formatter) { + TorNetworkSettingsWindow torNetworkSettingsWindow, CorruptedDataBaseFilesHandler corruptedDataBaseFilesHandler, + BSFormatter formatter) { this.walletsManager = walletsManager; this.walletsSetup = walletsSetup; this.btcWalletService = btcWalletService; @@ -277,6 +280,7 @@ public class MainViewModel implements ViewModel { this.closedTradableManager = closedTradableManager; this.accountAgeWitnessService = accountAgeWitnessService; this.torNetworkSettingsWindow = torNetworkSettingsWindow; + this.corruptedDataBaseFilesHandler = corruptedDataBaseFilesHandler; this.formatter = formatter; TxIdTextField.setPreferences(preferences); @@ -707,6 +711,8 @@ public class MainViewModel implements ViewModel { if (walletsSetup.downloadPercentageProperty().get() == 1) checkForLockedUpFunds(); + checkForCorruptedDataBaseFiles(); + allBasicServicesInitialized = true; } @@ -1262,6 +1268,25 @@ public class MainViewModel implements ViewModel { } } + private void checkForCorruptedDataBaseFiles() { + List files = corruptedDataBaseFilesHandler.getCorruptedDatabaseFiles(); + if (!files.isEmpty()) { + if (files.size() > 1 || !files.get(0).equals("ViewPathAsString")) { + // show warning that some files has been corrupted + new Popup<>() + .warning(Res.get("popup.warning.incompatibleDB", + files.toString(), + getAppDateDir())) + .useShutDownButton() + .show(); + } else { + log.debug("We detected incompatible data base file for Navigation. " + + "That is a minor issue happening with refactoring of UI classes " + + "and we don't display a warning popup to the user."); + } + } + } + private void setupDevDummyPaymentAccounts() { if (user.getPaymentAccounts() != null && user.getPaymentAccounts().isEmpty()) { PerfectMoneyAccount perfectMoneyAccount = new PerfectMoneyAccount(); From 294da24c6380a6f740618950dc3b4558eb2c46d6 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Tue, 1 May 2018 13:02:03 +0200 Subject: [PATCH 2/4] Improve readability by avoiding nested conditionals --- .../java/bisq/desktop/main/MainViewModel.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/bisq/desktop/main/MainViewModel.java b/src/main/java/bisq/desktop/main/MainViewModel.java index 3baea883b3..e8585fc34b 100644 --- a/src/main/java/bisq/desktop/main/MainViewModel.java +++ b/src/main/java/bisq/desktop/main/MainViewModel.java @@ -1270,21 +1270,22 @@ public class MainViewModel implements ViewModel { private void checkForCorruptedDataBaseFiles() { List files = corruptedDataBaseFilesHandler.getCorruptedDatabaseFiles(); - if (!files.isEmpty()) { - if (files.size() > 1 || !files.get(0).equals("ViewPathAsString")) { - // show warning that some files has been corrupted - new Popup<>() - .warning(Res.get("popup.warning.incompatibleDB", - files.toString(), - getAppDateDir())) - .useShutDownButton() - .show(); - } else { - log.debug("We detected incompatible data base file for Navigation. " + - "That is a minor issue happening with refactoring of UI classes " + - "and we don't display a warning popup to the user."); - } + + if (files.size() == 0) + return; + + if (files.size() == 1 && files.get(0).equals("ViewPathAsString")) { + log.debug("We detected incompatible data base file for Navigation. " + + "That is a minor issue happening with refactoring of UI classes " + + "and we don't display a warning popup to the user."); + return; } + + // show warning that some files have been corrupted + new Popup<>() + .warning(Res.get("popup.warning.incompatibleDB", files.toString(), getAppDateDir())) + .useShutDownButton() + .show(); } private void setupDevDummyPaymentAccounts() { From 03a97dfde3ffc02ab29d19832f032b8349c7782e Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Tue, 1 May 2018 13:25:50 +0200 Subject: [PATCH 3/4] Capitalize as "Database" vs "DataBase" --- src/main/java/bisq/desktop/main/MainViewModel.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/bisq/desktop/main/MainViewModel.java b/src/main/java/bisq/desktop/main/MainViewModel.java index e8585fc34b..2029f71dc2 100644 --- a/src/main/java/bisq/desktop/main/MainViewModel.java +++ b/src/main/java/bisq/desktop/main/MainViewModel.java @@ -88,7 +88,7 @@ import bisq.common.app.Version; import bisq.common.crypto.CryptoException; import bisq.common.crypto.KeyRing; import bisq.common.crypto.SealedAndSigned; -import bisq.common.storage.CorruptedDataBaseFilesHandler; +import bisq.common.storage.CorruptedDatabaseFilesHandler; import org.bitcoinj.core.Address; import org.bitcoinj.core.Coin; @@ -175,7 +175,7 @@ public class MainViewModel implements ViewModel { private final ClosedTradableManager closedTradableManager; private final AccountAgeWitnessService accountAgeWitnessService; final TorNetworkSettingsWindow torNetworkSettingsWindow; - private final CorruptedDataBaseFilesHandler corruptedDataBaseFilesHandler; + private final CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler; private final BSFormatter formatter; // BTC network @@ -250,7 +250,7 @@ public class MainViewModel implements ViewModel { DaoSetup daoSetup, EncryptionService encryptionService, KeyRing keyRing, BisqEnvironment bisqEnvironment, FailedTradesManager failedTradesManager, ClosedTradableManager closedTradableManager, AccountAgeWitnessService accountAgeWitnessService, - TorNetworkSettingsWindow torNetworkSettingsWindow, CorruptedDataBaseFilesHandler corruptedDataBaseFilesHandler, + TorNetworkSettingsWindow torNetworkSettingsWindow, CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler, BSFormatter formatter) { this.walletsManager = walletsManager; this.walletsSetup = walletsSetup; @@ -280,7 +280,7 @@ public class MainViewModel implements ViewModel { this.closedTradableManager = closedTradableManager; this.accountAgeWitnessService = accountAgeWitnessService; this.torNetworkSettingsWindow = torNetworkSettingsWindow; - this.corruptedDataBaseFilesHandler = corruptedDataBaseFilesHandler; + this.corruptedDatabaseFilesHandler = corruptedDatabaseFilesHandler; this.formatter = formatter; TxIdTextField.setPreferences(preferences); @@ -1269,7 +1269,7 @@ public class MainViewModel implements ViewModel { } private void checkForCorruptedDataBaseFiles() { - List files = corruptedDataBaseFilesHandler.getCorruptedDatabaseFiles(); + List files = corruptedDatabaseFilesHandler.getCorruptedDatabaseFiles(); if (files.size() == 0) return; From 1d2e86c280e29c745733c0c51d30be76937ccb1a Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Tue, 1 May 2018 13:29:09 +0200 Subject: [PATCH 4/4] Wrap code at 120 characters (bisq-network/style#3) --- src/main/java/bisq/desktop/main/MainViewModel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/bisq/desktop/main/MainViewModel.java b/src/main/java/bisq/desktop/main/MainViewModel.java index 2029f71dc2..29b157c49e 100644 --- a/src/main/java/bisq/desktop/main/MainViewModel.java +++ b/src/main/java/bisq/desktop/main/MainViewModel.java @@ -250,8 +250,8 @@ public class MainViewModel implements ViewModel { DaoSetup daoSetup, EncryptionService encryptionService, KeyRing keyRing, BisqEnvironment bisqEnvironment, FailedTradesManager failedTradesManager, ClosedTradableManager closedTradableManager, AccountAgeWitnessService accountAgeWitnessService, - TorNetworkSettingsWindow torNetworkSettingsWindow, CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler, - BSFormatter formatter) { + TorNetworkSettingsWindow torNetworkSettingsWindow, + CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler, BSFormatter formatter) { this.walletsManager = walletsManager; this.walletsSetup = walletsSetup; this.btcWalletService = btcWalletService;