mirror of
https://github.com/bitwarden/desktop.git
synced 2024-11-28 12:35:40 +01:00
system idle locking
This commit is contained in:
parent
132c59f8fc
commit
1ef0d7a9a9
@ -20,6 +20,7 @@
|
||||
"css-loader": "^0.28.7",
|
||||
"electron": "1.8.2",
|
||||
"electron-builder": "19.56.0",
|
||||
"electron-rebuild": "1.7.3",
|
||||
"electron-reload": "1.2.2",
|
||||
"electron-store": "^1.3.0",
|
||||
"extract-text-webpack-plugin": "^3.0.1",
|
||||
@ -55,6 +56,7 @@
|
||||
"rxjs": "^5.5.6",
|
||||
"zone.js": "^0.8.19",
|
||||
"angular2-toaster": "4.0.2",
|
||||
"angulartics2": "5.0.1"
|
||||
"angulartics2": "5.0.1",
|
||||
"desktop-idle": "1.1.1"
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ export class SettingsComponent implements OnInit {
|
||||
{ name: i18nService.t('thirtyMinutes'), value: 30 },
|
||||
{ name: i18nService.t('oneHour'), value: 60 },
|
||||
{ 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('onLocked'), value: -2 },
|
||||
{ name: i18nService.t('onRestart'), value: -1 },
|
||||
|
@ -10,8 +10,8 @@ import {
|
||||
|
||||
import { WindowMain } from './window.main';
|
||||
|
||||
import { MessagingService } from 'jslib/abstractions/messaging.service';
|
||||
import { I18nService } from 'jslib/abstractions/i18n.service';
|
||||
import { MessagingService } from 'jslib/abstractions/messaging.service';
|
||||
|
||||
export class MenuMain {
|
||||
constructor(private windowMain: WindowMain, private i18nService: I18nService,
|
||||
|
@ -5,20 +5,47 @@ import { ConstantsService } from 'jslib/services/constants.service';
|
||||
import { MessagingService } from 'jslib/abstractions/messaging.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 {
|
||||
private idle: boolean = false;
|
||||
|
||||
constructor(private storageService: StorageService, private messagingService: MessagingService) { }
|
||||
|
||||
init() {
|
||||
// System sleep
|
||||
powerMonitor.on('suspend', async () => {
|
||||
const lockOption = await this.storageService.get<number>(ConstantsService.lockOptionKey);
|
||||
const lockOption = await this.getLockOption();
|
||||
if (lockOption === -3) {
|
||||
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
|
||||
}
|
||||
|
||||
private async getLockOption(): Promise<number> {
|
||||
return await this.storageService.get<number>(ConstantsService.lockOptionKey);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user