Rework env variables for cli

This commit is contained in:
crschnick
2026-09-08 13:47:40 +00:00
parent 8bf97b7ea9
commit 1b6b714a44
4 changed files with 43 additions and 13 deletions
@@ -17,6 +17,9 @@ public class BeaconServer {
InetSocketAddress adress = new InetSocketAddress(local, port);
socket.connect(adress, 5000);
} catch (Exception e) {
if (AppProperties.get().isDebugCli()) {
e.printStackTrace();
}
return false;
}
@@ -217,6 +217,7 @@ public class AppProperties {
beaconLockFile = beaconAuthFile.getParent().resolve("lock");
clearLeftoverAuthFile();
debugCli = Optional.ofNullable(System.getProperty(AppNames.propertyName("debugCli")))
.or(() -> Optional.ofNullable(System.getenv("XPIPE_DEBUG")))
.map(Boolean::parseBoolean)
.orElse(false);
}
@@ -1,6 +1,7 @@
package io.xpipe.app.terminal;
import io.xpipe.app.core.AppInstallation;
import io.xpipe.app.core.AppLogs;
import io.xpipe.app.core.AppProperties;
import io.xpipe.app.issue.ErrorEventFactory;
import io.xpipe.app.prefs.AppPrefs;
@@ -61,10 +62,13 @@ public class TerminalPaneConfiguration {
boolean enableLogging,
boolean alwaysPromptRestart)
throws Exception {
var debugMode = AppProperties.get().isDeveloperMode()
&& AppLogs.get().isWriteToSysout();
if (!enableLogging || !AppPrefs.get().enableTerminalLogging().get()) {
var sc = LocalShell.getShell();
var register = TerminalLauncher.getTerminalRegisterCommand(request, sc);
var launcherScript =
var launcherScript = (debugMode ? sc.getShellDialect().getSetEnvironmentVariableCommand("XPIPE_DEBUG", "true") + "\n" : "") +
register + "\n" + sc.getShellDialect().terminalLauncherScript(request, title, alwaysPromptRestart);
var config = new TerminalPaneConfiguration(request, title, paneIndex, launcherScript, sc.getShellDialect());
return config;
@@ -85,6 +89,7 @@ public class TerminalPaneConfiguration {
sc,
ShellDialects.POWERSHELL.terminalLauncherScript(request, title, alwaysPromptRestart));
var content = """
%s
%s
echo 'Session logging is active, output file is "sessions\\%s"'
Start-Transcript -Force -LiteralPath "%s" | Out-Null
@@ -92,6 +97,7 @@ public class TerminalPaneConfiguration {
Stop-Transcript | Out-Null
echo 'Session logging is finished, output file is "sessions\\%s"'
""".formatted(
debugMode ? ShellDialects.POWERSHELL.getSetEnvironmentVariableCommand("XPIPE_DEBUG", "true") : "",
TerminalLauncher.getTerminalRegisterCommand(
request, LocalShell.getLocalPowershell().orElseThrow()),
logFile.getFileName(),
@@ -130,12 +136,14 @@ public class TerminalPaneConfiguration {
? "script -e -q '%s' \"%s\"".formatted(logFile, command)
: "script --quiet --command '%s' \"%s\"".formatted(command, logFile);
var content = """
%s
%s
echo "Session logging is active, output file is sessions/%s"
%s
echo "Session logging is finished, output file is sessions/%s"
cat "%s" | "%s" terminal-clean > "%s.txt"
""".formatted(
debugMode ? ShellDialects.POWERSHELL.getSetEnvironmentVariableCommand("XPIPE_DEBUG", "true") : "",
TerminalLauncher.getTerminalRegisterCommand(request, sc),
logFile.getFileName(),
scriptCommand,
@@ -5,10 +5,38 @@ import io.xpipe.app.issue.TrackEvent;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
public class LocalExec {
public static void prepareLocalProcessEnvironment(Map<String, String> env) {
// https://bugs.openjdk.org/browse/JDK-8360500
env.remove("_JPACKAGE_LAUNCHER");
// Remove debug mode vars
env.remove("JAVA_EXEC");
env.remove("CDS_JVM_OPTS");
// Remove any custom java vars
env.remove("_JAVA_OPTIONS");
env.remove("JAVA_TOOL_OPTIONS");
env.remove("JDK_JAVA_OPTIONS");
// Remove dev vars
env.remove("XPIPE_MAPPING");
// Ensure that electron applications on Linux use wayland features if possible
// https://github.com/microsoft/vscode/issues/207033#issuecomment-2167500295
if (OsType.ofLocal() == OsType.LINUX && !AppSystemInfo.ofLinux().isVirtualMachine()) {
env.put("ELECTRON_OZONE_PLATFORM_HINT", "auto");
}
// Add proxy vars
var proxyMap = HttpProxy.getEnvironmentVariables();
env.putAll(proxyMap);
}
public static Process executeAsync(String... command) {
var list = Arrays.stream(command).filter(s -> s != null).toList();
try {
@@ -22,12 +50,7 @@ public class LocalExec {
pb.directory(AppSystemInfo.ofCurrent().getUserHome().toFile());
var env = pb.environment();
// https://bugs.openjdk.org/browse/JDK-8360500
env.remove("_JPACKAGE_LAUNCHER");
env.remove("_JAVA_OPTIONS");
env.remove("JAVA_TOOL_OPTIONS");
env.remove("JDK_JAVA_OPTIONS");
prepareLocalProcessEnvironment(env);
return pb.start();
} catch (Exception ex) {
@@ -49,12 +72,7 @@ public class LocalExec {
pb.directory(AppSystemInfo.ofCurrent().getUserHome().toFile());
var env = pb.environment();
// https://bugs.openjdk.org/browse/JDK-8360500
env.remove("_JPACKAGE_LAUNCHER");
env.remove("_JAVA_OPTIONS");
env.remove("JAVA_TOOL_OPTIONS");
env.remove("JDK_JAVA_OPTIONS");
prepareLocalProcessEnvironment(env);
var process = pb.start();
var out = process.getInputStream().readAllBytes();