Skip to content

feat(lib/vscode): add log out to application menu #2922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 23, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(lib/vscode): add log out to application menu
This adds a new option to the Application Menu called Log out.

It deletes the code-server cookie and logs a user out.
  • Loading branch information
jsjoeio committed Mar 23, 2021
commit 9f790fd2f32e6fbcee0300d8b47be187d9937c9e
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { registerThemingParticipant, IThemeService } from 'vs/platform/theme/com
import { MenuBarVisibility, getTitleBarStyle, IWindowOpenable, getMenuBarVisibility } from 'vs/platform/windows/common/windows';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IAction, Action, SubmenuAction, Separator } from 'vs/base/common/actions';
import * as DOM from 'vs/base/browser/dom';
import { addDisposableListener, Dimension, EventType } from 'vs/base/browser/dom';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { isMacintosh, isWeb, isIOS, isNative } from 'vs/base/common/platform';
Expand Down Expand Up @@ -38,6 +39,7 @@ import { KeyCode } from 'vs/base/common/keyCodes';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { IsWebContext } from 'vs/platform/contextkey/common/contextkeys';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { ILogService } from 'vs/platform/log/common/log';

export abstract class MenubarControl extends Disposable {

Expand Down Expand Up @@ -312,7 +314,8 @@ export class CustomMenubarControl extends MenubarControl {
@IThemeService private readonly themeService: IThemeService,
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
@IHostService protected readonly hostService: IHostService,
@ICommandService commandService: ICommandService
@ICommandService commandService: ICommandService,
@ILogService private readonly logService: ILogService
) {
super(menuService, workspacesService, contextKeyService, keybindingService, configurationService, labelService, updateService, storageService, notificationService, preferencesService, environmentService, accessibilityService, hostService, commandService);

Expand Down Expand Up @@ -711,6 +714,28 @@ export class CustomMenubarControl extends MenubarControl {
webNavigationActions.pop();
}

webNavigationActions.push(new Action('logout', localize('logout', "Log out"), undefined, true,
async (event?: MouseEvent) => {
const COOKIE_KEY = 'key';
const loginCookie = DOM.getCookieValue(COOKIE_KEY);

this.logService.info('Logging out of code-server');

if(loginCookie) {
this.logService.info(`Removing cookie under ${COOKIE_KEY}`);

if (document && document.cookie) {
// We delete the cookie by setting the expiration to a date/time in the past
document.cookie = COOKIE_KEY +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
window.location.href = '/login';
} else {
this.logService.warn('Could not delete cookie because document and/or document.cookie is undefined');
}
} else {
this.logService.warn('Could not log out because we could not find cookie');
}
}))

return webNavigationActions;
}

Expand Down