From 82e88eb1ba1f3a3ae353f907206f708cf17e3d99 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 11 Jan 2018 15:30:58 -0500 Subject: [PATCH] move "in UI" methods to popup utils --- .../accountsLoginTwoFactorController.js | 4 +-- .../components/action-buttons.component.ts | 7 ++-- src/popup/app/components/pop-out.component.ts | 4 ++- src/popup/app/current/current.component.ts | 6 ++-- src/popup/app/services/popupUtils.service.ts | 33 +++++++++++++++++++ src/services/browserPlatformUtils.service.ts | 17 ---------- 6 files changed, 45 insertions(+), 26 deletions(-) diff --git a/src/popup/app/accounts/accountsLoginTwoFactorController.js b/src/popup/app/accounts/accountsLoginTwoFactorController.js index dd7a5dcfe2..c644ad8de9 100644 --- a/src/popup/app/accounts/accountsLoginTwoFactorController.js +++ b/src/popup/app/accounts/accountsLoginTwoFactorController.js @@ -184,8 +184,8 @@ angular $scope.twoFactorEmail = params.Email; if (chrome.extension.getViews({ type: 'popup' }).length > 0 && - !platformUtilsService.inSidebar($window) && !platformUtilsService.inTab($window) && - !platformUtilsService.inPopout($window)) { + !popupUtilsService.inSidebar($window) && !popupUtilsService.inTab($window) && + !popupUtilsService.inPopout($window)) { SweetAlert.swal({ title: i18nService.twoStepLogin, text: i18nService.popup2faCloseMessage, diff --git a/src/popup/app/components/action-buttons.component.ts b/src/popup/app/components/action-buttons.component.ts index 2e0ba01c7f..0295ae9d66 100644 --- a/src/popup/app/components/action-buttons.component.ts +++ b/src/popup/app/components/action-buttons.component.ts @@ -2,7 +2,7 @@ import * as template from './action-buttons.component.html'; import { ConstantsService } from 'jslib/services/constants.service'; -import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; +import PopupUtilsService from '../services/popupUtils.service'; export class ActionButtonsController implements ng.IController { onView: Function; @@ -13,8 +13,7 @@ export class ActionButtonsController implements ng.IController { constants: ConstantsService; constructor(private i18nService: any, private $analytics: any, private constantsService: ConstantsService, - private toastr: any, private $timeout: ng.ITimeoutService, private $window: ng.IWindowService, - private platformUtilsService: PlatformUtilsService) { + private toastr: any, private $timeout: ng.ITimeoutService, private $window: ng.IWindowService) { this.i18n = i18nService; this.constants = constantsService; } @@ -25,7 +24,7 @@ export class ActionButtonsController implements ng.IController { if (self.cipher.login.uri.startsWith('http://') || self.cipher.login.uri.startsWith('https://')) { self.$analytics.eventTrack('Launched Website From Listing'); chrome.tabs.create({ url: self.cipher.login.uri }); - if (self.platformUtilsService.inPopup(self.$window)) { + if (PopupUtilsService.inPopup(self.$window)) { self.$window.close(); } } diff --git a/src/popup/app/components/pop-out.component.ts b/src/popup/app/components/pop-out.component.ts index a5c388ae58..657d843acc 100644 --- a/src/popup/app/components/pop-out.component.ts +++ b/src/popup/app/components/pop-out.component.ts @@ -2,6 +2,8 @@ import * as template from './pop-out.component.html'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; +import PopupUtilsService from '../services/popupUtils.service'; + export class PopOutController implements ng.IController { i18n: any; @@ -39,7 +41,7 @@ export class PopOutController implements ng.IController { height: bodyRect.height, }); - if (this.platformUtilsService.inPopup(this.$window)) { + if (PopupUtilsService.inPopup(this.$window)) { this.$window.close(); } } else if (chrome && chrome.tabs && chrome.tabs.create) { diff --git a/src/popup/app/current/current.component.ts b/src/popup/app/current/current.component.ts index b4e402813b..566a4176e5 100644 --- a/src/popup/app/current/current.component.ts +++ b/src/popup/app/current/current.component.ts @@ -8,6 +8,8 @@ import { UtilsService } from 'jslib/abstractions/utils.service'; import { AutofillService } from '../../../services/abstractions/autofill.service'; +import PopupUtilsService from '../services/popupUtils.service'; + export class CurrentController { i18n: any; pageDetails: any = []; @@ -27,7 +29,7 @@ export class CurrentController { private $state: any, private $timeout: ng.ITimeoutService, private autofillService: AutofillService, private $analytics: any, private i18nService: any, private $filter: ng.IFilterService) { this.i18n = i18nService; - this.inSidebar = platformUtilsService.inSidebar($window); + this.inSidebar = PopupUtilsService.inSidebar($window); this.disableSearch = platformUtilsService.isEdge(); $scope.$on('syncCompleted', (event: any, successfully: boolean) => { @@ -85,7 +87,7 @@ export class CurrentController { if (totpCode && this.platformUtilsService.isFirefox()) { this.utilsService.copyToClipboard(totpCode, document); } - if (this.platformUtilsService.inPopup(this.$window)) { + if (PopupUtilsService.inPopup(this.$window)) { this.$window.close(); } }).catch(() => { diff --git a/src/popup/app/services/popupUtils.service.ts b/src/popup/app/services/popupUtils.service.ts index dc6175d752..a3a7aa4723 100644 --- a/src/popup/app/services/popupUtils.service.ts +++ b/src/popup/app/services/popupUtils.service.ts @@ -81,7 +81,40 @@ export default class PopupUtilsService { }); } + static inSidebar(theWindow: Window): boolean { + return theWindow.location.search !== '' && theWindow.location.search.indexOf('uilocation=sidebar') > -1; + } + + static inTab(theWindow: Window): boolean { + return theWindow.location.search !== '' && theWindow.location.search.indexOf('uilocation=tab') > -1; + } + + static inPopout(theWindow: Window): boolean { + return theWindow.location.search !== '' && theWindow.location.search.indexOf('uilocation=popout') > -1; + } + + static inPopup(theWindow: Window): boolean { + return theWindow.location.search === '' || theWindow.location.search.indexOf('uilocation=') === -1 || + theWindow.location.search.indexOf('uilocation=popup') > -1; + } + initListSectionItemListeners(doc: Document, angular: any): void { PopupUtilsService.initListSectionItemListeners(doc, angular); } + + inSidebar(theWindow: Window): boolean { + return PopupUtilsService.inSidebar(theWindow); + } + + inTab(theWindow: Window): boolean { + return PopupUtilsService.inTab(theWindow); + } + + inPopout(theWindow: Window): boolean { + return PopupUtilsService.inPopout(theWindow); + } + + inPopup(theWindow: Window): boolean { + return PopupUtilsService.inPopup(theWindow); + } } diff --git a/src/services/browserPlatformUtils.service.ts b/src/services/browserPlatformUtils.service.ts index 8bdf75ee1b..b58e5b81e3 100644 --- a/src/services/browserPlatformUtils.service.ts +++ b/src/services/browserPlatformUtils.service.ts @@ -116,23 +116,6 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService return BrowserPlatformUtilsService.getDomain(uriString); } - inSidebar(theWindow: Window): boolean { - return theWindow.location.search !== '' && theWindow.location.search.indexOf('uilocation=sidebar') > -1; - } - - inTab(theWindow: Window): boolean { - return theWindow.location.search !== '' && theWindow.location.search.indexOf('uilocation=tab') > -1; - } - - inPopout(theWindow: Window): boolean { - return theWindow.location.search !== '' && theWindow.location.search.indexOf('uilocation=popout') > -1; - } - - inPopup(theWindow: Window): boolean { - return theWindow.location.search === '' || theWindow.location.search.indexOf('uilocation=') === -1 || - theWindow.location.search.indexOf('uilocation=popup') > -1; - } - isViewOpen(): boolean { const popupOpen = chrome.extension.getViews({ type: 'popup' }).length > 0; if (popupOpen) {