From cf38a10284467c69af871ca1e832a598c6ae92c0 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Thu, 7 Jul 2022 12:01:34 +0200 Subject: [PATCH] Change text from registration to "naming" and prefill device name --- .../hub/RegisterDeviceController.java | 18 +++++++++++++++++- src/main/resources/i18n/strings.properties | 12 ++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java b/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java index a8cbe4148..7fdbf4b95 100644 --- a/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java +++ b/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java @@ -25,6 +25,9 @@ import javafx.scene.Scene; import javafx.scene.control.TextField; import javafx.stage.Stage; import javafx.stage.WindowEvent; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; @@ -33,6 +36,7 @@ import java.nio.charset.StandardCharsets; import java.util.Objects; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.atomic.AtomicReference; @KeyLoadingScoped @@ -69,6 +73,18 @@ public class RegisterDeviceController implements FxController { this.httpClient = HttpClient.newBuilder().executor(executor).build(); } + public void initialize() { + deviceNameField.setText(System.getProperty("user.name") + "-" + determineHostname()); + } + + private String determineHostname() { + try { + return new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("hostname").getInputStream())).readLine(); + } catch (IOException e) { + return String.valueOf(ThreadLocalRandom.current().nextInt()); + } + } + @FXML public void register() { var keyUri = URI.create(hubConfig.devicesResourceUrl + deviceId); @@ -84,7 +100,7 @@ public class RegisterDeviceController implements FxController { .build(); httpClient.sendAsync(request, HttpResponse.BodyHandlers.discarding()) // .handleAsync((response, throwable) -> { - if( response != null) { + if (response != null) { this.registrationSucceeded(response); } else { this.registrationFailed(throwable); diff --git a/src/main/resources/i18n/strings.properties b/src/main/resources/i18n/strings.properties index a908b8370..a7f59b63d 100644 --- a/src/main/resources/i18n/strings.properties +++ b/src/main/resources/i18n/strings.properties @@ -133,16 +133,16 @@ hub.auth.loginLink=Not redirected? Click here to open it. hub.receive.message=Processing response… hub.receive.description=Cryptomator is receiving and processing the response from Hub. Please wait. ### Register Device -hub.register.message=Register device? -hub.register.description=This seems to be the first access from this device to Cryptomator Hub. In order to unlock any vault, you need to choose a name and register it. +hub.register.message=Device name required +hub.register.description=This seems to be the first Hub access from this device. In order to identify it for access authorization, you need to name this device. hub.register.nameLabel=Device Name -hub.register.registerBtn=Register +hub.register.registerBtn=Confirm ### Registration Success -hub.registerSuccess.message=Device registered +hub.registerSuccess.message=Device named hub.registerSuccess.description=To access the vault, your device needs to be authorized by the vault owner. ### Registration Failed -hub.registerFailed.message=Device registration failed -hub.registerFailed.description=An error was thrown in the registration process. For more details, look into the application log. +hub.registerFailed.message=Device naming failed +hub.registerFailed.description=An error was thrown in the naming process. For more details, look into the application log. ### Unauthorized hub.unauthorized.message=Access denied hub.unauthorized.description=Your device has not yet been authorized to access this vault. Ask the vault owner to authorize it.