@@ -32,6 +32,7 @@ import soy.iko.opencode.ui.screens.SessionsScreen
3232fun OpencodeApp(state: UiState, dispatch: (Event) -> Unit) {
3333 val snackbar = remember { SnackbarHostState() }
3434 var showStopConfirm by remember { mutableStateOf(false) }
35+ var showDisconnectConfirm by remember { mutableStateOf(false) }
3536
3637 LaunchedEffect(state.error) {
3738 state.error?.let {
@@ -49,7 +50,8 @@ fun OpencodeApp(state: UiState, dispatch: (Event) -> Unit) {
4950 when (state.screen) {
5051 // Leaving mid-generation would silently drop the reply, so confirm first.
5152 Screen.Chat -> if (state.generating) showStopConfirm = true else dispatch(Event.NavigateToSessions)
52− Screen.Sessions -> dispatch(Event.NavigateToConnect)
53+ // Disconnecting drops the server session, so guard the back button.
54+ Screen.Sessions -> showDisconnectConfirm = true
5355 Screen.Connect -> Unit
5456 }
5557 }
@@ -76,6 +78,27 @@ fun OpencodeApp(state: UiState, dispatch: (Event) -> Unit) {
7678 )
7779 }
7880
81+ if (showDisconnectConfirm) {
82+ AlertDialog(
83+ onDismissRequest = { showDisconnectConfirm = false },
84+ title = { Text("Disconnect?") },
85+ text = { Text("You will be disconnected from the server.") },
86+ confirmButton = {
87+ TextButton(onClick = {
88+ showDisconnectConfirm = false
89+ dispatch(Event.NavigateToConnect)
90+ }) {
91+ Text("Disconnect")
92+ }
93+ },
94+ dismissButton = {
95+ TextButton(onClick = { showDisconnectConfirm = false }) {
96+ Text("Cancel")
97+ }
98+ },
99+ )
100+ }
101+
79102 Scaffold(snackbarHost = { SnackbarHost(snackbar) }) { padding ->
80103 AnimatedContent(
81104 targetState = state.screen,