Fix not on FX user thread

This commit is contained in:
huangyuhui
2018-09-09 19:38:14 +08:00
parent 25d79a94f8
commit 5cbde9cc33
3 changed files with 14 additions and 12 deletions

View File

@@ -21,12 +21,14 @@ import com.jfoenix.concurrency.JFXUtilities;
import javafx.application.Application; import javafx.application.Application;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.stage.Stage; import javafx.stage.Stage;
import org.jackhuang.hmcl.setting.ConfigHolder;
import org.jackhuang.hmcl.task.Schedulers; import org.jackhuang.hmcl.task.Schedulers;
import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.Controllers;
import org.jackhuang.hmcl.upgrade.UpdateChecker; import org.jackhuang.hmcl.upgrade.UpdateChecker;
import org.jackhuang.hmcl.util.*; import org.jackhuang.hmcl.util.*;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
@@ -37,6 +39,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.jackhuang.hmcl.util.Logging.LOG; import static org.jackhuang.hmcl.util.Logging.LOG;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
public final class Launcher extends Application { public final class Launcher extends Application {
@@ -44,6 +47,12 @@ public final class Launcher extends Application {
public void start(Stage primaryStage) { public void start(Stage primaryStage) {
Thread.currentThread().setUncaughtExceptionHandler(CRASH_REPORTER); Thread.currentThread().setUncaughtExceptionHandler(CRASH_REPORTER);
try {
ConfigHolder.init();
} catch (IOException e) {
Main.showErrorAndExit(i18n("fatal.config_loading_failure", Paths.get("").toAbsolutePath().normalize()));
}
try { try {
// When launcher visibility is set to "hide and reopen" without Platform.implicitExit = false, // When launcher visibility is set to "hide and reopen" without Platform.implicitExit = false,
// Stage.show() cannot work again because JavaFX Toolkit have already shut down. // Stage.show() cannot work again because JavaFX Toolkit have already shut down.

View File

@@ -49,12 +49,6 @@ public final class Main {
return; return;
} }
try {
ConfigHolder.init();
} catch (IOException e) {
showErrorAndExit(i18n("fatal.config_loading_failure", Paths.get("").toAbsolutePath().normalize()));
}
Launcher.main(args); Launcher.main(args);
} }
@@ -100,7 +94,7 @@ public final class Main {
/** /**
* Indicates that a fatal error has occurred, and that the application cannot start. * Indicates that a fatal error has occurred, and that the application cannot start.
*/ */
private static void showErrorAndExit(String message) { static void showErrorAndExit(String message) {
System.err.println(message); System.err.println(message);
System.err.println("A fatal error has occurred, forcibly exiting."); System.err.println("A fatal error has occurred, forcibly exiting.");
JOptionPane.showMessageDialog(null, message, "Error", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null, message, "Error", JOptionPane.ERROR_MESSAGE);
@@ -110,7 +104,7 @@ public final class Main {
/** /**
* Indicates that potential issues have been detected, and that the application may not function properly (but it can still run). * Indicates that potential issues have been detected, and that the application may not function properly (but it can still run).
*/ */
private static void showWarningAndContinue(String message) { static void showWarningAndContinue(String message) {
System.err.println(message); System.err.println(message);
System.err.println("Potential issues have been detected."); System.err.println("Potential issues have been detected.");
JOptionPane.showMessageDialog(null, message, "Warning", JOptionPane.WARNING_MESSAGE); JOptionPane.showMessageDialog(null, message, "Warning", JOptionPane.WARNING_MESSAGE);

View File

@@ -18,6 +18,7 @@
package org.jackhuang.hmcl.setting; package org.jackhuang.hmcl.setting;
import com.google.gson.*; import com.google.gson.*;
import javafx.application.Platform;
import javafx.beans.InvalidationListener; import javafx.beans.InvalidationListener;
import javafx.beans.Observable; import javafx.beans.Observable;
import javafx.beans.property.*; import javafx.beans.property.*;
@@ -28,8 +29,6 @@ import org.jackhuang.hmcl.game.HMCLCacheRepository;
import org.jackhuang.hmcl.game.HMCLGameRepository; import org.jackhuang.hmcl.game.HMCLGameRepository;
import org.jackhuang.hmcl.game.Version; import org.jackhuang.hmcl.game.Version;
import org.jackhuang.hmcl.mod.ModManager; import org.jackhuang.hmcl.mod.ModManager;
import org.jackhuang.hmcl.task.Schedulers;
import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.ui.WeakListenerHelper; import org.jackhuang.hmcl.ui.WeakListenerHelper;
import org.jackhuang.hmcl.util.*; import org.jackhuang.hmcl.util.*;
@@ -206,8 +205,8 @@ public final class Profile implements Observable {
observableHelper.removeListener(listener); observableHelper.removeListener(listener);
} }
protected void invalidate() { private void invalidate() {
Schedulers.computation().schedule(observableHelper::invalidate); Platform.runLater(observableHelper::invalidate);
} }
public static final class Serializer implements JsonSerializer<Profile>, JsonDeserializer<Profile> { public static final class Serializer implements JsonSerializer<Profile>, JsonDeserializer<Profile> {