From 4fb8a27a78b8b3358c6abd5c358d23001cd9fa2d Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Mon, 19 Dec 2016 12:06:41 +0100 Subject: [PATCH] removed MAC warning screen --- .../ui/controllers/MacWarningsController.java | 165 ------------------ .../ui/controllers/UnlockedController.java | 39 +---- .../ui/src/main/resources/localization/en.txt | 6 - 3 files changed, 1 insertion(+), 209 deletions(-) delete mode 100644 main/ui/src/main/java/org/cryptomator/ui/controllers/MacWarningsController.java diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/MacWarningsController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/MacWarningsController.java deleted file mode 100644 index cb890e1f6..000000000 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/MacWarningsController.java +++ /dev/null @@ -1,165 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Sebastian Stenzel and others. - * This file is licensed under the terms of the MIT license. - * See the LICENSE.txt file for more info. - * - * Contributors: - * Sebastian Stenzel - initial API and implementation - *******************************************************************************/ -package org.cryptomator.ui.controllers; - -import java.net.URL; -import java.util.stream.Collectors; - -import javax.inject.Inject; - -import org.cryptomator.ui.model.Vault; -import org.cryptomator.ui.settings.Localization; - -import javafx.application.Application; -import javafx.beans.Observable; -import javafx.beans.property.BooleanProperty; -import javafx.beans.property.ObjectProperty; -import javafx.beans.property.ReadOnlyStringWrapper; -import javafx.beans.property.SimpleBooleanProperty; -import javafx.beans.property.SimpleObjectProperty; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import javafx.beans.value.WeakChangeListener; -import javafx.collections.FXCollections; -import javafx.collections.ListChangeListener; -import javafx.collections.ListChangeListener.Change; -import javafx.collections.ObservableList; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.scene.control.Button; -import javafx.scene.control.ListView; -import javafx.scene.control.cell.CheckBoxListCell; -import javafx.stage.Stage; -import javafx.util.StringConverter; - -public class MacWarningsController extends LocalizedFXMLViewController { - - private final Application application; - private final ObservableList warnings = FXCollections.observableArrayList(); - private final ListChangeListener unauthenticatedResourcesChangeListener = this::unauthenticatedResourcesDidChange; - private final ChangeListener stageVisibilityChangeListener = this::windowVisibilityDidChange; - final ObjectProperty vault = new SimpleObjectProperty<>(); - private Stage stage; - - @Inject - public MacWarningsController(Application application, Localization localization) { - super(localization); - this.application = application; - } - - @FXML - private ListView warningsList; - - @FXML - private Button whitelistButton; - - @Override - public void initialize() { - warnings.addListener(this::warningsDidInvalidate); - warningsList.setItems(warnings); - warningsList.setCellFactory(CheckBoxListCell.forListView(Warning::selectedProperty, new StringConverter() { - - @Override - public String toString(Warning object) { - return object.getName(); - } - - @Override - public Warning fromString(String string) { - return null; - } - - })); - } - - @Override - protected URL getFxmlResourceUrl() { - return getClass().getResource("/fxml/mac_warnings.fxml"); - } - - @Override - public void initStage(Stage stage) { - super.initStage(stage); - this.stage = stage; - stage.showingProperty().addListener(new WeakChangeListener<>(stageVisibilityChangeListener)); - } - - @FXML - private void didClickWhitelistButton(ActionEvent event) { - warnings.filtered(w -> w.isSelected()).stream().forEach(w -> { - final String resourceToBeWhitelisted = w.getName(); - vault.get().getWhitelistedResourcesWithInvalidMac().add(resourceToBeWhitelisted); - vault.get().getNamesOfResourcesWithInvalidMac().remove(resourceToBeWhitelisted); - }); - warnings.removeIf(w -> w.isSelected()); - } - - @FXML - private void didClickMoreInformationButton(ActionEvent event) { - application.getHostServices().showDocument("https://cryptomator.freshdesk.com/support/solutions/articles/16000003666-what-does-mac-authentication-failed-mean-"); - } - - private void unauthenticatedResourcesDidChange(Change change) { - while (change.next()) { - if (change.wasAdded()) { - warnings.addAll(change.getAddedSubList().stream().map(Warning::new).collect(Collectors.toList())); - } else if (change.wasRemoved()) { - change.getRemoved().forEach(str -> { - warnings.removeIf(w -> str.equals(w.name.get())); - }); - } - } - } - - private void warningsDidInvalidate(Observable observable) { - disableWhitelistButtonIfNothingSelected(); - } - - private void windowVisibilityDidChange(ObservableValue observable, Boolean oldValue, Boolean newValue) { - if (Boolean.TRUE.equals(newValue)) { - stage.setTitle(String.format(localization.getString("macWarnings.windowTitle"), vault.get().name().getValue())); - warnings.addAll(vault.get().getNamesOfResourcesWithInvalidMac().stream().map(Warning::new).collect(Collectors.toList())); - vault.get().getNamesOfResourcesWithInvalidMac().addListener(this.unauthenticatedResourcesChangeListener); - } else { - vault.get().getNamesOfResourcesWithInvalidMac().clear(); - vault.get().getNamesOfResourcesWithInvalidMac().removeListener(this.unauthenticatedResourcesChangeListener); - } - } - - private void disableWhitelistButtonIfNothingSelected() { - whitelistButton.setDisable(warnings.filtered(w -> w.isSelected()).isEmpty()); - } - - private class Warning { - - private final ReadOnlyStringWrapper name = new ReadOnlyStringWrapper(); - private final BooleanProperty selected = new SimpleBooleanProperty(false); - - public Warning(String name) { - this.name.set(name); - this.selectedProperty().addListener(change -> { - disableWhitelistButtonIfNothingSelected(); - }); - } - - public String getName() { - return name.get(); - } - - public BooleanProperty selectedProperty() { - return selected; - } - - public boolean isSelected() { - return selected.get(); - } - - } - -} diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockedController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockedController.java index b160804bd..c2c578e7d 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockedController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockedController.java @@ -12,21 +12,17 @@ import java.net.URL; import java.util.Optional; import javax.inject.Inject; -import javax.inject.Provider; import org.cryptomator.ui.model.Vault; import org.cryptomator.ui.settings.Localization; -import org.cryptomator.ui.util.ActiveWindowStyleSupport; import org.cryptomator.ui.util.AsyncTaskService; import org.fxmisc.easybind.EasyBind; import javafx.animation.Animation; import javafx.animation.KeyFrame; import javafx.animation.Timeline; -import javafx.application.Platform; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; -import javafx.collections.ListChangeListener; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.fxml.FXML; @@ -42,7 +38,6 @@ import javafx.scene.control.ToggleButton; import javafx.scene.input.Clipboard; import javafx.scene.input.ClipboardContent; import javafx.stage.PopupWindow.AnchorLocation; -import javafx.stage.Stage; import javafx.util.Duration; public class UnlockedController extends LocalizedFXMLViewController { @@ -50,8 +45,6 @@ public class UnlockedController extends LocalizedFXMLViewController { private static final int IO_SAMPLING_STEPS = 100; private static final double IO_SAMPLING_INTERVAL = 0.25; - private final Stage macWarningsWindow = new Stage(); - private final MacWarningsController macWarningsController; private final AsyncTaskService asyncTaskService; private final ObjectProperty vault = new SimpleObjectProperty<>(); private Optional listener = Optional.empty(); @@ -76,19 +69,13 @@ public class UnlockedController extends LocalizedFXMLViewController { private MenuItem revealVaultMenuItem; @Inject - public UnlockedController(Localization localization, Provider macWarningsControllerProvider, AsyncTaskService asyncTaskService) { + public UnlockedController(Localization localization, AsyncTaskService asyncTaskService) { super(localization); - this.macWarningsController = macWarningsControllerProvider.get(); this.asyncTaskService = asyncTaskService; - - macWarningsController.vault.bind(this.vault); } @Override public void initialize() { - macWarningsController.initStage(macWarningsWindow); - ActiveWindowStyleSupport.startObservingFocus(macWarningsWindow); - revealVaultMenuItem.disableProperty().bind(EasyBind.map(vault, vault -> vault != null && !vault.isMounted())); EasyBind.subscribe(vault, this::vaultChanged); @@ -105,18 +92,6 @@ public class UnlockedController extends LocalizedFXMLViewController { return; } - // listen to MAC warnings as long as this vault is unlocked: - // TODO overheadhunter: reimplement eventually - /* - * final ListChangeListener macWarningsListener = this::macWarningsDidChange; - * newVault.getNamesOfResourcesWithInvalidMac().addListener(macWarningsListener); - * newVault.unlockedProperty().addListener((observable, oldValue, newValue) -> { - * if (Boolean.FALSE.equals(newValue)) { - * newVault.getNamesOfResourcesWithInvalidMac().removeListener(macWarningsListener); - * } - * }); - */ - if (!vault.get().isMounted()) { // TODO Markus Kreusch #393: hyperlink auf FAQ oder sowas? messageLabel.setText(localization.getString("unlocked.label.mountFailed")); @@ -166,18 +141,6 @@ public class UnlockedController extends LocalizedFXMLViewController { Clipboard.getSystemClipboard().setContent(clipboardContent); } - // **************************************** - // MAC Auth Warnings - // **************************************** - - private void macWarningsDidChange(ListChangeListener.Change change) { - if (change.getList().size() > 0) { - Platform.runLater(macWarningsWindow::show); - } else { - Platform.runLater(macWarningsWindow::hide); - } - } - // **************************************** // IO Graph // **************************************** diff --git a/main/ui/src/main/resources/localization/en.txt b/main/ui/src/main/resources/localization/en.txt index 64c749bb4..5036deefa 100644 --- a/main/ui/src/main/resources/localization/en.txt +++ b/main/ui/src/main/resources/localization/en.txt @@ -95,12 +95,6 @@ unlocked.label.statsEncrypted=encrypted unlocked.label.statsDecrypted=decrypted unlocked.ioGraph.yAxis.label=Throughput (MiB/s) -# mac_warnings.fxml -macWarnings.windowTitle=Danger - Corrupted file in %s -macWarnings.message=Cryptomator detected potentially malicious corruptions in the following files: -macWarnings.moreInformationButton=Learn More -macWarnings.whitelistButton=Decrypt Selected Anyway - # settings.fxml settings.version.label=Version %s settings.checkForUpdates.label=Check for Updates