fix threading issue on terminal wallet load

This commit is contained in:
Craig Raw 2022-10-11 12:16:18 +02:00
parent 778564a954
commit 81cde4756a

View file

@ -52,7 +52,10 @@ public class LoadWallet implements Runnable {
loadWalletService.setExecutor(Storage.LoadWalletService.getSingleThreadedExecutor()); loadWalletService.setExecutor(Storage.LoadWalletService.getSingleThreadedExecutor());
loadWalletService.setOnSucceeded(workerStateEvent -> { loadWalletService.setOnSucceeded(workerStateEvent -> {
WalletAndKey walletAndKey = loadWalletService.getValue(); WalletAndKey walletAndKey = loadWalletService.getValue();
SparrowTerminal.get().getGuiThread().invokeLater(() -> openWallet(storage, walletAndKey)); SparrowTerminal.get().getGuiThread().invokeLater(() -> {
SparrowTerminal.get().getGui().removeWindow(loadingDialog);
Platform.runLater(() -> openWallet(storage, walletAndKey));
});
}); });
loadWalletService.setOnFailed(workerStateEvent -> { loadWalletService.setOnFailed(workerStateEvent -> {
Throwable exception = workerStateEvent.getSource().getException(); Throwable exception = workerStateEvent.getSource().getException();
@ -77,7 +80,10 @@ public class LoadWallet implements Runnable {
loadWalletService.setOnSucceeded(workerStateEvent -> { loadWalletService.setOnSucceeded(workerStateEvent -> {
EventManager.get().post(new StorageEvent(storage.getWalletId(null), TimedEvent.Action.END, "Done")); EventManager.get().post(new StorageEvent(storage.getWalletId(null), TimedEvent.Action.END, "Done"));
WalletAndKey walletAndKey = loadWalletService.getValue(); WalletAndKey walletAndKey = loadWalletService.getValue();
SparrowTerminal.get().getGuiThread().invokeLater(() -> openWallet(storage, walletAndKey)); SparrowTerminal.get().getGuiThread().invokeLater(() -> {
SparrowTerminal.get().getGui().removeWindow(loadingDialog);
Platform.runLater(() -> openWallet(storage, walletAndKey));
});
}); });
loadWalletService.setOnFailed(workerStateEvent -> { loadWalletService.setOnFailed(workerStateEvent -> {
EventManager.get().post(new StorageEvent(storage.getWalletId(null), TimedEvent.Action.END, "Failed")); EventManager.get().post(new StorageEvent(storage.getWalletId(null), TimedEvent.Action.END, "Failed"));
@ -108,8 +114,6 @@ public class LoadWallet implements Runnable {
} }
private void openWallet(Storage storage, WalletAndKey walletAndKey) { private void openWallet(Storage storage, WalletAndKey walletAndKey) {
SparrowTerminal.get().getGui().removeWindow(loadingDialog);
try { try {
storage.restorePublicKeysFromSeed(walletAndKey.getWallet(), walletAndKey.getKey()); storage.restorePublicKeysFromSeed(walletAndKey.getWallet(), walletAndKey.getKey());
if(!walletAndKey.getWallet().isValid()) { if(!walletAndKey.getWallet().isValid()) {
@ -120,7 +124,7 @@ public class LoadWallet implements Runnable {
openWallet(entry.getValue(), entry.getKey()); openWallet(entry.getValue(), entry.getKey());
} }
if(walletAndKey.getWallet().isMasterWallet()) { if(walletAndKey.getWallet().isMasterWallet()) {
getOpeningDialog(walletAndKey.getWallet()).showDialog(SparrowTerminal.get().getGui()); SparrowTerminal.get().getGuiThread().invokeLater(() -> getOpeningDialog(walletAndKey.getWallet()).showDialog(SparrowTerminal.get().getGui()));
} }
} catch(Exception e) { } catch(Exception e) {
log.error("Wallet Error", e); log.error("Wallet Error", e);
@ -131,7 +135,6 @@ public class LoadWallet implements Runnable {
} }
private void addWallet(Storage storage, Wallet wallet) { private void addWallet(Storage storage, Wallet wallet) {
Platform.runLater(() -> {
if(wallet.isNested()) { if(wallet.isNested()) {
WalletData walletData = SparrowTerminal.get().getWalletData().get(wallet.getMasterWallet()); WalletData walletData = SparrowTerminal.get().getWalletData().get(wallet.getMasterWallet());
WalletForm walletForm = new WalletForm(storage, wallet); WalletForm walletForm = new WalletForm(storage, wallet);
@ -155,7 +158,6 @@ public class LoadWallet implements Runnable {
} }
EventManager.get().post(new WalletOpenedEvent(storage, wallet)); EventManager.get().post(new WalletOpenedEvent(storage, wallet));
});
} }
public static DialogWindow getOpeningDialog(Wallet masterWallet) { public static DialogWindow getOpeningDialog(Wallet masterWallet) {