1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-05 19:23:19 +00:00

Autofill/pm 21864 center unlock vault modal (#14867)

* Center the Locked Vault modal when using passkeys

* Revert swift changes and handle offscreen modals

* Remove comments
This commit is contained in:
Jeffrey Holland
2025-06-02 18:31:34 +02:00
committed by GitHub
parent 10ae123cb2
commit 0376ead84e
2 changed files with 25 additions and 4 deletions

View File

@@ -138,14 +138,13 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
private func getWindowPosition() -> Position {
let frame = self.view.window?.frame ?? .zero
let screenHeight = NSScreen.main?.frame.height ?? 0
let screenHeight = NSScreen.main?.frame.height ?? 0
// frame.width and frame.height is always 0. Estimating works OK for now.
let estimatedWidth:CGFloat = 400;
let estimatedHeight:CGFloat = 200;
let centerX = Int32(round(frame.origin.x + estimatedWidth/2))
let centerY = Int32(round(screenHeight - (frame.origin.y + estimatedHeight/2)))
return Position(x: centerX, y:centerY)
}

View File

@@ -265,6 +265,7 @@ export class DesktopFido2UserInterfaceSession implements Fido2UserInterfaceSessi
): Promise<void> {
// Load the UI:
await this.desktopSettingsService.setModalMode(true, showTrafficButtons, position);
await this.centerOffscreenPopup();
await this.router.navigate([
route,
{
@@ -341,7 +342,7 @@ export class DesktopFido2UserInterfaceSession implements Fido2UserInterfaceSessi
const status = await firstValueFrom(this.authService.activeAccountStatus$);
if (status !== AuthenticationStatus.Unlocked) {
await this.showUi("/lock", this.windowObject.windowXy, true, true);
await this.showUi("/lock", undefined, true, true);
let status2: AuthenticationStatus;
try {
@@ -370,4 +371,25 @@ export class DesktopFido2UserInterfaceSession implements Fido2UserInterfaceSessi
async close() {
this.logService.warning("close");
}
private async centerOffscreenPopup() {
if (!this.windowObject.windowXy) {
return;
}
const popupWidth = 600;
const popupHeight = 600;
const window = await firstValueFrom(this.desktopSettingsService.window$);
const { width, height } = window.displayBounds;
const { x, y } = this.windowObject.windowXy;
if (x < popupWidth || x > width - popupWidth || y < popupHeight || y > height - popupHeight) {
const popupHeightOffset = 300;
const { width, height } = window.displayBounds;
const centeredX = width / 2;
const centeredY = (height - popupHeightOffset) / 2;
this.windowObject.windowXy = { x: centeredX, y: centeredY };
}
}
}