Various small fixes

This commit is contained in:
crschnick 2023-03-09 20:45:13 +00:00
parent 782be482d0
commit 1ea4018379
5 changed files with 40 additions and 12 deletions

View file

@ -8,6 +8,7 @@ import io.xpipe.app.fxcomps.impl.HorizontalComp;
import io.xpipe.app.fxcomps.impl.VerticalComp; import io.xpipe.app.fxcomps.impl.VerticalComp;
import io.xpipe.app.fxcomps.util.BindingsHelper; import io.xpipe.app.fxcomps.util.BindingsHelper;
import io.xpipe.app.storage.DataStorage; import io.xpipe.app.storage.DataStorage;
import io.xpipe.app.storage.DataStoreEntry;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
@ -21,15 +22,21 @@ import java.util.List;
public class StoreEntrySection implements StorageFilter.Filterable { public class StoreEntrySection implements StorageFilter.Filterable {
private static final Comparator<StoreEntrySection> COMPARATOR = Comparator.<StoreEntrySection, Instant>comparing(
o -> o.entry.getEntry().getState().equals(DataStoreEntry.State.COMPLETE_AND_VALID)
? o.entry.getEntry().getLastAccess()
: Instant.EPOCH).reversed()
.thenComparing(
storeEntrySection -> storeEntrySection.entry.getEntry().getName());
public StoreEntrySection(StoreEntryWrapper entry, ObservableList<StoreEntrySection> children) { public StoreEntrySection(StoreEntryWrapper entry, ObservableList<StoreEntrySection> children) {
this.entry = entry; this.entry = entry;
this.children = children; this.children = children;
} }
public static ObservableList<StoreEntrySection> createTopLevels() { public static ObservableList<StoreEntrySection> createTopLevels() {
var filtered = BindingsHelper.filteredContentBinding( var filtered =
StoreViewState.get().getAllEntries(), BindingsHelper.filteredContentBinding(StoreViewState.get().getAllEntries(), storeEntryWrapper -> {
storeEntryWrapper -> {
if (!storeEntryWrapper.getEntry().getState().isUsable()) { if (!storeEntryWrapper.getEntry().getState().isUsable()) {
return true; return true;
} }
@ -38,14 +45,13 @@ public class StoreEntrySection implements StorageFilter.Filterable {
.getEntry() .getEntry()
.getProvider() .getProvider()
.getParent(storeEntryWrapper.getEntry().getStore()); .getParent(storeEntryWrapper.getEntry().getStore());
return parent == null || (DataStorage.get().getStoreEntryIfPresent(parent).isEmpty()); return parent == null
|| (DataStorage.get().getStoreEntryIfPresent(parent).isEmpty());
}); });
var topLevel = BindingsHelper.mappedContentBinding(filtered, storeEntryWrapper -> create(storeEntryWrapper)); var topLevel = BindingsHelper.mappedContentBinding(filtered, storeEntryWrapper -> create(storeEntryWrapper));
var ordered = BindingsHelper.orderedContentBinding( var ordered = BindingsHelper.orderedContentBinding(
topLevel, topLevel,
Comparator.<StoreEntrySection, Instant>comparing(storeEntrySection -> COMPARATOR);
storeEntrySection.entry.lastAccessProperty().getValue())
.reversed());
return ordered; return ordered;
} }
@ -65,9 +71,7 @@ public class StoreEntrySection implements StorageFilter.Filterable {
var children = BindingsHelper.mappedContentBinding(filtered, entry1 -> create(entry1)); var children = BindingsHelper.mappedContentBinding(filtered, entry1 -> create(entry1));
var ordered = BindingsHelper.orderedContentBinding( var ordered = BindingsHelper.orderedContentBinding(
children, children,
Comparator.<StoreEntrySection, Instant>comparing(storeEntrySection -> COMPARATOR);
storeEntrySection.entry.lastAccessProperty().getValue())
.reversed());
return new StoreEntrySection(e, ordered); return new StoreEntrySection(e, ordered);
} }

View file

@ -10,18 +10,35 @@ import io.xpipe.core.util.SecretValue;
import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
import java.util.HashMap;
import java.util.Map;
public class AskpassExchangeImpl extends AskpassExchange public class AskpassExchangeImpl extends AskpassExchange
implements MessageExchangeImpl<AskpassExchange.Request, AskpassExchange.Response> { implements MessageExchangeImpl<AskpassExchange.Request, AskpassExchange.Response> {
private final Map<String, String> requestToId = new HashMap<>();
private final Map<String, SecretValue> passwords = new HashMap<>();
@Override @Override
public Response handleRequest(BeaconHandler handler, Request msg) throws Exception { public Response handleRequest(BeaconHandler handler, Request msg) throws Exception {
OperationMode.switchTo(OperationMode.GUI); if (OperationMode.get().equals(OperationMode.BACKGROUND)) {
OperationMode.switchTo(OperationMode.TRAY);
}
// SecretValue set = AppCache.get(msg.getId(), SecretValue.class, () -> null); // SecretValue set = AppCache.get(msg.getId(), SecretValue.class, () -> null);
// if (set != null) { // if (set != null) {
// return Response.builder().value(set).build(); // return Response.builder().value(set).build();
// } // }
if (requestToId.containsKey(msg.getRequest())) {
var id = requestToId.remove(msg.getRequest());
passwords.remove(id);
}
if (passwords.containsKey(msg.getId())) {
return Response.builder().value(passwords.get(msg.getId()).getSecretValue()).build();
}
var prop = var prop =
new SimpleObjectProperty<SecretValue>(); new SimpleObjectProperty<SecretValue>();
var r = AppWindowHelper.showBlockingAlert(alert -> { var r = AppWindowHelper.showBlockingAlert(alert -> {
@ -39,6 +56,10 @@ public class AskpassExchangeImpl extends AskpassExchange
return prop.getValue(); return prop.getValue();
}) })
.orElse(null); .orElse(null);
passwords.put(msg.getId(), r);
requestToId.put(msg.getRequest(), msg.getId());
return Response.builder().value(r != null ? r.getSecretValue() : null).build(); return Response.builder().value(r != null ? r.getSecretValue() : null).build();
} }
} }

View file

@ -15,6 +15,7 @@ public abstract class ScanProvider {
@Value @Value
public static class ScanOperation { public static class ScanOperation {
String nameKey; String nameKey;
boolean defaultSelected;
FailableRunnable<Exception> scanner; FailableRunnable<Exception> scanner;
} }

View file

@ -30,7 +30,7 @@ public class ScanAlert {
} }
var selected = new SimpleListProperty<ScanProvider.ScanOperation>( var selected = new SimpleListProperty<ScanProvider.ScanOperation>(
FXCollections.observableList(new ArrayList<>(applicable))); FXCollections.observableList(new ArrayList<>(applicable.stream().filter(scanOperation -> scanOperation.isDefaultSelected()).toList())));
var busy = new SimpleBooleanProperty(); var busy = new SimpleBooleanProperty();
AppWindowHelper.showAlert( AppWindowHelper.showAlert(
alert -> { alert -> {

View file

@ -20,6 +20,8 @@ public class AskpassExchange implements MessageExchange {
public static class Request implements RequestMessage { public static class Request implements RequestMessage {
@NonNull @NonNull
String id; String id;
@NonNull
String request;
String prompt; String prompt;
} }