1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-20 01:13:48 +00:00
Files
browser/apps/desktop/src/main/menu/menu.account.ts
Matt Gibson 78248db590 Platform/pm 19/platform team file moves (#5460)
* Rename service-factory folder

* Move cryptographic service factories

* Move crypto models

* Move crypto services

* Move domain base class

* Platform code owners

* Move desktop log services

* Move log files

* Establish component library ownership

* Move background listeners

* Move background background

* Move localization to Platform

* Move browser alarms to Platform

* Move browser state to Platform

* Move CLI state to Platform

* Move Desktop native concerns to Platform

* Move flag and misc to Platform

* Lint fixes

* Move electron state to platform

* Move web state to Platform

* Move lib state to Platform

* Fix broken tests

* Rename interface to idiomatic TS

* `npm run prettier` 🤖

* Resolve review feedback

* Set platform as owners of web core and shared

* Expand moved services

* Fix test types

---------

Co-authored-by: Hinton <hinton@users.noreply.github.com>
2023-06-06 15:34:53 -05:00

132 lines
3.8 KiB
TypeScript

import { BrowserWindow, dialog, MenuItemConstructorOptions, shell } from "electron";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
import { isMacAppStore, isWindowsStore } from "../../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,
this.separator,
this.deleteAccount,
];
}
private readonly _i18nService: I18nService;
private readonly _messagingService: MessagingService;
private readonly _webVaultUrl: string;
private readonly _window: BrowserWindow;
private readonly _isLocked: boolean;
constructor(
i18nService: I18nService,
messagingService: MessagingService,
webVaultUrl: string,
window: BrowserWindow,
isLocked: boolean
) {
this._i18nService = i18nService;
this._messagingService = messagingService;
this._webVaultUrl = webVaultUrl;
this._window = window;
this._isLocked = isLocked;
}
private get premiumMembership(): MenuItemConstructorOptions {
return {
label: this.localize("premiumMembership"),
click: () => this.sendMessage("openPremium"),
id: "premiumMembership",
visible: !isWindowsStore() && !isMacAppStore(),
enabled: !this._isLocked,
};
}
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._isLocked,
};
}
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._isLocked,
};
}
private get fingerprintPhrase(): MenuItemConstructorOptions {
return {
label: this.localize("fingerprintPhrase"),
id: "fingerprintPhrase",
click: () => this.sendMessage("showFingerprintPhrase"),
enabled: !this._isLocked,
};
}
private get deleteAccount(): MenuItemConstructorOptions {
return {
label: this.localize("deleteAccount"),
id: "deleteAccount",
click: () => this.sendMessage("deleteAccount"),
enabled: !this._isLocked,
};
}
private get separator(): MenuItemConstructorOptions {
return { type: "separator" };
}
private localize(s: string) {
return this._i18nService.t(s);
}
private sendMessage(message: string, args?: any) {
this._messagingService.send(message, args);
}
}