Implementing new settings and locking after a certain amount of minutes

This commit is contained in:
Martin Beyer
2021-03-29 10:44:39 +02:00
parent 8592e3667b
commit 1292548042
6 changed files with 64 additions and 14 deletions
@@ -40,6 +40,8 @@ public class VaultSettings {
public static final boolean DEFAULT_LOCK_ON_SLEEP = false;
public static final boolean DEFAULT_LOCK_AFTER_IDLETIME = false;
public static final String DEFAULT_LOCK_IDLETIME_IN_MINUTES = "30";
public static final boolean DEFAULT_LOCK_AFTER_TIME = false;
public static final String DEFAULT_LOCK_TIME_IN_MINUTES = "30";
private static final Random RNG = new Random();
@@ -58,6 +60,8 @@ public class VaultSettings {
private final BooleanProperty lockOnSleep = new SimpleBooleanProperty(DEFAULT_LOCK_ON_SLEEP);
private final BooleanProperty lockAfterIdleTime = new SimpleBooleanProperty(DEFAULT_LOCK_AFTER_IDLETIME);
private final StringProperty lockIdleTimeInMinutes = new SimpleStringProperty(DEFAULT_LOCK_IDLETIME_IN_MINUTES);
private final BooleanProperty lockAfterTime = new SimpleBooleanProperty(DEFAULT_LOCK_AFTER_TIME);
private final StringProperty lockTimeInMinutes = new SimpleStringProperty(DEFAULT_LOCK_TIME_IN_MINUTES);
private final StringBinding mountName;
public VaultSettings(String id) {
@@ -66,7 +70,7 @@ public class VaultSettings {
}
Observable[] observables() {
return new Observable[]{path, displayName, winDriveLetter, unlockAfterStartup, revealAfterMount, useCustomMountPath, customMountPath, usesReadOnlyMode, mountFlags, filenameLengthLimit, actionAfterUnlock, lockOnSleep, lockAfterIdleTime, lockIdleTimeInMinutes};
return new Observable[]{path, displayName, winDriveLetter, unlockAfterStartup, revealAfterMount, useCustomMountPath, customMountPath, usesReadOnlyMode, mountFlags, filenameLengthLimit, actionAfterUnlock, lockOnSleep, lockAfterIdleTime, lockIdleTimeInMinutes, lockAfterTime, lockTimeInMinutes};
}
public static VaultSettings withRandomId() {
@@ -179,6 +183,14 @@ public class VaultSettings {
return lockIdleTimeInMinutes;
}
public BooleanProperty lockAfterTime() {
return lockAfterTime;
}
public StringProperty lockTimeInMinutes() {
return lockTimeInMinutes;
}
/* Hashcode/Equals */
@Override
@@ -34,6 +34,8 @@ class VaultSettingsJsonAdapter {
out.name("lockOnSleep").value(value.lockOnSleep().get());
out.name("lockAfterIdleTime").value(value.lockAfterIdleTime().get());
out.name("lockIdleTimeInMinutes").value(value.lockIdleTimeInMinutes().get());
out.name("lockAfterTime").value(value.lockAfterTime().get());
out.name("lockTimeInMinutes").value(value.lockTimeInMinutes().get());
out.endObject();
}
@@ -54,6 +56,8 @@ class VaultSettingsJsonAdapter {
boolean lockOnSleep = VaultSettings.DEFAULT_LOCK_ON_SLEEP;
boolean lockAfterIdleTime = VaultSettings.DEFAULT_LOCK_AFTER_IDLETIME;
String lockIdleTimeInMinutes = VaultSettings.DEFAULT_LOCK_IDLETIME_IN_MINUTES;
boolean lockAfterTime = VaultSettings.DEFAULT_LOCK_AFTER_TIME;
String lockTimeInMinutes = VaultSettings.DEFAULT_LOCK_TIME_IN_MINUTES;
in.beginObject();
while (in.hasNext()) {
@@ -75,6 +79,8 @@ class VaultSettingsJsonAdapter {
case "lockOnSleep" -> lockOnSleep = in.nextBoolean();
case "lockAfterIdleTime" -> lockAfterIdleTime = in.nextBoolean();
case "lockIdleTimeInMinutes" -> lockIdleTimeInMinutes = in.nextString();
case "lockAfterTime" -> lockAfterTime = in.nextBoolean();
case "lockTimeInMinutes" -> lockTimeInMinutes = in.nextString();
default -> {
LOG.warn("Unsupported vault setting found in JSON: " + name);
in.skipValue();
@@ -102,6 +108,8 @@ class VaultSettingsJsonAdapter {
vaultSettings.lockOnSleep().set(lockOnSleep);
vaultSettings.lockAfterIdleTime().set(lockAfterIdleTime);
vaultSettings.lockIdleTimeInMinutes().set(lockIdleTimeInMinutes);
vaultSettings.lockAfterTime().set(lockAfterTime);
vaultSettings.lockTimeInMinutes().set(lockTimeInMinutes);
return vaultSettings;
}