Rework launchable stores

This commit is contained in:
crschnick 2024-08-12 07:10:46 +00:00
parent 9b7cca8589
commit 41f71d45a7
6 changed files with 8 additions and 64 deletions

View file

@ -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);

View file

@ -1,6 +0,0 @@
package io.xpipe.core.store;
public interface LaunchableStore extends DataStore {
default void launch() throws Exception {}
}

View file

@ -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;

View file

@ -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<DataStore> 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<DataStore> 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<DataStore> 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<DataStore> 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();
}
}
}
}

View file

@ -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);

View file

@ -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;
}