From e6d6275daa1408efa2083d57a10a64c82ffde554 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 19 Aug 2019 09:38:59 -0400 Subject: [PATCH] async fillCipher --- src/browser/browserApi.ts | 2 +- src/popup/vault/current-tab.component.ts | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/browser/browserApi.ts b/src/browser/browserApi.ts index fbd92bf8b9..31dab16fdd 100644 --- a/src/browser/browserApi.ts +++ b/src/browser/browserApi.ts @@ -229,7 +229,7 @@ export class BrowserApi { browser.tabs.update({ active: true }).finally(win.close); } else if (BrowserApi.isWebExtensionsApi || BrowserApi.isChromeApi) { win.close(); - } else if (BrowserApi.isSafariApi && safari.extension.popovers && safari.extension.popovers.length > 0) { + } else if (BrowserApi.isSafariApi) { SafariApp.sendMessageToApp('hideWindow'); } } diff --git a/src/popup/vault/current-tab.component.ts b/src/popup/vault/current-tab.component.ts index 81b753f719..ed576bdf89 100644 --- a/src/popup/vault/current-tab.component.ts +++ b/src/popup/vault/current-tab.component.ts @@ -130,7 +130,7 @@ export class CurrentTabComponent implements OnInit, OnDestroy { this.router.navigate(['/view-cipher'], { queryParams: { cipherId: cipher.id } }); } - fillCipher(cipher: CipherView) { + async fillCipher(cipher: CipherView) { this.totpCode = null; if (this.totpTimeout != null) { window.clearTimeout(this.totpTimeout); @@ -142,27 +142,26 @@ export class CurrentTabComponent implements OnInit, OnDestroy { return; } - this.autofillService.doAutoFill({ - cipher: cipher, - pageDetails: this.pageDetails, - doc: window.document, - }).then((totpCode) => { - this.totpCode = totpCode; + try { + this.totpCode = await this.autofillService.doAutoFill({ + cipher: cipher, + pageDetails: this.pageDetails, + doc: window.document, + }); this.analytics.eventTrack.next({ action: 'Autofilled' }); - if (totpCode != null && !this.platformUtilsService.isSafari()) { - this.platformUtilsService.copyToClipboard(totpCode, { window: window }); + if (this.totpCode != null && !this.platformUtilsService.isSafari()) { + this.platformUtilsService.copyToClipboard(this.totpCode, { window: window }); } - if (this.popupUtilsService.inPopup(window)) { BrowserApi.closePopup(window); } - }).catch(() => { + } catch { this.ngZone.run(() => { this.analytics.eventTrack.next({ action: 'Autofilled Error' }); this.toasterService.popAsync('error', null, this.i18nService.t('autofillError')); this.changeDetectorRef.detectChanges(); }); - }); + } // Weird bug in Safari won't allow clipboard copying after a promise call, so we have this workaround if (cipher.type === CipherType.Login && this.platformUtilsService.isSafari()) {