Search in sources :

Example 1 with DaemonInfo

use of com.vaklinov.zcashui.ZCashInstallationObserver.DaemonInfo in project zencash-swing-wallet-ui by ZencashOfficial.

the class DashboardPanel method updateDaemonStatusLabel.

private void updateDaemonStatusLabel() throws IOException, InterruptedException, WalletCallException {
    DaemonInfo daemonInfo = this.daemonInfoGatheringThread.getLastData();
    // It is possible there has been no gathering initially
    if (daemonInfo == null) {
        return;
    }
    String daemonStatus = langUtil.getString("panel.dashboard.deamon.status.running");
    if (daemonInfo.status != DAEMON_STATUS.RUNNING) {
        daemonStatus = langUtil.getString("panel.dashboard.deamon.status.not.running");
    }
    String runtimeInfo = "";
    // If the virtual size/CPU are 0 - do not show them
    String virtual = "";
    if (daemonInfo.virtualSizeMB > 0) {
        virtual = langUtil.getString("panel.dashboard.deamon.info.virtual", daemonInfo.virtualSizeMB);
    }
    String cpuPercentage = "";
    if (daemonInfo.cpuPercentage > 0) {
        cpuPercentage = langUtil.getString("panel.dashboard.deamon.info.cpu", daemonInfo.cpuPercentage);
    }
    if (daemonInfo.status == DAEMON_STATUS.RUNNING) {
        runtimeInfo = langUtil.getString("panel.dashboard.deamon.runtime.info", daemonInfo.residentSizeMB, virtual, cpuPercentage);
    }
    // TODO: what if ZCash directory is non-default...
    File walletDAT = new File(OSUtil.getBlockchainDirectory() + "/wallet.dat");
    if (this.installationObserver.isOnTestNet()) {
        walletDAT = new File(OSUtil.getBlockchainDirectory() + "/testnet3" + "/wallet.dat");
    }
    if (this.OSInfo == null) {
        this.OSInfo = OSUtil.getSystemInfo();
    }
    String walletEncryption = "";
    // TODO: Use a one-off data gathering thread - better design
    if (this.walletIsEncrypted != null) {
        String encryptionText = (this.walletIsEncrypted ? "" : langUtil.getString("panel.dashboard.deamon.status.not")) + langUtil.getString("panel.dashboard.deamon.status.encrypted");
        walletEncryption = langUtil.getString("panel.dashboard.deamon.status.walletencrypted.text", encryptionText);
    }
    String text = langUtil.getString("panel.dashboard.deamon.status.text", daemonStatus, runtimeInfo, walletDAT.getCanonicalPath(), walletEncryption, OSUtil.getProgramDirectory(), OSUtil.getBlockchainDirectory(), this.OSInfo);
    this.daemonStatusLabel.setText(text);
}
Also used : DaemonInfo(com.vaklinov.zcashui.ZCashInstallationObserver.DaemonInfo) File(java.io.File)

Example 2 with DaemonInfo

use of com.vaklinov.zcashui.ZCashInstallationObserver.DaemonInfo in project zencash-swing-wallet-ui by ZencashOfficial.

the class ZCashUI method main.

