fix: cache clearing

This commit is contained in:
rushiiMachine 2025-06-10 13:36:20 -07:00
parent ff345fbcce
commit 4011177373
No known key found for this signature in database
GPG key ID: DCBE5952BB3B6420
5 changed files with 15 additions and 7 deletions

View file

@ -47,7 +47,8 @@ class PathManager(
* Delete the entire cache dir and recreate it.
*/
fun clearCache() {
cacheDir.deleteRecursively()
context.cacheDir.deleteRecursively()
context.externalCacheDir?.deleteRecursively()
cacheDir.mkdirs()
}

View file

@ -269,7 +269,7 @@ class PatchingScreen(private val data: PatchOptions) : Screen, Parcelable {
),
onClick = {
cacheCleared = true
model.cancelInstall()
model.clearCache()
},
)
}

View file

@ -62,8 +62,6 @@ class PatchingScreenModel(
}
}
fun getCurrentInstallId(): String? = installId
fun launchApp() {
if (state.value !is PatchingScreenState.Success)
return
@ -78,6 +76,13 @@ class PatchingScreenModel(
}
}
fun clearCache() = screenModelScope.launchBlock {
paths.clearCache()
application.showToast(R.string.action_cleared_cache)
}
fun getCurrentInstallId(): String? = installId
fun cancelInstall() = screenModelScope.launchBlock(Dispatchers.IO) {
runnerJob?.cancel("Manual cancellation")

View file

@ -5,6 +5,7 @@ import androidx.compose.runtime.*
import cafe.adriel.voyager.core.model.ScreenModel
import cafe.adriel.voyager.core.model.screenModelScope
import com.aliucord.manager.R
import com.aliucord.manager.manager.PathManager
import com.aliucord.manager.manager.PreferencesManager
import com.aliucord.manager.ui.theme.Theme
import com.aliucord.manager.util.launchBlock
@ -14,6 +15,7 @@ import kotlinx.coroutines.launch
class SettingsModel(
private val application: Application,
private val paths: PathManager,
val preferences: PreferencesManager,
) : ScreenModel {
var showThemeDialog by mutableStateOf(false)
@ -44,8 +46,8 @@ class SettingsModel(
preferences.keepPatchedApks = value
}
fun clearCacheDir() = screenModelScope.launchBlock {
application.externalCacheDir?.deleteRecursively()
fun clearCache() = screenModelScope.launchBlock {
paths.clearCache()
application.showToast(R.string.action_cleared_cache)
}
}

View file

@ -119,7 +119,7 @@ class SettingsScreen : Screen, Parcelable {
),
onClick = {
clearedCache = true
model.clearCacheDir()
model.clearCache()
},
modifier = Modifier
.padding(horizontal = 18.dp, vertical = 10.dp)