Skip to content

Commit d384b53

Browse files
committed
Notify when workspace stops running
1 parent ad4c22d commit d384b53

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/workspaceMonitor.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export class WorkspaceMonitor implements vscode.Disposable {
4949
try {
5050
const newWorkspaceData = JSON.parse(event.data) as Workspace
5151
this.update(newWorkspaceData)
52+
this.maybeNotify(newWorkspaceData)
5253
this.onChange.fire(newWorkspaceData)
5354
} catch (error) {
5455
this.notifyError(error)
@@ -65,6 +66,7 @@ export class WorkspaceMonitor implements vscode.Disposable {
6566
this.updateStatusBarItem.command = "coder.workspace.update"
6667

6768
this.update(workspace) // Set initial state.
69+
this.maybeNotify(workspace)
6870
}
6971

7072
/**
@@ -81,9 +83,13 @@ export class WorkspaceMonitor implements vscode.Disposable {
8183
private update(workspace: Workspace) {
8284
this.updateContext(workspace)
8385
this.updateStatusBar(workspace)
86+
}
87+
88+
private maybeNotify(workspace: Workspace) {
8489
this.maybeNotifyOutdated(workspace)
8590
this.maybeNotifyAutostop(workspace)
8691
this.maybeNotifyDeletion(workspace)
92+
this.maybeNotifyNotRunning(workspace)
8793
}
8894

8995
private maybeNotifyAutostop(workspace: Workspace) {
@@ -111,6 +117,22 @@ export class WorkspaceMonitor implements vscode.Disposable {
111117
}
112118
}
113119

120+
private maybeNotifyNotRunning(workspace: Workspace) {
121+
if (workspace.latest_build.status !== "running") {
122+
const action = vscode.window.showInformationMessage(
123+
"Your workspace is no longer running!",
124+
{
125+
detail: "Reloading the window to reconnect.",
126+
},
127+
"Reload Window",
128+
)
129+
if (!action) {
130+
return
131+
}
132+
vscode.commands.executeCommand("workbench.action.reloadWindow")
133+
}
134+
}
135+
114136
private isImpending(target: string, notifyTime: number): boolean {
115137
const nowTime = new Date().getTime()
116138
const targetTime = new Date(target).getTime()

0 commit comments

Comments
 (0)