Skip to content

Commit 12837d8

Browse files
JanKoehnleinakosyakov
authored andcommitted
[extension] allow workspace snapshots (microsoft#2811)
1 parent 02fb304 commit 12837d8

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

extensions/gitpod/package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
"command": "gitpod.ExtendTimeout",
6868
"title": "%extendTimeout%"
6969
},
70+
{
71+
"command": "gitpod.takeSnapshot",
72+
"title": "%takeSnapshot%"
73+
},
7074
{
7175
"command": "gitpod.ports.openBrowser",
7276
"title": "%openBrowser%",
@@ -109,8 +113,12 @@
109113
"group": "gitpod@20"
110114
},
111115
{
112-
"command": "gitpod.stop.ws",
116+
"command": "gitpod.takeSnapshot",
113117
"group": "gitpod@30"
118+
},
119+
{
120+
"command": "gitpod.stop.ws",
121+
"group": "gitpod@40"
114122
}
115123
],
116124
"accounts/context": [
@@ -128,7 +136,7 @@
128136
},
129137
{
130138
"command": "gitpod.ExtendTimeout",
131-
"group": "navigation@40"
139+
"group": "navigation@50"
132140
}
133141
],
134142
"menuBar/help": [

extensions/gitpod/package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"stopWorkspace": "Gitpod: Stop Workspace",
1313
"upgradeSubscription": "Gitpod: Upgrade Subscription",
1414
"extendTimeout": "Gitpod: Extend Workspace Timeout",
15+
"takeSnapshot": "Gitpod: Share Workspace Snapshot",
1516
"openBrowser": "Open Browser",
1617
"openPreview": "Open Preview",
1718
"makePrivate": "Make Private",

extensions/gitpod/src/extension.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ export async function activate(context: vscode.ExtensionContext) {
5656
'function:getWorkspaceTimeout',
5757
'resource:workspace::' + workspaceId + '::get/update',
5858
'function:accessCodeSyncStorage',
59-
'function:getLoggedInUser'
59+
'function:getLoggedInUser',
60+
'function:takeSnapshot'
6061
]);
6162
const pendingServerToken = (async () => {
6263
const getTokenRequest = new GetTokenRequest();
@@ -149,7 +150,34 @@ export async function activate(context: vscode.ExtensionContext) {
149150
vscode.window.showErrorMessage(`Cannot extend workspace timeout: ${err.toString()}`);
150151
}
151152
}));
152-
153+
context.subscriptions.push(vscode.commands.registerCommand('gitpod.takeSnapshot', async () => {
154+
try {
155+
const snapshotId = await vscode.window.withProgress({
156+
location: vscode.ProgressLocation.Notification,
157+
cancellable: true,
158+
title: 'Capturing workspace snapshot'
159+
}, _ => {
160+
return gitpodService.server.takeSnapshot({ workspaceId /*, layoutData?*/ });
161+
});
162+
const hostname = gitpodApi.getHost();
163+
const uri = `https://${hostname}#snapshot/${snapshotId}`;
164+
const copyAction = await vscode.window.showInformationMessage(`The current state is captured in a snapshot. Sharing the link '${uri}' allows anybody to create their own copy of this workspace.`,
165+
'Copy URL to Clipboard', 'Copy Markdown button', 'Copy HTML button');
166+
switch (copyAction) {
167+
case 'Copy URL to Clipboard':
168+
await vscode.env.clipboard.writeText(uri);
169+
break;
170+
case 'Copy Markdown button':
171+
await vscode.env.clipboard.writeText(`[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](${uri})`);
172+
break;
173+
case 'Copy HTML button':
174+
await vscode.env.clipboard.writeText(`<a href="${uri}"><img alt="Open in Gitpod" src="https://gitpod.io/button/open-in-gitpod.svg"></a>`);
175+
}
176+
} catch (err) {
177+
console.error('cannot capture workspace snapshot', err);
178+
await vscode.window.showErrorMessage(`Cannot capture workspace snapshot: ${err.toString()}`);
179+
}
180+
}));
153181
const communityStatusBarItem = vscode.window.createStatusBarItem({
154182
id: 'gitpod.community',
155183
name: 'Chat with us on Discourse',

0 commit comments

Comments
 (0)