1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-10 21:50:15 +00:00

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
This commit is contained in:
Jeffrey Holland
2025-06-19 14:44:38 +02:00
committed by GitHub
parent c873f5a6e0
commit 7d72b98863

View File

@@ -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() {