-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Update checked, with support for stable and snapshot builds
feat: Show launchy version in top bar
- Loading branch information
Showing
5 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
group=com.mineinabyss | ||
version=2.0.0-beta.1 | ||
version=2.0.0-beta.2 | ||
idofrontVersion=0.24.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/kotlin/com/mineinabyss/launchy/logic/GithubUpdateChecker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.mineinabyss.launchy.logic | ||
|
||
import com.mineinabyss.launchy.data.Constants | ||
import com.mineinabyss.launchy.data.Formats | ||
import io.ktor.client.request.* | ||
import io.ktor.client.statement.* | ||
import io.ktor.http.* | ||
import kotlinx.serialization.Serializable | ||
|
||
sealed interface AppUpdateState { | ||
data object Unknown : AppUpdateState | ||
data object NoUpdate : AppUpdateState | ||
data class UpdateAvailable(val release: GithubRelease) : AppUpdateState | ||
} | ||
|
||
object GithubUpdateChecker { | ||
suspend fun checkForUpdates(): AppUpdateState = runCatching { | ||
val currVersion = Constants.APP_VERSION ?: return AppUpdateState.Unknown | ||
val currTag = "v$currVersion" | ||
val current = Downloader.httpClient.get { | ||
url("https://api.github.com/repos/${Constants.GITHUB_REPO}/releases/tags/$currTag") | ||
} | ||
val currentRelease = if (current.status != HttpStatusCode.OK) null | ||
else Formats.json.decodeFromString<GithubRelease>(current.bodyAsText()) | ||
|
||
val latest = if (currentRelease?.prerelease == true) getLatestPrerelease() | ||
else getLatestStableRelease() | ||
println("Current $currentRelease") | ||
println("Latest $latest") | ||
return if (latest.tag_name == currTag) AppUpdateState.NoUpdate else AppUpdateState.UpdateAvailable(latest) | ||
}.getOrDefault(AppUpdateState.Unknown) | ||
|
||
suspend fun getLatestPrerelease(): GithubRelease { | ||
val response = Downloader.httpClient.get { | ||
url("https://api.github.com/repos/${Constants.GITHUB_REPO}/releases") | ||
} | ||
|
||
val releases = Formats.json.decodeFromString<List<GithubRelease>>(response.bodyAsText()) | ||
return releases.maxBy { it.published_at } | ||
} | ||
|
||
suspend fun getLatestStableRelease(): GithubRelease { | ||
val response = Downloader.httpClient.get { | ||
url("https://api.github.com/repos/${Constants.GITHUB_REPO}/releases/latest") | ||
} | ||
return Formats.json.decodeFromString<GithubRelease>(response.bodyAsText()) | ||
} | ||
} | ||
|
||
|
||
@Serializable | ||
data class GithubRelease( | ||
val published_at: String, | ||
val tag_name: String, | ||
val html_url: String, | ||
val prerelease: Boolean, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters