@@ -39,7 +39,6 @@ import androidx.compose.runtime.Composable
3939import androidx.compose.runtime.getValue
4040import androidx.compose.runtime.mutableIntStateOf
4141import androidx.compose.runtime.mutableStateOf
42- import androidx.compose.runtime.rememberCoroutineScope
4342import androidx.compose.runtime.saveable.rememberSaveable
4443import androidx.compose.runtime.setValue
4544import androidx.compose.ui.Alignment
@@ -52,6 +51,8 @@ import androidx.compose.ui.unit.sp
5251import androidx.navigation.NavController
5352import androidx.navigation.NavHostController
5453import androidx.navigation.compose.rememberNavController
54+ import kotlinx.coroutines.CoroutineScope
55+ import kotlinx.coroutines.Dispatchers
5556import kotlinx.coroutines.launch
5657import org.vonderheidt.hips.navigation.Screen
5758import org.vonderheidt.hips.ui.theme.HiPSTheme
@@ -80,9 +81,6 @@ fun HomeScreen(navController: NavController, modifier: Modifier) {
8081 val currentLocalContext = LocalContext .current
8182 val clipboardManager = currentLocalContext.getSystemService(Context .CLIPBOARD_SERVICE ) as ClipboardManager
8283
83- // Coroutines
84- val coroutineScope = rememberCoroutineScope()
85-
8684 // UI components
8785 Column (
8886 modifier = modifier
@@ -253,7 +251,9 @@ fun HomeScreen(navController: NavController, modifier: Modifier) {
253251 isLoading = true
254252
255253 // Call encode or decode function as coroutine, depending on mode selected
256- coroutineScope.launch {
254+ // Use Dispatchers.Default since LLM inference is CPU-bound
255+ // Keep encapsulation of coroutine vs if-else like this so the loading animation works
256+ CoroutineScope (Dispatchers .Default ).launch {
257257 if (selectedMode == 0 ) {
258258 coverText = Steganography .encode(context, secretMessage)
259259 }
0 commit comments