]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/app.component.ts
Fix playback rate
[github/Chocobozzz/PeerTube.git] / client / src / app / app.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { DomSanitizer, SafeHtml } from '@angular/platform-browser'
3 import { GuardsCheckStart, Router } from '@angular/router'
4 import { AuthService, RedirectService, ServerService } from '@app/core'
5 import { isInSmallView } from '@app/shared/misc/utils'
6
7 @Component({
8 selector: 'my-app',
9 templateUrl: './app.component.html',
10 styleUrls: [ './app.component.scss' ]
11 })
12 export class AppComponent implements OnInit {
13 notificationOptions = {
14 timeOut: 5000,
15 lastOnBottom: true,
16 clickToClose: true,
17 maxLength: 0,
18 maxStack: 7,
19 showProgressBar: false,
20 pauseOnHover: false,
21 preventDuplicates: false,
22 preventLastDuplicates: 'visible',
23 rtl: false
24 }
25
26 isMenuDisplayed = true
27
28 customCSS: SafeHtml
29
30 constructor (
31 private router: Router,
32 private authService: AuthService,
33 private serverService: ServerService,
34 private domSanitizer: DomSanitizer,
35 private redirectService: RedirectService
36 ) {}
37
38 get serverVersion () {
39 return this.serverService.getConfig().serverVersion
40 }
41
42 get instanceName () {
43 return this.serverService.getConfig().instance.name
44 }
45
46 ngOnInit () {
47 if (this.router.url === '/') {
48 this.redirectService.redirectToHomepage()
49 }
50
51 this.authService.loadClientCredentials()
52
53 if (this.authService.isLoggedIn()) {
54 // The service will automatically redirect to the login page if the token is not valid anymore
55 this.authService.refreshUserInformation()
56 }
57
58 // Load custom data from server
59 this.serverService.loadConfig()
60 this.serverService.loadVideoCategories()
61 this.serverService.loadVideoLanguages()
62 this.serverService.loadVideoLicences()
63 this.serverService.loadVideoPrivacies()
64
65 // Do not display menu on small screens
66 if (isInSmallView()) {
67 this.isMenuDisplayed = false
68 }
69
70 this.router.events.subscribe(
71 e => {
72 // User clicked on a link in the menu, change the page
73 if (e instanceof GuardsCheckStart && isInSmallView()) {
74 this.isMenuDisplayed = false
75 }
76 }
77 )
78
79 this.serverService.configLoaded
80 .subscribe(() => {
81 const config = this.serverService.getConfig()
82
83 // We test customCSS in case or the admin removed the css
84 if (this.customCSS || config.instance.customizations.css) {
85 const styleTag = '<style>' + config.instance.customizations.css + '</style>'
86 this.customCSS = this.domSanitizer.bypassSecurityTrustHtml(styleTag)
87 }
88
89 if (config.instance.customizations.javascript) {
90 try {
91 // tslint:disable:no-eval
92 eval(config.instance.customizations.javascript)
93 } catch (err) {
94 console.error('Cannot eval custom JavaScript.', err)
95 }
96 }
97 })
98 }
99
100 toggleMenu () {
101 window.scrollTo(0, 0)
102 this.isMenuDisplayed = !this.isMenuDisplayed
103 }
104
105 getMainColClasses () {
106 // Take all width is the menu is not displayed
107 if (this.isMenuDisplayed === false) return [ 'expanded' ]
108
109 return []
110 }
111 }