From 7d72b98863704eae20c733064583f6a9b04a8bed Mon Sep 17 00:00:00 2001 From: Jeffrey Holland <124393578+jholland-livefront@users.noreply.github.com> Date: Thu, 19 Jun 2025 14:44:38 +0200 Subject: [PATCH] Autofill/pm 22821 center vault modal (#15243) * Center the vault modal for passkeys * Add comments and fix electron-builder.json * Set values to Int32 in the ternaries --- .../CredentialProviderViewController.swift | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/desktop/macos/autofill-extension/CredentialProviderViewController.swift b/apps/desktop/macos/autofill-extension/CredentialProviderViewController.swift index 4288ca8f3fe..d2cb14ea91e 100644 --- a/apps/desktop/macos/autofill-extension/CredentialProviderViewController.swift +++ b/apps/desktop/macos/autofill-extension/CredentialProviderViewController.swift @@ -139,13 +139,20 @@ class CredentialProviderViewController: ASCredentialProviderViewController { private func getWindowPosition() -> Position { let frame = self.view.window?.frame ?? .zero let screenHeight = NSScreen.main?.frame.height ?? 0 + let screenWidth = NSScreen.main?.frame.width ?? 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) + // passkey modals are 600x600. + let modalHeight: CGFloat = 600; + let modalWidth: CGFloat = 600; + let centerX = round(frame.origin.x + estimatedWidth/2) + let centerY = round(screenHeight - (frame.origin.y + estimatedHeight/2)) + // Check if centerX or centerY are beyond either edge of the screen. If they are find the center of the screen, otherwise use the original value. + let positionX = centerX + modalWidth >= screenWidth || CGFloat(centerX) - modalWidth <= 0 ? Int32(screenWidth/2) : Int32(centerX) + let positionY = centerY + modalHeight >= screenHeight || CGFloat(centerY) - modalHeight <= 0 ? Int32(screenHeight/2) : Int32(centerY) + return Position(x: positionX, y: positionY) } override func loadView() {