xpipe/app/src/main/java/io/xpipe/app/core/check/AppShellCheck.java
crschnick 3e7fbe89ac Merge branch prefs into master
The changes have been squashed as the commit history and messages were not very carefully crafted. There isn't that much value in preserving random commit messages.

Also due to diverging branches, rebasing or merging it was difficult.
2024-02-28 07:36:31 +00:00

52 lines
2 KiB
Java

package io.xpipe.app.core.check;
import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.app.util.LocalShell;
import io.xpipe.core.process.ProcessControlProvider;
import io.xpipe.core.process.ProcessOutputException;
import java.util.Optional;
public class AppShellCheck {
public static void check() {
var err = selfTestErrorCheck();
if (err.isPresent()) {
var msg =
"""
Shell self-test failed for %s:
%s
This indicates that something is seriously wrong and certain shell functionality will not work as expected.
The most likely causes are:
- On Windows, an AntiVirus program might block required programs and commands
- The system shell is restricted or blocked
- The operating system is not supported
You can reach out to us if you want to properly diagnose the cause individually and hopefully fix it.
"""
.formatted(
ProcessControlProvider.get()
.getEffectiveLocalDialect()
.getDisplayName(),
err.get());
ErrorEvent.fromThrowable(new IllegalStateException(msg)).handle();
}
}
private static Optional<String> selfTestErrorCheck() {
try (var command = LocalShell.getShell().command("echo test").complex().start()) {
var out = command.readStdoutOrThrow();
if (!out.equals("test")) {
return Optional.of("Expected \"test\", got \"" + out + "\"");
}
} catch (ProcessOutputException ex) {
return Optional.ofNullable(ex.getOutput());
} catch (Throwable t) {
return Optional.ofNullable(t.getMessage());
}
return Optional.empty();
}
}