mirror of
https://github.com/bitwarden/browser
synced 2026-02-02 09:43:29 +00:00
Move macOS-specific position quirk to native code
This commit is contained in:
@@ -190,19 +190,24 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
|
||||
logger.log("[autofill-extension] position: Final window frame: \(NSStringFromRect(finalWindowFrame))")
|
||||
|
||||
// Use stabilized window frame if available, otherwise fallback to mouse position
|
||||
let x, y: Int32
|
||||
if finalWindowFrame.origin.x != 0 || finalWindowFrame.origin.y != 0 {
|
||||
let centerX = Int32(round(finalWindowFrame.origin.x))
|
||||
let 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)
|
||||
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)
|
||||
x = mouseX
|
||||
y = mouseY
|
||||
}
|
||||
// Add 100 pixels to the x-coordinate to offset the native OS dialog positioning.
|
||||
return Position(x: x + 100, y: y)
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
|
||||
@@ -213,7 +213,7 @@ export class DesktopAutofillService implements OnDestroy {
|
||||
try {
|
||||
const response = await this.fido2AuthenticatorService.makeCredential(
|
||||
this.convertRegistrationRequest(request),
|
||||
{ windowXy: normalizePosition(request.windowXy) },
|
||||
{ windowXy: request.windowXy },
|
||||
controller,
|
||||
);
|
||||
|
||||
@@ -281,7 +281,7 @@ export class DesktopAutofillService implements OnDestroy {
|
||||
|
||||
const response = await this.fido2AuthenticatorService.getAssertion(
|
||||
this.convertAssertionRequest(request, true),
|
||||
{ windowXy: normalizePosition(request.windowXy) },
|
||||
{ windowXy: request.windowXy },
|
||||
controller,
|
||||
);
|
||||
|
||||
@@ -309,7 +309,7 @@ export class DesktopAutofillService implements OnDestroy {
|
||||
try {
|
||||
const response = await this.fido2AuthenticatorService.getAssertion(
|
||||
this.convertAssertionRequest(request),
|
||||
{ windowXy: normalizePosition(request.windowXy) },
|
||||
{ windowXy: request.windowXy },
|
||||
controller,
|
||||
);
|
||||
|
||||
@@ -442,14 +442,4 @@ export class DesktopAutofillService implements OnDestroy {
|
||||
this.destroy$.next();
|
||||
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 xPostionOffset = 100;
|
||||
|
||||
return {
|
||||
x: Math.round(position.x + xPostionOffset),
|
||||
y: Math.round(position.y),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user