Various fixes

This commit is contained in:
crschnick
2026-09-27 14:11:16 +00:00
parent 309757210c
commit 37ff49cdf2
10 changed files with 21 additions and 15 deletions
@@ -29,7 +29,7 @@ public class AppLocalTemp {
ErrorEventFactory.fromThrowable(new IOException("Invalid file type for " + temp))
.term()
.handle();
return null;
return temp;
}
try {
@@ -44,7 +44,7 @@ public class AppLocalTemp {
return temp;
} catch (Exception e) {
ErrorEventFactory.fromThrowable(e).description("Unable to set temp dir permissions " + temp).term().handle();
return null;
return temp;
}
} else {
var temp =
@@ -14,14 +14,14 @@ import java.util.stream.Collectors;
public class ExternalApplicationHelper {
public static String replaceVariableArgument(String format, String variable, String value) {
public static String replaceVariableArgument(String format, String variable, String value, boolean quoteLiteral) {
// Support for legacy variables that were not upper case
variable = variable.toUpperCase(Locale.ROOT);
format = format.replace("$" + variable.toLowerCase(Locale.ROOT), "$" + variable.toUpperCase(Locale.ROOT));
var fileString = LocalShell.getDialect().fileArgument(value);
var substitute = quoteLiteral ? LocalShell.getDialect().literalArgument(value) : value;
// Check if the variable is already quoted
var quotedFormatString = format.contains("\"$" + variable + "\"");
return format.replace(quotedFormatString ? ("\"$" + variable + "\"") : ("$" + variable), fileString);
return format.replace(quotedFormatString ? ("\"$" + variable + "\"") : ("$" + variable), substitute);
}
public static void startAsync(String raw) throws Exception {
@@ -503,7 +503,7 @@ public interface ExternalEditorType extends PrefsChoiceValue {
var format =
customCommand.toLowerCase(Locale.ROOT).contains("$file") ? customCommand : customCommand + " $FILE";
var command = CommandBuilder.of()
.add(ExternalApplicationHelper.replaceVariableArgument(format, "FILE", file.toString()));
.add(ExternalApplicationHelper.replaceVariableArgument(format, "FILE", file.toString(), true));
if (AppPrefs.get().customEditorCommandInTerminal().get()) {
TerminalLaunch.builder()
.title(file.toString())
@@ -35,7 +35,7 @@ public class ScriptHelper {
ShellDialect type, ShellControl processControl, String content, boolean log) {
content = type.prepareScriptContent(processControl, content);
var fileName = "xpipe-" + getScriptHash(processControl, content);
var temp = processControl.getSubTemporaryDirectory();
var temp = ShellTemp.getSubDirectory(processControl, "shell");
var file = temp.join(fileName + "." + type.getScriptFileEnding());
return createExecScriptRaw(processControl, file, content, log);
}
@@ -99,6 +99,7 @@ public class ShellTemp {
if (newSession) {
clearTemp(sc);
try {
sc.view().mkdir(subTemp);
sc.view().touch(sessionFile);
} catch (ProcessOutputException pex) {
if (!pex.getOutput().toLowerCase().contains("no space left on device")) {
@@ -111,9 +112,13 @@ public class ShellTemp {
}
private static void clearTemp(ShellControl sc) throws Exception {
var subTemp = getUserSpecificTempDataDirectoryPath(sc);
if (sc.view().directoryExists(subTemp)) {
clearFiles(sc, subTemp);
var toClean = getUserSpecificTempDataDirectoryPath(sc);
// Only clear local shell dir to not interfere with AppLocalTemp too much
if (sc.isLocal()) {
toClean = toClean.join("shell");
}
if (sc.view().directoryExists(toClean)) {
clearFiles(sc, toClean);
}
}
@@ -50,7 +50,8 @@ public class CustomRdpClient implements ExternalApplicationType, ExternalRdpClie
format,
"FILE",
writeRdpConfigFile(configuration.getTitle(), configuration.getConfig())
.toString())));
.toString(),
true)));
}
@Override
@@ -44,7 +44,7 @@ public class CustomSpiceClient implements ExternalSpiceClient {
var format = command.toLowerCase(Locale.ROOT).contains("$file") ? command : command + " $FILE";
var toExecute = ExternalApplicationHelper.replaceVariableArgument(
format, "ADDRESS", configuration.getFile().toString());
format, "FILE", configuration.getFile().toString(), true);
ExternalApplicationHelper.startAsync(CommandBuilder.of().add(toExecute));
}
@@ -37,7 +37,7 @@ public class CustomTerminalType implements ExternalApplicationType, ExternalTerm
var format = custom.toLowerCase(Locale.ROOT).contains("$cmd") ? custom : custom + " $CMD";
try (var sc = LocalShell.getShell()) {
var toExecute = ExternalApplicationHelper.replaceVariableArgument(
format, "CMD", configuration.single().getScriptFile().toString());
format, "CMD", configuration.single().getScriptFile().toString(), false);
// We can't be sure whether the command is blocking or not, so always make it not blocking
if (sc.getOsType() == OsType.WINDOWS) {
toExecute = "start \"" + configuration.getCleanTitle() + "\" " + toExecute;
@@ -44,7 +44,7 @@ public class CustomVncClient implements ExternalVncClient {
var address = configuration.getHost() + ":" + configuration.getPort();
var format = command.toLowerCase(Locale.ROOT).contains("$address") ? command : command + " $ADDRESS";
var toExecute = ExternalApplicationHelper.replaceVariableArgument(format, "ADDRESS", address);
var toExecute = ExternalApplicationHelper.replaceVariableArgument(format, "ADDRESS", address, true);
ExternalApplicationHelper.startAsync(CommandBuilder.of().add(toExecute));
}
@@ -148,7 +148,7 @@ public interface ServiceProtocolType {
var format = commandTemplate.toLowerCase(Locale.ROOT).contains("$port")
? commandTemplate
: commandTemplate + " localhost:$PORT";
var toExecute = ExternalApplicationHelper.replaceVariableArgument(format, "PORT", port);
var toExecute = ExternalApplicationHelper.replaceVariableArgument(format, "PORT", port, false);
// We can't be sure whether the command is blocking or not, so always make it not blocking
ExternalApplicationHelper.startAsync(toExecute);
}