Search in sources :

Example 1 with PersistedDataHost

use of bisq.common.proto.persistable.PersistedDataHost in project bisq-desktop by bisq-network.

the class BisqApp method start.

@SuppressWarnings("PointlessBooleanExpression")
@Override
public void start(Stage stage) throws IOException {
    BisqApp.primaryStage = stage;
    try {
        // Guice
        bisqAppModule = new BisqAppModule(bisqEnvironment, primaryStage);
        injector = Guice.createInjector(bisqAppModule);
        injector.getInstance(InjectorViewFactory.class).setInjector(injector);
        // All classes which are persisting objects need to be added here
        // Maintain order!
        ArrayList<PersistedDataHost> persistedDataHosts = new ArrayList<>();
        final Preferences preferences = injector.getInstance(Preferences.class);
        persistedDataHosts.add(preferences);
        persistedDataHosts.add(injector.getInstance(User.class));
        persistedDataHosts.add(injector.getInstance(Navigation.class));
        persistedDataHosts.add(injector.getInstance(AddressEntryList.class));
        persistedDataHosts.add(injector.getInstance(OpenOfferManager.class));
        persistedDataHosts.add(injector.getInstance(TradeManager.class));
        persistedDataHosts.add(injector.getInstance(ClosedTradableManager.class));
        persistedDataHosts.add(injector.getInstance(FailedTradesManager.class));
        persistedDataHosts.add(injector.getInstance(DisputeManager.class));
        persistedDataHosts.add(injector.getInstance(P2PService.class));
        persistedDataHosts.add(injector.getInstance(ProposalCollectionsService.class));
        persistedDataHosts.add(injector.getInstance(VoteService.class));
        // we apply at startup the reading of persisted data but don't want to get it triggered in the constructor
        persistedDataHosts.forEach(e -> {
            try {
                log.debug("call readPersisted at " + e.getClass().getSimpleName());
                e.readPersisted();
            } catch (Throwable e1) {
                log.error("readPersisted error", e1);
            }
        });
        boolean useDevMode = injector.getInstance(Key.get(Boolean.class, Names.named(AppOptionKeys.USE_DEV_MODE)));
        DevEnv.setDevMode(useDevMode);
        Version.setBaseCryptoNetworkId(BisqEnvironment.getBaseCurrencyNetwork().ordinal());
        Version.printVersion();
        if (Utilities.isLinux())
            System.setProperty("prism.lcdtext", "false");
        Storage.setDatabaseCorruptionHandler((String fileName) -> {
            corruptedDatabaseFiles.add(fileName);
            if (mainView != null)
                mainView.setPersistedFilesCorrupted(corruptedDatabaseFiles);
        });
        // load the main view and create the main scene
        CachingViewLoader viewLoader = injector.getInstance(CachingViewLoader.class);
        mainView = (MainView) viewLoader.load(MainView.class);
        mainView.setPersistedFilesCorrupted(corruptedDatabaseFiles);
        scene = new Scene(mainView.getRoot(), INITIAL_SCENE_WIDTH, INITIAL_SCENE_HEIGHT);
        scene.getStylesheets().setAll("/bisq/desktop/bisq.css", "/bisq/desktop/images.css", "/bisq/desktop/CandleStickChart.css");
        // configure the system tray
        SystemTray.create(primaryStage, shutDownHandler);
        primaryStage.setOnCloseRequest(event -> {
            event.consume();
            stop();
        });
        scene.addEventHandler(KeyEvent.KEY_RELEASED, keyEvent -> {
            Utilities.isAltOrCtrlPressed(KeyCode.W, keyEvent);
            if (Utilities.isCtrlPressed(KeyCode.W, keyEvent) || Utilities.isCtrlPressed(KeyCode.Q, keyEvent)) {
                stop();
            } else {
                if (Utilities.isAltOrCtrlPressed(KeyCode.E, keyEvent)) {
                    showEmptyWalletPopup(injector.getInstance(BtcWalletService.class));
                } else if (Utilities.isAltOrCtrlPressed(KeyCode.M, keyEvent)) {
                    showSendAlertMessagePopup();
                } else if (Utilities.isAltOrCtrlPressed(KeyCode.F, keyEvent)) {
                    showFilterPopup();
                } else if (Utilities.isAltOrCtrlPressed(KeyCode.J, keyEvent)) {
                    WalletsManager walletsManager = injector.getInstance(WalletsManager.class);
                    if (walletsManager.areWalletsAvailable())
                        new ShowWalletDataWindow(walletsManager).show();
                    else
                        new Popup<>().warning(Res.get("popup.warning.walletNotInitialized")).show();
                } else if (Utilities.isAltOrCtrlPressed(KeyCode.G, keyEvent)) {
                    if (injector.getInstance(BtcWalletService.class).isWalletReady())
                        injector.getInstance(ManualPayoutTxWindow.class).show();
                    else
                        new Popup<>().warning(Res.get("popup.warning.walletNotInitialized")).show();
                } else if (DevEnv.isDevMode()) {
                    // dev ode only
                    if (Utilities.isAltOrCtrlPressed(KeyCode.B, keyEvent)) {
                        // BSQ empty wallet not public yet
                        showEmptyWalletPopup(injector.getInstance(BsqWalletService.class));
                    } else if (Utilities.isAltOrCtrlPressed(KeyCode.P, keyEvent)) {
                        showFPSWindow();
                    } else if (Utilities.isAltOrCtrlPressed(KeyCode.Z, keyEvent)) {
                        showDebugWindow();
                    }
                }
            }
        });
        // configure the primary stage
        primaryStage.setTitle(bisqEnvironment.getRequiredProperty(AppOptionKeys.APP_NAME_KEY));
        primaryStage.setScene(scene);
        primaryStage.setMinWidth(1020);
        primaryStage.setMinHeight(620);
        // on windows the title icon is also used as task bar icon in a larger size
        // on Linux no title icon is supported but also a large task bar icon is derived from that title icon
        String iconPath;
        if (Utilities.isOSX())
            iconPath = ImageUtil.isRetina() ? "/images/window_icon@2x.png" : "/images/window_icon.png";
        else if (Utilities.isWindows())
            iconPath = "/images/task_bar_icon_windows.png";
        else
            iconPath = "/images/task_bar_icon_linux.png";
        primaryStage.getIcons().add(new Image(getClass().getResourceAsStream(iconPath)));
        // make the UI visible
        primaryStage.show();
        if (!Utilities.isCorrectOSArchitecture()) {
            String osArchitecture = Utilities.getOSArchitecture();
            // We don't force a shutdown as the osArchitecture might in strange cases return a wrong value.
            // Needs at least more testing on different machines...
            new Popup<>().warning(Res.get("popup.warning.wrongVersion", osArchitecture, Utilities.getJVMArchitecture(), osArchitecture)).show();
        }
        UserThread.runPeriodically(() -> Profiler.printSystemLoad(log), LOG_MEMORY_PERIOD_MIN, TimeUnit.MINUTES);
    } catch (Throwable throwable) {
        log.error("Error during app init", throwable);
        showErrorPopup(throwable, false);
    }
}
Also used : TradeManager(bisq.core.trade.TradeManager) ShowWalletDataWindow(bisq.desktop.main.overlays.windows.ShowWalletDataWindow) User(bisq.core.user.User) WalletsManager(bisq.core.btc.wallet.WalletsManager) DisputeManager(bisq.core.arbitration.DisputeManager) ArrayList(java.util.ArrayList) VoteService(bisq.core.dao.vote.VoteService) P2PService(bisq.network.p2p.P2PService) Image(javafx.scene.image.Image) CachingViewLoader(bisq.desktop.common.view.CachingViewLoader) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) Popup(bisq.desktop.main.overlays.popups.Popup) AddressEntryList(bisq.core.btc.AddressEntryList) Preferences(bisq.core.user.Preferences) InjectorViewFactory(bisq.desktop.common.view.guice.InjectorViewFactory) FailedTradesManager(bisq.core.trade.failed.FailedTradesManager) Navigation(bisq.desktop.Navigation) Scene(javafx.scene.Scene) ProposalCollectionsService(bisq.core.dao.proposal.ProposalCollectionsService) OpenOfferManager(bisq.core.offer.OpenOfferManager) PersistedDataHost(bisq.common.proto.persistable.PersistedDataHost) ClosedTradableManager(bisq.core.trade.closed.ClosedTradableManager)

