1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-10 13:40:06 +00:00

Change windowXy to a Record instead of [number,number]

This commit is contained in:
Anders Åberg
2025-02-28 10:11:16 +01:00
parent 866d8c4c27
commit c02f81eb5a
11 changed files with 45 additions and 25 deletions

View File

@@ -2,7 +2,7 @@ use std::sync::Arc;
use serde::{Deserialize, Serialize};
use crate::{BitwardenError, Callback, UserVerification};
use crate::{BitwardenError, Callback, Position, UserVerification};
#[derive(uniffi::Record, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
@@ -11,7 +11,7 @@ pub struct PasskeyAssertionRequest {
client_data_hash: Vec<u8>,
user_verification: UserVerification,
allowed_credentials: Vec<Vec<u8>>,
window_xy: Vec<i32>,
window_xy: Position,
//extension_input: Vec<u8>, TODO: Implement support for extensions
}
@@ -25,7 +25,7 @@ pub struct PasskeyAssertionWithoutUserInterfaceRequest {
record_identifier: Option<String>,
client_data_hash: Vec<u8>,
user_verification: UserVerification,
window_xy: Vec<i32>,
window_xy: Position,
}
#[derive(uniffi::Record, Serialize, Deserialize)]

View File

@@ -29,6 +29,13 @@ pub enum UserVerification {
Discouraged,
}
#[derive(uniffi::Record, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Position {
pub x: i32,
pub y: i32,
}
#[derive(Debug, uniffi::Error, Serialize, Deserialize)]
pub enum BitwardenError {
Internal(String),

View File

@@ -2,7 +2,7 @@ use std::sync::Arc;
use serde::{Deserialize, Serialize};
use crate::{BitwardenError, Callback, UserVerification};
use crate::{BitwardenError, Callback, Position, UserVerification};
#[derive(uniffi::Record, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
@@ -13,7 +13,7 @@ pub struct PasskeyRegistrationRequest {
client_data_hash: Vec<u8>,
user_verification: UserVerification,
supported_algorithms: Vec<i32>,
window_xy: Vec<i32>,
window_xy: Position,
}
#[derive(uniffi::Record, Serialize, Deserialize)]

View File

@@ -129,6 +129,10 @@ export declare namespace autofill {
Required = 'required',
Discouraged = 'discouraged'
}
export interface Position {
x: number
y: number
}
export interface PasskeyRegistrationRequest {
rpId: string
userName: string
@@ -136,7 +140,7 @@ export declare namespace autofill {
clientDataHash: Array<number>
userVerification: UserVerification
supportedAlgorithms: Array<number>
windowXy: Array<number>
windowXy: Position
}
export interface PasskeyRegistrationResponse {
rpId: string
@@ -149,7 +153,7 @@ export declare namespace autofill {
clientDataHash: Array<number>
userVerification: UserVerification
allowedCredentials: Array<Array<number>>
windowXy: Array<number>
windowXy: Position
}
export interface PasskeyAssertionWithoutUserInterfaceRequest {
rpId: string
@@ -159,7 +163,7 @@ export declare namespace autofill {
recordIdentifier?: string
clientDataHash: Array<number>
userVerification: UserVerification
windowXy: Array<number>
windowXy: Position
}
export interface PasskeyAssertionResponse {
rpId: string

View File

@@ -582,6 +582,14 @@ pub mod autofill {
pub value: Result<T, BitwardenError>,
}
#[napi(object)]
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Position {
pub x: i32,
pub y: i32,
}
#[napi(object)]
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
@@ -592,7 +600,7 @@ pub mod autofill {
pub client_data_hash: Vec<u8>,
pub user_verification: UserVerification,
pub supported_algorithms: Vec<i32>,
pub window_xy: Vec<i32>,
pub window_xy: Position,
}
#[napi(object)]
@@ -613,7 +621,7 @@ pub mod autofill {
pub client_data_hash: Vec<u8>,
pub user_verification: UserVerification,
pub allowed_credentials: Vec<Vec<u8>>,
pub window_xy: Vec<i32>,
pub window_xy: Position,
//extension_input: Vec<u8>, TODO: Implement support for extensions
}
@@ -628,7 +636,7 @@ pub mod autofill {
pub record_identifier: Option<String>,
pub client_data_hash: Vec<u8>,
pub user_verification: UserVerification,
pub window_xy: Vec<i32>,
pub window_xy: Position,
}
#[napi(object)]

View File

@@ -89,7 +89,7 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
self.extensionContext.completeRequest(withSelectedCredential: passwordCredential, completionHandler: nil)
}
private func getWindowPosition() -> [Int32] {
private func getWindowPosition() -> Position {
let frame = self.view.window?.frame ?? .zero
let screenHeight = NSScreen.main?.frame.height ?? 0
@@ -99,7 +99,7 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
let centerX = Int32(round(frame.origin.x + estimatedWidth/2))
let centerY = Int32(round(screenHeight - (frame.origin.y + estimatedHeight/2)))
return [centerX, centerY]
return Position(x: centerX, y:centerY)
}
override func loadView() {
@@ -255,7 +255,6 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
userVerification: userVerification,
supportedAlgorithms: request.supportedAlgorithms.map{ Int32($0.rawValue) },
windowXy: self.getWindowPosition()
)
logger.log("[autofill-extension] prepareInterface(passkey) calling preparePasskeyRegistration")

View File

@@ -151,7 +151,7 @@ export class DesktopAutofillService implements OnDestroy {
void this.fido2AuthenticatorService
.makeCredential(
this.convertRegistrationRequest(request),
{ windowXy: request.windowXy as [number, number] }, // TODO: Not sure if we want to change the type of windowXy to just number[] or if rust can generate [number,number]?
{ windowXy: request.windowXy },
controller,
)
.then((response) => {
@@ -206,7 +206,7 @@ export class DesktopAutofillService implements OnDestroy {
void this.fido2AuthenticatorService
.getAssertion(
this.convertAssertionRequest(request, true),
{ windowXy: request.windowXy as [number, number] },
{ windowXy: request.windowXy },
controller,
)
.then((response) => {
@@ -226,7 +226,7 @@ export class DesktopAutofillService implements OnDestroy {
void this.fido2AuthenticatorService
.getAssertion(
this.convertAssertionRequest(request),
{ windowXy: request.windowXy as [number, number] },
{ windowXy: request.windowXy },
controller,
)
.then((response) => {

View File

@@ -40,7 +40,7 @@ export type NativeWindowObject = {
/**
* The position of the window, first entry is the x position, second is the y position
*/
windowXy?: [number, number];
windowXy?: { x: number; y: number };
};
export class DesktopFido2UserInterfaceService
@@ -234,7 +234,7 @@ export class DesktopFido2UserInterfaceSession implements Fido2UserInterfaceSessi
}
}
private async showUi(route: string, position?: [number, number]): Promise<void> {
private async showUi(route: string, position?: { x: number; y: number }): Promise<void> {
// Load the UI:
// maybe toggling to modal mode shouldn't be done here?
await this.desktopSettingsService.setModalMode(true, position);

View File

@@ -14,5 +14,5 @@ export class WindowState {
export class ModalModeState {
isModalModeActive: boolean;
modalPosition?: [number, number]; // Modal position is often passed from the native UI
modalPosition?: { x: number; y: number }; // Modal position is often passed from the native UI
}

View File

@@ -6,7 +6,9 @@ import { WindowState } from "./models/domain/window-state";
const popupWidth = 680;
const popupHeight = 500;
export function applyPopupModalStyles(window: BrowserWindow, position?: [number, number]) {
type Position = { x: number; y: number };
export function applyPopupModalStyles(window: BrowserWindow, position?: Position) {
window.unmaximize();
window.setSize(popupWidth, popupHeight);
window.setWindowButtonVisibility?.(false);
@@ -27,10 +29,10 @@ export function applyPopupModalStyles(window: BrowserWindow, position?: [number,
}
}
function positionWindow(window: BrowserWindow, position?: [number, number]) {
function positionWindow(window: BrowserWindow, position?: Position) {
if (position) {
const centeredX = position[0] - popupWidth / 2;
const centeredY = position[1] - popupHeight / 2;
const centeredX = position.x - popupWidth / 2;
const centeredY = position.y - popupHeight / 2;
window.setPosition(centeredX, centeredY);
} else {
window.center();

View File

@@ -291,7 +291,7 @@ export class DesktopSettingsService {
* Sets the modal mode of the application. Setting this changes the windows-size and other properties.
* @param value `true` if the application is in modal mode, `false` if it is not.
*/
async setModalMode(value: boolean, modalPosition?: [number, number]) {
async setModalMode(value: boolean, modalPosition?: { x: number; y: number }) {
await this.modalModeState.update(() => ({
isModalModeActive: value,
modalPosition,