save donation key to settings

This commit is contained in:
Sebastian Stenzel
2019-11-19 21:20:00 +01:00
parent 28d58922e3
commit c6fc1d93a0
10 changed files with 97 additions and 52 deletions

View File

@@ -69,6 +69,7 @@ public class Settings {
preferredVolumeImpl.addListener(this::somethingChanged);
theme.addListener(this::somethingChanged);
userInterfaceOrientation.addListener(this::somethingChanged);
licenseKey.addListener(this::somethingChanged);
}
void setSaveCmd(Consumer<Settings> saveCmd) {

View File

@@ -38,6 +38,7 @@ public class SettingsJsonAdapter extends TypeAdapter<Settings> {
out.name("preferredVolumeImpl").value(value.preferredVolumeImpl().get().name());
out.name("theme").value(value.theme().get().name());
out.name("uiOrientation").value(value.userInterfaceOrientation().get().name());
out.name("licenseKey").value(value.licenseKey().get());
out.endObject();
}
@@ -90,6 +91,9 @@ public class SettingsJsonAdapter extends TypeAdapter<Settings> {
case "uiOrientation":
settings.userInterfaceOrientation().set(parseUiOrientation(in.nextString()));
break;
case "licenseKey":
settings.licenseKey().set(in.nextString());
break;
default:
LOG.warn("Unsupported vault setting found in JSON: " + name);
in.skipValue();

View File

@@ -15,9 +15,11 @@ public enum FontAwesome5Icon {
EYE_SLASH("\uF070"), //
FILE_IMPORT("\uF56F"), //
FOLDER_OPEN("\uF07C"), //
HAND_HOLDING_HEART("\uF4BE"), //
HEART("\uF004"), //
HDD("\uF0A0"), //
KEY("\uF084"), //
LINK("\uF0C1"), //
LOCK_ALT("\uF30D"), //
LOCK_OPEN_ALT("\uF3C2"), //
PLUS("\uF067"), //
@@ -26,7 +28,7 @@ public enum FontAwesome5Icon {
SPINNER("\uF110"), //
SYNC("\uF021"), //
TIMES("\uF00D"), //
USER_CHECK("\uf4fc"), //
USER_CROWN("\uF6A4"), //
WRENCH("\uF0AD"), //
;

View File

@@ -5,8 +5,10 @@
*******************************************************************************/
package org.cryptomator.ui.fxapp;
import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import javafx.application.Application;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.image.Image;
@@ -44,6 +46,9 @@ abstract class FxApplicationModule {
return Optional.empty();
}
}
@Binds
abstract Application bindApplication(FxApplication application);
@Provides
static MainWindowComponent provideMainWindowComponent(MainWindowComponent.Builder builder) {

View File

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

View File

@@ -72,7 +72,7 @@ abstract class PreferencesModule {
@Binds
@IntoMap
@FxControllerKey(RegistrationPreferencesController.class)
abstract FxController bindRegistrationPreferencesController(RegistrationPreferencesController controller);
@FxControllerKey(LicenseKeyPreferencesController.class)
abstract FxController bindLicenseKeyPreferencesController(LicenseKeyPreferencesController controller);
}

View File

@@ -7,7 +7,9 @@
xmlns:fx="http://javafx.com/fxml"
fx:id="tabPane"
fx:controller="org.cryptomator.ui.preferences.PreferencesController"
minWidth="400"
minWidth="-Infinity"
maxWidth="-Infinity"
prefWidth="500"
tabClosingPolicy="UNAVAILABLE"
tabDragPolicy="FIXED">
<tabs>
@@ -35,12 +37,12 @@
<fx:include source="/fxml/preferences_updates.fxml"/>
</content>
</Tab>
<Tab fx:id="registrationTab" text="%preferences.registration">
<Tab fx:id="donationKeyTab" text="%preferences.donationKey">
<graphic>
<FontAwesome5IconView glyph="USER_CHECK"/>
<FontAwesome5IconView glyph="HEART"/>
</graphic>
<content>
<fx:include source="/fxml/preferences_registration.fxml"/>
<fx:include source="/fxml/preferences_donationkey.fxml"/>
</content>
</Tab>
</tabs>

View File

@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Hyperlink?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.Circle?>
<?import org.cryptomator.ui.controls.FontAwesome5IconView?>
<?import org.cryptomator.ui.controls.FormattedLabel?>
<VBox xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="org.cryptomator.ui.preferences.LicenseKeyPreferencesController"
spacing="18">
<padding>
<Insets topRightBottomLeft="12"/>
</padding>
<children>
<StackPane VBox.vgrow="NEVER" prefHeight="60">
<HBox spacing="12" alignment="CENTER_LEFT" visible="${controller.validLicense}">
<StackPane alignment="CENTER" HBox.hgrow="NEVER">
<Circle styleClass="glyph-icon-primary" radius="24"/>
<FontAwesome5IconView styleClass="glyph-icon-white" glyph="USER_CROWN" glyphSize="24"/>
</StackPane>
<FormattedLabel format="%preferences.donationKey.registeredFor" arg1="${controller.licenseSubject}" wrapText="true"/>
</HBox>
<HBox spacing="12" alignment="CENTER_LEFT" visible="${!controller.validLicense}">
<StackPane alignment="CENTER" HBox.hgrow="NEVER">
<Circle styleClass="glyph-icon-primary" radius="24"/>
<FontAwesome5IconView styleClass="glyph-icon-white" glyph="HAND_HOLDING_HEART" glyphSize="24"/>
</StackPane>
<VBox HBox.hgrow="ALWAYS" spacing="6">
<Label text="%preferences.donationKey.noDonationKey" wrapText="true" VBox.vgrow="ALWAYS"/>
<Hyperlink text="%preferences.donationKey.getDonationKey" onAction="#getDonationKey" contentDisplay="LEFT">
<graphic>
<FontAwesome5IconView glyph="LINK"/>
</graphic>
</Hyperlink>
</VBox>
</HBox>
</StackPane>
<TextArea fx:id="donationKeyField" wrapText="true" VBox.vgrow="ALWAYS" prefRowCount="6"/>
</children>
</VBox>

View File

@@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.Circle?>
<?import org.cryptomator.ui.controls.FontAwesome5IconView?>
<?import org.cryptomator.ui.controls.FormattedLabel?>
<?import javafx.scene.control.TextArea?>
<VBox xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="org.cryptomator.ui.preferences.RegistrationPreferencesController"
spacing="18">
<padding>
<Insets topRightBottomLeft="12"/>
</padding>
<children>
<HBox spacing="12" alignment="CENTER_LEFT" VBox.vgrow="NEVER" visible="${controller.registered}">
<StackPane alignment="CENTER" HBox.hgrow="NEVER">
<Circle styleClass="glyph-icon-primary" radius="24"/>
<FontAwesome5IconView styleClass="glyph-icon-white" glyph="HEART" glyphSize="24"/>
</StackPane>
<FormattedLabel format="%preferences.registration.registeredFor" arg1="${controller.licenseSubject}" textAlignment="CENTER" wrapText="true"/>
</HBox>
<TextArea fx:id="registrationKeyField" wrapText="true" VBox.vgrow="ALWAYS"/>
</children>
</VBox>

View File

@@ -123,9 +123,11 @@ preferences.updates.currentVersion=Current Version: %s
preferences.updates.autoUpdateCheck=Check for updates automatically
preferences.updates.checkNowBtn=Check Now
preferences.updates.updateAvailable=Update to version %s available.
## Registration
preferences.registration=Registration
preferences.registration.registeredFor=Registered for %s
## Donation Key
preferences.donationKey=Donation
preferences.donationKey.registeredFor=Registered for %s
preferences.donationKey.noDonationKey=No valid donation key found. It's like a license key but for awesome people using free software. ;-)
preferences.donationKey.getDonationKey=Get a donation key
# Main Window
main.closeBtn.tooltip=Close