diff --git a/src/popup/app/app.js b/src/popup/app/app.js index a41b20d7285..4bb27571f64 100644 --- a/src/popup/app/app.js +++ b/src/popup/app/app.js @@ -26,6 +26,7 @@ import ToolsModule from './tools/tools.module'; import ServicesModule from './services/services.module'; import LockModule from './lock/lock.module'; import CurrentModule from './current/current.module'; +import GlobalModule from './global/global.module'; // Model imports import { Attachment } from '../../models/domain/attachment'; @@ -83,7 +84,7 @@ angular ComponentsModule, ServicesModule, - 'bit.global', + GlobalModule, 'bit.accounts', CurrentModule, 'bit.vault', @@ -93,11 +94,6 @@ angular ]); require('./config'); -require('./global/globalModule.js'); -require('./global/mainController.js'); -require('./global/tabsController.js'); -require('./global/baseController.js'); -require('./global/privateModeController.js'); require('./accounts/accountsModule.js'); require('./accounts/accountsLoginController.js'); require('./accounts/accountsLoginTwoFactorController.js'); diff --git a/src/popup/app/global/base.controller.ts b/src/popup/app/global/base.controller.ts new file mode 100644 index 00000000000..d762c6d9a58 --- /dev/null +++ b/src/popup/app/global/base.controller.ts @@ -0,0 +1,5 @@ +export class BaseController implements ng.IController { + constructor($scope: any, i18nService: any) { + $scope.i18n = i18nService; + } +} diff --git a/src/popup/app/global/baseController.js b/src/popup/app/global/baseController.js deleted file mode 100644 index 5eb980ad366..00000000000 --- a/src/popup/app/global/baseController.js +++ /dev/null @@ -1,6 +0,0 @@ -angular - .module('bit.global') - - .controller('baseController', function ($scope, i18nService) { - $scope.i18n = i18nService; - }); diff --git a/src/popup/app/global/global.module.ts b/src/popup/app/global/global.module.ts new file mode 100644 index 00000000000..f56dcd0d2b8 --- /dev/null +++ b/src/popup/app/global/global.module.ts @@ -0,0 +1,15 @@ +import * as angular from 'angular'; +import { BaseController } from './base.controller'; +import { MainController } from './main.controller'; +import { PrivateModeController } from './private-mode.controller'; +import { TabsController } from './tabs.controller'; + +export default angular + .module('bit.global', ['ngAnimate']) + + .controller('mainController', MainController) + .controller('baseController', BaseController) + .controller('tabsController', TabsController) + .controller('privateModeController', PrivateModeController) + + .name; diff --git a/src/popup/app/global/globalModule.js b/src/popup/app/global/globalModule.js deleted file mode 100644 index 4e60c9109fd..00000000000 --- a/src/popup/app/global/globalModule.js +++ /dev/null @@ -1,2 +0,0 @@ -angular - .module('bit.global', ['ngAnimate']); diff --git a/src/popup/app/global/main.controller.ts b/src/popup/app/global/main.controller.ts new file mode 100644 index 00000000000..4bd4f26b4e3 --- /dev/null +++ b/src/popup/app/global/main.controller.ts @@ -0,0 +1,46 @@ +import { UtilsService } from '../../../services/abstractions/utils.service'; + +export class MainController implements ng.IController { + smBody: boolean; + xsBody: boolean; + animation: string; + + constructor($scope: any, $transitions: any, $state: any, authService: any, toastr: any, + i18nService: any, $analytics: any, utilsService: UtilsService, $window: any) { + this.animation = ''; + this.xsBody = $window.screen.availHeight < 600; + this.smBody = !this.xsBody && $window.screen.availHeight <= 800; + + $transitions.onSuccess({}, (transition: any) => { + const toParams = transition.params('to'); + + if (toParams.animation) { + this.animation = toParams.animation; + } else { + this.animation = ''; + } + }); + + chrome.runtime.onMessage.addListener((msg: any, sender: any, sendResponse: any) => { + if (msg.command === 'syncCompleted') { + $scope.$broadcast('syncCompleted', msg.successfully); + } else if (msg.command === 'syncStarted') { + $scope.$broadcast('syncStarted'); + } else if (msg.command === 'doneLoggingOut') { + authService.logOut(() => { + $analytics.eventTrack('Logged Out'); + if (msg.expired) { + toastr.warning(i18nService.loginExpired, i18nService.loggedOut); + } + $state.go('home'); + }); + } else if (msg.command === 'collectPageDetailsResponse' && msg.sender === 'currentController') { + $scope.$broadcast('collectPageDetailsResponse', { + frameId: sender.frameId, + tab: msg.tab, + details: msg.details, + }); + } + }); + } +} diff --git a/src/popup/app/global/mainController.js b/src/popup/app/global/mainController.js deleted file mode 100644 index 279918b66f9..00000000000 --- a/src/popup/app/global/mainController.js +++ /dev/null @@ -1,46 +0,0 @@ -angular - .module('bit.global') - - .controller('mainController', function ($scope, $transitions, $state, authService, toastr, i18nService, $analytics, utilsService, - $window) { - var self = this; - self.animation = ''; - self.xsBody = $window.screen.availHeight < 600; - self.smBody = !self.xsBody && $window.screen.availHeight <= 800; - - $transitions.onSuccess({}, function(transition) { - const toParams = transition.params("to"); - - if (toParams.animation) { - self.animation = toParams.animation; - return; - } else { - self.animation = ''; - } - }); - - chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) { - if (msg.command === 'syncCompleted') { - $scope.$broadcast('syncCompleted', msg.successfully); - } - else if (msg.command === 'syncStarted') { - $scope.$broadcast('syncStarted'); - } - else if (msg.command === 'doneLoggingOut') { - authService.logOut(function () { - $analytics.eventTrack('Logged Out'); - if (msg.expired) { - toastr.warning(i18nService.loginExpired, i18nService.loggedOut); - } - $state.go('home'); - }); - } - else if (msg.command === 'collectPageDetailsResponse' && msg.sender === 'currentController') { - $scope.$broadcast('collectPageDetailsResponse', { - frameId: sender.frameId, - tab: msg.tab, - details: msg.details - }); - } - }); - }); diff --git a/src/popup/app/global/private-mode.controller.ts b/src/popup/app/global/private-mode.controller.ts new file mode 100644 index 00000000000..fe7186c398b --- /dev/null +++ b/src/popup/app/global/private-mode.controller.ts @@ -0,0 +1,9 @@ +export class PrivateModeController implements ng.IController { + constructor($scope: any) { + $scope.privateModeMessage = chrome.i18n.getMessage('privateModeMessage'); + $scope.learnMoreMessage = chrome.i18n.getMessage('learnMore'); + $scope.learnMore = () => { + chrome.tabs.create({ url: 'https://help.bitwarden.com/article/extension-wont-load-in-private-mode/' }); + }; + } +} diff --git a/src/popup/app/global/privateModeController.js b/src/popup/app/global/privateModeController.js deleted file mode 100644 index 395000ea2aa..00000000000 --- a/src/popup/app/global/privateModeController.js +++ /dev/null @@ -1,10 +0,0 @@ -angular - .module('bit.global') - - .controller('privateModeController', function ($scope) { - $scope.privateModeMessage = chrome.i18n.getMessage("privateModeMessage"); - $scope.learnMoreMessage = chrome.i18n.getMessage("learnMore"); - $scope.learnMore = function () { - chrome.tabs.create({ url: 'https://help.bitwarden.com/article/extension-wont-load-in-private-mode/' }); - }; - }); diff --git a/src/popup/app/global/tabs.controller.ts b/src/popup/app/global/tabs.controller.ts new file mode 100644 index 00000000000..729c569d102 --- /dev/null +++ b/src/popup/app/global/tabs.controller.ts @@ -0,0 +1,6 @@ +export class TabsController implements ng.IController { + constructor($scope: any, $state: any, i18nService: any) { + $scope.$state = $state; + $scope.i18n = i18nService; + } +} diff --git a/src/popup/app/global/tabsController.js b/src/popup/app/global/tabsController.js deleted file mode 100644 index 24225996bdb..00000000000 --- a/src/popup/app/global/tabsController.js +++ /dev/null @@ -1,7 +0,0 @@ -angular - .module('bit.global') - - .controller('tabsController', function ($scope, $state, i18nService) { - $scope.$state = $state; - $scope.i18n = i18nService; - });