From 4fc21767bea63ed686c1dbc9301d3f5342ff7475 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 12 Jan 2018 16:42:47 -0500 Subject: [PATCH] browser api for closing popup --- src/browser/browserApi.ts | 8 ++++++++ src/popup/app/components/action-buttons.component.ts | 2 +- src/popup/app/components/pop-out.component.ts | 2 +- src/popup/app/current/current.component.ts | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/browser/browserApi.ts b/src/browser/browserApi.ts index 26d3226c6d..4a079225e8 100644 --- a/src/browser/browserApi.ts +++ b/src/browser/browserApi.ts @@ -170,6 +170,14 @@ class BrowserApi { } } + static closePopup(win: Window) { + if (BrowserApi.isChromeApi) { + win.close(); + } else if (BrowserApi.isSafariApi && safari.extension.popovers && safari.extension.popovers.length > 0) { + safari.extension.popovers[0].hide(); + } + } + private static makeTabObject(tab: any) { if (BrowserApi.isChromeApi) { return tab; diff --git a/src/popup/app/components/action-buttons.component.ts b/src/popup/app/components/action-buttons.component.ts index 6d22473262..5ebc6480d0 100644 --- a/src/popup/app/components/action-buttons.component.ts +++ b/src/popup/app/components/action-buttons.component.ts @@ -27,7 +27,7 @@ export class ActionButtonsController implements ng.IController { self.$analytics.eventTrack('Launched Website From Listing'); BrowserApi.createNewTab(self.cipher.login.uri); if (PopupUtilsService.inPopup(self.$window)) { - self.$window.close(); + BrowserApi.closePopup(self.$window); } } }); diff --git a/src/popup/app/components/pop-out.component.ts b/src/popup/app/components/pop-out.component.ts index 25f8829098..46ffec4b2e 100644 --- a/src/popup/app/components/pop-out.component.ts +++ b/src/popup/app/components/pop-out.component.ts @@ -42,7 +42,7 @@ export class PopOutController implements ng.IController { }); if (PopupUtilsService.inPopup(this.$window)) { - this.$window.close(); + BrowserApi.closePopup(this.$window); } } else if ((typeof chrome !== 'undefined') && chrome.tabs && chrome.tabs.create) { href = href.replace('uilocation=popup', 'uilocation=tab') diff --git a/src/popup/app/current/current.component.ts b/src/popup/app/current/current.component.ts index b991f6cd44..16a0f03e93 100644 --- a/src/popup/app/current/current.component.ts +++ b/src/popup/app/current/current.component.ts @@ -90,7 +90,7 @@ export class CurrentController { this.utilsService.copyToClipboard(totpCode, document); } if (PopupUtilsService.inPopup(this.$window)) { - this.$window.close(); + BrowserApi.closePopup(this.$window); } }).catch(() => { this.$analytics.eventTrack('Autofilled Error');