瀏覽代碼

Merge pull request #3060 from cryptomator/feature/error-dialog-lookup-permission

Ask before looking up error code
mindmonk 1 年之前
父節點
當前提交
296ae20cc2

+ 29 - 9
src/main/java/org/cryptomator/ui/error/ErrorController.java

@@ -65,11 +65,13 @@ public class ErrorController implements FxController {
 	private final Scene previousScene;
 	private final Stage window;
 	private final Environment environment;
+	private final ExecutorService executorService;
 
 	private final BooleanProperty copiedDetails = new SimpleBooleanProperty();
 	private final ObjectProperty<ErrorDiscussion> matchingErrorDiscussion = new SimpleObjectProperty<>();
 	private final BooleanExpression errorSolutionFound = matchingErrorDiscussion.isNotNull();
 	private final BooleanProperty isLoadingHttpResponse = new SimpleBooleanProperty();
+	private final BooleanProperty askedForLookupDatabasePermission = new SimpleBooleanProperty();
 
 	@Inject
 	ErrorController(Application application, @Named("stackTrace") String stackTrace, ErrorCode errorCode, @Nullable Scene previousScene, Stage window, Environment environment, ExecutorService executorService) {
@@ -79,15 +81,7 @@ public class ErrorController implements FxController {
 		this.previousScene = previousScene;
 		this.window = window;
 		this.environment = environment;
-
-		isLoadingHttpResponse.set(true);
-		HttpClient httpClient = HttpClient.newBuilder().version(HttpClient.Version.HTTP_1_1).build();
-		HttpRequest httpRequest = HttpRequest.newBuilder()//
-				.uri(URI.create(ERROR_CODES_URL))//
-				.build();
-		httpClient.sendAsync(httpRequest, HttpResponse.BodyHandlers.ofInputStream())//
-				.thenAcceptAsync(this::loadHttpResponse, executorService)//
-				.whenCompleteAsync((r, e) -> isLoadingHttpResponse.set(false), Platform::runLater);
+		this.executorService = executorService;
 	}
 
 	@FXML
@@ -140,6 +134,24 @@ public class ErrorController implements FxController {
 		CompletableFuture.delayedExecutor(2, TimeUnit.SECONDS, Platform::runLater).execute(() -> copiedDetails.set(false));
 	}
 
+	@FXML
+	public void dismiss() {
+		askedForLookupDatabasePermission.set(true);
+	}
+
+	@FXML
+	public void lookUpSolution() {
+		isLoadingHttpResponse.set(true);
+		askedForLookupDatabasePermission.set(true);
+		HttpClient httpClient = HttpClient.newBuilder().version(HttpClient.Version.HTTP_1_1).build();
+		HttpRequest httpRequest = HttpRequest.newBuilder()//
+				.uri(URI.create(ERROR_CODES_URL))//
+				.build();
+		httpClient.sendAsync(httpRequest, HttpResponse.BodyHandlers.ofInputStream())//
+				.thenAcceptAsync(this::loadHttpResponse, executorService)//
+				.whenCompleteAsync((r, e) -> isLoadingHttpResponse.set(false), Platform::runLater);
+	}
+
 	private void loadHttpResponse(HttpResponse<InputStream> response) {
 		if (response.statusCode() != 200) {
 			LOG.error("Status code {} when trying to load {} ", response.statusCode(), response.uri());
@@ -293,4 +305,12 @@ public class ErrorController implements FxController {
 		return isLoadingHttpResponse.get();
 	}
 
+	public BooleanProperty askedForLookupDatabasePermissionProperty() {
+		return askedForLookupDatabasePermission;
+	}
+
+	public boolean getAskedForLookupDatabasePermission() {
+		return askedForLookupDatabasePermission.get();
+	}
+
 }

+ 31 - 19
src/main/resources/fxml/error.fxml

@@ -32,25 +32,37 @@
 			</StackPane>
 			<VBox spacing="6" HBox.hgrow="ALWAYS">
 				<FormattedLabel styleClass="label-extra-large" format="%error.message" arg1="${controller.errorCode}"/>
-				<FontAwesome5Spinner glyphSize="24" visible="${controller.isLoadingHttpResponse}" managed="${controller.isLoadingHttpResponse}"/>
-				<VBox visible="${!controller.isLoadingHttpResponse}" managed="${!controller.isLoadingHttpResponse}">
-					<Label text="%error.existingSolutionDescription" wrapText="true" visible="${controller.errorSolutionFound}" managed="${controller.errorSolutionFound}"/>
-					<Hyperlink styleClass="hyperlink-underline" text="%error.hyperlink.solution" onAction="#showSolution" contentDisplay="LEFT" visible="${controller.errorSolutionFound}" managed="${controller.errorSolutionFound}">
-						<graphic>
-							<FontAwesome5IconView glyph="LINK" glyphSize="12"/>
-						</graphic>
-					</Hyperlink>
-					<Label text="%error.description" wrapText="true" visible="${!controller.errorSolutionFound}" managed="${!controller.errorSolutionFound}"/>
-					<Hyperlink styleClass="hyperlink-underline" text="%error.hyperlink.lookup" onAction="#searchError" contentDisplay="LEFT" visible="${!controller.errorSolutionFound}" managed="${!controller.errorSolutionFound}">
-						<graphic>
-							<FontAwesome5IconView glyph="LINK" glyphSize="12"/>
-						</graphic>
-					</Hyperlink>
-					<Hyperlink styleClass="hyperlink-underline" text="%error.hyperlink.report" onAction="#reportError" contentDisplay="LEFT" visible="${!controller.errorSolutionFound}" managed="${!controller.errorSolutionFound}">
-						<graphic>
-							<FontAwesome5IconView glyph="LINK" glyphSize="12"/>
-						</graphic>
-					</Hyperlink>
+				<VBox visible="${!controller.askedForLookupDatabasePermission}" managed="${!controller.askedForLookupDatabasePermission}">
+					<Label text="%error.lookupPermissionMessage" wrapText="true"/>
+					<Region VBox.vgrow="ALWAYS" minHeight="18"/>
+					<ButtonBar buttonMinWidth="120" buttonOrder="+NY">
+						<buttons>
+							<Button text="%error.dismiss" ButtonBar.buttonData="NO" onAction="#dismiss"/>
+							<Button text="%error.lookUpSolution" ButtonBar.buttonData="YES" defaultButton="true" onAction="#lookUpSolution"/>
+						</buttons>
+					</ButtonBar>
+				</VBox>
+				<VBox visible="${controller.askedForLookupDatabasePermission}" managed="${controller.askedForLookupDatabasePermission}">
+					<FontAwesome5Spinner glyphSize="24" visible="${controller.isLoadingHttpResponse}" managed="${controller.isLoadingHttpResponse}"/>
+					<VBox visible="${!controller.isLoadingHttpResponse}" managed="${!controller.isLoadingHttpResponse}">
+						<Label text="%error.existingSolutionDescription" wrapText="true" visible="${controller.errorSolutionFound}" managed="${controller.errorSolutionFound}"/>
+						<Hyperlink styleClass="hyperlink-underline" text="%error.hyperlink.solution" onAction="#showSolution" contentDisplay="LEFT" visible="${controller.errorSolutionFound}" managed="${controller.errorSolutionFound}">
+							<graphic>
+								<FontAwesome5IconView glyph="LINK" glyphSize="12"/>
+							</graphic>
+						</Hyperlink>
+						<Label text="%error.description" wrapText="true" visible="${!controller.errorSolutionFound}" managed="${!controller.errorSolutionFound}"/>
+						<Hyperlink styleClass="hyperlink-underline" text="%error.hyperlink.lookup" onAction="#searchError" contentDisplay="LEFT" visible="${!controller.errorSolutionFound}" managed="${!controller.errorSolutionFound}">
+							<graphic>
+								<FontAwesome5IconView glyph="LINK" glyphSize="12"/>
+							</graphic>
+						</Hyperlink>
+						<Hyperlink styleClass="hyperlink-underline" text="%error.hyperlink.report" onAction="#reportError" contentDisplay="LEFT" visible="${!controller.errorSolutionFound}" managed="${!controller.errorSolutionFound}">
+							<graphic>
+								<FontAwesome5IconView glyph="LINK" glyphSize="12"/>
+							</graphic>
+						</Hyperlink>
+					</VBox>
 				</VBox>
 			</VBox>
 		</HBox>

+ 3 - 1
src/main/resources/i18n/strings.properties

@@ -23,7 +23,9 @@ error.hyperlink.report=Report this error
 error.technicalDetails=Details:
 error.existingSolutionDescription=Cryptomator didn't expect this to happen. But we found an existing solution for this error. Please take a look at the following link.
 error.hyperlink.solution=Look up the solution
-
+error.lookupPermissionMessage=Cryptomator can look up a solution for this problem online. This will send a request to our problem database from your IP address.
+error.dismiss=Dismiss
+error.lookUpSolution=Look up Solution
 
 # Defaults
 defaults.vault.vaultName=Vault