1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-09 21:20:27 +00:00

Only pass necessary service to MenuMain

MenuMain only needs service references instead of a full reference to Main
This commit is contained in:
Daniel James Smith
2023-02-08 12:14:43 +01:00
parent 0623b9ce25
commit caaaebbc0c
2 changed files with 21 additions and 13 deletions

View File

@@ -103,13 +103,19 @@ export class Main {
);
this.messagingMain = new MessagingMain(this, this.stateService);
this.updaterMain = new UpdaterMain(this.i18nService, this.windowMain);
this.menuMain = new MenuMain(this);
this.trayMain = new TrayMain(this.windowMain, this.i18nService, this.stateService);
this.messagingService = new ElectronMainMessagingService(this.windowMain, (message) => {
this.messagingMain.onMessage(message);
});
this.powerMonitorMain = new PowerMonitorMain(this.messagingService);
this.menuMain = new MenuMain(
this.i18nService,
this.messagingService,
this.stateService,
this.windowMain,
this.updaterMain
);
if (process.platform === "win32") {
// eslint-disable-next-line

View File

@@ -1,8 +1,10 @@
import { app, Menu } from "electron";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { MessagingService } from "@bitwarden/common/abstractions/messaging.service";
import { StateService } from "@bitwarden/common/abstractions/state.service";
import { Main } from "../../main";
import { UpdaterMain } from "../updater.main";
import { WindowMain } from "../window.main";
import { MenuUpdateRequest } from "./menu.updater";
@@ -11,13 +13,13 @@ import { Menubar } from "./menubar";
const cloudWebVaultUrl = "https://vault.bitwarden.com";
export class MenuMain {
private i18nService: I18nService;
private windowMain: WindowMain;
constructor(private main: Main) {
this.i18nService = main.i18nService;
this.windowMain = main.windowMain;
}
constructor(
private i18nService: I18nService,
private messagingService: MessagingService,
private stateService: StateService,
private windowMain: WindowMain,
private updaterMain: UpdaterMain
) {}
async init() {
this.initContextMenu();
@@ -31,9 +33,9 @@ export class MenuMain {
private async setMenu(updateRequest?: MenuUpdateRequest) {
Menu.setApplicationMenu(
new Menubar(
this.main.i18nService,
this.main.messagingService,
this.main.updaterMain,
this.i18nService,
this.messagingService,
this.updaterMain,
this.windowMain,
await this.getWebVaultUrl(),
app.getVersion(),
@@ -44,7 +46,7 @@ export class MenuMain {
private async getWebVaultUrl() {
let webVaultUrl = cloudWebVaultUrl;
const urlsObj: any = await this.main.stateService.getEnvironmentUrls();
const urlsObj = await this.stateService.getEnvironmentUrls();
if (urlsObj != null) {
if (urlsObj.base != null) {
webVaultUrl = urlsObj.base;