Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2a9f5e1

Browse files
authored
fix: env. action buttons state (#23)
- the action buttons like (start/stop/update) did not change visibilityor enabled property when the workspace changed its running status- this fix regenerates the list of available actions in order to force are-draw in UI when workspace status changes-resolves#12
1 parent8f1d3a3 commit2a9f5e1

File tree

1 file changed

+41
-37
lines changed

1 file changed

+41
-37
lines changed

‎src/main/kotlin/com/coder/toolbox/CoderRemoteEnvironment.kt‎

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import com.jetbrains.toolbox.api.remoteDev.states.RemoteEnvironmentState
1717
importcom.jetbrains.toolbox.api.ui.actions.ActionDescription
1818
importkotlinx.coroutines.delay
1919
importkotlinx.coroutines.flow.MutableStateFlow
20-
importkotlinx.coroutines.flow.StateFlow
2120
importkotlinx.coroutines.flow.update
2221
importkotlinx.coroutines.isActive
2322
importkotlinx.coroutines.launch
@@ -44,46 +43,46 @@ class CoderRemoteEnvironment(
4443
overrideval description:MutableStateFlow<EnvironmentDescription>=
4544
MutableStateFlow(EnvironmentDescription.General(context.i18n.pnotr(workspace.templateDisplayName)))
4645

47-
overrideval actionsList:StateFlow<List<ActionDescription>>=MutableStateFlow(
48-
listOf(
49-
Action(context.i18n.ptrl("Open web terminal")) {
50-
context.cs.launch {
51-
BrowserUtil.browse(client.url.withPath("/${workspace.ownerName}/$name/terminal").toString()) {
52-
context.ui.showErrorInfoPopup(it)
53-
}
46+
overrideval actionsList:MutableStateFlow<List<ActionDescription>>=MutableStateFlow(getAvailableActions())
47+
48+
privatefungetAvailableActions():List<ActionDescription>=listOf(
49+
Action(context.i18n.ptrl("Open web terminal")) {
50+
context.cs.launch {
51+
BrowserUtil.browse(client.url.withPath("/${workspace.ownerName}/$name/terminal").toString()) {
52+
context.ui.showErrorInfoPopup(it)
5453
}
55-
},
56-
Action(context.i18n.ptrl("Open in dashboard")) {
57-
context.cs.launch {
58-
BrowserUtil.browse(client.url.withPath("/@${workspace.ownerName}/${workspace.name}").toString()) {
59-
context.ui.showErrorInfoPopup(it)
60-
}
54+
}
55+
},
56+
Action(context.i18n.ptrl("Open in dashboard")) {
57+
context.cs.launch {
58+
BrowserUtil.browse(client.url.withPath("/@${workspace.ownerName}/${workspace.name}").toString()) {
59+
context.ui.showErrorInfoPopup(it)
6160
}
62-
},
61+
}
62+
},
6363

64-
Action(context.i18n.ptrl("View template")) {
65-
context.cs.launch {
66-
BrowserUtil.browse(client.url.withPath("/templates/${workspace.templateName}").toString()) {
67-
context.ui.showErrorInfoPopup(it)
68-
}
64+
Action(context.i18n.ptrl("View template")) {
65+
context.cs.launch {
66+
BrowserUtil.browse(client.url.withPath("/templates/${workspace.templateName}").toString()) {
67+
context.ui.showErrorInfoPopup(it)
6968
}
70-
},
71-
Action(context.i18n.ptrl("Start"), enabled= { wsRawStatus.canStart() }) {
72-
val build= client.startWorkspace(workspace)
73-
workspace= workspace.copy(latestBuild= build)
74-
update(workspace, agent)
75-
},
76-
Action(context.i18n.ptrl("Stop"), enabled= { wsRawStatus.canStop() }) {
77-
val build= client.stopWorkspace(workspace)
78-
workspace= workspace.copy(latestBuild= build)
79-
update(workspace, agent)
80-
},
81-
Action(context.i18n.ptrl("Update"), enabled= { workspace.outdated }) {
82-
val build= client.updateWorkspace(workspace)
83-
workspace= workspace.copy(latestBuild= build)
84-
update(workspace, agent)
85-
})
86-
)
69+
}
70+
},
71+
Action(context.i18n.ptrl("Start"), enabled= { wsRawStatus.canStart() }) {
72+
val build= client.startWorkspace(workspace)
73+
workspace=workspace.copy(latestBuild= build)
74+
update(workspace, agent)
75+
},
76+
Action(context.i18n.ptrl("Stop"), enabled= { wsRawStatus.canStop() }) {
77+
val build= client.stopWorkspace(workspace)
78+
workspace=workspace.copy(latestBuild= build)
79+
update(workspace, agent)
80+
},
81+
Action(context.i18n.ptrl("Update"), enabled= {workspace.outdated }) {
82+
val build= client.updateWorkspace(workspace)
83+
workspace=workspace.copy(latestBuild= build)
84+
update(workspace, agent)
85+
})
8786

8887
/**
8988
* Update the workspace/agent status to the listeners, if it has changed.
@@ -92,6 +91,11 @@ class CoderRemoteEnvironment(
9291
this.workspace= workspace
9392
this.agent= agent
9493
wsRawStatus=WorkspaceAndAgentStatus.from(workspace, agent)
94+
// we have to regenerate the action list in order to force a redraw
95+
// because the actions don't have a state flow on the enabled property
96+
actionsList.update {
97+
getAvailableActions()
98+
}
9599
context.cs.launch {
96100
state.update {
97101
wsRawStatus.toRemoteEnvironmentState(context)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp