mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-09-30 00:56:56 +13:00
Rework licensing [stage]
This commit is contained in:
parent
d38e6ea289
commit
d1c2cc27af
7 changed files with 31 additions and 33 deletions
|
@ -62,11 +62,11 @@ public class AppI18n {
|
|||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static StringBinding readableDuration(String s, ObservableValue<Instant> instant) {
|
||||
return readableDuration(instant, rs -> getValue(getInstance().getLocalised(s), rs));
|
||||
public static StringBinding readableInstant(String s, ObservableValue<Instant> instant) {
|
||||
return readableInstant(instant, rs -> getValue(getInstance().getLocalised(s), rs));
|
||||
}
|
||||
|
||||
public static StringBinding readableDuration(ObservableValue<Instant> instant, UnaryOperator<String> op) {
|
||||
public static StringBinding readableInstant(ObservableValue<Instant> instant, UnaryOperator<String> op) {
|
||||
return Bindings.createStringBinding(
|
||||
() -> {
|
||||
if (instant.getValue() == null) {
|
||||
|
@ -79,7 +79,7 @@ public class AppI18n {
|
|||
instant);
|
||||
}
|
||||
|
||||
public static StringBinding readableDuration(ObservableValue<Instant> instant) {
|
||||
public static StringBinding readableInstant(ObservableValue<Instant> instant) {
|
||||
return Bindings.createStringBinding(
|
||||
() -> {
|
||||
if (instant.getValue() == null) {
|
||||
|
@ -91,6 +91,19 @@ public class AppI18n {
|
|||
instant);
|
||||
}
|
||||
|
||||
public static StringBinding readableDuration(ObservableValue<Duration> duration) {
|
||||
return Bindings.createStringBinding(
|
||||
() -> {
|
||||
if (duration.getValue() == null) {
|
||||
return "null";
|
||||
}
|
||||
|
||||
return getInstance().prettyTime.formatDuration(
|
||||
getInstance().prettyTime.approximateDuration(Instant.now().plus(duration.getValue())));
|
||||
},
|
||||
duration);
|
||||
}
|
||||
|
||||
public static ObservableValue<String> observable(String s, Object... vars) {
|
||||
if (s == null) {
|
||||
return null;
|
||||
|
|
|
@ -10,7 +10,6 @@ import com.dlsc.preferencesfx.model.Setting;
|
|||
import io.xpipe.app.comp.base.ButtonComp;
|
||||
import io.xpipe.app.core.AppI18n;
|
||||
import io.xpipe.app.util.LicenseProvider;
|
||||
import io.xpipe.app.util.LicenseType;
|
||||
import io.xpipe.app.util.LockChangeAlert;
|
||||
import io.xpipe.core.util.XPipeInstallation;
|
||||
import javafx.beans.binding.Bindings;
|
||||
|
@ -57,8 +56,7 @@ public class VaultCategory extends AppPrefsCategory {
|
|||
|
||||
@SneakyThrows
|
||||
public Category create() {
|
||||
var pro = LicenseType.isAtLeast(
|
||||
LicenseProvider.get().getLicenseType(), LicenseType.PROFESSIONAL);
|
||||
var pro = LicenseProvider.get().getFeature("gitVault").isSupported();
|
||||
BooleanField enable = BooleanField.ofBooleanType(prefs.enableGitStorage)
|
||||
.editable(pro)
|
||||
.render(() -> {
|
||||
|
|
|
@ -35,12 +35,12 @@ public abstract class LicenseProvider {
|
|||
}
|
||||
}
|
||||
|
||||
public abstract LicensedFeature getFeature(String id);
|
||||
|
||||
public abstract void handleShellControl(ShellControl sc);
|
||||
|
||||
public abstract void showLicenseAlert(LicenseRequiredException ex);
|
||||
|
||||
public abstract LicenseType getLicenseType();
|
||||
|
||||
public abstract void init();
|
||||
|
||||
public abstract Comp<?> overviewPage();
|
||||
|
|
|
@ -8,12 +8,10 @@ public class LicenseRequiredException extends RuntimeException {
|
|||
|
||||
String featureName;
|
||||
boolean plural;
|
||||
LicenseType minLicense;
|
||||
|
||||
public LicenseRequiredException(String featureName, boolean plural, LicenseType minLicense) {
|
||||
super(featureName + (plural ? " are" : " is") + " only supported with a " + minLicense.name().toLowerCase() + " license");
|
||||
public LicenseRequiredException(String featureName, boolean plural) {
|
||||
super(featureName + (plural ? " are" : " is") + " only supported with a professional license");
|
||||
this.featureName = featureName;
|
||||
this.plural = plural;
|
||||
this.minLicense = minLicense;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
package io.xpipe.app.util;
|
||||
|
||||
public enum LicenseType {
|
||||
|
||||
COMMUNITY,
|
||||
PROFESSIONAL,
|
||||
ENTERPRISE;
|
||||
|
||||
public static boolean isAtLeast(LicenseType input, LicenseType target) {
|
||||
if (target == COMMUNITY) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (target == PROFESSIONAL) {
|
||||
return input == PROFESSIONAL || input == ENTERPRISE;
|
||||
}
|
||||
|
||||
return target == ENTERPRISE;
|
||||
}
|
||||
}
|
8
app/src/main/java/io/xpipe/app/util/LicensedFeature.java
Normal file
8
app/src/main/java/io/xpipe/app/util/LicensedFeature.java
Normal file
|
@ -0,0 +1,8 @@
|
|||
package io.xpipe.app.util;
|
||||
|
||||
public interface LicensedFeature {
|
||||
|
||||
String getId();
|
||||
|
||||
boolean isSupported();
|
||||
}
|
|
@ -118,6 +118,7 @@ open module io.xpipe.app {
|
|||
uses ScanProvider;
|
||||
uses BrowserAction;
|
||||
uses LicenseProvider;
|
||||
uses io.xpipe.app.util.LicensedFeature;
|
||||
|
||||
provides Module with StorageJacksonModule;
|
||||
provides ModuleLayerLoader with
|
||||
|
|
Loading…
Reference in a new issue