1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-18 02:41:15 +02:00

from async for safari bug

This commit is contained in:
Kyle Spearrin 2018-04-23 11:40:23 -04:00
parent b40e51a7d1
commit 613dfaafd0

View File

@ -126,7 +126,7 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
this.router.navigate(['/view-cipher'], { queryParams: { cipherId: cipher.id } }); this.router.navigate(['/view-cipher'], { queryParams: { cipherId: cipher.id } });
} }
async fillCipher(cipher: CipherView) { fillCipher(cipher: CipherView) {
this.totpCode = null; this.totpCode = null;
if (this.totpTimeout != null) { if (this.totpTimeout != null) {
window.clearTimeout(this.totpTimeout); window.clearTimeout(this.totpTimeout);
@ -138,28 +138,27 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
return; return;
} }
try { this.autofillService.doAutoFill({
this.totpCode = await this.autofillService.doAutoFill({ cipher: cipher,
cipher: cipher, pageDetails: this.pageDetails,
pageDetails: this.pageDetails, doc: window.document,
doc: window.document, }).then((totpCode) => {
}); this.totpCode = totpCode;
this.analytics.eventTrack.next({ action: 'Autofilled' }); this.analytics.eventTrack.next({ action: 'Autofilled' });
if (this.totpCode != null && !this.platformUtilsService.isSafari()) { if (totpCode != null && !this.platformUtilsService.isSafari()) {
this.platformUtilsService.copyToClipboard(this.totpCode, { doc: window.document }); this.platformUtilsService.copyToClipboard(totpCode, { doc: window.document });
} }
if (this.popupUtilsService.inPopup(window)) { if (this.popupUtilsService.inPopup(window)) {
BrowserApi.closePopup(window); BrowserApi.closePopup(window);
} }
} catch { }).catch(() => {
this.analytics.eventTrack.next({ action: 'Autofilled Error' }); this.analytics.eventTrack.next({ action: 'Autofilled Error' });
this.toasterService.popAsync('error', null, this.i18nService.t('autofillError')); this.toasterService.popAsync('error', null, this.i18nService.t('autofillError'));
} });
// Weird bug in Safari won't allow clipboard copying after promise call, so we have this workaround // Weird bug in Safari won't allow clipboard copying after a promise call, so we have this workaround
if (this.platformUtilsService.isSafari()) { if (cipher.type === CipherType.Login && this.platformUtilsService.isSafari()) {
this.totpTimeout = window.setTimeout(() => { this.totpTimeout = window.setTimeout(() => {
if (this.totpCode != null) { if (this.totpCode != null) {
this.platformUtilsService.copyToClipboard(this.totpCode, { doc: window.document }); this.platformUtilsService.copyToClipboard(this.totpCode, { doc: window.document });