mirror of
https://github.com/geode-sdk/android-launcher.git
synced 2026-10-21 16:32:39 +00:00
some release download state fixes
This commit is contained in:
1 file changed
+16
-5
@@ -98,7 +98,10 @@ class ReleaseManager private constructor(
|
|||||||
|
|
||||||
var dismissedLauncherUpdate = false
|
var dismissedLauncherUpdate = false
|
||||||
|
|
||||||
|
var skipStateUpdate = false
|
||||||
|
|
||||||
private fun sendError(e: Exception) {
|
private fun sendError(e: Exception) {
|
||||||
|
skipStateUpdate = true
|
||||||
_uiState.value = ReleaseManagerState.Failure(e)
|
_uiState.value = ReleaseManagerState.Failure(e)
|
||||||
|
|
||||||
// ignore cancellation, it's good actually
|
// ignore cancellation, it's good actually
|
||||||
@@ -170,7 +173,7 @@ class ReleaseManager private constructor(
|
|||||||
return Result.success(outputFile)
|
return Result.success(outputFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun performResourceDownload(resourceAsset: DownloadableAsset, initialSize: Long) {
|
private suspend fun performResourceDownload(resourceAsset: DownloadableAsset, initialSize: Long): Boolean {
|
||||||
val guessSize = if (resourceAsset.size == null) null else initialSize + resourceAsset.size
|
val guessSize = if (resourceAsset.size == null) null else initialSize + resourceAsset.size
|
||||||
val guessInitial = if (guessSize == null) 0 else initialSize
|
val guessInitial = if (guessSize == null) 0 else initialSize
|
||||||
_uiState.value = ReleaseManagerState.InDownload(guessInitial, guessSize)
|
_uiState.value = ReleaseManagerState.InDownload(guessInitial, guessSize)
|
||||||
@@ -189,7 +192,8 @@ class ReleaseManager private constructor(
|
|||||||
httpClient,
|
httpClient,
|
||||||
resourceAsset.url,
|
resourceAsset.url,
|
||||||
onProgress = { progress, outOf ->
|
onProgress = { progress, outOf ->
|
||||||
_uiState.value = ReleaseManagerState.InDownload(initialSize + progress, outOf + initialSize)
|
if (!skipStateUpdate)
|
||||||
|
_uiState.value = ReleaseManagerState.InDownload(initialSize + progress, outOf + initialSize)
|
||||||
},
|
},
|
||||||
onResponse = { body ->
|
onResponse = { body ->
|
||||||
DownloadUtils.copyZipStreamToDirectory(
|
DownloadUtils.copyZipStreamToDirectory(
|
||||||
@@ -208,16 +212,20 @@ class ReleaseManager private constructor(
|
|||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
sendError(e)
|
sendError(e)
|
||||||
return
|
return false
|
||||||
} finally {
|
} finally {
|
||||||
val tempPathClone = File(outputPath)
|
val tempPathClone = File(outputPath)
|
||||||
runCatching {
|
runCatching {
|
||||||
if (tempPathClone.exists()) tempPathClone.deleteRecursively()
|
if (tempPathClone.exists()) tempPathClone.deleteRecursively()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun performUpdate(release: Downloadable) {
|
private suspend fun performUpdate(release: Downloadable) {
|
||||||
|
skipStateUpdate = false
|
||||||
|
|
||||||
val releaseAsset = release.getDownload()
|
val releaseAsset = release.getDownload()
|
||||||
if (releaseAsset == null) {
|
if (releaseAsset == null) {
|
||||||
val noAssetException = Exception("missing Android download")
|
val noAssetException = Exception("missing Android download")
|
||||||
@@ -252,7 +260,8 @@ class ReleaseManager private constructor(
|
|||||||
httpClient,
|
httpClient,
|
||||||
releaseAsset.url,
|
releaseAsset.url,
|
||||||
onProgress = { progress, outOf ->
|
onProgress = { progress, outOf ->
|
||||||
_uiState.value = ReleaseManagerState.InDownload(progress, outOf + resourcesSize)
|
if (!skipStateUpdate)
|
||||||
|
_uiState.value = ReleaseManagerState.InDownload(progress, outOf + resourcesSize)
|
||||||
|
|
||||||
releaseSize = max(outOf, releaseSize)
|
releaseSize = max(outOf, releaseSize)
|
||||||
},
|
},
|
||||||
@@ -289,7 +298,9 @@ class ReleaseManager private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (resourcesAsset != null) {
|
if (resourcesAsset != null) {
|
||||||
performResourceDownload(resourcesAsset, releaseSize)
|
if (!performResourceDownload(resourcesAsset, releaseSize)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// extraction performed
|
// extraction performed
|
||||||
|
|||||||
Reference in new issue
Block a user