From 64ba300408835387b7f540e38f6cc6c86bd2b2c0 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Wed, 31 Jan 2018 00:25:39 -0500 Subject: [PATCH 1/2] Add cleanup tor files button to tor network settings --- .../resources/i18n/displayStrings.properties | 9 ++- .../i18n/displayStrings_de.properties | 2 +- gui/src/main/java/io/bisq/gui/bisq.css | 9 +++ .../main/java/io/bisq/gui/main/MainView.java | 16 +++-- .../java/io/bisq/gui/main/MainViewModel.java | 6 +- .../io/bisq/gui/main/overlays/Overlay.java | 20 +++--- .../windows/TorNetworkSettingsWindow.java | 72 +++++++++++++++---- .../settings/network/NetworkSettingsView.java | 15 +++- 8 files changed, 112 insertions(+), 37 deletions(-) diff --git a/common/src/main/resources/i18n/displayStrings.properties b/common/src/main/resources/i18n/displayStrings.properties index b91705f6fad..c4e3387f4b6 100644 --- a/common/src/main/resources/i18n/displayStrings.properties +++ b/common/src/main/resources/i18n/displayStrings.properties @@ -811,7 +811,7 @@ settings.net.roundTripTimeColumn=Roundtrip settings.net.sentBytesColumn=Sent settings.net.receivedBytesColumn=Received settings.net.peerTypeColumn=Peer type -settings.net.openTorSettingsButton=Open Tor network settings +settings.net.openTorSettingsButton=Open Tor settings settings.net.needRestart=You need to restart the application to apply that change.\nDo you want to do that now? settings.net.notKnownYet=Not known yet... @@ -1248,7 +1248,12 @@ torNetworkSettingWindow.enterBridge=Enter one or more bridge relays (one per lin torNetworkSettingWindow.enterBridgePrompt=type address:port torNetworkSettingWindow.restartInfo=You need to restart to apply the changes torNetworkSettingWindow.openTorWebPage=Open Tor project web page -torNetworkSettingWindow.info=If Tor is blocked by your internet provider or in your country you can try to use Tor bridges.\n\ +torNetworkSettingWindow.deleteFiles.header=Connection problems? +torNetworkSettingWindow.deleteFiles.info=If you have repeated connection problems at start up, deleting outdated Tor files might help. To do that click the button below and restart afterwards. +torNetworkSettingWindow.deleteFiles.button=Deleting outdated Tor files and shut down +torNetworkSettingWindow.deleteFiles.success=Deleting outdated Tor files wa successful. Please restart. +torNetworkSettingWindow.bridges.header=Is Tor blocked? +torNetworkSettingWindow.bridges.info=If Tor is blocked by your internet provider or in your country you can try to use Tor bridges.\n\ Visit the Tor web page at: https://bridges.torproject.org/bridges to learn more about \ bridges and pluggable transports. diff --git a/common/src/main/resources/i18n/displayStrings_de.properties b/common/src/main/resources/i18n/displayStrings_de.properties index a91c7c7c788..6ac81584954 100644 --- a/common/src/main/resources/i18n/displayStrings_de.properties +++ b/common/src/main/resources/i18n/displayStrings_de.properties @@ -1101,7 +1101,7 @@ torNetworkSettingWindow.enterBridge="Bridge relays" angeben (zeilenweise): torNetworkSettingWindow.enterBridgePrompt=address:port eingeben torNetworkSettingWindow.restartInfo=Du musst neu starten, um Änderungen anzuwenden torNetworkSettingWindow.openTorWebPage=Tor Webseite öffnen -torNetworkSettingWindow.info=Falls Tor von deinem Internetanbieter oder Land blockiert wird, kannst du es mit \ +torNetworkSettingWindow.bridges.info=Falls Tor von deinem Internetanbieter oder Land blockiert wird, kannst du es mit \ "Tor Bridges" versuchen.\n\ Besuche die Tor Webseite unter: https://bridges.torproject.org/bridges, um mehr über "Bridges" und \ "Pluggable Transports" zu erfahren. diff --git a/gui/src/main/java/io/bisq/gui/bisq.css b/gui/src/main/java/io/bisq/gui/bisq.css index 017a2e9dc65..4a2835f3565 100644 --- a/gui/src/main/java/io/bisq/gui/bisq.css +++ b/gui/src/main/java/io/bisq/gui/bisq.css @@ -1068,6 +1068,15 @@ textfield */ -fx-effect: dropshadow(gaussian, #999, 10, 0, 0, 0); } +#popup-grid-pane-bg { + -fx-font-size: 14; + -fx-text-fill: #333; + -fx-background-color: -bs-content-bg-grey; + -fx-background-radius: 10 10 10 10; + -fx-background-insets: 10; + -fx-effect: dropshadow(gaussian, #999, 10, 0, 0, 0); +} + #notification-popup-headline { -fx-font-size: 13; -fx-font-weight: bold; diff --git a/gui/src/main/java/io/bisq/gui/main/MainView.java b/gui/src/main/java/io/bisq/gui/main/MainView.java index daa700ff96b..1443fc2feb8 100644 --- a/gui/src/main/java/io/bisq/gui/main/MainView.java +++ b/gui/src/main/java/io/bisq/gui/main/MainView.java @@ -37,7 +37,6 @@ import io.bisq.gui.main.offer.BuyOfferView; import io.bisq.gui.main.offer.SellOfferView; import io.bisq.gui.main.overlays.popups.Popup; -import io.bisq.gui.main.overlays.windows.TorNetworkSettingsWindow; import io.bisq.gui.main.portfolio.PortfolioView; import io.bisq.gui.main.settings.SettingsView; import io.bisq.gui.util.BSFormatter; @@ -100,12 +99,15 @@ public static void removeEffect() { transitions.removeEffect(MainView.rootContainer); } - private final ToggleGroup navButtons = new ToggleGroup(); + private static Transitions transitions; + private static StackPane rootContainer; + private final ViewLoader viewLoader; private final Navigation navigation; - private static Transitions transitions; private final BSFormatter formatter; + + private final ToggleGroup navButtons = new ToggleGroup(); private ChangeListener walletServiceErrorMsgListener; private ChangeListener btcSyncIconIdListener; private ChangeListener splashP2PNetworkErrorMsgListener; @@ -117,11 +119,13 @@ public static void removeEffect() { private Label btcSplashInfo; private List persistedFilesCorrupted; private Popup p2PNetworkWarnMsgPopup, btcNetworkWarnMsgPopup; - private static StackPane rootContainer; @SuppressWarnings("WeakerAccess") @Inject - public MainView(MainViewModel model, CachingViewLoader viewLoader, Navigation navigation, Transitions transitions, + public MainView(MainViewModel model, + CachingViewLoader viewLoader, + Navigation navigation, + Transitions transitions, BSFormatter formatter) { super(model); this.viewLoader = viewLoader; @@ -478,7 +482,7 @@ private VBox createSplashScreen() { showTorNetworkSettingsButton.setVisible(false); showTorNetworkSettingsButton.setManaged(false); showTorNetworkSettingsButton.setOnAction(e -> { - new TorNetworkSettingsWindow(model.preferences).show(); + model.torNetworkSettingsWindow.show(); }); ImageView splashP2PNetworkIcon = new ImageView(); diff --git a/gui/src/main/java/io/bisq/gui/main/MainViewModel.java b/gui/src/main/java/io/bisq/gui/main/MainViewModel.java index 3df28964643..79a33085760 100644 --- a/gui/src/main/java/io/bisq/gui/main/MainViewModel.java +++ b/gui/src/main/java/io/bisq/gui/main/MainViewModel.java @@ -144,6 +144,7 @@ public class MainViewModel implements ViewModel { private final FailedTradesManager failedTradesManager; private final ClosedTradableManager closedTradableManager; private final AccountAgeWitnessService accountAgeWitnessService; + final TorNetworkSettingsWindow torNetworkSettingsWindow; private final BSFormatter formatter; // BTC network @@ -197,7 +198,6 @@ public class MainViewModel implements ViewModel { private MonadicBinding marketPriceBinding; @SuppressWarnings({"unused", "FieldCanBeLocal"}) private Subscription priceFeedAllLoadedSubscription; - private TorNetworkSettingsWindow torNetworkSettingsWindow; private BooleanProperty p2pNetWorkReady; private final BooleanProperty walletInitialized = new SimpleBooleanProperty(); private boolean allBasicServicesInitialized; @@ -219,7 +219,7 @@ public MainViewModel(WalletsManager walletsManager, WalletsSetup walletsSetup, DaoManager daoManager, EncryptionService encryptionService, KeyRing keyRing, BisqEnvironment bisqEnvironment, FailedTradesManager failedTradesManager, ClosedTradableManager closedTradableManager, AccountAgeWitnessService accountAgeWitnessService, - BSFormatter formatter) { + TorNetworkSettingsWindow torNetworkSettingsWindow, BSFormatter formatter) { this.walletsManager = walletsManager; this.walletsSetup = walletsSetup; this.btcWalletService = btcWalletService; @@ -247,6 +247,7 @@ public MainViewModel(WalletsManager walletsManager, WalletsSetup walletsSetup, this.failedTradesManager = failedTradesManager; this.closedTradableManager = closedTradableManager; this.accountAgeWitnessService = accountAgeWitnessService; + this.torNetworkSettingsWindow = torNetworkSettingsWindow; this.formatter = formatter; TxIdTextField.setPreferences(preferences); @@ -332,7 +333,6 @@ private void startBasicServices() { private void showTorNetworkSettingsWindow() { MainView.blur(); - torNetworkSettingsWindow = new TorNetworkSettingsWindow(preferences).useShutDownButton(); torNetworkSettingsWindow.show(); } diff --git a/gui/src/main/java/io/bisq/gui/main/overlays/Overlay.java b/gui/src/main/java/io/bisq/gui/main/overlays/Overlay.java index 6c7949e6e90..2884a3eaeef 100644 --- a/gui/src/main/java/io/bisq/gui/main/overlays/Overlay.java +++ b/gui/src/main/java/io/bisq/gui/main/overlays/Overlay.java @@ -174,17 +174,19 @@ protected void onShow() { } public void hide() { - animateHide(() -> { - removeEffectFromBackground(); + if (gridPane != null) { + animateHide(() -> { + removeEffectFromBackground(); - if (stage != null) - stage.hide(); - else - log.warn("Stage is null"); + if (stage != null) + stage.hide(); + else + log.warn("Stage is null"); - cleanup(); - onHidden(); - }); + cleanup(); + onHidden(); + }); + } } protected void onHidden() { diff --git a/gui/src/main/java/io/bisq/gui/main/overlays/windows/TorNetworkSettingsWindow.java b/gui/src/main/java/io/bisq/gui/main/overlays/windows/TorNetworkSettingsWindow.java index 80d9a44a664..55b4056c45e 100644 --- a/gui/src/main/java/io/bisq/gui/main/overlays/windows/TorNetworkSettingsWindow.java +++ b/gui/src/main/java/io/bisq/gui/main/overlays/windows/TorNetworkSettingsWindow.java @@ -35,12 +35,17 @@ package io.bisq.gui.main.overlays.windows; +import com.google.inject.name.Named; import io.bisq.common.UserThread; import io.bisq.common.locale.Res; +import io.bisq.common.storage.FileUtil; import io.bisq.common.util.Tuple2; import io.bisq.common.util.Utilities; import io.bisq.core.user.Preferences; import io.bisq.gui.main.overlays.Overlay; +import io.bisq.gui.main.overlays.popups.Popup; +import io.bisq.gui.util.Layout; +import io.bisq.network.NetworkOptionKeys; import io.bisq.network.p2p.network.DefaultPluggableTransports; import javafx.collections.FXCollections; import javafx.geometry.HPos; @@ -56,8 +61,11 @@ import javafx.util.StringConverter; import lombok.extern.slf4j.Slf4j; +import javax.inject.Inject; +import java.io.File; import java.io.IOException; import java.net.URI; +import java.nio.file.Paths; import java.util.Arrays; import java.util.concurrent.TimeUnit; @@ -80,6 +88,7 @@ public enum Transport { } private final Preferences preferences; + private final File torDir; private RadioButton noBridgesRadioButton, providedBridgesRadioButton, customBridgesRadioButton; private Label enterBridgeLabel; private ComboBox transportTypeComboBox; @@ -89,13 +98,18 @@ public enum Transport { private Transport selectedTorTransportOrdinal = Transport.OBFS_4; private String customBridges = ""; - public TorNetworkSettingsWindow(Preferences preferences) { + @Inject + public TorNetworkSettingsWindow(Preferences preferences, + @Named(NetworkOptionKeys.TOR_DIR) File torDir) { this.preferences = preferences; + this.torDir = torDir; + type = Type.Attention; useShutDownButton(); } + /////////////////////////////////////////////////////////////////////////////////////////// // Public API /////////////////////////////////////////////////////////////////////////////////////////// @@ -106,8 +120,6 @@ public void show() { width = 1000; createGridPane(); - addHeadLine(); - addSeparator(); addContent(); addCloseButton(); applyStyles(); @@ -174,23 +186,46 @@ protected void setupKeyHandler(Scene scene) { } } + @Override + protected void applyStyles() { + super.applyStyles(); + gridPane.setId("popup-grid-pane-bg"); + } + private void addContent() { - gridPane.setStyle("-fx-background-color: #f8f8f8;"); + addTitledGroupBg(gridPane, ++rowIndex, 1, Res.get("torNetworkSettingWindow.deleteFiles.header")); + + Label deleteFilesLabel = addLabel(gridPane, rowIndex, Res.get("torNetworkSettingWindow.deleteFiles.info"), Layout.FIRST_ROW_DISTANCE); + deleteFilesLabel.setWrapText(true); + GridPane.setColumnIndex(deleteFilesLabel, 0); + GridPane.setColumnSpan(deleteFilesLabel, 2); + GridPane.setHalignment(deleteFilesLabel, HPos.LEFT); + GridPane.setValignment(deleteFilesLabel, VPos.TOP); + + Button deleteFilesButton = addButtonAfterGroup(gridPane, ++rowIndex, Res.get("torNetworkSettingWindow.deleteFiles.button")); + deleteFilesButton.setOnAction(e -> { + cleanTorDir(); + new Popup<>().feedback(Res.get("torNetworkSettingWindow.deleteFiles.success")).show(); + }); - Label label = addLabel(gridPane, ++rowIndex, Res.get("torNetworkSettingWindow.info")); - label.setWrapText(true); - GridPane.setColumnIndex(label, 0); - GridPane.setColumnSpan(label, 2); - GridPane.setHalignment(label, HPos.LEFT); - GridPane.setValignment(label, VPos.TOP); - GridPane.setMargin(label, new Insets(0, 0, 20, 0)); + addTitledGroupBg(gridPane, ++rowIndex, 7, Res.get("torNetworkSettingWindow.bridges.header"), Layout.GROUP_DISTANCE); + + Label bridgesLabel = addLabel(gridPane, rowIndex, Res.get("torNetworkSettingWindow.bridges.info"), Layout.FIRST_ROW_AND_GROUP_DISTANCE); + bridgesLabel.setWrapText(true); + GridPane.setColumnIndex(bridgesLabel, 0); + GridPane.setColumnSpan(bridgesLabel, 2); + GridPane.setHalignment(bridgesLabel, HPos.LEFT); + GridPane.setValignment(bridgesLabel, VPos.TOP); + + //addLabelTextArea(gridPane, rowIndex, Res.get("torNetworkSettingWindow.info"), "", Layout.FIRST_ROW_AND_GROUP_DISTANCE); ToggleGroup toggleGroup = new ToggleGroup(); // noBridges noBridgesRadioButton = addRadioButton(gridPane, ++rowIndex, toggleGroup, Res.get("torNetworkSettingWindow.noBridges")); noBridgesRadioButton.setUserData(BridgeOption.NONE); + GridPane.setMargin(noBridgesRadioButton, new Insets(20, 0, 0, 0)); // providedBridges providedBridgesRadioButton = addRadioButton(gridPane, ++rowIndex, toggleGroup, Res.get("torNetworkSettingWindow.providedBridges")); @@ -238,8 +273,8 @@ public Transport fromString(String string) { GridPane.setColumnIndex(label2, 1); GridPane.setColumnSpan(label2, 2); GridPane.setHalignment(label2, HPos.LEFT); - GridPane.setValignment(label, VPos.TOP); - GridPane.setMargin(label, new Insets(10, 10, 20, 0)); + GridPane.setValignment(label2, VPos.TOP); + GridPane.setMargin(label2, new Insets(10, 10, 20, 0)); // init persisted values selectedBridgeOption = BridgeOption.values()[preferences.getBridgeOptionOrdinal()]; @@ -281,6 +316,17 @@ public Transport fromString(String string) { ); } + private void cleanTorDir() { + final File hiddenservice = new File(Paths.get(torDir.getAbsolutePath(), "hiddenservice").toString()); + try { + FileUtil.deleteDirectory(torDir, hiddenservice); + } catch (IOException e) { + e.printStackTrace(); + log.error(e.toString()); + new Popup<>().error(e.toString()).show(); + } + } + private void applyToggleSelection() { switch (selectedBridgeOption) { case PROVIDED: diff --git a/gui/src/main/java/io/bisq/gui/main/settings/network/NetworkSettingsView.java b/gui/src/main/java/io/bisq/gui/main/settings/network/NetworkSettingsView.java index 1ca38a9aeeb..2cf5e8df671 100644 --- a/gui/src/main/java/io/bisq/gui/main/settings/network/NetworkSettingsView.java +++ b/gui/src/main/java/io/bisq/gui/main/settings/network/NetworkSettingsView.java @@ -90,6 +90,7 @@ public class NetworkSettingsView extends ActivatableViewAndModel filterPropertyListener; @Inject - public NetworkSettingsView(WalletsSetup walletsSetup, P2PService p2PService, Preferences preferences, BitcoinNodes bitcoinNodes, - FilterManager filterManager, BisqEnvironment bisqEnvironment, Clock clock, BSFormatter formatter) { + public NetworkSettingsView(WalletsSetup walletsSetup, + P2PService p2PService, + Preferences preferences, + BitcoinNodes bitcoinNodes, + FilterManager filterManager, + BisqEnvironment bisqEnvironment, + TorNetworkSettingsWindow torNetworkSettingsWindow, + Clock clock, + BSFormatter formatter) { super(); this.walletsSetup = walletsSetup; this.p2PService = p2PService; @@ -118,6 +126,7 @@ public NetworkSettingsView(WalletsSetup walletsSetup, P2PService p2PService, Pre this.bitcoinNodes = bitcoinNodes; this.filterManager = filterManager; this.bisqEnvironment = bisqEnvironment; + this.torNetworkSettingsWindow = torNetworkSettingsWindow; this.clock = clock; this.formatter = formatter; } @@ -260,7 +269,7 @@ public void activate() { btcNodesInputTextField.textProperty().addListener(btcNodesInputTextFieldListener); btcNodesInputTextField.focusedProperty().addListener(btcNodesInputTextFieldFocusListener); - openTorSettingsButton.setOnAction(e -> new TorNetworkSettingsWindow(preferences).show()); + openTorSettingsButton.setOnAction(e -> torNetworkSettingsWindow.show()); } @Override From eeeabaf015ff658f49dfb01e8839c5efb7917d92 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Wed, 31 Jan 2018 11:42:16 -0500 Subject: [PATCH 2/2] Fix typos --- common/src/main/resources/i18n/displayStrings.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/src/main/resources/i18n/displayStrings.properties b/common/src/main/resources/i18n/displayStrings.properties index c4e3387f4b6..4a88042a2f0 100644 --- a/common/src/main/resources/i18n/displayStrings.properties +++ b/common/src/main/resources/i18n/displayStrings.properties @@ -1250,8 +1250,8 @@ torNetworkSettingWindow.restartInfo=You need to restart to apply the changes torNetworkSettingWindow.openTorWebPage=Open Tor project web page torNetworkSettingWindow.deleteFiles.header=Connection problems? torNetworkSettingWindow.deleteFiles.info=If you have repeated connection problems at start up, deleting outdated Tor files might help. To do that click the button below and restart afterwards. -torNetworkSettingWindow.deleteFiles.button=Deleting outdated Tor files and shut down -torNetworkSettingWindow.deleteFiles.success=Deleting outdated Tor files wa successful. Please restart. +torNetworkSettingWindow.deleteFiles.button=Delete outdated Tor files and shut down +torNetworkSettingWindow.deleteFiles.success=Outdated Tor files deleted successfully. Please restart. torNetworkSettingWindow.bridges.header=Is Tor blocked? torNetworkSettingWindow.bridges.info=If Tor is blocked by your internet provider or in your country you can try to use Tor bridges.\n\ Visit the Tor web page at: https://bridges.torproject.org/bridges to learn more about \