Further improvements:

* adding Log messages
* change lock workflow to type of Task<Void>
* set vault state based solely on task state
* replaced dialogue stubs with real text
This commit is contained in:
Armin Schrenk
2020-11-19 16:31:16 +01:00
parent 432a9a27f1
commit 4db57cc0dc
8 changed files with 51 additions and 20 deletions

View File

@@ -113,7 +113,7 @@ public class FxApplication extends Application {
public void startLockWorkflow(Vault vault, Optional<Stage> owner) {
Platform.runLater(() -> {
lockWindowBuilderProvider.get().vault(vault).owner(owner).build().startLockWorkflow();
LOG.debug("Locking vault {}", vault.getDisplayName());
LOG.debug("Start lock workflow for {}", vault.getDisplayName());
});
}

View File

@@ -19,7 +19,7 @@ public interface LockComponent {
LockWorkflow lockWorkflow();
default Future<Boolean> startLockWorkflow() {
default Future<Void> startLockWorkflow() {
LockWorkflow workflow = lockWorkflow();
defaultExecutorService().submit(workflow);
return workflow;

View File

@@ -45,4 +45,10 @@ public class LockForcedController implements FxController {
}
}
// ----- Getter & Setter -----
public String getVaultName() {
return vault.getDisplayName();
}
}

View File

@@ -17,7 +17,15 @@ import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.Window;
public class LockWorkflow extends Task<Boolean> {
/**
* The sequence of actions performed and checked during lock of a vault.
* <p>
* This class implements the Task interface, sucht that it can run in the background with some possible forground operations/requests to the ui, without blocking the main app.
* If the task succeeded, the vault was successfully locked.
* If the task is canceled, the lock was canceled.
* If the task failed, the lock failed due to an exception.
*/
public class LockWorkflow extends Task<Void> {
private static final Logger LOG = LoggerFactory.getLogger(LockWorkflow.class);
@@ -37,15 +45,11 @@ public class LockWorkflow extends Task<Boolean> {
}
@Override
protected Boolean call() throws Volume.VolumeException, InterruptedException {
// change vault state to processing -- done by overriding scheduled method of Task
if (attemptLock() || attemptForcedLock()) {
handleSuccess();
return true;
} else {
//canceled -- for error the overriden failed() method is responsible
return false;
protected Void call() throws Volume.VolumeException, InterruptedException {
if (!attemptLock()) {
attemptForcedLock();
}
return null;
}
private boolean attemptLock() {
@@ -53,7 +57,7 @@ public class LockWorkflow extends Task<Boolean> {
vault.lock(false);
return true;
} catch (Volume.VolumeException e) {
e.printStackTrace();
LOG.debug("Regular lock of {} failed.", vault.getDisplayName(), e);
return false;
}
}
@@ -77,17 +81,13 @@ public class LockWorkflow extends Task<Boolean> {
vault.lock(true);
return true;
case CANCEL:
// if lock was performed over main window, show it again
this.cancel(false);
return false;
default:
return false;
}
}
private void handleSuccess() {
LOG.info("Lock of {} succeeded.", vault.getDisplayName());
}
@Override
protected void scheduled() {
vault.setState(VaultState.PROCESSING);
@@ -95,17 +95,19 @@ public class LockWorkflow extends Task<Boolean> {
@Override
protected void succeeded() {
LOG.info("Lock of {} succeeded.", vault.getDisplayName());
vault.setState(VaultState.LOCKED);
}
@Override
protected void failed() {
LOG.info("Failed to lock {}.", vault.getDisplayName());
LOG.warn("Failed to lock {}.", vault.getDisplayName());
vault.setState(VaultState.UNLOCKED);
}
@Override
protected void cancelled() {
LOG.debug("Lock of {} canceled.", vault.getDisplayName());
vault.setState(VaultState.UNLOCKED);
}

View File

@@ -105,6 +105,11 @@
-fx-font-size: 1.5em;
}
.label-medium {
-fx-font-family: 'Open Sans SemiBold';
-fx-font-size: 1.2em;
}
.label-small {
-fx-font-size: 0.8em;
}

View File

@@ -105,6 +105,11 @@
-fx-font-size: 1.5em;
}
.label-medium {
-fx-font-family: 'Open Sans SemiBold';
-fx-font-size: 1.2em;
}
.label-small {
-fx-font-size: 0.8em;
}

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import org.cryptomator.ui.controls.FontAwesome5IconView?>
<?import org.cryptomator.ui.controls.FormattedLabel?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonBar?>
@@ -25,14 +26,18 @@
<Circle styleClass="glyph-icon-orange" radius="24"/>
<FontAwesome5IconView styleClass="glyph-icon-white" glyph="EXCLAMATION" glyphSize="24"/>
</StackPane>
<Label text="Yadda yadda" wrapText="true" textAlignment="LEFT" HBox.hgrow="ALWAYS"/>
<VBox spacing="6">
<Label styleClass="label-medium" text="%lock.forced.heading"/>
<FormattedLabel format="%lock.forced.message" arg1="${controller.vaultName}" wrapText="true"/>
</VBox>
</HBox>
<VBox alignment="BOTTOM_CENTER" VBox.vgrow="ALWAYS">
<ButtonBar buttonMinWidth="120" buttonOrder="+CI">
<buttons>
<Button text="%generic.button.cancel" ButtonBar.buttonData="CANCEL_CLOSE" defaultButton="true" cancelButton="true" onAction="#cancel"/>
<Button text="Use the FORCE, Luke!" ButtonBar.buttonData="FINISH" onAction="#confirmForcedLock"/>
<!-- TODO: third button with retry? -->
<Button text="%lock.forced.confirmBtn" ButtonBar.buttonData="FINISH" onAction="#confirmForcedLock"/>
</buttons>
</ButtonBar>
</VBox>

View File

@@ -108,6 +108,14 @@ unlock.error.heading=Unable to unlock vault
unlock.error.invalidMountPoint.notExisting=Mount point "%s" is not a directory, not empty or does not exist.
unlock.error.invalidMountPoint.existing=Mount point "%s" already exists or parent folder is missing.
# Lock
## Force
lock.forced.heading=Forcefully Lock Vault?
lock.forced.message=The vault "%s" cannot be locked due to open files or pending operations. Close those files and wait until I/O operations are finished and try again.\n Alternatively, you can enforce locking risking to loose unsaved data.
lock.forced.confirmBtn=Force Locking
## Failure
lock.fail.message=TODO
# Migration
migration.title=Upgrade Vault
## Start