From 48d1743ab52b8e3906cf31faaf81359e0b4eb092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20=C3=85berg?= Date: Thu, 20 Feb 2025 00:32:50 +0100 Subject: [PATCH] Rename inModalMode to modalMode --- .../components/fido2placeholder.component.ts | 6 +++--- .../desktop-fido2-user-interface.service.ts | 6 +++--- apps/desktop/src/main.ts | 2 +- apps/desktop/src/main/window.main.ts | 12 ++++++------ .../src/platform/models/domain/window-state.ts | 4 ++-- .../services/desktop-settings.service.ts | 17 ++++++++++------- 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/apps/desktop/src/app/components/fido2placeholder.component.ts b/apps/desktop/src/app/components/fido2placeholder.component.ts index 84558ac27dc..96d52c011d4 100644 --- a/apps/desktop/src/app/components/fido2placeholder.component.ts +++ b/apps/desktop/src/app/components/fido2placeholder.component.ts @@ -73,7 +73,7 @@ export class Fido2PlaceholderComponent implements OnInit, OnDestroy { this.session?.confirmChosenCipher(cipherId); await this.router.navigate(["/"]); - await this.desktopSettingsService.setInModalMode(false); + await this.desktopSettingsService.setModalMode(false); } ngOnDestroy() { @@ -103,7 +103,7 @@ export class Fido2PlaceholderComponent implements OnInit, OnDestroy { // The session currently toggles modal on and send us here // But if this route is somehow opened outside of session we want to make sure we clean up? await this.router.navigate(["/"]); - await this.desktopSettingsService.setInModalMode(false); + await this.desktopSettingsService.setModalMode(false); } catch (error) { // TODO: Handle error appropriately } @@ -111,7 +111,7 @@ export class Fido2PlaceholderComponent implements OnInit, OnDestroy { async closeModal() { await this.router.navigate(["/"]); - await this.desktopSettingsService.setInModalMode(false); + await this.desktopSettingsService.setModalMode(false); this.session.notifyConfirmNewCredential(false); // little bit hacky: 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 5fbd667b3e9..e08a288e044 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 @@ -150,7 +150,7 @@ export class DesktopFido2UserInterfaceSession implements Fido2UserInterfaceSessi return { cipherId: resultCipherId, userVerified: true }; } finally { // Make sure to clean up so the app is never stuck in modal mode? - await this.desktopSettingsService.setInModalMode(false); + await this.desktopSettingsService.setModalMode(false); } } @@ -225,14 +225,14 @@ export class DesktopFido2UserInterfaceSession implements Fido2UserInterfaceSessi return { cipherId: this.createdCipher.id, userVerified: userVerification }; } finally { // Make sure to clean up so the app is never stuck in modal mode? - await this.desktopSettingsService.setInModalMode(false); + await this.desktopSettingsService.setModalMode(false); } } private async showUi(route: string, position?: [number, number]): Promise { // Load the UI: // maybe toggling to modal mode shouldn't be done here? - await this.desktopSettingsService.setInModalMode(true, position); + await this.desktopSettingsService.setModalMode(true, position); await this.router.navigate(["/passkeys"]); } diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts index c1f08927073..1ff9fe1675c 100644 --- a/apps/desktop/src/main.ts +++ b/apps/desktop/src/main.ts @@ -279,7 +279,7 @@ export class Main { async () => { await this.toggleHardwareAcceleration(); // Reset modal mode to make sure main window is displayed correctly - await this.desktopSettingsService.resetInModalMode(); + await this.desktopSettingsService.resetModalMode(); await this.windowMain.init(); await this.i18nService.init(); await this.messagingMain.init(); diff --git a/apps/desktop/src/main/window.main.ts b/apps/desktop/src/main/window.main.ts index b5e02f64557..1a1151e62a3 100644 --- a/apps/desktop/src/main/window.main.ts +++ b/apps/desktop/src/main/window.main.ts @@ -77,16 +77,16 @@ export class WindowMain { } }); - this.desktopSettingsService.inModalMode$ + this.desktopSettingsService.modalMode$ .pipe( pairwise(), concatMap(async ([lastValue, newValue]) => { - if (lastValue.modalMode && !newValue.modalMode) { + if (lastValue.isModalModeActive && !newValue.isModalModeActive) { // Reset the window state to the main window state applyMainWindowStyles(this.win, this.windowStates[mainWindowSizeKey]); // Because modal is used in front of another app, UX wise it makes sense to hide the main window when leaving modal mode. this.win.hide(); - } else if (!lastValue.modalMode && newValue.modalMode) { + } else if (!lastValue.isModalModeActive && newValue.isModalModeActive) { // Apply the popup modal styles this.logService.info("Applying popup modal styles", newValue.modalPosition); applyPopupModalStyles(this.win, newValue.modalPosition); @@ -209,7 +209,7 @@ export class WindowMain { return; } - await this.desktopSettingsService.setInModalMode(modal); + await this.desktopSettingsService.setModalMode(modal); await this.win.loadURL( url.format({ protocol: "file:", @@ -405,9 +405,9 @@ export class WindowMain { return; } - const inModalMode = await firstValueFrom(this.desktopSettingsService.inModalMode$); + const modalMode = await firstValueFrom(this.desktopSettingsService.modalMode$); - if (inModalMode) { + if (modalMode.isModalModeActive) { return; } diff --git a/apps/desktop/src/platform/models/domain/window-state.ts b/apps/desktop/src/platform/models/domain/window-state.ts index f0292abfff4..8aead4477f6 100644 --- a/apps/desktop/src/platform/models/domain/window-state.ts +++ b/apps/desktop/src/platform/models/domain/window-state.ts @@ -13,6 +13,6 @@ export class WindowState { } export class ModalModeState { - modalMode: boolean; - modalPosition?: [number, number]; + isModalModeActive: boolean; + modalPosition?: [number, number]; // Modal position is often passed from the native UI } diff --git a/apps/desktop/src/platform/services/desktop-settings.service.ts b/apps/desktop/src/platform/services/desktop-settings.service.ts index 422a6f0913e..d52405e697c 100644 --- a/apps/desktop/src/platform/services/desktop-settings.service.ts +++ b/apps/desktop/src/platform/services/desktop-settings.service.ts @@ -75,7 +75,7 @@ const MINIMIZE_ON_COPY = new UserKeyDefinition(DESKTOP_SETTINGS_DISK, " clearOn: [], // User setting, no need to clear }); -const IN_MODAL_MODE = new KeyDefinition(DESKTOP_SETTINGS_DISK, "inModalMode", { +const MODAL_MODE = new KeyDefinition(DESKTOP_SETTINGS_DISK, "modalMode", { deserializer: (b) => b, }); @@ -159,9 +159,9 @@ export class DesktopSettingsService { */ minimizeOnCopy$ = this.minimizeOnCopyState.state$.pipe(map(Boolean)); - private readonly inModalModeState = this.stateProvider.getGlobal(IN_MODAL_MODE); + private readonly modalModeState = this.stateProvider.getGlobal(MODAL_MODE); - inModalMode$ = this.inModalModeState.state$; + modalMode$ = this.modalModeState.state$; constructor(private stateProvider: StateProvider) { this.window$ = this.windowState.state$.pipe( @@ -175,8 +175,8 @@ export class DesktopSettingsService { * This is used to clear the setting on application start to make sure we don't end up * stuck in modal mode if the application is force-closed in modal mode. */ - async resetInModalMode() { - await this.inModalModeState.update(() => ({ modalMode: false })); + async resetModalMode() { + await this.modalModeState.update(() => ({ isModalModeActive: false })); } async setHardwareAcceleration(enabled: boolean) { @@ -291,7 +291,10 @@ 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 setInModalMode(value: boolean, windowXy?: [number, number]) { - await this.inModalModeState.update(() => ({ modalMode: value, modalPosition: windowXy })); + async setModalMode(value: boolean, modalPosition?: [number, number]) { + await this.modalModeState.update(() => ({ + isModalModeActive: value, + modalPosition: modalPosition, + })); } }