diff --git a/ext/base/src/main/java/io/xpipe/ext/base/action/RunScriptActionMenu.java b/ext/base/src/main/java/io/xpipe/ext/base/action/RunScriptActionMenu.java index 94808806c..8380aa77b 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/action/RunScriptActionMenu.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/action/RunScriptActionMenu.java @@ -3,6 +3,7 @@ package io.xpipe.ext.base.action; import io.xpipe.app.comp.store.StoreViewState; import io.xpipe.app.core.AppI18n; import io.xpipe.app.ext.ActionProvider; +import io.xpipe.app.prefs.AppPrefs; import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.app.util.TerminalLauncher; import io.xpipe.core.process.ShellStoreState; @@ -17,7 +18,7 @@ import java.util.List; public class RunScriptActionMenu implements ActionProvider { @Value - private static class ScriptActionProvider implements ActionProvider { + private static class TerminalRunActionProvider implements ActionProvider { ScriptHierarchy hierarchy; @@ -41,10 +42,6 @@ public class RunScriptActionMenu implements ActionProvider { @Override public LeafDataStoreCallSite getLeafDataStoreCallSite() { - if (!hierarchy.isLeaf()) { - return null; - } - return new LeafDataStoreCallSite() { @Override public Action createAction(DataStoreEntryRef store) { @@ -53,12 +50,15 @@ public class RunScriptActionMenu implements ActionProvider { @Override public ObservableValue getName(DataStoreEntryRef store) { - return new SimpleStringProperty(hierarchy.getBase().get().getName()); + var t = AppPrefs.get().terminalType().getValue(); + return AppI18n.observable( + "executeInTerminal", + t != null ? t.toTranslatedString().getValue() : "?"); } @Override public String getIcon(DataStoreEntryRef store) { - return "mdi2p-play-box-multiple-outline"; + return "mdi2d-desktop-mac"; } @Override @@ -67,10 +67,91 @@ public class RunScriptActionMenu implements ActionProvider { } }; } + } + + @Value + private static class BackgroundRunActionProvider implements ActionProvider { + + ScriptHierarchy hierarchy; + + @Value + private class Action implements ActionProvider.Action { + + DataStoreEntryRef shellStore; + + @Override + public void execute() throws Exception { + try (var sc = shellStore.getStore().control().start()) { + var script = hierarchy.getLeafBase().getStore().assembleScriptChain(sc); + sc.command(script).execute(); + } + } + } + + @Override + public LeafDataStoreCallSite getLeafDataStoreCallSite() { + return new LeafDataStoreCallSite() { + @Override + public Action createAction(DataStoreEntryRef store) { + return new Action(store); + } + + @Override + public ObservableValue getName(DataStoreEntryRef store) { + return AppI18n.observable("executeInBackground"); + } + + @Override + public String getIcon(DataStoreEntryRef store) { + return "mdi2f-flip-to-back"; + } + + @Override + public Class getApplicableClass() { + return ShellStore.class; + } + }; + } + } + + @Value + private static class ScriptActionProvider implements ActionProvider { + + ScriptHierarchy hierarchy; + + private BranchDataStoreCallSite getLeafSite() { + return new BranchDataStoreCallSite() { + + @Override + public Class getApplicableClass() { + return ShellStore.class; + } + + @Override + public ObservableValue getName(DataStoreEntryRef store) { + return new SimpleStringProperty(hierarchy.getBase().get().getName()); + } + + @Override + public boolean isDynamicallyGenerated() { + return true; + } + + @Override + public String getIcon(DataStoreEntryRef store) { + return "mdi2p-play-box-multiple-outline"; + } + + @Override + public List getChildren(DataStoreEntryRef store) { + return List.of(new TerminalRunActionProvider(hierarchy), new BackgroundRunActionProvider(hierarchy)); + } + }; + } public BranchDataStoreCallSite getBranchDataStoreCallSite() { if (hierarchy.isLeaf()) { - return null; + return getLeafSite(); } return new BranchDataStoreCallSite() {