VERY experimental Nintendo Switch 2 emulator
C++
android: Move game deserialization to another thread
Charles Lombardo44e8e8c1691d
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.ktindex 6e09fa81d2..004b25b04d 100644--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt@@ -49,26 +49,33 @@ class GamesViewModel : ViewModel() {// Retrieve list of cached gamesval storedGames = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext).getStringSet(GameHelper.KEY_GAMES, emptySet())- if (storedGames!!.isNotEmpty()) {- val deserializedGames = mutableSetOf<Game>()- storedGames.forEach {- val game: Game- try {- game = Json.decodeFromString(it)- } catch (e: MissingFieldException) {- return@forEach- }- val gameExists =- DocumentFile.fromSingleUri(YuzuApplication.appContext, Uri.parse(game.path))- ?.exists()- if (gameExists == true) {- deserializedGames.add(game)+ viewModelScope.launch {+ withContext(Dispatchers.IO) {+ if (storedGames!!.isNotEmpty()) {+ val deserializedGames = mutableSetOf<Game>()+ storedGames.forEach {+ val game: Game+ try {+ game = Json.decodeFromString(it)+ } catch (e: MissingFieldException) {+ return@forEach+ }++ val gameExists =+ DocumentFile.fromSingleUri(+ YuzuApplication.appContext,+ Uri.parse(game.path)+ )?.exists()+ if (gameExists == true) {+ deserializedGames.add(game)+ }+ }+ setGames(deserializedGames.toList())}+ reloadGames(false)}- setGames(deserializedGames.toList())}- reloadGames(false)}fun setGames(games: List<Game>) {