Replace updateSource with updateChannel
This commit is contained in:
@@ -29,7 +29,7 @@ public final class Metadata {
|
|||||||
public static final String NAME = "HMCL";
|
public static final String NAME = "HMCL";
|
||||||
public static final String TITLE = NAME + " " + VERSION;
|
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 UPDATE_URL = System.getProperty("hmcl.update_source.override", "https://hmcl.huangyuhui.net/api/update_link");
|
||||||
public static final String CONTACT_URL = UPDATE_SERVER_URL + "/hmcl.php";
|
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";
|
public static final String PUBLISH_URL = "http://www.mcbbs.net/thread-142335-1-1.html";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,9 +39,12 @@ import javafx.beans.value.ObservableBooleanValue;
|
|||||||
public final class UpdateChecker {
|
public final class UpdateChecker {
|
||||||
private 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 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(
|
private static BooleanBinding outdated = Bindings.createBooleanBinding(
|
||||||
() -> {
|
() -> {
|
||||||
RemoteVersion latest = latestVersion.get();
|
RemoteVersion latest = latestVersion.get();
|
||||||
@@ -53,6 +56,18 @@ public final class UpdateChecker {
|
|||||||
},
|
},
|
||||||
latestVersion);
|
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() {
|
public static RemoteVersion getLatestVersion() {
|
||||||
return latestVersion.get();
|
return latestVersion.get();
|
||||||
}
|
}
|
||||||
@@ -61,18 +76,6 @@ public final class UpdateChecker {
|
|||||||
return latestVersion;
|
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() {
|
public static boolean isOutdated() {
|
||||||
return outdated.get();
|
return outdated.get();
|
||||||
}
|
}
|
||||||
@@ -82,18 +85,18 @@ public final class UpdateChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void checkUpdate() throws IOException {
|
public static void checkUpdate() throws IOException {
|
||||||
String source = updateSource.get();
|
|
||||||
if (source == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!IntegrityChecker.isSelfVerified()) {
|
if (!IntegrityChecker.isSelfVerified()) {
|
||||||
return;
|
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(() -> {
|
Platform.runLater(() -> {
|
||||||
if (source.equals(updateSource.get())) {
|
if (channel.equals(getUpdateChannel())) {
|
||||||
latestVersion.set(fetched);
|
latestVersion.set(fetched);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user