mirror of
				https://git.tardis.systems/mirrors/yuzu
				synced 2025-10-31 18:54:14 +01:00 
			
		
		
		
	Merge pull request #11915 from t895/startup-freeze
android: Move game deserialization to another thread
This commit is contained in:
		
						commit
						789c16305d
					
				| @ -49,26 +49,33 @@ class GamesViewModel : ViewModel() { | |||||||
|         // Retrieve list of cached games |         // Retrieve list of cached games | ||||||
|         val storedGames = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) |         val storedGames = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) | ||||||
|             .getStringSet(GameHelper.KEY_GAMES, emptySet()) |             .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 = |         viewModelScope.launch { | ||||||
|                     DocumentFile.fromSingleUri(YuzuApplication.appContext, Uri.parse(game.path)) |             withContext(Dispatchers.IO) { | ||||||
|                         ?.exists() |                 if (storedGames!!.isNotEmpty()) { | ||||||
|                 if (gameExists == true) { |                     val deserializedGames = mutableSetOf<Game>() | ||||||
|                     deserializedGames.add(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>) { |     fun setGames(games: List<Game>) { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user