mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-09-05 15:47:32 +00:00
avoid duplicate network drives on windows
This commit is contained in:
@@ -16,6 +16,7 @@ import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.apache.commons.lang3.CharUtils;
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.cryptomator.ui.settings.Localization;
|
||||
import org.cryptomator.ui.settings.Settings;
|
||||
import org.fxmisc.easybind.EasyBind;
|
||||
@@ -43,6 +44,9 @@ public class SettingsController extends AbstractFXMLViewController {
|
||||
|
||||
@FXML
|
||||
private TextField portField;
|
||||
|
||||
@FXML
|
||||
private CheckBox useIpv6Checkbox;
|
||||
|
||||
@FXML
|
||||
private Label versionLabel;
|
||||
@@ -53,10 +57,13 @@ public class SettingsController extends AbstractFXMLViewController {
|
||||
checkForUpdatesCheckbox.setSelected(settings.isCheckForUpdatesEnabled() && !areUpdatesManagedExternally());
|
||||
portField.setText(String.valueOf(settings.getPort()));
|
||||
portField.addEventFilter(KeyEvent.KEY_TYPED, this::filterNumericKeyEvents);
|
||||
useIpv6Checkbox.setDisable(!SystemUtils.IS_OS_WINDOWS);
|
||||
useIpv6Checkbox.setSelected(SystemUtils.IS_OS_WINDOWS && settings.shouldUseIpv6());
|
||||
versionLabel.setText(String.format(localization.getString("settings.version.label"), applicationVersion().orElse("SNAPSHOT")));
|
||||
|
||||
EasyBind.subscribe(portField.textProperty(), this::portDidChange);
|
||||
EasyBind.subscribe(checkForUpdatesCheckbox.selectedProperty(), settings::setCheckForUpdatesEnabled);
|
||||
EasyBind.subscribe(portField.textProperty(), this::portDidChange);
|
||||
EasyBind.subscribe(useIpv6Checkbox.selectedProperty(), settings::setUseIpv6);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.cryptomator.frontend.webdav.mount.WindowsDriveLetters;
|
||||
import org.cryptomator.ui.controls.SecPasswordField;
|
||||
import org.cryptomator.ui.model.Vault;
|
||||
import org.cryptomator.ui.settings.Localization;
|
||||
import org.cryptomator.ui.settings.Settings;
|
||||
import org.fxmisc.easybind.EasyBind;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -58,16 +59,18 @@ public class UnlockController extends AbstractFXMLViewController {
|
||||
private final Localization localization;
|
||||
private final ExecutorService exec;
|
||||
private final Lazy<FrontendFactory> frontendFactory;
|
||||
private final Settings settings;
|
||||
private final WindowsDriveLetters driveLetters;
|
||||
private final ChangeListener<Character> driveLetterChangeListener = this::winDriveLetterDidChange;
|
||||
final ObjectProperty<Vault> vault = new SimpleObjectProperty<>();
|
||||
|
||||
@Inject
|
||||
public UnlockController(Application app, Localization localization, ExecutorService exec, Lazy<FrontendFactory> frontendFactory, WindowsDriveLetters driveLetters) {
|
||||
public UnlockController(Application app, Localization localization, ExecutorService exec, Lazy<FrontendFactory> frontendFactory, Settings settings, WindowsDriveLetters driveLetters) {
|
||||
this.app = app;
|
||||
this.localization = localization;
|
||||
this.exec = exec;
|
||||
this.frontendFactory = frontendFactory;
|
||||
this.settings = settings;
|
||||
this.driveLetters = driveLetters;
|
||||
}
|
||||
|
||||
@@ -279,7 +282,7 @@ public class UnlockController extends AbstractFXMLViewController {
|
||||
|
||||
private void unlock(CharSequence password) {
|
||||
try {
|
||||
vault.get().activateFrontend(frontendFactory.get(), password);
|
||||
vault.get().activateFrontend(frontendFactory.get(), settings, password);
|
||||
vault.get().reveal();
|
||||
} catch (InvalidPassphraseException e) {
|
||||
Platform.runLater(() -> {
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.cryptomator.frontend.Frontend;
|
||||
import org.cryptomator.frontend.Frontend.MountParam;
|
||||
import org.cryptomator.frontend.FrontendCreationFailedException;
|
||||
import org.cryptomator.frontend.FrontendFactory;
|
||||
import org.cryptomator.ui.settings.Settings;
|
||||
import org.cryptomator.ui.util.DeferredClosable;
|
||||
import org.cryptomator.ui.util.DeferredCloser;
|
||||
import org.cryptomator.ui.util.FXThreads;
|
||||
@@ -112,7 +113,7 @@ public class Vault implements CryptoFileSystemDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void activateFrontend(FrontendFactory frontendFactory, CharSequence passphrase) throws FrontendCreationFailedException {
|
||||
public synchronized void activateFrontend(FrontendFactory frontendFactory, Settings settings, CharSequence passphrase) throws FrontendCreationFailedException {
|
||||
boolean success = false;
|
||||
try {
|
||||
FileSystem fs = getNioFileSystem();
|
||||
@@ -123,7 +124,7 @@ public class Vault implements CryptoFileSystemDelegate {
|
||||
String contextPath = StringUtils.prependIfMissing(mountName, "/");
|
||||
Frontend frontend = frontendFactory.create(statsFs, contextPath);
|
||||
filesystemFrontend = closer.closeLater(frontend);
|
||||
frontend.mount(getMountParams());
|
||||
frontend.mount(getMountParams(settings));
|
||||
success = true;
|
||||
} catch (UncheckedIOException | CommandFailedException e) {
|
||||
throw new FrontendCreationFailedException(e);
|
||||
@@ -140,10 +141,12 @@ public class Vault implements CryptoFileSystemDelegate {
|
||||
Platform.runLater(() -> unlocked.set(false));
|
||||
}
|
||||
|
||||
private Map<MountParam, Optional<String>> getMountParams() {
|
||||
private Map<MountParam, Optional<String>> getMountParams(Settings settings) {
|
||||
String hostname = SystemUtils.IS_OS_WINDOWS && settings.shouldUseIpv6() ? "0--1.ipv6-literal.net" : "localhost";
|
||||
return ImmutableMap.of( //
|
||||
MountParam.MOUNT_NAME, Optional.ofNullable(mountName), //
|
||||
MountParam.WIN_DRIVE_LETTER, Optional.ofNullable(CharUtils.toString(winDriveLetter)) //
|
||||
MountParam.WIN_DRIVE_LETTER, Optional.ofNullable(CharUtils.toString(winDriveLetter)), //
|
||||
MountParam.HOSTNAME, Optional.of(hostname) //
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ import javax.inject.Singleton;
|
||||
|
||||
import org.cryptomator.filesystem.crypto.CryptoFileSystemFactory;
|
||||
import org.cryptomator.filesystem.shortening.ShorteningFileSystemFactory;
|
||||
import org.cryptomator.frontend.webdav.mount.WebDavMounter;
|
||||
import org.cryptomator.ui.util.DeferredCloser;
|
||||
|
||||
@Singleton
|
||||
@@ -26,7 +25,7 @@ public class VaultFactory {
|
||||
private final DeferredCloser closer;
|
||||
|
||||
@Inject
|
||||
public VaultFactory(ShorteningFileSystemFactory shorteningFileSystemFactory, CryptoFileSystemFactory cryptoFileSystemFactory, WebDavMounter mounter, DeferredCloser closer) {
|
||||
public VaultFactory(ShorteningFileSystemFactory shorteningFileSystemFactory, CryptoFileSystemFactory cryptoFileSystemFactory, DeferredCloser closer) {
|
||||
this.shorteningFileSystemFactory = shorteningFileSystemFactory;
|
||||
this.cryptoFileSystemFactory = cryptoFileSystemFactory;
|
||||
this.closer = closer;
|
||||
|
||||
@@ -17,13 +17,14 @@ import org.cryptomator.ui.model.Vault;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
|
||||
@JsonPropertyOrder(value = {"directories", "checkForUpdatesEnabled", "port", "numTrayNotifications"})
|
||||
@JsonPropertyOrder(value = {"directories", "checkForUpdatesEnabled", "port", "useIpv6", "numTrayNotifications"})
|
||||
public class Settings implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 7609959894417878744L;
|
||||
public static final int MIN_PORT = 1024;
|
||||
public static final int MAX_PORT = 65535;
|
||||
public static final int DEFAULT_PORT = 0;
|
||||
public static final boolean DEFAULT_USE_IPV6 = false;
|
||||
public static final Integer DEFAULT_NUM_TRAY_NOTIFICATIONS = 3;
|
||||
|
||||
@JsonProperty("directories")
|
||||
@@ -34,6 +35,9 @@ public class Settings implements Serializable {
|
||||
|
||||
@JsonProperty("port")
|
||||
private Integer port;
|
||||
|
||||
@JsonProperty("useIpv6")
|
||||
private Boolean useIpv6;
|
||||
|
||||
@JsonProperty("numTrayNotifications")
|
||||
private Integer numTrayNotifications;
|
||||
@@ -86,6 +90,14 @@ public class Settings implements Serializable {
|
||||
return port == DEFAULT_PORT || port >= MIN_PORT && port <= MAX_PORT;
|
||||
}
|
||||
|
||||
public boolean shouldUseIpv6() {
|
||||
return useIpv6 == null ? DEFAULT_USE_IPV6 : useIpv6;
|
||||
}
|
||||
|
||||
public void setUseIpv6(boolean useIpv6) {
|
||||
this.useIpv6 = useIpv6;
|
||||
}
|
||||
|
||||
public Integer getNumTrayNotifications() {
|
||||
return numTrayNotifications == null ? DEFAULT_NUM_TRAY_NOTIFICATIONS : numTrayNotifications;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,10 @@
|
||||
<!-- Row 1 -->
|
||||
<Label GridPane.rowIndex="1" GridPane.columnIndex="0" text="%settings.port.label" cacheShape="true" cache="true" />
|
||||
<TextField GridPane.rowIndex="1" GridPane.columnIndex="1" fx:id="portField" cacheShape="true" cache="true" promptText="%settings.port.prompt" />
|
||||
|
||||
<!-- Row 2 -->
|
||||
<Label GridPane.rowIndex="2" GridPane.columnIndex="0" text="%settings.useipv6.label" cacheShape="true" cache="true" />
|
||||
<CheckBox GridPane.rowIndex="2" GridPane.columnIndex="1" fx:id="useIpv6Checkbox" cacheShape="true" cache="true" />
|
||||
</children>
|
||||
</GridPane>
|
||||
<Label VBox.vgrow="NEVER" text="%settings.requiresRestartLabel" alignment="CENTER" cacheShape="true" cache="true" />
|
||||
|
||||
@@ -78,6 +78,7 @@ settings.version.label=Version %s
|
||||
settings.checkForUpdates.label=Check for updates
|
||||
settings.port.label=WebDAV Port *
|
||||
settings.port.prompt=0 = Choose automatically
|
||||
settings.useipv6.label=Use IPv6 literal
|
||||
settings.requiresRestartLabel=* Cryptomator needs to restart
|
||||
|
||||
# tray icon
|
||||
|
||||
@@ -78,6 +78,7 @@ settings.version.label=Version %s
|
||||
settings.checkForUpdates.label=Auf Updates prüfen
|
||||
settings.port.label=WebDAV Port *
|
||||
settings.port.prompt=0 = Automatisch wählen
|
||||
settings.useipv6.label=IPv6-Literal nutzen
|
||||
settings.requiresRestartLabel=* benötigt Neustart von Cryptomator
|
||||
|
||||
# tray icon
|
||||
|
||||
Reference in New Issue
Block a user