Skip to content

Commit

Permalink
feat: cache folder
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Oct 4, 2023
1 parent 99ef2b4 commit f3d2741
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 25 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/li/songe/gkd/debug/SnapshotExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ object SnapshotExt {
"${getSnapshotParentPath(snapshotId)}/${snapshotId}.png"

suspend fun getSnapshotZipFile(snapshotId: Long): File {
val file = File(snapshotZipDir.absolutePath + "/${snapshotId}.zip")
val file = File(snapshotZipDir, "${snapshotId}.zip")
if (file.exists()) {
file.delete()
}
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/java/li/songe/gkd/util/Cache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ import com.blankj.utilcode.util.PathUtils
import java.io.File

private val cacheParentDir by lazy {
PathUtils.getExternalAppCachePath()
File(PathUtils.getExternalAppCachePath())
}

val snapshotZipDir by lazy {
File(cacheParentDir.plus("/snapshotZip")).apply {
File(cacheParentDir, "snapshotZip").apply {
if (!exists()) {
mkdirs()
}
}
}
val newVersionApkDir by lazy {
File(cacheParentDir, "newVersionApk").apply {
if (!exists()) {
mkdirs()
}
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/li/songe/gkd/util/LoadStatus.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package li.songe.gkd.util

sealed class LoadStatus<out T> {
data class Loading(val progress: Float = 0f) : LoadStatus<Nothing>()
data class Failure(val exception: Exception) : LoadStatus<Nothing>()
data class Success<T>(val result: T) : LoadStatus<T>()
}
13 changes: 0 additions & 13 deletions app/src/main/java/li/songe/gkd/util/Status.kt

This file was deleted.

11 changes: 2 additions & 9 deletions app/src/main/java/li/songe/gkd/util/Upgrade.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog
import com.blankj.utilcode.util.AppUtils
import com.blankj.utilcode.util.PathUtils
import io.ktor.client.call.body
import io.ktor.client.plugins.onDownload
import io.ktor.client.request.get
Expand Down Expand Up @@ -51,12 +50,6 @@ data class NewVersion(
val fileSize: Long? = null,
) : Parcelable

sealed class LoadStatus<out T> {
data class Loading(val progress: Float = 0f) : LoadStatus<Nothing>()
data class Failure(val exception: Exception) : LoadStatus<Nothing>()
data class Success<T>(val result: T) : LoadStatus<T>()
}

private const val UPDATE_URL = "https://registry.npmmirror.com/@gkd-kit/app/latest/files/index.json"

val checkUpdatingFlow by lazy { MutableStateFlow(false) }
Expand All @@ -82,7 +75,7 @@ suspend fun checkUpdate(): NewVersion? {
fun startDownload(newVersion: NewVersion) {
if (downloadStatusFlow.value is LoadStatus.Loading) return
downloadStatusFlow.value = LoadStatus.Loading(0f)
val newApkFile = File(PathUtils.getExternalAppCachePath() + "/v${newVersion.versionCode}.apk")
val newApkFile = File(newVersionApkDir, "v${newVersion.versionCode}.apk")
if (newApkFile.exists()) {
newApkFile.delete()
}
Expand Down Expand Up @@ -217,7 +210,7 @@ fun UpgradeDialog() {
}

fun initUpgrade() {
if (storeFlow.value.autoCheckAppUpdate) {
if (storeFlow.value.autoCheckAppUpdate && isMainProcess) {
appScope.launch {
try {
checkUpdate()
Expand Down

0 comments on commit f3d2741

Please sign in to comment.