From 1ea4018379a4e1ffd569cb55b3986e5d0c3c7cb1 Mon Sep 17 00:00:00 2001 From: crschnick Date: Thu, 9 Mar 2023 20:45:13 +0000 Subject: [PATCH] Various small fixes --- .../comp/storage/store/StoreEntrySection.java | 24 +++++++++++-------- .../app/exchange/AskpassExchangeImpl.java | 23 +++++++++++++++++- .../java/io/xpipe/app/ext/ScanProvider.java | 1 + .../java/io/xpipe/app/util/ScanAlert.java | 2 +- .../beacon/exchange/AskpassExchange.java | 2 ++ 5 files changed, 40 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/comp/storage/store/StoreEntrySection.java b/app/src/main/java/io/xpipe/app/comp/storage/store/StoreEntrySection.java index 756782d7d..a7e631ee7 100644 --- a/app/src/main/java/io/xpipe/app/comp/storage/store/StoreEntrySection.java +++ b/app/src/main/java/io/xpipe/app/comp/storage/store/StoreEntrySection.java @@ -8,6 +8,7 @@ import io.xpipe.app.fxcomps.impl.HorizontalComp; import io.xpipe.app.fxcomps.impl.VerticalComp; import io.xpipe.app.fxcomps.util.BindingsHelper; import io.xpipe.app.storage.DataStorage; +import io.xpipe.app.storage.DataStoreEntry; import javafx.beans.binding.Bindings; import javafx.collections.FXCollections; import javafx.collections.ObservableList; @@ -21,15 +22,21 @@ import java.util.List; public class StoreEntrySection implements StorageFilter.Filterable { + private static final Comparator COMPARATOR = Comparator.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 children) { this.entry = entry; this.children = children; } public static ObservableList createTopLevels() { - var filtered = BindingsHelper.filteredContentBinding( - StoreViewState.get().getAllEntries(), - storeEntryWrapper -> { + var filtered = + BindingsHelper.filteredContentBinding(StoreViewState.get().getAllEntries(), storeEntryWrapper -> { if (!storeEntryWrapper.getEntry().getState().isUsable()) { return true; } @@ -38,14 +45,13 @@ public class StoreEntrySection implements StorageFilter.Filterable { .getEntry() .getProvider() .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 ordered = BindingsHelper.orderedContentBinding( topLevel, - Comparator.comparing(storeEntrySection -> - storeEntrySection.entry.lastAccessProperty().getValue()) - .reversed()); + COMPARATOR); return ordered; } @@ -65,9 +71,7 @@ public class StoreEntrySection implements StorageFilter.Filterable { var children = BindingsHelper.mappedContentBinding(filtered, entry1 -> create(entry1)); var ordered = BindingsHelper.orderedContentBinding( children, - Comparator.comparing(storeEntrySection -> - storeEntrySection.entry.lastAccessProperty().getValue()) - .reversed()); + COMPARATOR); return new StoreEntrySection(e, ordered); } diff --git a/app/src/main/java/io/xpipe/app/exchange/AskpassExchangeImpl.java b/app/src/main/java/io/xpipe/app/exchange/AskpassExchangeImpl.java index 5582ae7db..af63c534e 100644 --- a/app/src/main/java/io/xpipe/app/exchange/AskpassExchangeImpl.java +++ b/app/src/main/java/io/xpipe/app/exchange/AskpassExchangeImpl.java @@ -10,18 +10,35 @@ import io.xpipe.core.util.SecretValue; import javafx.beans.property.SimpleObjectProperty; import javafx.scene.control.Alert; +import java.util.HashMap; +import java.util.Map; + public class AskpassExchangeImpl extends AskpassExchange implements MessageExchangeImpl { + private final Map requestToId = new HashMap<>(); + private final Map passwords = new HashMap<>(); + @Override 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); // if (set != null) { // 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 = new SimpleObjectProperty(); var r = AppWindowHelper.showBlockingAlert(alert -> { @@ -39,6 +56,10 @@ public class AskpassExchangeImpl extends AskpassExchange return prop.getValue(); }) .orElse(null); + + passwords.put(msg.getId(), r); + requestToId.put(msg.getRequest(), msg.getId()); + return Response.builder().value(r != null ? r.getSecretValue() : null).build(); } } diff --git a/app/src/main/java/io/xpipe/app/ext/ScanProvider.java b/app/src/main/java/io/xpipe/app/ext/ScanProvider.java index 30585e802..578c9a6a6 100644 --- a/app/src/main/java/io/xpipe/app/ext/ScanProvider.java +++ b/app/src/main/java/io/xpipe/app/ext/ScanProvider.java @@ -15,6 +15,7 @@ public abstract class ScanProvider { @Value public static class ScanOperation { String nameKey; + boolean defaultSelected; FailableRunnable scanner; } diff --git a/app/src/main/java/io/xpipe/app/util/ScanAlert.java b/app/src/main/java/io/xpipe/app/util/ScanAlert.java index d04f6b7ac..2f148eae5 100644 --- a/app/src/main/java/io/xpipe/app/util/ScanAlert.java +++ b/app/src/main/java/io/xpipe/app/util/ScanAlert.java @@ -30,7 +30,7 @@ public class ScanAlert { } var selected = new SimpleListProperty( - FXCollections.observableList(new ArrayList<>(applicable))); + FXCollections.observableList(new ArrayList<>(applicable.stream().filter(scanOperation -> scanOperation.isDefaultSelected()).toList()))); var busy = new SimpleBooleanProperty(); AppWindowHelper.showAlert( alert -> { diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/AskpassExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/AskpassExchange.java index f12cb087a..795b8e6df 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/AskpassExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/AskpassExchange.java @@ -20,6 +20,8 @@ public class AskpassExchange implements MessageExchange { public static class Request implements RequestMessage { @NonNull String id; + @NonNull + String request; String prompt; }