Initial get latest version using github restful api

This commit is contained in:
tarsin committed 2023-07-05 08:39:22 +08:00
1 parent 1119798ce8
commit 38ddca2342
1 file changed
+8
@@ -30,6 +30,7 @@ import com.hippo.ehviewer.ui.LocalNavController
import com.hippo.ehviewer.ui.tools.toAnnotatedString
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.json.JSONArray
import org.json.JSONObject
private const val REPO_URL = "https://github.com/Ehviewer-Overhauled/Ehviewer"
@@ -104,6 +105,13 @@ fun AboutScreen() {
JSONObject(body.string()).getJSONObject("commit").getString("sha")
}.take(7)
if (commitSha != curSha) launchSnackBar(commitSha)
} else {
val curVersion = BuildConfig.VERSION_NAME
val releaseUrl = "https://api.github.com/repos/Ehviewer-Overhauled/Ehviewer/releases"
val latestVersion = ehRequest(releaseUrl).execute {
JSONArray(body.string())[0] as JSONObject
}.getString("name")
if (latestVersion != curVersion) launchSnackBar(latestVersion)
}
}
}