From a7c7ae0081d72db78a054e86f183e770ea71802a Mon Sep 17 00:00:00 2001 From: Konstantin Hudyakov Date: Mon, 6 Jul 2026 18:02:44 +0300 Subject: [PATCH] [terminal] IJPL-249368 Do not abort application termination if user canceled terminal processes check This exception actually prevented the application closing - let's catch it and interpret as "do not perform any checks and proceed to project closing". Also, let's give this progress a meaningful title since there are reports that users cancel it (and they actually see it). (cherry picked from commit 72b1d5d5f70be839c5aa463a02028f9883b20ff2) IJ-CR-212635 GitOrigin-RevId: 709be7b5bcbf66e6395d7bd4a2951af284536561 --- .../impl/TerminalProcessesClosingNotifier.kt | 18 ++++++++++++++++-- .../messages/TerminalBundle.properties | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/plugins/terminal/frontend/src/com/intellij/terminal/frontend/toolwindow/impl/TerminalProcessesClosingNotifier.kt b/plugins/terminal/frontend/src/com/intellij/terminal/frontend/toolwindow/impl/TerminalProcessesClosingNotifier.kt index 22c4ee628403..cf8549b8f80e 100644 --- a/plugins/terminal/frontend/src/com/intellij/terminal/frontend/toolwindow/impl/TerminalProcessesClosingNotifier.kt +++ b/plugins/terminal/frontend/src/com/intellij/terminal/frontend/toolwindow/impl/TerminalProcessesClosingNotifier.kt @@ -8,6 +8,7 @@ import com.intellij.openapi.application.ApplicationListener import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.components.serviceIfCreated import com.intellij.openapi.extensions.ExtensionNotApplicableException +import com.intellij.openapi.progress.ProgressManager import com.intellij.openapi.project.Project import com.intellij.openapi.project.ProjectManager import com.intellij.openapi.project.VetoableProjectManagerListener @@ -19,12 +20,14 @@ import com.intellij.terminal.frontend.toolwindow.TerminalToolWindowTabsManager import com.intellij.terminal.frontend.view.TerminalView import com.intellij.terminal.ui.TerminalWidget import com.intellij.util.asDisposable +import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Deferred import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll import kotlinx.coroutines.coroutineScope +import org.jetbrains.plugins.terminal.TerminalBundle import org.jetbrains.plugins.terminal.TerminalToolWindowManager import java.time.LocalDateTime @@ -78,9 +81,20 @@ internal object TerminalProcessesClosingNotifier : VetoableProjectManagerListene return true } - val tabTitlesToConfirm = runWithModalProgressBlocking(project, "") { - collectTabTitlesToConfirm(reworkedViews, classicWidgets) + val tabTitlesToConfirm = try { + runWithModalProgressBlocking(project, TerminalBundle.message("checking.running.terminal.processes.progress")) { + collectTabTitlesToConfirm(reworkedViews, classicWidgets) + } } + catch (_: CancellationException) { + ProgressManager.checkCanceled() + // User pressed "cancel" in the progress dialog. + // Since the user's intention is to close the project, + // consider that the user wants to skip any additional checks and finally close the project. + project.putUserData(PROCESSES_TERMINATION_CONFIRMED_TIME_KEY, LocalDateTime.now()) + return true + } + if (tabTitlesToConfirm.isEmpty()) { return true } diff --git a/plugins/terminal/resources/messages/TerminalBundle.properties b/plugins/terminal/resources/messages/TerminalBundle.properties index 136ae0b15155..3c444e9a580f 100644 --- a/plugins/terminal/resources/messages/TerminalBundle.properties +++ b/plugins/terminal/resources/messages/TerminalBundle.properties @@ -187,6 +187,7 @@ progress.text.running.terminal=Running the terminal\u2026 session.terminated.text=Session completed see.ide.log.error.description=See IDE log (Help | {0}) for the details. local.environment.name=Host +checking.running.terminal.processes.progress=Checking Running Terminal Processes closing.terminal.processes.progress=Closing Terminal Processes group.advanced.settings.terminal=Terminal