1
0
mirror of https://github.com/bitwarden/desktop synced 2026-01-03 09:03:21 +00:00
Files
desktop/src/main/menu.file.ts
Addison Beck 0b306ca1a7 [Account Switching] [Feature] Add the ability to maintain state for up to 5 accounts at once (#1079)
* [refactor] Remove references to deprecated services

* [feature] Implement account switching

* [bug] Fix state handling for authentication dependent system menu items

* [bug] Enable the account switcher to fucntion properly when switching to a locked accounts

* [feature] Enable locking any account from the menu

* [bug] Ensure the avatar instance used in the account switcher updates on account change

* [style] Fix lint complaints

* [bug] Ensure the logout command callback can handle any user in state

* [style] Fix lint complaints

* rollup

* [style] Fix lint complaints

* [bug] Don't clean up state until everything else is done on logout

* [bug] Navigate to vault on a succesful account switch

* [bug] Init the state service on start

* [feature] Limit account switching to 5 account maximum

* [bug] Resolve app lock state with 5 logged out accounts

* [chore] Update account refrences to match recent jslib restructuring

* [bug] Add missing awaits

* [bug] Update app menu on logout

* [bug] Hide the switcher if there are no authed accounts

* [bug] Move authenticationStatus display information out of jslib

* [bug] Remove unused active style from scss

* [refactor] Rewrite the menu bar

* [style] Fix lint complaints

* [bug] Clean state of loggout out user after redirect

* [bug] Redirect on logout if not explicity provided a userId that isn't active

* [bug] Relocated several settings items to persistant storage

* [bug] Correct account switcher styles on all themes

* [chore] Include state migration service in services

* [bug] Swap to next account on logout

* [bug] Correct DI service

* [bug] fix loginGuard deps in services.module

* [chore] update jslib

* [bug] Remove badly merged scss

* [chore] update jslib

* [review] Code review cleanup

* [review] Code review cleanup

Co-authored-by: Hinton <oscar@oscarhinton.com>
2021-12-15 17:32:00 -05:00

135 lines
3.9 KiB
TypeScript

import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { MessagingService } from 'jslib-common/abstractions/messaging.service';
import { isMacAppStore } from 'jslib-electron/utils';
import { IMenubarMenu } from './menubar';
import { MenuItemConstructorOptions } from 'electron';
export class FileMenu implements IMenubarMenu {
readonly id: string = 'fileMenu';
get label(): string {
return this.localize('file');
}
get items(): MenuItemConstructorOptions[] {
return [
this.addNewLogin,
this.addNewItem,
this.addNewFolder,
this.separator,
this.syncVault,
this.exportVault,
this.quitBitwarden,
];
}
private readonly _i18nService: I18nService;
private readonly _messagingService: MessagingService;
private readonly _isAuthenticated: boolean;
constructor(
i18nService: I18nService,
messagingService: MessagingService,
isAuthenticated: boolean,
) {
this._i18nService = i18nService;
this._messagingService = messagingService;
this._isAuthenticated = isAuthenticated;
}
private get addNewLogin(): MenuItemConstructorOptions {
return {
label: this.localize('addNewLogin'),
click: () => this.sendMessage('newLogin'),
accelerator: 'CmdOrCtrl+N',
id: 'addNewLogin',
};
}
private get addNewItem(): MenuItemConstructorOptions {
return {
label: this.localize('addNewItem'),
id: 'addNewItem',
submenu: this.addNewItemSubmenu,
enabled: this._isAuthenticated,
};
}
private get addNewItemSubmenu(): MenuItemConstructorOptions[] {
return [
{
id: 'typeLogin',
label: this.localize('typeLogin'),
click: () => this.sendMessage('newLogin'),
accelerator: 'CmdOrCtrl+Shift+L',
},
{
id: 'typeCard',
label: this.localize('typeCard'),
click: () => this.sendMessage('newCard'),
accelerator: 'CmdOrCtrl+Shift+C',
},
{
id: 'typeIdentity',
label: this.localize('typeIdentity'),
click: () => this.sendMessage('newIdentity'),
accelerator: 'CmdOrCtrl+Shift+I',
},
{
id: 'typeSecureNote',
label: this.localize('typeSecureNote'),
click: () => this.sendMessage('newSecureNote'),
accelerator: 'CmdOrCtrl+Shift+S',
},
];
}
private get addNewFolder(): MenuItemConstructorOptions {
return {
id: 'addNewFolder',
label: this.localize('addNewFolder'),
click: () => this.sendMessage('newFolder'),
};
}
private get separator(): MenuItemConstructorOptions {
return { type: 'separator' };
}
private get syncVault(): MenuItemConstructorOptions {
return {
id: 'syncVault',
label: this.localize('syncVault'),
click: () => this.sendMessage('syncVault'),
};
}
private get exportVault(): MenuItemConstructorOptions {
return {
id: 'exportVault',
label: this.localize('exportVault'),
click: () => this.sendMessage('exportVault'),
};
}
private get quitBitwarden(): MenuItemConstructorOptions {
return {
id: 'quitBitwarden',
label: this.localize('quitBitwarden'),
visible: !isMacAppStore(),
role: 'quit',
};
}
private localize(s: string) {
return this._i18nService.t(s);
}
private sendMessage(message: string) {
this._messagingService.send(message);
}
}