@@ -25,6 +25,7 @@ import com.jetbrains.toolbox.api.remoteDev.states.RemoteEnvironmentState
2525import com.jetbrains.toolbox.api.ui.actions.ActionDescription
2626import com.jetbrains.toolbox.api.ui.components.TextType
2727import com.squareup.moshi.Moshi
28+ import kotlinx.coroutines.CoroutineName
2829import kotlinx.coroutines.Job
2930import kotlinx.coroutines.delay
3031import kotlinx.coroutines.flow.MutableStateFlow
@@ -81,72 +82,65 @@ class CoderRemoteEnvironment(
8182 private fun getAvailableActions (): List <ActionDescription > {
8283 val actions = mutableListOf<ActionDescription >()
8384 if (wsRawStatus.canStop()) {
84- actions.add(Action (context.i18n.ptrl(" Open web terminal" )) {
85- context.cs.launch {
86- context.desktop.browse(client.url.withPath(" /${workspace.ownerName} /$name /terminal" ).toString()) {
87- context.ui.showErrorInfoPopup(it)
88- }
85+ actions.add(Action (context, " Open web terminal" ) {
86+ context.desktop.browse(client.url.withPath(" /${workspace.ownerName} /$name /terminal" ).toString()) {
87+ context.ui.showErrorInfoPopup(it)
8988 }
90- })
89+ }
90+ )
9191 }
9292 actions.add(
93- Action (context.i18n.ptrl(" Open in dashboard" )) {
94- context.cs.launch {
95- context.desktop.browse(
96- client.url.withPath(" /@${workspace.ownerName} /${workspace.name} " ).toString()
97- ) {
98- context.ui.showErrorInfoPopup(it)
99- }
100- }
101- })
102-
103- actions.add(Action (context.i18n.ptrl(" View template" )) {
104- context.cs.launch {
105- context.desktop.browse(client.url.withPath(" /templates/${workspace.templateName} " ).toString()) {
93+ Action (context, " Open in dashboard" ) {
94+ context.desktop.browse(
95+ client.url.withPath(" /@${workspace.ownerName} /${workspace.name} " ).toString()
96+ ) {
10697 context.ui.showErrorInfoPopup(it)
10798 }
10899 }
109- })
100+ )
101+
102+ actions.add(Action (context, " View template" ) {
103+ context.desktop.browse(client.url.withPath(" /templates/${workspace.templateName} " ).toString()) {
104+ context.ui.showErrorInfoPopup(it)
105+ }
106+ }
107+ )
110108
111109 if (wsRawStatus.canStart()) {
112110 if (workspace.outdated) {
113- actions.add(Action (context.i18n.ptrl(" Update and start" )) {
114- context.cs.launch {
115- val build = client.updateWorkspace(workspace)
116- update(workspace.copy(latestBuild = build), agent)
117- }
118- })
111+ actions.add(Action (context, " Update and start" ) {
112+ val build = client.updateWorkspace(workspace)
113+ update(workspace.copy(latestBuild = build), agent)
114+ }
115+ )
119116 } else {
120- actions.add(Action (context.i18n.ptrl(" Start" )) {
121- context.cs.launch {
122- val build = client.startWorkspace(workspace)
123- update(workspace.copy(latestBuild = build), agent)
117+ actions.add(Action (context, " Start" ) {
118+ val build = client.startWorkspace(workspace)
119+ update(workspace.copy(latestBuild = build), agent)
124120
125- }
126- } )
121+ }
122+ )
127123 }
128124 }
129125 if (wsRawStatus.canStop()) {
130126 if (workspace.outdated) {
131- actions.add(Action (context.i18n.ptrl(" Update and restart" )) {
132- context.cs.launch {
133- val build = client.updateWorkspace(workspace)
134- update(workspace.copy(latestBuild = build), agent)
135- }
136- })
137- }
138- actions.add(Action (context.i18n.ptrl(" Stop" )) {
139- context.cs.launch {
140- tryStopSshConnection()
141-
142- val build = client.stopWorkspace(workspace)
127+ actions.add(Action (context, " Update and restart" ) {
128+ val build = client.updateWorkspace(workspace)
143129 update(workspace.copy(latestBuild = build), agent)
144130 }
145- })
131+ )
132+ }
133+ actions.add(Action (context, " Stop" ) {
134+ tryStopSshConnection()
135+
136+ val build = client.stopWorkspace(workspace)
137+ update(workspace.copy(latestBuild = build), agent)
138+ }
139+ )
146140 }
147141 actions.add(CoderDelimiter (context.i18n.pnotr(" " )))
148- actions.add(Action (context.i18n.ptrl( " Delete workspace" ) , highlightInRed = true ) {
149- context.cs.launch {
142+ actions.add(Action (context, " Delete workspace" , highlightInRed = true ) {
143+ context.cs.launch( CoroutineName ( " Delete Workspace Action " )) {
150144 var dialogText =
151145 if (wsRawStatus.canStop()) " This will close the workspace and remove all its information, including files, unsaved changes, history, and usage data."
152146 else " This will remove all information from the workspace, including files, unsaved changes, history, and usage data."
@@ -192,7 +186,7 @@ class CoderRemoteEnvironment(
192186 pollJob = pollNetworkMetrics()
193187 }
194188
195- private fun pollNetworkMetrics (): Job = context.cs.launch {
189+ private fun pollNetworkMetrics (): Job = context.cs.launch( CoroutineName ( " Network Metrics Poller " )) {
196190 context.logger.info(" Starting the network metrics poll job for $id " )
197191 while (isActive) {
198192 context.logger.debug(" Searching SSH command's PID for workspace $id ..." )
@@ -250,7 +244,7 @@ class CoderRemoteEnvironment(
250244 actionsList.update {
251245 getAvailableActions()
252246 }
253- context.cs.launch {
247+ context.cs.launch( CoroutineName ( " Workspace Status Updater " )) {
254248 state.update {
255249 wsRawStatus.toRemoteEnvironmentState(context)
256250 }
@@ -285,7 +279,7 @@ class CoderRemoteEnvironment(
285279 */
286280 fun startSshConnection (): Boolean {
287281 if (wsRawStatus.ready() && ! isConnected.value) {
288- context.cs.launch {
282+ context.cs.launch( CoroutineName ( " SSH Connection Trigger " )) {
289283 connectionRequest.update {
290284 true
291285 }
@@ -306,7 +300,7 @@ class CoderRemoteEnvironment(
306300 WorkspaceAndAgentStatus .DELETING .toRemoteEnvironmentState(context)
307301 }
308302
309- context.cs.launch {
303+ context.cs.launch( CoroutineName ( " Workspace Deletion Poller " )) {
310304 withTimeout(5 .minutes) {
311305 var workspaceStillExists = true
312306 while (context.cs.isActive && workspaceStillExists) {
0 commit comments