@@ -25,13 +25,20 @@ export class SupervisorServiceClient {
25
25
readonly ideReady = this . supervisorReady . then ( ( ) => this . checkReady ( "ide" ) ) ;
26
26
readonly contentReady = Promise . all ( [ this . supervisorReady ] ) . then ( ( ) => this . checkReady ( "content" ) ) ;
27
27
readonly getWorkspaceInfoPromise = this . supervisorReady . then ( ( ) => this . getWorkspaceInfo ( ) ) ;
28
- readonly supervisorWillShutdown = this . supervisorReady . then ( ( ) => this . checkWillShutdown ( ) ) ;
28
+ private _supervisorWillShutdown : Promise < void > | undefined ;
29
29
30
30
private constructor ( ) { }
31
31
32
+ public get supervisorWillShutdown ( ) {
33
+ if ( ! this . _supervisorWillShutdown ) {
34
+ this . _supervisorWillShutdown = this . supervisorReady . then ( ( ) => this . checkWillShutdown ( ) ) ;
35
+ }
36
+ return this . _supervisorWillShutdown ;
37
+ }
38
+
32
39
private async checkWillShutdown ( delay = false ) : Promise < void > {
33
40
if ( delay ) {
34
- await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
41
+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
35
42
}
36
43
try {
37
44
const wsSupervisorStatusUrl = GitpodHostUrl . fromWorkspaceUrl ( window . location . href ) . with ( ( url ) => {
@@ -49,7 +56,11 @@ export class SupervisorServiceClient {
49
56
}
50
57
if ( response . status === 502 ) {
51
58
// bad gateway, supervisor is gone
52
- return
59
+ return ;
60
+ }
61
+ if ( response . status === 302 && response . headers . get ( "location" ) ?. includes ( "/start/" ) ) {
62
+ // redirect to start page, workspace is closed
63
+ return ;
53
64
}
54
65
console . debug (
55
66
`failed to check whether is about to shutdown, trying again...` ,
@@ -64,7 +75,7 @@ export class SupervisorServiceClient {
64
75
await this . checkWillShutdown ( true ) ;
65
76
}
66
77
67
- private async checkReady ( kind : "content" | "ide" | "supervisor" , delay ?: boolean ) : Promise < any > {
78
+ private async checkReady ( kind : "content" | "ide" | "supervisor" , delay ?: boolean ) : Promise < any > {
68
79
if ( delay ) {
69
80
await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
70
81
}
0 commit comments