mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-02 20:36:44 +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;
|
||||
if(db.hasFiles()) {
|
||||
for(File file : db.getFiles()) {
|
||||
openTransactionFile(file);
|
||||
if(isWalletFile(file)) {
|
||||
openWalletFile(file);
|
||||
} else {
|
||||
openTransactionFile(file);
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
}
|
||||
|
@ -181,6 +185,11 @@ public class AppController implements Initializable {
|
|||
if(walletAdded || walletRemoved) {
|
||||
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));
|
||||
}
|
||||
|
||||
private boolean isWalletFile(File file) {
|
||||
FileType fileType = IOUtils.getFileType(file);
|
||||
return FileType.JSON.equals(fileType) || FileType.BINARY.equals(fileType);
|
||||
}
|
||||
|
||||
public void newWallet(ActionEvent event) {
|
||||
WalletNameDialog dlg = new WalletNameDialog();
|
||||
Optional<String> walletName = dlg.showAndWait();
|
||||
|
|
|
@ -31,6 +31,7 @@ public class MainApp extends Application {
|
|||
GlyphFontRegistry.register(new FontAwesome5());
|
||||
GlyphFontRegistry.register(new FontAwesome5Brands());
|
||||
|
||||
boolean createNewWallet = false;
|
||||
Mode mode = Config.get().getMode();
|
||||
if(mode == null) {
|
||||
WelcomeDialog welcomeDialog = new WelcomeDialog(getHostServices());
|
||||
|
@ -40,8 +41,9 @@ public class MainApp extends Application {
|
|||
Config.get().setMode(mode);
|
||||
|
||||
if(mode.equals(Mode.ONLINE)) {
|
||||
PreferencesDialog preferencesDialog = new PreferencesDialog(PreferenceGroup.SERVER);
|
||||
preferencesDialog.showAndWait();
|
||||
PreferencesDialog preferencesDialog = new PreferencesDialog(PreferenceGroup.SERVER, true);
|
||||
Optional<Boolean> optNewWallet = preferencesDialog.showAndWait();
|
||||
createNewWallet = optNewWallet.isPresent() && optNewWallet.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +66,10 @@ public class MainApp extends Application {
|
|||
|
||||
stage.show();
|
||||
|
||||
if(createNewWallet) {
|
||||
appController.newWallet(null);
|
||||
}
|
||||
|
||||
List<File> recentWalletFiles = Config.get().getRecentWalletFiles();
|
||||
if(recentWalletFiles != null) {
|
||||
for(File walletFile : recentWalletFiles) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.sparrowwallet.sparrow.io;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class IOUtils {
|
||||
|
@ -9,6 +8,19 @@ public class IOUtils {
|
|||
try {
|
||||
String type = Files.probeContentType(file.toPath());
|
||||
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;
|
||||
} else if (type.equals("application/json")) {
|
||||
return FileType.JSON;
|
||||
|
|
|
@ -11,12 +11,16 @@ import org.controlsfx.tools.Borders;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
public class PreferencesDialog extends Dialog<Void> {
|
||||
public class PreferencesDialog extends Dialog<Boolean> {
|
||||
public PreferencesDialog() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public PreferencesDialog(PreferenceGroup initialGroup) {
|
||||
this(initialGroup, false);
|
||||
}
|
||||
|
||||
public PreferencesDialog(PreferenceGroup initialGroup, boolean initialSetup) {
|
||||
final DialogPane dialogPane = getDialogPane();
|
||||
|
||||
try {
|
||||
|
@ -32,8 +36,16 @@ public class PreferencesDialog extends Dialog<Void> {
|
|||
|
||||
final ButtonType closeButtonType = new javafx.scene.control.ButtonType("Close", ButtonBar.ButtonData.CANCEL_CLOSE);
|
||||
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.setPrefHeight(500);
|
||||
|
||||
setResultConverter(dialogButton -> dialogButton == newWalletButtonType ? Boolean.TRUE : null);
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue