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: run UI logic on the main thread [WPB-9458] 🍒 #3056

Merged
merged 2 commits into from
May 31, 2024
Merged
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
29 changes: 14 additions & 15 deletions app/src/main/kotlin/com/wire/android/ui/WireActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ import com.wire.android.navigation.NavigationGraph
import com.wire.android.navigation.navigateToItem
import com.wire.android.navigation.rememberNavigator
import com.wire.android.ui.calling.getIncomingCallIntent
import com.wire.android.ui.calling.getOutgoingCallIntent
import com.wire.android.ui.calling.getOngoingCallIntent
import com.wire.android.ui.calling.getOutgoingCallIntent
import com.wire.android.ui.common.snackbar.LocalSnackbarHostState
import com.wire.android.ui.common.topappbar.CommonTopAppBar
import com.wire.android.ui.common.topappbar.CommonTopAppBarViewModel
Expand Down Expand Up @@ -151,7 +151,7 @@ class WireActivity : AppCompatActivity() {

WindowCompat.setDecorFitsSystemWindows(window, false)

lifecycleScope.launch(Dispatchers.Default) {
lifecycleScope.launch {

appLogger.i("$TAG persistent connection status")
viewModel.observePersistentConnectionStatus()
Expand All @@ -167,12 +167,11 @@ class WireActivity : AppCompatActivity() {
InitialAppState.LOGGED_IN -> HomeScreenDestination
}
appLogger.i("$TAG composable content")
withContext(Dispatchers.Main) {
setComposableContent(startDestination) {
appLogger.i("$TAG splash hide")
shouldKeepSplashOpen = false
handleDeepLink(intent, savedInstanceState)
}

setComposableContent(startDestination) {
appLogger.i("$TAG splash hide")
shouldKeepSplashOpen = false
handleDeepLink(intent, savedInstanceState)
}
}
}
Expand Down Expand Up @@ -237,17 +236,17 @@ class WireActivity : AppCompatActivity() {

// This setup needs to be done after the navigation graph is created, because building the graph takes some time,
// and if any NavigationCommand is executed before the graph is fully built, it will cause a NullPointerException.
setUpNavigation(navigator.navController, onComplete)
handleScreenshotCensoring()
handleDialogs(navigator::navigate)
SetUpNavigation(navigator.navController, onComplete)
HandleScreenshotCensoring()
HandleDialogs(navigator::navigate)
}
}
}
}
}

@Composable
private fun setUpNavigation(
private fun SetUpNavigation(
navController: NavHostController,
onComplete: () -> Unit,
) {
Expand Down Expand Up @@ -281,7 +280,7 @@ class WireActivity : AppCompatActivity() {
}

@Composable
private fun handleScreenshotCensoring() {
private fun HandleScreenshotCensoring() {
LaunchedEffect(viewModel.globalAppState.screenshotCensoringEnabled) {
if (viewModel.globalAppState.screenshotCensoringEnabled) {
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
Expand All @@ -293,7 +292,7 @@ class WireActivity : AppCompatActivity() {

@Suppress("ComplexMethod")
@Composable
private fun handleDialogs(navigate: (NavigationCommand) -> Unit) {
private fun HandleDialogs(navigate: (NavigationCommand) -> Unit) {
val context = LocalContext.current
with(featureFlagNotificationViewModel.featureFlagState) {
if (shouldShowTeamAppLockDialog) {
Expand Down Expand Up @@ -471,7 +470,7 @@ class WireActivity : AppCompatActivity() {
override fun onResume() {
super.onResume()

lifecycleScope.launch(Dispatchers.Default) {
lifecycleScope.launch {
lockCodeTimeManager.get().observeAppLock()
// Listen to one flow in a lifecycle-aware manner using flowWithLifecycle
.flowWithLifecycle(lifecycle, Lifecycle.State.STARTED)
Expand Down
Loading