diff options
author | liamwhite <liamwhite@users.noreply.github.com> | 2023-10-30 14:59:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-30 14:59:45 +0100 |
commit | 789c16305deae9f58567afb56560e0ac22caed7a (patch) | |
tree | 02c70f5703980580b971d11b8863cddf6c46ca06 /src/android | |
parent | Merge pull request #11910 from liamwhite/surface-lost-on-creation (diff) | |
parent | android: Move game deserialization to another thread (diff) | |
download | yuzu-789c16305deae9f58567afb56560e0ac22caed7a.tar yuzu-789c16305deae9f58567afb56560e0ac22caed7a.tar.gz yuzu-789c16305deae9f58567afb56560e0ac22caed7a.tar.bz2 yuzu-789c16305deae9f58567afb56560e0ac22caed7a.tar.lz yuzu-789c16305deae9f58567afb56560e0ac22caed7a.tar.xz yuzu-789c16305deae9f58567afb56560e0ac22caed7a.tar.zst yuzu-789c16305deae9f58567afb56560e0ac22caed7a.zip |
Diffstat (limited to 'src/android')
-rw-r--r-- | src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt | 39 |
1 files changed, 23 insertions, 16 deletions
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.kt index 6e09fa81d..004b25b04 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 games val 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>) { |