1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-13 01:58:44 +02:00

system idle locking

This commit is contained in:
Kyle Spearrin 2018-02-11 00:09:47 -05:00
parent 132c59f8fc
commit 1ef0d7a9a9
4 changed files with 34 additions and 5 deletions

View File

@ -20,6 +20,7 @@
"css-loader": "^0.28.7", "css-loader": "^0.28.7",
"electron": "1.8.2", "electron": "1.8.2",
"electron-builder": "19.56.0", "electron-builder": "19.56.0",
"electron-rebuild": "1.7.3",
"electron-reload": "1.2.2", "electron-reload": "1.2.2",
"electron-store": "^1.3.0", "electron-store": "^1.3.0",
"extract-text-webpack-plugin": "^3.0.1", "extract-text-webpack-plugin": "^3.0.1",
@ -55,6 +56,7 @@
"rxjs": "^5.5.6", "rxjs": "^5.5.6",
"zone.js": "^0.8.19", "zone.js": "^0.8.19",
"angular2-toaster": "4.0.2", "angular2-toaster": "4.0.2",
"angulartics2": "5.0.1" "angulartics2": "5.0.1",
"desktop-idle": "1.1.1"
} }
} }

View File

@ -36,7 +36,7 @@ export class SettingsComponent implements OnInit {
{ name: i18nService.t('thirtyMinutes'), value: 30 }, { name: i18nService.t('thirtyMinutes'), value: 30 },
{ name: i18nService.t('oneHour'), value: 60 }, { name: i18nService.t('oneHour'), value: 60 },
{ name: i18nService.t('fourHours'), value: 240 }, { name: i18nService.t('fourHours'), value: 240 },
// { name: i18nService.t('onIdle'), value: -4 }, { name: i18nService.t('onIdle'), value: -4 },
{ name: i18nService.t('onSleep'), value: -3 }, { name: i18nService.t('onSleep'), value: -3 },
// { name: i18nService.t('onLocked'), value: -2 }, // { name: i18nService.t('onLocked'), value: -2 },
{ name: i18nService.t('onRestart'), value: -1 }, { name: i18nService.t('onRestart'), value: -1 },

View File

@ -10,8 +10,8 @@ import {
import { WindowMain } from './window.main'; import { WindowMain } from './window.main';
import { MessagingService } from 'jslib/abstractions/messaging.service';
import { I18nService } from 'jslib/abstractions/i18n.service'; 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 i18nService: I18nService, constructor(private windowMain: WindowMain, private i18nService: I18nService,

View File

@ -5,20 +5,47 @@ import { ConstantsService } from 'jslib/services/constants.service';
import { MessagingService } from 'jslib/abstractions/messaging.service'; import { MessagingService } from 'jslib/abstractions/messaging.service';
import { StorageService } from 'jslib/abstractions/storage.service'; import { StorageService } from 'jslib/abstractions/storage.service';
// tslint:disable-next-line
const desktopIdle = require('desktop-idle');
const IdleLockSeconds = 5 * 60; // 5 minutes
const IdleCheckInterval = 30 * 1000; // 30 seconds
export class PowerMonitorMain { export class PowerMonitorMain {
private idle: boolean = false;
constructor(private storageService: StorageService, private messagingService: MessagingService) { } constructor(private storageService: StorageService, private messagingService: MessagingService) { }
init() { init() {
// System sleep // System sleep
powerMonitor.on('suspend', async () => { powerMonitor.on('suspend', async () => {
const lockOption = await this.storageService.get<number>(ConstantsService.lockOptionKey); const lockOption = await this.getLockOption();
if (lockOption === -3) { if (lockOption === -3) {
this.messagingService.send('lockVault'); this.messagingService.send('lockVault');
} }
}); });
// TODO: System idle // System idle
global.setInterval(async () => {
const idleSeconds: number = desktopIdle.getIdleTime();
const idle = idleSeconds >= IdleLockSeconds;
if (idle) {
if (this.idle) {
return;
}
const lockOption = await this.getLockOption();
if (lockOption === -4) {
this.messagingService.send('lockVault');
}
}
this.idle = idle;
}, IdleCheckInterval);
// TODO: System locked // TODO: System locked
} }
private async getLockOption(): Promise<number> {
return await this.storageService.get<number>(ConstantsService.lockOptionKey);
}
} }