Refactor uiVersion
This commit is contained in:
@@ -50,6 +50,8 @@ import java.util.stream.Stream;
|
||||
|
||||
public final class Config implements Cloneable, Observable {
|
||||
|
||||
public static final int CURRENT_UI_VERSION = 0;
|
||||
|
||||
private static final Gson CONFIG_GSON = new GsonBuilder()
|
||||
.registerTypeAdapter(VersionSetting.class, VersionSetting.Serializer.INSTANCE)
|
||||
.registerTypeAdapter(Profile.class, Profile.Serializer.INSTANCE)
|
||||
@@ -145,6 +147,13 @@ public final class Config implements Cloneable, Observable {
|
||||
@SerializedName("_version")
|
||||
private IntegerProperty configVersion = new SimpleIntegerProperty(0);
|
||||
|
||||
/**
|
||||
* The version of UI that the user have last used.
|
||||
* If there is a major change in UI, {@link Config#CURRENT_UI_VERSION} should be increased.
|
||||
* When {@link #CURRENT_UI_VERSION} is higher than the property, the user guide should be shown,
|
||||
* then this property is set to the same value as {@link #CURRENT_UI_VERSION}.
|
||||
* In particular, the property is default to 0, so that whoever open the application for the first time will see the guide.
|
||||
*/
|
||||
@SerializedName("uiVersion")
|
||||
private IntegerProperty uiVersion = new SimpleIntegerProperty(0);
|
||||
|
||||
|
||||
@@ -52,13 +52,6 @@ public final class ConfigHolder {
|
||||
return configInstance;
|
||||
}
|
||||
|
||||
public static boolean isNewlyCreated() {
|
||||
if (configInstance == null) {
|
||||
throw new IllegalStateException("Configuration hasn't been loaded");
|
||||
}
|
||||
return newlyCreated;
|
||||
}
|
||||
|
||||
public synchronized static void init() throws IOException {
|
||||
if (configInstance != null) {
|
||||
throw new IllegalStateException("Configuration is already loaded");
|
||||
|
||||
@@ -60,7 +60,6 @@ import static org.jackhuang.hmcl.setting.ConfigHolder.config;
|
||||
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
||||
|
||||
public final class Controllers {
|
||||
public static final int UI_VERSION = 1;
|
||||
|
||||
private static Scene scene;
|
||||
private static Stage stage;
|
||||
|
||||
@@ -40,7 +40,7 @@ import javafx.util.Duration;
|
||||
import org.jackhuang.hmcl.Launcher;
|
||||
import org.jackhuang.hmcl.Metadata;
|
||||
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorDnD;
|
||||
import org.jackhuang.hmcl.setting.ConfigHolder;
|
||||
import org.jackhuang.hmcl.setting.Config;
|
||||
import org.jackhuang.hmcl.setting.EnumBackgroundImage;
|
||||
import org.jackhuang.hmcl.task.TaskExecutor;
|
||||
import org.jackhuang.hmcl.ui.Controllers;
|
||||
@@ -108,9 +108,11 @@ public class DecoratorController {
|
||||
nowAnimation.play();
|
||||
});
|
||||
|
||||
if (ConfigHolder.config().getUiVersion() < Controllers.UI_VERSION && config().getLocalization().getLocale() == Locale.CHINA) {
|
||||
ConfigHolder.config().setUiVersion(Controllers.UI_VERSION);
|
||||
decorator.getContainer().setAll(welcomeView);
|
||||
if (switchedToNewUI()) {
|
||||
if (config().getLocalization().getLocale() == Locale.CHINA) {
|
||||
// currently, user guide is only available in Chinese
|
||||
decorator.getContainer().setAll(welcomeView);
|
||||
}
|
||||
}
|
||||
|
||||
setupBackground();
|
||||
@@ -122,6 +124,17 @@ public class DecoratorController {
|
||||
return decorator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the user is seeing the current version of UI for the first time.
|
||||
*/
|
||||
private boolean switchedToNewUI() {
|
||||
if (config().getUiVersion() < Config.CURRENT_UI_VERSION) {
|
||||
config().setUiVersion(Config.CURRENT_UI_VERSION);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ==== Background ====
|
||||
|
||||
private void setupBackground() {
|
||||
|
||||
Reference in New Issue
Block a user