From c02f81eb5a146caa772667e20bb72c71b8903a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20=C3=85berg?= Date: Fri, 28 Feb 2025 10:11:16 +0100 Subject: [PATCH] Change windowXy to a Record instead of [number,number] --- .../desktop_native/macos_provider/src/assertion.rs | 6 +++--- .../desktop_native/macos_provider/src/lib.rs | 7 +++++++ .../macos_provider/src/registration.rs | 4 ++-- apps/desktop/desktop_native/napi/index.d.ts | 10 +++++++--- apps/desktop/desktop_native/napi/src/lib.rs | 14 +++++++++++--- .../CredentialProviderViewController.swift | 5 ++--- .../autofill/services/desktop-autofill.service.ts | 6 +++--- .../desktop-fido2-user-interface.service.ts | 4 ++-- .../src/platform/models/domain/window-state.ts | 2 +- apps/desktop/src/platform/popup-modal-styles.ts | 10 ++++++---- .../platform/services/desktop-settings.service.ts | 2 +- 11 files changed, 45 insertions(+), 25 deletions(-) diff --git a/apps/desktop/desktop_native/macos_provider/src/assertion.rs b/apps/desktop/desktop_native/macos_provider/src/assertion.rs index a530bb26a22..c5b43bb87fa 100644 --- a/apps/desktop/desktop_native/macos_provider/src/assertion.rs +++ b/apps/desktop/desktop_native/macos_provider/src/assertion.rs @@ -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, user_verification: UserVerification, allowed_credentials: Vec>, - window_xy: Vec, + window_xy: Position, //extension_input: Vec, TODO: Implement support for extensions } @@ -25,7 +25,7 @@ pub struct PasskeyAssertionWithoutUserInterfaceRequest { record_identifier: Option, client_data_hash: Vec, user_verification: UserVerification, - window_xy: Vec, + window_xy: Position, } #[derive(uniffi::Record, Serialize, Deserialize)] diff --git a/apps/desktop/desktop_native/macos_provider/src/lib.rs b/apps/desktop/desktop_native/macos_provider/src/lib.rs index d59a88b8ab6..8f2499ae68d 100644 --- a/apps/desktop/desktop_native/macos_provider/src/lib.rs +++ b/apps/desktop/desktop_native/macos_provider/src/lib.rs @@ -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), diff --git a/apps/desktop/desktop_native/macos_provider/src/registration.rs b/apps/desktop/desktop_native/macos_provider/src/registration.rs index 89260c2defc..9e697b75c16 100644 --- a/apps/desktop/desktop_native/macos_provider/src/registration.rs +++ b/apps/desktop/desktop_native/macos_provider/src/registration.rs @@ -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, user_verification: UserVerification, supported_algorithms: Vec, - window_xy: Vec, + window_xy: Position, } #[derive(uniffi::Record, Serialize, Deserialize)] diff --git a/apps/desktop/desktop_native/napi/index.d.ts b/apps/desktop/desktop_native/napi/index.d.ts index 1bf64596700..a79f6937aa2 100644 --- a/apps/desktop/desktop_native/napi/index.d.ts +++ b/apps/desktop/desktop_native/napi/index.d.ts @@ -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 userVerification: UserVerification supportedAlgorithms: Array - windowXy: Array + windowXy: Position } export interface PasskeyRegistrationResponse { rpId: string @@ -149,7 +153,7 @@ export declare namespace autofill { clientDataHash: Array userVerification: UserVerification allowedCredentials: Array> - windowXy: Array + windowXy: Position } export interface PasskeyAssertionWithoutUserInterfaceRequest { rpId: string @@ -159,7 +163,7 @@ export declare namespace autofill { recordIdentifier?: string clientDataHash: Array userVerification: UserVerification - windowXy: Array + windowXy: Position } export interface PasskeyAssertionResponse { rpId: string diff --git a/apps/desktop/desktop_native/napi/src/lib.rs b/apps/desktop/desktop_native/napi/src/lib.rs index 7edea7308af..8e29916d64f 100644 --- a/apps/desktop/desktop_native/napi/src/lib.rs +++ b/apps/desktop/desktop_native/napi/src/lib.rs @@ -582,6 +582,14 @@ pub mod autofill { pub value: Result, } + #[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, pub user_verification: UserVerification, pub supported_algorithms: Vec, - pub window_xy: Vec, + pub window_xy: Position, } #[napi(object)] @@ -613,7 +621,7 @@ pub mod autofill { pub client_data_hash: Vec, pub user_verification: UserVerification, pub allowed_credentials: Vec>, - pub window_xy: Vec, + pub window_xy: Position, //extension_input: Vec, TODO: Implement support for extensions } @@ -628,7 +636,7 @@ pub mod autofill { pub record_identifier: Option, pub client_data_hash: Vec, pub user_verification: UserVerification, - pub window_xy: Vec, + pub window_xy: Position, } #[napi(object)] diff --git a/apps/desktop/macos/autofill-extension/CredentialProviderViewController.swift b/apps/desktop/macos/autofill-extension/CredentialProviderViewController.swift index 8cb07bee292..2f952a29217 100644 --- a/apps/desktop/macos/autofill-extension/CredentialProviderViewController.swift +++ b/apps/desktop/macos/autofill-extension/CredentialProviderViewController.swift @@ -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") diff --git a/apps/desktop/src/autofill/services/desktop-autofill.service.ts b/apps/desktop/src/autofill/services/desktop-autofill.service.ts index faabc71b19f..577550dc3fd 100644 --- a/apps/desktop/src/autofill/services/desktop-autofill.service.ts +++ b/apps/desktop/src/autofill/services/desktop-autofill.service.ts @@ -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) => { diff --git a/apps/desktop/src/autofill/services/desktop-fido2-user-interface.service.ts b/apps/desktop/src/autofill/services/desktop-fido2-user-interface.service.ts index 0cba3459cd3..98cdde02775 100644 --- a/apps/desktop/src/autofill/services/desktop-fido2-user-interface.service.ts +++ b/apps/desktop/src/autofill/services/desktop-fido2-user-interface.service.ts @@ -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 { + private async showUi(route: string, position?: { x: number; y: number }): Promise { // Load the UI: // maybe toggling to modal mode shouldn't be done here? await this.desktopSettingsService.setModalMode(true, position); diff --git a/apps/desktop/src/platform/models/domain/window-state.ts b/apps/desktop/src/platform/models/domain/window-state.ts index 8aead4477f6..0efc9a1efab 100644 --- a/apps/desktop/src/platform/models/domain/window-state.ts +++ b/apps/desktop/src/platform/models/domain/window-state.ts @@ -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 } diff --git a/apps/desktop/src/platform/popup-modal-styles.ts b/apps/desktop/src/platform/popup-modal-styles.ts index f71bd35c82b..ae46ebb5c76 100644 --- a/apps/desktop/src/platform/popup-modal-styles.ts +++ b/apps/desktop/src/platform/popup-modal-styles.ts @@ -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(); diff --git a/apps/desktop/src/platform/services/desktop-settings.service.ts b/apps/desktop/src/platform/services/desktop-settings.service.ts index 5edd69f0143..2a06c910f3d 100644 --- a/apps/desktop/src/platform/services/desktop-settings.service.ts +++ b/apps/desktop/src/platform/services/desktop-settings.service.ts @@ -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,