mirror of
https://github.com/bitwarden/desktop
synced 2026-01-03 00:53:56 +00:00
* [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>
122 lines
3.9 KiB
TypeScript
122 lines
3.9 KiB
TypeScript
import {
|
|
BrowserWindow,
|
|
dialog,
|
|
MenuItemConstructorOptions,
|
|
shell,
|
|
} from 'electron';
|
|
|
|
import { I18nService } from 'jslib-common/abstractions/i18n.service';
|
|
import { MessagingService } from 'jslib-common/abstractions/messaging.service';
|
|
|
|
import { isMacAppStore, isWindowsStore } from 'jslib-electron/utils';
|
|
|
|
import { IMenubarMenu } from './menubar';
|
|
|
|
export class AccountMenu implements IMenubarMenu {
|
|
readonly id: string = 'accountMenu';
|
|
|
|
get label(): string {
|
|
return this.localize('account');
|
|
}
|
|
|
|
get items(): MenuItemConstructorOptions[] {
|
|
return [
|
|
this.premiumMembership,
|
|
this.changeMasterPassword,
|
|
this.twoStepLogin,
|
|
this.fingerprintPhrase,
|
|
];
|
|
}
|
|
|
|
private readonly _i18nService: I18nService;
|
|
private readonly _messagingService: MessagingService;
|
|
private readonly _webVaultUrl: string;
|
|
private readonly _window: BrowserWindow;
|
|
private readonly _isAuthenticated: boolean;
|
|
|
|
constructor(
|
|
i18nService: I18nService,
|
|
messagingService: MessagingService,
|
|
webVaultUrl: string,
|
|
window: BrowserWindow,
|
|
isAuthenticated: boolean,
|
|
) {
|
|
this._i18nService = i18nService;
|
|
this._messagingService = messagingService;
|
|
this._webVaultUrl = webVaultUrl;
|
|
this._window = window;
|
|
this._isAuthenticated = isAuthenticated;
|
|
}
|
|
|
|
private get premiumMembership(): MenuItemConstructorOptions {
|
|
return {
|
|
label: this.localize('premiumMembership'),
|
|
click: () => this.sendMessage('openPremium'),
|
|
id: 'premiumMembership',
|
|
visible: !isWindowsStore() && !isMacAppStore(),
|
|
enabled: this._isAuthenticated,
|
|
};
|
|
}
|
|
|
|
private get changeMasterPassword(): MenuItemConstructorOptions {
|
|
return {
|
|
label: this.localize('changeMasterPass'),
|
|
id: 'changeMasterPass',
|
|
click: async () => {
|
|
const result = await dialog.showMessageBox(this._window, {
|
|
title: this.localize('changeMasterPass'),
|
|
message: this.localize('changeMasterPass'),
|
|
detail: this.localize('changeMasterPasswordConfirmation'),
|
|
buttons: [this.localize('yes'), this.localize('no')],
|
|
cancelId: 1,
|
|
defaultId: 0,
|
|
noLink: true,
|
|
});
|
|
if (result.response === 0) {
|
|
shell.openExternal(this._webVaultUrl);
|
|
}
|
|
},
|
|
enabled: this._isAuthenticated,
|
|
};
|
|
}
|
|
|
|
private get twoStepLogin(): MenuItemConstructorOptions {
|
|
return {
|
|
label: this.localize('twoStepLogin'),
|
|
id: 'twoStepLogin',
|
|
click: async () => {
|
|
const result = await dialog.showMessageBox(this._window, {
|
|
title: this.localize('twoStepLogin'),
|
|
message: this.localize('twoStepLogin'),
|
|
detail: this.localize('twoStepLoginConfirmation'),
|
|
buttons: [this.localize('yes'), this.localize('no')],
|
|
cancelId: 1,
|
|
defaultId: 0,
|
|
noLink: true,
|
|
});
|
|
if (result.response === 0) {
|
|
shell.openExternal(this._webVaultUrl);
|
|
}
|
|
},
|
|
enabled: this._isAuthenticated,
|
|
};
|
|
}
|
|
|
|
private get fingerprintPhrase(): MenuItemConstructorOptions {
|
|
return {
|
|
label: this.localize('fingerprintPhrase'),
|
|
id: 'fingerprintPhrase',
|
|
click: () => this.sendMessage('showFingerprintPhrase'),
|
|
enabled: this._isAuthenticated,
|
|
};
|
|
}
|
|
|
|
private localize(s: string) {
|
|
return this._i18nService.t(s);
|
|
}
|
|
|
|
private sendMessage(message: string, args?: any) {
|
|
this._messagingService.send(message, args);
|
|
}
|
|
}
|