bitwarden-estensione-browser/apps/desktop/src/main/power-monitor.main.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.1 KiB
TypeScript
Raw Normal View History

2018-02-11 05:24:22 +01:00
import { powerMonitor } from "electron";
import { MessageSender } from "@bitwarden/common/platform/messaging";
import { isSnapStore } from "../utils";
2018-02-11 05:24:22 +01:00
2018-02-11 06:09:47 +01:00
// tslint:disable-next-line
const IdleLockSeconds = 5 * 60; // 5 minutes
const IdleCheckInterval = 30 * 1000; // 30 seconds
2018-02-11 05:24:22 +01:00
export class PowerMonitorMain {
2022-02-24 20:50:19 +01:00
private idle = false;
2018-02-11 06:09:47 +01:00
constructor(private messagingService: MessageSender) {}
2018-02-11 05:24:22 +01:00
init() {
2018-07-26 22:50:05 +02:00
// ref: https://github.com/electron/electron/issues/13767
if (!isSnapStore()) {
// System sleep
powerMonitor.on("suspend", () => {
[PM-469] [PM-1325] [PS-1165] [PS-1257] Small refactorings/improvements on the desktop app main (#4704) * Only pass necessary service to power-monitor PowerMonitorMain only requires the messagingService instead of a full reference to Main * Remove never changing constructor params Window.main has a defaultWidth and defaultHeight that never change, so they do not need to get passed in from outside hideTitleBar is always true, so there is no need to make it a param * Remove projectName from updater This is likely another relict from sharing this previously with dircetory-connector and is not needed anymore * Only pass necessary service to MenuMain MenuMain only needs service references instead of a full reference to Main * Refactor biometrics service Create BiometricsService that takes care of loading the platformspecifc services, hiding the implementation details Make it clearer which dependencies are needed by a specific biometrics-service (compile-error vs runtime-error) Add unit tests Isolate biometrics import/exports with a barrel file * Fix #3148 recordActivity was only getting called when user-activity in the main window is recognized When using biometrics to unlock, the Windows Hello/TouchID prompt would be focused and no input would be recognised. LastActive would have an old value and the vault would get locked * Improve reloading with biometrics * Mock import of desktop-native * Add mock for "@bitwarden/desktop-native-linux-x64-musl" * Revert "Add mock for "@bitwarden/desktop-native-linux-x64-musl"" This reverts commit 69771b94bf34ba9af9d23370b7d92ff8a20ec92e. * mock the exports of desktop-native * Pass process.platform inot BiometricsService
2023-03-10 21:32:26 +01:00
this.messagingService.send("systemSuspended");
2021-12-20 15:47:17 +01:00
});
}
2018-02-11 05:24:22 +01:00
2019-03-19 21:12:26 +01:00
if (process.platform !== "linux") {
// System locked
powerMonitor.on("lock-screen", () => {
[PM-469] [PM-1325] [PS-1165] [PS-1257] Small refactorings/improvements on the desktop app main (#4704) * Only pass necessary service to power-monitor PowerMonitorMain only requires the messagingService instead of a full reference to Main * Remove never changing constructor params Window.main has a defaultWidth and defaultHeight that never change, so they do not need to get passed in from outside hideTitleBar is always true, so there is no need to make it a param * Remove projectName from updater This is likely another relict from sharing this previously with dircetory-connector and is not needed anymore * Only pass necessary service to MenuMain MenuMain only needs service references instead of a full reference to Main * Refactor biometrics service Create BiometricsService that takes care of loading the platformspecifc services, hiding the implementation details Make it clearer which dependencies are needed by a specific biometrics-service (compile-error vs runtime-error) Add unit tests Isolate biometrics import/exports with a barrel file * Fix #3148 recordActivity was only getting called when user-activity in the main window is recognized When using biometrics to unlock, the Windows Hello/TouchID prompt would be focused and no input would be recognised. LastActive would have an old value and the vault would get locked * Improve reloading with biometrics * Mock import of desktop-native * Add mock for "@bitwarden/desktop-native-linux-x64-musl" * Revert "Add mock for "@bitwarden/desktop-native-linux-x64-musl"" This reverts commit 69771b94bf34ba9af9d23370b7d92ff8a20ec92e. * mock the exports of desktop-native * Pass process.platform inot BiometricsService
2023-03-10 21:32:26 +01:00
this.messagingService.send("systemLocked");
2021-12-20 15:47:17 +01:00
});
}
2019-03-19 21:12:26 +01:00
2018-02-11 06:09:47 +01:00
// System idle
global.setInterval(() => {
2021-02-03 18:47:44 +01:00
const idleSeconds: number = powerMonitor.getSystemIdleTime();
2018-02-11 06:09:47 +01:00
const idle = idleSeconds >= IdleLockSeconds;
if (idle) {
if (this.idle) {
return;
}
[PM-469] [PM-1325] [PS-1165] [PS-1257] Small refactorings/improvements on the desktop app main (#4704) * Only pass necessary service to power-monitor PowerMonitorMain only requires the messagingService instead of a full reference to Main * Remove never changing constructor params Window.main has a defaultWidth and defaultHeight that never change, so they do not need to get passed in from outside hideTitleBar is always true, so there is no need to make it a param * Remove projectName from updater This is likely another relict from sharing this previously with dircetory-connector and is not needed anymore * Only pass necessary service to MenuMain MenuMain only needs service references instead of a full reference to Main * Refactor biometrics service Create BiometricsService that takes care of loading the platformspecifc services, hiding the implementation details Make it clearer which dependencies are needed by a specific biometrics-service (compile-error vs runtime-error) Add unit tests Isolate biometrics import/exports with a barrel file * Fix #3148 recordActivity was only getting called when user-activity in the main window is recognized When using biometrics to unlock, the Windows Hello/TouchID prompt would be focused and no input would be recognised. LastActive would have an old value and the vault would get locked * Improve reloading with biometrics * Mock import of desktop-native * Add mock for "@bitwarden/desktop-native-linux-x64-musl" * Revert "Add mock for "@bitwarden/desktop-native-linux-x64-musl"" This reverts commit 69771b94bf34ba9af9d23370b7d92ff8a20ec92e. * mock the exports of desktop-native * Pass process.platform inot BiometricsService
2023-03-10 21:32:26 +01:00
this.messagingService.send("systemIdle");
2018-02-11 06:09:47 +01:00
}
this.idle = idle;
}, IdleCheckInterval);
2018-02-11 05:24:22 +01:00
}
}