From 55f62f92ddcbf78b6b311bc73e37d310b6319d79 Mon Sep 17 00:00:00 2001 From: woodser Date: Sun, 9 May 2021 11:14:58 -0400 Subject: [PATCH] sync notifications to FX thread only in desktop app (#60) daemon starting and stopping without exceptions --- .../core/btc/wallet/XmrWalletService.java | 44 +++--------- .../portfolio/pendingtrades/BuyerSubView.java | 68 ++++++++++--------- .../pendingtrades/PendingTradesView.java | 14 +++- .../pendingtrades/SellerSubView.java | 68 ++++++++++--------- 4 files changed, 94 insertions(+), 100 deletions(-) diff --git a/core/src/main/java/bisq/core/btc/wallet/XmrWalletService.java b/core/src/main/java/bisq/core/btc/wallet/XmrWalletService.java index 47c1c456ea..f182032d3c 100644 --- a/core/src/main/java/bisq/core/btc/wallet/XmrWalletService.java +++ b/core/src/main/java/bisq/core/btc/wallet/XmrWalletService.java @@ -15,8 +15,6 @@ import javax.inject.Inject; import com.google.common.util.concurrent.FutureCallback; -import javafx.application.Platform; - import java.io.File; import java.math.BigInteger; @@ -81,11 +79,7 @@ public class XmrWalletService { @Override public void onBalancesChanged(BigInteger newBalance, BigInteger newUnlockedBalance) { - Platform.runLater(new Runnable() { // jni wallet runs on separate thread which cannot update fx - @Override public void run() { - notifyBalanceListeners(); - } - }); + notifyBalanceListeners(); } }); }); @@ -324,10 +318,10 @@ public class XmrWalletService { threads.add(new Thread(new Runnable() { @Override public void run() { - System.out.println("XmrWalletServie.shutDown() closing wallet within thread!!!"); - System.out.println("Wallet balance: " + wallet.getBalance()); try { walletsSetup.getWalletConfig().closeWallet(openWallet); } - catch (Exception e) { e.printStackTrace(); } + catch (Exception e) { + e.printStackTrace(); // exception expected on shutdown when run as daemon TODO (woodser): detect if running as daemon + } } })); } @@ -415,47 +409,27 @@ public class XmrWalletService { @Override public void onSyncProgress(long height, long startHeight, long endHeight, double percentDone, String message) { - Platform.runLater(new Runnable() { // jni wallet runs on separate thread which cannot update fx - @Override public void run() { - listener.onSyncProgress(height, startHeight, endHeight, percentDone, message); - } - }); + listener.onSyncProgress(height, startHeight, endHeight, percentDone, message); } @Override public void onNewBlock(long height) { - Platform.runLater(new Runnable() { // jni wallet runs on separate thread which cannot update fx - @Override public void run() { - listener.onNewBlock(height); - } - }); + listener.onNewBlock(height); } @Override public void onBalancesChanged(BigInteger newBalance, BigInteger newUnlockedBalance) { - Platform.runLater(new Runnable() { // jni wallet runs on separate thread which cannot update fx - @Override public void run() { - listener.onBalancesChanged(newBalance, newUnlockedBalance); - } - }); + listener.onBalancesChanged(newBalance, newUnlockedBalance); } @Override public void onOutputReceived(MoneroOutputWallet output) { - Platform.runLater(new Runnable() { // jni wallet runs on separate thread which cannot update fx - @Override public void run() { - listener.onOutputReceived(output); - } - }); + listener.onOutputReceived(output); } @Override public void onOutputSpent(MoneroOutputWallet output) { - Platform.runLater(new Runnable() { // jni wallet runs on separate thread which cannot update fx - @Override public void run() { - listener.onOutputSpent(output); - } - }); + listener.onOutputSpent(output); } } } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/BuyerSubView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/BuyerSubView.java index aee1e70c63..8cce568068 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/BuyerSubView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/BuyerSubView.java @@ -29,6 +29,8 @@ import org.fxmisc.easybind.EasyBind; import lombok.extern.slf4j.Slf4j; +import javafx.application.Platform; + @Slf4j public class BuyerSubView extends TradeSubView { private TradeWizardItem step1; @@ -74,40 +76,44 @@ public class BuyerSubView extends TradeSubView { protected void onViewStateChanged(PendingTradesViewModel.State viewState) { super.onViewStateChanged(viewState); - if (viewState != null) { - PendingTradesViewModel.BuyerState buyerState = (PendingTradesViewModel.BuyerState) viewState; + Platform.runLater(new Runnable() { + @Override public void run() { + if (viewState != null) { + PendingTradesViewModel.BuyerState buyerState = (PendingTradesViewModel.BuyerState) viewState; - step1.setDisabled(); - step2.setDisabled(); - step3.setDisabled(); - step4.setDisabled(); + step1.setDisabled(); + step2.setDisabled(); + step3.setDisabled(); + step4.setDisabled(); - switch (buyerState) { - case UNDEFINED: - break; - case STEP1: - showItem(step1); - break; - case STEP2: - step1.setCompleted(); - showItem(step2); - break; - case STEP3: - step1.setCompleted(); - step2.setCompleted(); - showItem(step3); - break; - case STEP4: - step1.setCompleted(); - step2.setCompleted(); - step3.setCompleted(); - showItem(step4); - break; - default: - log.warn("unhandled buyerState " + buyerState); - break; + switch (buyerState) { + case UNDEFINED: + break; + case STEP1: + showItem(step1); + break; + case STEP2: + step1.setCompleted(); + showItem(step2); + break; + case STEP3: + step1.setCompleted(); + step2.setCompleted(); + showItem(step3); + break; + case STEP4: + step1.setCompleted(); + step2.setCompleted(); + step3.setCompleted(); + showItem(step4); + break; + default: + log.warn("unhandled buyerState " + buyerState); + break; + } + } } - } + }); } } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesView.java index 5dabe5cbed..4249ad4e56 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesView.java @@ -93,7 +93,7 @@ import javafx.geometry.Pos; import org.fxmisc.easybind.EasyBind; import org.fxmisc.easybind.Subscription; - +import javafx.application.Platform; import javafx.beans.binding.Bindings; import javafx.beans.property.ReadOnlyObjectWrapper; import javafx.beans.value.ChangeListener; @@ -618,7 +618,11 @@ public class PendingTradesView extends ActivatableViewAndModel update(); + listener = (observable, oldValue, newValue) -> Platform.runLater(new Runnable() { + @Override public void run() { + update(); + } + }); trade.stateProperty().addListener(listener); update(); } else { @@ -932,7 +936,11 @@ public class PendingTradesView extends ActivatableViewAndModel update(); + listener = (observable, oldValue, newValue) -> Platform.runLater(new Runnable() { + @Override public void run() { + update(); + } + }); trade.stateProperty().addListener(listener); update(); } else { diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/SellerSubView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/SellerSubView.java index 33d6990016..88dcdb897f 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/SellerSubView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/SellerSubView.java @@ -29,6 +29,8 @@ import org.fxmisc.easybind.EasyBind; import lombok.extern.slf4j.Slf4j; +import javafx.application.Platform; + @Slf4j public class SellerSubView extends TradeSubView { private TradeWizardItem step1; @@ -74,40 +76,44 @@ public class SellerSubView extends TradeSubView { protected void onViewStateChanged(PendingTradesViewModel.State viewState) { super.onViewStateChanged(viewState); - if (viewState != null) { - PendingTradesViewModel.SellerState sellerState = (PendingTradesViewModel.SellerState) viewState; + Platform.runLater(new Runnable() { + @Override public void run() { + if (viewState != null) { + PendingTradesViewModel.SellerState sellerState = (PendingTradesViewModel.SellerState) viewState; - step1.setDisabled(); - step2.setDisabled(); - step3.setDisabled(); - step4.setDisabled(); + step1.setDisabled(); + step2.setDisabled(); + step3.setDisabled(); + step4.setDisabled(); - switch (sellerState) { - case UNDEFINED: - break; - case STEP1: - showItem(step1); - break; - case STEP2: - step1.setCompleted(); - showItem(step2); - break; - case STEP3: - step1.setCompleted(); - step2.setCompleted(); - showItem(step3); - break; - case STEP4: - step1.setCompleted(); - step2.setCompleted(); - step3.setCompleted(); - showItem(step4); - break; - default: - log.warn("unhandled viewState " + sellerState); - break; + switch (sellerState) { + case UNDEFINED: + break; + case STEP1: + showItem(step1); + break; + case STEP2: + step1.setCompleted(); + showItem(step2); + break; + case STEP3: + step1.setCompleted(); + step2.setCompleted(); + showItem(step3); + break; + case STEP4: + step1.setCompleted(); + step2.setCompleted(); + step3.setCompleted(); + showItem(step4); + break; + default: + log.warn("unhandled viewState " + sellerState); + break; + } + } } - } + }); } }