mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-12-22 19:49:32 +00:00
sync notifications to FX thread only in desktop app (#60)
daemon starting and stopping without exceptions
This commit is contained in:
parent
fcdc627d00
commit
55f62f92dd
4 changed files with 94 additions and 100 deletions
|
@ -15,8 +15,6 @@ import javax.inject.Inject;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.FutureCallback;
|
import com.google.common.util.concurrent.FutureCallback;
|
||||||
|
|
||||||
import javafx.application.Platform;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
@ -81,13 +79,9 @@ public class XmrWalletService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBalancesChanged(BigInteger newBalance, BigInteger newUnlockedBalance) {
|
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() {
|
threads.add(new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
System.out.println("XmrWalletServie.shutDown() closing wallet within thread!!!");
|
|
||||||
System.out.println("Wallet balance: " + wallet.getBalance());
|
|
||||||
try { walletsSetup.getWalletConfig().closeWallet(openWallet); }
|
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
|
@Override
|
||||||
public void onSyncProgress(long height, long startHeight, long endHeight, double percentDone, String message) {
|
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
|
@Override
|
||||||
public void onNewBlock(long height) {
|
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
|
@Override
|
||||||
public void onBalancesChanged(BigInteger newBalance, BigInteger newUnlockedBalance) {
|
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
|
@Override
|
||||||
public void onOutputReceived(MoneroOutputWallet output) {
|
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
|
@Override
|
||||||
public void onOutputSpent(MoneroOutputWallet output) {
|
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);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@ import org.fxmisc.easybind.EasyBind;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import javafx.application.Platform;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class BuyerSubView extends TradeSubView {
|
public class BuyerSubView extends TradeSubView {
|
||||||
private TradeWizardItem step1;
|
private TradeWizardItem step1;
|
||||||
|
@ -74,6 +76,8 @@ public class BuyerSubView extends TradeSubView {
|
||||||
protected void onViewStateChanged(PendingTradesViewModel.State viewState) {
|
protected void onViewStateChanged(PendingTradesViewModel.State viewState) {
|
||||||
super.onViewStateChanged(viewState);
|
super.onViewStateChanged(viewState);
|
||||||
|
|
||||||
|
Platform.runLater(new Runnable() {
|
||||||
|
@Override public void run() {
|
||||||
if (viewState != null) {
|
if (viewState != null) {
|
||||||
PendingTradesViewModel.BuyerState buyerState = (PendingTradesViewModel.BuyerState) viewState;
|
PendingTradesViewModel.BuyerState buyerState = (PendingTradesViewModel.BuyerState) viewState;
|
||||||
|
|
||||||
|
@ -109,6 +113,8 @@ public class BuyerSubView extends TradeSubView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ import javafx.geometry.Pos;
|
||||||
|
|
||||||
import org.fxmisc.easybind.EasyBind;
|
import org.fxmisc.easybind.EasyBind;
|
||||||
import org.fxmisc.easybind.Subscription;
|
import org.fxmisc.easybind.Subscription;
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.beans.binding.Bindings;
|
import javafx.beans.binding.Bindings;
|
||||||
import javafx.beans.property.ReadOnlyObjectWrapper;
|
import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
|
@ -618,7 +618,11 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
||||||
|
|
||||||
if (item != null && !empty) {
|
if (item != null && !empty) {
|
||||||
trade = item.getTrade();
|
trade = item.getTrade();
|
||||||
listener = (observable, oldValue, newValue) -> update();
|
listener = (observable, oldValue, newValue) -> Platform.runLater(new Runnable() {
|
||||||
|
@Override public void run() {
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
});
|
||||||
trade.stateProperty().addListener(listener);
|
trade.stateProperty().addListener(listener);
|
||||||
update();
|
update();
|
||||||
} else {
|
} else {
|
||||||
|
@ -932,7 +936,11 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
||||||
super.updateItem(newItem, empty);
|
super.updateItem(newItem, empty);
|
||||||
if (!empty && newItem != null) {
|
if (!empty && newItem != null) {
|
||||||
trade = newItem.getTrade();
|
trade = newItem.getTrade();
|
||||||
listener = (observable, oldValue, newValue) -> update();
|
listener = (observable, oldValue, newValue) -> Platform.runLater(new Runnable() {
|
||||||
|
@Override public void run() {
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
});
|
||||||
trade.stateProperty().addListener(listener);
|
trade.stateProperty().addListener(listener);
|
||||||
update();
|
update();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -29,6 +29,8 @@ import org.fxmisc.easybind.EasyBind;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import javafx.application.Platform;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SellerSubView extends TradeSubView {
|
public class SellerSubView extends TradeSubView {
|
||||||
private TradeWizardItem step1;
|
private TradeWizardItem step1;
|
||||||
|
@ -74,6 +76,8 @@ public class SellerSubView extends TradeSubView {
|
||||||
protected void onViewStateChanged(PendingTradesViewModel.State viewState) {
|
protected void onViewStateChanged(PendingTradesViewModel.State viewState) {
|
||||||
super.onViewStateChanged(viewState);
|
super.onViewStateChanged(viewState);
|
||||||
|
|
||||||
|
Platform.runLater(new Runnable() {
|
||||||
|
@Override public void run() {
|
||||||
if (viewState != null) {
|
if (viewState != null) {
|
||||||
PendingTradesViewModel.SellerState sellerState = (PendingTradesViewModel.SellerState) viewState;
|
PendingTradesViewModel.SellerState sellerState = (PendingTradesViewModel.SellerState) viewState;
|
||||||
|
|
||||||
|
@ -109,6 +113,8 @@ public class SellerSubView extends TradeSubView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue