fix(gui): download only latest version info for jadx update (#1397)
This commit is contained in:
@@ -7,8 +7,6 @@ import java.lang.reflect.Type;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -19,21 +17,20 @@ import com.google.gson.reflect.TypeToken;
|
||||
import jadx.api.JadxDecompiler;
|
||||
import jadx.gui.update.data.Release;
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
public class JadxUpdate {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(JadxUpdate.class);
|
||||
|
||||
public static final String JADX_RELEASES_URL = "https://github.com/skylot/jadx/releases";
|
||||
|
||||
private static final String GITHUB_API_URL = "https://api.github.com/";
|
||||
private static final String GITHUB_RELEASES_URL = GITHUB_API_URL + "repos/skylot/jadx/releases";
|
||||
private static final String GITHUB_LATEST_RELEASE_URL = GITHUB_API_URL + "repos/skylot/jadx/releases/latest";
|
||||
|
||||
private static final Gson GSON = new Gson();
|
||||
|
||||
private static final Type RELEASES_LIST_TYPE = new TypeToken<List<Release>>() {
|
||||
private static final Type RELEASE_TYPE = new TypeToken<Release>() {
|
||||
}.getType();
|
||||
|
||||
private static final Comparator<Release> RELEASE_COMPARATOR = (o1, o2) -> VersionComparator.checkAndCompare(o1.getName(), o2.getName());
|
||||
|
||||
public interface IUpdateCallback {
|
||||
void onUpdate(Release r);
|
||||
}
|
||||
@@ -64,18 +61,15 @@ public class JadxUpdate {
|
||||
LOG.debug("Ignore check for update: development version");
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Release> list = get(GITHUB_RELEASES_URL, RELEASES_LIST_TYPE);
|
||||
if (list == null) {
|
||||
Release latest = get(GITHUB_LATEST_RELEASE_URL, RELEASE_TYPE);
|
||||
if (latest == null) {
|
||||
return null;
|
||||
}
|
||||
list.removeIf(release -> release.getName().equalsIgnoreCase(version) || release.isPreRelease());
|
||||
if (list.isEmpty()) {
|
||||
String latestName = latest.getName();
|
||||
if (latestName.equalsIgnoreCase(version)) {
|
||||
return null;
|
||||
}
|
||||
list.sort(RELEASE_COMPARATOR);
|
||||
Release latest = list.get(list.size() - 1);
|
||||
if (VersionComparator.checkAndCompare(version, latest.getName()) >= 0) {
|
||||
if (VersionComparator.checkAndCompare(version, latestName) >= 0) {
|
||||
return null;
|
||||
}
|
||||
LOG.info("Found new jadx version: {}", latest);
|
||||
|
||||
@@ -2,15 +2,9 @@ package jadx.gui.update.data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class Release {
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
@SerializedName("prerelease")
|
||||
private boolean preRelease;
|
||||
|
||||
private List<Asset> assets;
|
||||
|
||||
public String getName() {
|
||||
@@ -29,14 +23,6 @@ public class Release {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public boolean isPreRelease() {
|
||||
return preRelease;
|
||||
}
|
||||
|
||||
public void setPreRelease(boolean preRelease) {
|
||||
this.preRelease = preRelease;
|
||||
}
|
||||
|
||||
public List<Asset> getAssets() {
|
||||
return assets;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user