Skip to content

Commit c3a42c9

Browse files
committed
Add logout command and menu options
1 parent e7a5275 commit c3a42c9

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

lib/vscode/src/vs/server/browser/client.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import * as path from 'vs/base/common/path';
22
import { URI } from 'vs/base/common/uri';
33
import { Options } from 'vs/ipc';
44
import { localize } from 'vs/nls';
5+
import { MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
6+
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
57
import { Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
6-
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
8+
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
79
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
810
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
911
import { ILogService } from 'vs/platform/log/common/log';
@@ -178,6 +180,34 @@ export const initialize = async (services: ServiceCollection): Promise<void> =>
178180
// Use to show or hide logout commands and menu options.
179181
const contextKeyService = (services.get(IContextKeyService) as IContextKeyService);
180182
contextKeyService.createKey('code-server.authed', options.authed);
183+
184+
// Add a logout command.
185+
const logoutEndpoint = path.join(options.base, '/logout') + `?base=${options.base}`;
186+
const LOGOUT_COMMAND_ID = 'code-server.logout';
187+
CommandsRegistry.registerCommand(
188+
LOGOUT_COMMAND_ID,
189+
() => {
190+
window.location.href = logoutEndpoint;
191+
},
192+
);
193+
194+
// Add logout to command palette.
195+
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
196+
command: {
197+
id: LOGOUT_COMMAND_ID,
198+
title: localize('logout', "Logout")
199+
},
200+
when: ContextKeyExpr.has('code-server.authed')
201+
});
202+
203+
// Add logout to the (web-only) home menu.
204+
MenuRegistry.appendMenuItem(MenuId.MenubarHomeMenu, {
205+
command: {
206+
id: LOGOUT_COMMAND_ID,
207+
title: localize('logout', "Logout")
208+
},
209+
when: ContextKeyExpr.has('code-server.authed')
210+
});
181211
};
182212

183213
export interface Query {

0 commit comments

Comments
 (0)