From 41f71d45a7c5b35dfbc24f94f9c369b3e498dbdf Mon Sep 17 00:00:00 2001 From: crschnick Date: Mon, 12 Aug 2024 07:10:46 +0000 Subject: [PATCH] Rework launchable stores --- .../io/xpipe/core/process/ShellTtyState.java | 2 +- .../io/xpipe/core/store/LaunchableStore.java | 6 --- .../java/io/xpipe/core/store/ShellStore.java | 2 +- .../ext/base/action/LaunchStoreAction.java | 43 ++----------------- .../xpipe/ext/base/action/XPipeUrlAction.java | 3 +- .../base/store/LaunchableTerminalStore.java | 16 ------- 6 files changed, 8 insertions(+), 64 deletions(-) delete mode 100644 core/src/main/java/io/xpipe/core/store/LaunchableStore.java delete mode 100644 ext/base/src/main/java/io/xpipe/ext/base/store/LaunchableTerminalStore.java diff --git a/core/src/main/java/io/xpipe/core/process/ShellTtyState.java b/core/src/main/java/io/xpipe/core/process/ShellTtyState.java index ef1afe101..68f040858 100644 --- a/core/src/main/java/io/xpipe/core/process/ShellTtyState.java +++ b/core/src/main/java/io/xpipe/core/process/ShellTtyState.java @@ -9,7 +9,7 @@ public enum ShellTtyState { @JsonProperty("none") NONE(true, false, false, true, true), @JsonProperty("merged") - MERGED_STDERR(false, false, false, false, true), + MERGED_STDERR(false, true, false, false, false), @JsonProperty("pty") PTY_ALLOCATED(false, true, true, false, false); diff --git a/core/src/main/java/io/xpipe/core/store/LaunchableStore.java b/core/src/main/java/io/xpipe/core/store/LaunchableStore.java deleted file mode 100644 index b0a5b3e77..000000000 --- a/core/src/main/java/io/xpipe/core/store/LaunchableStore.java +++ /dev/null @@ -1,6 +0,0 @@ -package io.xpipe.core.store; - -public interface LaunchableStore extends DataStore { - - default void launch() throws Exception {} -} diff --git a/core/src/main/java/io/xpipe/core/store/ShellStore.java b/core/src/main/java/io/xpipe/core/store/ShellStore.java index 549b09780..3401dcde9 100644 --- a/core/src/main/java/io/xpipe/core/store/ShellStore.java +++ b/core/src/main/java/io/xpipe/core/store/ShellStore.java @@ -3,7 +3,7 @@ package io.xpipe.core.store; import io.xpipe.core.process.ProcessControl; import io.xpipe.core.process.ShellControl; -public interface ShellStore extends DataStore, LaunchableStore, FileSystemStore, ValidatableStore { +public interface ShellStore extends DataStore, FileSystemStore, ValidatableStore { static boolean isLocal(ShellStore s) { return s instanceof LocalStore; diff --git a/ext/base/src/main/java/io/xpipe/ext/base/action/LaunchStoreAction.java b/ext/base/src/main/java/io/xpipe/ext/base/action/LaunchStoreAction.java index 9ebaa088a..5e98e31eb 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/action/LaunchStoreAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/action/LaunchStoreAction.java @@ -2,19 +2,10 @@ package io.xpipe.ext.base.action; import io.xpipe.app.core.AppI18n; import io.xpipe.app.ext.ActionProvider; -import io.xpipe.app.storage.DataStorage; -import io.xpipe.app.storage.DataStoreEntry; import io.xpipe.app.storage.DataStoreEntryRef; -import io.xpipe.app.util.TerminalLauncher; import io.xpipe.core.store.DataStore; -import io.xpipe.core.store.LaunchableStore; -import io.xpipe.core.store.ShellStore; -import io.xpipe.ext.base.script.ScriptStore; - import javafx.beans.value.ObservableValue; -import lombok.Value; - public class LaunchStoreAction implements ActionProvider { @Override @@ -33,7 +24,7 @@ public class LaunchStoreAction implements ActionProvider { @Override public ActionProvider.Action createAction(DataStoreEntryRef store) { - return new Action(store.get()); + return store.get().getProvider().launchAction(store.get()); } @Override @@ -44,8 +35,7 @@ public class LaunchStoreAction implements ActionProvider { @Override public boolean isApplicable(DataStoreEntryRef o) { return o.get().getValidity().isUsable() - && (o.getStore() instanceof LaunchableStore - || o.get().getProvider().launchAction(o.get()) != null); + && (o.get().getProvider().launchAction(o.get()) != null); } @Override @@ -66,7 +56,7 @@ public class LaunchStoreAction implements ActionProvider { @Override public ActionProvider.Action createAction(DataStoreEntryRef store) { - return new Action(store.get()); + return store.get().getProvider().launchAction(store.get()); } @Override @@ -77,33 +67,8 @@ public class LaunchStoreAction implements ActionProvider { @Override public boolean isApplicable(DataStoreEntryRef o) { return o.get().getValidity().isUsable() - && (o.getStore() instanceof LaunchableStore - || o.get().getProvider().launchAction(o.get()) != null); + && (o.get().getProvider().launchAction(o.get()) != null); } }; } - - @Value - static class Action implements ActionProvider.Action { - - DataStoreEntry entry; - - @Override - public void execute() throws Exception { - var storeName = DataStorage.get().getStoreEntryDisplayName(entry); - if (entry.getStore() instanceof ShellStore s) { - TerminalLauncher.open(entry, storeName, null, ScriptStore.controlWithDefaultScripts(s.control())); - return; - } - - if (entry.getStore() instanceof LaunchableStore s) { - s.launch(); - return; - } - - if (entry.getProvider().launchAction(entry) != null) { - entry.getProvider().launchAction(entry).execute(); - } - } - } } diff --git a/ext/base/src/main/java/io/xpipe/ext/base/action/XPipeUrlAction.java b/ext/base/src/main/java/io/xpipe/ext/base/action/XPipeUrlAction.java index 7a7807a0f..72508c2f3 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/action/XPipeUrlAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/action/XPipeUrlAction.java @@ -43,7 +43,8 @@ public class XPipeUrlAction implements ActionProvider { if (!entry.getValidity().isUsable()) { return null; } - return new LaunchStoreAction.Action(entry); + var p = entry.getProvider(); + return p.launchAction(entry); } case "action" -> { var id = args.get(1); diff --git a/ext/base/src/main/java/io/xpipe/ext/base/store/LaunchableTerminalStore.java b/ext/base/src/main/java/io/xpipe/ext/base/store/LaunchableTerminalStore.java deleted file mode 100644 index 8feb2ad24..000000000 --- a/ext/base/src/main/java/io/xpipe/ext/base/store/LaunchableTerminalStore.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.xpipe.ext.base.store; - -import io.xpipe.app.util.TerminalLauncher; -import io.xpipe.core.process.ProcessControl; -import io.xpipe.core.store.LaunchableStore; -import io.xpipe.ext.base.SelfReferentialStore; - -public interface LaunchableTerminalStore extends SelfReferentialStore, LaunchableStore { - - @Override - default void launch() throws Exception { - TerminalLauncher.open(getSelfEntry(), getSelfEntry().getName(), null, prepareLaunchCommand()); - } - - ProcessControl prepareLaunchCommand() throws Exception; -}