feat: disallow enabling keep patched APKs when external cache directory doesn't exist
This commit is contained in:
parent
a1e7594698
commit
fe6fe5367a
5 changed files with 22 additions and 5 deletions
|
|
@ -34,14 +34,13 @@ class PathManager(
|
|||
val keystoreFile = aliucordDir.resolve("ks.keystore")
|
||||
|
||||
/**
|
||||
* Use the external cache directory (`/storage/emulated/0/Android/data/com.aliucord.manager/cache`)
|
||||
* Uses the external cache directory (`/storage/emulated/0/Android/data/com.aliucord.manager/cache`)
|
||||
* when dev mode or preserving APKs is enabled. Otherwise, default to internal app cache.
|
||||
*/
|
||||
private val cacheDir
|
||||
val cacheDir: File
|
||||
get() = when (prefs.devMode || prefs.keepPatchedApks) {
|
||||
false -> context.cacheDir
|
||||
true -> context.externalCacheDir
|
||||
?: throw Error("External cache directory isn't supported")
|
||||
true -> context.externalCacheDir ?: context.cacheDir
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package com.aliucord.manager.manager
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import androidx.compose.runtime.Stable
|
||||
import com.aliucord.manager.manager.base.BasePreferenceManager
|
||||
import com.aliucord.manager.ui.components.Theme
|
||||
|
||||
@Stable
|
||||
class PreferencesManager(preferences: SharedPreferences) : BasePreferenceManager(preferences) {
|
||||
var theme by enumPreference("theme", Theme.DARK)
|
||||
var dynamicColor by booleanPreference("dynamic_color", false)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ import com.aliucord.manager.manager.PreferencesManager
|
|||
import com.aliucord.manager.ui.components.Theme
|
||||
import com.aliucord.manager.util.launchBlock
|
||||
import com.aliucord.manager.util.showToast
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class SettingsModel(
|
||||
private val application: Application,
|
||||
|
|
@ -29,6 +31,19 @@ class SettingsModel(
|
|||
preferences.theme = theme
|
||||
}
|
||||
|
||||
fun setKeepPatchedApks(value: Boolean) {
|
||||
// Disallow setting keep APKs if externalCacheDir doesn't exist (some ROMs)
|
||||
if (value && application.externalCacheDir == null) {
|
||||
screenModelScope.launch {
|
||||
delay(300)
|
||||
preferences.keepPatchedApks = false
|
||||
application.showToast(R.string.setting_keep_patched_apks_error)
|
||||
}
|
||||
}
|
||||
|
||||
preferences.keepPatchedApks = value
|
||||
}
|
||||
|
||||
fun clearCacheDir() = screenModelScope.launchBlock {
|
||||
application.externalCacheDir?.deleteRecursively()
|
||||
application.showToast(R.string.action_cleared_cache)
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ class SettingsScreen : Screen, Parcelable {
|
|||
secondaryLabel = stringResource(R.string.setting_keep_patched_apks_desc),
|
||||
icon = { Icon(painterResource(R.drawable.ic_delete_forever), null) },
|
||||
pref = preferences.keepPatchedApks,
|
||||
onPrefChange = { preferences.keepPatchedApks = it },
|
||||
onPrefChange = model::setKeepPatchedApks,
|
||||
)
|
||||
|
||||
var clearedCache by rememberSaveable { mutableStateOf(false) }
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@
|
|||
<string name="setting_dynamic_color_desc">Enables Material You theming on Android 12+</string>
|
||||
<string name="setting_keep_patched_apks">Keep patched APKs</string>
|
||||
<string name="setting_keep_patched_apks_desc">Keep all patched files and APKs after installing for debugging.</string>
|
||||
<string name="setting_keep_patched_apks_error">This device does not support external cache directories!</string>
|
||||
|
||||
<string name="theme_system">System</string>
|
||||
<string name="theme_dark">Dark</string>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue