2727import org .jackhuang .hmcl .util .versioning .VersionNumber ;
2828
2929import java .io .IOException ;
30+ import java .util .LinkedHashMap ;
3031
31- import static org .jackhuang .hmcl .util . Lang . mapOf ;
32- import static org .jackhuang .hmcl .util .Lang .thread ;
32+ import static org .jackhuang .hmcl .setting . ConfigHolder . config ;
33+ import static org .jackhuang .hmcl .util .Lang .* ;
3334import static org .jackhuang .hmcl .util .logging .Logger .LOG ;
34- import static org .jackhuang .hmcl .util .Pair .pair ;
3535
3636public final class UpdateChecker {
37- private UpdateChecker () {}
37+ private UpdateChecker () {
38+ }
3839
3940 private static final ObjectProperty <RemoteVersion > latestVersion = new SimpleObjectProperty <>();
4041 private static final BooleanBinding outdated = Bindings .createBooleanBinding (
@@ -55,7 +56,7 @@ private UpdateChecker() {}
5556 private static final ReadOnlyBooleanWrapper checkingUpdate = new ReadOnlyBooleanWrapper (false );
5657
5758 public static void init () {
58- requestCheckUpdate (UpdateChannel .getChannel ());
59+ requestCheckUpdate (UpdateChannel .getChannel (), config (). isAcceptPreviewUpdate () );
5960 }
6061
6162 public static RemoteVersion getLatestVersion () {
@@ -82,24 +83,25 @@ public static ReadOnlyBooleanProperty checkingUpdateProperty() {
8283 return checkingUpdate .getReadOnlyProperty ();
8384 }
8485
85- private static RemoteVersion checkUpdate (UpdateChannel channel ) throws IOException {
86+ private static RemoteVersion checkUpdate (UpdateChannel channel , boolean preview ) throws IOException {
8687 if (!IntegrityChecker .DISABLE_SELF_INTEGRITY_CHECK && !IntegrityChecker .isSelfVerified ()) {
8788 throw new IOException ("Self verification failed" );
8889 }
8990
90- String url = NetworkUtils . withQuery ( Metadata . HMCL_UPDATE_URL , mapOf (
91- pair ("version" , Metadata .VERSION ),
92- pair ( "channel" , channel .channelName )) );
91+ LinkedHashMap < String , String > query = new LinkedHashMap <>();
92+ query . put ("version" , Metadata .VERSION );
93+ query . put ( "channel" , preview ? channel . channelName + "-preview" : channel .channelName );
9394
94- return RemoteVersion .fetch (channel , url );
95+ String url = NetworkUtils .withQuery (Metadata .HMCL_UPDATE_URL , query );
96+ return RemoteVersion .fetch (channel , preview , url );
9597 }
9698
9799 private static boolean isDevelopmentVersion (String version ) {
98100 return version .contains ("@" ) || // eg. @develop@
99101 version .contains ("SNAPSHOT" ); // eg. 3.5.SNAPSHOT
100102 }
101103
102- public static void requestCheckUpdate (UpdateChannel channel ) {
104+ public static void requestCheckUpdate (UpdateChannel channel , boolean preview ) {
103105 Platform .runLater (() -> {
104106 if (isCheckingUpdate ())
105107 return ;
@@ -108,8 +110,8 @@ public static void requestCheckUpdate(UpdateChannel channel) {
108110 thread (() -> {
109111 RemoteVersion result = null ;
110112 try {
111- result = checkUpdate (channel );
112- LOG .info ("Latest version (" + channel + ") is " + result );
113+ result = checkUpdate (channel , preview );
114+ LOG .info ("Latest version (" + channel + ", preview=" + preview + " ) is " + result );
113115 } catch (IOException e ) {
114116 LOG .warning ("Failed to check for update" , e );
115117 }
0 commit comments