diff --git a/package.json b/package.json index fde8f80800..f83fd54daa 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/app/accounts/settings.component.ts b/src/app/accounts/settings.component.ts index 5cbf17f2ee..a11e2bbeba 100644 --- a/src/app/accounts/settings.component.ts +++ b/src/app/accounts/settings.component.ts @@ -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 }, diff --git a/src/main/menu.main.ts b/src/main/menu.main.ts index 79d812fc49..dd0f45ed77 100644 --- a/src/main/menu.main.ts +++ b/src/main/menu.main.ts @@ -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, diff --git a/src/main/powerMonitor.main.ts b/src/main/powerMonitor.main.ts index 41698e761f..cd91980e17 100644 --- a/src/main/powerMonitor.main.ts +++ b/src/main/powerMonitor.main.ts @@ -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(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 { + return await this.storageService.get(ConstantsService.lockOptionKey); + } }