Aggregations

PersistedDataHost (bisq.common.proto.persistable.PersistedDataHost)1 DisputeManager (bisq.core.arbitration.DisputeManager)1 AddressEntryList (bisq.core.btc.AddressEntryList)1 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)1 WalletsManager (bisq.core.btc.wallet.WalletsManager)1 ProposalCollectionsService (bisq.core.dao.proposal.ProposalCollectionsService)1 VoteService (bisq.core.dao.vote.VoteService)1 OpenOfferManager (bisq.core.offer.OpenOfferManager)1 TradeManager (bisq.core.trade.TradeManager)1 ClosedTradableManager (bisq.core.trade.closed.ClosedTradableManager)1 FailedTradesManager (bisq.core.trade.failed.FailedTradesManager)1 Preferences (bisq.core.user.Preferences)1 User (bisq.core.user.User)1 Navigation (bisq.desktop.Navigation)1 CachingViewLoader (bisq.desktop.common.view.CachingViewLoader)1 InjectorViewFactory (bisq.desktop.common.view.guice.InjectorViewFactory)1 Popup (bisq.desktop.main.overlays.popups.Popup)1 ShowWalletDataWindow (bisq.desktop.main.overlays.windows.ShowWalletDataWindow)1 P2PService (bisq.network.p2p.P2PService)1 ArrayList (java.util.ArrayList)1