mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-04 21:36:45 +00:00
initial setup and drag file improvements
This commit is contained in:
parent
37c3d573e0
commit
f3a7d583a5
4 changed files with 50 additions and 6 deletions
|
@ -146,7 +146,11 @@ public class AppController implements Initializable {
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
if(db.hasFiles()) {
|
if(db.hasFiles()) {
|
||||||
for(File file : db.getFiles()) {
|
for(File file : db.getFiles()) {
|
||||||
openTransactionFile(file);
|
if(isWalletFile(file)) {
|
||||||
|
openWalletFile(file);
|
||||||
|
} else {
|
||||||
|
openTransactionFile(file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
|
@ -181,6 +185,11 @@ public class AppController implements Initializable {
|
||||||
if(walletAdded || walletRemoved) {
|
if(walletAdded || walletRemoved) {
|
||||||
EventManager.get().post(new OpenWalletsEvent(getOpenWallets()));
|
EventManager.get().post(new OpenWalletsEvent(getOpenWallets()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(tabs.getTabs().isEmpty()) {
|
||||||
|
Stage tabStage = (Stage)tabs.getScene().getWindow();
|
||||||
|
tabStage.setTitle("Sparrow");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -583,6 +592,11 @@ public class AppController implements Initializable {
|
||||||
EventManager.get().post(new BitcoinUnitChangedEvent(unit));
|
EventManager.get().post(new BitcoinUnitChangedEvent(unit));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isWalletFile(File file) {
|
||||||
|
FileType fileType = IOUtils.getFileType(file);
|
||||||
|
return FileType.JSON.equals(fileType) || FileType.BINARY.equals(fileType);
|
||||||
|
}
|
||||||
|
|
||||||
public void newWallet(ActionEvent event) {
|
public void newWallet(ActionEvent event) {
|
||||||
WalletNameDialog dlg = new WalletNameDialog();
|
WalletNameDialog dlg = new WalletNameDialog();
|
||||||
Optional<String> walletName = dlg.showAndWait();
|
Optional<String> walletName = dlg.showAndWait();
|
||||||
|
|
|
@ -31,6 +31,7 @@ public class MainApp extends Application {
|
||||||
GlyphFontRegistry.register(new FontAwesome5());
|
GlyphFontRegistry.register(new FontAwesome5());
|
||||||
GlyphFontRegistry.register(new FontAwesome5Brands());
|
GlyphFontRegistry.register(new FontAwesome5Brands());
|
||||||
|
|
||||||
|
boolean createNewWallet = false;
|
||||||
Mode mode = Config.get().getMode();
|
Mode mode = Config.get().getMode();
|
||||||
if(mode == null) {
|
if(mode == null) {
|
||||||
WelcomeDialog welcomeDialog = new WelcomeDialog(getHostServices());
|
WelcomeDialog welcomeDialog = new WelcomeDialog(getHostServices());
|
||||||
|
@ -40,8 +41,9 @@ public class MainApp extends Application {
|
||||||
Config.get().setMode(mode);
|
Config.get().setMode(mode);
|
||||||
|
|
||||||
if(mode.equals(Mode.ONLINE)) {
|
if(mode.equals(Mode.ONLINE)) {
|
||||||
PreferencesDialog preferencesDialog = new PreferencesDialog(PreferenceGroup.SERVER);
|
PreferencesDialog preferencesDialog = new PreferencesDialog(PreferenceGroup.SERVER, true);
|
||||||
preferencesDialog.showAndWait();
|
Optional<Boolean> optNewWallet = preferencesDialog.showAndWait();
|
||||||
|
createNewWallet = optNewWallet.isPresent() && optNewWallet.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,6 +66,10 @@ public class MainApp extends Application {
|
||||||
|
|
||||||
stage.show();
|
stage.show();
|
||||||
|
|
||||||
|
if(createNewWallet) {
|
||||||
|
appController.newWallet(null);
|
||||||
|
}
|
||||||
|
|
||||||
List<File> recentWalletFiles = Config.get().getRecentWalletFiles();
|
List<File> recentWalletFiles = Config.get().getRecentWalletFiles();
|
||||||
if(recentWalletFiles != null) {
|
if(recentWalletFiles != null) {
|
||||||
for(File walletFile : recentWalletFiles) {
|
for(File walletFile : recentWalletFiles) {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.sparrowwallet.sparrow.io;
|
package com.sparrowwallet.sparrow.io;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
|
||||||
public class IOUtils {
|
public class IOUtils {
|
||||||
|
@ -9,6 +8,19 @@ public class IOUtils {
|
||||||
try {
|
try {
|
||||||
String type = Files.probeContentType(file.toPath());
|
String type = Files.probeContentType(file.toPath());
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
|
if(file.getName().toLowerCase().endsWith("txn") || file.getName().toLowerCase().endsWith("psbt")) {
|
||||||
|
return FileType.TEXT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(file.exists()) {
|
||||||
|
try(BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)))) {
|
||||||
|
String line = br.readLine();
|
||||||
|
if(line.startsWith("01000000") || line.startsWith("cHNid")) {
|
||||||
|
return FileType.TEXT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return FileType.BINARY;
|
return FileType.BINARY;
|
||||||
} else if (type.equals("application/json")) {
|
} else if (type.equals("application/json")) {
|
||||||
return FileType.JSON;
|
return FileType.JSON;
|
||||||
|
|
|
@ -11,12 +11,16 @@ import org.controlsfx.tools.Borders;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class PreferencesDialog extends Dialog<Void> {
|
public class PreferencesDialog extends Dialog<Boolean> {
|
||||||
public PreferencesDialog() {
|
public PreferencesDialog() {
|
||||||
this(null);
|
this(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PreferencesDialog(PreferenceGroup initialGroup) {
|
public PreferencesDialog(PreferenceGroup initialGroup) {
|
||||||
|
this(initialGroup, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PreferencesDialog(PreferenceGroup initialGroup, boolean initialSetup) {
|
||||||
final DialogPane dialogPane = getDialogPane();
|
final DialogPane dialogPane = getDialogPane();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -32,8 +36,16 @@ public class PreferencesDialog extends Dialog<Void> {
|
||||||
|
|
||||||
final ButtonType closeButtonType = new javafx.scene.control.ButtonType("Close", ButtonBar.ButtonData.CANCEL_CLOSE);
|
final ButtonType closeButtonType = new javafx.scene.control.ButtonType("Close", ButtonBar.ButtonData.CANCEL_CLOSE);
|
||||||
dialogPane.getButtonTypes().addAll(closeButtonType);
|
dialogPane.getButtonTypes().addAll(closeButtonType);
|
||||||
|
|
||||||
|
final ButtonType newWalletButtonType = new javafx.scene.control.ButtonType("Create New Wallet", ButtonBar.ButtonData.OK_DONE);
|
||||||
|
if(initialSetup) {
|
||||||
|
dialogPane.getButtonTypes().addAll(newWalletButtonType);
|
||||||
|
}
|
||||||
|
|
||||||
dialogPane.setPrefWidth(650);
|
dialogPane.setPrefWidth(650);
|
||||||
dialogPane.setPrefHeight(500);
|
dialogPane.setPrefHeight(500);
|
||||||
|
|
||||||
|
setResultConverter(dialogButton -> dialogButton == newWalletButtonType ? Boolean.TRUE : null);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue