1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-11-27 12:26:38 +01:00

[bug] Inactive accounts with power-based timeout settings are not timing out (#1278)

* [bug] Move bulk of system lock checks into app.component

* [review] Extract shared system timeout logic

* [review] Correct an improper number

* [review] Opt for a more locally scoped system timeout helper than a dedicated enum
This commit is contained in:
Addison Beck 2022-02-01 11:31:30 -05:00 committed by GitHub
parent 2b22a39d45
commit 48ff9f61ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 27 deletions

View File

@ -53,6 +53,12 @@ const BroadcasterSubscriptionId = "AppComponent";
const IdleTimeout = 60000 * 10; // 10 minutes
const SyncInterval = 6 * 60 * 60 * 1000; // 6 hours
const systemTimeoutOptions = {
onLock: -2,
onSuspend: -3,
onIdle: -4,
};
@Component({
selector: "app-root",
styles: [],
@ -339,6 +345,12 @@ export class AppComponent implements OnInit {
this.router.navigate(["vault"]);
}
break;
case "systemSuspended":
await this.checkForSystemTimeout(systemTimeoutOptions.onSuspend);
case "systemLocked":
await this.checkForSystemTimeout(systemTimeoutOptions.onLock);
case "systemIdle":
await this.checkForSystemTimeout(systemTimeoutOptions.onIdle);
}
});
});
@ -583,4 +595,24 @@ export class AppComponent implements OnInit {
}
await this.systemService.startProcessReload();
}
private async checkForSystemTimeout(timeout: number): Promise<void> {
for (const userId in this.stateService.accounts.getValue()) {
if (userId == null) {
continue;
}
const options = await this.getVaultTimeoutOptions(userId);
if (options[0] === timeout) {
options[1] === "logOut"
? this.logOut(false, userId)
: await this.vaultTimeoutService.lock(true, userId);
}
}
}
private async getVaultTimeoutOptions(userId: string): Promise<[number, string]> {
const timeout = await this.stateService.getVaultTimeout({ userId: userId });
const action = await this.stateService.getVaultTimeoutAction({ userId: userId });
return [timeout, action];
}
}

View File

@ -17,30 +17,20 @@ export class PowerMonitorMain {
// ref: https://github.com/electron/electron/issues/13767
if (!isSnapStore()) {
// System sleep
powerMonitor.on("suspend", async () => {
const options = await this.getVaultTimeoutOptions();
if (options[0] === -3) {
options[1] === "logOut"
? this.main.messagingService.send("logout", { expired: false })
: this.main.messagingService.send("lockVault");
}
powerMonitor.on("suspend", () => {
this.main.messagingService.send("systemSuspended");
});
}
if (process.platform !== "linux") {
// System locked
powerMonitor.on("lock-screen", async () => {
const options = await this.getVaultTimeoutOptions();
if (options[0] === -2) {
options[1] === "logOut"
? this.main.messagingService.send("logout", { expired: false })
: this.main.messagingService.send("lockVault");
}
powerMonitor.on("lock-screen", () => {
this.main.messagingService.send("systemLocked");
});
}
// System idle
global.setInterval(async () => {
global.setInterval(() => {
const idleSeconds: number = powerMonitor.getSystemIdleTime();
const idle = idleSeconds >= IdleLockSeconds;
if (idle) {
@ -48,21 +38,10 @@ export class PowerMonitorMain {
return;
}
const options = await this.getVaultTimeoutOptions();
if (options[0] === -4) {
options[1] === "logOut"
? this.main.messagingService.send("logout", { expired: false })
: this.main.messagingService.send("lockVault");
}
this.main.messagingService.send("systemIdle");
}
this.idle = idle;
}, IdleCheckInterval);
}
private async getVaultTimeoutOptions(): Promise<[number, string]> {
const timeout = await this.main.stateService.getVaultTimeout();
const action = await this.main.stateService.getVaultTimeoutAction();
return [timeout, action];
}
}