public static void main(String[] argv) throws IOException {
    try {
        OS_TYPE os = OSUtil.getOSType();
        if ((os == OS_TYPE.WINDOWS) || (os == OS_TYPE.MAC_OS)) {
            possiblyCreateZENConfigFile();
        }
        LanguageUtil langUtil = LanguageUtil.instance();
        Log.info("Starting ZENCash Swing Wallet ...");
        Log.info("OS: " + System.getProperty("os.name") + " = " + os);
        Log.info("Current directory: " + new File(".").getCanonicalPath());
        Log.info("Class path: " + System.getProperty("java.class.path"));
        Log.info("Environment PATH: " + System.getenv("PATH"));
        // Look and feel settings - a custom OS-look and feel is set for Windows
        if (os == OS_TYPE.WINDOWS) {
            // Custom Windows L&F and font settings
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        // This font looks good but on Windows 7 it misses some chars like the stars...
        // FontUIResource font = new FontUIResource("Lucida Sans Unicode", Font.PLAIN, 11);
        // UIManager.put("Table.font", font);
        } else if (os == OS_TYPE.MAC_OS) {
            // The MacOS L&F is active by default - the property sets the menu bar Mac style
            System.setProperty("apple.laf.useScreenMenuBar", "true");
        } else {
            for (LookAndFeelInfo ui : UIManager.getInstalledLookAndFeels()) {
                Log.info("Available look and feel: " + ui.getName() + " " + ui.getClassName());
                if (ui.getName().equals("Nimbus")) {
                    Log.info("Setting look and feel: {0}", ui.getClassName());
                    UIManager.setLookAndFeel(ui.getClassName());
                    break;
                }
                ;
            }
        }
        // If zend is currently not running, do a startup of the daemon as a child process
        // It may be started but not ready - then also show dialog
        ZCashInstallationObserver initialInstallationObserver = new ZCashInstallationObserver(OSUtil.getProgramDirectory());
        DaemonInfo zcashdInfo = initialInstallationObserver.getDaemonInfo();
        initialInstallationObserver = null;
        ZCashClientCaller initialClientCaller = new ZCashClientCaller(OSUtil.getProgramDirectory());
        boolean daemonStartInProgress = false;
        try {
            if (zcashdInfo.status == DAEMON_STATUS.RUNNING) {
                NetworkAndBlockchainInfo info = initialClientCaller.getNetworkAndBlockchainInfo();
                // If more than 20 minutes behind in the blockchain - startup in progress
                if ((System.currentTimeMillis() - info.lastBlockDate.getTime()) > (20 * 60 * 1000)) {
                    Log.info("Current blockchain synchronization date is " + new Date(info.lastBlockDate.getTime()));
                    daemonStartInProgress = true;
                }
            }
        } catch (WalletCallException wce) {
            if (// Started but not ready
            (wce.getMessage().indexOf("{\"code\":-28") != -1) || (wce.getMessage().indexOf("error code: -28") != -1)) {
                Log.info("zend is currently starting...");
                daemonStartInProgress = true;
            }
        }
        StartupProgressDialog startupBar = null;
        if ((zcashdInfo.status != DAEMON_STATUS.RUNNING) || (daemonStartInProgress)) {
            Log.info("zend is not runing at the moment or has not started/synchronized 100% - showing splash...");
            startupBar = new StartupProgressDialog(initialClientCaller);
            startupBar.setVisible(true);
            startupBar.waitForStartup();
        }
        initialClientCaller = null;
        // Main GUI is created here
        ZCashUI ui = new ZCashUI(startupBar);
        ui.setVisible(true);
    } catch (InstallationDetectionException ide) {
        Log.error("Unexpected error: ", ide);
        JOptionPane.showMessageDialog(null, LanguageUtil.instance().getString("main.frame.option.pane.installation.error.text", OSUtil.getProgramDirectory(), ide.getMessage()), LanguageUtil.instance().getString("main.frame.option.pane.installation.error.title"), JOptionPane.ERROR_MESSAGE);
        System.exit(1);
    } catch (WalletCallException wce) {
        Log.error("Unexpected error: ", wce);
        if ((wce.getMessage().indexOf("{\"code\":-28,\"message\"") != -1) || (wce.getMessage().indexOf("error code: -28") != -1)) {
            JOptionPane.showMessageDialog(null, LanguageUtil.instance().getString("main.frame.option.pane.wallet.communication.error.text"), LanguageUtil.instance().getString("main.frame.option.pane.wallet.communication.error.title"), JOptionPane.ERROR_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(null, LanguageUtil.instance().getString("main.frame.option.pane.wallet.communication.error.2.text", wce.getMessage()), LanguageUtil.instance().getString("main.frame.option.pane.wallet.communication.error.2.title"), JOptionPane.ERROR_MESSAGE);
        }
        System.exit(2);
    } catch (Exception e) {
        Log.error("Unexpected error: ", e);
        JOptionPane.showMessageDialog(null, LanguageUtil.instance().getString("main.frame.option.pane.wallet.critical.error.text", e.getMessage()), LanguageUtil.instance().getString("main.frame.option.pane.wallet.critical.error.title"), JOptionPane.ERROR_MESSAGE);
        System.exit(3);
    } catch (Error err) {
        // Last resort catch for unexpected problems - just to inform the user
        err.printStackTrace();
        JOptionPane.showMessageDialog(null, LanguageUtil.instance().getString("main.frame.option.pane.wallet.critical.error.2.text", err.getMessage()), LanguageUtil.instance().getString("main.frame.option.pane.wallet.critical.error.2.title"), JOptionPane.ERROR_MESSAGE);
        System.exit(4);
    }
}
Also used : LookAndFeelInfo(javax.swing.UIManager.LookAndFeelInfo) OS_TYPE(com.vaklinov.zcashui.OSUtil.OS_TYPE) Date(java.util.Date) InstallationDetectionException(com.vaklinov.zcashui.ZCashInstallationObserver.InstallationDetectionException) IOException(java.io.IOException) WalletCallException(com.vaklinov.zcashui.ZCashClientCaller.WalletCallException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DaemonInfo(com.vaklinov.zcashui.ZCashInstallationObserver.DaemonInfo) NetworkAndBlockchainInfo(com.vaklinov.zcashui.ZCashClientCaller.NetworkAndBlockchainInfo) InstallationDetectionException(com.vaklinov.zcashui.ZCashInstallationObserver.InstallationDetectionException) WalletCallException(com.vaklinov.zcashui.ZCashClientCaller.WalletCallException) File(java.io.File)

Aggregations

DaemonInfo (com.vaklinov.zcashui.ZCashInstallationObserver.DaemonInfo)2 File (java.io.File)2 OS_TYPE (com.vaklinov.zcashui.OSUtil.OS_TYPE)1 NetworkAndBlockchainInfo (com.vaklinov.zcashui.ZCashClientCaller.NetworkAndBlockchainInfo)1 WalletCallException (com.vaklinov.zcashui.ZCashClientCaller.WalletCallException)1 InstallationDetectionException (com.vaklinov.zcashui.ZCashInstallationObserver.InstallationDetectionException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Date (java.util.Date)1 LookAndFeelInfo (javax.swing.UIManager.LookAndFeelInfo)1