Skip to content

Commit 7238ce4

Browse files
committed
feat: add shutdown menu command
1 parent 18ddfff commit 7238ce4

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
"command": "coderWorkspaces.rebuildWorkspace",
4747
"when": "view == coderWorkspaces"
4848
},
49+
{
50+
"command": "coderWorkspaces.shutdownWorkspace",
51+
"when": "view == coderWorkspaces"
52+
},
4953
{
5054
"command": "coderWorkspaces.openWorkspace",
5155
"when": "view == coderWorkspaces"
@@ -61,6 +65,10 @@
6165
"command": "coderWorkspaces.rebuildWorkspace",
6266
"title": "Rebuild Workspace"
6367
},
68+
{
69+
"command": "coderWorkspaces.shutdownWorkspace",
70+
"title": "Shutdown Workspace"
71+
},
6472
{
6573
"command": "coderWorkspaces.openWorkspace",
6674
"title": "Open Workspace"

src/extension.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import * as vscode from 'vscode';
44

5-
import { CoderWorkspacesProvider, CoderWorkspace, rebuildWorkspace, openWorkspace } from './workspaces';
5+
import { CoderWorkspacesProvider, CoderWorkspace, rebuildWorkspace, openWorkspace, shutdownWorkspace } from './workspaces';
66

77
export function activate(context: vscode.ExtensionContext) {
88
const workspaceProvider = new CoderWorkspacesProvider();
@@ -15,6 +15,10 @@ export function activate(context: vscode.ExtensionContext) {
1515
const { name } = ws.workspace;
1616
rebuildWorkspace(name).then(() => workspaceProvider.refresh());
1717
});
18+
vscode.commands.registerCommand("coderWorkspaces.shutdownWorkspace", (ws: CoderWorkspace) => {
19+
const { name } = ws.workspace;
20+
shutdownWorkspace(name).then(() => workspaceProvider.refresh());
21+
});
1822

1923
vscode.commands.registerCommand("coderWorkspaces.refreshWorkspaces", () => {
2024
workspaceProvider.refresh();

src/workspaces.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ export const rebuildWorkspace = async (name: string): Promise<void> => {
3838
});
3939
};
4040

41+
export const shutdownWorkspace = async (name: string): Promise<void> => {
42+
return new Promise((res, rej) => {
43+
cp.exec(`coder envs stop ${name}`, (err, stdout, stderr) => {
44+
if (err) {
45+
vscode.window.showErrorMessage(`Failed to shutdown Coder Workspaces: ${err}`);
46+
rej(err);
47+
return;
48+
}
49+
res();
50+
vscode.window.showInformationMessage(`Shutting down Coder Workspace "${name}"`);
51+
});
52+
});
53+
};
54+
4155
export const openWorkspace = async (name: string): Promise<void> => {
4256
return new Promise((res, rej) => {
4357
cp.exec(`code --remote "ssh-remote+coder.${name}" /home/coder`, (err, stdout, stderr) => {
@@ -50,7 +64,7 @@ export const openWorkspace = async (name: string): Promise<void> => {
5064
vscode.window.showInformationMessage(`Opening Coder Workspace "${name}"`);
5165
});
5266
});
53-
}
67+
};
5468

5569
const getWorkspaces = async (): Promise<CoderWorkspace[]> => {
5670
const images = await getImages();

0 commit comments

Comments
 (0)