electron main class
This commit is contained in:
parent
baaebdd2ad
commit
216c77fa25
|
@ -22,7 +22,7 @@
|
||||||
"build:main": "webpack --config webpack.main.js",
|
"build:main": "webpack --config webpack.main.js",
|
||||||
"build:renderer": "webpack --config webpack.renderer.js",
|
"build:renderer": "webpack --config webpack.renderer.js",
|
||||||
"build:renderer:watch": "webpack --config webpack.renderer.js --watch",
|
"build:renderer:watch": "webpack --config webpack.renderer.js --watch",
|
||||||
"electron": "npm run build:main && (electron ./build --dev --watch | npm run build:renderer:watch)",
|
"electron": "npm run build:main && (electron ./build --watch | npm run build:renderer:watch)",
|
||||||
"pack": "electron-builder --dir",
|
"pack": "electron-builder --dir",
|
||||||
"dist": "electron-builder"
|
"dist": "electron-builder"
|
||||||
},
|
},
|
||||||
|
|
77
src/main.ts
77
src/main.ts
|
@ -1,42 +1,59 @@
|
||||||
import { BrowserWindow } from 'electron';
|
import { BrowserWindow } from 'electron';
|
||||||
|
|
||||||
|
import { DesktopMainMessagingService } from './services/desktopMainMessaging.service';
|
||||||
|
import { DesktopStorageService } from './services/desktopStorage.service';
|
||||||
|
import { I18nService } from './services/i18n.service';
|
||||||
|
|
||||||
import { MenuMain } from './main/menu.main';
|
import { MenuMain } from './main/menu.main';
|
||||||
import { MessagingMain } from './main/messaging.main';
|
import { MessagingMain } from './main/messaging.main';
|
||||||
import { PowerMonitorMain } from './main/powerMonitor.main';
|
import { PowerMonitorMain } from './main/powerMonitor.main';
|
||||||
import { UpdaterMain } from './main/updater.main';
|
import { UpdaterMain } from './main/updater.main';
|
||||||
import { WindowMain } from './main/window.main';
|
import { WindowMain } from './main/window.main';
|
||||||
|
|
||||||
import { DesktopMainMessagingService } from './services/desktopMainMessaging.service';
|
export class Main {
|
||||||
import { DesktopStorageService } from './services/desktopStorage.service';
|
i18nService: I18nService;
|
||||||
import { I18nService } from './services/i18n.service';
|
storageService: DesktopStorageService;
|
||||||
|
messagingService: DesktopMainMessagingService;
|
||||||
|
|
||||||
const args = process.argv.slice(1);
|
windowMain: WindowMain;
|
||||||
const watch = args.some((val) => val === '--watch');
|
messagingMain: MessagingMain;
|
||||||
const dev = args.some((val) => val === '--dev');
|
updaterMain: UpdaterMain;
|
||||||
|
menuMain: MenuMain;
|
||||||
|
powerMonitorMain: PowerMonitorMain;
|
||||||
|
|
||||||
if (watch) {
|
constructor() {
|
||||||
// tslint:disable-next-line
|
const args = process.argv.slice(1);
|
||||||
require('electron-reload')(__dirname, {});
|
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 () => {
|
||||||
|
await this.i18nService.init();
|
||||||
|
this.messagingMain.init();
|
||||||
|
this.menuMain.init();
|
||||||
|
this.powerMonitorMain.init();
|
||||||
|
await this.updaterMain.init();
|
||||||
|
}, (e: any) => {
|
||||||
|
// tslint:disable-next-line
|
||||||
|
console.error(e);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const windowMain = new WindowMain(dev);
|
const main = new Main();
|
||||||
const messagingMain = new MessagingMain(windowMain);
|
main.bootstrap();
|
||||||
|
|
||||||
const i18nService = new I18nService('en', './locales/');
|
|
||||||
const storageService = new DesktopStorageService();
|
|
||||||
const messagingService = new DesktopMainMessagingService(windowMain, messagingMain);
|
|
||||||
|
|
||||||
const updaterMain = new UpdaterMain(windowMain, i18nService);
|
|
||||||
const menuMain = new MenuMain(windowMain, updaterMain, i18nService, messagingService);
|
|
||||||
const powerMonitorMain = new PowerMonitorMain(storageService, messagingService);
|
|
||||||
|
|
||||||
windowMain.init().then(async () => {
|
|
||||||
messagingMain.init();
|
|
||||||
await i18nService.init();
|
|
||||||
menuMain.init();
|
|
||||||
powerMonitorMain.init();
|
|
||||||
await updaterMain.init();
|
|
||||||
}, (e: any) => {
|
|
||||||
// tslint:disable-next-line
|
|
||||||
console.log(e);
|
|
||||||
});
|
|
||||||
|
|
|
@ -10,15 +10,10 @@ import {
|
||||||
shell,
|
shell,
|
||||||
} from 'electron';
|
} from 'electron';
|
||||||
|
|
||||||
import { UpdaterMain } from './updater.main';
|
import { Main } from '../main';
|
||||||
import { WindowMain } from './window.main';
|
|
||||||
|
|
||||||
import { I18nService } from 'jslib/abstractions/i18n.service';
|
|
||||||
import { MessagingService } from 'jslib/abstractions/messaging.service';
|
|
||||||
|
|
||||||
export class MenuMain {
|
export class MenuMain {
|
||||||
constructor(private windowMain: WindowMain, private updaterMain: UpdaterMain,
|
constructor(private main: Main) { }
|
||||||
private i18nService: I18nService, private messagingService: MessagingService) { }
|
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this.initContextMenu();
|
this.initContextMenu();
|
||||||
|
@ -51,14 +46,14 @@ export class MenuMain {
|
||||||
{ role: 'selectall' },
|
{ role: 'selectall' },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
this.windowMain.win.webContents.on('context-menu', (e, props) => {
|
this.main.windowMain.win.webContents.on('context-menu', (e, props) => {
|
||||||
const selected = props.selectionText && props.selectionText.trim() !== '';
|
const selected = props.selectionText && props.selectionText.trim() !== '';
|
||||||
if (props.isEditable && selected) {
|
if (props.isEditable && selected) {
|
||||||
inputSelectionMenu.popup(this.windowMain.win);
|
inputSelectionMenu.popup(this.main.windowMain.win);
|
||||||
} else if (props.isEditable) {
|
} else if (props.isEditable) {
|
||||||
inputMenu.popup(this.windowMain.win);
|
inputMenu.popup(this.main.windowMain.win);
|
||||||
} else if (selected) {
|
} else if (selected) {
|
||||||
selectionMenu.popup(this.windowMain.win);
|
selectionMenu.popup(this.main.windowMain.win);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -66,51 +61,51 @@ export class MenuMain {
|
||||||
private initApplicationMenu() {
|
private initApplicationMenu() {
|
||||||
const template: MenuItemConstructorOptions[] = [
|
const template: MenuItemConstructorOptions[] = [
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('file'),
|
label: this.main.i18nService.t('file'),
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('addNewLogin'),
|
label: this.main.i18nService.t('addNewLogin'),
|
||||||
click: () => this.messagingService.send('newLogin'),
|
click: () => this.main.messagingService.send('newLogin'),
|
||||||
accelerator: 'CmdOrCtrl+N',
|
accelerator: 'CmdOrCtrl+N',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('addNewItem'),
|
label: this.main.i18nService.t('addNewItem'),
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('typeLogin'),
|
label: this.main.i18nService.t('typeLogin'),
|
||||||
click: () => this.messagingService.send('newLogin'),
|
click: () => this.main.messagingService.send('newLogin'),
|
||||||
accelerator: 'Alt+L',
|
accelerator: 'Alt+L',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('typeCard'),
|
label: this.main.i18nService.t('typeCard'),
|
||||||
click: () => this.messagingService.send('newCard'),
|
click: () => this.main.messagingService.send('newCard'),
|
||||||
accelerator: 'Alt+C',
|
accelerator: 'Alt+C',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('typeIdentity'),
|
label: this.main.i18nService.t('typeIdentity'),
|
||||||
click: () => this.messagingService.send('newIdentity'),
|
click: () => this.main.messagingService.send('newIdentity'),
|
||||||
accelerator: 'Alt+I',
|
accelerator: 'Alt+I',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('typeSecureNote'),
|
label: this.main.i18nService.t('typeSecureNote'),
|
||||||
click: () => this.messagingService.send('newSecureNote'),
|
click: () => this.main.messagingService.send('newSecureNote'),
|
||||||
accelerator: 'Alt+S',
|
accelerator: 'Alt+S',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('addNewFolder'),
|
label: this.main.i18nService.t('addNewFolder'),
|
||||||
click: () => this.messagingService.send('newFolder'),
|
click: () => this.main.messagingService.send('newFolder'),
|
||||||
},
|
},
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('syncVault'),
|
label: this.main.i18nService.t('syncVault'),
|
||||||
click: () => this.messagingService.send('syncVault'),
|
click: () => this.main.messagingService.send('syncVault'),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('edit'),
|
label: this.main.i18nService.t('edit'),
|
||||||
submenu: [
|
submenu: [
|
||||||
{ role: 'undo' },
|
{ role: 'undo' },
|
||||||
{ role: 'redo' },
|
{ role: 'redo' },
|
||||||
|
@ -123,16 +118,16 @@ export class MenuMain {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('view'),
|
label: this.main.i18nService.t('view'),
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('passwordGenerator'),
|
label: this.main.i18nService.t('passwordGenerator'),
|
||||||
click: () => this.messagingService.send('openPasswordGenerator'),
|
click: () => this.main.messagingService.send('openPasswordGenerator'),
|
||||||
accelerator: 'CmdOrCtrl+G',
|
accelerator: 'CmdOrCtrl+G',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('searchVault'),
|
label: this.main.i18nService.t('searchVault'),
|
||||||
click: () => this.messagingService.send('focusSearch'),
|
click: () => this.main.messagingService.send('focusSearch'),
|
||||||
accelerator: 'CmdOrCtrl+F',
|
accelerator: 'CmdOrCtrl+F',
|
||||||
},
|
},
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
|
@ -148,19 +143,19 @@ export class MenuMain {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('account'),
|
label: this.main.i18nService.t('account'),
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('premiumMembership'),
|
label: this.main.i18nService.t('premiumMembership'),
|
||||||
click: () => this.messagingService.send('premiumMembership'),
|
click: () => this.main.messagingService.send('premiumMembership'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('changeMasterPass'),
|
label: this.main.i18nService.t('changeMasterPass'),
|
||||||
click: () => {
|
click: () => {
|
||||||
const result = dialog.showMessageBox(this.windowMain.win, {
|
const result = dialog.showMessageBox(this.main.windowMain.win, {
|
||||||
title: this.i18nService.t('changeMasterPass'),
|
title: this.main.i18nService.t('changeMasterPass'),
|
||||||
message: this.i18nService.t('changeMasterPasswordConfirmation'),
|
message: this.main.i18nService.t('changeMasterPasswordConfirmation'),
|
||||||
buttons: [this.i18nService.t('yes'), this.i18nService.t('no')],
|
buttons: [this.main.i18nService.t('yes'), this.main.i18nService.t('no')],
|
||||||
cancelId: 1,
|
cancelId: 1,
|
||||||
defaultId: 0,
|
defaultId: 0,
|
||||||
noLink: true,
|
noLink: true,
|
||||||
|
@ -171,12 +166,12 @@ export class MenuMain {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('changeEmail'),
|
label: this.main.i18nService.t('changeEmail'),
|
||||||
click: () => {
|
click: () => {
|
||||||
const result = dialog.showMessageBox(this.windowMain.win, {
|
const result = dialog.showMessageBox(this.main.windowMain.win, {
|
||||||
title: this.i18nService.t('changeEmail'),
|
title: this.main.i18nService.t('changeEmail'),
|
||||||
message: this.i18nService.t('changeEmailConfirmation'),
|
message: this.main.i18nService.t('changeEmailConfirmation'),
|
||||||
buttons: [this.i18nService.t('yes'), this.i18nService.t('no')],
|
buttons: [this.main.i18nService.t('yes'), this.main.i18nService.t('no')],
|
||||||
cancelId: 1,
|
cancelId: 1,
|
||||||
defaultId: 0,
|
defaultId: 0,
|
||||||
noLink: true,
|
noLink: true,
|
||||||
|
@ -187,12 +182,12 @@ export class MenuMain {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('twoStepLogin'),
|
label: this.main.i18nService.t('twoStepLogin'),
|
||||||
click: () => {
|
click: () => {
|
||||||
const result = dialog.showMessageBox(this.windowMain.win, {
|
const result = dialog.showMessageBox(this.main.windowMain.win, {
|
||||||
title: this.i18nService.t('twoStepLogin'),
|
title: this.main.i18nService.t('twoStepLogin'),
|
||||||
message: this.i18nService.t('twoStepLoginConfirmation'),
|
message: this.main.i18nService.t('twoStepLoginConfirmation'),
|
||||||
buttons: [this.i18nService.t('yes'), this.i18nService.t('no')],
|
buttons: [this.main.i18nService.t('yes'), this.main.i18nService.t('no')],
|
||||||
cancelId: 1,
|
cancelId: 1,
|
||||||
defaultId: 0,
|
defaultId: 0,
|
||||||
noLink: true,
|
noLink: true,
|
||||||
|
@ -204,18 +199,18 @@ export class MenuMain {
|
||||||
},
|
},
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('logOut'),
|
label: this.main.i18nService.t('logOut'),
|
||||||
click: () => {
|
click: () => {
|
||||||
const result = dialog.showMessageBox(this.windowMain.win, {
|
const result = dialog.showMessageBox(this.main.windowMain.win, {
|
||||||
title: this.i18nService.t('logOut'),
|
title: this.main.i18nService.t('logOut'),
|
||||||
message: this.i18nService.t('logOutConfirmation'),
|
message: this.main.i18nService.t('logOutConfirmation'),
|
||||||
buttons: [this.i18nService.t('logOut'), this.i18nService.t('cancel')],
|
buttons: [this.main.i18nService.t('logOut'), this.main.i18nService.t('cancel')],
|
||||||
cancelId: 1,
|
cancelId: 1,
|
||||||
defaultId: 0,
|
defaultId: 0,
|
||||||
noLink: true,
|
noLink: true,
|
||||||
});
|
});
|
||||||
if (result === 0) {
|
if (result === 0) {
|
||||||
this.messagingService.send('logout');
|
this.main.messagingService.send('logout');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -232,23 +227,23 @@ export class MenuMain {
|
||||||
role: 'help',
|
role: 'help',
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('emailUs'),
|
label: this.main.i18nService.t('emailUs'),
|
||||||
click: () => shell.openExternal('mailTo:hello@bitwarden.com'),
|
click: () => shell.openExternal('mailTo:hello@bitwarden.com'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('visitOurWebsite'),
|
label: this.main.i18nService.t('visitOurWebsite'),
|
||||||
click: () => shell.openExternal('https://bitwarden.com/contact'),
|
click: () => shell.openExternal('https://bitwarden.com/contact'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('fileBugReport'),
|
label: this.main.i18nService.t('fileBugReport'),
|
||||||
click: () => shell.openExternal('https://github.com/bitwarden/desktop'),
|
click: () => shell.openExternal('https://github.com/bitwarden/desktop'),
|
||||||
},
|
},
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('followUs'),
|
label: this.main.i18nService.t('followUs'),
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('blog'),
|
label: this.main.i18nService.t('blog'),
|
||||||
click: () => shell.openExternal('https://blog.bitwarden.com'),
|
click: () => shell.openExternal('https://blog.bitwarden.com'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -271,11 +266,11 @@ export class MenuMain {
|
||||||
},
|
},
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('goToWebVault'),
|
label: this.main.i18nService.t('goToWebVault'),
|
||||||
click: () => shell.openExternal('https://vault.bitwarden.com'),
|
click: () => shell.openExternal('https://vault.bitwarden.com'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('getMobileApp'),
|
label: this.main.i18nService.t('getMobileApp'),
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
label: 'iOS',
|
label: 'iOS',
|
||||||
|
@ -294,7 +289,7 @@ export class MenuMain {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('getBrowserExtension'),
|
label: this.main.i18nService.t('getBrowserExtension'),
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
label: 'Chrome',
|
label: 'Chrome',
|
||||||
|
@ -340,19 +335,19 @@ export class MenuMain {
|
||||||
const firstMenuOptions: MenuItemConstructorOptions[] = [
|
const firstMenuOptions: MenuItemConstructorOptions[] = [
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('settings'),
|
label: this.main.i18nService.t('settings'),
|
||||||
click: () => this.messagingService.send('openSettings'),
|
click: () => this.main.messagingService.send('openSettings'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('lockNow'),
|
label: this.main.i18nService.t('lockNow'),
|
||||||
click: () => this.messagingService.send('lockVault'),
|
click: () => this.main.messagingService.send('lockVault'),
|
||||||
accelerator: 'CmdOrCtrl+L',
|
accelerator: 'CmdOrCtrl+L',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const updateMenuItem = {
|
const updateMenuItem = {
|
||||||
label: this.i18nService.t('checkForUpdates'),
|
label: this.main.i18nService.t('checkForUpdates'),
|
||||||
click: () => this.updaterMain.checkForUpdate(true),
|
click: () => this.main.updaterMain.checkForUpdate(true),
|
||||||
id: 'checkForUpdates',
|
id: 'checkForUpdates',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -395,20 +390,20 @@ export class MenuMain {
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
updateMenuItem,
|
updateMenuItem,
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('about'),
|
label: this.main.i18nService.t('about'),
|
||||||
click: () => {
|
click: () => {
|
||||||
const aboutInformation = this.i18nService.t('version', app.getVersion()) +
|
const aboutInformation = this.main.i18nService.t('version', app.getVersion()) +
|
||||||
'\nShell ' + process.versions.electron +
|
'\nShell ' + process.versions.electron +
|
||||||
'\nRenderer ' + process.versions.chrome +
|
'\nRenderer ' + process.versions.chrome +
|
||||||
'\nNode ' + process.versions.node +
|
'\nNode ' + process.versions.node +
|
||||||
'\nArchitecture ' + process.arch;
|
'\nArchitecture ' + process.arch;
|
||||||
const result = dialog.showMessageBox(this.windowMain.win, {
|
const result = dialog.showMessageBox(this.main.windowMain.win, {
|
||||||
title: 'Bitwarden',
|
title: 'Bitwarden',
|
||||||
message: 'Bitwarden',
|
message: 'Bitwarden',
|
||||||
detail: aboutInformation,
|
detail: aboutInformation,
|
||||||
type: 'info',
|
type: 'info',
|
||||||
noLink: true,
|
noLink: true,
|
||||||
buttons: [this.i18nService.t('ok'), this.i18nService.t('copy')],
|
buttons: [this.main.i18nService.t('ok'), this.main.i18nService.t('copy')],
|
||||||
});
|
});
|
||||||
if (result === 1) {
|
if (result === 1) {
|
||||||
clipboard.writeText(aboutInformation);
|
clipboard.writeText(aboutInformation);
|
||||||
|
|
|
@ -9,7 +9,7 @@ import {
|
||||||
setPassword,
|
setPassword,
|
||||||
} from 'keytar';
|
} from 'keytar';
|
||||||
|
|
||||||
import { WindowMain } from './window.main';
|
import { Main } from '../main';
|
||||||
|
|
||||||
const KeytarService = 'Bitwarden';
|
const KeytarService = 'Bitwarden';
|
||||||
const SyncInterval = 5 * 60 * 1000; // 5 minutes
|
const SyncInterval = 5 * 60 * 1000; // 5 minutes
|
||||||
|
@ -17,7 +17,7 @@ const SyncInterval = 5 * 60 * 1000; // 5 minutes
|
||||||
export class MessagingMain {
|
export class MessagingMain {
|
||||||
private syncTimeout: NodeJS.Timer;
|
private syncTimeout: NodeJS.Timer;
|
||||||
|
|
||||||
constructor(private windowMain: WindowMain) { }
|
constructor(private main: Main) { }
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this.scheduleNextSync();
|
this.scheduleNextSync();
|
||||||
|
@ -65,7 +65,7 @@ export class MessagingMain {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.syncTimeout = global.setTimeout(() => {
|
this.syncTimeout = global.setTimeout(() => {
|
||||||
this.windowMain.win.webContents.send('messagingService', {
|
this.main.windowMain.win.webContents.send('messagingService', {
|
||||||
command: 'checkSyncVault',
|
command: 'checkSyncVault',
|
||||||
});
|
});
|
||||||
}, SyncInterval);
|
}, SyncInterval);
|
||||||
|
|
|
@ -2,8 +2,7 @@ import { powerMonitor } from 'electron';
|
||||||
|
|
||||||
import { ConstantsService } from 'jslib/services/constants.service';
|
import { ConstantsService } from 'jslib/services/constants.service';
|
||||||
|
|
||||||
import { MessagingService } from 'jslib/abstractions/messaging.service';
|
import { Main } from '../main';
|
||||||
import { StorageService } from 'jslib/abstractions/storage.service';
|
|
||||||
|
|
||||||
// tslint:disable-next-line
|
// tslint:disable-next-line
|
||||||
const desktopIdle = require('desktop-idle');
|
const desktopIdle = require('desktop-idle');
|
||||||
|
@ -13,14 +12,14 @@ const IdleCheckInterval = 30 * 1000; // 30 seconds
|
||||||
export class PowerMonitorMain {
|
export class PowerMonitorMain {
|
||||||
private idle: boolean = false;
|
private idle: boolean = false;
|
||||||
|
|
||||||
constructor(private storageService: StorageService, private messagingService: MessagingService) { }
|
constructor(private main: Main) { }
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
// System sleep
|
// System sleep
|
||||||
powerMonitor.on('suspend', async () => {
|
powerMonitor.on('suspend', async () => {
|
||||||
const lockOption = await this.getLockOption();
|
const lockOption = await this.getLockOption();
|
||||||
if (lockOption === -3) {
|
if (lockOption === -3) {
|
||||||
this.messagingService.send('lockVault');
|
this.main.messagingService.send('lockVault');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -35,7 +34,7 @@ export class PowerMonitorMain {
|
||||||
|
|
||||||
const lockOption = await this.getLockOption();
|
const lockOption = await this.getLockOption();
|
||||||
if (lockOption === -4) {
|
if (lockOption === -4) {
|
||||||
this.messagingService.send('lockVault');
|
this.main.messagingService.send('lockVault');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +45,6 @@ export class PowerMonitorMain {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getLockOption(): Promise<number> {
|
private async getLockOption(): Promise<number> {
|
||||||
return await this.storageService.get<number>(ConstantsService.lockOptionKey);
|
return await this.main.storageService.get<number>(ConstantsService.lockOptionKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,21 +5,18 @@ import {
|
||||||
} from 'electron';
|
} from 'electron';
|
||||||
import { autoUpdater } from 'electron-updater';
|
import { autoUpdater } from 'electron-updater';
|
||||||
|
|
||||||
|
import { Main } from '../main';
|
||||||
import { isDev } from '../scripts/utils';
|
import { isDev } from '../scripts/utils';
|
||||||
import { WindowMain } from './window.main';
|
|
||||||
|
|
||||||
import { I18nService } from 'jslib/abstractions/i18n.service';
|
|
||||||
|
|
||||||
const UpdaterCheckInitalDelay = 5 * 1000; // 5 seconds
|
const UpdaterCheckInitalDelay = 5 * 1000; // 5 seconds
|
||||||
const UpdaterCheckInterval = 12 * 60 * 60 * 1000; // 12 hours
|
const UpdaterCheckInterval = 12 * 60 * 60 * 1000; // 12 hours
|
||||||
|
|
||||||
export class UpdaterMain {
|
export class UpdaterMain {
|
||||||
|
|
||||||
private doingUpdateCheck = false;
|
private doingUpdateCheck = false;
|
||||||
private doingUpdateCheckWithFeedback = false;
|
private doingUpdateCheckWithFeedback = false;
|
||||||
private updateMenuItem: MenuItem;
|
private updateMenuItem: MenuItem;
|
||||||
|
|
||||||
constructor(private windowMain: WindowMain, private i18nService: I18nService) { }
|
constructor(private main: Main) { }
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
global.setTimeout(async () => await this.checkForUpdate(), UpdaterCheckInitalDelay);
|
global.setTimeout(async () => await this.checkForUpdate(), UpdaterCheckInitalDelay);
|
||||||
|
@ -33,12 +30,12 @@ export class UpdaterMain {
|
||||||
|
|
||||||
autoUpdater.on('update-available', () => {
|
autoUpdater.on('update-available', () => {
|
||||||
if (this.doingUpdateCheckWithFeedback) {
|
if (this.doingUpdateCheckWithFeedback) {
|
||||||
const result = dialog.showMessageBox(this.windowMain.win, {
|
const result = dialog.showMessageBox(this.main.windowMain.win, {
|
||||||
type: 'info',
|
type: 'info',
|
||||||
title: this.i18nService.t('updateAvailable'),
|
title: this.main.i18nService.t('updateAvailable'),
|
||||||
message: this.i18nService.t('updateAvailable'),
|
message: this.main.i18nService.t('updateAvailable'),
|
||||||
detail: this.i18nService.t('updateAvailableDesc'),
|
detail: this.main.i18nService.t('updateAvailableDesc'),
|
||||||
buttons: [this.i18nService.t('yes'), this.i18nService.t('no')],
|
buttons: [this.main.i18nService.t('yes'), this.main.i18nService.t('no')],
|
||||||
cancelId: 1,
|
cancelId: 1,
|
||||||
defaultId: 0,
|
defaultId: 0,
|
||||||
noLink: true,
|
noLink: true,
|
||||||
|
@ -54,8 +51,8 @@ export class UpdaterMain {
|
||||||
|
|
||||||
autoUpdater.on('update-not-available', () => {
|
autoUpdater.on('update-not-available', () => {
|
||||||
if (this.doingUpdateCheckWithFeedback) {
|
if (this.doingUpdateCheckWithFeedback) {
|
||||||
dialog.showMessageBox(this.windowMain.win, {
|
dialog.showMessageBox(this.main.windowMain.win, {
|
||||||
message: this.i18nService.t('noUpdatesAvailable'),
|
message: this.main.i18nService.t('noUpdatesAvailable'),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,14 +60,14 @@ export class UpdaterMain {
|
||||||
});
|
});
|
||||||
|
|
||||||
autoUpdater.on('update-downloaded', (info) => {
|
autoUpdater.on('update-downloaded', (info) => {
|
||||||
this.updateMenuItem.label = this.i18nService.t('restartToUpdate');
|
this.updateMenuItem.label = this.main.i18nService.t('restartToUpdate');
|
||||||
|
|
||||||
const result = dialog.showMessageBox(this.windowMain.win, {
|
const result = dialog.showMessageBox(this.main.windowMain.win, {
|
||||||
type: 'info',
|
type: 'info',
|
||||||
title: this.i18nService.t('restartToUpdate'),
|
title: this.main.i18nService.t('restartToUpdate'),
|
||||||
message: this.i18nService.t('restartToUpdate'),
|
message: this.main.i18nService.t('restartToUpdate'),
|
||||||
detail: this.i18nService.t('restartToUpdateDesc', info.version),
|
detail: this.main.i18nService.t('restartToUpdateDesc', info.version),
|
||||||
buttons: [this.i18nService.t('restart'), this.i18nService.t('later')],
|
buttons: [this.main.i18nService.t('restart'), this.main.i18nService.t('later')],
|
||||||
cancelId: 1,
|
cancelId: 1,
|
||||||
defaultId: 0,
|
defaultId: 0,
|
||||||
noLink: true,
|
noLink: true,
|
||||||
|
@ -83,8 +80,8 @@ export class UpdaterMain {
|
||||||
|
|
||||||
autoUpdater.on('error', (error) => {
|
autoUpdater.on('error', (error) => {
|
||||||
if (this.doingUpdateCheckWithFeedback) {
|
if (this.doingUpdateCheckWithFeedback) {
|
||||||
dialog.showErrorBox(this.i18nService.t('updateError'),
|
dialog.showErrorBox(this.main.i18nService.t('updateError'),
|
||||||
error == null ? this.i18nService.t('unknown') : (error.stack || error).toString());
|
error == null ? this.main.i18nService.t('unknown') : (error.stack || error).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.reset();
|
this.reset();
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
|
import { isDev } from '../scripts/utils';
|
||||||
import { app, BrowserWindow, screen } from 'electron';
|
import { app, BrowserWindow, screen } from 'electron';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as url from 'url';
|
import * as url from 'url';
|
||||||
|
|
||||||
|
import { Main } from '../main';
|
||||||
|
|
||||||
export class WindowMain {
|
export class WindowMain {
|
||||||
win: BrowserWindow;
|
win: BrowserWindow;
|
||||||
|
|
||||||
constructor(private dev: boolean) { }
|
constructor(private main: Main) { }
|
||||||
|
|
||||||
init(): Promise<any> {
|
init(): Promise<any> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
@ -65,7 +68,7 @@ export class WindowMain {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Open the DevTools.
|
// Open the DevTools.
|
||||||
if (this.dev) {
|
if (isDev()) {
|
||||||
this.win.webContents.openDevTools();
|
this.win.webContents.openDevTools();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
import { MessagingService } from 'jslib/abstractions';
|
import { MessagingService } from 'jslib/abstractions';
|
||||||
|
|
||||||
import { MessagingMain } from '../main/messaging.main';
|
import { Main } from '../main';
|
||||||
import { WindowMain } from '../main/window.main';
|
|
||||||
|
|
||||||
export class DesktopMainMessagingService implements MessagingService {
|
export class DesktopMainMessagingService implements MessagingService {
|
||||||
constructor(private windowMain: WindowMain, private messagingMain: MessagingMain) { }
|
constructor(private main: Main) { }
|
||||||
|
|
||||||
send(subscriber: string, arg: any = {}) {
|
send(subscriber: string, arg: any = {}) {
|
||||||
const message = Object.assign({}, { command: subscriber }, arg);
|
const message = Object.assign({}, { command: subscriber }, arg);
|
||||||
this.windowMain.win.webContents.send('messagingService', message);
|
this.main.windowMain.win.webContents.send('messagingService', message);
|
||||||
this.messagingMain.onMessage(message);
|
this.main.messagingMain.onMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue