recheck vault state when focusing window

fixes #1190
fixes #1110
fixes #1139
This commit is contained in:
Sebastian Stenzel
2020-05-11 08:08:15 +02:00
parent 79c3137b90
commit 75f360903c
3 changed files with 39 additions and 16 deletions

View File

@@ -92,8 +92,27 @@ public class VaultListManager {
}
return compBuilder.build().vault();
}
public static VaultState redetermineVaultState(Vault vault) {
VaultState previousState = vault.getState();
return switch (previousState) {
case LOCKED, NEEDS_MIGRATION, MISSING -> {
try {
VaultState determinedState = determineVaultState(vault.getPath());
vault.setState(determinedState);
yield determinedState;
} catch (IOException e) {
LOG.warn("Failed to determine vault state for " + vault.getPath(), e);
vault.setState(VaultState.ERROR);
vault.setLastKnownException(e);
yield VaultState.ERROR;
}
}
case ERROR, UNLOCKED, PROCESSING -> previousState;
};
}
public static VaultState determineVaultState(Path pathToVault) throws IOException {
private static VaultState determineVaultState(Path pathToVault) throws IOException {
if (!CryptoFileSystemProvider.containsVault(pathToVault, MASTERKEY_FILENAME)) {
return VaultState.MISSING;
} else if (Migrators.get().needsMigration(pathToVault, MASTERKEY_FILENAME)) {

View File

@@ -1,12 +1,17 @@
package org.cryptomator.ui.mainwindow;
import javafx.beans.Observable;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.fxml.FXML;
import javafx.scene.input.DragEvent;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import org.apache.commons.lang3.SystemUtils;
import org.cryptomator.common.vaults.Vault;
import org.cryptomator.common.vaults.VaultListManager;
import org.cryptomator.ui.common.FxController;
import org.cryptomator.ui.wrongfilealert.WrongFileAlertComponent;
@@ -28,15 +33,19 @@ public class MainWindowController implements FxController {
private static final Logger LOG = LoggerFactory.getLogger(MainWindowController.class);
private final Stage window;
private final VaultListManager vaultListManager;
private final ReadOnlyObjectProperty<Vault> selectedVault;
private final WrongFileAlertComponent.Builder wrongFileAlert;
private final BooleanProperty draggingOver = new SimpleBooleanProperty();
private final BooleanProperty draggingVaultOver = new SimpleBooleanProperty();
public StackPane root;
@Inject
public MainWindowController(VaultListManager vaultListManager, WrongFileAlertComponent.Builder wrongFileAlert) {
public MainWindowController(@MainWindow Stage window, VaultListManager vaultListManager, ObjectProperty<Vault> selectedVault, WrongFileAlertComponent.Builder wrongFileAlert) {
this.window = window;
this.vaultListManager = vaultListManager;
this.selectedVault = selectedVault;
this.wrongFileAlert = wrongFileAlert;
}
@@ -50,6 +59,14 @@ public class MainWindowController implements FxController {
if (SystemUtils.IS_OS_WINDOWS) {
root.getStyleClass().add("os-windows");
}
window.focusedProperty().addListener(this::mainWindowFocusChanged);
}
private void mainWindowFocusChanged(Observable observable) {
var v = selectedVault.get();
if (v != null) {
VaultListManager.redetermineVaultState(v);
}
}
private void handleDragEvent(DragEvent event) {

View File

@@ -64,20 +64,7 @@ public class VaultListController implements FxController {
if (newValue == null) {
return;
}
VaultState reportedState = newValue.getState();
switch (reportedState) {
case LOCKED, NEEDS_MIGRATION, MISSING -> {
try {
VaultState determinedState = VaultListManager.determineVaultState(newValue.getPath());
newValue.setState(determinedState);
} catch (IOException e) {
LOG.warn("Failed to determine vault state for " + newValue.getPath(), e);
newValue.setState(VaultState.ERROR);
newValue.setLastKnownException(e);
}
}
case ERROR, UNLOCKED, PROCESSING -> {}
}
VaultListManager.redetermineVaultState(newValue);
}
@FXML