mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2026-08-11 09:08:02 +00:00
suggest configuring a custom wallets directory when opening a wallet from a non-default location
This commit is contained in:
@@ -1140,12 +1140,37 @@ public class AppController implements Initializable {
|
||||
AppServices.moveToActiveWindowScreen(window, 800, 450);
|
||||
List<File> files = fileChooser.showOpenMultipleDialog(window);
|
||||
if(files != null) {
|
||||
configureWalletsDir(files);
|
||||
for(File file : files) {
|
||||
openWalletFile(file, forceSameWindow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void configureWalletsDir(List<File> files) {
|
||||
List<File> parentDirs = files.stream().map(File::getParentFile).distinct().collect(Collectors.toList());
|
||||
if(parentDirs.size() == 1 && !Boolean.FALSE.equals(Config.get().getSuggestChangeWalletsDir())) {
|
||||
File selectedDir = parentDirs.getFirst();
|
||||
boolean sameDir;
|
||||
try {
|
||||
sameDir = Files.isSameFile(selectedDir.toPath(), Storage.getWalletsDir().toPath());
|
||||
} catch(IOException e) {
|
||||
sameDir = selectedDir.toPath().normalize().equals(Storage.getWalletsDir().toPath().normalize());
|
||||
}
|
||||
if(!sameDir) {
|
||||
ConfirmationAlert alert = new ConfirmationAlert("Change wallets directory?",
|
||||
"Do you want to configure Sparrow to use " + selectedDir + " as the default wallets directory?", ButtonType.NO, ButtonType.YES);
|
||||
Optional<ButtonType> optType = alert.showAndWait();
|
||||
if(optType.isPresent() && optType.get() == ButtonType.YES) {
|
||||
Config.get().setWalletsDir(selectedDir);
|
||||
Config.get().setSuggestChangeWalletsDir(null);
|
||||
} else if(alert.isDontAskAgain()) {
|
||||
Config.get().setSuggestChangeWalletsDir(Boolean.FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void openWalletFile(File file, boolean forceSameWindow) {
|
||||
try {
|
||||
Storage storage = new Storage(file);
|
||||
|
||||
@@ -59,6 +59,8 @@ public class Config {
|
||||
private Boolean connectToBroadcast;
|
||||
private Boolean connectToResolve;
|
||||
private Boolean suggestSendToMany;
|
||||
private Boolean suggestChangeWalletsDir;
|
||||
private File walletsDir;
|
||||
private List<File> recentWalletFiles;
|
||||
private Integer keyDerivationPeriod;
|
||||
private long dustAttackThreshold = DUST_ATTACK_THRESHOLD_SATS;
|
||||
@@ -406,6 +408,24 @@ public class Config {
|
||||
flush();
|
||||
}
|
||||
|
||||
public Boolean getSuggestChangeWalletsDir() {
|
||||
return suggestChangeWalletsDir;
|
||||
}
|
||||
|
||||
public void setSuggestChangeWalletsDir(Boolean suggestChangeWalletsDir) {
|
||||
this.suggestChangeWalletsDir = suggestChangeWalletsDir;
|
||||
flush();
|
||||
}
|
||||
|
||||
public File getWalletsDir() {
|
||||
return walletsDir;
|
||||
}
|
||||
|
||||
public void setWalletsDir(File walletsDir) {
|
||||
this.walletsDir = walletsDir;
|
||||
flush();
|
||||
}
|
||||
|
||||
public List<File> getRecentWalletFiles() {
|
||||
return recentWalletFiles;
|
||||
}
|
||||
|
||||
@@ -485,7 +485,16 @@ public class Storage {
|
||||
}
|
||||
|
||||
public static File getWalletsDir() {
|
||||
File walletsDir = new File(getSparrowDir(), WALLETS_DIR);
|
||||
File walletsDir = Config.get().getWalletsDir();
|
||||
if(walletsDir != null) {
|
||||
if(!walletsDir.exists() && (walletsDir.getParentFile() == null || !walletsDir.getParentFile().exists() || !walletsDir.getParentFile().canWrite())) {
|
||||
log.info("Configured wallets directory " + walletsDir.getAbsolutePath() + " is not reachable, reverting to default");
|
||||
walletsDir = null;
|
||||
}
|
||||
}
|
||||
if(walletsDir == null) {
|
||||
walletsDir = new File(getSparrowDir(), WALLETS_DIR);
|
||||
}
|
||||
if(!walletsDir.exists()) {
|
||||
createOwnerOnlyDirectory(walletsDir);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user