app.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * Copyright © 2016-2017 Threema GmbH (https://threema.ch/).
  3. *
  4. * This file is part of Threema Web.
  5. *
  6. * Threema Web is free software: you can redistribute it and/or modify it
  7. * under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with Threema Web. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. import config from './config';
  20. import './controllers';
  21. import './directives';
  22. import './filters';
  23. import './partials/messenger';
  24. import './partials/welcome';
  25. import './services';
  26. import './threema/container';
  27. // Create app module and set dependencies
  28. angular.module('3ema', [
  29. // Angular
  30. 'ngAnimate',
  31. 'ngSanitize',
  32. // 3rd party
  33. 'ui.router',
  34. 'angular-inview',
  35. 'monospaced.qrcode',
  36. 'luegg.directives',
  37. 'pascalprecht.translate',
  38. 'ngMaterial',
  39. // Own
  40. '3ema.filters',
  41. '3ema.directives',
  42. '3ema.container',
  43. '3ema.services',
  44. '3ema.controllers',
  45. '3ema.welcome',
  46. '3ema.messenger',
  47. ])
  48. // Set versions
  49. .value('VERSION', '0.0.1')
  50. .value('PROTOCOL_VERSION', 1)
  51. // Configuration object
  52. .constant('CONFIG', config)
  53. // Set cache bust parameter
  54. .constant('CACHE_BUST', 'v=[[VERSION]]')
  55. // Constants to be used by controllers
  56. .constant('BROWSER_MIN_VERSIONS', {
  57. FF: 47,
  58. CHROME: 45,
  59. OPERA: 32,
  60. })
  61. // Set default route
  62. .config(['$urlRouterProvider', ($urlRouterProvider) => {
  63. $urlRouterProvider.otherwise('/welcome');
  64. }])
  65. // Configure i18n / l10n
  66. .config(['$translateProvider', ($translateProvider: ng.translate.ITranslateProvider) => {
  67. $translateProvider.useSanitizeValueStrategy('sanitizeParameters');
  68. $translateProvider.useMessageFormatInterpolation();
  69. $translateProvider
  70. .useStaticFilesLoader({
  71. prefix: 'i18n/',
  72. suffix: '.json',
  73. })
  74. .uniformLanguageTag('java')
  75. .registerAvailableLanguageKeys(['en', 'de'], {
  76. 'en_*': 'en',
  77. 'de_*': 'de',
  78. })
  79. .determinePreferredLanguage()
  80. .fallbackLanguage('en');
  81. }])
  82. // Configure theme
  83. .config(['$mdThemingProvider', ($mdThemingProvider) => {
  84. $mdThemingProvider.theme('default')
  85. .primaryPalette('grey', {
  86. default: '800',
  87. })
  88. .accentPalette('teal', {
  89. default: '500',
  90. });
  91. }])
  92. // Optimizations: https://docs.angularjs.org/guide/production
  93. .config(['$compileProvider', ($compileProvider) => {
  94. // Disable debug info for improved performance
  95. // TODO: Somehow breaks overflow: scroll on chat window.
  96. // Comment for now.
  97. // $compileProvider.debugInfoEnabled(false);
  98. }])
  99. // Add cache busting parameter to some HTTP requests
  100. .config(['$httpProvider', ($httpProvider: ng.IHttpProvider) => {
  101. $httpProvider.interceptors.push(['CACHE_BUST', (CACHE_BUST: string) => {
  102. return {
  103. request: (config) => {
  104. if (config.url.indexOf('partials/') !== -1 ||
  105. config.url.indexOf('directives/') !== -1 ||
  106. config.url.indexOf('i18n/') !== -1) {
  107. const separator = config.url.indexOf('?') === -1 ? '?' : '&';
  108. config.url = config.url + separator + CACHE_BUST;
  109. }
  110. return config;
  111. },
  112. };
  113. }]);
  114. }])
  115. ;