From 9d8e19622febfd2312ef1cbdb46449b9afa3fd48 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Sun, 31 Oct 2021 16:18:49 +0100 Subject: [PATCH] avoid multiple parallel passphrase prompts - fixes #4811 --- tabby-core/src/services/vault.service.ts | 6 ++++-- tabby-core/src/utils.ts | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tabby-core/src/services/vault.service.ts b/tabby-core/src/services/vault.service.ts index b7439e51..1e50cc74 100644 --- a/tabby-core/src/services/vault.service.ts +++ b/tabby-core/src/services/vault.service.ts @@ -3,7 +3,7 @@ import { promisify } from 'util' import { Injectable, NgZone } from '@angular/core' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' import { AsyncSubject, Subject, Observable } from 'rxjs' -import { wrapPromise } from '../utils' +import { wrapPromise, serializeFunction } from '../utils' import { UnlockVaultModalComponent } from '../components/unlockVaultModal.component' import { NotificationsService } from './notifications.service' import { SelectorService } from './selector.service' @@ -114,7 +114,9 @@ export class VaultService { private zone: NgZone, private notifications: NotificationsService, private ngbModal: NgbModal, - ) { } + ) { + this.getPassphrase = serializeFunction(this.getPassphrase.bind(this)) + } async setEnabled (enabled: boolean, passphrase?: string): Promise { if (enabled) { diff --git a/tabby-core/src/utils.ts b/tabby-core/src/utils.ts index 59821565..4e7ce896 100644 --- a/tabby-core/src/utils.ts +++ b/tabby-core/src/utils.ts @@ -64,3 +64,12 @@ export const TAB_COLORS = [ { name: 'Red', value: '#d9534f' }, { name: 'Yellow', value: '#ffd500' }, ] + +export function serializeFunction Promise> (fn: T): T { + let queue = Promise.resolve() + return (...args) => { + const res = queue.then(() => fn(...args)) + queue = res.catch(() => null) + return res + } +}