From 49769f986a5d8d94090099c7cfbe7b2514a61f95 Mon Sep 17 00:00:00 2001 From: Jan-Peter Klein Date: Fri, 3 Nov 2023 10:47:43 +0100 Subject: [PATCH] remove port from settings --- src/main/java/org/cryptomator/common/CommonsModule.java | 7 ++++--- .../java/org/cryptomator/common/settings/Settings.java | 5 ----- .../org/cryptomator/common/settings/SettingsJson.java | 3 --- .../org/cryptomator/common/settings/VaultSettings.java | 1 + .../cryptomator/common/settings/VaultSettingsJson.java | 2 +- .../org/cryptomator/common/vaults/VaultListManager.java | 4 ++-- .../org/cryptomator/common/settings/SettingsJsonTest.java | 2 -- .../org/cryptomator/common/settings/SettingsTest.java | 8 ++------ 8 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/cryptomator/common/CommonsModule.java b/src/main/java/org/cryptomator/common/CommonsModule.java index 76dfb92ed..9cba60131 100644 --- a/src/main/java/org/cryptomator/common/CommonsModule.java +++ b/src/main/java/org/cryptomator/common/CommonsModule.java @@ -12,6 +12,7 @@ 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; @@ -139,10 +140,10 @@ public abstract class CommonsModule { @Provides @Singleton - static ObservableValue provideServerSocketAddressBinding(Settings settings) { - return settings.port.map(port -> { + 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, settings.port.intValue()); + return InetSocketAddress.createUnresolved(host, vaultSettings.port.intValue()); }); } diff --git a/src/main/java/org/cryptomator/common/settings/Settings.java b/src/main/java/org/cryptomator/common/settings/Settings.java index 4e0e0df97..b8a872a98 100644 --- a/src/main/java/org/cryptomator/common/settings/Settings.java +++ b/src/main/java/org/cryptomator/common/settings/Settings.java @@ -36,7 +36,6 @@ public class Settings { static final boolean DEFAULT_START_HIDDEN = false; static final boolean DEFAULT_AUTO_CLOSE_VAULTS = false; static final boolean DEFAULT_USE_KEYCHAIN = true; - static final int DEFAULT_PORT = 42427; static final int DEFAULT_NUM_TRAY_NOTIFICATIONS = 3; static final boolean DEFAULT_DEBUG_MODE = false; static final UiTheme DEFAULT_THEME = UiTheme.LIGHT; @@ -52,7 +51,6 @@ public class Settings { public final BooleanProperty startHidden; public final BooleanProperty autoCloseVaults; public final BooleanProperty useKeychain; - public final IntegerProperty port; public final IntegerProperty numTrayNotifications; public final BooleanProperty debugMode; public final ObjectProperty theme; @@ -89,7 +87,6 @@ public class Settings { this.startHidden = new SimpleBooleanProperty(this, "startHidden", json.startHidden); this.autoCloseVaults = new SimpleBooleanProperty(this, "autoCloseVaults", json.autoCloseVaults); this.useKeychain = new SimpleBooleanProperty(this, "useKeychain", json.useKeychain); - this.port = new SimpleIntegerProperty(this, "webDavPort", json.port); this.numTrayNotifications = new SimpleIntegerProperty(this, "numTrayNotifications", json.numTrayNotifications); this.debugMode = new SimpleBooleanProperty(this, "debugMode", json.debugMode); this.theme = new SimpleObjectProperty<>(this, "theme", json.theme); @@ -116,7 +113,6 @@ public class Settings { startHidden.addListener(this::somethingChanged); autoCloseVaults.addListener(this::somethingChanged); useKeychain.addListener(this::somethingChanged); - port.addListener(this::somethingChanged); numTrayNotifications.addListener(this::somethingChanged); debugMode.addListener(this::somethingChanged); theme.addListener(this::somethingChanged); @@ -170,7 +166,6 @@ public class Settings { json.startHidden = startHidden.get(); json.autoCloseVaults = autoCloseVaults.get(); json.useKeychain = useKeychain.get(); - json.port = port.get(); json.numTrayNotifications = numTrayNotifications.get(); json.debugMode = debugMode.get(); json.theme = theme.get(); diff --git a/src/main/java/org/cryptomator/common/settings/SettingsJson.java b/src/main/java/org/cryptomator/common/settings/SettingsJson.java index 2c7c963da..d1c9137c5 100644 --- a/src/main/java/org/cryptomator/common/settings/SettingsJson.java +++ b/src/main/java/org/cryptomator/common/settings/SettingsJson.java @@ -46,9 +46,6 @@ class SettingsJson { @JsonProperty("numTrayNotifications") int numTrayNotifications = Settings.DEFAULT_NUM_TRAY_NOTIFICATIONS; - @JsonProperty("port") - int port = Settings.DEFAULT_PORT; - @JsonProperty("showMinimizeButton") boolean showMinimizeButton = Settings.DEFAULT_SHOW_MINIMIZE_BUTTON; diff --git a/src/main/java/org/cryptomator/common/settings/VaultSettings.java b/src/main/java/org/cryptomator/common/settings/VaultSettings.java index 0a5fe45c1..5baf12ff0 100644 --- a/src/main/java/org/cryptomator/common/settings/VaultSettings.java +++ b/src/main/java/org/cryptomator/common/settings/VaultSettings.java @@ -38,6 +38,7 @@ public class VaultSettings { static final WhenUnlocked DEFAULT_ACTION_AFTER_UNLOCK = WhenUnlocked.ASK; static final boolean DEFAULT_AUTOLOCK_WHEN_IDLE = false; static final int DEFAULT_AUTOLOCK_IDLE_SECONDS = 30 * 60; + static final int DEFAULT_PORT = 42427; private static final Random RNG = new Random(); diff --git a/src/main/java/org/cryptomator/common/settings/VaultSettingsJson.java b/src/main/java/org/cryptomator/common/settings/VaultSettingsJson.java index cb03c401e..43aa204e8 100644 --- a/src/main/java/org/cryptomator/common/settings/VaultSettingsJson.java +++ b/src/main/java/org/cryptomator/common/settings/VaultSettingsJson.java @@ -49,7 +49,7 @@ class VaultSettingsJson { String mountService; @JsonProperty("port") - int port = Settings.DEFAULT_PORT; + int port = VaultSettings.DEFAULT_PORT; @Deprecated(since = "1.7.0") @JsonProperty(value = "winDriveLetter", access = JsonProperty.Access.WRITE_ONLY) // WRITE_ONLY means value is "written" into the java object during deserialization. Upvote this: https://github.com/FasterXML/jackson-annotations/issues/233 diff --git a/src/main/java/org/cryptomator/common/vaults/VaultListManager.java b/src/main/java/org/cryptomator/common/vaults/VaultListManager.java index 1ed5274ed..0351981a0 100644 --- a/src/main/java/org/cryptomator/common/vaults/VaultListManager.java +++ b/src/main/java/org/cryptomator/common/vaults/VaultListManager.java @@ -73,8 +73,8 @@ public class VaultListManager { private VaultSettings newVaultSettings(Path path) { VaultSettings vaultSettings = VaultSettings.withRandomId(); vaultSettings.path.set(path); - vaultSettings.mountService.set(settings.mountService.getValue()); - vaultSettings.port.set(settings.port.getValue()); + 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/test/java/org/cryptomator/common/settings/SettingsJsonTest.java b/src/test/java/org/cryptomator/common/settings/SettingsJsonTest.java index da78ee5bc..00107bc58 100644 --- a/src/test/java/org/cryptomator/common/settings/SettingsJsonTest.java +++ b/src/test/java/org/cryptomator/common/settings/SettingsJsonTest.java @@ -26,7 +26,6 @@ public class SettingsJsonTest { ], "autoCloseVaults" : true, "checkForUpdatesEnabled": true, - "port": 8080, "language": "de-DE", "numTrayNotifications": 42 } @@ -39,7 +38,6 @@ public class SettingsJsonTest { Assertions.assertEquals("/vault1", jsonObj.directories.get(0).path); Assertions.assertEquals("/vault2", jsonObj.directories.get(1).path); Assertions.assertEquals("--foo --bar", jsonObj.directories.get(1).mountFlags); - Assertions.assertEquals(8080, jsonObj.port); Assertions.assertTrue(jsonObj.autoCloseVaults); Assertions.assertEquals("de-DE", jsonObj.language); Assertions.assertEquals(42, jsonObj.numTrayNotifications); diff --git a/src/test/java/org/cryptomator/common/settings/SettingsTest.java b/src/test/java/org/cryptomator/common/settings/SettingsTest.java index cd737ac11..ee18b50c1 100644 --- a/src/test/java/org/cryptomator/common/settings/SettingsTest.java +++ b/src/test/java/org/cryptomator/common/settings/SettingsTest.java @@ -24,16 +24,12 @@ public class SettingsTest { Mockito.verify(changeListener, Mockito.times(0)).accept(settings); // first change (to property): - settings.port.set(42428); + settings.directories.add(vaultSettings); Mockito.verify(changeListener, Mockito.times(1)).accept(settings); // second change (to list): - 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); + Mockito.verify(changeListener, Mockito.times(2)).accept(settings); } }