|
@@ -1,6 +1,7 @@
|
|
|
package org.cryptomator.ui.preferences;
|
|
|
|
|
|
import com.auth0.jwt.interfaces.DecodedJWT;
|
|
|
+import javafx.application.Application;
|
|
|
import javafx.beans.binding.Bindings;
|
|
|
import javafx.beans.binding.BooleanBinding;
|
|
|
import javafx.beans.binding.StringBinding;
|
|
@@ -17,22 +18,26 @@ import javax.inject.Inject;
|
|
|
import java.util.Optional;
|
|
|
|
|
|
@PreferencesScoped
|
|
|
-public class RegistrationPreferencesController implements FxController {
|
|
|
+public class LicenseKeyPreferencesController implements FxController {
|
|
|
+
|
|
|
+ private static final String DONATION_URI = "https://cryptomator.org/#donate";
|
|
|
|
|
|
private final Settings settings;
|
|
|
+ private final Application application;
|
|
|
private final LicenseChecker licenseChecker;
|
|
|
private final ObjectProperty<DecodedJWT> validJwtClaims;
|
|
|
private final StringBinding licenseSubject;
|
|
|
- private final BooleanBinding registeredProperty;
|
|
|
- public TextArea registrationKeyField;
|
|
|
+ private final BooleanBinding validLicenseProperty;
|
|
|
+ public TextArea donationKeyField;
|
|
|
|
|
|
@Inject
|
|
|
- RegistrationPreferencesController(Settings settings, LicenseChecker licenseChecker) {
|
|
|
+ LicenseKeyPreferencesController(Settings settings, Application application, LicenseChecker licenseChecker) {
|
|
|
this.settings = settings;
|
|
|
+ this.application = application;
|
|
|
this.licenseChecker = licenseChecker;
|
|
|
this.validJwtClaims = new SimpleObjectProperty<>();
|
|
|
this.licenseSubject = Bindings.createStringBinding(this::getLicenseSubject, validJwtClaims);
|
|
|
- this.registeredProperty = validJwtClaims.isNotNull();
|
|
|
+ this.validLicenseProperty = validJwtClaims.isNotNull();
|
|
|
|
|
|
Optional<DecodedJWT> claims = licenseChecker.check(settings.licenseKey().get());
|
|
|
validJwtClaims.set(claims.orElse(null));
|
|
@@ -40,7 +45,8 @@ public class RegistrationPreferencesController implements FxController {
|
|
|
|
|
|
@FXML
|
|
|
public void initialize() {
|
|
|
- registrationKeyField.textProperty().addListener(this::registrationKeyChanged);
|
|
|
+ donationKeyField.setText(settings.licenseKey().get());
|
|
|
+ donationKeyField.textProperty().addListener(this::registrationKeyChanged);
|
|
|
}
|
|
|
|
|
|
private void registrationKeyChanged(@SuppressWarnings("unused") ObservableValue<? extends String> observable, @SuppressWarnings("unused") String oldValue, String newValue) {
|
|
@@ -51,12 +57,17 @@ public class RegistrationPreferencesController implements FxController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @FXML
|
|
|
+ public void getDonationKey() {
|
|
|
+ application.getHostServices().showDocument(DONATION_URI);
|
|
|
+ }
|
|
|
+
|
|
|
/* Observable Properties */
|
|
|
-
|
|
|
+
|
|
|
public StringBinding licenseSubjectProperty() {
|
|
|
return licenseSubject;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public String getLicenseSubject() {
|
|
|
DecodedJWT claims = validJwtClaims.get();
|
|
|
if (claims != null) {
|
|
@@ -66,12 +77,11 @@ public class RegistrationPreferencesController implements FxController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public BooleanBinding registeredProperty() {
|
|
|
- return registeredProperty;
|
|
|
+ public BooleanBinding validLicenseProperty() {
|
|
|
+ return validLicenseProperty;
|
|
|
}
|
|
|
|
|
|
- public boolean isRegistered() {
|
|
|
- return registeredProperty.get();
|
|
|
+ public boolean isValidLicense() {
|
|
|
+ return validLicenseProperty.get();
|
|
|
}
|
|
|
-
|
|
|
}
|