浏览代码

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

Armin Schrenk 4 年之前
父节点
当前提交
4db57cc0dc

+ 1 - 1
main/ui/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java

@@ -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());
 		});
 	}
 

+ 1 - 1
main/ui/src/main/java/org/cryptomator/ui/lock/LockComponent.java

@@ -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;

+ 6 - 0
main/ui/src/main/java/org/cryptomator/ui/lock/LockForcedController.java

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

+ 18 - 16
main/ui/src/main/java/org/cryptomator/ui/lock/LockWorkflow.java

@@ -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);
 	}
 

+ 5 - 0
main/ui/src/main/resources/css/dark_theme.css

@@ -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;
 }

+ 5 - 0
main/ui/src/main/resources/css/light_theme.css

@@ -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;
 }

+ 7 - 2
main/ui/src/main/resources/fxml/lock_forced.fxml

@@ -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>

+ 8 - 0
main/ui/src/main/resources/i18n/strings.properties

@@ -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