bitwarden-estensione-browser/src/main.ts

78 lines
2.6 KiB
TypeScript
Raw Normal View History

2018-02-15 21:27:56 +01:00
import { app, BrowserWindow } from 'electron';
import * as path from 'path';
2018-01-16 21:58:17 +01:00
2018-02-14 05:38:18 +01:00
import { DesktopMainMessagingService } from './services/desktopMainMessaging.service';
import { DesktopStorageService } from './services/desktopStorage.service';
import { I18nService } from './services/i18n.service';
2018-02-08 19:10:13 +01:00
import { MenuMain } from './main/menu.main';
import { MessagingMain } from './main/messaging.main';
2018-02-11 05:24:22 +01:00
import { PowerMonitorMain } from './main/powerMonitor.main';
2018-02-12 22:07:14 +01:00
import { UpdaterMain } from './main/updater.main';
2018-02-08 19:10:13 +01:00
import { WindowMain } from './main/window.main';
2018-01-23 19:59:01 +01:00
2018-02-23 05:19:59 +01:00
// tslint:disable-next-line
2018-02-22 21:54:09 +01:00
const osLocale = require('os-locale');
2018-02-14 05:38:18 +01:00
export class Main {
i18nService: I18nService;
storageService: DesktopStorageService;
messagingService: DesktopMainMessagingService;
windowMain: WindowMain;
messagingMain: MessagingMain;
updaterMain: UpdaterMain;
menuMain: MenuMain;
powerMonitorMain: PowerMonitorMain;
constructor() {
2018-02-15 21:27:56 +01:00
// Set paths for portable builds
let appDataPath = null;
if (process.env.BITWARDEN_APPDATA_DIR != null) {
appDataPath = process.env.BITWARDEN_APPDATA_DIR;
} else if (process.env.PORTABLE_EXECUTABLE_DIR != null) {
appDataPath = path.join(process.env.PORTABLE_EXECUTABLE_DIR, 'bitwarden-appdata');
}
if (appDataPath != null) {
2018-02-15 21:27:56 +01:00
app.setPath('userData', appDataPath);
app.setPath('logs', path.join(appDataPath, 'logs'));
}
2018-02-14 05:38:18 +01:00
const args = process.argv.slice(1);
const watch = args.some((val) => val === '--watch');
if (watch) {
// tslint:disable-next-line
require('electron-reload')(__dirname, {});
}
this.i18nService = new I18nService('en', './locales/');
this.storageService = new DesktopStorageService();
this.messagingService = new DesktopMainMessagingService(this);
this.windowMain = new WindowMain(this);
this.messagingMain = new MessagingMain(this);
this.updaterMain = new UpdaterMain(this);
this.menuMain = new MenuMain(this);
this.powerMonitorMain = new PowerMonitorMain(this);
}
bootstrap() {
this.windowMain.init().then(async () => {
2018-02-22 21:54:09 +01:00
const locale = await osLocale();
2018-02-21 14:58:42 +01:00
await this.i18nService.init(locale.replace('_', '-'));
2018-02-14 05:38:18 +01:00
this.messagingMain.init();
this.menuMain.init();
this.powerMonitorMain.init();
await this.updaterMain.init();
}, (e: any) => {
// tslint:disable-next-line
console.error(e);
});
}
2018-01-16 23:30:57 +01:00
}
2018-02-14 05:38:18 +01:00
const main = new Main();
main.bootstrap();