app.ts 3.9 KB

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