@@ -9,6 +9,7 @@ import { registerThemingParticipant, IThemeService } from 'vs/platform/theme/com
99import { MenuBarVisibility , getTitleBarStyle , IWindowOpenable , getMenuBarVisibility } from 'vs/platform/windows/common/windows' ;
1010import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
1111import { IAction , Action , SubmenuAction , Separator } from 'vs/base/common/actions' ;
12+ import * as DOM from 'vs/base/browser/dom' ;
1213import { addDisposableListener , Dimension , EventType } from 'vs/base/browser/dom' ;
1314import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
1415import { isMacintosh , isWeb , isIOS , isNative } from 'vs/base/common/platform' ;
@@ -38,6 +39,7 @@ import { KeyCode } from 'vs/base/common/keyCodes';
3839import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry' ;
3940import { IsWebContext } from 'vs/platform/contextkey/common/contextkeys' ;
4041import { ICommandService } from 'vs/platform/commands/common/commands' ;
42+ import { ILogService } from 'vs/platform/log/common/log' ;
4143
4244export abstract class MenubarControl extends Disposable {
4345
@@ -312,7 +314,8 @@ export class CustomMenubarControl extends MenubarControl {
312314 @IThemeService private readonly themeService : IThemeService ,
313315 @IWorkbenchLayoutService private readonly layoutService : IWorkbenchLayoutService ,
314316 @IHostService protected readonly hostService : IHostService ,
315- @ICommandService commandService : ICommandService
317+ @ICommandService commandService : ICommandService ,
318+ @ILogService private readonly logService : ILogService
316319 ) {
317320 super ( menuService , workspacesService , contextKeyService , keybindingService , configurationService , labelService , updateService , storageService , notificationService , preferencesService , environmentService , accessibilityService , hostService , commandService ) ;
318321
@@ -711,6 +714,28 @@ export class CustomMenubarControl extends MenubarControl {
711714 webNavigationActions . pop ( ) ;
712715 }
713716
717+ webNavigationActions . push ( new Action ( 'logout' , localize ( 'logout' , "Log out" ) , undefined , true ,
718+ async ( event ?: MouseEvent ) => {
719+ const COOKIE_KEY = 'key' ;
720+ const loginCookie = DOM . getCookieValue ( COOKIE_KEY ) ;
721+
722+ this . logService . info ( 'Logging out of code-server' ) ;
723+
724+ if ( loginCookie ) {
725+ this . logService . info ( `Removing cookie under ${ COOKIE_KEY } ` ) ;
726+
727+ if ( document && document . cookie ) {
728+ // We delete the cookie by setting the expiration to a date/time in the past
729+ document . cookie = COOKIE_KEY + '=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;' ;
730+ window . location . href = '/login' ;
731+ } else {
732+ this . logService . warn ( 'Could not delete cookie because document and/or document.cookie is undefined' ) ;
733+ }
734+ } else {
735+ this . logService . warn ( 'Could not log out because we could not find cookie' ) ;
736+ }
737+ } ) )
738+
714739 return webNavigationActions ;
715740 }
716741
0 commit comments