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-24 05:12:06 +01:00
|
|
|
import { LogService } from './services/log.service';
|
2018-02-14 05:38:18 +01:00
|
|
|
|
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-14 05:38:18 +01:00
|
|
|
export class Main {
|
2018-02-24 05:12:06 +01:00
|
|
|
logService: LogService;
|
2018-02-14 05:38:18 +01:00
|
|
|
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
|
2018-02-20 22:04:35 +01:00
|
|
|
let appDataPath = null;
|
|
|
|
if (process.env.BITWARDEN_APPDATA_DIR != null) {
|
|
|
|
appDataPath = process.env.BITWARDEN_APPDATA_DIR;
|
2018-02-23 23:11:18 +01:00
|
|
|
} else if (process.platform === 'win32' && process.env.PORTABLE_EXECUTABLE_DIR != null) {
|
2018-02-20 22:04:35 +01:00
|
|
|
appDataPath = path.join(process.env.PORTABLE_EXECUTABLE_DIR, 'bitwarden-appdata');
|
2018-02-23 23:11:18 +01:00
|
|
|
} else if (process.platform === 'linux' && process.env.SNAP_USER_DATA != null) {
|
2018-02-23 23:16:00 +01:00
|
|
|
appDataPath = path.join(process.env.SNAP_USER_DATA, 'appdata');
|
2018-02-20 22:04:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (appDataPath != null) {
|
2018-02-15 21:27:56 +01:00
|
|
|
app.setPath('userData', appDataPath);
|
|
|
|
}
|
2018-02-25 15:51:21 +01:00
|
|
|
app.setPath('logs', path.join(app.getPath('userData'), 'logs'));
|
2018-02-15 21:27:56 +01:00
|
|
|
|
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, {});
|
|
|
|
}
|
|
|
|
|
2018-02-25 15:51:21 +01:00
|
|
|
this.logService = new LogService(null, app.getPath('userData'));
|
2018-02-14 05:38:18 +01:00
|
|
|
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-28 16:52:59 +01:00
|
|
|
const locale = app.getLocale();
|
|
|
|
await this.i18nService.init(locale);
|
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();
|