mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 07:43: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:
@@ -105,6 +105,16 @@ export class NativeMessagingBackground {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async connect() {
|
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...");
|
this.logService.info("[Native Messaging IPC] Connecting to Bitwarden Desktop app...");
|
||||||
const appId = await this.appIdService.getAppId();
|
const appId = await this.appIdService.getAppId();
|
||||||
this.appId = appId;
|
this.appId = appId;
|
||||||
|
|||||||
@@ -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 { VaultTimeoutSettingsService } from "@bitwarden/common/key-management/vault-timeout";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.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";
|
import { BrowserApi } from "../../platform/browser/browser-api";
|
||||||
|
|
||||||
export class BackgroundBrowserBiometricsService extends BiometricsService {
|
export class BackgroundBrowserBiometricsService extends BiometricsService {
|
||||||
|
BACKGROUND_POLLING_INTERVAL = 30_000;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private nativeMessagingBackground: () => NativeMessagingBackground,
|
private nativeMessagingBackground: () => NativeMessagingBackground,
|
||||||
private logService: LogService,
|
private logService: LogService,
|
||||||
@@ -26,6 +31,24 @@ export class BackgroundBrowserBiometricsService extends BiometricsService {
|
|||||||
private vaultTimeoutSettingsService: VaultTimeoutSettingsService,
|
private vaultTimeoutSettingsService: VaultTimeoutSettingsService,
|
||||||
) {
|
) {
|
||||||
super();
|
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> {
|
async authenticateWithBiometrics(): Promise<boolean> {
|
||||||
@@ -48,8 +71,6 @@ export class BackgroundBrowserBiometricsService extends BiometricsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.ensureConnected();
|
|
||||||
|
|
||||||
const response = await this.nativeMessagingBackground().callCommand({
|
const response = await this.nativeMessagingBackground().callCommand({
|
||||||
command: BiometricsCommands.GetBiometricsStatus,
|
command: BiometricsCommands.GetBiometricsStatus,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user