forked from geode-sdk/android-launcher
reorganize release api
This commit is contained in:
6 files changed
+20
-28
No files matched your search
@@ -36,7 +36,7 @@ import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import com.geode.launcher.api.ReleaseViewModel
|
||||
import com.geode.launcher.updater.ReleaseViewModel
|
||||
import com.geode.launcher.ui.theme.GeodeLauncherTheme
|
||||
import com.geode.launcher.ui.theme.LocalTheme
|
||||
import com.geode.launcher.ui.theme.Theme
|
||||
@@ -44,7 +44,7 @@ import com.geode.launcher.ui.theme.Typography
|
||||
import com.geode.launcher.utils.Constants
|
||||
import com.geode.launcher.utils.LaunchUtils
|
||||
import com.geode.launcher.utils.PreferenceUtils
|
||||
import com.geode.launcher.utils.ReleaseManager
|
||||
import com.geode.launcher.updater.ReleaseManager
|
||||
import com.geode.launcher.utils.useCountdownTimer
|
||||
import java.net.ConnectException
|
||||
import java.net.UnknownHostException
|
||||
|
||||
@@ -47,7 +47,7 @@ import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import com.geode.launcher.api.ReleaseViewModel
|
||||
import com.geode.launcher.updater.ReleaseViewModel
|
||||
import com.geode.launcher.ui.theme.GeodeLauncherTheme
|
||||
import com.geode.launcher.ui.theme.LocalTheme
|
||||
import com.geode.launcher.ui.theme.Theme
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.geode.launcher.api
|
||||
package com.geode.launcher.updater
|
||||
|
||||
import com.geode.launcher.utils.LaunchUtils
|
||||
import kotlinx.datetime.Instant
|
||||
+10
-12
@@ -1,9 +1,10 @@
|
||||
package com.geode.launcher.utils
|
||||
package com.geode.launcher.updater
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.geode.launcher.api.Release
|
||||
import com.geode.launcher.api.ReleaseRepository
|
||||
import com.geode.launcher.utils.DownloadUtils
|
||||
import com.geode.launcher.utils.LaunchUtils
|
||||
import com.geode.launcher.utils.PreferenceUtils
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
@@ -32,7 +33,7 @@ class ReleaseManager private constructor(
|
||||
private lateinit var managerInstance: ReleaseManager
|
||||
|
||||
fun get(context: Context): ReleaseManager {
|
||||
if (!::managerInstance.isInitialized) {
|
||||
if (!Companion::managerInstance.isInitialized) {
|
||||
val applicationContext = context.applicationContext
|
||||
|
||||
val httpClient = OkHttpClient.Builder()
|
||||
@@ -90,13 +91,7 @@ class ReleaseManager private constructor(
|
||||
val sharedPreferences = PreferenceUtils.get(applicationContext)
|
||||
val useNightly = sharedPreferences.getBoolean(PreferenceUtils.Key.RELEASE_CHANNEL)
|
||||
|
||||
val latestRelease = if (useNightly) {
|
||||
releaseRepository.getLatestNightlyRelease()
|
||||
} else {
|
||||
releaseRepository.getLatestRelease()
|
||||
}
|
||||
|
||||
return latestRelease
|
||||
return releaseRepository.getLatestGeodeRelease(useNightly)
|
||||
}
|
||||
|
||||
private suspend fun performUpdate(release: Release) {
|
||||
@@ -112,7 +107,10 @@ class ReleaseManager private constructor(
|
||||
_uiState.value = ReleaseManagerState.InDownload(0, releaseAsset.size.toLong())
|
||||
|
||||
try {
|
||||
val fileStream = DownloadUtils.downloadStream(httpClient, releaseAsset.browserDownloadUrl) { progress, outOf ->
|
||||
val fileStream = DownloadUtils.downloadStream(
|
||||
httpClient,
|
||||
releaseAsset.browserDownloadUrl
|
||||
) { progress, outOf ->
|
||||
_uiState.value = ReleaseManagerState.InDownload(progress, outOf)
|
||||
}
|
||||
|
||||
+5
-10
@@ -1,4 +1,4 @@
|
||||
package com.geode.launcher.api
|
||||
package com.geode.launcher.updater
|
||||
|
||||
import com.geode.launcher.utils.DownloadUtils.executeCoroutine
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
@@ -12,20 +12,15 @@ import java.net.URL
|
||||
|
||||
class ReleaseRepository(private val httpClient: OkHttpClient) {
|
||||
companion object {
|
||||
private const val GITHUB_API_BASE = "https://api.github.com/repos/geode-sdk/geode"
|
||||
private const val GITHUB_API_BASE = "https://api.github.com"
|
||||
private const val GITHUB_API_HEADER = "X-GitHub-Api-Version"
|
||||
private const val GITHUB_API_VERSION = "2022-11-28"
|
||||
}
|
||||
|
||||
suspend fun getLatestNightlyRelease(): Release? {
|
||||
val nightlyPath = "$GITHUB_API_BASE/releases/tags/nightly"
|
||||
val url = URL(nightlyPath)
|
||||
suspend fun getLatestGeodeRelease(isNightly: Boolean = false): Release? {
|
||||
val releasePath = if (isNightly) "$GITHUB_API_BASE/releases/tags/nightly"
|
||||
else "$GITHUB_API_BASE/repos/geode-sdk/geode/releases/latest"
|
||||
|
||||
return getReleaseByUrl(url)
|
||||
}
|
||||
|
||||
suspend fun getLatestRelease(): Release? {
|
||||
val releasePath = "$GITHUB_API_BASE/releases/latest"
|
||||
val url = URL(releasePath)
|
||||
|
||||
return getReleaseByUrl(url)
|
||||
+1
-2
@@ -1,4 +1,4 @@
|
||||
package com.geode.launcher.api
|
||||
package com.geode.launcher.updater
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.ViewModel
|
||||
@@ -7,7 +7,6 @@ import androidx.lifecycle.ViewModelProvider.AndroidViewModelFactory.Companion.AP
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.lifecycle.viewmodel.initializer
|
||||
import androidx.lifecycle.viewmodel.viewModelFactory
|
||||
import com.geode.launcher.utils.ReleaseManager
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
Reference in new issue
Block a user