Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Thread sync throwing exception sometimes crashing app #3634

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.homeassistant.companion.android.thread.ThreadManager
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
Expand Down Expand Up @@ -62,7 +63,7 @@ class DeveloperSettingsPresenterImpl @Inject constructor(
override fun runThreadDebug(context: Context, serverId: Int) {
mainScope.launch {
try {
when (val syncResult = threadManager.syncPreferredDataset(context, serverId, this)) {
when (val syncResult = threadManager.syncPreferredDataset(context, serverId, CoroutineScope(coroutineContext + SupervisorJob()))) {
is ThreadManager.SyncResult.ServerUnsupported ->
view.onThreadDebugResult(context.getString(commonR.string.thread_debug_result_unsupported_server), false)
is ThreadManager.SyncResult.OnlyOnServer -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import io.homeassistant.companion.android.util.UrlUtil
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down Expand Up @@ -333,7 +334,7 @@ class WebViewPresenterImpl @Inject constructor(

mainScope.launch {
val deviceThreadIntent = try {
when (val result = threadUseCase.syncPreferredDataset(context, serverId, this)) {
when (val result = threadUseCase.syncPreferredDataset(context, serverId, CoroutineScope(coroutineContext + SupervisorJob()))) {
is ThreadManager.SyncResult.OnlyOnDevice -> result.exportIntent
is ThreadManager.SyncResult.AllHaveCredentials -> result.exportIntent
else -> null
Expand Down