1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-29 17:38:04 +01:00

move "in UI" methods to popup utils

This commit is contained in:
Kyle Spearrin 2018-01-11 15:30:58 -05:00
parent 9921d6dba3
commit 82e88eb1ba
6 changed files with 45 additions and 26 deletions

View File

@ -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,

View File

@ -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();
}
}

View File

@ -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) {

View File

@ -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(() => {

View File

@ -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);
}
}

View File

@ -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) {