closes #24194: switch to IO dispatcher when cleaning wallpapers
This commit is contained in:
parent
ad95f950bb
commit
154ec3402e
|
@ -40,17 +40,17 @@ class WallpaperFileManager(
|
||||||
* Remove all wallpapers that are not the [currentWallpaper] or in [availableWallpapers].
|
* Remove all wallpapers that are not the [currentWallpaper] or in [availableWallpapers].
|
||||||
*/
|
*/
|
||||||
fun clean(currentWallpaper: Wallpaper, availableWallpapers: List<Wallpaper.Remote>) {
|
fun clean(currentWallpaper: Wallpaper, availableWallpapers: List<Wallpaper.Remote>) {
|
||||||
|
scope.launch {
|
||||||
val wallpapersToKeep = (listOf(currentWallpaper) + availableWallpapers).map { it.name }
|
val wallpapersToKeep = (listOf(currentWallpaper) + availableWallpapers).map { it.name }
|
||||||
cleanChildren(portraitDirectory, wallpapersToKeep)
|
cleanChildren(portraitDirectory, wallpapersToKeep)
|
||||||
cleanChildren(landscapeDirectory, wallpapersToKeep)
|
cleanChildren(landscapeDirectory, wallpapersToKeep)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun cleanChildren(dir: File, wallpapersToKeep: List<String>) {
|
private fun cleanChildren(dir: File, wallpapersToKeep: List<String>) {
|
||||||
for (file in dir.walkTopDown()) {
|
for (file in dir.walkTopDown()) {
|
||||||
if (file.isDirectory || file.nameWithoutExtension in wallpapersToKeep) continue
|
if (file.isDirectory || file.nameWithoutExtension in wallpapersToKeep) continue
|
||||||
scope.launch {
|
|
||||||
file.delete()
|
file.delete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user