From ba34b37f8ae9bdefbf816254d43cd0ba62db8730 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Mon, 29 Jul 2019 16:28:29 +0200 Subject: [PATCH] Added options to start Cryptomator in background (references #418) --- .../org/cryptomator/common/settings/Settings.java | 7 +++++++ .../common/settings/SettingsJsonAdapter.java | 4 ++++ .../ui/preferences/PreferencesController.java | 3 +++ .../cryptomator/ui/traymenu/TrayMenuController.java | 11 ++++++++++- main/ui/src/main/resources/fxml/preferences.fxml | 2 ++ main/ui/src/main/resources/i18n/strings.properties | 1 + main/ui/src/main/resources/i18n/strings_en.properties | 1 + 7 files changed, 28 insertions(+), 1 deletion(-) diff --git a/main/commons/src/main/java/org/cryptomator/common/settings/Settings.java b/main/commons/src/main/java/org/cryptomator/common/settings/Settings.java index 9c5a3c96b..3960cf1f6 100644 --- a/main/commons/src/main/java/org/cryptomator/common/settings/Settings.java +++ b/main/commons/src/main/java/org/cryptomator/common/settings/Settings.java @@ -26,6 +26,7 @@ public class Settings { public static final int MAX_PORT = 65535; public static final boolean DEFAULT_ASKED_FOR_UPDATE_CHECK = false; public static final boolean DEFAULT_CHECK_FOR_UDPATES = false; + public static final boolean DEFAULT_START_HIDDEN = 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; @@ -36,6 +37,7 @@ public class Settings { private final ObservableList directories = FXCollections.observableArrayList(VaultSettings::observables); private final BooleanProperty askedForUpdateCheck = new SimpleBooleanProperty(DEFAULT_ASKED_FOR_UPDATE_CHECK); private final BooleanProperty checkForUpdates = new SimpleBooleanProperty(DEFAULT_CHECK_FOR_UDPATES); + private final BooleanProperty startHidden = new SimpleBooleanProperty(DEFAULT_START_HIDDEN); 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); @@ -52,6 +54,7 @@ public class Settings { directories.addListener(this::somethingChanged); askedForUpdateCheck.addListener(this::somethingChanged); checkForUpdates.addListener(this::somethingChanged); + startHidden.addListener(this::somethingChanged); port.addListener(this::somethingChanged); numTrayNotifications.addListener(this::somethingChanged); preferredGvfsScheme.addListener(this::somethingChanged); @@ -87,6 +90,10 @@ public class Settings { public BooleanProperty checkForUpdates() { return checkForUpdates; } + + public BooleanProperty startHidden() { + return startHidden; + } public IntegerProperty port() { return port; diff --git a/main/commons/src/main/java/org/cryptomator/common/settings/SettingsJsonAdapter.java b/main/commons/src/main/java/org/cryptomator/common/settings/SettingsJsonAdapter.java index 42ae08f38..0929ed050 100644 --- a/main/commons/src/main/java/org/cryptomator/common/settings/SettingsJsonAdapter.java +++ b/main/commons/src/main/java/org/cryptomator/common/settings/SettingsJsonAdapter.java @@ -29,6 +29,7 @@ public class SettingsJsonAdapter extends TypeAdapter { writeVaultSettingsArray(out, value.getDirectories()); out.name("askedForUpdateCheck").value(value.askedForUpdateCheck().get()); out.name("checkForUpdatesEnabled").value(value.checkForUpdates().get()); + out.name("startHidden").value(value.startHidden().get()); out.name("port").value(value.port().get()); out.name("numTrayNotifications").value(value.numTrayNotifications().get()); out.name("preferredGvfsScheme").value(value.preferredGvfsScheme().get().name()); @@ -63,6 +64,9 @@ public class SettingsJsonAdapter extends TypeAdapter { case "checkForUpdatesEnabled": settings.checkForUpdates().set(in.nextBoolean()); break; + case "startHidden": + settings.startHidden().set(in.nextBoolean()); + break; case "port": settings.port().set(in.nextInt()); break; diff --git a/main/ui/src/main/java/org/cryptomator/ui/preferences/PreferencesController.java b/main/ui/src/main/java/org/cryptomator/ui/preferences/PreferencesController.java index e229ab2a4..5614c25bd 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/preferences/PreferencesController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/preferences/PreferencesController.java @@ -22,6 +22,7 @@ public class PreferencesController implements FxController { private final Settings settings; private final BooleanBinding showWebDavSettings; public ChoiceBox themeChoiceBox; + public CheckBox startHiddenCheckbox; public CheckBox checkForUpdatesCheckbox; public CheckBox debugModeCheckbox; public ChoiceBox volumeTypeChoicBox; @@ -40,6 +41,8 @@ public class PreferencesController implements FxController { themeChoiceBox.valueProperty().bindBidirectional(settings.theme()); themeChoiceBox.setConverter(new UiThemeConverter()); + startHiddenCheckbox.selectedProperty().bindBidirectional(settings.startHidden()); + checkForUpdatesCheckbox.selectedProperty().bindBidirectional(settings.checkForUpdates()); debugModeCheckbox.selectedProperty().bindBidirectional(settings.debugMode()); diff --git a/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java b/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java index e2217c810..1f763965c 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java @@ -1,5 +1,7 @@ package org.cryptomator.ui.traymenu; +import org.cryptomator.common.settings.Settings; + import javax.inject.Inject; import javax.inject.Named; import java.awt.Desktop; @@ -14,12 +16,14 @@ class TrayMenuController { private final FxApplicationStarter fxApplicationStarter; private final CountDownLatch shutdownLatch; + private final Settings settings; private final PopupMenu menu; @Inject - TrayMenuController(FxApplicationStarter fxApplicationStarter, @Named("shutdownLatch") CountDownLatch shutdownLatch) { + TrayMenuController(FxApplicationStarter fxApplicationStarter, @Named("shutdownLatch") CountDownLatch shutdownLatch, Settings settings) { this.fxApplicationStarter = fxApplicationStarter; this.shutdownLatch = shutdownLatch; + this.settings = settings; this.menu = new PopupMenu(); } @@ -35,6 +39,11 @@ class TrayMenuController { if (Desktop.getDesktop().isSupported(Desktop.Action.APP_PREFERENCES)) { Desktop.getDesktop().setPreferencesHandler(this::showPreferencesWindow); } + + // show window on start? + if (!settings.startHidden().get()) { + showMainWindow(null); + } } private void rebuildMenu() { diff --git a/main/ui/src/main/resources/fxml/preferences.fxml b/main/ui/src/main/resources/fxml/preferences.fxml index 0a0e4ea26..89b043940 100644 --- a/main/ui/src/main/resources/fxml/preferences.fxml +++ b/main/ui/src/main/resources/fxml/preferences.fxml @@ -22,6 +22,8 @@ + + diff --git a/main/ui/src/main/resources/i18n/strings.properties b/main/ui/src/main/resources/i18n/strings.properties index 8352dd9c3..040d014da 100644 --- a/main/ui/src/main/resources/i18n/strings.properties +++ b/main/ui/src/main/resources/i18n/strings.properties @@ -5,6 +5,7 @@ main.settingsBtn.tooltip=Settings preferences.title=Preferences preferences.autoUpdateCheck=Check for updates automatically preferences.debugLogging=Enable debug logging +preferences.startHidden=Hide window when starting Cryptomator preferences.theme=Look & Feel preferences.volumeType=Volume type unlock.deleteSavedPasswordDialog.title=Delete Saved Password diff --git a/main/ui/src/main/resources/i18n/strings_en.properties b/main/ui/src/main/resources/i18n/strings_en.properties index 60f05f5dd..57381e36a 100644 --- a/main/ui/src/main/resources/i18n/strings_en.properties +++ b/main/ui/src/main/resources/i18n/strings_en.properties @@ -4,6 +4,7 @@ main.closeBtn.tooltip=Close main.settingsBtn.tooltip=Settings preferences.autoUpdateCheck=Check for updates automatically preferences.debugLogging=Enable debug logging +preferences.startHidden=Hide window when starting Cryptomator preferences.theme=Look & Feel preferences.volumeType=Volume type vaultlist.emptyList.onboardingInstruction=Click here to add a vault \ No newline at end of file