mirror of
https://github.com/gkd-kit/gkd.git
synced 2024-11-16 11:42:22 +08:00
feat: cache folder
This commit is contained in:
parent
99ef2b4141
commit
f3d2741309
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
7
app/src/main/java/li/songe/gkd/util/LoadStatus.kt
Normal file
7
app/src/main/java/li/songe/gkd/util/LoadStatus.kt
Normal file
|
@ -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>()
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package li.songe.gkd.util
|
||||
|
||||
sealed class Status<out T> {
|
||||
object Empty : Status<Nothing>()
|
||||
|
||||
/**
|
||||
* @param value 0f to 1f
|
||||
*/
|
||||
class Progress(val value: Float = 0f) : Status<Nothing>()
|
||||
class Success<T>(val value: T) : Status<T>()
|
||||
class Error(val value: Any?) : Status<Nothing>() {
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
@ -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) }
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -217,7 +210,7 @@ fun UpgradeDialog() {
|
|||
}
|
||||
|
||||
fun initUpgrade() {
|
||||
if (storeFlow.value.autoCheckAppUpdate) {
|
||||
if (storeFlow.value.autoCheckAppUpdate && isMainProcess) {
|
||||
appScope.launch {
|
||||
try {
|
||||
checkUpdate()
|
||||
|
|
Loading…
Reference in New Issue
Block a user