2018-02-08 21:58:47 +01:00
|
|
|
import {
|
|
|
|
app,
|
|
|
|
Menu,
|
|
|
|
} from 'electron';
|
|
|
|
|
2018-02-14 05:38:18 +01:00
|
|
|
import { Main } from '../main';
|
2018-04-24 22:30:47 +02:00
|
|
|
|
2021-06-07 19:26:36 +02:00
|
|
|
import { BaseMenu } from 'jslib-electron/baseMenu';
|
2018-04-25 21:43:26 +02:00
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
import { MenuUpdateRequest } from './menu.updater';
|
|
|
|
import { Menubar } from './menubar';
|
2018-02-09 06:21:00 +01:00
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
const cloudWebVaultUrl: string = 'https://vault.bitwarden.com';
|
2018-02-19 14:52:53 +01:00
|
|
|
|
2018-04-25 21:43:26 +02:00
|
|
|
export class MenuMain extends BaseMenu {
|
|
|
|
constructor(private main: Main) {
|
2018-05-08 15:40:33 +02:00
|
|
|
super(main.i18nService, main.windowMain);
|
2018-04-25 21:43:26 +02:00
|
|
|
}
|
2018-02-08 19:10:13 +01:00
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
async init() {
|
2018-02-14 05:06:45 +01:00
|
|
|
this.initContextMenu();
|
2021-12-15 23:32:00 +01:00
|
|
|
await this.setMenu();
|
2018-02-14 06:26:32 +01:00
|
|
|
}
|
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
async updateApplicationMenuState(updateRequest: MenuUpdateRequest) {
|
|
|
|
await this.setMenu(updateRequest);
|
2018-02-14 05:06:45 +01:00
|
|
|
}
|
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
private async setMenu(updateRequest?: MenuUpdateRequest) {
|
|
|
|
Menu.setApplicationMenu(new Menubar(
|
|
|
|
this.main.i18nService,
|
|
|
|
this.main.messagingService,
|
|
|
|
this.main.updaterMain,
|
|
|
|
this.windowMain,
|
|
|
|
await this.getWebVaultUrl(),
|
|
|
|
app.getVersion(),
|
|
|
|
updateRequest,
|
|
|
|
).menu);
|
2018-02-08 19:10:13 +01:00
|
|
|
}
|
2018-02-19 14:52:53 +01:00
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
private async getWebVaultUrl() {
|
|
|
|
let webVaultUrl = cloudWebVaultUrl;
|
|
|
|
const urlsObj: any = await this.main.stateService.getEnvironmentUrls();
|
2018-02-19 14:52:53 +01:00
|
|
|
if (urlsObj != null) {
|
|
|
|
if (urlsObj.base != null) {
|
2021-12-15 23:32:00 +01:00
|
|
|
webVaultUrl = urlsObj.base;
|
2018-02-19 14:52:53 +01:00
|
|
|
} else if (urlsObj.webVault != null) {
|
2021-12-15 23:32:00 +01:00
|
|
|
webVaultUrl = urlsObj.webVault;
|
2018-02-19 14:52:53 +01:00
|
|
|
}
|
|
|
|
}
|
2021-12-15 23:32:00 +01:00
|
|
|
return webVaultUrl;
|
2018-02-19 14:52:53 +01:00
|
|
|
}
|
2021-12-15 23:32:00 +01:00
|
|
|
|
2018-02-08 19:10:13 +01:00
|
|
|
}
|