diff --git a/app/src/main/java/io/xpipe/app/core/AppI18n.java b/app/src/main/java/io/xpipe/app/core/AppI18n.java index 09f572736..a7b5599ec 100644 --- a/app/src/main/java/io/xpipe/app/core/AppI18n.java +++ b/app/src/main/java/io/xpipe/app/core/AppI18n.java @@ -62,11 +62,11 @@ public class AppI18n { return INSTANCE; } - public static StringBinding readableDuration(String s, ObservableValue instant) { - return readableDuration(instant, rs -> getValue(getInstance().getLocalised(s), rs)); + public static StringBinding readableInstant(String s, ObservableValue instant) { + return readableInstant(instant, rs -> getValue(getInstance().getLocalised(s), rs)); } - public static StringBinding readableDuration(ObservableValue instant, UnaryOperator op) { + public static StringBinding readableInstant(ObservableValue instant, UnaryOperator op) { return Bindings.createStringBinding( () -> { if (instant.getValue() == null) { @@ -79,7 +79,7 @@ public class AppI18n { instant); } - public static StringBinding readableDuration(ObservableValue instant) { + public static StringBinding readableInstant(ObservableValue instant) { return Bindings.createStringBinding( () -> { if (instant.getValue() == null) { @@ -91,6 +91,19 @@ public class AppI18n { instant); } + public static StringBinding readableDuration(ObservableValue 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 observable(String s, Object... vars) { if (s == null) { return null; diff --git a/app/src/main/java/io/xpipe/app/prefs/VaultCategory.java b/app/src/main/java/io/xpipe/app/prefs/VaultCategory.java index dc9eae5bc..28b78ea01 100644 --- a/app/src/main/java/io/xpipe/app/prefs/VaultCategory.java +++ b/app/src/main/java/io/xpipe/app/prefs/VaultCategory.java @@ -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(() -> { diff --git a/app/src/main/java/io/xpipe/app/util/LicenseProvider.java b/app/src/main/java/io/xpipe/app/util/LicenseProvider.java index dbc6fb10c..212266a9f 100644 --- a/app/src/main/java/io/xpipe/app/util/LicenseProvider.java +++ b/app/src/main/java/io/xpipe/app/util/LicenseProvider.java @@ -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(); diff --git a/app/src/main/java/io/xpipe/app/util/LicenseRequiredException.java b/app/src/main/java/io/xpipe/app/util/LicenseRequiredException.java index 9ece05d31..00d598d2e 100644 --- a/app/src/main/java/io/xpipe/app/util/LicenseRequiredException.java +++ b/app/src/main/java/io/xpipe/app/util/LicenseRequiredException.java @@ -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; } } diff --git a/app/src/main/java/io/xpipe/app/util/LicenseType.java b/app/src/main/java/io/xpipe/app/util/LicenseType.java deleted file mode 100644 index 0cc2b720d..000000000 --- a/app/src/main/java/io/xpipe/app/util/LicenseType.java +++ /dev/null @@ -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; - } -} diff --git a/app/src/main/java/io/xpipe/app/util/LicensedFeature.java b/app/src/main/java/io/xpipe/app/util/LicensedFeature.java new file mode 100644 index 000000000..1d637742c --- /dev/null +++ b/app/src/main/java/io/xpipe/app/util/LicensedFeature.java @@ -0,0 +1,8 @@ +package io.xpipe.app.util; + +public interface LicensedFeature { + + String getId(); + + boolean isSupported(); +} diff --git a/app/src/main/java/module-info.java b/app/src/main/java/module-info.java index 41dbf8087..fb1d763b5 100644 --- a/app/src/main/java/module-info.java +++ b/app/src/main/java/module-info.java @@ -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