Search in sources :

Example 1 with PreferencesDialog

use of com.sparrowwallet.sparrow.preferences.PreferencesDialog in project sparrow by sparrowwallet.

the class MainApp method start.

@Override
public void start(Stage stage) throws Exception {
    this.mainStage = stage;
    GlyphFontRegistry.register(new FontAwesome5());
    GlyphFontRegistry.register(new FontAwesome5Brands());
    Font.loadFont(AppServices.class.getResourceAsStream("/font/RobotoMono-Regular.ttf"), 13);
    AppServices.initialize(this);
    boolean createNewWallet = false;
    Mode mode = Config.get().getMode();
    if (mode == null) {
        WelcomeDialog welcomeDialog = new WelcomeDialog();
        Optional<Mode> optionalMode = welcomeDialog.showAndWait();
        if (optionalMode.isPresent()) {
            mode = optionalMode.get();
            Config.get().setMode(mode);
            if (mode.equals(Mode.ONLINE)) {
                PreferencesDialog preferencesDialog = new PreferencesDialog(PreferenceGroup.SERVER, true);
                Optional<Boolean> optNewWallet = preferencesDialog.showAndWait();
                createNewWallet = optNewWallet.isPresent() && optNewWallet.get();
            } else if (Network.get() == Network.MAINNET) {
                Config.get().setServerType(ServerType.PUBLIC_ELECTRUM_SERVER);
                List<PublicElectrumServer> servers = PublicElectrumServer.getServers();
                Config.get().setPublicElectrumServer(servers.get(new Random().nextInt(servers.size())).getUrl());
            }
        }
    }
    if (Config.get().getServerType() == null && Config.get().getCoreServer() == null && Config.get().getElectrumServer() != null) {
        Config.get().setServerType(ServerType.ELECTRUM_SERVER);
    }
    if (Config.get().getHdCapture() == null && Platform.getCurrent() == Platform.OSX) {
        Config.get().setHdCapture(Boolean.TRUE);
    }
    System.setProperty(Wallet.ALLOW_DERIVATIONS_MATCHING_OTHER_SCRIPT_TYPES_PROPERTY, Boolean.toString(!Config.get().isValidateDerivationPaths()));
    if (Config.get().getAppHeight() != null && Config.get().getAppWidth() != null) {
        mainStage.setWidth(Config.get().getAppWidth());
        mainStage.setHeight(Config.get().getAppHeight());
    }
    AppController appController = AppServices.newAppWindow(stage);
    if (createNewWallet) {
        appController.newWallet(null);
    }
    List<File> recentWalletFiles = Config.get().getRecentWalletFiles();
    if (recentWalletFiles != null) {
        // Preserve wallet order as far as possible. Unencrypted wallets will still be opened first.
        List<File> encryptedWalletFiles = recentWalletFiles.stream().filter(Storage::isEncrypted).collect(Collectors.toList());
        List<File> sortedWalletFiles = new ArrayList<>(recentWalletFiles);
        sortedWalletFiles.removeAll(encryptedWalletFiles);
        sortedWalletFiles.addAll(encryptedWalletFiles);
        for (File walletFile : sortedWalletFiles) {
            if (walletFile.exists()) {
                appController.openWalletFile(walletFile, false);
            }
        }
    }
    AppServices.openFileUriArguments(stage);
    AppServices.get().start();
}
Also used : FontAwesome5(com.sparrowwallet.sparrow.glyphfont.FontAwesome5) PreferencesDialog(com.sparrowwallet.sparrow.preferences.PreferencesDialog) FontAwesome5Brands(com.sparrowwallet.sparrow.glyphfont.FontAwesome5Brands) InstanceList(com.sparrowwallet.sparrow.instance.InstanceList) File(java.io.File)

Aggregations

FontAwesome5 (com.sparrowwallet.sparrow.glyphfont.FontAwesome5)1 FontAwesome5Brands (com.sparrowwallet.sparrow.glyphfont.FontAwesome5Brands)1 InstanceList (com.sparrowwallet.sparrow.instance.InstanceList)1 PreferencesDialog (com.sparrowwallet.sparrow.preferences.PreferencesDialog)1 File (java.io.File)1