From ab5eb3092988f46b8093279d52156b71c7499e39 Mon Sep 17 00:00:00 2001 From: Bernd Schoolmann Date: Fri, 30 May 2025 13:48:43 +0200 Subject: [PATCH] Apply small fixes --- apps/browser/src/_locales/en/messages.json | 3 +++ .../account-switcher.component.ts | 6 +++++ .../background/nativeMessaging.background.ts | 22 +++++++++---------- .../foreground-synced-unlock.service.ts | 6 ++--- apps/desktop/src/main/messaging.main.ts | 1 + .../src/lock/components/lock.component.html | 8 ++++--- .../src/lock/components/lock.component.ts | 18 +++++++++++++-- 7 files changed, 45 insertions(+), 19 deletions(-) diff --git a/apps/browser/src/_locales/en/messages.json b/apps/browser/src/_locales/en/messages.json index 52e08afa59b..d11c2d5a6ba 100644 --- a/apps/browser/src/_locales/en/messages.json +++ b/apps/browser/src/_locales/en/messages.json @@ -2177,6 +2177,9 @@ "lockScreenDesktopNotRunning": { "message": "This user's account is synchronized with the desktop app, but the desktop app is not running." }, + "lockScreenDesktopRunningButLoggedOut": { + "message": "User account synchronization is enabled, but the active account is logged out in the desktop app." + }, "unlockWithBiometrics": { "message": "Unlock with biometrics" }, diff --git a/apps/browser/src/auth/popup/account-switching/account-switcher.component.ts b/apps/browser/src/auth/popup/account-switching/account-switcher.component.ts index d575c48deaf..10736a2d7b8 100644 --- a/apps/browser/src/auth/popup/account-switching/account-switcher.component.ts +++ b/apps/browser/src/auth/popup/account-switching/account-switcher.component.ts @@ -131,6 +131,12 @@ export class AccountSwitcherComponent implements OnInit, OnDestroy { async lockAll() { this.loading = true; + + const accounts = await firstValueFrom(this.accountService.accounts$); + for (const userId of Object.keys(accounts) as UserId[]) { + await this.foregroundSyncedUnlockService.lock(userId); + } + await this.lockService.lockAll(); await this.router.navigate(["lock"]); } diff --git a/apps/browser/src/background/nativeMessaging.background.ts b/apps/browser/src/background/nativeMessaging.background.ts index 0e55cc95872..62613e98561 100644 --- a/apps/browser/src/background/nativeMessaging.background.ts +++ b/apps/browser/src/background/nativeMessaging.background.ts @@ -298,18 +298,18 @@ export class NativeMessagingBackground { const callback = new Promise((resolver, rejecter) => { this.callbacks.set(messageId, { resolver, rejecter }); + message.messageId = messageId; + this.send(message) + .then(() => {}) + .catch((e) => { + this.logService.error( + `[Native Messaging IPC] Error sending message of type ${message.command} to Bitwarden Desktop app. Error: ${e}`, + ); + const callback = this.callbacks.get(messageId); + this.callbacks.delete(messageId); + callback?.rejecter("errorConnecting"); + }); }); - message.messageId = messageId; - try { - await this.send(message); - } catch (e) { - this.logService.info( - `[Native Messaging IPC] Error sending message of type ${message.command} to Bitwarden Desktop app. Error: ${e}`, - ); - const callback = this.callbacks.get(messageId); - this.callbacks.delete(messageId); - callback?.rejecter("errorConnecting"); - } setTimeout(() => { if (this.callbacks.has(messageId)) { diff --git a/apps/browser/src/key-management/synced-unlock/foreground-synced-unlock.service.ts b/apps/browser/src/key-management/synced-unlock/foreground-synced-unlock.service.ts index 232f29135ab..0e229e8113a 100644 --- a/apps/browser/src/key-management/synced-unlock/foreground-synced-unlock.service.ts +++ b/apps/browser/src/key-management/synced-unlock/foreground-synced-unlock.service.ts @@ -43,7 +43,7 @@ export class ForegroundSyncedUnlockService extends SyncedUnlockService { result: AuthenticationStatus; error: string; }>(SyncedUnlockStateCommands.GetUserStatusFromDesktop, { userId }); - if (!response.result) { + if (response.result == null) { throw response.error; } return response.result; @@ -54,7 +54,7 @@ export class ForegroundSyncedUnlockService extends SyncedUnlockService { result: UserKey; error: string; }>(SyncedUnlockStateCommands.GetUserKeyFromDesktop, { userId }); - if (!response.result) { + if (response.result == null) { return null; } return response.result; @@ -65,7 +65,7 @@ export class ForegroundSyncedUnlockService extends SyncedUnlockService { result: boolean; error: string; }>(SyncedUnlockStateCommands.FocusDesktopApp); - if (!response.result) { + if (response.result == null) { throw response.error; } } diff --git a/apps/desktop/src/main/messaging.main.ts b/apps/desktop/src/main/messaging.main.ts index bb4063d64fd..a220f76d1de 100644 --- a/apps/desktop/src/main/messaging.main.ts +++ b/apps/desktop/src/main/messaging.main.ts @@ -157,6 +157,7 @@ Terminal=false`; private setFocus() { this.main.trayMain.restoreFromTray(); + this.main.windowMain.win.focus(); this.main.windowMain.win.focusOnWebView(); } diff --git a/libs/key-management-ui/src/lock/components/lock.component.html b/libs/key-management-ui/src/lock/components/lock.component.html index b56a2ea2ff9..588ea26b3c5 100644 --- a/libs/key-management-ui/src/lock/components/lock.component.html +++ b/libs/key-management-ui/src/lock/components/lock.component.html @@ -8,8 +8,7 @@
- {{ "lockScreenSynchronizedNote" | i18n }} + {{ "lockScreenSynchronizedNote" | i18n }} @@ -17,9 +16,12 @@ - + {{ "lockScreenDesktopNotRunning" | i18n }} + + {{ "lockScreenDesktopRunningButLoggedOut" | i18n }} + diff --git a/libs/key-management-ui/src/lock/components/lock.component.ts b/libs/key-management-ui/src/lock/components/lock.component.ts index b4ab3b5fce4..b6ce21cb167 100644 --- a/libs/key-management-ui/src/lock/components/lock.component.ts +++ b/libs/key-management-ui/src/lock/components/lock.component.ts @@ -22,6 +22,7 @@ import { InternalPolicyService } from "@bitwarden/common/admin-console/abstracti import { MasterPasswordPolicyOptions } from "@bitwarden/common/admin-console/models/domain/master-password-policy-options"; import { Account, AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction"; +import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status"; import { VerificationType } from "@bitwarden/common/auth/enums/verification-type"; import { ForceSetPasswordReason } from "@bitwarden/common/auth/models/domain/force-set-password-reason"; import { getUserId } from "@bitwarden/common/auth/services/account.service"; @@ -138,6 +139,7 @@ export class LockComponent implements OnInit, OnDestroy { unlockViaDesktop = false; isDesktopOpen = false; + activeUserLoggedOut = false; showLocalUnlockOptions = true; desktopUnlockFormGroup: FormGroup = new FormGroup({}); @@ -212,12 +214,24 @@ export class LockComponent implements OnInit, OnDestroy { takeUntil(this.destroy$), ) .subscribe(); - interval(500) + interval(1000) .pipe( switchMap(async () => { try { + const activeAccount = await firstValueFrom(this.accountService.activeAccount$); + if (activeAccount == null) { + return; + } + this.isDesktopOpen = await this.syncedUnlockService.isConnected(); - this.showLocalUnlockOptions = !(this.isDesktopOpen && this.unlockViaDesktop); + this.activeUserLoggedOut = + (await this.syncedUnlockService.getUserStatusFromDesktop(activeAccount.id)) === + AuthenticationStatus.LoggedOut; + this.showLocalUnlockOptions = !( + this.isDesktopOpen && + this.unlockViaDesktop && + !this.activeUserLoggedOut + ); } catch (e) { this.logService.error(e); }