Add ability to delete and update abuse on client
[oweals/peertube.git] / client / src / main.ts
1 import { enableProdMode, TRANSLATIONS, TRANSLATIONS_FORMAT } from '@angular/core'
2 import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
3
4 import { AppModule } from './app/app.module'
5 import { environment } from './environments/environment'
6
7 import { hmrBootstrap } from './hmr'
8 import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils'
9
10 let providers = []
11 if (environment.production) {
12   enableProdMode()
13 }
14
15 // Template translation, should be in the bootstrap step
16 if (isOnDevLocale()) {
17   const locale = getDevLocale()
18   const translations = require(`raw-loader!./locale/target/angular_${locale}.xml`)
19
20   providers = [
21     { provide: TRANSLATIONS, useValue: translations },
22     { provide: TRANSLATIONS_FORMAT, useValue: 'xlf' }
23   ]
24 }
25
26 const bootstrap = () => platformBrowserDynamic()
27   .bootstrapModule(AppModule, { providers })
28   .then(bootstrapModule => {
29     // TODO: Uncomment and remove unregistration when https://github.com/angular/angular/issues/21191 is fixed
30     // TODO: Remove when https://github.com/angular/angular-cli/issues/8779 is fixed?
31     // if ('serviceWorker' in navigator && environment.production) {
32     //   navigator.serviceWorker.register('/ngsw-worker.js')
33     //     .catch(err => console.error('Cannot register service worker.', err))
34     // }
35
36     if (navigator.serviceWorker) {
37       navigator.serviceWorker.getRegistrations()
38         .then(registrations => {
39           for (const registration of registrations) {
40             registration.unregister()
41           }
42         })
43     }
44
45     return bootstrapModule
46   })
47   .catch(err => {
48     console.error(err)
49     return null
50   })
51
52 if (environment.hmr) {
53   if (module[ 'hot' ]) {
54     hmrBootstrap(module, bootstrap)
55   } else {
56     console.error('HMR is not enabled for webpack-dev-server!')
57     console.log('Are you using the --hmr flag for ng serve?')
58   }
59 } else {
60   bootstrap()
61 }