package com.suno.android.common_ui.effects import android.content.Context import androidx.browser.customtabs.CustomTabsIntent import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.core.net.toUri @Composable fun LaunchCustomTabEffect( context: Context, url: String, onSuccessfulLaunch: () -> Unit, onException: (exception: Exception) -> Unit, ) { // Bind to the Custom Tabs service LaunchedEffect(Unit) { try { val builder = CustomTabsIntent.Builder() val customTabsIntent = builder.build() customTabsIntent.launchUrl( context, url.toUri(), ) // todo: I really hate this as a solution that works. There's also minor graphical flickering that happens... onSuccessfulLaunch.invoke() } catch (exception: Exception) { onException.invoke(exception) } } }