From bce2d1ea5c709fc6e60de95515b42522ce63e452 Mon Sep 17 00:00:00 2001 From: Glavo Date: Sun, 28 Aug 2022 21:05:43 +0800 Subject: [PATCH] Revert ExitWaiter (#1668) --- .../org/jackhuang/hmcl/launch/ExitWaiter.java | 47 +++++++------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/ExitWaiter.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/ExitWaiter.java index 086b70812..7ae18c285 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/ExitWaiter.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/ExitWaiter.java @@ -26,7 +26,9 @@ import org.jackhuang.hmcl.util.StringUtils; import org.jackhuang.hmcl.util.platform.ManagedProcess; import java.util.Collection; +import java.util.List; import java.util.function.BiConsumer; +import java.util.stream.Collectors; /** * @@ -58,38 +60,23 @@ final class ExitWaiter implements Runnable { for (Thread thread : joins) thread.join(); - ProcessListener.ExitType exitType = null; - for (String line : process.getLines()) { - Log4jLevel level = Log4jLevel.guessLevel(line); - if (Log4jLevel.isError(level)) { - // LaunchWrapper will catch the exception logged and will exit normally. - if (exitCode != 0 && StringUtils.containsOne(line, - "Could not create the Java Virtual Machine.", - "Error occurred during initialization of VM", - "A fatal exception has occurred. Program will exit.")) { - EventBus.EVENT_BUS.fireEvent(new JVMLaunchFailedEvent(this, process)); - exitType = ProcessListener.ExitType.JVM_ERROR; - break; - } + List errorLines = process.getLines().stream() + .filter(Log4jLevel::guessLogLineError).collect(Collectors.toList()); + ProcessListener.ExitType exitType; - if (exitCode != 0 || StringUtils.containsOne(line, "Unable to launch")) { - EventBus.EVENT_BUS.fireEvent(new ProcessExitedAbnormallyEvent(this, process)); - exitType = ProcessListener.ExitType.APPLICATION_ERROR; - break; - } - } - - 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) + // LaunchWrapper will catch the exception logged and will exit normally. + if (exitCode != 0 && StringUtils.containsOne(errorLines, + "Could not create the Java Virtual Machine.", + "Error occurred during initialization of VM", + "A fatal exception has occurred. Program will exit.")) { + EventBus.EVENT_BUS.fireEvent(new JVMLaunchFailedEvent(this, process)); + exitType = ProcessListener.ExitType.JVM_ERROR; + } else if (exitCode != 0 || StringUtils.containsOne(errorLines, "Unable to launch")) { + EventBus.EVENT_BUS.fireEvent(new ProcessExitedAbnormallyEvent(this, process)); + exitType = ProcessListener.ExitType.APPLICATION_ERROR; + } else { exitType = ProcessListener.ExitType.NORMAL; + } EventBus.EVENT_BUS.fireEvent(new ProcessStoppedEvent(this, process));