Skip to content

Commit

Permalink
Adopt blocking approach for reacting to tile events, inspired by #3974
Browse files Browse the repository at this point in the history
  • Loading branch information
slovdahl committed Oct 27, 2023
1 parent c5a4001 commit 7ef7a61
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.guava.future
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import javax.inject.Inject
import io.homeassistant.companion.android.common.R as commonR

Expand Down Expand Up @@ -94,8 +96,8 @@ class TemplateTile : TileService() {
.build()
}

override fun onTileAddEvent(requestParams: EventBuilders.TileAddEvent) {
serviceScope.launch {
override fun onTileAddEvent(requestParams: EventBuilders.TileAddEvent): Unit = runBlocking {
withContext(Dispatchers.IO) {
/**
* When the app is updated from an older version (which only supported a single Template Tile),
* and the user is adding a new Template Tile, we can't tell for sure if it's the 1st or 2nd Tile.
Expand All @@ -115,8 +117,8 @@ class TemplateTile : TileService() {
}
}

override fun onTileRemoveEvent(requestParams: EventBuilders.TileRemoveEvent) {
serviceScope.launch {
override fun onTileRemoveEvent(requestParams: EventBuilders.TileRemoveEvent): Unit = runBlocking {
withContext(Dispatchers.IO) {
wearPrefsRepository.removeTemplateTile(requestParams.tileId)
}
}
Expand Down

0 comments on commit 7ef7a61

Please sign in to comment.