1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-12 22:33:35 +00:00

[PM-22781] Implement autoconnect to desktop app on app start (#15266)

* Implement autoconnect to desktop app on app start

* Update apps/browser/src/background/nativeMessaging.background.ts

Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com>

* Silence errors and only connect while popup is not open

* Run autoconnect regardless of popup being open

---------

Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com>
This commit is contained in:
Bernd Schoolmann
2025-07-11 19:43:10 +02:00
committed by GitHub
parent c9f642e491
commit a32f745c99
2 changed files with 33 additions and 2 deletions

View File

@@ -105,6 +105,16 @@ export class NativeMessagingBackground {
}
async connect() {
if (!(await BrowserApi.permissionsGranted(["nativeMessaging"]))) {
this.logService.warning(
"[Native Messaging IPC] Native messaging permission is missing for biometrics",
);
return;
}
if (this.connected || this.connecting) {
return;
}
this.logService.info("[Native Messaging IPC] Connecting to Bitwarden Desktop app...");
const appId = await this.appIdService.getAppId();
this.appId = appId;

View File

@@ -1,3 +1,6 @@
import { combineLatest, timer } from "rxjs";
import { filter, concatMap } from "rxjs/operators";
import { VaultTimeoutSettingsService } from "@bitwarden/common/key-management/vault-timeout";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
@@ -17,6 +20,8 @@ import { NativeMessagingBackground } from "../../background/nativeMessaging.back
import { BrowserApi } from "../../platform/browser/browser-api";
export class BackgroundBrowserBiometricsService extends BiometricsService {
BACKGROUND_POLLING_INTERVAL = 30_000;
constructor(
private nativeMessagingBackground: () => NativeMessagingBackground,
private logService: LogService,
@@ -26,6 +31,24 @@ export class BackgroundBrowserBiometricsService extends BiometricsService {
private vaultTimeoutSettingsService: VaultTimeoutSettingsService,
) {
super();
// Always connect to the native messaging background if biometrics are enabled, not just when it is used
// so that there is no wait when used.
const biometricsEnabled = this.biometricStateService.biometricUnlockEnabled$;
combineLatest([timer(0, this.BACKGROUND_POLLING_INTERVAL), biometricsEnabled])
.pipe(
filter(([_, enabled]) => enabled),
filter(([_]) => !this.nativeMessagingBackground().connected),
concatMap(async () => {
try {
await this.nativeMessagingBackground().connect();
await this.getBiometricsStatus();
} catch {
// Ignore
}
}),
)
.subscribe();
}
async authenticateWithBiometrics(): Promise<boolean> {
@@ -48,8 +71,6 @@ export class BackgroundBrowserBiometricsService extends BiometricsService {
}
try {
await this.ensureConnected();
const response = await this.nativeMessagingBackground().callCommand({
command: BiometricsCommands.GetBiometricsStatus,
});