@@ -39,32 +39,37 @@ export class WorkspaceMonitor implements vscode.Disposable {
39
39
const watchUrl = new URL ( `${ url } /api/v2/workspaces/${ workspace . id } /watch` )
40
40
this . storage . writeToCoderOutputChannel ( `Monitoring ${ watchUrl } ` )
41
41
42
- this . eventSource = new EventSource ( watchUrl . toString ( ) , {
42
+ const eventSource = new EventSource ( watchUrl . toString ( ) , {
43
43
headers : {
44
44
"Coder-Session-Token" : token ,
45
45
} ,
46
46
} )
47
47
48
- this . eventSource . addEventListener ( "data" , ( event ) => {
48
+ eventSource . addEventListener ( "data" , ( event ) => {
49
49
try {
50
50
const newWorkspaceData = JSON . parse ( event . data ) as Workspace
51
51
this . update ( newWorkspaceData )
52
+ this . maybeNotify ( newWorkspaceData )
52
53
this . onChange . fire ( newWorkspaceData )
53
54
} catch ( error ) {
54
55
this . notifyError ( error )
55
56
}
56
57
} )
57
58
58
- this . eventSource . addEventListener ( "error" , ( error ) => {
59
+ eventSource . addEventListener ( "error" , ( error ) => {
59
60
this . notifyError ( error )
60
61
} )
61
62
63
+ // Store so we can close in dispose().
64
+ this . eventSource = eventSource
65
+
62
66
this . updateStatusBarItem = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Left , 999 )
63
67
this . updateStatusBarItem . name = "Coder Workspace Update"
64
68
this . updateStatusBarItem . text = "$(fold-up) Update Workspace"
65
69
this . updateStatusBarItem . command = "coder.workspace.update"
66
70
67
71
this . update ( workspace ) // Set initial state.
72
+ this . maybeNotify ( workspace )
68
73
}
69
74
70
75
/**
@@ -81,9 +86,13 @@ export class WorkspaceMonitor implements vscode.Disposable {
81
86
private update ( workspace : Workspace ) {
82
87
this . updateContext ( workspace )
83
88
this . updateStatusBar ( workspace )
89
+ }
90
+
91
+ private maybeNotify ( workspace : Workspace ) {
84
92
this . maybeNotifyOutdated ( workspace )
85
93
this . maybeNotifyAutostop ( workspace )
86
94
this . maybeNotifyDeletion ( workspace )
95
+ this . maybeNotifyNotRunning ( workspace )
87
96
}
88
97
89
98
private maybeNotifyAutostop ( workspace : Workspace ) {
@@ -111,6 +120,23 @@ export class WorkspaceMonitor implements vscode.Disposable {
111
120
}
112
121
}
113
122
123
+ private maybeNotifyNotRunning ( workspace : Workspace ) {
124
+ if ( workspace . latest_build . status !== "running" ) {
125
+ vscode . window . showInformationMessage (
126
+ "Your workspace is no longer running!" ,
127
+ {
128
+ detail : "Reloading the window to reconnect." ,
129
+ } ,
130
+ "Reload Window" ,
131
+ ) . then ( ( action ) => {
132
+ if ( ! action ) {
133
+ return
134
+ }
135
+ vscode . commands . executeCommand ( "workbench.action.reloadWindow" )
136
+ } )
137
+ }
138
+ }
139
+
114
140
private isImpending ( target : string , notifyTime : number ) : boolean {
115
141
const nowTime = new Date ( ) . getTime ( )
116
142
const targetTime = new Date ( target ) . getTime ( )
0 commit comments