mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-09-28 23:31:43 +12:00
Don't minimize detached windows applications
This commit is contained in:
parent
a1ec6cb422
commit
00a36628e9
6 changed files with 24 additions and 22 deletions
|
@ -2,7 +2,7 @@ package io.xpipe.app.browser.action;
|
|||
|
||||
import io.xpipe.app.browser.BrowserEntry;
|
||||
import io.xpipe.app.browser.OpenFileSystemModel;
|
||||
import io.xpipe.app.util.ScriptHelper;
|
||||
import io.xpipe.app.util.ApplicationHelper;
|
||||
import io.xpipe.core.process.ShellControl;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -14,7 +14,7 @@ public abstract class ExecuteApplicationAction implements LeafAction, Applicatio
|
|||
ShellControl sc = model.getFileSystem().getShell().orElseThrow();
|
||||
for (BrowserEntry entry : entries) {
|
||||
var command = detach()
|
||||
? ScriptHelper.createDetachCommand(sc, createCommand(model, entry))
|
||||
? ApplicationHelper.createDetachCommand(sc, createCommand(model, entry))
|
||||
: createCommand(model, entry);
|
||||
try (var cc = sc.command(command)
|
||||
.withWorkingDirectory(model.getCurrentDirectory().getPath())
|
||||
|
|
|
@ -3,7 +3,7 @@ package io.xpipe.app.browser.action;
|
|||
import io.xpipe.app.browser.BrowserEntry;
|
||||
import io.xpipe.app.browser.OpenFileSystemModel;
|
||||
import io.xpipe.app.prefs.AppPrefs;
|
||||
import io.xpipe.app.util.ScriptHelper;
|
||||
import io.xpipe.app.util.ApplicationHelper;
|
||||
import io.xpipe.app.util.TerminalHelper;
|
||||
import io.xpipe.core.process.ShellControl;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
@ -51,7 +51,7 @@ public abstract class MultiExecuteAction implements BranchAction {
|
|||
model.withShell(
|
||||
pc -> {
|
||||
for (BrowserEntry entry : entries) {
|
||||
var cmd = ScriptHelper.createDetachCommand(pc, createCommand(pc, model, entry));
|
||||
var cmd = ApplicationHelper.createDetachCommand(pc, createCommand(pc, model, entry));
|
||||
pc.command(cmd)
|
||||
.withWorkingDirectory(model.getCurrentDirectory()
|
||||
.getPath())
|
||||
|
|
|
@ -555,7 +555,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
|||
.resolve("wezterm-gui").toString())
|
||||
.add("start")
|
||||
.addFile(configuration.getScriptFile()).buildString(LocalShell.getShell());
|
||||
c = ScriptHelper.createDetachCommand(LocalShell.getShell(), c);
|
||||
c = ApplicationHelper.createDetachCommand(LocalShell.getShell(), c);
|
||||
LocalShell.getShell().executeSimpleCommand(c);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -67,7 +67,7 @@ public class TroubleshootComp extends Comp<CompStructure<?>> {
|
|||
XPipeInstallation.getDaemonDebugScriptPath(sc.getOsType()));
|
||||
if (sc.getOsType().equals(OsType.WINDOWS)) {
|
||||
sc.executeSimpleCommand(
|
||||
ScriptHelper.createDetachCommand(sc, "\"" + script + "\""));
|
||||
ApplicationHelper.createDetachCommand(sc, "\"" + script + "\""));
|
||||
} else {
|
||||
TerminalHelper.open("XPipe Debug", LocalShell.getShell().command("\"" + script + "\""));
|
||||
}
|
||||
|
|
|
@ -3,7 +3,9 @@ package io.xpipe.app.util;
|
|||
import io.xpipe.app.issue.ErrorEvent;
|
||||
import io.xpipe.app.issue.TrackEvent;
|
||||
import io.xpipe.app.storage.DataStoreEntry;
|
||||
import io.xpipe.core.process.OsType;
|
||||
import io.xpipe.core.process.ShellControl;
|
||||
import io.xpipe.core.process.ShellDialects;
|
||||
import io.xpipe.core.util.FailableSupplier;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -24,7 +26,7 @@ public class ApplicationHelper {
|
|||
|
||||
public static void executeLocalApplication(Function<ShellControl, String> s, boolean detach) throws Exception {
|
||||
try (var sc = LocalShell.getShell().start()) {
|
||||
var cmd = detach ? ScriptHelper.createDetachCommand(sc, s.apply(sc)) : s.apply(sc);
|
||||
var cmd = detach ? createDetachCommand(sc, s.apply(sc)) : s.apply(sc);
|
||||
TrackEvent.withDebug("proc", "Executing local application")
|
||||
.tag("command", cmd)
|
||||
.handle();
|
||||
|
@ -34,6 +36,21 @@ public class ApplicationHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public static String createDetachCommand(ShellControl pc, String command) {
|
||||
if (pc.getShellDialect().equals(ShellDialects.POWERSHELL)) {
|
||||
var script = ScriptHelper.createExecScript(pc, command);
|
||||
return String.format(
|
||||
"Start-Process -FilePath powershell.exe -ArgumentList \"-NoProfile\", \"-File\", %s",
|
||||
ShellDialects.POWERSHELL.fileArgument(script));
|
||||
}
|
||||
|
||||
if (pc.getOsType().equals(OsType.WINDOWS)) {
|
||||
return "start \"\" " + command;
|
||||
} else {
|
||||
return "nohup " + command + " </dev/null &>/dev/null & disown";
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isInPath(ShellControl processControl, String executable) throws Exception {
|
||||
return processControl.executeSimpleBooleanCommand(
|
||||
processControl.getShellDialect().getWhichCommand(executable));
|
||||
|
|
|
@ -11,21 +11,6 @@ import java.util.Random;
|
|||
|
||||
public class ScriptHelper {
|
||||
|
||||
public static String createDetachCommand(ShellControl pc, String command) {
|
||||
if (pc.getShellDialect().equals(ShellDialects.POWERSHELL)) {
|
||||
var script = ScriptHelper.createExecScript(pc, command);
|
||||
return String.format(
|
||||
"Start-Process -WindowStyle Minimized -FilePath powershell.exe -ArgumentList \"-NoProfile\", \"-File\", %s",
|
||||
ShellDialects.POWERSHELL.fileArgument(script));
|
||||
}
|
||||
|
||||
if (pc.getOsType().equals(OsType.WINDOWS)) {
|
||||
return "start \"\" /MIN " + command;
|
||||
} else {
|
||||
return "nohup " + command + " </dev/null &>/dev/null & disown";
|
||||
}
|
||||
}
|
||||
|
||||
public static int getScriptId() {
|
||||
// A deterministic approach can cause permission problems when two different users execute the same command on a
|
||||
// system
|
||||
|
|
Loading…
Reference in a new issue