Replace updateSource with updateChannel

This commit is contained in:
yushijinhun
2018-08-04 21:39:19 +08:00
parent 7096135cdf
commit bdb7afa860
2 changed files with 26 additions and 23 deletions

View File

@@ -29,7 +29,7 @@ public final class Metadata {
public static final String NAME = "HMCL";
public static final String TITLE = NAME + " " + VERSION;
public static final String UPDATE_SERVER_URL = System.getProperty("hmcl.update_source.override", "https://hmcl.huangyuhui.net");
public static final String CONTACT_URL = UPDATE_SERVER_URL + "/hmcl.php";
public static final String UPDATE_URL = System.getProperty("hmcl.update_source.override", "https://hmcl.huangyuhui.net/api/update_link");
public static final String CONTACT_URL = "https://www.huangyuhui.net/hmcl.php";
public static final String PUBLISH_URL = "http://www.mcbbs.net/thread-142335-1-1.html";
}

View File

@@ -39,9 +39,12 @@ import javafx.beans.value.ObservableBooleanValue;
public final class UpdateChecker {
private UpdateChecker() {}
public static final String CHANNEL_STABLE = "stable";
public static final String CHANNEL_DEV = "dev";
private static StringProperty updateChannel = new SimpleStringProperty(CHANNEL_STABLE);
private static ObjectProperty<RemoteVersion> latestVersion = new SimpleObjectProperty<>();
private static StringProperty updateSource = new SimpleStringProperty(
NetworkUtils.withQuery(Metadata.UPDATE_SERVER_URL + "/api/update_link", mapOf(pair("version", Metadata.VERSION))));
private static BooleanBinding outdated = Bindings.createBooleanBinding(
() -> {
RemoteVersion latest = latestVersion.get();
@@ -53,6 +56,18 @@ public final class UpdateChecker {
},
latestVersion);
public static String getUpdateChannel() {
return updateChannel.get();
}
public static void setUpdateChannel(String updateChannel) {
UpdateChecker.updateChannel.set(updateChannel);
}
public static StringProperty updateChannelProperty() {
return updateChannel;
}
public static RemoteVersion getLatestVersion() {
return latestVersion.get();
}
@@ -61,18 +76,6 @@ public final class UpdateChecker {
return latestVersion;
}
public static String getUpdateSource() {
return updateSource.get();
}
public static void setUpdateSource(String updateSource) {
UpdateChecker.updateSource.set(updateSource);
}
public static StringProperty updateSourceProperty() {
return updateSource;
}
public static boolean isOutdated() {
return outdated.get();
}
@@ -82,18 +85,18 @@ public final class UpdateChecker {
}
public static void checkUpdate() throws IOException {
String source = updateSource.get();
if (source == null) {
return;
}
if (!IntegrityChecker.isSelfVerified()) {
return;
}
RemoteVersion fetched = RemoteVersion.fetch(source);
String channel = getUpdateChannel();
String url = NetworkUtils.withQuery(Metadata.UPDATE_URL, mapOf(
pair("version", Metadata.VERSION),
pair("channel", channel)));
RemoteVersion fetched = RemoteVersion.fetch(url);
Platform.runLater(() -> {
if (source.equals(updateSource.get())) {
if (channel.equals(getUpdateChannel())) {
latestVersion.set(fetched);
}
});