chore(event): 移除过时且远古的进程退出事件,并将下载速度事件与全局 EventBus 解耦 (#7063)

This commit is contained in:
鱼前三百 authored and GitHub committed 2026-10-25 16:40:47 +08:00
1 parent 0c40dcdeed
commit bc27eda220
5 files changed
+1 -170

No files matched your search

@@ -1,56 +0,0 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2020 huangyuhui <[email protected]> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.jackhuang.hmcl.event;
import org.jackhuang.hmcl.util.ToStringBuilder;
import org.jackhuang.hmcl.util.platform.ManagedProcess;
/**
* This event gets fired when we launch the JVM and it got crashed.
* <br>
* This event is fired on the {@link org.jackhuang.hmcl.event.EventBus#EVENT_BUS}
*
* @author huangyuhui
*/
public class JVMLaunchFailedEvent extends Event {
private final ManagedProcess process;
/**
* Constructor.
*
* @param source {@link org.jackhuang.hmcl.launch.ExitWaiter}
* @param process the crashed process.
*/
public JVMLaunchFailedEvent(Object source, ManagedProcess process) {
super(source);
this.process = process;
}
public ManagedProcess getProcess() {
return process;
}
@Override
public String toString() {
return new ToStringBuilder(this)
.append("source", source)
.append("process", process)
.toString();
}
}
@@ -1,56 +0,0 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2020 huangyuhui <[email protected]> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.jackhuang.hmcl.event;
import org.jackhuang.hmcl.util.ToStringBuilder;
import org.jackhuang.hmcl.util.platform.ManagedProcess;
/**
* This event gets fired when a JavaProcess exited abnormally and the exit code is not zero.
*
* This event is fired on the {@link org.jackhuang.hmcl.event.EventBus#EVENT_BUS}
*
* @author huangyuhui
*/
public final class ProcessExitedAbnormallyEvent extends Event {
private final ManagedProcess process;
/**
* Constructor.
*
* @param source {@link org.jackhuang.hmcl.launch.ExitWaiter}
* @param process The process that exited abnormally.
*/
public ProcessExitedAbnormallyEvent(Object source, ManagedProcess process) {
super(source);
this.process = process;
}
public ManagedProcess getProcess() {
return process;
}
@Override
public String toString() {
return new ToStringBuilder(this)
.append("source", source)
.append("process", process)
.toString();
}
}
@@ -1,47 +0,0 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2020 huangyuhui <[email protected]> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.jackhuang.hmcl.event;
import org.jackhuang.hmcl.util.platform.ManagedProcess;
/**
* This event gets fired when minecraft process exited successfully and the exit code is 0.
* <br>
* This event is fired on the {@link org.jackhuang.hmcl.event.EventBus#EVENT_BUS}
*
* @author huangyuhui
*/
public class ProcessStoppedEvent extends Event {
private final ManagedProcess process;
/**
* Constructor.
*
* @param source {@link org.jackhuang.hmcl.launch.ExitWaiter}
* @param process minecraft process
*/
public ProcessStoppedEvent(Object source, ManagedProcess process) {
super(source);
this.process = process;
}
public ManagedProcess getProcess() {
return process;
}
}
@@ -17,10 +17,6 @@
*/
package org.jackhuang.hmcl.launch;
import org.jackhuang.hmcl.event.EventBus;
import org.jackhuang.hmcl.event.JVMLaunchFailedEvent;
import org.jackhuang.hmcl.event.ProcessExitedAbnormallyEvent;
import org.jackhuang.hmcl.event.ProcessStoppedEvent;
import org.jackhuang.hmcl.util.Log4jLevel;
import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.platform.ManagedProcess;
@@ -67,13 +63,10 @@ final class ExitWaiter implements Runnable {
"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,
"Crash report saved to", "Could not save crash report to", "This crash report has been saved to:",
"Unable to launch", "An exception was thrown, the game will display an error screen and halt.")) {
EventBus.EVENT_BUS.fireEvent(new ProcessExitedAbnormallyEvent(this, process));
if (exitCode == 137 && OperatingSystem.CURRENT_OS.isLinuxOrBSD()) {
exitType = ProcessListener.ExitType.SIGKILL;
} else {
@@ -83,8 +76,6 @@ final class ExitWaiter implements Runnable {
exitType = ProcessListener.ExitType.NORMAL;
}
EventBus.EVENT_BUS.fireEvent(new ProcessStoppedEvent(this, process));
watcher.accept(exitCode, exitType);
} catch (InterruptedException e) {
watcher.accept(1, ProcessListener.ExitType.INTERRUPTED);
@@ -21,7 +21,6 @@ import org.glavo.url.WebURL;
import org.jackhuang.hmcl.download.DownloadCandidate;
import org.jackhuang.hmcl.download.DownloadCandidates;
import org.jackhuang.hmcl.event.Event;
import org.jackhuang.hmcl.event.EventBus;
import org.jackhuang.hmcl.event.EventManager;
import org.jackhuang.hmcl.util.*;
import org.jackhuang.hmcl.util.io.*;
@@ -587,7 +586,7 @@ public abstract class FetchTask<T extends @UnknownNullability Object> extends Ta
private static final Timer timer = new Timer("DownloadSpeedRecorder", true);
private static final AtomicLong downloadSpeed = new AtomicLong(0L);
public static final EventManager<SpeedEvent> SPEED_EVENT = EventBus.EVENT_BUS.channel(SpeedEvent.class);
public static final EventManager<SpeedEvent> SPEED_EVENT = new EventManager<>();
static {
timer.schedule(new TimerTask() {