diff --git a/main/ui/src/main/java/org/cryptomator/ui/Cryptomator.java b/main/ui/src/main/java/org/cryptomator/ui/Cryptomator.java index f4fbdb1a0..3150ddc4d 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/Cryptomator.java +++ b/main/ui/src/main/java/org/cryptomator/ui/Cryptomator.java @@ -36,6 +36,8 @@ public class Cryptomator { private static final CleanShutdownPerformer CLEAN_SHUTDOWN_PERFORMER = new CleanShutdownPerformer(); public static void main(String[] args) { + String cryptomatorVersion = Optional.ofNullable(Cryptomator.class.getPackage().getImplementationVersion()).orElse("SNAPSHOT"); + LOG.info("Starting Cryptomator {} on {} {} ({})", cryptomatorVersion, SystemUtils.OS_NAME, SystemUtils.OS_VERSION, SystemUtils.OS_ARCH); if (SystemUtils.IS_OS_MAC_OSX) { /* * On OSX we're in an awkward position. We need to register a handler in the main thread of this application. However, we can't diff --git a/main/ui/src/main/java/org/cryptomator/ui/MainApplication.java b/main/ui/src/main/java/org/cryptomator/ui/MainApplication.java index ed01184b3..86c16261b 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/MainApplication.java +++ b/main/ui/src/main/java/org/cryptomator/ui/MainApplication.java @@ -38,6 +38,7 @@ public class MainApplication extends Application { @Override public void start(Stage primaryStage) throws IOException { + LOG.info("JavaFX application started"); final CryptomatorComponent comp = DaggerCryptomatorComponent.builder().cryptomatorModule(new CryptomatorModule(this, primaryStage)).build(); final MainController mainCtrl = comp.mainController(); closer = comp.deferredCloser(); diff --git a/main/ui/src/main/java/org/cryptomator/ui/settings/Settings.java b/main/ui/src/main/java/org/cryptomator/ui/settings/Settings.java index 85c8fefdc..ca3800069 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/settings/Settings.java +++ b/main/ui/src/main/java/org/cryptomator/ui/settings/Settings.java @@ -11,6 +11,7 @@ package org.cryptomator.ui.settings; import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import java.util.function.Consumer; import org.cryptomator.ui.model.Vault; @@ -27,6 +28,8 @@ public class Settings implements Serializable { public static final boolean DEFAULT_USE_IPV6 = false; public static final Integer DEFAULT_NUM_TRAY_NOTIFICATIONS = 3; + private final Consumer saveCmd; + @JsonProperty("directories") private List directories; @@ -35,7 +38,7 @@ public class Settings implements Serializable { @JsonProperty("port") private Integer port; - + @JsonProperty("useIpv6") private Boolean useIpv6; @@ -46,7 +49,26 @@ public class Settings implements Serializable { * Package-private constructor; use {@link SettingsProvider}. */ Settings() { + this.saveCmd = s -> { + }; + } + private Settings(Consumer saveCmd) { + this.saveCmd = saveCmd; + } + + Settings withSaveCmd(Consumer saveCmd) { + final Settings result = new Settings(saveCmd); + result.directories = this.directories; + result.checkForUpdatesEnabled = this.checkForUpdatesEnabled; + result.port = this.port; + result.useIpv6 = this.useIpv6; + result.numTrayNotifications = this.numTrayNotifications; + return result; + } + + private void save() { + saveCmd.accept(this); } /* Getter/Setter */ @@ -60,6 +82,7 @@ public class Settings implements Serializable { public void setDirectories(List directories) { this.directories = directories; + save(); } public boolean isCheckForUpdatesEnabled() { @@ -69,6 +92,7 @@ public class Settings implements Serializable { public void setCheckForUpdatesEnabled(boolean checkForUpdatesEnabled) { this.checkForUpdatesEnabled = checkForUpdatesEnabled; + save(); } public void setPort(int port) { @@ -76,6 +100,7 @@ public class Settings implements Serializable { throw new IllegalArgumentException("Invalid port"); } this.port = port; + save(); } public int getPort() { @@ -96,6 +121,7 @@ public class Settings implements Serializable { public void setUseIpv6(boolean useIpv6) { this.useIpv6 = useIpv6; + save(); } public Integer getNumTrayNotifications() { @@ -104,6 +130,7 @@ public class Settings implements Serializable { public void setNumTrayNotifications(Integer numTrayNotifications) { this.numTrayNotifications = numTrayNotifications; + save(); } } diff --git a/main/ui/src/main/java/org/cryptomator/ui/settings/SettingsProvider.java b/main/ui/src/main/java/org/cryptomator/ui/settings/SettingsProvider.java index 9d40ac09d..1bfddbddf 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/settings/SettingsProvider.java +++ b/main/ui/src/main/java/org/cryptomator/ui/settings/SettingsProvider.java @@ -23,7 +23,6 @@ import javax.inject.Provider; import javax.inject.Singleton; import org.apache.commons.lang3.SystemUtils; -import org.cryptomator.ui.util.DeferredCloser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,7 +31,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; @Singleton public class SettingsProvider implements Provider { - private static final Logger LOG = LoggerFactory.getLogger(Settings.class); + private static final Logger LOG = LoggerFactory.getLogger(SettingsProvider.class); private static final Path SETTINGS_DIR; private static final String SETTINGS_FILE = "settings.json"; @@ -52,12 +51,10 @@ public class SettingsProvider implements Provider { } } - private final DeferredCloser deferredCloser; private final ObjectMapper objectMapper; @Inject - public SettingsProvider(DeferredCloser deferredCloser, @Named("VaultJsonMapper") ObjectMapper objectMapper) { - this.deferredCloser = deferredCloser; + public SettingsProvider(@Named("VaultJsonMapper") ObjectMapper objectMapper) { this.objectMapper = objectMapper; } @@ -77,12 +74,12 @@ public class SettingsProvider implements Provider { final Path settingsPath = getSettingsPath(); final InputStream in = Files.newInputStream(settingsPath, StandardOpenOption.READ); settings = objectMapper.readValue(in, Settings.class); + LOG.info("Settings loaded from " + settingsPath); } catch (IOException e) { - LOG.warn("Failed to load settings, creating new one."); + LOG.info("Failed to load settings, creating new one."); settings = new Settings(); } - deferredCloser.closeLater(settings, this::save); - return settings; + return settings.withSaveCmd(this::save); } private void save(Settings settings) { @@ -94,6 +91,7 @@ public class SettingsProvider implements Provider { Files.createDirectories(settingsPath.getParent()); final OutputStream out = Files.newOutputStream(settingsPath, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE); objectMapper.writeValue(out, settings); + LOG.info("Settings saved to " + settingsPath); } catch (IOException e) { LOG.error("Failed to save settings.", e); }