From 8f85777887f433fe48e52bc3641094e4a7bb75a9 Mon Sep 17 00:00:00 2001 From: Jan-Peter Klein Date: Tue, 31 May 2022 11:18:20 +0200 Subject: [PATCH 01/10] =?UTF-8?q?implemented=20functionality=20of=20featur?= =?UTF-8?q?e=20request=20issue=20#1713=20"On=20closing=20of=20the=20applic?= =?UTF-8?q?ation:=20Always=20lock=20and=20quit=20=E2=80=93=20without=20ask?= =?UTF-8?q?ing"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/cryptomator/common/settings/Settings.java | 7 +++++++ .../common/settings/SettingsJsonAdapter.java | 2 ++ .../ui/fxapp/FxApplicationTerminator.java | 7 +++++-- .../preferences/GeneralPreferencesController.java | 3 +++ .../org/cryptomator/ui/quit/QuitController.java | 13 +++++++++++-- src/main/resources/fxml/preferences_general.fxml | 2 ++ src/main/resources/fxml/quit.fxml | 6 +++++- src/main/resources/i18n/strings.properties | 2 ++ .../common/settings/SettingsJsonAdapterTest.java | 2 ++ 9 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/cryptomator/common/settings/Settings.java b/src/main/java/org/cryptomator/common/settings/Settings.java index 8cc23bbfc..670fec410 100644 --- a/src/main/java/org/cryptomator/common/settings/Settings.java +++ b/src/main/java/org/cryptomator/common/settings/Settings.java @@ -32,6 +32,7 @@ public class Settings { public static final boolean DEFAULT_ASKED_FOR_UPDATE_CHECK = false; public static final boolean DEFAULT_CHECK_FOR_UPDATES = false; public static final boolean DEFAULT_START_HIDDEN = false; + public static final boolean DEFAULT_AUTO_CLOSE_VAULTS = false; public static final int DEFAULT_PORT = 42427; public static final int DEFAULT_NUM_TRAY_NOTIFICATIONS = 3; public static final WebDavUrlScheme DEFAULT_GVFS_SCHEME = WebDavUrlScheme.DAV; @@ -51,6 +52,7 @@ public class Settings { private final BooleanProperty askedForUpdateCheck = new SimpleBooleanProperty(DEFAULT_ASKED_FOR_UPDATE_CHECK); private final BooleanProperty checkForUpdates = new SimpleBooleanProperty(DEFAULT_CHECK_FOR_UPDATES); private final BooleanProperty startHidden = new SimpleBooleanProperty(DEFAULT_START_HIDDEN); + private final BooleanProperty autoCloseVaults = new SimpleBooleanProperty(DEFAULT_AUTO_CLOSE_VAULTS); private final IntegerProperty port = new SimpleIntegerProperty(DEFAULT_PORT); private final IntegerProperty numTrayNotifications = new SimpleIntegerProperty(DEFAULT_NUM_TRAY_NOTIFICATIONS); private final ObjectProperty preferredGvfsScheme = new SimpleObjectProperty<>(DEFAULT_GVFS_SCHEME); @@ -82,6 +84,7 @@ public class Settings { askedForUpdateCheck.addListener(this::somethingChanged); checkForUpdates.addListener(this::somethingChanged); startHidden.addListener(this::somethingChanged); + autoCloseVaults.addListener(this::somethingChanged); port.addListener(this::somethingChanged); numTrayNotifications.addListener(this::somethingChanged); preferredGvfsScheme.addListener(this::somethingChanged); @@ -133,6 +136,10 @@ public class Settings { return startHidden; } + public BooleanProperty autoCloseVaults() { + return autoCloseVaults; + } + public IntegerProperty port() { return port; } diff --git a/src/main/java/org/cryptomator/common/settings/SettingsJsonAdapter.java b/src/main/java/org/cryptomator/common/settings/SettingsJsonAdapter.java index d10066f8f..3f4614604 100644 --- a/src/main/java/org/cryptomator/common/settings/SettingsJsonAdapter.java +++ b/src/main/java/org/cryptomator/common/settings/SettingsJsonAdapter.java @@ -41,6 +41,7 @@ public class SettingsJsonAdapter extends TypeAdapter { out.name("askedForUpdateCheck").value(value.askedForUpdateCheck().get()); out.name("checkForUpdatesEnabled").value(value.checkForUpdates().get()); out.name("startHidden").value(value.startHidden().get()); + out.name("autoCloseVaults").value(value.autoCloseVaults().get()); out.name("port").value(value.port().get()); out.name("numTrayNotifications").value(value.numTrayNotifications().get()); out.name("preferredGvfsScheme").value(value.preferredGvfsScheme().get().name()); @@ -82,6 +83,7 @@ public class SettingsJsonAdapter extends TypeAdapter { case "askedForUpdateCheck" -> settings.askedForUpdateCheck().set(in.nextBoolean()); case "checkForUpdatesEnabled" -> settings.checkForUpdates().set(in.nextBoolean()); case "startHidden" -> settings.startHidden().set(in.nextBoolean()); + case "autoCloseVaults" -> settings.autoCloseVaults().set(in.nextBoolean()); case "port" -> settings.port().set(in.nextInt()); case "numTrayNotifications" -> settings.numTrayNotifications().set(in.nextInt()); case "preferredGvfsScheme" -> settings.preferredGvfsScheme().set(parseWebDavUrlSchemePrefix(in.nextString())); diff --git a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationTerminator.java b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationTerminator.java index 7c7b07c1e..5b68b5992 100644 --- a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationTerminator.java +++ b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationTerminator.java @@ -2,6 +2,7 @@ package org.cryptomator.ui.fxapp; import com.google.common.base.Preconditions; import org.cryptomator.common.ShutdownHook; +import org.cryptomator.common.settings.Settings; import org.cryptomator.common.vaults.LockNotCompletedException; import org.cryptomator.common.vaults.Vault; import org.cryptomator.common.vaults.VaultState; @@ -33,12 +34,14 @@ public class FxApplicationTerminator { private final ShutdownHook shutdownHook; private final FxApplicationWindows appWindows; private final AtomicBoolean allowQuitWithoutPrompt = new AtomicBoolean(); + private final Settings settings; @Inject - public FxApplicationTerminator(ObservableList vaults, ShutdownHook shutdownHook, FxApplicationWindows appWindows) { + public FxApplicationTerminator(ObservableList vaults, ShutdownHook shutdownHook, FxApplicationWindows appWindows, Settings settings) { this.vaults = vaults; this.shutdownHook = shutdownHook; this.appWindows = appWindows; + this.settings = settings; } public void initialize() { @@ -92,7 +95,7 @@ public class FxApplicationTerminator { */ private void handleQuitRequest(@SuppressWarnings("unused") @Nullable EventObject e, QuitResponse response) { var exitingResponse = new ExitingQuitResponse(response); - if (allowQuitWithoutPrompt.get()) { + if (allowQuitWithoutPrompt.get() || settings.autoCloseVaults().get()) { exitingResponse.performQuit(); } else { appWindows.showQuitWindow(exitingResponse); diff --git a/src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java b/src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java index d33e919b6..f35f17f27 100644 --- a/src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java +++ b/src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java @@ -36,6 +36,7 @@ public class GeneralPreferencesController implements FxController { private final FxApplicationWindows appWindows; public ChoiceBox keychainBackendChoiceBox; public CheckBox startHiddenCheckbox; + public CheckBox autoCloseVaultsCheckbox; public CheckBox debugModeCheckbox; public CheckBox autoStartCheckbox; public ToggleGroup nodeOrientation; @@ -55,6 +56,8 @@ public class GeneralPreferencesController implements FxController { public void initialize() { startHiddenCheckbox.selectedProperty().bindBidirectional(settings.startHidden()); + autoCloseVaultsCheckbox.selectedProperty().bindBidirectional(settings.autoCloseVaults()); + debugModeCheckbox.selectedProperty().bindBidirectional(settings.debugMode()); autoStartProvider.ifPresent(autoStart -> autoStartCheckbox.setSelected(autoStart.isEnabled())); diff --git a/src/main/java/org/cryptomator/ui/quit/QuitController.java b/src/main/java/org/cryptomator/ui/quit/QuitController.java index 207ae42c8..b4dfe408e 100644 --- a/src/main/java/org/cryptomator/ui/quit/QuitController.java +++ b/src/main/java/org/cryptomator/ui/quit/QuitController.java @@ -1,5 +1,6 @@ package org.cryptomator.ui.quit; +import org.cryptomator.common.settings.Settings; import org.cryptomator.common.vaults.Vault; import org.cryptomator.ui.common.FxController; import org.cryptomator.ui.common.VaultService; @@ -11,6 +12,7 @@ import javafx.collections.ObservableList; import javafx.concurrent.Task; import javafx.fxml.FXML; import javafx.scene.control.Button; +import javafx.scene.control.CheckBox; import javafx.scene.control.ContentDisplay; import javafx.stage.Stage; import java.awt.desktop.QuitResponse; @@ -30,19 +32,26 @@ public class QuitController implements FxController { private final ExecutorService executorService; private final VaultService vaultService; private final AtomicReference quitResponse = new AtomicReference<>(); - + private final Settings settings; /* FXML */ public Button lockAndQuitButton; + public CheckBox rememberAlwaysLockAndQuitCheckbox; @Inject - QuitController(@QuitWindow Stage window, ObservableList vaults, ExecutorService executorService, VaultService vaultService) { + QuitController(@QuitWindow Stage window, ObservableList vaults, ExecutorService executorService, VaultService vaultService, Settings settings) { this.window = window; this.unlockedVaults = vaults.filtered(Vault::isUnlocked); this.executorService = executorService; this.vaultService = vaultService; + this.settings = settings; window.setOnCloseRequest(windowEvent -> cancel()); } + @FXML + public void initialize() { + rememberAlwaysLockAndQuitCheckbox.selectedProperty().bindBidirectional(settings.autoCloseVaults()); + } + public void updateQuitRequest(QuitResponse newResponse) { var oldResponse = quitResponse.getAndSet(newResponse); if (oldResponse != null) { diff --git a/src/main/resources/fxml/preferences_general.fxml b/src/main/resources/fxml/preferences_general.fxml index 6d2b68447..c255e2a0f 100644 --- a/src/main/resources/fxml/preferences_general.fxml +++ b/src/main/resources/fxml/preferences_general.fxml @@ -24,6 +24,8 @@ + + diff --git a/src/main/resources/i18n/strings.properties b/src/main/resources/i18n/strings.properties index 8660c8532..655eb7d94 100644 --- a/src/main/resources/i18n/strings.properties +++ b/src/main/resources/i18n/strings.properties @@ -194,6 +194,7 @@ preferences.title=Preferences ## General preferences.general=General preferences.general.startHidden=Hide window when starting Cryptomator +preferences.general.autoCloseVaults=Lock open vaults automatically when quitting application preferences.general.debugLogging=Enable debug logging preferences.general.debugDirectory=Reveal log files preferences.general.autoStart=Launch Cryptomator on system start @@ -382,3 +383,4 @@ passwordStrength.messageLabel.4=Very strong # Quit quit.prompt=Quit application? There are unlocked vaults. quit.lockAndQuit=Lock and Quit +quit.prompt.rememberAlwaysLockAndQuitCheckbox=Always lock all vaults and quit application \ No newline at end of file diff --git a/src/test/java/org/cryptomator/common/settings/SettingsJsonAdapterTest.java b/src/test/java/org/cryptomator/common/settings/SettingsJsonAdapterTest.java index a8bc4551a..fc24fdbf1 100644 --- a/src/test/java/org/cryptomator/common/settings/SettingsJsonAdapterTest.java +++ b/src/test/java/org/cryptomator/common/settings/SettingsJsonAdapterTest.java @@ -27,6 +27,7 @@ public class SettingsJsonAdapterTest { {"id": "1", "path": "/vault1", "mountName": "vault1", "winDriveLetter": "X"}, {"id": "2", "path": "/vault2", "mountName": "vault2", "winDriveLetter": "Y"} ], + "autoCloseVaults" : true, "checkForUpdatesEnabled": true, "port": 8080, "language": "de-DE", @@ -40,6 +41,7 @@ public class SettingsJsonAdapterTest { Assertions.assertTrue(settings.checkForUpdates().get()); Assertions.assertEquals(2, settings.getDirectories().size()); Assertions.assertEquals(8080, settings.port().get()); + Assertions.assertEquals(true, settings.autoCloseVaults().get()); Assertions.assertEquals("de-DE", settings.languageProperty().get()); Assertions.assertEquals(42, settings.numTrayNotifications().get()); Assertions.assertEquals(WebDavUrlScheme.DAV, settings.preferredGvfsScheme().get()); From 6f33cf8df7d49e5ac3e5e683b0ef86e134c0383d Mon Sep 17 00:00:00 2001 From: Jan-Peter Klein Date: Tue, 31 May 2022 14:09:12 +0200 Subject: [PATCH 02/10] removed checkbox in quit prompt --- .../java/org/cryptomator/ui/quit/QuitController.java | 10 +--------- src/main/resources/fxml/quit.fxml | 6 +----- src/main/resources/i18n/strings.properties | 3 +-- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/cryptomator/ui/quit/QuitController.java b/src/main/java/org/cryptomator/ui/quit/QuitController.java index b4dfe408e..e9cf1f365 100644 --- a/src/main/java/org/cryptomator/ui/quit/QuitController.java +++ b/src/main/java/org/cryptomator/ui/quit/QuitController.java @@ -12,7 +12,6 @@ import javafx.collections.ObservableList; import javafx.concurrent.Task; import javafx.fxml.FXML; import javafx.scene.control.Button; -import javafx.scene.control.CheckBox; import javafx.scene.control.ContentDisplay; import javafx.stage.Stage; import java.awt.desktop.QuitResponse; @@ -32,10 +31,9 @@ public class QuitController implements FxController { private final ExecutorService executorService; private final VaultService vaultService; private final AtomicReference quitResponse = new AtomicReference<>(); - private final Settings settings; + /* FXML */ public Button lockAndQuitButton; - public CheckBox rememberAlwaysLockAndQuitCheckbox; @Inject QuitController(@QuitWindow Stage window, ObservableList vaults, ExecutorService executorService, VaultService vaultService, Settings settings) { @@ -43,15 +41,9 @@ public class QuitController implements FxController { this.unlockedVaults = vaults.filtered(Vault::isUnlocked); this.executorService = executorService; this.vaultService = vaultService; - this.settings = settings; window.setOnCloseRequest(windowEvent -> cancel()); } - @FXML - public void initialize() { - rememberAlwaysLockAndQuitCheckbox.selectedProperty().bindBidirectional(settings.autoCloseVaults()); - } - public void updateQuitRequest(QuitResponse newResponse) { var oldResponse = quitResponse.getAndSet(newResponse); if (oldResponse != null) { diff --git a/src/main/resources/fxml/quit.fxml b/src/main/resources/fxml/quit.fxml index 9c8bfc416..8db6eafc7 100644 --- a/src/main/resources/fxml/quit.fxml +++ b/src/main/resources/fxml/quit.fxml @@ -10,7 +10,6 @@ - - - +