From d6cccd1d5a3aa3d0ebaf15c08b50b26d4110e5ce Mon Sep 17 00:00:00 2001 From: Christopher Schnick Date: Wed, 19 Oct 2022 05:20:17 +0200 Subject: [PATCH] Small fixes --- .../java/io/xpipe/core/store/DataFlow.java | 18 ++++++++++++++---- .../java/io/xpipe/core/store/ShellTypes.java | 2 +- .../io/xpipe/extension/DataStoreProvider.java | 9 ++++++--- .../io/xpipe/extension/DataStoreProviders.java | 15 ++++++++++++++- .../io/xpipe/extension/util/DialogHelper.java | 14 +++++++------- 5 files changed, 42 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/io/xpipe/core/store/DataFlow.java b/core/src/main/java/io/xpipe/core/store/DataFlow.java index fa3e0c78b..ff116688d 100644 --- a/core/src/main/java/io/xpipe/core/store/DataFlow.java +++ b/core/src/main/java/io/xpipe/core/store/DataFlow.java @@ -4,13 +4,19 @@ import com.fasterxml.jackson.annotation.JsonProperty; public enum DataFlow { @JsonProperty("input") - INPUT, + INPUT("Input"), @JsonProperty("output") - OUTPUT, + OUTPUT("Output"), @JsonProperty("inputOutput") - INPUT_OUTPUT, + INPUT_OUTPUT("Input/Output"), @JsonProperty("transformer") - TRANSFORMER; + TRANSFORMER("Transformer"); + + private final String displayName; + + DataFlow(String displayName) { + this.displayName = displayName; + } public boolean hasInput() { return this == INPUT || this == INPUT_OUTPUT; @@ -19,4 +25,8 @@ public enum DataFlow { public boolean hasOutput() { return this == OUTPUT || this == INPUT_OUTPUT; } + + public String getDisplayName() { + return displayName; + } } diff --git a/core/src/main/java/io/xpipe/core/store/ShellTypes.java b/core/src/main/java/io/xpipe/core/store/ShellTypes.java index 1021f75f3..fc3f787ec 100644 --- a/core/src/main/java/io/xpipe/core/store/ShellTypes.java +++ b/core/src/main/java/io/xpipe/core/store/ShellTypes.java @@ -42,7 +42,7 @@ public class ShellTypes { public static StandardShellStore.ShellType[] getAvailable(ShellStore store) throws Exception { var o = store.prepareCommand(List.of(), List.of("echo", "$0"), null, StandardCharsets.US_ASCII) .executeAndReadStdoutOrThrow(); - if (!o.trim().equals("$0")) { + if (o.trim().length() > 0 && !o.trim().equals("$0")) { return getLinuxShells(); } else { return getWindowsShells(); diff --git a/extension/src/main/java/io/xpipe/extension/DataStoreProvider.java b/extension/src/main/java/io/xpipe/extension/DataStoreProvider.java index 999bd9ed9..027ceb666 100644 --- a/extension/src/main/java/io/xpipe/extension/DataStoreProvider.java +++ b/extension/src/main/java/io/xpipe/extension/DataStoreProvider.java @@ -1,7 +1,10 @@ package io.xpipe.extension; import io.xpipe.core.dialog.Dialog; -import io.xpipe.core.store.*; +import io.xpipe.core.store.DataStore; +import io.xpipe.core.store.MachineFileStore; +import io.xpipe.core.store.ShellStore; +import io.xpipe.core.store.StreamDataStore; import io.xpipe.core.util.JacksonizedValue; import javafx.beans.property.Property; @@ -90,8 +93,8 @@ public interface DataStoreProvider { List> getStoreClasses(); - default DataFlow[] getPossibleFlows() { - return new DataFlow[] {DataFlow.INPUT}; + default boolean shouldShow() { + return true; } enum Category { diff --git a/extension/src/main/java/io/xpipe/extension/DataStoreProviders.java b/extension/src/main/java/io/xpipe/extension/DataStoreProviders.java index 533265828..2dcda4bb1 100644 --- a/extension/src/main/java/io/xpipe/extension/DataStoreProviders.java +++ b/extension/src/main/java/io/xpipe/extension/DataStoreProviders.java @@ -36,10 +36,23 @@ public class DataStoreProviders { } return ALL.stream() - .filter(d -> d.getPossibleNames().stream().anyMatch(s -> s.equalsIgnoreCase(name))) + .filter(d -> d.getPossibleNames().stream() + .anyMatch(s -> nameAlternatives(s).stream().anyMatch(s1 -> s1.equalsIgnoreCase(name))) + || d.getId().equalsIgnoreCase(name)) .findAny(); } + private static List nameAlternatives(String name) { + var split = List.of(name.split("_")); + return List.of( + String.join(" ", split), + String.join("_", split), + String.join("-", split), + split.stream() + .map(s -> s.equals(split.get(0)) ? s : s.substring(0, 1).toUpperCase() + s.substring(1)) + .collect(Collectors.joining())); + } + public static Optional byString(String s) { if (ALL == null) { throw new IllegalStateException("Not initialized"); diff --git a/extension/src/main/java/io/xpipe/extension/util/DialogHelper.java b/extension/src/main/java/io/xpipe/extension/util/DialogHelper.java index e46f4cb07..d13ff3eb8 100644 --- a/extension/src/main/java/io/xpipe/extension/util/DialogHelper.java +++ b/extension/src/main/java/io/xpipe/extension/util/DialogHelper.java @@ -21,10 +21,10 @@ public class DialogHelper { } public static Dialog machineQuery(DataStore store) { - var storeName = XPipeDaemon.getInstance().getStoreName(store).orElse("local"); + var storeName = XPipeDaemon.getInstance().getStoreName(store).orElse("localhost"); return Dialog.query("Machine", false, true, false, storeName, QueryConverter.STRING) .map((String name) -> { - if (name.equals("local")) { + if (name.equals("local") || name.equals("localhost")) { return new LocalStore(); } @@ -42,14 +42,14 @@ public class DialogHelper { } public static Dialog dataStoreFlowQuery(DataFlow flow, DataFlow[] available) { - return Dialog.choice("flow", o -> o.toString(), true, flow, available); + return Dialog.choice("Flow", (DataFlow o) -> o.getDisplayName(), true, flow, available); } - public static Dialog shellQuery(DataStore store) { - var storeName = XPipeDaemon.getInstance().getStoreName(store).orElse("local"); - return Dialog.query("Shell", false, true, false, storeName, QueryConverter.STRING) + public static Dialog shellQuery(String displayName, DataStore store) { + var storeName = XPipeDaemon.getInstance().getStoreName(store).orElse("localhost"); + return Dialog.query(displayName, false, true, false, storeName, QueryConverter.STRING) .map((String name) -> { - if (name.equals("local")) { + if (name.equals("local") || name.equals("localhost")) { return new LocalStore(); }