app.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /**
  2. * Copyright © 2016-2019 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 {AsyncEvent} from 'ts-events';
  20. import './components';
  21. import config from './config';
  22. import './controllers';
  23. import './directives';
  24. import './filters';
  25. import './partials/messenger';
  26. import './partials/welcome';
  27. import './services';
  28. import './threema/container';
  29. // Configure asynchronous events
  30. AsyncEvent.setScheduler(function(callback) {
  31. // Replace the default setImmediate() call by a setTimeout(, 0) call
  32. setTimeout(callback, 0);
  33. });
  34. // Create app module and set dependencies
  35. angular.module('3ema', [
  36. // Angular
  37. 'ngAnimate',
  38. 'ngSanitize',
  39. 'ngAria',
  40. // 3rd party
  41. 'ui.router',
  42. 'angular-inview',
  43. 'monospaced.qrcode',
  44. 'luegg.directives',
  45. 'pascalprecht.translate',
  46. 'ngMaterial',
  47. // Own
  48. '3ema.filters',
  49. '3ema.components',
  50. '3ema.directives',
  51. '3ema.container',
  52. '3ema.services',
  53. '3ema.controllers',
  54. '3ema.welcome',
  55. '3ema.messenger',
  56. ])
  57. // Set versions
  58. .value('VERSION', config.VERSION)
  59. .value('PROTOCOL_VERSION', 2)
  60. // Configuration object
  61. .constant('CONFIG', config)
  62. // Set cache bust parameter
  63. .constant('CACHE_BUST', `v=${config.VERSION}`)
  64. // Constants to be used by controllers
  65. .constant('BROWSER_MIN_VERSIONS', {
  66. FF: 60,
  67. CHROME: 65,
  68. OPERA: 52,
  69. SAFARI: 11,
  70. })
  71. // Set default route
  72. .config(['$urlRouterProvider', ($urlRouterProvider) => {
  73. $urlRouterProvider.otherwise('/welcome');
  74. }])
  75. // Configure i18n / l10n
  76. .config(['$translateProvider', ($translateProvider: ng.translate.ITranslateProvider) => {
  77. $translateProvider.useSanitizeValueStrategy('sanitizeParameters');
  78. $translateProvider.useMessageFormatInterpolation();
  79. $translateProvider
  80. .useStaticFilesLoader({
  81. prefix: 'i18n/',
  82. suffix: '.json',
  83. })
  84. .uniformLanguageTag('java')
  85. .registerAvailableLanguageKeys(['cs', 'de', 'en', 'es', 'fr', 'nl', 'sk', 'uk', 'zh'], {
  86. 'cs_*': 'cs',
  87. 'de_*': 'de',
  88. 'en_*': 'en',
  89. 'es_*': 'es',
  90. 'fr_*': 'fr',
  91. 'nl_*': 'nl',
  92. 'sk_*': 'sk',
  93. 'uk_*': 'uk',
  94. 'zh_*': 'zh',
  95. })
  96. .determinePreferredLanguage()
  97. .fallbackLanguage('en');
  98. }])
  99. // Configure theme
  100. .config(['$mdThemingProvider', ($mdThemingProvider) => {
  101. $mdThemingProvider.theme('default')
  102. .primaryPalette('grey', {
  103. default: '800',
  104. })
  105. .accentPalette('teal', {
  106. default: '500',
  107. });
  108. }])
  109. // Optimizations: https://docs.angularjs.org/guide/production
  110. .config(['$compileProvider', ($compileProvider) => {
  111. // Disable debug info for improved performance
  112. // TODO: Somehow breaks overflow: scroll on chat window.
  113. // Comment for now.
  114. // $compileProvider.debugInfoEnabled(false);
  115. }])
  116. // Add cache busting parameter to some HTTP requests
  117. .config(['$httpProvider', ($httpProvider: ng.IHttpProvider) => {
  118. $httpProvider.interceptors.push(['CACHE_BUST', (CACHE_BUST: string) => {
  119. return {
  120. request: (conf) => {
  121. if (conf.url.indexOf('partials/') !== -1 ||
  122. conf.url.indexOf('directives/') !== -1 ||
  123. conf.url.indexOf('components/') !== -1 ||
  124. conf.url.indexOf('i18n/') !== -1) {
  125. const separator = conf.url.indexOf('?') === -1 ? '?' : '&';
  126. conf.url = conf.url + separator + CACHE_BUST;
  127. }
  128. return conf;
  129. },
  130. };
  131. }]);
  132. }])
  133. ;