diff --git a/composeApp/src/androidMain/kotlin/com/nuvio/app/core/ui/PlatformExitApp.android.kt b/composeApp/src/androidMain/kotlin/com/nuvio/app/core/ui/PlatformExitApp.android.kt new file mode 100644 index 00000000..53b64a7a --- /dev/null +++ b/composeApp/src/androidMain/kotlin/com/nuvio/app/core/ui/PlatformExitApp.android.kt @@ -0,0 +1,9 @@ +package com.nuvio.app.core.ui + +import android.os.Process +import kotlin.system.exitProcess + +actual fun platformExitApp() { + Process.killProcess(Process.myPid()) + exitProcess(0) +} diff --git a/composeApp/src/commonMain/kotlin/com/nuvio/app/App.kt b/composeApp/src/commonMain/kotlin/com/nuvio/app/App.kt index e9167521..6a8e1125 100644 --- a/composeApp/src/commonMain/kotlin/com/nuvio/app/App.kt +++ b/composeApp/src/commonMain/kotlin/com/nuvio/app/App.kt @@ -80,7 +80,9 @@ import com.nuvio.app.core.sync.SyncManager import com.nuvio.app.core.ui.NuvioNavigationBar import com.nuvio.app.core.ui.NuvioContinueWatchingActionSheet import com.nuvio.app.core.ui.NuvioPosterActionSheet +import com.nuvio.app.core.ui.NuvioStatusModal import com.nuvio.app.core.ui.PlatformBackHandler +import com.nuvio.app.core.ui.platformExitApp import com.nuvio.app.core.ui.configurePlatformImageLoader import com.nuvio.app.core.ui.NuvioToastHost import com.nuvio.app.core.ui.NuvioToastController @@ -421,6 +423,7 @@ private fun MainAppContent( val hapticFeedback = LocalHapticFeedback.current val coroutineScope = rememberCoroutineScope() var selectedTab by rememberSaveable { mutableStateOf(AppScreenTab.Home) } + var showExitConfirmation by rememberSaveable { mutableStateOf(false) } var selectedPosterForActions by remember { mutableStateOf(null) } var selectedContinueWatchingForActions by remember { mutableStateOf(null) } var showLibraryListPicker by remember { mutableStateOf(false) } @@ -827,8 +830,14 @@ private fun MainAppContent( ) { composable { PlatformBackHandler( - enabled = selectedTab != AppScreenTab.Home, - onBack = { selectedTab = AppScreenTab.Home }, + enabled = true, + onBack = { + if (selectedTab != AppScreenTab.Home) { + selectedTab = AppScreenTab.Home + } else { + showExitConfirmation = !showExitConfirmation + } + }, ) BoxWithConstraints(modifier = Modifier.fillMaxSize()) { @@ -1673,6 +1682,21 @@ private fun MainAppContent( }, ) + NuvioStatusModal( + title = "Exit app", + message = "Do you want to exit the app?", + isVisible = showExitConfirmation, + confirmText = "Yes", + dismissText = "No", + onConfirm = { + showExitConfirmation = false + platformExitApp() + }, + onDismiss = { + showExitConfirmation = false + }, + ) + androidx.compose.animation.AnimatedVisibility( visible = !initialHomeReady || profileSwitchLoading, enter = fadeIn(), diff --git a/composeApp/src/commonMain/kotlin/com/nuvio/app/core/ui/PlatformExitApp.kt b/composeApp/src/commonMain/kotlin/com/nuvio/app/core/ui/PlatformExitApp.kt new file mode 100644 index 00000000..4f2076cb --- /dev/null +++ b/composeApp/src/commonMain/kotlin/com/nuvio/app/core/ui/PlatformExitApp.kt @@ -0,0 +1,3 @@ +package com.nuvio.app.core.ui + +expect fun platformExitApp() diff --git a/composeApp/src/iosMain/kotlin/com/nuvio/app/core/ui/PlatformExitApp.ios.kt b/composeApp/src/iosMain/kotlin/com/nuvio/app/core/ui/PlatformExitApp.ios.kt new file mode 100644 index 00000000..7ef17934 --- /dev/null +++ b/composeApp/src/iosMain/kotlin/com/nuvio/app/core/ui/PlatformExitApp.ios.kt @@ -0,0 +1,3 @@ +package com.nuvio.app.core.ui + +actual fun platformExitApp() = Unit