app.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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.definePalette('threema', {
  102. 50: 'f2faf5',
  103. 100: 'e6f6eb',
  104. 200: 'cdedd9',
  105. 300: 'b4e4c5',
  106. 400: '9bdbb2',
  107. 500: '82d29f',
  108. 600: '69ca8c',
  109. 700: '50c078',
  110. 800: '37b865',
  111. 900: '1eae52',
  112. A100: '05a63f',
  113. A200: '048432',
  114. A400: '03732b',
  115. A700: '036325',
  116. contrastDefaultColor: 'light',
  117. contrastDarkColors: ['50', '100', '200', '300', '400', '500', '600'],
  118. });
  119. $mdThemingProvider.theme('default')
  120. .primaryPalette('grey', {
  121. default: '800',
  122. })
  123. .accentPalette('threema', {
  124. default: 'A100',
  125. });
  126. }])
  127. // Optimizations: https://docs.angularjs.org/guide/production
  128. .config(['$compileProvider', ($compileProvider) => {
  129. // Disable debug info for improved performance
  130. // TODO: Somehow breaks overflow: scroll on chat window.
  131. // Comment for now.
  132. // $compileProvider.debugInfoEnabled(false);
  133. }])
  134. // Add cache busting parameter to some HTTP requests
  135. .config(['$httpProvider', ($httpProvider: ng.IHttpProvider) => {
  136. $httpProvider.interceptors.push(['CACHE_BUST', (CACHE_BUST: string) => {
  137. return {
  138. request: (conf) => {
  139. if (conf.url.indexOf('partials/') !== -1 ||
  140. conf.url.indexOf('directives/') !== -1 ||
  141. conf.url.indexOf('components/') !== -1 ||
  142. conf.url.indexOf('i18n/') !== -1) {
  143. const separator = conf.url.indexOf('?') === -1 ? '?' : '&';
  144. conf.url = conf.url + separator + CACHE_BUST;
  145. }
  146. return conf;
  147. },
  148. };
  149. }]);
  150. }])
  151. ;