mirror of
https://github.com/bitwarden/browser.git
synced 2024-12-27 17:18:04 +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:
parent
2b22a39d45
commit
48ff9f61ae
@ -53,6 +53,12 @@ const BroadcasterSubscriptionId = "AppComponent";
|
|||||||
const IdleTimeout = 60000 * 10; // 10 minutes
|
const IdleTimeout = 60000 * 10; // 10 minutes
|
||||||
const SyncInterval = 6 * 60 * 60 * 1000; // 6 hours
|
const SyncInterval = 6 * 60 * 60 * 1000; // 6 hours
|
||||||
|
|
||||||
|
const systemTimeoutOptions = {
|
||||||
|
onLock: -2,
|
||||||
|
onSuspend: -3,
|
||||||
|
onIdle: -4,
|
||||||
|
};
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "app-root",
|
selector: "app-root",
|
||||||
styles: [],
|
styles: [],
|
||||||
@ -339,6 +345,12 @@ export class AppComponent implements OnInit {
|
|||||||
this.router.navigate(["vault"]);
|
this.router.navigate(["vault"]);
|
||||||
}
|
}
|
||||||
break;
|
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();
|
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];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,30 +17,20 @@ export class PowerMonitorMain {
|
|||||||
// ref: https://github.com/electron/electron/issues/13767
|
// ref: https://github.com/electron/electron/issues/13767
|
||||||
if (!isSnapStore()) {
|
if (!isSnapStore()) {
|
||||||
// System sleep
|
// System sleep
|
||||||
powerMonitor.on("suspend", async () => {
|
powerMonitor.on("suspend", () => {
|
||||||
const options = await this.getVaultTimeoutOptions();
|
this.main.messagingService.send("systemSuspended");
|
||||||
if (options[0] === -3) {
|
|
||||||
options[1] === "logOut"
|
|
||||||
? this.main.messagingService.send("logout", { expired: false })
|
|
||||||
: this.main.messagingService.send("lockVault");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.platform !== "linux") {
|
if (process.platform !== "linux") {
|
||||||
// System locked
|
// System locked
|
||||||
powerMonitor.on("lock-screen", async () => {
|
powerMonitor.on("lock-screen", () => {
|
||||||
const options = await this.getVaultTimeoutOptions();
|
this.main.messagingService.send("systemLocked");
|
||||||
if (options[0] === -2) {
|
|
||||||
options[1] === "logOut"
|
|
||||||
? this.main.messagingService.send("logout", { expired: false })
|
|
||||||
: this.main.messagingService.send("lockVault");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// System idle
|
// System idle
|
||||||
global.setInterval(async () => {
|
global.setInterval(() => {
|
||||||
const idleSeconds: number = powerMonitor.getSystemIdleTime();
|
const idleSeconds: number = powerMonitor.getSystemIdleTime();
|
||||||
const idle = idleSeconds >= IdleLockSeconds;
|
const idle = idleSeconds >= IdleLockSeconds;
|
||||||
if (idle) {
|
if (idle) {
|
||||||
@ -48,21 +38,10 @@ export class PowerMonitorMain {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const options = await this.getVaultTimeoutOptions();
|
this.main.messagingService.send("systemIdle");
|
||||||
if (options[0] === -4) {
|
|
||||||
options[1] === "logOut"
|
|
||||||
? this.main.messagingService.send("logout", { expired: false })
|
|
||||||
: this.main.messagingService.send("lockVault");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.idle = idle;
|
this.idle = idle;
|
||||||
}, IdleCheckInterval);
|
}, IdleCheckInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getVaultTimeoutOptions(): Promise<[number, string]> {
|
|
||||||
const timeout = await this.main.stateService.getVaultTimeout();
|
|
||||||
const action = await this.main.stateService.getVaultTimeoutAction();
|
|
||||||
return [timeout, action];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user