@@ -46,6 +46,7 @@ import io.gitpod.jetbrains.gateway.common.GitpodConnectionHandleFactory
4646import io.gitpod.jetbrains.icons.GitpodIcons
4747import kotlinx.coroutines.*
4848import kotlinx.coroutines.future.await
49+ import java.awt.Component
4950import java.net.URL
5051import java.net.http.HttpClient
5152import java.net.http.HttpRequest
@@ -71,6 +72,17 @@ class GitpodConnectionProvider : GatewayConnectionProvider {
7172 private val jacksonMapper = jacksonObjectMapper()
7273 .configure(DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false )
7374
75+
76+ private fun showTimedOutDialogDialog (workspaceId : String , detail : String? ) {
77+ val title = " Workspace Timed Out"
78+ val message = " Your workspace $workspaceId has timed out${if (detail.isNullOrBlank()) " " else " : $detail " } ."
79+ val okButton = Messages .getOkButton()
80+ val options = arrayOf(okButton)
81+ val defaultIndex = 0
82+ val icon = Messages .getInformationIcon()
83+ Messages .showDialog(message, title, options, defaultIndex, icon)
84+ }
85+
7486 override suspend fun connect (
7587 parameters : Map <String , String >,
7688 requestor : ConnectionRequestor
@@ -188,6 +200,7 @@ class GitpodConnectionProvider : GatewayConnectionProvider {
188200 var thinClientJob: Job ? = null
189201
190202 var lastUpdate: WorkspaceInstance ? = null
203+ var canceledByGitpod = false
191204 try {
192205 for (update in updates) {
193206 try {
@@ -255,8 +268,8 @@ class GitpodConnectionProvider : GatewayConnectionProvider {
255268 statusMessage.text = " "
256269 }
257270 }
258-
259271 if (update.status.phase == " stopping" || update.status.phase == " stopped" ) {
272+ canceledByGitpod = true
260273 thinClientJob?.cancel()
261274 thinClient?.close()
262275 }
@@ -295,11 +308,34 @@ class GitpodConnectionProvider : GatewayConnectionProvider {
295308 SshHostTunnelConnector (credentials),
296309 URI (joinLinkResp.joinLink)
297310 )
311+ var triggeredClientClosed = false
298312 clientHandle.clientClosed.advise(connectionLifetime) {
299- application.invokeLater {
300- GlobalScope .launch {
301- // Delay for 5 seconds to wait the thinClient actually close
302- delay(5000 )
313+ // Been canceled by user
314+ if (! canceledByGitpod) {
315+ application.invokeLater {
316+ connectionLifetime.terminate()
317+ }
318+ return @advise
319+ }
320+ if (triggeredClientClosed) {
321+ return @advise
322+ }
323+ triggeredClientClosed = true
324+ // Wait until workspace is stopped
325+ suspend fun waitUntilStopped (): Boolean {
326+ while (lastUpdate.status.phase != " stopped" ) {
327+ delay(1000 )
328+ }
329+ return true
330+ }
331+ // Check if it's timed out, if so, show timed out dialog
332+ GlobalScope .launch {
333+ val isInStoppedPhase = waitUntilStopped()
334+ val isTimedOut = isInStoppedPhase && phaseMessage.text == " Timed Out"
335+ application.invokeLater {
336+ if (isTimedOut) {
337+ showTimedOutDialogDialog(connectParams.resolvedWorkspaceId, lastUpdate.status.conditions.timeout)
338+ }
303339 connectionLifetime.terminate()
304340 }
305341 }
0 commit comments