diff --git a/apps/desktop/src/app/services/services.module.ts b/apps/desktop/src/app/services/services.module.ts index 0f541907995..e5b0b96a3e3 100644 --- a/apps/desktop/src/app/services/services.module.ts +++ b/apps/desktop/src/app/services/services.module.ts @@ -325,7 +325,13 @@ const safeProviders: SafeProvider[] = [ safeProvider({ provide: Fido2UserInterfaceServiceAbstraction, useClass: DesktopFido2UserInterfaceService, - deps: [AuthServiceAbstraction, CipherServiceAbstraction, AccountService, LogService], + deps: [ + AuthServiceAbstraction, + CipherServiceAbstraction, + AccountService, + LogService, + MessagingServiceAbstraction, + ], }), safeProvider({ provide: Fido2AuthenticatorServiceAbstraction, 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 684b19e7394..c78adc96537 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 @@ -10,6 +10,7 @@ import { PickCredentialParams, } from "@bitwarden/common/platform/abstractions/fido2/fido2-user-interface.service.abstraction"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; +import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; import { CipherRepromptType, CipherType, SecureNoteType } from "@bitwarden/common/vault/enums"; import { CardView } from "@bitwarden/common/vault/models/view/card.view"; @@ -27,6 +28,7 @@ export class DesktopFido2UserInterfaceService private cipherService: CipherService, private accountService: AccountService, private logService: LogService, + private messagingService: MessagingService, ) {} async newSession( @@ -40,6 +42,7 @@ export class DesktopFido2UserInterfaceService this.cipherService, this.accountService, this.logService, + this.messagingService, ); } } @@ -50,6 +53,7 @@ export class DesktopFido2UserInterfaceSession implements Fido2UserInterfaceSessi private cipherService: CipherService, private accountService: AccountService, private logService: LogService, + private messagingService: MessagingService, ) {} async pickCredential({ @@ -75,6 +79,8 @@ export class DesktopFido2UserInterfaceSession implements Fido2UserInterfaceSessi rpId, ); + await this.messagingService.send("loadurl", { url: "/passkeys", modal: true }); + // Store the passkey on a new cipher to avoid replacing something important const cipher = new CipherView(); cipher.name = credentialName; diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts index c4ae8e1c103..c1f08927073 100644 --- a/apps/desktop/src/main.ts +++ b/apps/desktop/src/main.ts @@ -187,7 +187,6 @@ export class Main { ); this.messagingMain = new MessagingMain(this, this.desktopSettingsService); this.updaterMain = new UpdaterMain(this.i18nService, this.windowMain); - this.trayMain = new TrayMain(this.windowMain, this.i18nService, this.desktopSettingsService); const messageSubject = new Subject>>(); this.messagingService = MessageSender.combine( @@ -195,6 +194,13 @@ export class Main { new ElectronMainMessagingService(this.windowMain), ); + this.trayMain = new TrayMain( + this.windowMain, + this.i18nService, + this.desktopSettingsService, + this.messagingService, + ); + messageSubject.asObservable().subscribe((message) => { void this.messagingMain.onMessage(message).catch((err) => { this.logService.error( diff --git a/apps/desktop/src/main/messaging.main.ts b/apps/desktop/src/main/messaging.main.ts index 0d86a7234e6..075f04cf91f 100644 --- a/apps/desktop/src/main/messaging.main.ts +++ b/apps/desktop/src/main/messaging.main.ts @@ -37,6 +37,9 @@ export class MessagingMain { async onMessage(message: any) { switch (message.command) { + case "loadurl": + await this.main.windowMain.loadUrl(message.url, message.modal); + break; case "scheduleNextSync": this.scheduleNextSync(); break; diff --git a/apps/desktop/src/main/tray.main.ts b/apps/desktop/src/main/tray.main.ts index 48ce292d238..f9000680907 100644 --- a/apps/desktop/src/main/tray.main.ts +++ b/apps/desktop/src/main/tray.main.ts @@ -1,15 +1,15 @@ // FIXME: Update this file to be type safe and remove this and next line // @ts-strict-ignore import * as path from "path"; -import * as url from "url"; import { app, BrowserWindow, Menu, MenuItemConstructorOptions, nativeImage, Tray } from "electron"; import { firstValueFrom } from "rxjs"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; +import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; import { DesktopSettingsService } from "../platform/services/desktop-settings.service"; -import { cleanUserAgent, isDev } from "../utils"; +import { isDev } from "../utils"; import { WindowMain } from "./window.main"; @@ -25,6 +25,7 @@ export class TrayMain { private windowMain: WindowMain, private i18nService: I18nService, private desktopSettingsService: DesktopSettingsService, + private messagingService: MessagingService, ) { if (process.platform === "win32") { this.icon = path.join(__dirname, "/images/icon.ico"); @@ -209,32 +210,6 @@ export class TrayMain { * @returns */ private async fakePopup() { - if (this.windowMain.win == null || this.windowMain.win.isDestroyed()) { - await this.windowMain.createWindow("modal-app"); - return; - } - - // Restyle existing - const existingWin = this.windowMain.win; - - await this.desktopSettingsService.setInModalMode(true); - await existingWin.loadURL( - url.format({ - protocol: "file:", - //pathname: `${__dirname}/index.html`, - pathname: path.join(__dirname, "/index.html"), - slashes: true, - hash: "/passkeys", - query: { - redirectUrl: "/passkeys", - }, - }), - { - userAgent: cleanUserAgent(existingWin.webContents.userAgent), - }, - ); - existingWin.once("ready-to-show", () => { - existingWin.show(); - }); + await this.messagingService.send("loadurl", { url: "/passkeys", modal: true }); } } diff --git a/apps/desktop/src/main/window.main.ts b/apps/desktop/src/main/window.main.ts index f9b06890977..5420959e287 100644 --- a/apps/desktop/src/main/window.main.ts +++ b/apps/desktop/src/main/window.main.ts @@ -202,6 +202,33 @@ export class WindowMain { } } + async loadUrl(targetPath: string, modal: boolean = false) { + if (this.win == null || this.win.isDestroyed()) { + await this.createWindow("modal-app"); + return; + } + + await this.desktopSettingsService.setInModalMode(modal); + await this.win.loadURL( + url.format({ + protocol: "file:", + //pathname: `${__dirname}/index.html`, + pathname: path.join(__dirname, "/index.html"), + slashes: true, + hash: targetPath, + query: { + redirectUrl: targetPath, + }, + }), + { + userAgent: cleanUserAgent(this.win.webContents.userAgent), + }, + ); + this.win.once("ready-to-show", () => { + this.win.show(); + }); + } + /** * Creates the main window. The template argument is used to determine the styling of the window and what url will be loaded. * When the template is "modal-app", the window will be styled as a modal and the passkeys page will be loaded.