diff --git a/apps/desktop/macos/autofill-extension/CredentialProviderViewController.swift b/apps/desktop/macos/autofill-extension/CredentialProviderViewController.swift index 5befed88563..4288ca8f3fe 100644 --- a/apps/desktop/macos/autofill-extension/CredentialProviderViewController.swift +++ b/apps/desktop/macos/autofill-extension/CredentialProviderViewController.swift @@ -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) } diff --git a/apps/desktop/src/autofill/services/desktop-fido2-user-interface.service.ts b/apps/desktop/src/autofill/services/desktop-fido2-user-interface.service.ts index 6bce6732c09..1b69f6fb57a 100644 --- a/apps/desktop/src/autofill/services/desktop-fido2-user-interface.service.ts +++ b/apps/desktop/src/autofill/services/desktop-fido2-user-interface.service.ts @@ -265,6 +265,7 @@ export class DesktopFido2UserInterfaceSession implements Fido2UserInterfaceSessi ): Promise { // 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 }; + } + } }