@@ -2,8 +2,10 @@ import * as path from 'vs/base/common/path';
2
2
import { URI } from 'vs/base/common/uri' ;
3
3
import { Options } from 'vs/ipc' ;
4
4
import { localize } from 'vs/nls' ;
5
+ import { MenuId , MenuRegistry } from 'vs/platform/actions/common/actions' ;
6
+ import { CommandsRegistry } from 'vs/platform/commands/common/commands' ;
5
7
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' ;
7
9
import { registerSingleton } from 'vs/platform/instantiation/common/extensions' ;
8
10
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection' ;
9
11
import { ILogService } from 'vs/platform/log/common/log' ;
@@ -178,6 +180,34 @@ export const initialize = async (services: ServiceCollection): Promise<void> =>
178
180
// Use to show or hide logout commands and menu options.
179
181
const contextKeyService = ( services . get ( IContextKeyService ) as IContextKeyService ) ;
180
182
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
+ } ) ;
181
211
} ;
182
212
183
213
export interface Query {
0 commit comments