From e7e88f13e3d096c7e61b6fbf87afde8ebcf10377 Mon Sep 17 00:00:00 2001 From: Jan-Peter Klein Date: Fri, 17 Nov 2023 14:51:13 +0100 Subject: [PATCH] improved code quality --- .../java/org/cryptomator/common/CommonsModule.java | 13 ------------- .../cryptomator/common/vaults/VaultListManager.java | 2 -- .../ui/preferences/VolumePreferencesController.java | 6 +----- .../unlock/UnlockFuseRestartRequiredController.java | 9 +++++++++ .../org/cryptomator/ui/unlock/UnlockWorkflow.java | 5 ----- .../cryptomator/common/settings/SettingsTest.java | 8 ++++++-- 6 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/cryptomator/common/CommonsModule.java b/src/main/java/org/cryptomator/common/CommonsModule.java index 9cba60131..5ea69da6d 100644 --- a/src/main/java/org/cryptomator/common/CommonsModule.java +++ b/src/main/java/org/cryptomator/common/CommonsModule.java @@ -7,12 +7,10 @@ package org.cryptomator.common; import dagger.Module; import dagger.Provides; -import org.apache.commons.lang3.SystemUtils; import org.cryptomator.common.keychain.KeychainModule; import org.cryptomator.common.mount.MountModule; import org.cryptomator.common.settings.Settings; import org.cryptomator.common.settings.SettingsProvider; -import org.cryptomator.common.settings.VaultSettings; import org.cryptomator.common.vaults.VaultComponent; import org.cryptomator.common.vaults.VaultListModule; import org.cryptomator.cryptolib.common.MasterkeyFileAccess; @@ -23,8 +21,6 @@ import org.slf4j.LoggerFactory; import javax.inject.Named; import javax.inject.Singleton; -import javafx.beans.value.ObservableValue; -import java.net.InetSocketAddress; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.util.Comparator; @@ -138,15 +134,6 @@ public abstract class CommonsModule { LOG.error("Uncaught exception in " + thread.getName(), throwable); } - @Provides - @Singleton - static ObservableValue provideServerSocketAddressBinding(VaultSettings vaultSettings) { - return vaultSettings.port.map(port -> { - String host = SystemUtils.IS_OS_WINDOWS ? "127.0.0.1" : "localhost"; - return InetSocketAddress.createUnresolved(host, vaultSettings.port.intValue()); - }); - } - @Provides @Singleton @Named("FUPFMS") diff --git a/src/main/java/org/cryptomator/common/vaults/VaultListManager.java b/src/main/java/org/cryptomator/common/vaults/VaultListManager.java index 0351981a0..cbcc281ac 100644 --- a/src/main/java/org/cryptomator/common/vaults/VaultListManager.java +++ b/src/main/java/org/cryptomator/common/vaults/VaultListManager.java @@ -73,8 +73,6 @@ public class VaultListManager { private VaultSettings newVaultSettings(Path path) { VaultSettings vaultSettings = VaultSettings.withRandomId(); vaultSettings.path.set(path); - vaultSettings.mountService.set(vaultSettings.mountService.getValue()); - vaultSettings.port.set(vaultSettings.port.getValue()); if (path.getFileName() != null) { vaultSettings.displayName.set(path.getFileName().toString()); } else { diff --git a/src/main/java/org/cryptomator/ui/preferences/VolumePreferencesController.java b/src/main/java/org/cryptomator/ui/preferences/VolumePreferencesController.java index fbd5d11ec..c06a4596b 100644 --- a/src/main/java/org/cryptomator/ui/preferences/VolumePreferencesController.java +++ b/src/main/java/org/cryptomator/ui/preferences/VolumePreferencesController.java @@ -3,13 +3,11 @@ package org.cryptomator.ui.preferences; import dagger.Lazy; import org.cryptomator.common.ObservableUtil; import org.cryptomator.common.settings.Settings; -import org.cryptomator.common.vaults.VaultModule; import org.cryptomator.integrations.mount.MountCapability; import org.cryptomator.integrations.mount.MountService; import org.cryptomator.ui.common.FxController; import javax.inject.Inject; -import javax.inject.Named; import javafx.application.Application; import javafx.beans.value.ObservableValue; import javafx.scene.control.ChoiceBox; @@ -17,7 +15,6 @@ import javafx.util.StringConverter; import java.util.List; import java.util.Optional; import java.util.ResourceBundle; -import java.util.concurrent.atomic.AtomicReference; @PreferencesScoped public class VolumePreferencesController implements FxController { @@ -39,7 +36,6 @@ public class VolumePreferencesController implements FxController { VolumePreferencesController(Settings settings, Lazy application, List mountProviders, - @Named("FUPFMS") AtomicReference firstUsedProblematicFuseMountService, ResourceBundle resourceBundle) { this.settings = settings; this.application = application; @@ -101,7 +97,7 @@ public class VolumePreferencesController implements FxController { /* Helpers */ - public class MountServiceConverter extends StringConverter { + private class MountServiceConverter extends StringConverter { @Override public String toString(MountService provider) { diff --git a/src/main/java/org/cryptomator/ui/unlock/UnlockFuseRestartRequiredController.java b/src/main/java/org/cryptomator/ui/unlock/UnlockFuseRestartRequiredController.java index 26ef4c7de..4f9e5649b 100644 --- a/src/main/java/org/cryptomator/ui/unlock/UnlockFuseRestartRequiredController.java +++ b/src/main/java/org/cryptomator/ui/unlock/UnlockFuseRestartRequiredController.java @@ -8,22 +8,31 @@ import org.cryptomator.ui.vaultoptions.SelectedVaultOptionsTab; import javax.inject.Inject; import javafx.fxml.FXML; import javafx.stage.Stage; +import java.util.ResourceBundle; @UnlockScoped public class UnlockFuseRestartRequiredController implements FxController { private final Stage window; + private final ResourceBundle resourceBundle; private final FxApplicationWindows appWindows; private final Vault vault; + @Inject UnlockFuseRestartRequiredController(@UnlockWindow Stage window, + ResourceBundle resourceBundle, FxApplicationWindows appWindows, @UnlockWindow Vault vault) { this.window = window; + this.resourceBundle = resourceBundle; this.appWindows = appWindows; this.vault = vault; } + public void initialize() { + window.setTitle(String.format(resourceBundle.getString("unlock.error.fuseRestartRequired.title"), vault.getDisplayName())); + } + @FXML public void close() { window.close(); diff --git a/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java b/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java index 7c776ad14..98385f1d6 100644 --- a/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java +++ b/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java @@ -23,7 +23,6 @@ import javafx.concurrent.Task; import javafx.scene.Scene; import javafx.stage.Stage; import java.io.IOException; -import java.util.ResourceBundle; /** * A multi-step task that consists of background activities as well as user interaction. @@ -36,7 +35,6 @@ public class UnlockWorkflow extends Task { private static final Logger LOG = LoggerFactory.getLogger(UnlockWorkflow.class); private final Stage window; - private final ResourceBundle resourceBundle; private final Vault vault; private final VaultService vaultService; private final Lazy successScene; @@ -48,7 +46,6 @@ public class UnlockWorkflow extends Task { @Inject UnlockWorkflow(@UnlockWindow Stage window, // - ResourceBundle resourceBundle, @UnlockWindow Vault vault, // VaultService vaultService, // @FxmlScene(FxmlFile.UNLOCK_SUCCESS) Lazy successScene, // @@ -58,7 +55,6 @@ public class UnlockWorkflow extends Task { @UnlockWindow KeyLoadingStrategy keyLoadingStrategy, // @UnlockWindow ObjectProperty illegalMountPointException) { this.window = window; - this.resourceBundle = resourceBundle; this.vault = vault; this.vaultService = vaultService; this.successScene = successScene; @@ -103,7 +99,6 @@ public class UnlockWorkflow extends Task { private void handleFuseRestartRequiredError(FuseRestartRequiredException fRRE) { Platform.runLater(() -> { window.setScene(fuseRestartRequiredScene.get()); - window.setTitle(String.format(resourceBundle.getString("unlock.error.fuseRestartRequired.title"), vault.getDisplayName())); window.show(); }); } diff --git a/src/test/java/org/cryptomator/common/settings/SettingsTest.java b/src/test/java/org/cryptomator/common/settings/SettingsTest.java index ee18b50c1..114b7f980 100644 --- a/src/test/java/org/cryptomator/common/settings/SettingsTest.java +++ b/src/test/java/org/cryptomator/common/settings/SettingsTest.java @@ -24,12 +24,16 @@ public class SettingsTest { Mockito.verify(changeListener, Mockito.times(0)).accept(settings); // first change (to property): - settings.directories.add(vaultSettings); + settings.windowXPosition.set(100); Mockito.verify(changeListener, Mockito.times(1)).accept(settings); // second change (to list): - vaultSettings.displayName.set("asd"); + settings.directories.add(vaultSettings); Mockito.verify(changeListener, Mockito.times(2)).accept(settings); + + // third change (to property of list item): + vaultSettings.displayName.set("asd"); + Mockito.verify(changeListener, Mockito.times(3)).accept(settings); } }