From 88cf1e9020373ac4767f46891d2fa130fa3aba6e Mon Sep 17 00:00:00 2001 From: Bernd Schoolmann Date: Sun, 6 Jul 2025 00:49:43 +0200 Subject: [PATCH] Auto hide after approving ssh --- .../autofill/services/ssh-agent.service.ts | 19 ++++++++++++++----- apps/desktop/src/main/window.main.ts | 6 ++++++ apps/desktop/src/platform/preload.ts | 1 + 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/apps/desktop/src/autofill/services/ssh-agent.service.ts b/apps/desktop/src/autofill/services/ssh-agent.service.ts index 3909e76689a..9886ccc7d25 100644 --- a/apps/desktop/src/autofill/services/ssh-agent.service.ts +++ b/apps/desktop/src/autofill/services/ssh-agent.service.ts @@ -98,7 +98,9 @@ export class SshAgentService implements OnDestroy { // switchMap is used here to prevent multiple requests from being processed at the same time, // and will cancel the previous request if a new one is received. switchMap(([message, status, account]) => { + let wasLocked = false; if (status !== AuthenticationStatus.Unlocked) { + wasLocked = true; ipc.platform.focusWindow(); this.toastService.showToast({ variant: "info", @@ -127,20 +129,20 @@ export class SshAgentService implements OnDestroy { throw error; }), - map(() => [message, account.id]), + map(() => [message, account.id, wasLocked]), ); } - return of([message, account.id]); + return of([message, account.id, wasLocked]); }), // This switchMap handles fetching the ciphers from the vault. - switchMap(([message, userId]: [Record, UserId]) => + switchMap(([message, userId, wasLocked]: [Record, UserId, boolean]) => from(this.cipherService.getAllDecrypted(userId)).pipe( - map((ciphers) => [message, ciphers] as const), + map((ciphers) => [message, ciphers, wasLocked] as const), ), ), // This concatMap handles showing the dialog to approve the request. - concatMap(async ([message, ciphers]) => { + concatMap(async ([message, ciphers, wasLocked]) => { const cipherId = message.cipherId as string; const isListRequest = message.isListRequest as boolean; const requestId = message.requestId as number; @@ -167,6 +169,9 @@ export class SshAgentService implements OnDestroy { }); await ipc.platform.sshAgent.setKeys(keys); await ipc.platform.sshAgent.signRequestResponse(requestId, true); + if (wasLocked) { + ipc.platform.minimizeWindow(); + } return; } @@ -178,6 +183,7 @@ export class SshAgentService implements OnDestroy { if (await this.needsAuthorization(cipherId, isAgentForwarding)) { ipc.platform.focusWindow(); + wasLocked = true; const cipher = ciphers.find((cipher) => cipher.id == cipherId); const dialogRef = ApproveSshRequestComponent.open( this.dialogService, @@ -186,6 +192,9 @@ export class SshAgentService implements OnDestroy { isAgentForwarding, namespace, ); + if (wasLocked) { + ipc.platform.minimizeWindow(); + } if (await firstValueFrom(dialogRef.closed)) { await this.rememberAuthorization(cipherId); diff --git a/apps/desktop/src/main/window.main.ts b/apps/desktop/src/main/window.main.ts index f1a55866079..ab339c2a13d 100644 --- a/apps/desktop/src/main/window.main.ts +++ b/apps/desktop/src/main/window.main.ts @@ -78,6 +78,12 @@ export class WindowMain { } }); + ipcMain.on("window-minimize", () => { + if (this.win != null) { + this.win.minimize(); + } + }); + this.desktopSettingsService.modalMode$ .pipe( pairwise(), diff --git a/apps/desktop/src/platform/preload.ts b/apps/desktop/src/platform/preload.ts index bf81021922f..cb748feaf96 100644 --- a/apps/desktop/src/platform/preload.ts +++ b/apps/desktop/src/platform/preload.ts @@ -146,6 +146,7 @@ export default { reloadProcess: () => ipcRenderer.send("reload-process"), focusWindow: () => ipcRenderer.send("window-focus"), hideWindow: () => ipcRenderer.send("window-hide"), + minimizeWindow: () => ipcRenderer.send("window-minimize"), log: (level: LogLevelType, message?: any, ...optionalParams: any[]) => ipcRenderer.invoke("ipc.log", { level, message, optionalParams }),