From 97079fb58d6f4b52d7c23775c0561c3bcf96d3f8 Mon Sep 17 00:00:00 2001 From: crschnick Date: Mon, 27 Mar 2023 10:49:25 +0000 Subject: [PATCH] Shell encoding fixes [release] --- .../xpipe/app/issue/SentryErrorHandler.java | 9 ++++--- .../xpipe/app/prefs/ExternalEditorType.java | 15 ++++++++--- .../xpipe/app/prefs/ExternalTerminalType.java | 2 +- .../java/io/xpipe/app/util/ScriptHelper.java | 10 +++++--- .../io/xpipe/core/process/ShellControl.java | 25 +++++++++++++------ .../io/xpipe/core/process/ShellDialect.java | 4 +-- version | 2 +- 7 files changed, 44 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/issue/SentryErrorHandler.java b/app/src/main/java/io/xpipe/app/issue/SentryErrorHandler.java index 183d11cc..3bda2198 100644 --- a/app/src/main/java/io/xpipe/app/issue/SentryErrorHandler.java +++ b/app/src/main/java/io/xpipe/app/issue/SentryErrorHandler.java @@ -27,10 +27,6 @@ public class SentryErrorHandler { options.setProguardUuid(AppProperties.get().getBuildUuid().toString()); options.setTag("os", System.getProperty("os.name")); }); - - var user = new User(); - user.setId(AppCache.getCachedUserId().toString()); - Sentry.setUser(user); } Thread.setDefaultUncaughtExceptionHandler((thread, ex) -> { @@ -95,6 +91,11 @@ public class SentryErrorHandler { s.setTag("message", ee.getDescription()); } } + + + var user = new User(); + user.setId(AppCache.getCachedUserId().toString()); + s.setUser(user); } private static Breadcrumb toBreadcrumb(TrackEvent te) { diff --git a/app/src/main/java/io/xpipe/app/prefs/ExternalEditorType.java b/app/src/main/java/io/xpipe/app/prefs/ExternalEditorType.java index b4910733..8b18b7ce 100644 --- a/app/src/main/java/io/xpipe/app/prefs/ExternalEditorType.java +++ b/app/src/main/java/io/xpipe/app/prefs/ExternalEditorType.java @@ -21,7 +21,7 @@ public interface ExternalEditorType extends PrefsChoiceValue { } }; - public static final ExternalEditorType VSCODE = new WindowsFullPathType("app.vscode") { + public static final ExternalEditorType VSCODE_WINDOWS = new WindowsFullPathType("app.vscode") { @Override protected Optional determinePath() { @@ -31,6 +31,11 @@ public interface ExternalEditorType extends PrefsChoiceValue { .resolve("bin") .resolve("code.cmd")); } + + @Override + public boolean detach() { + return false; + } }; public static final ExternalEditorType NOTEPADPLUSPLUS_WINDOWS = new WindowsFullPathType("app.notepad++") { @@ -129,6 +134,10 @@ public interface ExternalEditorType extends PrefsChoiceValue { super(id); } + public boolean detach() { + return true; + } + @Override public void launch(Path file) throws Exception { var path = determinePath(); @@ -139,11 +148,11 @@ public interface ExternalEditorType extends PrefsChoiceValue { ApplicationHelper.executeLocalApplication( sc -> String.format( "%s %s", sc.getShellDialect().fileArgument(path.get().toString()), sc.getShellDialect().fileArgument(file.toString())), - true); + detach()); } } - public static final List WINDOWS_EDITORS = List.of(VSCODE, NOTEPADPLUSPLUS_WINDOWS, NOTEPAD); + public static final List WINDOWS_EDITORS = List.of(VSCODE_WINDOWS, NOTEPADPLUSPLUS_WINDOWS, NOTEPAD); public static final List LINUX_EDITORS = List.of(VSCODE_LINUX, KATE, GEDIT, PLUMA, LEAFPAD, MOUSEPAD); public static final List MACOS_EDITORS = List.of(VSCODE_MACOS, SUBLIME_MACOS, TEXT_EDIT); diff --git a/app/src/main/java/io/xpipe/app/prefs/ExternalTerminalType.java b/app/src/main/java/io/xpipe/app/prefs/ExternalTerminalType.java index 3f4e0d81..4f4b2b48 100644 --- a/app/src/main/java/io/xpipe/app/prefs/ExternalTerminalType.java +++ b/app/src/main/java/io/xpipe/app/prefs/ExternalTerminalType.java @@ -152,7 +152,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue { @Override public void launch(String name, String command) throws Exception { try (ShellControl pc = LocalStore.getShell()) { - var suffix = command.equals(pc.getShellDialect().getNormalOpenCommand()) + var suffix = command.equals(pc.getShellDialect().getOpenCommand()) ? "\"\"" : "\"" + command.replaceAll("\"", "\\\\\"") + "\""; var cmd = "osascript -e 'tell app \"" + "Terminal" + "\" to do script " + suffix + "'"; diff --git a/app/src/main/java/io/xpipe/app/util/ScriptHelper.java b/app/src/main/java/io/xpipe/app/util/ScriptHelper.java index fde6b5c9..89b17aa8 100644 --- a/app/src/main/java/io/xpipe/app/util/ScriptHelper.java +++ b/app/src/main/java/io/xpipe/app/util/ScriptHelper.java @@ -52,13 +52,15 @@ public class ScriptHelper { public static String constructInitFile( ShellControl processControl, List init, String toExecuteInShell) { ShellDialect t = processControl.getShellDialect(); - if (init.size() == 0 && toExecuteInShell == null) { - return null; - } + + // We always want to generate and init file +// if (init.size() == 0 && toExecuteInShell == null) { +// return null; +// } if (init.size() == 0) { // Check for special case of the command to be executed just being another shell script - if (toExecuteInShell.endsWith(".sh") || toExecuteInShell.endsWith(".bat")) { + if (toExecuteInShell != null && (toExecuteInShell.endsWith(".sh") || toExecuteInShell.endsWith(".bat"))) { return toExecuteInShell; } } diff --git a/core/src/main/java/io/xpipe/core/process/ShellControl.java b/core/src/main/java/io/xpipe/core/process/ShellControl.java index 39fbc2ec..f15d2015 100644 --- a/core/src/main/java/io/xpipe/core/process/ShellControl.java +++ b/core/src/main/java/io/xpipe/core/process/ShellControl.java @@ -10,6 +10,7 @@ import java.util.Arrays; import java.util.List; import java.util.concurrent.Semaphore; import java.util.function.Consumer; +import java.util.function.Function; public interface ShellControl extends ProcessControl { @@ -72,21 +73,28 @@ public interface ShellControl extends ProcessControl { SecretValue getElevationPassword(); default ShellControl subShell(@NonNull ShellDialect type) { - return subShell(p -> type.getNormalOpenCommand(), (shellProcessControl, s) -> { - return s == null ? type.getNormalOpenCommand() : type.executeCommandWithShell(s); - }) - .elevationPassword(getElevationPassword()); + return subShell(p -> type.getOpenCommand(), null).elevationPassword(getElevationPassword()); } - default ShellControl subShell(@NonNull List command) { - return subShell( - shellProcessControl -> shellProcessControl.getShellDialect().flatten(command), null); + default ShellControl identicalSubShell() { + return subShell(p -> p.getShellDialect().getOpenCommand(), null) + .elevationPassword(getElevationPassword()); } default ShellControl subShell(@NonNull String command) { return subShell(processControl -> command, null); } + default T enforceDialect(@NonNull ShellDialect type, Function sc) throws Exception { + if (isRunning() && getShellDialect().equals(type)) { + return sc.apply(this); + } else { + try (var sub = subShell(type).start()) { + return sc.apply(sub); + } + } + } + ShellControl subShell( FailableFunction command, FailableBiFunction terminalCommand); @@ -110,7 +118,8 @@ public interface ShellControl extends ProcessControl { } default CommandControl command(List command) { - return command(shellProcessControl -> shellProcessControl.getShellDialect().flatten(command)); + return command( + shellProcessControl -> shellProcessControl.getShellDialect().flatten(command)); } void exitAndWait() throws IOException; diff --git a/core/src/main/java/io/xpipe/core/process/ShellDialect.java b/core/src/main/java/io/xpipe/core/process/ShellDialect.java index e3107723..9e0423f8 100644 --- a/core/src/main/java/io/xpipe/core/process/ShellDialect.java +++ b/core/src/main/java/io/xpipe/core/process/ShellDialect.java @@ -91,9 +91,9 @@ public interface ShellDialect { return getPrintVariableCommand(name); } - String getNormalOpenCommand(); + String getOpenCommand(); - String prepareInitFileOpenCommand(ShellControl parent, String file); + String prepareTerminalInitFileOpenCommand(ShellControl parent, String file) throws Exception; String runScript(String file); diff --git a/version b/version index 3c7d01c2..dc2fb792 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.5.20 \ No newline at end of file +0.5.21 \ No newline at end of file