forked from recloudstream/cloudstream
update inuppupdater
This commit is contained in:
parent
d167c9a3cb
commit
11e000ecc8
2 changed files with 79 additions and 49 deletions
|
@ -16,6 +16,7 @@ import com.fasterxml.jackson.module.kotlin.KotlinModule
|
||||||
import com.fasterxml.jackson.module.kotlin.readValue
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
import com.lagradost.cloudstream3.BuildConfig
|
import com.lagradost.cloudstream3.BuildConfig
|
||||||
import com.lagradost.cloudstream3.R
|
import com.lagradost.cloudstream3.R
|
||||||
|
import com.lagradost.cloudstream3.utils.InAppUpdater.Companion.runAutoUpdate
|
||||||
import java.io.*
|
import java.io.*
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.net.URLConnection
|
import java.net.URLConnection
|
||||||
|
@ -48,7 +49,7 @@ class InAppUpdater {
|
||||||
)
|
)
|
||||||
|
|
||||||
data class GithubTag(
|
data class GithubTag(
|
||||||
@JsonProperty("object") val object: GithubObject,
|
@JsonProperty("object") val github_object: GithubObject,
|
||||||
)
|
)
|
||||||
|
|
||||||
data class Update(
|
data class Update(
|
||||||
|
@ -63,6 +64,19 @@ class InAppUpdater {
|
||||||
|
|
||||||
private fun Activity.getAppUpdate(): Update {
|
private fun Activity.getAppUpdate(): Update {
|
||||||
try {
|
try {
|
||||||
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
|
return if (settingsManager.getBoolean(getString(R.string.prerelease_update_key), false)) {
|
||||||
|
getPreReleaseUpdate()
|
||||||
|
} else {
|
||||||
|
getReleaseUpdate()
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
println(e)
|
||||||
|
return Update(false, null, null, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Activity.getReleaseUpdate(): Update {
|
||||||
val url = "https://api.github.com/repos/LagradOst/CloudStream-3/releases"
|
val url = "https://api.github.com/repos/LagradOst/CloudStream-3/releases"
|
||||||
val headers = mapOf("Accept" to "application/vnd.github.v3+json")
|
val headers = mapOf("Accept" to "application/vnd.github.v3+json")
|
||||||
val response =
|
val response =
|
||||||
|
@ -78,9 +92,9 @@ class InAppUpdater {
|
||||||
versionRegex.find(it.name)?.groupValues?.get(2)
|
versionRegex.find(it.name)?.groupValues?.get(2)
|
||||||
}).toList().lastOrNull()*/
|
}).toList().lastOrNull()*/
|
||||||
val found =
|
val found =
|
||||||
response.filter({ rel ->
|
response.filter { rel ->
|
||||||
!rel.prerelease
|
!rel.prerelease
|
||||||
}).sortedWith(compareBy { release ->
|
}.sortedWith(compareBy { release ->
|
||||||
release.assets.filter { it.content_type == "application/vnd.android.package-archive" }
|
release.assets.filter { it.content_type == "application/vnd.android.package-archive" }
|
||||||
.getOrNull(0)?.name?.let { it1 ->
|
.getOrNull(0)?.name?.let { it1 ->
|
||||||
versionRegex.find(
|
versionRegex.find(
|
||||||
|
@ -103,10 +117,31 @@ class InAppUpdater {
|
||||||
} else {
|
} else {
|
||||||
Update(false, null, null, null)
|
Update(false, null, null, null)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} catch (e: Exception) {
|
private fun Activity.getPreReleaseUpdate(): Update {
|
||||||
println(e)
|
// TODO: change url
|
||||||
return Update(false, null, null, null)
|
val tagUrl = "https://api.github.com/repos/C10udburst/CloudStream-3/git/ref/tags/pre-release"
|
||||||
|
val releaseUrl = "https://api.github.com/repos/C10udburst/CloudStream-3/releases"
|
||||||
|
val headers = mapOf("Accept" to "application/vnd.github.v3+json")
|
||||||
|
val response =
|
||||||
|
mapper.readValue<List<GithubRelease>>(khttp.get(releaseUrl, headers = headers).text)
|
||||||
|
|
||||||
|
val found =
|
||||||
|
response.lastOrNull { rel ->
|
||||||
|
rel.prerelease
|
||||||
|
}
|
||||||
|
val foundAsset = found?.assets?.getOrNull(0)
|
||||||
|
|
||||||
|
val tagResponse =
|
||||||
|
mapper.readValue<GithubTag>(khttp.get(tagUrl, headers = headers).text)
|
||||||
|
|
||||||
|
val shouldUpdate = (getString(R.string.prerelease_commit_hash) != tagResponse.github_object.sha)
|
||||||
|
|
||||||
|
return if (foundAsset != null) {
|
||||||
|
Update(shouldUpdate, foundAsset.browser_download_url, tagResponse.github_object.sha, found.body)
|
||||||
|
} else {
|
||||||
|
Update(false, null, null, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||||
android:width="24dp"
|
android:viewportHeight="24" android:viewportWidth="24"
|
||||||
android:height="24dp"
|
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
android:viewportWidth="24"
|
<path android:fillColor="@android:color/white" android:pathData="M7,5h10v2h2L19,3c0,-1.1 -0.9,-1.99 -2,-1.99L7,1c-1.1,0 -2,0.9 -2,2v4h2L7,5zM15.41,16.59L20,12l-4.59,-4.59L14,8.83 17.17,12 14,15.17l1.41,1.42zM10,15.17L6.83,12 10,8.83 8.59,7.41 4,12l4.59,4.59L10,15.17zM17,19L7,19v-2L5,17v4c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2v-4h-2v2z"/>
|
||||||
android:viewportHeight="24"
|
|
||||||
android:tint="?attr/colorControlNormal">
|
|
||||||
<path
|
|
||||||
android:fillColor="@android:color/white"
|
|
||||||
android:pathData="M7,5h10v2h2L19,3c0,-1.1 -0.9,-1.99 -2,-1.99L7,1c-1.1,0 -2,0.9 -2,2v4h2L7,5zM15.41,16.59L20,12l-4.59,-4.59L14,8.83 17.17,12 14,15.17l1.41,1.42zM10,15.17L6.83,12 10,8.83 8.59,7.41 4,12l4.59,4.59L10,15.17zM17,19L7,19v-2L5,17v4c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2v-4h-2v2z"/>
|
|
||||||
</vector>
|
</vector>
|
||||||
|
|
Loading…
Reference in a new issue