ensure order of unencrypted wallet tabs is retained across restarts

This commit is contained in:
Craig Raw 2022-03-31 11:42:46 +02:00
parent 58cd50f674
commit d9bba16eb6
2 changed files with 15 additions and 0 deletions

View file

@ -893,6 +893,7 @@ public class AppController implements Initializable {
Storage storage = new Storage(file); Storage storage = new Storage(file);
if(!storage.isEncrypted()) { if(!storage.isEncrypted()) {
Storage.LoadWalletService loadWalletService = new Storage.LoadWalletService(storage); Storage.LoadWalletService loadWalletService = new Storage.LoadWalletService(storage);
loadWalletService.setExecutor(Storage.LoadWalletService.getSingleThreadedExecutor());
loadWalletService.setOnSucceeded(workerStateEvent -> { loadWalletService.setOnSucceeded(workerStateEvent -> {
WalletAndKey walletAndKey = loadWalletService.getValue(); WalletAndKey walletAndKey = loadWalletService.getValue();
openWallet(storage, walletAndKey, this, forceSameWindow); openWallet(storage, walletAndKey, this, forceSameWindow);

View file

@ -8,6 +8,7 @@ import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.sparrow.MainApp; import com.sparrowwallet.sparrow.MainApp;
import javafx.concurrent.Service; import javafx.concurrent.Service;
import javafx.concurrent.Task; import javafx.concurrent.Task;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.controlsfx.tools.Platform; import org.controlsfx.tools.Platform;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -22,6 +23,8 @@ import java.security.cert.CertificateEncodingException;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -509,6 +512,8 @@ public class Storage {
private final Storage storage; private final Storage storage;
private final SecureString password; private final SecureString password;
private static Executor singleThreadedExecutor;
public LoadWalletService(Storage storage) { public LoadWalletService(Storage storage) {
this.storage = storage; this.storage = storage;
this.password = null; this.password = null;
@ -536,6 +541,15 @@ public class Storage {
} }
}; };
} }
public static Executor getSingleThreadedExecutor() {
if(singleThreadedExecutor == null) {
BasicThreadFactory factory = new BasicThreadFactory.Builder().namingPattern("LoadWalletService-single").daemon(true).priority(Thread.MIN_PRIORITY).build();
singleThreadedExecutor = Executors.newSingleThreadScheduledExecutor(factory);
}
return singleThreadedExecutor;
}
} }
public static class KeyDerivationService extends Service<ECKey> { public static class KeyDerivationService extends Service<ECKey> {