Search in sources :

Example 1 with UpdateInfo

use of lee.study.down.model.UpdateInfo in project proxyee-down by monkeyWie.

the class GithubUpdateService method main.

public static void main(String[] args) throws Exception {
    GithubUpdateService githubUpdateService = new GithubUpdateService();
    UpdateInfo updateInfo = githubUpdateService.check(1.0F);
    githubUpdateService.update(updateInfo, null);
}
Also used : UpdateInfo(lee.study.down.model.UpdateInfo)

Example 2 with UpdateInfo

use of lee.study.down.model.UpdateInfo in project proxyee-down by monkeyWie.

the class GithubUpdateService method check.

@Override
public UpdateInfo check(float currVersion) throws Exception {
    UpdateInfo updateInfo = new UpdateInfo();
    Document document = Jsoup.connect("https://github.com/monkeyWie/proxyee-down/releases").get();
    Elements versions = document.select("h1.release-title.text-normal");
    Collections.sort(versions, (v1, v2) -> {
        float version1 = Float.parseFloat(v1.text());
        float version2 = Float.parseFloat(v2.text());
        return version1 < version2 ? 1 : -1;
    });
    float maxVersion = Float.parseFloat(versions.get(0).text());
    if (maxVersion > currVersion) {
        updateInfo.setVersion(maxVersion);
        updateInfo.setVersionStr(versions.get(0).text());
        Element releaseDiv = versions.get(0).parent().parent();
        for (Element element : releaseDiv.select(".d-block.py-2")) {
            if (element.select("strong").text().indexOf("-jar.zip") != -1) {
                updateInfo.setUrl("https://github.com" + element.select("a").attr("href"));
                break;
            }
        }
        if (updateInfo.getUrl() == null) {
            return null;
        }
        updateInfo.setDesc(releaseDiv.select(".markdown-body").html());
        return updateInfo;
    }
    return null;
}
Also used : Element(org.jsoup.nodes.Element) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) UpdateInfo(lee.study.down.model.UpdateInfo)

Aggregations

UpdateInfo (lee.study.down.model.UpdateInfo)2 Document (org.jsoup.nodes.Document)1 Element (org.jsoup.nodes.Element)1 Elements (org.jsoup.select.Elements)1