mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-17 02:01:27 +00:00
Remove legacy concepts:
* in vaultSettings, displayName does not listen on path * the caller/creater of vault settings must set the name explicitly * add localizable default vault name
This commit is contained in:
@@ -19,7 +19,6 @@ import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.fxmisc.easybind.EasyBind;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
@@ -60,31 +59,12 @@ public class VaultSettings {
|
||||
public VaultSettings(String id) {
|
||||
this.id = Objects.requireNonNull(id);
|
||||
this.mountName = Bindings.createStringBinding(this::normalizeDisplayName, displayName);
|
||||
|
||||
EasyBind.subscribe(path, this::deriveDisplayNameFromPathOrUseDefault);
|
||||
}
|
||||
|
||||
Observable[] observables() {
|
||||
return new Observable[]{path, displayName, winDriveLetter, unlockAfterStartup, revealAfterMount, useCustomMountPath, customMountPath, usesReadOnlyMode, mountFlags, filenameLengthLimit, actionAfterUnlock};
|
||||
}
|
||||
|
||||
private void deriveDisplayNameFromPathOrUseDefault(Path newPath) {
|
||||
final boolean mountNameSet = !StringUtils.isBlank(displayName.get());
|
||||
final boolean dirnameExists = (newPath != null) && (newPath.getFileName() != null);
|
||||
final String defaultPattern = DEFAULT_MOUNT_NAME + " " + id;
|
||||
|
||||
if (!mountNameSet && dirnameExists) {
|
||||
displayName.set(newPath.getFileName().toString());
|
||||
} else if (!mountNameSet && !dirnameExists) {
|
||||
displayName.set(defaultPattern);
|
||||
} else if (mountNameSet && dirnameExists) {
|
||||
if (displayName.get().equals(defaultPattern)) {
|
||||
//this is okay, since this function is only executed if the path changes (aka, the vault is created or added)
|
||||
displayName.set(newPath.getFileName().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static VaultSettings withRandomId() {
|
||||
return new VaultSettings(generateId());
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class VaultSettingsJsonAdapter {
|
||||
public VaultSettings read(JsonReader in) throws IOException {
|
||||
String id = null;
|
||||
String path = null;
|
||||
String mountName = null;
|
||||
String displayName = null;
|
||||
String customMountPath = null;
|
||||
String winDriveLetter = null;
|
||||
boolean unlockAfterStartup = VaultSettings.DEFAULT_UNLOCK_AFTER_STARTUP;
|
||||
@@ -54,7 +54,7 @@ class VaultSettingsJsonAdapter {
|
||||
switch (name) {
|
||||
case "id" -> id = in.nextString();
|
||||
case "path" -> path = in.nextString();
|
||||
case "mountName" -> mountName = in.nextString();
|
||||
case "mountName" -> displayName = in.nextString(); //YES, this is correct (legacy reasons)
|
||||
case "winDriveLetter" -> winDriveLetter = in.nextString();
|
||||
case "unlockAfterStartup" -> unlockAfterStartup = in.nextBoolean();
|
||||
case "revealAfterMount" -> revealAfterMount = in.nextBoolean();
|
||||
@@ -73,7 +73,7 @@ class VaultSettingsJsonAdapter {
|
||||
in.endObject();
|
||||
|
||||
VaultSettings vaultSettings = (id == null) ? VaultSettings.withRandomId() : new VaultSettings(id);
|
||||
vaultSettings.displayName().set(mountName);
|
||||
vaultSettings.displayName().set(displayName);
|
||||
vaultSettings.path().set(Paths.get(path));
|
||||
vaultSettings.winDriveLetter().set(winDriveLetter);
|
||||
vaultSettings.unlockAfterStartup().set(unlockAfterStartup);
|
||||
|
||||
@@ -20,11 +20,11 @@ import org.slf4j.LoggerFactory;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.cryptomator.common.Constants.MASTERKEY_FILENAME;
|
||||
@@ -35,11 +35,13 @@ public class VaultListManager {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(VaultListManager.class);
|
||||
|
||||
private final VaultComponent.Builder vaultComponentBuilder;
|
||||
private final ResourceBundle resourceBundle;
|
||||
private final ObservableList<Vault> vaultList;
|
||||
|
||||
@Inject
|
||||
public VaultListManager(VaultComponent.Builder vaultComponentBuilder, Settings settings) {
|
||||
public VaultListManager(VaultComponent.Builder vaultComponentBuilder, ResourceBundle resourceBundle, Settings settings) {
|
||||
this.vaultComponentBuilder = vaultComponentBuilder;
|
||||
this.resourceBundle = resourceBundle;
|
||||
this.vaultList = FXCollections.observableArrayList(Vault::observables);
|
||||
|
||||
addAll(settings.getDirectories());
|
||||
@@ -59,14 +61,23 @@ public class VaultListManager {
|
||||
if (alreadyExistingVault.isPresent()) {
|
||||
return alreadyExistingVault.get();
|
||||
} else {
|
||||
VaultSettings vaultSettings = VaultSettings.withRandomId();
|
||||
vaultSettings.path().set(normalizedPathToVault);
|
||||
Vault newVault = create(vaultSettings);
|
||||
Vault newVault = create(newVaultSettings(normalizedPathToVault));
|
||||
vaultList.add(newVault);
|
||||
return newVault;
|
||||
}
|
||||
}
|
||||
|
||||
private VaultSettings newVaultSettings(Path path) {
|
||||
VaultSettings vaultSettings = VaultSettings.withRandomId();
|
||||
vaultSettings.path().set(path);
|
||||
if (path.getFileName() != null) {
|
||||
vaultSettings.displayName().set(path.getFileName().toString());
|
||||
} else {
|
||||
vaultSettings.displayName().set(resourceBundle.getString("defaults.vault.vaultName"));
|
||||
}
|
||||
return vaultSettings;
|
||||
}
|
||||
|
||||
private void addAll(Collection<VaultSettings> vaultSettings) {
|
||||
Collection<Vault> vaults = vaultSettings.stream().map(this::create).collect(Collectors.toList());
|
||||
vaultList.addAll(vaults);
|
||||
@@ -92,7 +103,7 @@ public class VaultListManager {
|
||||
}
|
||||
return compBuilder.build().vault();
|
||||
}
|
||||
|
||||
|
||||
public static VaultState redetermineVaultState(Vault vault) {
|
||||
VaultState previousState = vault.getState();
|
||||
return switch (previousState) {
|
||||
|
||||
@@ -17,6 +17,9 @@ generic.button.print=Print
|
||||
generic.error.title=An unexpected error occured
|
||||
generic.error.instruction=This should not have happened. Please report the error text below and include a description of what steps did lead to this error.
|
||||
|
||||
# Defaults
|
||||
defaults.vault.vaultName=Vault
|
||||
|
||||
# Tray Menu
|
||||
traymenu.showMainWindow=Show
|
||||
traymenu.showPreferencesWindow=Preferences
|
||||
|
||||
Reference in New Issue
Block a user