mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-11 12:56:53 -04:00
Shutdown Now to prevent NPE when task executed after app closed
This commit is contained in:
parent
2575f10497
commit
a9261b759b
@ -171,6 +171,8 @@ public final class Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void showUpdate() {
|
public static void showUpdate() {
|
||||||
|
if (stage == null) // shut down
|
||||||
|
return;
|
||||||
getLeftPaneController().showUpdate();
|
getLeftPaneController().showUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,8 @@ import org.jackhuang.hmcl.Launcher;
|
|||||||
import org.jackhuang.hmcl.event.Event;
|
import org.jackhuang.hmcl.event.Event;
|
||||||
import org.jackhuang.hmcl.event.EventBus;
|
import org.jackhuang.hmcl.event.EventBus;
|
||||||
import org.jackhuang.hmcl.event.OutOfDateEvent;
|
import org.jackhuang.hmcl.event.OutOfDateEvent;
|
||||||
|
import org.jackhuang.hmcl.task.GetTask;
|
||||||
|
import org.jackhuang.hmcl.task.Task;
|
||||||
import org.jackhuang.hmcl.task.TaskResult;
|
import org.jackhuang.hmcl.task.TaskResult;
|
||||||
import org.jackhuang.hmcl.ui.construct.MessageBox;
|
import org.jackhuang.hmcl.ui.construct.MessageBox;
|
||||||
import org.jackhuang.hmcl.util.Constants;
|
import org.jackhuang.hmcl.util.Constants;
|
||||||
@ -30,6 +32,8 @@ import org.jackhuang.hmcl.util.NetworkUtils;
|
|||||||
import org.jackhuang.hmcl.util.VersionNumber;
|
import org.jackhuang.hmcl.util.VersionNumber;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@ -65,13 +69,20 @@ public final class UpdateChecker {
|
|||||||
*/
|
*/
|
||||||
public TaskResult<VersionNumber> process(final boolean showMessage) {
|
public TaskResult<VersionNumber> process(final boolean showMessage) {
|
||||||
return new TaskResult<VersionNumber>() {
|
return new TaskResult<VersionNumber>() {
|
||||||
|
GetTask http = new GetTask(NetworkUtils.toURL("https://huangyuhui.duapp.com/hmcl/update.php?version=" + Launcher.VERSION));
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<? extends Task> getDependents() {
|
||||||
|
return value == null ? Collections.singleton(http) : Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() throws Exception {
|
public void execute() throws Exception {
|
||||||
if (Launcher.VERSION.contains("@"))
|
if (Launcher.VERSION.contains("@"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
versionString = NetworkUtils.doGet(NetworkUtils.toURL("https://huangyuhui.duapp.com/hmcl/update.php?version=" + Launcher.VERSION));
|
versionString = http.getResult();
|
||||||
value = VersionNumber.asVersion(versionString);
|
value = VersionNumber.asVersion(versionString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,6 +172,12 @@ public class DefaultGameRepository implements GameRepository {
|
|||||||
if (files != null)
|
if (files != null)
|
||||||
for (File dir : files)
|
for (File dir : files)
|
||||||
if (dir.isDirectory()) {
|
if (dir.isDirectory()) {
|
||||||
|
if (Thread.interrupted()) {
|
||||||
|
this.versions = new HashMap<>();
|
||||||
|
loaded = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String id = dir.getName();
|
String id = dir.getName();
|
||||||
File json = new File(dir, id + ".json");
|
File json = new File(dir, id + ".json");
|
||||||
|
|
||||||
|
@ -119,12 +119,12 @@ public final class Schedulers {
|
|||||||
Logging.LOG.info("Shutting down executor services.");
|
Logging.LOG.info("Shutting down executor services.");
|
||||||
|
|
||||||
if (CACHED_EXECUTOR != null)
|
if (CACHED_EXECUTOR != null)
|
||||||
CACHED_EXECUTOR.shutdown();
|
CACHED_EXECUTOR.shutdownNow();
|
||||||
|
|
||||||
if (IO_EXECUTOR != null)
|
if (IO_EXECUTOR != null)
|
||||||
IO_EXECUTOR.shutdown();
|
IO_EXECUTOR.shutdownNow();
|
||||||
|
|
||||||
if (SINGLE_EXECUTOR != null)
|
if (SINGLE_EXECUTOR != null)
|
||||||
SINGLE_EXECUTOR.shutdown();
|
SINGLE_EXECUTOR.shutdownNow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,8 +89,10 @@ public final class TaskExecutor {
|
|||||||
|
|
||||||
while (!workerQueue.isEmpty()) {
|
while (!workerQueue.isEmpty()) {
|
||||||
Future<?> future = workerQueue.poll();
|
Future<?> future = workerQueue.poll();
|
||||||
if (future != null)
|
if (future != null) {
|
||||||
future.cancel(true);
|
future.cancel(true);
|
||||||
|
System.out.println("Canceled " + future);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user