@@ -2,8 +2,10 @@ import * as path from 'vs/base/common/path';
22import { URI } from 'vs/base/common/uri' ;
33import { Options } from 'vs/ipc' ;
44import { localize } from 'vs/nls' ;
5+ import { MenuId , MenuRegistry } from 'vs/platform/actions/common/actions' ;
6+ import { CommandsRegistry } from 'vs/platform/commands/common/commands' ;
57import { 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' ;
79import { registerSingleton } from 'vs/platform/instantiation/common/extensions' ;
810import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection' ;
911import { 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' , "Log out" )
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' , "Log out" )
208+ } ,
209+ when : ContextKeyExpr . has ( 'code-server.authed' )
210+ } ) ;
181211} ;
182212
183213export interface Query {
0 commit comments