mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-18 02:31:27 +00:00
fixes #209
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<Settings> saveCmd;
|
||||
|
||||
@JsonProperty("directories")
|
||||
private List<Vault> 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<Settings> saveCmd) {
|
||||
this.saveCmd = saveCmd;
|
||||
}
|
||||
|
||||
Settings withSaveCmd(Consumer<Settings> 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<Vault> 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Settings> {
|
||||
|
||||
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<Settings> {
|
||||
}
|
||||
}
|
||||
|
||||
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<Settings> {
|
||||
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<Settings> {
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user