mirror of
https://github.com/bitwarden/desktop.git
synced 2025-02-07 23:51:27 +01:00
0ba2589461
* Update jslib (101c568 -> 14b01f2) (#506) * Update jslib (14b01f2 -> 1513b25) (#510) * [jslib] Update (1513b25 -> 7c3a9d6) (#516) * update jslib (1513b25 -> 7c3a9d6) * Updated call to constructor super * [SSO] Added SSO flows & functionality (#513) * update jslib * bump version * Added sso button (wip) * Added sso & change password // Added modules/routes // Added strings for localization * Added password strength comp // reverted login route * Updated sso component to send client id // added routing for sso // added crypto function to services module provider list * Added deep linking * First round of UI updates // Added sso browser launching // Added missing strings * Updated UI and added missing strings * Removed extra change password style * Let constructor for WindowMain handle default width/height * Prepared for jslib update * Update jslib (1513b25 -> 7c3a9d6) * Update login super * Added params for launchSsoBrowser function * Update jslib (7c3a9d6 -> 4203937) * Added missing strings, removed unnecessary class param * Upgrade TypeScript (#517) * Updated password score // Update styles * Removed password-strength component files * Cleaned up module class // Fixed UL/LI formatting issues * Use exisiting loading string // removed new string * Update jslib (4203937 -> 9957125) * Updated class to perform new submit actions * Upgrade Angular (#520) * di resolution for CryptoFunctionServiceAbstraction * Update jslib (9957125 -> 5d874d0) (#521) * Updated change password flow to match web * Updated callout style Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> Co-authored-by: Oscar Hinton <hinton.oscar@gmail.com> Co-authored-by: Vincent Salucci <26154748+vincentsalucci@users.noreply.github.com> Co-authored-by: Oscar Hinton <hinton.oscar@gmail.com>
172 lines
7.0 KiB
TypeScript
172 lines
7.0 KiB
TypeScript
import { app, globalShortcut } from 'electron';
|
|
import * as path from 'path';
|
|
|
|
import { I18nService } from './services/i18n.service';
|
|
|
|
import { MenuMain } from './main/menu.main';
|
|
import { MessagingMain } from './main/messaging.main';
|
|
import { PowerMonitorMain } from './main/powerMonitor.main';
|
|
|
|
import { ConstantsService } from 'jslib/services/constants.service';
|
|
|
|
import { BiometricMain } from 'jslib/abstractions/biometric.main';
|
|
import { ElectronConstants } from 'jslib/electron/electronConstants';
|
|
import { KeytarStorageListener } from 'jslib/electron/keytarStorageListener';
|
|
import { ElectronLogService } from 'jslib/electron/services/electronLog.service';
|
|
import { ElectronMainMessagingService } from 'jslib/electron/services/electronMainMessaging.service';
|
|
import { ElectronStorageService } from 'jslib/electron/services/electronStorage.service';
|
|
import { TrayMain } from 'jslib/electron/tray.main';
|
|
import { UpdaterMain } from 'jslib/electron/updater.main';
|
|
import { WindowMain } from 'jslib/electron/window.main';
|
|
|
|
export class Main {
|
|
logService: ElectronLogService;
|
|
i18nService: I18nService;
|
|
storageService: ElectronStorageService;
|
|
messagingService: ElectronMainMessagingService;
|
|
keytarStorageListener: KeytarStorageListener;
|
|
|
|
windowMain: WindowMain;
|
|
messagingMain: MessagingMain;
|
|
updaterMain: UpdaterMain;
|
|
menuMain: MenuMain;
|
|
powerMonitorMain: PowerMonitorMain;
|
|
trayMain: TrayMain;
|
|
biometricMain: BiometricMain;
|
|
|
|
constructor() {
|
|
// Set paths for portable builds
|
|
let appDataPath = null;
|
|
if (process.env.BITWARDEN_APPDATA_DIR != null) {
|
|
appDataPath = process.env.BITWARDEN_APPDATA_DIR;
|
|
} else if (process.platform === 'win32' && process.env.PORTABLE_EXECUTABLE_DIR != null) {
|
|
appDataPath = path.join(process.env.PORTABLE_EXECUTABLE_DIR, 'bitwarden-appdata');
|
|
} else if (process.platform === 'linux' && process.env.SNAP_USER_DATA != null) {
|
|
appDataPath = path.join(process.env.SNAP_USER_DATA, 'appdata');
|
|
}
|
|
|
|
app.on('ready', () => {
|
|
/*
|
|
globalShortcut.register('CommandOrControl+Shift+L', async () => {
|
|
if (this.windowMain.win === null) {
|
|
await this.windowMain.createWindow();
|
|
}
|
|
|
|
this.messagingService.send('focusSearch');
|
|
this.windowMain.win.show();
|
|
});
|
|
|
|
globalShortcut.register('CommandOrControl+Shift+G', async () => {
|
|
if (this.windowMain.win === null) {
|
|
await this.windowMain.createWindow();
|
|
}
|
|
|
|
this.messagingService.send('openPasswordGenerator');
|
|
this.windowMain.win.show();
|
|
});
|
|
*/
|
|
});
|
|
|
|
if (appDataPath != null) {
|
|
app.setPath('userData', appDataPath);
|
|
}
|
|
app.setPath('logs', path.join(app.getPath('userData'), 'logs'));
|
|
|
|
const args = process.argv.slice(1);
|
|
const watch = args.some((val) => val === '--watch');
|
|
|
|
if (watch) {
|
|
// tslint:disable-next-line
|
|
require('electron-reload')(__dirname, {});
|
|
}
|
|
|
|
this.logService = new ElectronLogService(null, app.getPath('userData'));
|
|
this.i18nService = new I18nService('en', './locales/');
|
|
|
|
const storageDefaults: any = {};
|
|
// Default vault timeout to "on restart", and action to "lock"
|
|
storageDefaults[ConstantsService.vaultTimeoutKey] = -1;
|
|
storageDefaults[ConstantsService.vaultTimeoutActionKey] = 'lock';
|
|
this.storageService = new ElectronStorageService(app.getPath('userData'), storageDefaults);
|
|
|
|
this.windowMain = new WindowMain(this.storageService, true, undefined, undefined,
|
|
(arg) => this.processDeepLink(arg));
|
|
this.messagingMain = new MessagingMain(this, this.storageService);
|
|
this.updaterMain = new UpdaterMain(this.i18nService, this.windowMain, 'desktop', () => {
|
|
this.menuMain.updateMenuItem.enabled = false;
|
|
}, () => {
|
|
this.menuMain.updateMenuItem.enabled = true;
|
|
}, () => {
|
|
this.menuMain.updateMenuItem.label = this.i18nService.t('restartToUpdate');
|
|
}, 'bitwarden');
|
|
this.menuMain = new MenuMain(this);
|
|
this.powerMonitorMain = new PowerMonitorMain(this);
|
|
this.trayMain = new TrayMain(this.windowMain, this.i18nService, this.storageService);
|
|
|
|
this.messagingService = new ElectronMainMessagingService(this.windowMain, (message) => {
|
|
this.messagingMain.onMessage(message);
|
|
});
|
|
|
|
this.keytarStorageListener = new KeytarStorageListener('Bitwarden');
|
|
|
|
if (process.platform === 'win32') {
|
|
const BiometricWindowsMain = require('jslib/electron/biometric.windows.main').default;
|
|
this.biometricMain = new BiometricWindowsMain(this.storageService, this.i18nService);
|
|
} else if (process.platform === 'darwin') {
|
|
const BiometricDarwinMain = require('jslib/electron/biometric.darwin.main').default;
|
|
this.biometricMain = new BiometricDarwinMain(this.storageService, this.i18nService);
|
|
}
|
|
}
|
|
|
|
bootstrap() {
|
|
this.keytarStorageListener.init();
|
|
this.windowMain.init().then(async () => {
|
|
const locale = await this.storageService.get<string>(ConstantsService.localeKey);
|
|
await this.i18nService.init(locale != null ? locale : app.getLocale());
|
|
this.messagingMain.init();
|
|
this.menuMain.init();
|
|
await this.trayMain.init('Bitwarden', [{
|
|
label: this.i18nService.t('lockNow'),
|
|
enabled: false,
|
|
id: 'lockNow',
|
|
click: () => this.messagingService.send('lockVault'),
|
|
}]);
|
|
if (await this.storageService.get<boolean>(ElectronConstants.enableStartToTrayKey)) {
|
|
this.trayMain.hideToTray();
|
|
}
|
|
this.powerMonitorMain.init();
|
|
await this.updaterMain.init();
|
|
if (this.biometricMain != null) {
|
|
await this.biometricMain.init();
|
|
}
|
|
|
|
if (!app.isDefaultProtocolClient('bitwarden')) {
|
|
app.setAsDefaultProtocolClient('bitwarden');
|
|
}
|
|
|
|
// Process protocol for macOS
|
|
app.on('open-url', (event, url) => {
|
|
event.preventDefault();
|
|
this.processDeepLink([url]);
|
|
});
|
|
}, (e: any) => {
|
|
// tslint:disable-next-line
|
|
console.error(e);
|
|
});
|
|
}
|
|
|
|
private processDeepLink(argv: string[]): void {
|
|
argv.filter((s) => s.indexOf('bitwarden://') === 0).forEach((s) => {
|
|
const url = new URL(s);
|
|
const code = url.searchParams.get('code');
|
|
const receivedState = url.searchParams.get('state');
|
|
if (code != null && receivedState != null) {
|
|
this.messagingService.send('ssoCallback', { code: code, state: receivedState });
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
const main = new Main();
|
|
main.bootstrap();
|