From 0fa6bd56e27a130aa5abb199fbea084ad66923b8 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 17 Oct 2022 13:52:40 +0200 Subject: [PATCH] add interface enum --- .../sparrowwallet/sparrow/AppServices.java | 4 ++-- .../com/sparrowwallet/sparrow/Interface.java | 23 +++++++++++++++++++ .../sparrowwallet/sparrow/SparrowWallet.java | 1 + 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/sparrowwallet/sparrow/Interface.java diff --git a/src/main/java/com/sparrowwallet/sparrow/AppServices.java b/src/main/java/com/sparrowwallet/sparrow/AppServices.java index 2a0a3377..3585c389 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppServices.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppServices.java @@ -210,7 +210,7 @@ public class AppServices { restartService(ratesService); } - if(config.isCheckNewVersions() && Network.get() == Network.MAINNET) { + if(config.isCheckNewVersions() && Network.get() == Network.MAINNET && Interface.get() == Interface.DESKTOP) { restartService(versionCheckService); } @@ -1104,7 +1104,7 @@ public class AppServices { Wallet wallet = walletTabData.getWallet(); Storage storage = walletTabData.getStorage(); - if(!storage.getWalletFile().exists() || wallet.containsSource(KeystoreSource.HW_USB)) { + if(Interface.get() == Interface.DESKTOP && (!storage.getWalletFile().exists() || wallet.containsSource(KeystoreSource.HW_USB))) { usbWallet = true; if(deviceEnumerateService == null) { diff --git a/src/main/java/com/sparrowwallet/sparrow/Interface.java b/src/main/java/com/sparrowwallet/sparrow/Interface.java new file mode 100644 index 00000000..56ac68c1 --- /dev/null +++ b/src/main/java/com/sparrowwallet/sparrow/Interface.java @@ -0,0 +1,23 @@ +package com.sparrowwallet.sparrow; + +public enum Interface { + DESKTOP, TERMINAL, SERVER; + + private static Interface currentInterface; + + public static Interface get() { + if(currentInterface == null) { + currentInterface = DESKTOP; + } + + return currentInterface; + } + + public static void set(Interface interf) { + if(currentInterface != null && interf != currentInterface) { + throw new IllegalStateException("Interface already set to " + currentInterface); + } + + currentInterface = interf; + } +} diff --git a/src/main/java/com/sparrowwallet/sparrow/SparrowWallet.java b/src/main/java/com/sparrowwallet/sparrow/SparrowWallet.java index 916704d9..9838e98a 100644 --- a/src/main/java/com/sparrowwallet/sparrow/SparrowWallet.java +++ b/src/main/java/com/sparrowwallet/sparrow/SparrowWallet.java @@ -87,6 +87,7 @@ public class SparrowWallet { SLF4JBridgeHandler.install(); if(args.terminal || java.awt.GraphicsEnvironment.isHeadless()) { + Interface.set(Interface.TERMINAL); PlatformImpl.setTaskbarApplication(false); Drongo.removeRootLogAppender("STDOUT"); com.sun.javafx.application.LauncherImpl.launchApplication(SparrowTerminal.class, SparrowWalletPreloader.class, argv);