Skip to content

Commit

Permalink
Merge pull request #138 from Erfa/develop
Browse files Browse the repository at this point in the history
Ensure all task exceptions are handled, to prevent crashes.
  • Loading branch information
theLee3 authored Jan 29, 2024
2 parents 0e842cb + 143d7e2 commit 431e52d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,16 @@ class Achievements(private var activityPluginBinding: ActivityPluginBinding) {
activity ?: return
achievementClient
.load(true)
.addOnCompleteListener { task ->
val data = task.result.get()
.addOnSuccessListener { annotatedData ->
val data = annotatedData.get()

if (data == null) {
result.error(
PluginError.FailedToLoadAchievements.errorCode(),
PluginError.FailedToLoadAchievements.errorMessage(),
null
)
return@addOnCompleteListener
return@addOnSuccessListener
}
val handler = CoroutineExceptionHandler { _, exception ->
result.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ class SaveGame(private var activityPluginBinding: ActivityPluginBinding) {
.setDescription(desc)
.build()
snapshotsClient.open(name, true, SnapshotsClient.RESOLUTION_POLICY_MOST_RECENTLY_MODIFIED)
.addOnCompleteListener { task ->
val snapshot = task.result.data
.addOnSuccessListener { annotatedData ->
val snapshot = annotatedData.data

if (snapshot != null) {
// Set the data payload for the snapshot
snapshot.snapshotContents.writeBytes(data.toByteArray())
Expand All @@ -77,6 +78,13 @@ class SaveGame(private var activityPluginBinding: ActivityPluginBinding) {
)
}
}
.addOnFailureListener {
result.error(
PluginError.FailedToSaveGame.errorCode(),
it.localizedMessage,
null
)
}
}

fun deleteGame(name: String, result: MethodChannel.Result) {
Expand Down

0 comments on commit 431e52d

Please sign in to comment.