Refactor uiVersion

This commit is contained in:
yushijinhun
2018-10-27 19:10:02 +08:00
parent c9d825b6c1
commit a1d9b52b9d
4 changed files with 26 additions and 12 deletions

View File

@@ -50,6 +50,8 @@ import java.util.stream.Stream;
public final class Config implements Cloneable, Observable { public final class Config implements Cloneable, Observable {
public static final int CURRENT_UI_VERSION = 0;
private static final Gson CONFIG_GSON = new GsonBuilder() private static final Gson CONFIG_GSON = new GsonBuilder()
.registerTypeAdapter(VersionSetting.class, VersionSetting.Serializer.INSTANCE) .registerTypeAdapter(VersionSetting.class, VersionSetting.Serializer.INSTANCE)
.registerTypeAdapter(Profile.class, Profile.Serializer.INSTANCE) .registerTypeAdapter(Profile.class, Profile.Serializer.INSTANCE)
@@ -145,6 +147,13 @@ public final class Config implements Cloneable, Observable {
@SerializedName("_version") @SerializedName("_version")
private IntegerProperty configVersion = new SimpleIntegerProperty(0); 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") @SerializedName("uiVersion")
private IntegerProperty uiVersion = new SimpleIntegerProperty(0); private IntegerProperty uiVersion = new SimpleIntegerProperty(0);

View File

@@ -52,13 +52,6 @@ public final class ConfigHolder {
return configInstance; 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 { public synchronized static void init() throws IOException {
if (configInstance != null) { if (configInstance != null) {
throw new IllegalStateException("Configuration is already loaded"); throw new IllegalStateException("Configuration is already loaded");

View File

@@ -60,7 +60,6 @@ import static org.jackhuang.hmcl.setting.ConfigHolder.config;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
public final class Controllers { public final class Controllers {
public static final int UI_VERSION = 1;
private static Scene scene; private static Scene scene;
private static Stage stage; private static Stage stage;

View File

@@ -40,7 +40,7 @@ import javafx.util.Duration;
import org.jackhuang.hmcl.Launcher; import org.jackhuang.hmcl.Launcher;
import org.jackhuang.hmcl.Metadata; import org.jackhuang.hmcl.Metadata;
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorDnD; 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.setting.EnumBackgroundImage;
import org.jackhuang.hmcl.task.TaskExecutor; import org.jackhuang.hmcl.task.TaskExecutor;
import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.Controllers;
@@ -108,9 +108,11 @@ public class DecoratorController {
nowAnimation.play(); nowAnimation.play();
}); });
if (ConfigHolder.config().getUiVersion() < Controllers.UI_VERSION && config().getLocalization().getLocale() == Locale.CHINA) { if (switchedToNewUI()) {
ConfigHolder.config().setUiVersion(Controllers.UI_VERSION); if (config().getLocalization().getLocale() == Locale.CHINA) {
decorator.getContainer().setAll(welcomeView); // currently, user guide is only available in Chinese
decorator.getContainer().setAll(welcomeView);
}
} }
setupBackground(); setupBackground();
@@ -122,6 +124,17 @@ public class DecoratorController {
return decorator; 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 ==== // ==== Background ====
private void setupBackground() { private void setupBackground() {