@@ -10,6 +10,7 @@ import com.coder.toolbox.sdk.v2.models.Workspace
10
10
import com.coder.toolbox.sdk.v2.models.WorkspaceAgent
11
11
import com.coder.toolbox.sdk.v2.models.WorkspaceStatus
12
12
import com.coder.toolbox.settings.CoderSettings
13
+ import com.jetbrains.toolbox.api.localization.LocalizableString
13
14
import kotlinx.coroutines.TimeoutCancellationException
14
15
import kotlinx.coroutines.delay
15
16
import kotlinx.coroutines.flow.StateFlow
@@ -48,7 +49,7 @@ open class CoderProtocolHandler(
48
49
val deploymentURL = params.url() ? : askUrl()
49
50
if (deploymentURL.isNullOrBlank()) {
50
51
context.logger.error(" Query parameter \" $URL \" is missing from URI $uri " )
51
- context.ui.showErrorInfoPopup (MissingArgumentException (" Can't handle URI because query parameter \" $URL \" is missing" ))
52
+ context.showErrorPopup (MissingArgumentException (" Can't handle URI because query parameter \" $URL \" is missing" ))
52
53
return
53
54
}
54
55
@@ -57,50 +58,39 @@ open class CoderProtocolHandler(
57
58
authenticate(deploymentURL, queryToken)
58
59
} catch (ex: Exception ) {
59
60
context.logger.error(ex, " Query parameter \" $TOKEN \" is missing from URI $uri " )
60
- context.ui.showErrorInfoPopup(
61
- IllegalStateException (
62
- humanizeConnectionError(
63
- deploymentURL.toURL(),
64
- true ,
65
- ex
66
- )
67
- )
68
- )
61
+ context.showErrorPopup(IllegalStateException (humanizeConnectionError(deploymentURL.toURL(), true , ex)))
69
62
return
70
63
}
71
64
72
65
// TODO: Show a dropdown and ask for the workspace if missing. Right now it's not possible because dialogs are quite limited
73
66
val workspaceName = params.workspace()
74
67
if (workspaceName.isNullOrBlank()) {
75
68
context.logger.error(" Query parameter \" $WORKSPACE \" is missing from URI $uri " )
76
- context.ui.showErrorInfoPopup (MissingArgumentException (" Can't handle URI because query parameter \" $WORKSPACE \" is missing" ))
69
+ context.showErrorPopup (MissingArgumentException (" Can't handle URI because query parameter \" $WORKSPACE \" is missing" ))
77
70
return
78
71
}
79
72
80
73
val workspaces = restClient.workspaces()
81
74
val workspace = workspaces.firstOrNull { it.name == workspaceName }
82
75
if (workspace == null ) {
83
76
context.logger.error(" There is no workspace with name $workspaceName on $deploymentURL " )
84
- context.ui.showErrorInfoPopup (MissingArgumentException (" Can't handle URI because workspace with name $workspaceName does not exist" ))
77
+ context.showErrorPopup (MissingArgumentException (" Can't handle URI because workspace with name $workspaceName does not exist" ))
85
78
return
86
79
}
87
80
88
81
when (workspace.latestBuild.status) {
89
82
WorkspaceStatus .PENDING , WorkspaceStatus .STARTING ->
90
83
if (restClient.waitForReady(workspace) != true ) {
91
84
context.logger.error(" $workspaceName from $deploymentURL could not be ready on time" )
92
- context.ui.showErrorInfoPopup (MissingArgumentException (" Can't handle URI because workspace $workspaceName could not be ready on time" ))
85
+ context.showErrorPopup (MissingArgumentException (" Can't handle URI because workspace $workspaceName could not be ready on time" ))
93
86
return
94
87
}
95
88
96
89
WorkspaceStatus .STOPPING , WorkspaceStatus .STOPPED ,
97
90
WorkspaceStatus .CANCELING , WorkspaceStatus .CANCELED -> {
98
91
if (context.settings.disableAutostart) {
99
- context.ui.showWindow()
100
- context.envPageManager.showPluginEnvironmentsPage(true )
101
-
102
92
context.logger.warn(" $workspaceName from $deploymentURL is not started and autostart is disabled." )
103
- context.ui. showInfoPopup(
93
+ context.showInfoPopup(
104
94
context.i18n.pnotr(" $workspaceName is not running" ),
105
95
context.i18n.ptrl(" Can't handle URI because workspace is not running and autostart is disabled. Please start the workspace manually and execute the URI again." ),
106
96
context.i18n.ptrl(" OK" )
@@ -111,14 +101,14 @@ open class CoderProtocolHandler(
111
101
restClient.startWorkspace(workspace)
112
102
if (restClient.waitForReady(workspace) != true ) {
113
103
context.logger.error(" $workspaceName from $deploymentURL could not be started on time" )
114
- context.ui.showErrorInfoPopup (MissingArgumentException (" Can't handle URI because workspace $workspaceName could not be started on time" ))
104
+ context.showErrorPopup (MissingArgumentException (" Can't handle URI because workspace $workspaceName could not be started on time" ))
115
105
return
116
106
}
117
107
}
118
108
119
109
WorkspaceStatus .FAILED , WorkspaceStatus .DELETING , WorkspaceStatus .DELETED -> {
120
110
context.logger.error(" Unable to connect to $workspaceName from $deploymentURL " )
121
- context.ui.showErrorInfoPopup (MissingArgumentException (" Can't handle URI because because we're unable to connect to workspace $workspaceName " ))
111
+ context.showErrorPopup (MissingArgumentException (" Can't handle URI because because we're unable to connect to workspace $workspaceName " ))
122
112
return
123
113
}
124
114
@@ -325,6 +315,25 @@ internal fun getMatchingAgent(
325
315
return agent
326
316
}
327
317
318
+ private suspend fun CoderToolboxContext.showErrorPopup (error : Throwable ) {
319
+ popupPluginMainPage()
320
+ this .ui.showErrorInfoPopup(error)
321
+ }
322
+
323
+ private suspend fun CoderToolboxContext.showInfoPopup (
324
+ title : LocalizableString ,
325
+ message : LocalizableString ,
326
+ okLabel : LocalizableString
327
+ ) {
328
+ popupPluginMainPage()
329
+ this .ui.showInfoPopup(title, message, okLabel)
330
+ }
331
+
332
+ private fun CoderToolboxContext.popupPluginMainPage () {
333
+ this .ui.showWindow()
334
+ this .envPageManager.showPluginEnvironmentsPage(true )
335
+ }
336
+
328
337
/* *
329
338
* Suspends the coroutine until first true value is received.
330
339
*/
0 commit comments