mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-25 17:10:27 +00:00
Rework preview handling
This commit is contained in:
parent
96848146c5
commit
f3bc8f5390
5 changed files with 58 additions and 11 deletions
|
@ -5,6 +5,7 @@ import io.xpipe.core.process.ShellControl;
|
|||
import io.xpipe.core.store.DataStore;
|
||||
import io.xpipe.core.util.FailableRunnable;
|
||||
import io.xpipe.core.util.ModuleLayerLoader;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Value;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
@ -29,11 +30,25 @@ public abstract class ScanProvider {
|
|||
}
|
||||
|
||||
@Value
|
||||
@AllArgsConstructor
|
||||
public static class ScanOperation {
|
||||
String nameKey;
|
||||
boolean disabled;
|
||||
boolean defaultSelected;
|
||||
FailableRunnable<Exception> scanner;
|
||||
String licenseFeatureId;
|
||||
|
||||
public ScanOperation(String nameKey, boolean disabled, boolean defaultSelected, FailableRunnable<Exception> scanner) {
|
||||
this.nameKey = nameKey;
|
||||
this.disabled = disabled;
|
||||
this.defaultSelected = defaultSelected;
|
||||
this.scanner = scanner;
|
||||
this.licenseFeatureId = null;
|
||||
}
|
||||
|
||||
public String getLicensedFeatureId() {
|
||||
return licenseFeatureId;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Loader implements ModuleLayerLoader {
|
||||
|
|
|
@ -421,12 +421,17 @@ public abstract class DataStorage {
|
|||
// pair.getKey().setStoreInternal(pair.getValue().getStore(), false);
|
||||
|
||||
// Update state by merging
|
||||
if (pair.getKey().getStorePersistentState() != null
|
||||
&& pair.getValue().get().getStorePersistentState() != null) {
|
||||
if (pair.getKey().getStorePersistentState() != null && pair.getValue().get().getStorePersistentState() != null) {
|
||||
var classMatch = pair.getKey().getStorePersistentState().getClass()
|
||||
.equals(pair.getValue().get().getStorePersistentState().getClass());
|
||||
// Children classes might not be the same, the same goes for state classes
|
||||
// This can happen when there are multiple child classes and the ids got switched around
|
||||
if (classMatch) {
|
||||
var mergedState = pair.getKey().getStorePersistentState().deepCopy();
|
||||
mergedState.merge(pair.getValue().get().getStorePersistentState());
|
||||
pair.getKey().setStorePersistentState(mergedState);
|
||||
}
|
||||
}
|
||||
});
|
||||
saveAsync();
|
||||
return !newChildren.isEmpty();
|
||||
|
|
|
@ -1,7 +1,21 @@
|
|||
package io.xpipe.app.util;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface LicensedFeature {
|
||||
|
||||
default Optional<String> getDescriptionSuffix() {
|
||||
if (isSupported()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
if (isPreviewSupported()) {
|
||||
return Optional.of("Preview");
|
||||
}
|
||||
|
||||
return Optional.of("Pro");
|
||||
}
|
||||
|
||||
String getId();
|
||||
|
||||
String getDisplayName();
|
||||
|
@ -12,5 +26,9 @@ public interface LicensedFeature {
|
|||
|
||||
boolean isPreviewSupported();
|
||||
|
||||
void throwIfUnsupported() throws LicenseRequiredException;
|
||||
default void throwIfUnsupported() throws LicenseRequiredException {
|
||||
if (!isSupported()) {
|
||||
throw new LicenseRequiredException(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -180,9 +180,18 @@ public class ScanAlert {
|
|||
.filter(scanOperation ->
|
||||
scanOperation.isDefaultSelected() && !scanOperation.isDisabled())
|
||||
.toList());
|
||||
Function<ScanProvider.ScanOperation, String> nameFunc = (ScanProvider.ScanOperation s) -> {
|
||||
var n = AppI18n.get(s.getNameKey());
|
||||
if (s.getLicensedFeatureId() == null) {
|
||||
return n;
|
||||
}
|
||||
|
||||
var suffix = LicenseProvider.get().getFeature(s.getLicensedFeatureId());
|
||||
return n + suffix.getDescriptionSuffix().map(d -> " (" + d + ")").orElse("");
|
||||
};
|
||||
var r = new ListSelectorComp<>(
|
||||
a,
|
||||
scanOperation -> AppI18n.get(scanOperation.getNameKey()),
|
||||
nameFunc,
|
||||
selected,
|
||||
scanOperation -> scanOperation.isDisabled(),
|
||||
a.size() > 3)
|
||||
|
|
|
@ -5,14 +5,14 @@ import lombok.Setter;
|
|||
|
||||
public class CountDown {
|
||||
|
||||
private long lastMillis = -1;
|
||||
private long millisecondsLeft;
|
||||
private volatile long lastMillis = -1;
|
||||
private volatile long millisecondsLeft;
|
||||
|
||||
@Setter
|
||||
private boolean active;
|
||||
private volatile boolean active;
|
||||
|
||||
@Getter
|
||||
private long maxMillis;
|
||||
private volatile long maxMillis;
|
||||
|
||||
private CountDown() {}
|
||||
|
||||
|
|
Loading…
Reference in a new issue