mirror of
https://github.com/bitwarden/browser
synced 2025-12-22 11:13:46 +00:00
[PM-9149] Enable "Timeout on System Lock" on Linux Desktop (#9645)
* Enable system lock detection on linux * Fix order of vault timeout options * Port to new plit core / napi desktop native crates * Make unimplemented implementation panic for on_lock * Remove unecessary String::from * Update cargo lock * Extract generation of vault timeout options
This commit is contained in:
@@ -46,7 +46,7 @@ export class SettingsComponent implements OnInit {
|
||||
protected readonly VaultTimeoutAction = VaultTimeoutAction;
|
||||
|
||||
showMinToTray = false;
|
||||
vaultTimeoutOptions: VaultTimeoutOption[];
|
||||
vaultTimeoutOptions: VaultTimeoutOption[] = [];
|
||||
localeOptions: any[];
|
||||
themeOptions: any[];
|
||||
clearClipboardOptions: any[];
|
||||
@@ -161,29 +161,6 @@ export class SettingsComponent implements OnInit {
|
||||
// DuckDuckGo browser is only for macos initially
|
||||
this.showDuckDuckGoIntegrationOption = isMac;
|
||||
|
||||
this.vaultTimeoutOptions = [
|
||||
{ name: this.i18nService.t("oneMinute"), value: 1 },
|
||||
{ name: this.i18nService.t("fiveMinutes"), value: 5 },
|
||||
{ name: this.i18nService.t("fifteenMinutes"), value: 15 },
|
||||
{ name: this.i18nService.t("thirtyMinutes"), value: 30 },
|
||||
{ name: this.i18nService.t("oneHour"), value: 60 },
|
||||
{ name: this.i18nService.t("fourHours"), value: 240 },
|
||||
{ name: this.i18nService.t("onIdle"), value: VaultTimeoutStringType.OnIdle },
|
||||
{ name: this.i18nService.t("onSleep"), value: VaultTimeoutStringType.OnSleep },
|
||||
];
|
||||
|
||||
if (this.platformUtilsService.getDevice() !== DeviceType.LinuxDesktop) {
|
||||
this.vaultTimeoutOptions.push({
|
||||
name: this.i18nService.t("onLocked"),
|
||||
value: VaultTimeoutStringType.OnLocked,
|
||||
});
|
||||
}
|
||||
|
||||
this.vaultTimeoutOptions = this.vaultTimeoutOptions.concat([
|
||||
{ name: this.i18nService.t("onRestart"), value: VaultTimeoutStringType.OnRestart },
|
||||
{ name: this.i18nService.t("never"), value: VaultTimeoutStringType.Never },
|
||||
]);
|
||||
|
||||
const localeOptions: any[] = [];
|
||||
this.i18nService.supportedTranslationLocales.forEach((locale) => {
|
||||
let name = locale;
|
||||
@@ -215,6 +192,8 @@ export class SettingsComponent implements OnInit {
|
||||
}
|
||||
|
||||
async ngOnInit() {
|
||||
this.vaultTimeoutOptions = await this.generateVaultTimeoutOptions();
|
||||
|
||||
this.userHasMasterPassword = await this.userVerificationService.hasMasterPassword();
|
||||
|
||||
this.isWindows = (await this.platformUtilsService.getDevice()) === DeviceType.WindowsDesktop;
|
||||
@@ -718,6 +697,33 @@ export class SettingsComponent implements OnInit {
|
||||
);
|
||||
}
|
||||
|
||||
private async generateVaultTimeoutOptions(): Promise<VaultTimeoutOption[]> {
|
||||
let vaultTimeoutOptions: VaultTimeoutOption[] = [
|
||||
{ name: this.i18nService.t("oneMinute"), value: 1 },
|
||||
{ name: this.i18nService.t("fiveMinutes"), value: 5 },
|
||||
{ name: this.i18nService.t("fifteenMinutes"), value: 15 },
|
||||
{ name: this.i18nService.t("thirtyMinutes"), value: 30 },
|
||||
{ name: this.i18nService.t("oneHour"), value: 60 },
|
||||
{ name: this.i18nService.t("fourHours"), value: 240 },
|
||||
{ name: this.i18nService.t("onIdle"), value: VaultTimeoutStringType.OnIdle },
|
||||
{ name: this.i18nService.t("onSleep"), value: VaultTimeoutStringType.OnSleep },
|
||||
];
|
||||
|
||||
if (await ipc.platform.powermonitor.isLockMonitorAvailable()) {
|
||||
vaultTimeoutOptions.push({
|
||||
name: this.i18nService.t("onLocked"),
|
||||
value: VaultTimeoutStringType.OnLocked,
|
||||
});
|
||||
}
|
||||
|
||||
vaultTimeoutOptions = vaultTimeoutOptions.concat([
|
||||
{ name: this.i18nService.t("onRestart"), value: VaultTimeoutStringType.OnRestart },
|
||||
{ name: this.i18nService.t("never"), value: VaultTimeoutStringType.Never },
|
||||
]);
|
||||
|
||||
return vaultTimeoutOptions;
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
|
||||
@@ -184,7 +184,7 @@ export class Main {
|
||||
});
|
||||
});
|
||||
|
||||
this.powerMonitorMain = new PowerMonitorMain(this.messagingService);
|
||||
this.powerMonitorMain = new PowerMonitorMain(this.messagingService, this.logService);
|
||||
this.menuMain = new MenuMain(
|
||||
this.i18nService,
|
||||
this.messagingService,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { powerMonitor } from "electron";
|
||||
import { ipcMain, powerMonitor } from "electron";
|
||||
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
import { MessageSender } from "@bitwarden/common/platform/messaging";
|
||||
import { powermonitors } from "@bitwarden/desktop-napi";
|
||||
|
||||
import { isSnapStore } from "../utils";
|
||||
|
||||
@@ -11,7 +13,10 @@ const IdleCheckInterval = 30 * 1000; // 30 seconds
|
||||
export class PowerMonitorMain {
|
||||
private idle = false;
|
||||
|
||||
constructor(private messagingService: MessageSender) {}
|
||||
constructor(
|
||||
private messagingService: MessageSender,
|
||||
private logService: LogService,
|
||||
) {}
|
||||
|
||||
init() {
|
||||
// ref: https://github.com/electron/electron/issues/13767
|
||||
@@ -27,7 +32,22 @@ export class PowerMonitorMain {
|
||||
powerMonitor.on("lock-screen", () => {
|
||||
this.messagingService.send("systemLocked");
|
||||
});
|
||||
} else {
|
||||
powermonitors
|
||||
.onLock(() => {
|
||||
this.messagingService.send("systemLocked");
|
||||
})
|
||||
.catch((error) => {
|
||||
this.logService.error("Error setting up lock monitor", { error });
|
||||
});
|
||||
}
|
||||
ipcMain.handle("powermonitor.isLockMonitorAvailable", async (_event: any, _message: any) => {
|
||||
if (process.platform !== "linux") {
|
||||
return true;
|
||||
} else {
|
||||
return await powermonitors.isLockMonitorAvailable();
|
||||
}
|
||||
});
|
||||
|
||||
// System idle
|
||||
global.setInterval(() => {
|
||||
|
||||
@@ -59,6 +59,11 @@ const clipboard = {
|
||||
write: (message: ClipboardWriteMessage) => ipcRenderer.invoke("clipboard.write", message),
|
||||
};
|
||||
|
||||
const powermonitor = {
|
||||
isLockMonitorAvailable: (): Promise<boolean> =>
|
||||
ipcRenderer.invoke("powermonitor.isLockMonitorAvailable"),
|
||||
};
|
||||
|
||||
const nativeMessaging = {
|
||||
sendReply: (message: EncryptedMessageResponse | UnencryptedMessageResponse) => {
|
||||
ipcRenderer.send("nativeMessagingReply", message);
|
||||
@@ -148,6 +153,7 @@ export default {
|
||||
passwords,
|
||||
biometric,
|
||||
clipboard,
|
||||
powermonitor,
|
||||
nativeMessaging,
|
||||
crypto,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user