Revert ExitWaiter (#1668)

This commit is contained in:
Glavo
2022-08-28 21:05:43 +08:00
committed by GitHub
parent cbc1e26b6f
commit bce2d1ea5c

View File

@@ -26,7 +26,9 @@ import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.platform.ManagedProcess; import org.jackhuang.hmcl.util.platform.ManagedProcess;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.stream.Collectors;
/** /**
* *
@@ -58,38 +60,23 @@ final class ExitWaiter implements Runnable {
for (Thread thread : joins) for (Thread thread : joins)
thread.join(); thread.join();
ProcessListener.ExitType exitType = null; List<String> errorLines = process.getLines().stream()
for (String line : process.getLines()) { .filter(Log4jLevel::guessLogLineError).collect(Collectors.toList());
Log4jLevel level = Log4jLevel.guessLevel(line); ProcessListener.ExitType exitType;
if (Log4jLevel.isError(level)) {
// LaunchWrapper will catch the exception logged and will exit normally. // LaunchWrapper will catch the exception logged and will exit normally.
if (exitCode != 0 && StringUtils.containsOne(line, if (exitCode != 0 && StringUtils.containsOne(errorLines,
"Could not create the Java Virtual Machine.", "Could not create the Java Virtual Machine.",
"Error occurred during initialization of VM", "Error occurred during initialization of VM",
"A fatal exception has occurred. Program will exit.")) { "A fatal exception has occurred. Program will exit.")) {
EventBus.EVENT_BUS.fireEvent(new JVMLaunchFailedEvent(this, process)); EventBus.EVENT_BUS.fireEvent(new JVMLaunchFailedEvent(this, process));
exitType = ProcessListener.ExitType.JVM_ERROR; exitType = ProcessListener.ExitType.JVM_ERROR;
break; } else if (exitCode != 0 || StringUtils.containsOne(errorLines, "Unable to launch")) {
}
if (exitCode != 0 || StringUtils.containsOne(line, "Unable to launch")) {
EventBus.EVENT_BUS.fireEvent(new ProcessExitedAbnormallyEvent(this, process)); EventBus.EVENT_BUS.fireEvent(new ProcessExitedAbnormallyEvent(this, process));
exitType = ProcessListener.ExitType.APPLICATION_ERROR; exitType = ProcessListener.ExitType.APPLICATION_ERROR;
break; } else {
}
}
if (level == Log4jLevel.WARN) {
if (StringUtils.containsOne(line, "Failed to create window")) {
EventBus.EVENT_BUS.fireEvent(new ProcessExitedAbnormallyEvent(this, process));
exitType = ProcessListener.ExitType.APPLICATION_ERROR;
break;
}
}
}
if (exitType == null)
exitType = ProcessListener.ExitType.NORMAL; exitType = ProcessListener.ExitType.NORMAL;
}
EventBus.EVENT_BUS.fireEvent(new ProcessStoppedEvent(this, process)); EventBus.EVENT_BUS.fireEvent(new ProcessStoppedEvent(this, process));