summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Charles Lombardo2023-10-29 14:15:37 -0400
committerGravatar Charles Lombardo2023-10-29 21:29:32 -0400
commit25815900236c45a340feb7654b6d49792c10c4f4 (patch)
tree653bb69ded0b4b2cbdb03a96ead617484e13d3df /src
parentMerge pull request #11866 from liamwhite/more-qt-nonsense (diff)
downloadyuzu-25815900236c45a340feb7654b6d49792c10c4f4.tar.gz
yuzu-25815900236c45a340feb7654b6d49792c10c4f4.tar.xz
yuzu-25815900236c45a340feb7654b6d49792c10c4f4.zip
android: Move game deserialization to another thread
Deserializing games from the cache in shared preferences was done on the main thread and could cause a stutter on startup.
Diffstat (limited to 'src')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt39
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() {
49 // Retrieve list of cached games 49 // Retrieve list of cached games
50 val storedGames = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) 50 val storedGames = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext)
51 .getStringSet(GameHelper.KEY_GAMES, emptySet()) 51 .getStringSet(GameHelper.KEY_GAMES, emptySet())
52 if (storedGames!!.isNotEmpty()) {
53 val deserializedGames = mutableSetOf<Game>()
54 storedGames.forEach {
55 val game: Game
56 try {
57 game = Json.decodeFromString(it)
58 } catch (e: MissingFieldException) {
59 return@forEach
60 }
61 52
62 val gameExists = 53 viewModelScope.launch {
63 DocumentFile.fromSingleUri(YuzuApplication.appContext, Uri.parse(game.path)) 54 withContext(Dispatchers.IO) {
64 ?.exists() 55 if (storedGames!!.isNotEmpty()) {
65 if (gameExists == true) { 56 val deserializedGames = mutableSetOf<Game>()
66 deserializedGames.add(game) 57 storedGames.forEach {
58 val game: Game
59 try {
60 game = Json.decodeFromString(it)
61 } catch (e: MissingFieldException) {
62 return@forEach
63 }
64
65 val gameExists =
66 DocumentFile.fromSingleUri(
67 YuzuApplication.appContext,
68 Uri.parse(game.path)
69 )?.exists()
70 if (gameExists == true) {
71 deserializedGames.add(game)
72 }
73 }
74 setGames(deserializedGames.toList())
67 } 75 }
76 reloadGames(false)
68 } 77 }
69 setGames(deserializedGames.toList())
70 } 78 }
71 reloadGames(false)
72 } 79 }
73 80
74 fun setGames(games: List<Game>) { 81 fun setGames(games: List<Game>) {