@@ -27,13 +27,25 @@ export interface RemoteDetails extends vscode.Disposable {
27
27
28
28
export class Remote {
29
29
public constructor (
30
+ // We use the proposed API to get access to useCustom in dialogs.
30
31
private readonly vscodeProposed : typeof vscode ,
31
32
private readonly storage : Storage ,
32
33
private readonly commands : Commands ,
33
34
private readonly mode : vscode . ExtensionMode ,
34
35
) { }
35
36
36
- private async waitForRunning ( restClient : Api , workspace : Workspace ) : Promise < Workspace > {
37
+ private async confirmStart ( workspaceName : string ) : Promise < boolean > {
38
+ const action = await this . vscodeProposed . window . showInformationMessage ( `Start ${ workspaceName } ?` , {
39
+ useCustom : true ,
40
+ modal : true ,
41
+ } , "Start" )
42
+ return action === "Start"
43
+ }
44
+
45
+ /**
46
+ * Try to get the workspace running. Return undefined if the user canceled.
47
+ */
48
+ private async maybeWaitForRunning ( restClient : Api , workspace : Workspace ) : Promise < Workspace | undefined > {
37
49
// Maybe already running?
38
50
if ( workspace . latest_build . status === "running" ) {
39
51
return workspace
@@ -83,18 +95,24 @@ export class Remote {
83
95
workspace = await waitForBuild ( restClient , writeEmitter , workspace )
84
96
break
85
97
case "stopped" :
98
+ if ( ! ( await this . confirmStart ( workspaceName ) ) ) {
99
+ return undefined
100
+ }
86
101
this . storage . writeToCoderOutputChannel ( `Starting ${ workspaceName } ...` )
87
102
workspace = await startWorkspace ( restClient , workspace )
88
103
break
89
104
case "failed" :
90
105
// On a first attempt, we will try starting a failed workspace
91
106
// (for example canceling a start seems to cause this state).
92
107
if ( attempts === 1 ) {
108
+ if ( ! ( await this . confirmStart ( workspaceName ) ) ) {
109
+ return undefined
110
+ }
93
111
this . storage . writeToCoderOutputChannel ( `Starting ${ workspaceName } ...` )
94
112
workspace = await startWorkspace ( restClient , workspace )
95
113
break
96
114
}
97
- // Otherwise fall through and error.
115
+ // Otherwise fall through and error.
98
116
case "canceled" :
99
117
case "canceling" :
100
118
case "deleted" :
@@ -255,8 +273,13 @@ export class Remote {
255
273
const action = await WorkspaceAction . init ( this . vscodeProposed , workspaceRestClient , this . storage )
256
274
257
275
// If the workspace is not in a running state, try to get it running.
258
- workspace = await this . waitForRunning ( workspaceRestClient , workspace )
259
- this . commands . workspace = workspace
276
+ const updatedWorkspace = await this . maybeWaitForRunning ( workspaceRestClient , workspace )
277
+ if ( ! updatedWorkspace ) {
278
+ // User declined to start the workspace.
279
+ await this . closeRemote ( )
280
+ return
281
+ }
282
+ this . commands . workspace = workspace = updatedWorkspace
260
283
261
284
// Pick an agent.
262
285
this . storage . writeToCoderOutputChannel ( `Finding agent for ${ workspaceName } ...` )
0 commit comments