Add debug preference to rebuild icon pack cache

This commit is contained in:
MM20 2023-04-17 18:57:15 +02:00
parent d3e1fb2767
commit d4cf895481
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
5 changed files with 23 additions and 2 deletions

View File

@ -56,6 +56,12 @@ fun DebugSettingsScreen() {
).show() ).show()
} }
}) })
Preference(
title = stringResource(R.string.preference_debug_reinstall_iconpacks),
summary = stringResource(R.string.preference_debug_reinstall_iconpacks_summary),
onClick = {
viewModel.reinstallIconPacks()
})
} }
} }
} }

View File

@ -2,6 +2,7 @@ package de.mm20.launcher2.ui.settings.debug
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import de.mm20.launcher2.data.customattrs.CustomAttributesRepository import de.mm20.launcher2.data.customattrs.CustomAttributesRepository
import de.mm20.launcher2.icons.IconService
import de.mm20.launcher2.searchable.SearchableRepository import de.mm20.launcher2.searchable.SearchableRepository
import org.koin.core.component.KoinComponent import org.koin.core.component.KoinComponent
import org.koin.core.component.inject import org.koin.core.component.inject
@ -10,9 +11,14 @@ class DebugSettingsScreenVM: ViewModel(), KoinComponent {
private val searchableRepository: SearchableRepository by inject() private val searchableRepository: SearchableRepository by inject()
private val customAttributesRepository: CustomAttributesRepository by inject() private val customAttributesRepository: CustomAttributesRepository by inject()
private val iconService: IconService by inject()
suspend fun cleanUpDatabase(): Int { suspend fun cleanUpDatabase(): Int {
var removed = searchableRepository.cleanupDatabase() var removed = searchableRepository.cleanupDatabase()
removed += customAttributesRepository.cleanupDatabase() removed += customAttributesRepository.cleanupDatabase()
return removed return removed
} }
fun reinstallIconPacks() {
iconService.reinstallAllIconPacks()
}
} }

View File

@ -458,6 +458,8 @@
<string name="preference_category_debug_tools">Tools</string> <string name="preference_category_debug_tools">Tools</string>
<string name="preference_debug_cleanup_database">Clean up database</string> <string name="preference_debug_cleanup_database">Clean up database</string>
<string name="preference_debug_cleanup_database_summary">Remove broken and unused entries from the launcher database</string> <string name="preference_debug_cleanup_database_summary">Remove broken and unused entries from the launcher database</string>
<string name="preference_debug_reinstall_iconpacks">Reinstall icon packs</string>
<string name="preference_debug_reinstall_iconpacks_summary">Clear and rebuild the icon pack cache</string>
<plurals name="debug_cleanup_database_result"> <plurals name="debug_cleanup_database_result">
<item quantity="one">%1$d entry has been removed.</item> <item quantity="one">%1$d entry has been removed.</item>
<item quantity="other">%1$d entries have been removed.</item> <item quantity="other">%1$d entries have been removed.</item>

View File

@ -50,7 +50,7 @@ class IconPackManager(
} }
private var updateIconPacksMutex = Mutex() private var updateIconPacksMutex = Mutex()
suspend fun updateIconPacks(): Boolean { suspend fun updateIconPacks(forceReinstall: Boolean = false): Boolean {
var iconsHaveBeenUpdated = false var iconsHaveBeenUpdated = false
updateIconPacksMutex.lock() updateIconPacksMutex.lock()
val installers = listOf( val installers = listOf(
@ -61,7 +61,7 @@ class IconPackManager(
for (installer in installers) { for (installer in installers) {
val iconPacks = installer.getInstalledIconPacks() val iconPacks = installer.getInstalledIconPacks()
for (pack in iconPacks) { for (pack in iconPacks) {
if (!installer.isInstalledAndUpToDate(pack)) { if (forceReinstall || !installer.isInstalledAndUpToDate(pack)) {
installer.install(pack) installer.install(pack)
iconsHaveBeenUpdated = true iconsHaveBeenUpdated = true
} else { } else {

View File

@ -228,6 +228,13 @@ class IconService(
} }
} }
fun reinstallAllIconPacks() {
scope.launch {
iconPackManager.updateIconPacks(forceReinstall = true)
iconPacksUpdated.tryEmit(Unit)
}
}
fun getInstalledIconPacks(): Flow<List<IconPack>> { fun getInstalledIconPacks(): Flow<List<IconPack>> {
return iconPackManager.getInstalledIconPacks() return iconPackManager.getInstalledIconPacks()
} }