1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-30 16:23:53 +00:00

Move macOS-specific window positioning to macOS provider

This commit is contained in:
Isaiah Inuwa
2026-01-07 10:23:49 -06:00
parent ce22286f28
commit bcaefeac47
2 changed files with 11 additions and 20 deletions

View File

@@ -189,20 +189,21 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
let finalWindowFrame = self.view.window?.frame ?? .zero
logger.log("[autofill-extension] position: Final window frame: \(NSStringFromRect(finalWindowFrame))")
let centerX, centerY: Int32;
// Use stabilized window frame if available, otherwise fallback to mouse position
if finalWindowFrame.origin.x != 0 || finalWindowFrame.origin.y != 0 {
let centerX = Int32(round(finalWindowFrame.origin.x))
let centerY = Int32(round(screenHeight - finalWindowFrame.origin.y))
centerX = Int32(round(finalWindowFrame.origin.x))
centerY = Int32(round(screenHeight - finalWindowFrame.origin.y))
logger.log("[autofill-extension] position: Using window position: x=\(centerX), y=\(centerY)")
return Position(x: centerX, y: centerY)
} else {
// Fallback to mouse position
let mouseLocation = NSEvent.mouseLocation
let mouseX = Int32(round(mouseLocation.x))
let mouseY = Int32(round(screenHeight - mouseLocation.y))
logger.log("[autofill-extension] position: Using mouse position fallback: x=\(mouseX), y=\(mouseY)")
return Position(x: mouseX, y: mouseY)
centerX = Int32(round(mouseLocation.x))
centerY = Int32(round(screenHeight - mouseLocation.y))
logger.log("[autofill-extension] position: Using mouse position fallback: x=\(centerX), y=\(centerY)")
}
// Add 100 pixels to the x-coordinate to offset the native OS dialog positioning.
return Position(x: centerX + 100, y: centerY)
}
override func viewDidLoad() {

View File

@@ -227,7 +227,7 @@ export class DesktopAutofillService implements OnDestroy {
try {
const response = await this.fido2AuthenticatorService.makeCredential(
this.convertRegistrationRequest(request),
{ windowXy: normalizePosition(request.windowXy) },
{ windowXy: request.windowXy },
controller,
);
@@ -293,7 +293,7 @@ export class DesktopAutofillService implements OnDestroy {
const response = await this.fido2AuthenticatorService.getAssertion(
this.convertAssertionRequest(request, true),
{ windowXy: normalizePosition(request.windowXy) },
{ windowXy: request.windowXy },
controller,
);
@@ -321,7 +321,7 @@ export class DesktopAutofillService implements OnDestroy {
try {
const response = await this.fido2AuthenticatorService.getAssertion(
this.convertAssertionRequest(request),
{ windowXy: normalizePosition(request.windowXy) },
{ windowXy: request.windowXy },
controller,
);
@@ -455,13 +455,3 @@ export class DesktopAutofillService implements OnDestroy {
this.destroy$.complete();
}
}
function normalizePosition(position: { x: number; y: number }): { x: number; y: number } {
// Add 100 pixels to the x-coordinate to offset the native OS dialog positioning.
const xPositionOffset = 100;
return {
x: Math.round(position.x + xPositionOffset),
y: Math.round(position.y),
};
}